aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGareth Rees <gareth@mysociety.org>2015-06-26 13:16:33 +0100
committerGareth Rees <gareth@mysociety.org>2015-06-26 13:16:33 +0100
commit1fbe86eaf63414404ba39da4162be5b4b3ffc996 (patch)
treea5ec9dc25ff5acc67b10726ce321710c5ceab99d
parent8d6088d6119c46026d17420ce416a6afee2e2346 (diff)
Destroy associated widget_votes
Prevents orphan widget_votes existing when the parent InfoRequest is destroyed.
-rw-r--r--app/models/info_request.rb2
-rw-r--r--spec/models/info_request_spec.rb7
2 files changed, 8 insertions, 1 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 3ce0e3cd2..b76ade834 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -53,7 +53,7 @@ class InfoRequest < ActiveRecord::Base
has_many :info_request_events, :order => 'created_at'
has_many :user_info_request_sent_alerts
has_many :track_things, :order => 'created_at desc'
- has_many :widget_votes
+ has_many :widget_votes, :dependent => :destroy
has_many :comments, :order => 'created_at'
has_many :censor_rules, :order => 'created_at desc'
has_many :mail_server_logs, :order => 'mail_server_log_done_id'
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index 5f3b118ed..344f9928c 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -154,6 +154,13 @@ describe InfoRequest do
@info_request.destroy
end
+ it 'destroys associated widget_votes' do
+ @info_request.save
+ @info_request.widget_votes.create(:cookie => 'x' * 20)
+ @info_request.destroy
+ expect(WidgetVote.where(:info_request_id => @info_request.id)).to be_empty
+ end
+
end
describe :fully_destroy do