Permalink
Browse files

Fix bad conditional on hash with false value

* It turns out that {:foo => false}[:foo].present? is false
* "and" and "or" are almost never what you really want:
   http://devblog.avdi.org/2010/08/02/using-and-and-or-in-ruby/
  • Loading branch information...
1 parent 3e1b0d1 commit dea5e3a429c7c511b4f9ea066c38f787678dbaa1 Dave Worth committed Jun 14, 2012
Showing with 7 additions and 1 deletion.
  1. +1 −1 app/models/mailbox.rb
  2. +6 −0 spec/models/mailbox_spec.rb
View
@@ -42,7 +42,7 @@ def conversations(options = {})
end
end
- if (options[:read].present? and options[:read]==false) or (options[:unread].present? and options[:unread]==true)
+ if (options.has_key?(:read) && options[:read]==false) || (options.has_key?(:unread) && options[:unread]==true)
conv = conv.unread(@messageable)
end
@@ -67,6 +67,12 @@
@entity2.mailbox.receipts.inbox[0].should==Receipt.recipient(@entity2).inbox.conversation(@conversation)[0]
@entity2.mailbox.receipts.inbox[1].should==Receipt.recipient(@entity2).inbox.conversation(@conversation)[1]
end
+
+ it "should understand the read option" do
+ @entity1.mailbox.inbox(read: false).count.should_not == 0
+ @conversation.mark_as_read(@entity1)
+ @entity1.mailbox.inbox(read: false).count.should == 0
+ end
it "should return trashed mails" do
@entity1.mailbox.receipts.move_to_trash

0 comments on commit dea5e3a

Please sign in to comment.