From abf3715e1052703a48948a747a681add0adc13b4 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Mon, 9 Apr 2018 20:57:12 -0700 Subject: [PATCH] Add spec on discard_all through an association Mostly as a sanity check --- spec/discard/model_spec.rb | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/spec/discard/model_spec.rb b/spec/discard/model_spec.rb index 0b34d46..93129d7 100644 --- a/spec/discard/model_spec.rb +++ b/spec/discard/model_spec.rb @@ -339,6 +339,45 @@ expect(post.reload).not_to be_discarded expect(post2.reload).not_to be_discarded end + + context "through a collection" do + with_model :Comment, scope: :all do + table do |t| + t.belongs_to :user + t.datetime :discarded_at + t.timestamps null: false + end + + model do + include Discard::Model + end + end + + with_model :User, scope: :all do + table do |t| + t.timestamps null: false + end + + model do + include Discard::Model + + has_many :comments + end + end + + it "can be discard all related posts" do + user1 = User.create! + user2 = User.create! + + 2.times { user1.comments.create! } + 2.times { user1.comments.create! } + + user1.comments.discard_all + + expect(user1.comments).to all(be_discarded) + expect(user2.comments).to all(be_undiscarded) + end + end end describe '.undiscard_all' do