Skip to content

Commit

Permalink
Add spec on discard_all through an association
Browse files Browse the repository at this point in the history
Mostly as a sanity check
  • Loading branch information
jhawthorn committed Apr 10, 2018
1 parent 3a169f0 commit abf3715
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions spec/discard/model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit abf3715

Please sign in to comment.