Skip to content

Commit

Permalink
fix(request): supprimer les requests_distributions quand une request …
Browse files Browse the repository at this point in the history
…est terminée #91
  • Loading branch information
Lelievre-david authored Dec 18, 2024
1 parent 2c3352a commit cf5538a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 6 additions & 0 deletions app/models/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ class Request < ApplicationRecord
length: { minimum: 1, message: :at_least_one }
validates :plant_stage, presence: true
end

after_transition to: :completed, do: :cleanup_request_distributions
end

def cleanup_request_distributions
request_distributions.destroy_all
end
end

Expand Down
6 changes: 0 additions & 6 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@
area: 40
)

Pot.create!(
name: 'My other pot',
shape: :other,
area: 120
)

building1 = Building.create!(
name: 'Main Building',
description: 'The main building that houses the primary operations.'
Expand Down
1 change: 1 addition & 0 deletions spec/acceptance/api/v1/requests_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@
request.reload
expect(response_body).to eq(request.to_blueprint)
expect(request.status).to eq(:completed)
expect(request.request_distributions).to be_empty
end
end

Expand Down

0 comments on commit cf5538a

Please sign in to comment.