Check geozone 'safe_to_delete' behavior as unit test instead of integration test

This commit is contained in:
Alberto Miedes Garcés
2016-12-13 18:38:13 +01:00
parent 419905fb59
commit db029964fa
2 changed files with 27 additions and 46 deletions

View File

@@ -83,7 +83,7 @@ feature 'Admin geozones' do
expect(Geozone.where(id: geozone.id)).to be_empty
end
scenario 'Delete geozone with associated proposal' do
scenario 'Delete geozone with associated element' do
geozone = create(:geozone, name: 'Delete me!')
create(:proposal, geozone: geozone)
@@ -97,49 +97,4 @@ feature 'Admin geozones' do
expect(page).to have_content 'Delete me!'
end
end
scenario 'Delete geozone with associated spending proposal' do
geozone = create(:geozone, name: 'Delete me!')
create(:spending_proposal, geozone: geozone)
visit admin_geozones_path
within("#geozone_#{geozone.id}") { click_link 'Delete' }
expect(page).to have_content "This geozone can't be deleted since there are elements attached to it"
within("#geozone_#{geozone.id}") do
expect(page).to have_content 'Delete me!'
end
end
scenario 'Delete geozone with associated debate' do
geozone = create(:geozone, name: 'Delete me!')
create(:debate, geozone: geozone)
visit admin_geozones_path
within("#geozone_#{geozone.id}") { click_link 'Delete' }
expect(page).to have_content "This geozone can't be deleted since there are elements attached to it"
within("#geozone_#{geozone.id}") do
expect(page).to have_content 'Delete me!'
end
end
scenario 'Delete geozone with associated user' do
geozone = create(:geozone, name: 'Delete me!')
create(:user, geozone: geozone)
visit admin_geozones_path
within("#geozone_#{geozone.id}") { click_link 'Delete' }
expect(page).to have_content "This geozone can't be deleted since there are elements attached to it"
within("#geozone_#{geozone.id}") do
expect(page).to have_content 'Delete me!'
end
end
end

View File

@@ -11,4 +11,30 @@ RSpec.describe Geozone, type: :model do
geozone.name = nil
expect(geozone).to_not be_valid
end
describe "#safe_to_destroy?" do
it "is true when not linked to other models" do
expect(geozone.safe_to_destroy?).to be_truthy
end
it "is false when already linked to user" do
create(:user, geozone: geozone)
expect(geozone.safe_to_destroy?).to be_falsey
end
it "is false when already linked to proposal" do
create(:proposal, geozone: geozone)
expect(geozone.safe_to_destroy?).to be_falsey
end
it "is false when already linked to spending proposal" do
create(:spending_proposal, geozone: geozone)
expect(geozone.safe_to_destroy?).to be_falsey
end
it "is false when already linked to debate" do
create(:debate, geozone: geozone)
expect(geozone.safe_to_destroy?).to be_falsey
end
end
end