Skip to content
This repository
Browse code

add `#is_read?` predicates to match `#is_unread?`

The symmetry of the postive assertion has nice expressiveness
  • Loading branch information...
commit 1344baf2f6dda9b4c070a2a36c89d449373b20bb 1 parent 3e1b0d1
authored June 14, 2012
4  app/models/conversation.rb
@@ -118,6 +118,10 @@ def is_completely_trashed?(participant)
118 118
 		return self.receipts_for(participant).trash.count == self.receipts_for(participant).count
119 119
 	end
120 120
 
  121
+	def is_read?(participant)
  122
+		!self.is_unread?(participant)
  123
+	end
  124
+
121 125
   #Returns true if the participant has at least one unread message of the conversation
122 126
 	def is_unread?(participant)
123 127
 		return false if participant.nil?
4  app/models/notification.rb
@@ -108,6 +108,10 @@ def is_unread?(participant)
108 108
     return !self.receipt_for(participant).first.read
109 109
   end
110 110
 
  111
+  def is_read?(participant)
  112
+    !self.is_unread?(participant)
  113
+  end
  114
+
111 115
   #Returns if the participant have trashed the Notification
112 116
   def is_trashed?(participant)
113 117
     return false if participant.nil?
9  spec/models/conversation_spec.rb
@@ -38,12 +38,15 @@
38 38
   end
39 39
 
40 40
   it "should be able to be marked as read" do
41  
-    @conversation.move_to_trash(@entity1)
  41
+    #@conversation.move_to_trash(@entity1)
  42
+    @conversation.mark_as_read(@entity1)
  43
+    @conversation.should be_is_read(@entity)
42 44
   end
43 45
 
44 46
   it "should be able to be marked as unread" do
45  
-    @conversation.move_to_trash(@entity1)
46  
-    @conversation.untrash(@entity1)
  47
+    @conversation.mark_as_read(@entity1)
  48
+    @conversation.mark_as_unread(@entity1)
  49
+    @conversation.should be_is_unread(@entity1)
47 50
   end
48 51
 
49 52
   describe "scopes" do
15  spec/models/notification_spec.rb
@@ -24,6 +24,21 @@
24 24
     notification.subject.should=="Subject"
25 25
     notification.body.should=="Body"       
26 26
   end
  27
+
  28
+  it "should be unread by default" do
  29
+    @entity1.notify("Subject", "Body")
  30
+    @entity1.mailbox.receipts.size.should==1
  31
+    notification = @entity1.mailbox.receipts.first.notification
  32
+    notification.should be_is_unread(@entity1)
  33
+  end
  34
+
  35
+  it "should be able to marked as read" do
  36
+    @entity1.notify("Subject", "Body")
  37
+    @entity1.mailbox.receipts.size.should==1
  38
+    notification = @entity1.mailbox.receipts.first.notification
  39
+    notification.mark_as_read(@entity1)
  40
+    notification.should be_is_read(@entity1)
  41
+  end
27 42
   
28 43
   it "should notify several users" do
29 44
     Notification.notify_all([@entity1,@entity2,@entity3],"Subject","Body")

0 notes on commit 1344baf

Please sign in to comment.
Something went wrong with that request. Please try again.