-
Notifications
You must be signed in to change notification settings - Fork 843
/
homepage_spec.rb
93 lines (73 loc) · 2.44 KB
/
homepage_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# typed: false
require "rails_helper"
RSpec.feature "Reading Homepage", type: :feature do
let!(:story) { create(:story, description: "Preview shown") }
feature "when logged out" do
scenario "homepage" do
visit "/"
expect(page).to have_content(story.title)
end
end
feature "when logged in" do
let(:user) { create(:user) }
before(:each) { stub_login_as user }
scenario "homepage" do
visit "/"
expect(page).to have_content(story.title)
end
scenario "shows previews if the user wants" do
user.show_story_previews = true
user.save!
visit "/"
expect(page).to have_content(story.description)
end
end
feature "as moderator" do
scenario "homepage as moderator" do
mod = create(:user, :moderator)
stub_login_as mod
visit "/"
expect(page).to have_content(story.title)
end
scenario "homepage as moderator with pending hat requests" do
create(:hat_request)
mod = create(:user, :moderator)
stub_login_as mod
visit "/"
expect(page).to have_content(story.title)
end
end
feature "browsing stories by tag" do
let(:tag_a) { Category.first.tags.create!(tag: "A1").tag }
let(:tag_b) { Category.first.tags.create!(tag: "B2").tag }
let!(:ab_story) { create(:story, tags_a: [tag_a, tag_b]) }
let!(:a_story) { create(:story, tags_a: [tag_a]) }
let!(:b_story) { create(:story, tags_a: [tag_b]) }
scenario "viewing one tag at a time" do
visit "/t/#{tag_a}"
expect(page).to have_content(ab_story.title)
expect(page).to have_content(a_story.title)
visit "/t/#{tag_b}"
expect(page).to have_content(ab_story.title)
expect(page).to have_content(b_story.title)
end
scenario "viewing two tags" do
tags = [tag_a, tag_b].join(",")
visit "/t/#{tags}"
expect(page).to have_content(ab_story.title)
expect(page).to have_content(a_story.title)
expect(page).to have_content(b_story.title)
end
context "errors" do
scenario "non-existent tag raises error" do
expect { visit "/t/definitelynosuchtaghere" }.to raise_error
end
scenario "non-existent tag with existing tag raises an error" do
expect { visit "/t/#{tag_a},definitelynosuchtaghere" }.to raise_error
end
scenario "non-unique existing tags raises an error" do
expect { visit "/t/#{tag_a},#{tag_a}" }.to raise_error
end
end
end
end