From 24c0ff6ce0f57665f2a70c03aca5e6636ffde23a Mon Sep 17 00:00:00 2001 From: Jacob Yarborough Date: Fri, 19 Jan 2024 15:38:11 -0500 Subject: [PATCH] Add sad path specs for incorrect and identical uris when creating a resource --- .../resource_adding_and_changing_spec.rb | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/spec/features/resource_adding_and_changing_spec.rb b/spec/features/resource_adding_and_changing_spec.rb index e45b1a45..3176ad2b 100644 --- a/spec/features/resource_adding_and_changing_spec.rb +++ b/spec/features/resource_adding_and_changing_spec.rb @@ -37,4 +37,44 @@ expect(page).to have_current_path(resource_path(resource, organization_id: user_organization), ignore_query: true) expect(page).to have_content(resource.name) end + + context "when invalid resource attributes are submitted" do + describe 'source URI is invalid' do + let!(:resource) { create(:resource, organization_id: user_organization.id) } + let(:resource_uri) { resource.source_uri } + + it "should display an error message and re-render the form" do + click_first_link "Resources" + click_first_link("Add Resource") + + fill_in "Caption", with: resource_attributes[:name] + fill_in "Canonical ID", with: resource_attributes[:canonical_id] + fill_in "Source URI", with: "Hello World!" + fill_in "Host URIs", with: "http://example.com/abc\nhttp://example.com/xyz" + click_button("Create Resource") + + expect(page).to have_current_path(resources_path(organization_id: user_organization)) + expect(page).to have_content("The Source URI is invalid.") + end + end + + describe 'source uri is not unique' do + let!(:resource) { create(:resource, organization_id: user_organization.id) } + let(:resource_uri) { resource.source_uri } + + it "should display an error message and re-render the form" do + click_first_link "Resources" + click_first_link("Add Resource") + + fill_in "Caption", with: resource_attributes[:name] + fill_in "Canonical ID", with: resource_attributes[:canonical_id] + fill_in "Source URI", with: resource_uri + fill_in "Host URIs", with: "http://example.com/abc\nhttp://example.com/xyz" + click_button("Create Resource") + + expect(page).to have_current_path(resources_path(organization_id: user_organization)) + expect(page).to have_content("The Source URI is already in use for this organization.") + end + end + end end