Skip to content

Commit

Permalink
Add scopes for deleted conversation and add missing scope tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ankit Famyial authored and Ankit Famyial committed Apr 17, 2016
1 parent 99d1687 commit 98e8830
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/models/mailboxer/conversation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class Mailboxer::Conversation < ActiveRecord::Base
scope :not_trash, lambda {|participant|
participant(participant).merge(Mailboxer::Receipt.not_trash)
}
scope :deleted, lambda {|participant|
participant(participant).merge(Mailboxer::Receipt.deleted)
}
scope :not_deleted, lambda {|participant|
participant(participant).merge(Mailboxer::Receipt.not_deleted)
}
scope :between, lambda {|participant_one, participant_two|
joins("INNER JOIN (#{Mailboxer::Notification.recipient(participant_two).to_sql}) `participant_two_notifications` ON `participant_two_notifications`.`conversation_id` = `mailboxer_conversations`.`id` AND `participant_two_notifications`.`type` IN ('Mailboxer::Message')").
joins("INNER JOIN `mailboxer_receipts` ON `mailboxer_receipts`.`notification_id` = `participant_two_notifications`.`id` ").
Expand Down
27 changes: 27 additions & 0 deletions spec/models/conversation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,33 @@
end
end

describe ".not_trash" do
it "finds non trashed conversations with receipts for participant" do
trashed_conversation = entity1.send_message(participant, "Body", "Subject").notification.conversation
trashed_conversation.move_to_trash(participant)

expect(Mailboxer::Conversation.not_trash(participant)).to eq [sentbox_conversation, inbox_conversation]
end
end

describe ".deleted" do
it "finds deleted conversations with receipts for participant" do
deleted_conversation = entity1.send_message(participant, "Body", "Subject").notification.conversation
deleted_conversation.mark_as_deleted(participant)

expect(Mailboxer::Conversation.deleted(participant)).to eq [deleted_conversation]
end
end

describe ".not_deleted" do
it "finds non trashed conversations with receipts for participant" do
deleted_conversation = entity1.send_message(participant, "Body", "Subject").notification.conversation
deleted_conversation.mark_as_deleted(participant)

expect(Mailboxer::Conversation.not_deleted(participant)).to eq [sentbox_conversation, inbox_conversation]
end
end

describe ".unread" do
it "finds unread conversations with receipts for participant" do
[sentbox_conversation, inbox_conversation].each {|c| c.mark_as_read(participant) }
Expand Down

0 comments on commit 98e8830

Please sign in to comment.