Skip to content

Commit

Permalink
Add sad path specs for incorrect and identical uris when creating a r…
Browse files Browse the repository at this point in the history
…esource
  • Loading branch information
jacobyarborough committed Jan 19, 2024
1 parent 97733b3 commit 24c0ff6
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions spec/features/resource_adding_and_changing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 24c0ff6

Please sign in to comment.