mailboxer 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -4,6 +4,7 @@ pkg/
4
4
  spec/dummy/db/*.sqlite3
5
5
  spec/dummy/log/*.log
6
6
  spec/dummy/tmp/
7
+ spec/dummy/.project
7
8
  **.tmp_*
8
9
  Gemfile.lock
9
10
  .idea
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.2.0
@@ -87,7 +87,7 @@ class Conversation < ActiveRecord::Base
87
87
 
88
88
  #Returns the receipts of the conversation for one participants
89
89
  def receipts_for(participant)
90
- return Receipt.conversation(self).receiver(participant)
90
+ return Receipt.conversation(self).receiver(participant)
91
91
  end
92
92
 
93
93
  #Returns the number of messages of the conversation
@@ -3,7 +3,7 @@ class Message < Notification
3
3
  belongs_to :conversation, :validate => true, :autosave => true
4
4
  validates_presence_of :sender
5
5
 
6
- class_inheritable_accessor :on_deliver_callback
6
+ class_attribute :on_deliver_callback
7
7
  protected :on_deliver_callback
8
8
  scope :conversation, lambda { |conversation|
9
9
  where(:conversation_id => conversation.id)
@@ -1,93 +1,109 @@
1
1
  class Receipt < ActiveRecord::Base
2
- belongs_to :notification, :validate => true, :autosave => true
3
- belongs_to :receiver, :polymorphic => :true
4
- belongs_to :message, :foreign_key => "notification_id"
5
-
6
- validates_presence_of :receiver
2
+ belongs_to :notification, :validate => true, :autosave => true
3
+ belongs_to :receiver, :polymorphic => :true
4
+ belongs_to :message, :foreign_key => "notification_id"
7
5
 
8
- scope :receiver, lambda { |receiver|
6
+ validates_presence_of :receiver
7
+
8
+ scope :receiver, lambda { |receiver|
9
9
  where(:receiver_id => receiver.id,:receiver_type => receiver.class.to_s)
10
10
  }
11
11
  #Notifications Scope checks type to be nil, not Notification because of STI behaviour
12
12
  #with the primary class (no type is saved)
13
13
  scope :notifications_receipts, joins(:notification).where('notifications.type' => nil)
14
14
  scope :messages_receipts, joins(:notification).where('notifications.type' => Message.to_s)
15
- scope :notification, lambda { |notification|
15
+ scope :notification, lambda { |notification|
16
16
  where(:notification_id => notification.id)
17
17
  }
18
- scope :conversation, lambda { |conversation|
19
- joins(:notification).where('notifications.conversation_id' => conversation.id)
18
+ scope :conversation, lambda { |conversation|
19
+ joins(:message).where('notifications.conversation_id' => conversation.id)
20
20
  }
21
- scope :sentbox, where(:mailbox_type => "sentbox")
22
- scope :inbox, where(:mailbox_type => "inbox")
23
- scope :trash, where(:trashed => true)
24
- scope :not_trash, where(:trashed => false)
25
- scope :read, where(:read => true)
26
- scope :unread, where(:read => false)
27
-
28
- after_validation :remove_duplicate_errors
29
- class << self
30
-
21
+ scope :sentbox, where(:mailbox_type => "sentbox")
22
+ scope :inbox, where(:mailbox_type => "inbox")
23
+ scope :trash, where(:trashed => true)
24
+ scope :not_trash, where(:trashed => false)
25
+ scope :read, where(:read => true)
26
+ scope :unread, where(:read => false)
27
+
28
+ after_validation :remove_duplicate_errors
29
+ class << self
31
30
  #Marks all the receipts from the relation as read
32
- def mark_as_read(options={})
33
- where(options).update_all(:read => true)
34
- end
31
+ def mark_as_read(options={})
32
+ update_receipts({:read => true}, options)
33
+ end
35
34
 
36
35
  #Marks all the receipts from the relation as unread
37
- def mark_as_unread(options={})
38
- where(options).update_all(:read => false)
39
- end
36
+ def mark_as_unread(options={})
37
+ update_receipts({:read => false}, options)
38
+ end
40
39
 
41
40
  #Marks all the receipts from the relation as trashed
42
- def move_to_trash(options={})
43
- where(options).update_all(:trashed => true)
44
- end
41
+ def move_to_trash(options={})
42
+ update_receipts({:trashed => true}, options)
43
+ end
45
44
 
46
45
  #Marks all the receipts from the relation as not trashed
47
- def untrash(options={})
48
- where(options).update_all(:trashed => false)
49
- end
46
+ def untrash(options={})
47
+ update_receipts({:trashed => false}, options)
48
+ end
50
49
 
51
50
  #Moves all the receipts from the relation to inbox
52
- def move_to_inbox(options={})
53
- where(options).update_all(:mailbox_type => :inbox, :trashed => false)
54
- end
51
+ def move_to_inbox(options={})
52
+ update_receipts({:mailbox_type => :inbox, :trashed => false}, options)
53
+ end
55
54
 
56
55
  #Moves all the receipts from the relation to sentbox
57
- def move_to_sentbox(options={})
58
- where(options).update_all(:mailbox_type => :sentbox, :trashed => false)
59
- end
60
- end
56
+ def move_to_sentbox(options={})
57
+ update_receipts({:mailbox_type => :sentbox, :trashed => false}, options)
58
+ end
59
+
60
+ #This methods helps to do a update_all with table joins, not currently supported by rails.
61
+ #Acording to the github ticket https://github.com/rails/rails/issues/522 it should be
62
+ #supported with 3.2.
63
+ def update_receipts(updates,options={})
64
+ ids = Array.new
65
+ where(options).each do |rcp|
66
+ ids << rcp.id
67
+ end
68
+ temp_ids = ids.clone
69
+ condition = "id = ? "
70
+ temp_ids.drop(1).each do
71
+ condition << "OR id = ? "
72
+ end
73
+ conditions = [condition].concat(ids)
74
+ Receipt.except(:where).except(:joins).where(conditions).update_all(updates)
75
+ end
76
+ end
61
77
 
62
78
  #Marks the receipt as read
63
- def mark_as_read
64
- update_attributes(:read => true)
65
- end
79
+ def mark_as_read
80
+ update_attributes(:read => true)
81
+ end
66
82
 
67
83
  #Marks the receipt as unread
68
- def mark_as_unread
69
- update_attributes(:read => false)
70
- end
84
+ def mark_as_unread
85
+ update_attributes(:read => false)
86
+ end
71
87
 
72
88
  #Marks the receipt as trashed
73
- def move_to_trash
74
- update_attributes(:trashed => true)
75
- end
89
+ def move_to_trash
90
+ update_attributes(:trashed => true)
91
+ end
76
92
 
77
93
  #Marks the receipt as not trashed
78
- def untrash
79
- update_attributes(:trashed => false)
80
- end
94
+ def untrash
95
+ update_attributes(:trashed => false)
96
+ end
81
97
 
82
98
  #Moves the receipt to inbox
83
- def move_to_inbox
84
- update_attributes(:mailbox_type => :inbox, :trashed => false)
85
- end
99
+ def move_to_inbox
100
+ update_attributes(:mailbox_type => :inbox, :trashed => false)
101
+ end
86
102
 
87
103
  #Moves the receipt to sentbox
88
- def move_to_sentbox
89
- update_attributes(:mailbox_type => :sentbox, :trashed => false)
90
- end
104
+ def move_to_sentbox
105
+ update_attributes(:mailbox_type => :sentbox, :trashed => false)
106
+ end
91
107
 
92
108
  #Returns the conversation associated to the receipt if the notification is a Message
93
109
  def conversation
@@ -95,16 +111,16 @@ class Receipt < ActiveRecord::Base
95
111
  return nil
96
112
  end
97
113
 
98
- protected
114
+ protected
99
115
 
100
116
  #Removes the duplicate error about not present subject from Conversation if it has been already
101
117
  #raised by Message
102
- def remove_duplicate_errors
103
- if self.errors["notification.conversation.subject"].present? and self.errors["notification.subject"].present?
104
- self.errors["notification.conversation.subject"].each do |msg|
105
- self.errors["notification.conversation.subject"].delete(msg)
106
- end
107
- end
108
- end
118
+ def remove_duplicate_errors
119
+ if self.errors["notification.conversation.subject"].present? and self.errors["notification.subject"].present?
120
+ self.errors["notification.conversation.subject"].each do |msg|
121
+ self.errors["notification.conversation.subject"].delete(msg)
122
+ end
123
+ end
124
+ end
109
125
 
110
126
  end
@@ -20,21 +20,21 @@ module Mailboxer
20
20
  #Returning any kind of indentification you want for the model
21
21
  def name
22
22
  super
23
- rescue
23
+ rescue NameError
24
24
  return "You should add method :name in your Messageable model"
25
25
  end
26
26
 
27
27
  #Returning the email address of the model
28
28
  def email
29
29
  super
30
- rescue
30
+ rescue NameError
31
31
  return "define_email@on_your.model"
32
32
  end
33
33
 
34
34
  #Returning whether an email should be sent for this object (Message or Notification)
35
35
  def should_email?(object)
36
36
  super
37
- rescue
37
+ rescue NameError
38
38
  return true
39
39
  end
40
40
 
data/mailboxer.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "mailboxer"
3
- s.version = "0.1.4"
3
+ s.version = "0.2.0"
4
4
  s.authors = ["Eduardo Casanova Cuesta"]
5
5
  s.summary = "Messaging system for rails apps."
6
6
  s.description = "A Rails engine that allows any model to act as messageable, permitting it interchange messages with any other messageable model." +
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
 
17
17
  # Development Gem dependencies
18
18
  #
19
- s.add_development_dependency('rails', '~> 3.0.5')
19
+ s.add_runtime_dependency('rails', '3.1.0.rc4')
20
20
  # Testing database
21
21
  s.add_development_dependency('sqlite3-ruby')
22
22
  # Debugging
@@ -24,13 +24,12 @@ Gem::Specification.new do |s|
24
24
  s.add_development_dependency('ruby-debug', '~> 0.10.3')
25
25
  end
26
26
  # Specs
27
- s.add_development_dependency('rspec-rails', '~> 2.5.0')
27
+ s.add_development_dependency('rspec-rails', '~> 2.6.1')
28
28
  # Fixtures
29
29
  s.add_development_dependency('factory_girl', '~> 1.3.2')
30
30
  # Population
31
31
  s.add_development_dependency('forgery', '~> 0.3.6')
32
32
  # Integration testing
33
33
  s.add_development_dependency('capybara', '~> 0.3.9')
34
-
35
34
  end
36
35
 
@@ -37,4 +37,13 @@ describe Conversation do
37
37
  @conversation.recipients.count(@entity2).should==1
38
38
  end
39
39
 
40
+ it "should be able to be marked as read" do
41
+ @conversation.move_to_trash(@entity1)
42
+ end
43
+
44
+ it "should be able to be marked as unread" do
45
+ @conversation.move_to_trash(@entity1)
46
+ @conversation.untrash(@entity1)
47
+ end
48
+
40
49
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailboxer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 4
10
- version: 0.1.4
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Eduardo Casanova Cuesta
@@ -15,10 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-11 00:00:00 +02:00
18
+ date: 2011-06-23 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
+ prerelease: false
22
23
  requirement: &id001 !ruby/object:Gem::Requirement
23
24
  none: false
24
25
  requirements:
@@ -32,25 +33,27 @@ dependencies:
32
33
  version: 0.9.1
33
34
  type: :runtime
34
35
  name: foreigner
35
- prerelease: false
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
38
+ prerelease: false
38
39
  requirement: &id002 !ruby/object:Gem::Requirement
39
40
  none: false
40
41
  requirements:
41
- - - ~>
42
+ - - "="
42
43
  - !ruby/object:Gem::Version
43
- hash: 13
44
+ hash: 15424109
44
45
  segments:
45
46
  - 3
47
+ - 1
46
48
  - 0
47
- - 5
48
- version: 3.0.5
49
- type: :development
49
+ - rc
50
+ - 4
51
+ version: 3.1.0.rc4
52
+ type: :runtime
50
53
  name: rails
51
- prerelease: false
52
54
  version_requirements: *id002
53
55
  - !ruby/object:Gem::Dependency
56
+ prerelease: false
54
57
  requirement: &id003 !ruby/object:Gem::Requirement
55
58
  none: false
56
59
  requirements:
@@ -62,9 +65,9 @@ dependencies:
62
65
  version: "0"
63
66
  type: :development
64
67
  name: sqlite3-ruby
65
- prerelease: false
66
68
  version_requirements: *id003
67
69
  - !ruby/object:Gem::Dependency
70
+ prerelease: false
68
71
  requirement: &id004 !ruby/object:Gem::Requirement
69
72
  none: false
70
73
  requirements:
@@ -78,25 +81,25 @@ dependencies:
78
81
  version: 0.10.3
79
82
  type: :development
80
83
  name: ruby-debug
81
- prerelease: false
82
84
  version_requirements: *id004
83
85
  - !ruby/object:Gem::Dependency
86
+ prerelease: false
84
87
  requirement: &id005 !ruby/object:Gem::Requirement
85
88
  none: false
86
89
  requirements:
87
90
  - - ~>
88
91
  - !ruby/object:Gem::Version
89
- hash: 27
92
+ hash: 21
90
93
  segments:
91
94
  - 2
92
- - 5
93
- - 0
94
- version: 2.5.0
95
+ - 6
96
+ - 1
97
+ version: 2.6.1
95
98
  type: :development
96
99
  name: rspec-rails
97
- prerelease: false
98
100
  version_requirements: *id005
99
101
  - !ruby/object:Gem::Dependency
102
+ prerelease: false
100
103
  requirement: &id006 !ruby/object:Gem::Requirement
101
104
  none: false
102
105
  requirements:
@@ -110,9 +113,9 @@ dependencies:
110
113
  version: 1.3.2
111
114
  type: :development
112
115
  name: factory_girl
113
- prerelease: false
114
116
  version_requirements: *id006
115
117
  - !ruby/object:Gem::Dependency
118
+ prerelease: false
116
119
  requirement: &id007 !ruby/object:Gem::Requirement
117
120
  none: false
118
121
  requirements:
@@ -126,9 +129,9 @@ dependencies:
126
129
  version: 0.3.6
127
130
  type: :development
128
131
  name: forgery
129
- prerelease: false
130
132
  version_requirements: *id007
131
133
  - !ruby/object:Gem::Dependency
134
+ prerelease: false
132
135
  requirement: &id008 !ruby/object:Gem::Requirement
133
136
  none: false
134
137
  requirements:
@@ -142,7 +145,6 @@ dependencies:
142
145
  version: 0.3.9
143
146
  type: :development
144
147
  name: capybara
145
- prerelease: false
146
148
  version_requirements: *id008
147
149
  description: A Rails engine that allows any model to act as messageable, permitting it interchange messages with any other messageable model.It also supports sending system notifications to messageable models.
148
150
  email: ecasanovac@gmail.com
@@ -181,7 +183,6 @@ files:
181
183
  - lib/mailboxer/exceptions.rb
182
184
  - lib/mailboxer/models/messageable.rb
183
185
  - mailboxer.gemspec
184
- - spec/dummy/.project
185
186
  - spec/dummy/Gemfile
186
187
  - spec/dummy/Gemfile.lock
187
188
  - spec/dummy/Rakefile
@@ -270,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
271
  requirements: []
271
272
 
272
273
  rubyforge_project:
273
- rubygems_version: 1.3.7
274
+ rubygems_version: 1.6.2
274
275
  signing_key:
275
276
  specification_version: 3
276
277
  summary: Messaging system for rails apps.