Skip to content

Commit

Permalink
Refactor spec to DRY up code
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobyarborough committed Jan 19, 2024
1 parent 24c0ff6 commit 1cfc199
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions spec/features/resource_adding_and_changing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
attributes_for(:resource, canonical_id: "abc123").symbolize_keys
end

it "succeeds" do
before(:each) do
click_first_link "Resources"
click_first_link("Add Resource")
end

it "succeeds" do
within(".form-field.resource_resource_groups") do
user_organization.resource_groups.default.each do |other_group|
uncheck(other_group.name)
Expand All @@ -39,14 +41,11 @@
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 }
let!(:resource) { create(:resource, organization_id: user_organization.id) }
let(:resource_uri) { resource.source_uri }

describe 'source URI is invalid' do
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!"
Expand All @@ -59,13 +58,7 @@
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
Expand Down

0 comments on commit 1cfc199

Please sign in to comment.