Skip to content

Commit bc04167

Browse files
author
strictlyNDN
committed
AO3-3245 - Update tests and move. Reduce owner check in controller. Update translation key
1 parent 96c4764 commit bc04167

File tree

4 files changed

+57
-59
lines changed

4 files changed

+57
-59
lines changed

app/controllers/works_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ def new
244244
@unposted = current_user.unposted_work
245245

246246
# Check if collection is closed and user doesn't have permission to post
247-
if @collection&.closed? && !@collection&.user_is_owner?(current_user) && !@collection&.user_is_maintainer?(current_user)
248-
flash[:error] = t(".closed_collection_error", collection_title: @collection.title)
247+
if @collection&.closed? && !@collection&.user_is_maintainer?(current_user)
248+
flash[:error] = t(".closed_collection", collection_title: @collection.title)
249249
redirect_to collection_path(@collection) and return
250250
end
251251

config/locales/controllers/en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ en:
305305
edit_tags:
306306
page_title: Edit Work Tags
307307
new:
308-
closed_collection_error: Sorry, the collection %{collection_title} is closed, new works cannot be added to it.
308+
closed_collection: Sorry, the collection %{collection_title} is closed. New works cannot be added to it.
309309
show:
310310
page_title:
311311
unrevealed: Mystery Work

spec/controllers/works/default_rails_actions_spec.rb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,60 @@ def call_with_params(params)
195195
it_redirects_to_simple(user_path(banned_user))
196196
expect(flash[:error]).to include("Your account has been banned.")
197197
end
198+
199+
context "when collection is closed" do
200+
let(:collection) { create(:collection, title: "Excalibur", collection_preference: create(:collection_preference, closed: true)) }
201+
let(:user) { create(:user) }
202+
203+
before { fake_login_known_user(user) }
204+
205+
it "redirects to collection page with error for non-maintainers" do
206+
get :new, params: { collection_id: collection.name }
207+
it_redirects_to_with_error(collection_path(collection), "Sorry, the collection Excalibur is closed. New works cannot be added to it.")
208+
end
209+
end
210+
211+
context "when collection is closed but user is owner" do
212+
let(:user) { create(:user) }
213+
let(:collection) { create(:collection, title: "Excalibur", collection_preference: create(:collection_preference, closed: true)) }
214+
let!(:participant) { collection.collection_participants.create(pseud: user.default_pseud, participant_role: CollectionParticipant::OWNER) }
215+
216+
before do
217+
fake_login_known_user(user)
218+
end
219+
220+
it "allows access to new work form" do
221+
get :new, params: { collection_id: collection.name }
222+
expect(response).to render_template("new")
223+
end
224+
end
225+
226+
context "when collection is closed but user is maintainer" do
227+
let(:user) { create(:user) }
228+
let(:collection) { create(:collection, title: "Excalibur", collection_preference: create(:collection_preference, closed: true)) }
229+
let!(:participant) { collection.collection_participants.create(pseud: user.default_pseud, participant_role: CollectionParticipant::MODERATOR) }
230+
231+
before do
232+
fake_login_known_user(user)
233+
end
234+
235+
it "allows access to new work form" do
236+
get :new, params: { collection_id: collection.name }
237+
expect(response).to render_template("new")
238+
end
239+
end
240+
241+
context "when collection is open" do
242+
let(:collection) { create(:collection, title: "Excalibur", collection_preference: create(:collection_preference, closed: false)) }
243+
let(:user) { create(:user) }
244+
245+
before { fake_login_known_user(user) }
246+
247+
it "allows access to new work form" do
248+
get :new, params: { collection_id: collection.name }
249+
expect(response).to render_template("new")
250+
end
251+
end
198252
end
199253

200254
describe "create" do

spec/controllers/works/works_controller_spec.rb

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,62 +6,6 @@
66
include LoginMacros
77
include RedirectExpectationHelper
88

9-
describe "GET #new" do
10-
context "when collection is closed" do
11-
let(:collection) { create(:collection, title: "Excalibur", collection_preference: create(:collection_preference, closed: true)) }
12-
let(:user) { create(:user) }
13-
14-
before { fake_login_known_user(user) }
15-
16-
it "redirects to collection page with error for non-maintainers" do
17-
get :new, params: { collection_id: collection.name }
18-
it_redirects_to_with_error(collection_path(collection), "Sorry, the collection Excalibur is closed, new works cannot be added to it.")
19-
end
20-
end
21-
22-
context "when collection is closed but user is owner" do
23-
let(:user) { create(:user) }
24-
let(:collection) { create(:collection, title: "Excalibur", collection_preference: create(:collection_preference, closed: true)) }
25-
26-
before do
27-
fake_login_known_user(user)
28-
collection.collection_participants.create(pseud: user.default_pseud, participant_role: CollectionParticipant::OWNER)
29-
end
30-
31-
it "allows access to new work form" do
32-
get :new, params: { collection_id: collection.name }
33-
expect(response).to render_template("new")
34-
end
35-
end
36-
37-
context "when collection is closed but user is maintainer" do
38-
let(:user) { create(:user) }
39-
let(:collection) { create(:collection, title: "Excalibur", collection_preference: create(:collection_preference, closed: true)) }
40-
41-
before do
42-
fake_login_known_user(user)
43-
collection.collection_participants.create(pseud: user.default_pseud, participant_role: CollectionParticipant::MODERATOR)
44-
end
45-
46-
it "allows access to new work form" do
47-
get :new, params: { collection_id: collection.name }
48-
expect(response).to render_template("new")
49-
end
50-
end
51-
52-
context "when collection is open" do
53-
let(:collection) { create(:collection, title: "Excalibur", collection_preference: create(:collection_preference, closed: false)) }
54-
let(:user) { create(:user) }
55-
56-
before { fake_login_known_user(user) }
57-
58-
it "allows access to new work form" do
59-
get :new, params: { collection_id: collection.name }
60-
expect(response).to render_template("new")
61-
end
62-
end
63-
end
64-
659
describe "GET #navigate" do
6610
context "denies access for work that isn't visible to user" do
6711
subject { get :navigate, params: { id: work.id } }

0 commit comments

Comments
 (0)