-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
proposals_spec.rb
223 lines (162 loc) · 7.19 KB
/
proposals_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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
require "rails_helper"
feature "Proposals" do
background do
login_as_manager
end
context "Create" do
scenario "Creating proposals on behalf of someone" do
user = create(:user, :level_two)
login_managed_user(user)
click_link "Create proposal"
within(".account-info") do
expect(page).to have_content "Identified as"
expect(page).to have_content user.username.to_s
expect(page).to have_content user.email.to_s
expect(page).to have_content user.document_number.to_s
end
fill_in "proposal_title", with: "Help refugees"
fill_in "proposal_question", with: "¿Would you like to give assistance to war refugees?"
fill_in "proposal_summary", with: "In summary, what we want is..."
fill_in "proposal_description", with: "This is very important because..."
fill_in "proposal_video_url", with: "https://www.youtube.com/watch?v=yRYFKcMa_Ek"
check "proposal_terms_of_service"
click_button "Create proposal"
expect(page).to have_content "Proposal created successfully."
expect(page).to have_content "Help refugees"
expect(page).to have_content "¿Would you like to give assistance to war refugees?"
expect(page).to have_content "In summary, what we want is..."
expect(page).to have_content "This is very important because..."
expect(page).to have_content "https://www.youtube.com/watch?v=yRYFKcMa_Ek"
expect(page).to have_content user.name
expect(page).to have_content I18n.l(Proposal.last.created_at.to_date)
expect(page).to have_current_path(management_proposal_path(Proposal.last))
end
scenario "Should not allow unverified users to create proposals" do
user = create(:user)
login_managed_user(user)
click_link "Create proposal"
expect(page).to have_content "User is not verified"
end
end
context "Show" do
scenario "When path matches the friendly url" do
proposal = create(:proposal)
user = create(:user, :level_two)
login_managed_user(user)
right_path = management_proposal_path(proposal)
visit right_path
expect(page).to have_current_path(right_path)
end
scenario "When path does not match the friendly url" do
proposal = create(:proposal)
user = create(:user, :level_two)
login_managed_user(user)
right_path = management_proposal_path(proposal)
old_path = "#{management_proposals_path}/#{proposal.id}-something-else"
visit old_path
expect(page).not_to have_current_path(old_path)
expect(page).to have_current_path(right_path)
end
end
scenario "Searching" do
proposal1 = create(:proposal, title: "Show me what you got")
proposal2 = create(:proposal, title: "Get Schwifty")
user = create(:user, :level_two)
login_managed_user(user)
click_link "Support proposals"
fill_in "search", with: "what you got"
click_button "Search"
expect(page).to have_current_path(management_proposals_path, ignore_query: true)
within(".proposals-list") do
expect(page).to have_css(".proposal", count: 1)
expect(page).to have_content(proposal1.title)
expect(page).to have_content(proposal1.summary)
expect(page).not_to have_content(proposal2.title)
expect(page).to have_css("a[href='#{management_proposal_path(proposal1)}']", text: proposal1.title)
end
end
scenario "Listing" do
proposal1 = create(:proposal, title: "Show me what you got")
proposal2 = create(:proposal, title: "Get Schwifty")
user = create(:user, :level_two)
login_managed_user(user)
click_link "Support proposals"
expect(page).to have_current_path(management_proposals_path)
within(".account-info") do
expect(page).to have_content "Identified as"
expect(page).to have_content user.username.to_s
expect(page).to have_content user.email.to_s
expect(page).to have_content user.document_number.to_s
end
within(".proposals-list") do
expect(page).to have_css(".proposal", count: 2)
expect(page).to have_css("a[href='#{management_proposal_path(proposal1)}']", text: proposal1.title)
expect(page).to have_content(proposal1.summary)
expect(page).to have_css("a[href='#{management_proposal_path(proposal2)}']", text: proposal2.title)
expect(page).to have_content(proposal2.summary)
end
end
context "Voting" do
let!(:proposal) { create(:proposal) }
scenario "Voting proposals on behalf of someone in index view", :js do
user = create(:user, :level_two)
login_managed_user(user)
click_link "Support proposals"
within(".proposals-list") do
click_link("Support")
expect(page).to have_content "1 support"
expect(page).to have_content "You have already supported this proposal. Share it!"
end
expect(page).to have_current_path(management_proposals_path)
end
scenario "Voting proposals on behalf of someone in show view", :js do
user = create(:user, :level_two)
login_managed_user(user)
click_link "Support proposals"
within(".proposals-list") { click_link proposal.title }
expect(page).to have_content proposal.code
within("#proposal_#{proposal.id}_votes") { click_link("Support") }
expect(page).to have_content "1 support"
expect(page).to have_content "You have already supported this proposal. Share it!"
expect(page).to have_current_path(management_proposal_path(proposal))
end
scenario "Should not allow unverified users to vote proposals" do
user = create(:user)
login_managed_user(user)
click_link "Support proposals"
expect(page).to have_content "User is not verified"
end
end
context "Printing" do
scenario "Printing proposals" do
6.times { create(:proposal) }
click_link "Print proposals"
expect(page).to have_css(".proposal", count: 5)
expect(page).to have_css("a[href='javascript:window.print();']", text: "Print")
end
scenario "Filtering proposals to be printed", :js do
worst_proposal = create(:proposal, title: "Worst proposal")
worst_proposal.update_column(:confidence_score, 2)
best_proposal = create(:proposal, title: "Best proposal")
best_proposal.update_column(:confidence_score, 10)
medium_proposal = create(:proposal, title: "Medium proposal")
medium_proposal.update_column(:confidence_score, 5)
user = create(:user, :level_two)
login_managed_user(user)
click_link "Print proposals"
expect(page).to have_selector(".js-order-selector[data-order='confidence_score']")
within(".proposals-list") do
expect(best_proposal.title).to appear_before(medium_proposal.title)
expect(medium_proposal.title).to appear_before(worst_proposal.title)
end
select "newest", from: "order-selector"
expect(page).to have_selector(".js-order-selector[data-order='created_at']")
expect(current_url).to include("order=created_at")
expect(current_url).to include("page=1")
within(".proposals-list") do
expect(medium_proposal.title).to appear_before(best_proposal.title)
expect(best_proposal.title).to appear_before(worst_proposal.title)
end
end
end
end