diff --git a/spec/requests/works_spec.rb b/spec/requests/works_spec.rb index 12ceac087..d1ac7fe16 100644 --- a/spec/requests/works_spec.rb +++ b/spec/requests/works_spec.rb @@ -57,7 +57,6 @@ context "when the work has been approved" do let(:work) { FactoryBot.create(:approved_work) } let(:collection) { work.collection } - let(:user) { FactoryBot.create(:super_admin_user) } context "when appending a second title" do let(:params) do @@ -84,24 +83,66 @@ end before do - # work.update_curator(user.id, user) - # collection.add_administrator(admin, user) patch work_url(work), params: params end - it "updates the title" do - expect(response.status).to eq(302) - work.reload + context "when authenticated as a super admin user" do + let(:user) { FactoryBot.create(:super_admin_user) } - expect(work.metadata).to be_a(Hash) - expect(work.metadata).to include("titles") - titles = work.metadata["titles"] - expect(titles.length).to eq(2) + it "updates the title" do + expect(response.status).to eq(302) + work.reload - subtitle = titles.last - expect(subtitle).to be_a(Hash) - expect(subtitle).to include("title" => "the subtitle") - expect(subtitle).to include("title_type" => "Subtitle") + expect(work.metadata).to be_a(Hash) + expect(work.metadata).to include("titles") + titles = work.metadata["titles"] + expect(titles.length).to eq(2) + + subtitle = titles.last + expect(subtitle).to be_a(Hash) + expect(subtitle).to include("title" => "the subtitle") + expect(subtitle).to include("title_type" => "Subtitle") + end + end + + context "when authenticated as the submitter of the Work" do + let(:user) { work.created_by_user } + + it "updates the title" do + expect(response.status).to eq(302) + work.reload + + expect(work.metadata).to be_a(Hash) + expect(work.metadata).to include("titles") + titles = work.metadata["titles"] + expect(titles.length).to eq(2) + + subtitle = titles.last + expect(subtitle).to be_a(Hash) + expect(subtitle).to include("title" => "the subtitle") + expect(subtitle).to include("title_type" => "Subtitle") + end + end + + context "when authenticated as the curator for the Work" do + let(:user) do + FactoryBot.create :user, collections_to_admin: [collection] + end + + it "updates the title" do + expect(response.status).to eq(302) + work.reload + + expect(work.metadata).to be_a(Hash) + expect(work.metadata).to include("titles") + titles = work.metadata["titles"] + expect(titles.length).to eq(2) + + subtitle = titles.last + expect(subtitle).to be_a(Hash) + expect(subtitle).to include("title" => "the subtitle") + expect(subtitle).to include("title_type" => "Subtitle") + end end end end