Skip to content

Commit

Permalink
Bugfix: place deletion was being allowed even if they were used in pr…
Browse files Browse the repository at this point in the history
…oject rules.
  • Loading branch information
kueda committed Jul 2, 2015
1 parent fa4d7ed commit b151f11
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/controllers/places_controller.rb
Expand Up @@ -216,7 +216,10 @@ def update

def destroy
errors = []
errors << "there are people using this place in their projects" if @place.projects.exists?
if @place.projects.exists? ||
ProjectObservationRule.where(ruler_type: 'Project', operand: @place, operator: "observed_in_place?").exists?
errors << "there are people using this place in their projects"
end
errors << "there are people using this place in their guides" if @place.guides.exists?
if errors.blank?
@place.destroy
Expand Down
15 changes: 14 additions & 1 deletion spec/controllers/places_controller_spec.rb
Expand Up @@ -18,13 +18,26 @@
describe "destroy" do
let(:user) { User.make! }
let(:place) { Place.make!(:user => user) }
it "should delete the place" do
before do
sign_in user
end
it "should delete the place" do
expect(place).not_to be_blank
expect {
delete :destroy, :id => place.id
}.to change(Place, :count).by(-1)
end
it "should fail if projects are using the place" do
p = Project.make!(place: place)
delete :destroy, id: place.id
expect( Place.find_by_id(place.id) ).not_to be_blank
end
it "should fail if projects are using the place in rules" do
p = Project.make!
p.project_observation_rules.create(operand: place, operator: 'observed_in_place?')
delete :destroy, id: place.id
expect( Place.find_by_id(place.id) ).not_to be_blank
end
end

describe "search" do
Expand Down

0 comments on commit b151f11

Please sign in to comment.