acts-as-messageable 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,8 +1,11 @@
1
1
  rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
- - rbx
4
+ - 1.9.3
5
+ - ruby-head
5
6
  - ree
7
+ - rbx-head
8
+ - rbx-head-d19
6
9
  gemfile:
7
10
  - Gemfile
8
11
  - gemfiles/Gemfile-3.0
data/Gemfile CHANGED
@@ -2,11 +2,11 @@ source "http://rubygems.org"
2
2
 
3
3
  gem "activerecord", ">= 3.0.0"
4
4
  gem "activesupport", ">= 3.0.0"
5
- gem "ancestry", "~> 1.2.4"
5
+ gem "ancestry", "~> 1.3.0"
6
6
  gem "railties", ">= 3.0.0"
7
7
 
8
8
  group :development do
9
- gem "rspec", "~> 2.8.0"
10
- gem "jeweler", "~> 1.7.0"
11
- gem "sqlite3-ruby"
9
+ gem "rspec", "~> 2.11.0"
10
+ gem "jeweler", "~> 1.8.0"
11
+ gem "sqlite3"
12
12
  end
data/README.md CHANGED
@@ -41,7 +41,8 @@ Usage
41
41
  class User < ActiveRecord::Base
42
42
  acts_as_messageable :table_name => "table_with_messages", # default 'messages'
43
43
  :required => :body # default [:topic, :body]
44
- :class_name => "CustomMessages" # default "ActsAsMessageable::Message"
44
+ :class_name => "CustomMessages" # default "ActsAsMessageable::Message",
45
+ :dependent => :destroy # default :nullify
45
46
  end
46
47
  ```
47
48
 
@@ -246,4 +247,19 @@ Message has been deleted **permanently**
246
247
  @alice.delete_message(@message) # @alice delete @message
247
248
  ```
248
249
 
250
+ Restore message
251
+ ===============
252
+
253
+ ```ruby
254
+ @alice.deleted_messages.process do |m|
255
+ m.restore # @alice restore 'm' message from trash
256
+ end
257
+ ```
258
+
259
+ ## Restore message without context
260
+
261
+ ```ruby
262
+ @alice.restore_message(@message) # @alice restore message from trash
263
+ ```
264
+
249
265
  Copyright © 2011 Piotr Niełacny (http://ruby-blog.pl), released under the MIT license
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.5
1
+ 0.4.6
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "acts-as-messageable"
8
- s.version = "0.4.5"
8
+ s.version = "0.4.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Piotr Nielacny"]
12
- s.date = "2012-02-08"
12
+ s.date = "2012-09-27"
13
13
  s.email = "piotr.nielacny@gmail.com"
14
14
  s.extra_rdoc_files = [
15
15
  "README.md"
@@ -27,18 +27,16 @@ Gem::Specification.new do |s|
27
27
  "gemfiles/Gemfile-3.1",
28
28
  "gemfiles/Gemfile-3.2",
29
29
  "lib/acts-as-messageable.rb",
30
- "lib/acts-as-messageable/acts-as-messageable.rb",
31
30
  "lib/acts-as-messageable/message.rb",
32
31
  "lib/acts-as-messageable/model.rb",
32
+ "lib/acts-as-messageable/railtie.rb",
33
33
  "lib/acts-as-messageable/relation.rb",
34
34
  "lib/generators/acts-as-messageable/migration/migration_generator.rb",
35
35
  "lib/generators/acts-as-messageable/migration/templates/migration.rb",
36
36
  "lib/generators/acts-as-messageable/migration/templates/migration_permanent.rb",
37
- "rails/init.rb",
38
37
  "spec/acts-as-messageable_spec.rb",
39
38
  "spec/custom-class_spec.rb",
40
39
  "spec/custom-required_spec.rb",
41
- "spec/inheritance_spec.rb",
42
40
  "spec/spec_helper.rb",
43
41
  "spec/support/admin.rb",
44
42
  "spec/support/send_message.rb",
@@ -46,7 +44,7 @@ Gem::Specification.new do |s|
46
44
  ]
47
45
  s.homepage = "http://github.com/LTe/acts-as-messageable"
48
46
  s.require_paths = ["lib"]
49
- s.rubygems_version = "1.8.15"
47
+ s.rubygems_version = "1.8.24"
50
48
  s.summary = "Make user messageable!;-)"
51
49
 
52
50
  if s.respond_to? :specification_version then
@@ -55,28 +53,28 @@ Gem::Specification.new do |s|
55
53
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
54
  s.add_runtime_dependency(%q<activerecord>, [">= 3.0.0"])
57
55
  s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0"])
58
- s.add_runtime_dependency(%q<ancestry>, ["~> 1.2.4"])
56
+ s.add_runtime_dependency(%q<ancestry>, ["~> 1.3.0"])
59
57
  s.add_runtime_dependency(%q<railties>, [">= 3.0.0"])
60
- s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
61
- s.add_development_dependency(%q<jeweler>, ["~> 1.7.0"])
62
- s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
58
+ s.add_development_dependency(%q<rspec>, ["~> 2.11.0"])
59
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.0"])
60
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
63
61
  else
64
62
  s.add_dependency(%q<activerecord>, [">= 3.0.0"])
65
63
  s.add_dependency(%q<activesupport>, [">= 3.0.0"])
66
- s.add_dependency(%q<ancestry>, ["~> 1.2.4"])
64
+ s.add_dependency(%q<ancestry>, ["~> 1.3.0"])
67
65
  s.add_dependency(%q<railties>, [">= 3.0.0"])
68
- s.add_dependency(%q<rspec>, ["~> 2.8.0"])
69
- s.add_dependency(%q<jeweler>, ["~> 1.7.0"])
70
- s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
66
+ s.add_dependency(%q<rspec>, ["~> 2.11.0"])
67
+ s.add_dependency(%q<jeweler>, ["~> 1.8.0"])
68
+ s.add_dependency(%q<sqlite3>, [">= 0"])
71
69
  end
72
70
  else
73
71
  s.add_dependency(%q<activerecord>, [">= 3.0.0"])
74
72
  s.add_dependency(%q<activesupport>, [">= 3.0.0"])
75
- s.add_dependency(%q<ancestry>, ["~> 1.2.4"])
73
+ s.add_dependency(%q<ancestry>, ["~> 1.3.0"])
76
74
  s.add_dependency(%q<railties>, [">= 3.0.0"])
77
- s.add_dependency(%q<rspec>, ["~> 2.8.0"])
78
- s.add_dependency(%q<jeweler>, ["~> 1.7.0"])
79
- s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
75
+ s.add_dependency(%q<rspec>, ["~> 2.11.0"])
76
+ s.add_dependency(%q<jeweler>, ["~> 1.8.0"])
77
+ s.add_dependency(%q<sqlite3>, [">= 0"])
80
78
  end
81
79
  end
82
80
 
@@ -4,4 +4,4 @@ module ActsAsMessageable
4
4
  autoload :Relation, 'acts-as-messageable/relation'
5
5
  end
6
6
 
7
- require 'acts-as-messageable/acts-as-messageable'
7
+ require 'acts-as-messageable/railtie'
@@ -21,7 +21,7 @@ module ActsAsMessageable
21
21
  :created_at,
22
22
  :updated_at
23
23
 
24
- attr_accessor :removed
24
+ attr_accessor :removed, :restored
25
25
  cattr_accessor :required
26
26
 
27
27
 
@@ -29,7 +29,10 @@ module ActsAsMessageable
29
29
  default_scope order("created_at desc")
30
30
  scope :are_from, lambda { |*args| where(:sent_messageable_id => args.first, :sent_messageable_type => args.first.class.name) }
31
31
  scope :are_to, lambda { |*args| where(:received_messageable_id => args.first, :received_messageable_type => args.first.class.name) }
32
- scope :with_id, lambda { |*args| where(:id => args.first) }
32
+ scope :with_id, lambda { |*args|
33
+ ActiveSupport::Deprecation.warn("Calling with_id is deprecated. Please use `find` instead.")
34
+ where(:id => args.first)
35
+ }
33
36
 
34
37
  scope :connected_with, lambda { |*args| where("(sent_messageable_type = :sent_type and
35
38
  sent_messageable_id = :sent_id and
@@ -47,7 +50,7 @@ module ActsAsMessageable
47
50
  :s_perm_delete => false)
48
51
  }
49
52
  scope :readed, lambda { where(:opened => true) }
50
- scope :unread, lambda { where(:opened => false) }
53
+ scope :unreaded, lambda { where(:opened => false) }
51
54
  scope :deleted, lambda { where(:recipient_delete => true, :sender_delete => true) }
52
55
 
53
56
  def open?
@@ -57,26 +60,17 @@ module ActsAsMessageable
57
60
  def open
58
61
  update_attributes!(:opened => true)
59
62
  end
60
-
61
- def mark_as_read
62
- open
63
- end
63
+ alias :mark_as_read :open
64
+ alias :read :open
64
65
 
65
66
  def close
66
67
  update_attributes!(:opened => false)
67
68
  end
69
+ alias :mark_as_unread :close
70
+ alias :unread :close
68
71
 
69
- def mark_as_unread
70
- close
71
- end
72
-
73
- def from
74
- sent_messageable
75
- end
76
-
77
- def to
78
- received_messageable
79
- end
72
+ alias :from :sent_messageable
73
+ alias :to :received_messageable
80
74
 
81
75
  def participant?(user)
82
76
  (to == user) || (from == user)
@@ -89,7 +83,11 @@ module ActsAsMessageable
89
83
  def delete
90
84
  self.removed = true
91
85
  end
92
-
86
+
87
+ def restore
88
+ self.restored = true
89
+ end
90
+
93
91
  def reply(*args)
94
92
  to.reply_to(self, *args)
95
93
  end
@@ -10,15 +10,18 @@ module ActsAsMessageable
10
10
 
11
11
  # Method make ActiveRecord::Base object messageable
12
12
  # @param [Symbol] :table_name - table name for messages
13
+ # @param [String] :class_name - message class name
14
+ # @param [Array, Symbol] :required - required fields in message
15
+ # @param [Symbol] :dependent - dependent option from ActiveRecord has_many method
13
16
  def acts_as_messageable(options = {})
14
17
  has_many :received_messages_relation,
15
18
  :as => :received_messageable,
16
19
  :class_name => options[:class_name] || "ActsAsMessageable::Message",
17
- :dependent => :nullify
20
+ :dependent => options[:dependent] || :nullify
18
21
  has_many :sent_messages_relation,
19
22
  :as => :sent_messageable,
20
23
  :class_name => options[:class_name] || "ActsAsMessageable::Message",
21
- :dependent => :nullify
24
+ :dependent => options[:dependent] || :nullify
22
25
 
23
26
  self.messages_class_name = (options[:class_name] || "ActsAsMessageable::Message").constantize
24
27
 
@@ -29,18 +32,14 @@ module ActsAsMessageable
29
32
  ActiveSupport::Deprecation.warn("Calling set_table_name is deprecated. Please use `self.table_name = 'the_name'` instead.")
30
33
  end
31
34
 
32
- if options[:required].is_a? Symbol
33
- self.messages_class_name.required = [options[:required]]
34
- elsif options[:required].is_a? Array
35
- self.messages_class_name.required = options[:required]
36
- else
37
- self.messages_class_name.required = [:topic, :body]
38
- end
39
-
35
+ self.messages_class_name.required = Array.wrap(options[:required] || [:topic, :body])
40
36
  self.messages_class_name.validates_presence_of self.messages_class_name.required
37
+
41
38
  include ActsAsMessageable::Model::InstanceMethods
42
39
  end
43
40
 
41
+ # Method recognize real object class
42
+ # @return [ActiveRecord::Base] class or relation object
44
43
  def resolve_active_record_ancestor
45
44
  self.reflect_on_association(:received_messages_relation).active_record
46
45
  end
@@ -48,7 +47,6 @@ module ActsAsMessageable
48
47
  end
49
48
 
50
49
  module InstanceMethods
51
- # Get all messages connected with user
52
50
  # @return [ActiveRecord::Relation] all messages connected with user
53
51
  def messages(trash = false)
54
52
  result = self.class.messages_class_name.connected_with(self, trash)
@@ -57,6 +55,7 @@ module ActsAsMessageable
57
55
  result
58
56
  end
59
57
 
58
+ # @return [ActiveRecord::Relation] returns all messages from inbox
60
59
  def received_messages
61
60
  result = received_messages_relation.scoped.where(:recipient_delete => false)
62
61
  result.relation_context = self
@@ -64,6 +63,7 @@ module ActsAsMessageable
64
63
  result
65
64
  end
66
65
 
66
+ # @return [ActiveRecord::Relation] returns all messages from outbox
67
67
  def sent_messages
68
68
  result = sent_messages_relation.scoped.where(:sender_delete => false)
69
69
  result.relation_context = self
@@ -71,6 +71,7 @@ module ActsAsMessageable
71
71
  result
72
72
  end
73
73
 
74
+ # @return [ActiveRecord::Relation] returns all messages from trash
74
75
  def deleted_messages
75
76
  messages true
76
77
  end
@@ -82,9 +83,10 @@ module ActsAsMessageable
82
83
  #
83
84
  # @return [ActsAsMessageable::Message] the message object
84
85
  def send_message(to, *args)
86
+ message_attributes = {}
87
+
85
88
  case args.first
86
89
  when String
87
- message_attributes = {}
88
90
  self.class.messages_class_name.required.each_with_index do |attribute, index|
89
91
  message_attributes[attribute] = args[index]
90
92
  end
@@ -100,10 +102,16 @@ module ActsAsMessageable
100
102
  message
101
103
  end
102
104
 
105
+ # Reply to given message
106
+ # @param [ActsAsMessageable::Message] message
107
+ # @param [String] topic
108
+ # @param [String] body
109
+ #
110
+ # @return [ActsAsMessageable::Message] a message that is a response to a given message
103
111
  def reply_to(message, *args)
104
112
  current_user = self
105
-
106
- if message.participant?(current_user)
113
+
114
+ if message.participant?(current_user)
107
115
  reply_message = send_message(message.from, *args)
108
116
  reply_message.parent = message
109
117
  reply_message.save
@@ -112,25 +120,37 @@ module ActsAsMessageable
112
120
  end
113
121
  end
114
122
 
123
+ # Mark message as deleted
115
124
  def delete_message(message)
116
125
  current_user = self
117
126
 
118
- if message.received_messageable == current_user
119
- unless message.recipient_delete
120
- message.update_attributes!(:recipient_delete => true)
127
+ case current_user
128
+ when message.to
129
+ attribute = message.recipient_delete ? :recipient_permanent_delete : :recipient_delete
130
+ when message.from
131
+ attribute = message.sender_delete ? :sender_permanent_delete : :sender_delete
121
132
  else
122
- message.update_attributes!(:recipient_permanent_delete => true)
123
- end
124
- elsif message.sent_messageable == current_user
125
- unless message.sender_delete
126
- message.update_attributes!(:sender_delete => true)
127
- else
128
- message.update_attributes!(:sender_permanent_delete => true)
129
- end
133
+ raise "#{current_user} can't delete this message"
130
134
  end
135
+
136
+ message.update_attributes!(attribute => true)
131
137
  end
132
138
 
133
- end
139
+ # Mark message as restored
140
+ def restore_message(message)
141
+ current_user = self
134
142
 
143
+ case current_user
144
+ when message.to
145
+ attribute = :recipient_delete
146
+ when message.from
147
+ attribute = :sender_delete
148
+ else
149
+ raise "#{current_user} can't delete this message"
150
+ end
151
+
152
+ message.update_attributes!(attribute => false)
153
+ end
154
+ end
135
155
  end
136
156
  end
@@ -5,8 +5,9 @@ module ActsAsMessageable
5
5
  def process(context = self.relation_context, &block)
6
6
  self.each do |message|
7
7
  block.call(message) if block_given?
8
- context.delete_message(message) if message.removed
8
+ context.delete_message(message) if message.removed
9
+ context.restore_message(message) if message.restored
9
10
  end
10
11
  end
11
12
  end
12
- end
13
+ end
@@ -1,76 +1,80 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- class User < ActiveRecord::Base
4
- acts_as_messageable
5
- end
1
+ require 'spec_helper'
6
2
 
7
3
  describe "ActsAsMessageable" do
8
-
9
- before(:all) do
4
+ before do
10
5
  User.acts_as_messageable
11
- end
12
-
13
- describe "prepare for specs" do
14
- it "should be 4 users in database" do
15
- User.count.should == 4
16
- end
6
+ @message = send_message
17
7
  end
18
8
 
19
9
  describe "send messages" do
20
10
  it "alice should have one message" do
21
- send_message
22
11
  @alice.messages.count.should == 1
23
12
  end
24
13
 
25
14
  it "alice should have one message from bob" do
26
- send_message
27
15
  @alice.messages.are_from(@bob).count.should == 1
28
16
  end
29
17
 
30
18
  it "bob should have one message" do
31
- send_message
32
19
  @bob.messages.count.should == 1
33
20
  end
34
21
 
35
22
  it "bob should have one message to alice in outbox" do
36
- send_message
37
23
  @bob.sent_messages.are_to(@alice).count.should == 1
38
24
  end
39
25
 
40
26
  it "bob should have one open message from alice" do
41
- send_message
42
27
  @alice.messages.are_from(@bob).process { |m| m.open }
43
28
  @alice.messages.readed.count.should == 1
44
29
  end
45
30
  end
46
-
31
+
32
+ describe "inheritance models" do
33
+ it "men send message to alice" do
34
+ send_message(@men, @alice)
35
+ @men.sent_messages.size.should be_equal(1)
36
+ @alice.received_messages.size.should be_equal(2)
37
+ end
38
+
39
+ it "messages method should receive all messages connected with user" do
40
+ send_message(@men, @alice)
41
+ @men.messages.size.should be_equal(1)
42
+ end
43
+
44
+ it "men send message and receive from alice" do
45
+ send_message(@men, @alice)
46
+ send_message(@alice, @men)
47
+
48
+ @men.messages.size.should be_equal(2)
49
+ @men.sent_messages.size.should be_equal(1)
50
+ @men.received_messages.size.should be_equal(1)
51
+ end
52
+ end
53
+
47
54
  describe "reply to messages" do
48
55
  it "pat should not be able to reply to a message from bob to alice" do
49
- @message = send_message
50
56
  @reply_message = @pat.reply_to(@message, "Re: Topic", "Body")
51
57
  @reply_message.should be_nil
52
58
  end
53
-
59
+
54
60
  it "alice should be able to reply to a message from bob to alice" do
55
- @message = send_message
56
61
  @reply_message = @alice.reply_to(@message, "Re: Topic", "Body")
57
62
  @reply_message.should_not be_nil
58
- @bob.messages.are_from(@alice).count.should == 1
59
- @alice.sent_messages.are_to(@bob).count.should == 1
60
- end
63
+ @bob.messages.are_from(@alice).count.should == 1
64
+ @alice.sent_messages.are_to(@bob).count.should == 1
65
+ end
61
66
 
62
67
  it "alice should be able to reply to a message using the message object" do
63
- @message = send_message
64
68
  @reply_message = @message.reply("Re: Topic", "Body")
65
- @reply_message.should_not be_nil
66
- @bob.messages.are_from(@alice).count.should == 1
67
- @alice.sent_messages.are_to(@bob).count.should == 1
69
+ @reply_message.should_not be_nil
70
+ @bob.messages.are_from(@alice).count.should == 1
71
+ @alice.sent_messages.are_to(@bob).count.should == 1
68
72
  end
69
73
  end
70
74
 
71
75
  describe "delete messages" do
76
+
72
77
  it "bob should have one deleted message from alice" do
73
- send_message
74
78
  @bob.messages.process do |m|
75
79
  m.delete
76
80
  end
@@ -85,8 +89,6 @@ describe "ActsAsMessageable" do
85
89
  end
86
90
 
87
91
  it "received_messages and sent_messages should work with .process method" do
88
- @message = send_message
89
-
90
92
  @bob.sent_messages.count.should == 1
91
93
  @alice.received_messages.count.should == 1
92
94
 
@@ -99,7 +101,6 @@ describe "ActsAsMessageable" do
99
101
  end
100
102
 
101
103
  it "message should permanent delete" do
102
- @message = send_message
103
104
  @alice.messages.process { |m| m.delete }
104
105
  @alice.messages.count.should == 0
105
106
 
@@ -112,14 +113,47 @@ describe "ActsAsMessageable" do
112
113
 
113
114
  @bob.sent_messages.count.should == 1
114
115
  end
116
+
117
+ it "pat should not able to delete message" do
118
+ lambda { @pat.delete_message(@message) }.should raise_error
119
+ end
120
+ end
121
+
122
+ describe "restore message" do
123
+ it "alice should restore message" do
124
+ @alice.received_messages.process { |m| m.delete }
125
+ @alice.restore_message(@message.reload)
126
+ @alice.received_messages.count.should == 1
127
+ end
128
+
129
+ it "should works with relation" do
130
+ @alice.received_messages.process { |m| m.delete }
131
+ @alice.received_messages.count.should == 0
132
+ @alice.deleted_messages.process { |m| m.restore }
133
+ @alice.received_messages.count.should == 1
134
+ end
135
+
136
+ it "pat should not able to restore message" do
137
+ lambda { @pat.restore_message(@message) }.should raise_error
138
+ end
115
139
  end
116
140
 
117
141
  describe "read/unread feature" do
118
142
  it "alice should have one unread message from bob" do
119
- send_message
120
- @alice.messages.are_from(@bob).unread.count.should == 1
143
+ @alice.messages.are_from(@bob).unreaded.count.should == 1
121
144
  @alice.messages.are_from(@bob).readed.count.should == 0
122
145
  end
146
+
147
+ it "alice should able to read message from bob" do
148
+ @alice.messages.are_from(@bob).first.read
149
+ @alice.messages.are_from(@bob).unreaded.count.should == 0
150
+ end
151
+
152
+ it "alice should able to unread message from bob" do
153
+ @alice.messages.are_from(@bob).first.read
154
+ @alice.messages.are_from(@bob).first.unread
155
+ @alice.messages.are_from(@bob).unreaded.count.should == 1
156
+ end
123
157
  end
124
158
 
125
159
  it "should be in database message with id ..." do
@@ -127,15 +161,17 @@ describe "ActsAsMessageable" do
127
161
  @bob.messages.with_id(message_id).count.should == 1
128
162
  end
129
163
 
164
+ it "finds proper message" do
165
+ @bob.messages.find(@message.id) == @message
166
+ end
167
+
130
168
  it "message should have proper topic" do
131
- send_message
132
169
  @bob.messages.count.should == 1
133
170
  @bob.messages.first.topic == "Topic"
134
171
  end
135
172
 
136
173
  describe "conversation" do
137
174
  it "bob send message to alice, and alice reply to bob message and show proper tree" do
138
- @message = send_message
139
175
  @reply_message = @alice.reply_to(@message, "Re: Topic", "Body")
140
176
 
141
177
  @reply_message.conversation.size.should == 2
@@ -144,7 +180,6 @@ describe "ActsAsMessageable" do
144
180
  end
145
181
 
146
182
  it "bob send message to alice, alice answer, and bob answer for alice answer" do
147
- @message = send_message
148
183
  @reply_message = @alice.reply_to(@message, "Re: Topic", "Body")
149
184
  @reply_reply_message = @bob.reply_to(@reply_message, "Re: Re: Topic", "Body")
150
185
 
@@ -166,18 +201,15 @@ describe "ActsAsMessageable" do
166
201
  end
167
202
 
168
203
  it "messages should return in right order :created_at" do
169
- @message = send_message
170
204
  @message = send_message(@bob, @alice, "Example", "Example Body")
171
205
  @alice.messages.last.body.should == "Body"
172
206
  end
173
207
 
174
208
  it "received_messages should return ActiveRecord::Relation" do
175
- send_message
176
209
  @alice.received_messages.class.should == ActiveRecord::Relation
177
210
  end
178
211
 
179
212
  it "sent_messages should return ActiveRecord::Relation" do
180
- send_message
181
213
  @bob.sent_messages.class.should == ActiveRecord::Relation
182
214
  end
183
215
 
@@ -188,7 +220,7 @@ describe "ActsAsMessageable" do
188
220
 
189
221
  it "bob send message to admin (different model) with the same id" do
190
222
  @bob.send_message(@alice, "hello", "alice")
191
- @alice.messages.are_to(@alice).size.should be_equal(1)
223
+ @alice.messages.are_to(@alice).size.should be_equal(2)
192
224
  @alice.messages.are_to(@admin).size.should be_equal(0)
193
225
  end
194
226
 
@@ -197,7 +229,6 @@ describe "ActsAsMessageable" do
197
229
  @bob.messages.are_from(@admin).size.should be_equal(1)
198
230
  @bob.messages.are_from(@alice).size.should be_equal(0)
199
231
  end
200
-
201
232
  end
202
233
 
203
234
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require "spec_helper"
2
2
 
3
3
  class CustomMessage < ActsAsMessageable::Message; end
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require 'spec_helper'
2
2
 
3
3
  describe "custom require" do
4
4
  before(:each) do
@@ -47,5 +47,4 @@ describe "custom require" do
47
47
  @alice.received_messages.first.body.should == "Hi Alice!"
48
48
  end
49
49
  end
50
-
51
50
  end
data/spec/spec_helper.rb CHANGED
@@ -12,11 +12,11 @@ RSpec.configure do |config|
12
12
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
13
13
  create_database
14
14
 
15
- @alice = User.create :email => "alice@example.com"
16
- @bob = User.create :email => "bob@example.com"
17
- @pat = User.create :email => "pat@example.com"
18
- @admin = Admin.create :email => "admin@example.com"
19
- @men = Men.create :email => "men@example.com"
15
+ @alice = User.create :email => "alice@example.com"
16
+ @bob = User.create :email => "bob@example.com"
17
+ @pat = User.create :email => "pat@example.com"
18
+ @admin = Admin.create :email => "admin@example.com"
19
+ @men = Men.create :email => "men@example.com"
20
20
  end
21
21
 
22
22
  config.after(:all) do
data/spec/support/user.rb CHANGED
@@ -4,3 +4,4 @@ end
4
4
 
5
5
  class Men < User
6
6
  end
7
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts-as-messageable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-08 00:00:00.000000000 Z
12
+ date: 2012-09-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &32872620 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 3.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *32872620
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: activesupport
27
- requirement: &32872120 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,21 +37,31 @@ dependencies:
32
37
  version: 3.0.0
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *32872120
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 3.0.0
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: ancestry
38
- requirement: &32871640 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
42
52
  - !ruby/object:Gem::Version
43
- version: 1.2.4
53
+ version: 1.3.0
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *32871640
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.0
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: railties
49
- requirement: &32871100 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,32 +69,47 @@ dependencies:
54
69
  version: 3.0.0
55
70
  type: :runtime
56
71
  prerelease: false
57
- version_requirements: *32871100
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 3.0.0
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: rspec
60
- requirement: &32870560 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ~>
64
84
  - !ruby/object:Gem::Version
65
- version: 2.8.0
85
+ version: 2.11.0
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *32870560
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 2.11.0
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: jeweler
71
- requirement: &32869960 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ~>
75
100
  - !ruby/object:Gem::Version
76
- version: 1.7.0
101
+ version: 1.8.0
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *32869960
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 1.8.0
80
110
  - !ruby/object:Gem::Dependency
81
- name: sqlite3-ruby
82
- requirement: &32869380 !ruby/object:Gem::Requirement
111
+ name: sqlite3
112
+ requirement: !ruby/object:Gem::Requirement
83
113
  none: false
84
114
  requirements:
85
115
  - - ! '>='
@@ -87,7 +117,12 @@ dependencies:
87
117
  version: '0'
88
118
  type: :development
89
119
  prerelease: false
90
- version_requirements: *32869380
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
91
126
  description:
92
127
  email: piotr.nielacny@gmail.com
93
128
  executables: []
@@ -107,18 +142,16 @@ files:
107
142
  - gemfiles/Gemfile-3.1
108
143
  - gemfiles/Gemfile-3.2
109
144
  - lib/acts-as-messageable.rb
110
- - lib/acts-as-messageable/acts-as-messageable.rb
111
145
  - lib/acts-as-messageable/message.rb
112
146
  - lib/acts-as-messageable/model.rb
147
+ - lib/acts-as-messageable/railtie.rb
113
148
  - lib/acts-as-messageable/relation.rb
114
149
  - lib/generators/acts-as-messageable/migration/migration_generator.rb
115
150
  - lib/generators/acts-as-messageable/migration/templates/migration.rb
116
151
  - lib/generators/acts-as-messageable/migration/templates/migration_permanent.rb
117
- - rails/init.rb
118
152
  - spec/acts-as-messageable_spec.rb
119
153
  - spec/custom-class_spec.rb
120
154
  - spec/custom-required_spec.rb
121
- - spec/inheritance_spec.rb
122
155
  - spec/spec_helper.rb
123
156
  - spec/support/admin.rb
124
157
  - spec/support/send_message.rb
@@ -137,7 +170,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
170
  version: '0'
138
171
  segments:
139
172
  - 0
140
- hash: -1660593036637960416
173
+ hash: 2981709725326590203
141
174
  required_rubygems_version: !ruby/object:Gem::Requirement
142
175
  none: false
143
176
  requirements:
@@ -146,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
179
  version: '0'
147
180
  requirements: []
148
181
  rubyforge_project:
149
- rubygems_version: 1.8.15
182
+ rubygems_version: 1.8.24
150
183
  signing_key:
151
184
  specification_version: 3
152
185
  summary: Make user messageable!;-)
data/rails/init.rb DELETED
@@ -1 +0,0 @@
1
- require 'acts-as-messageable'
@@ -1,23 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "inheritance models" do
4
- it "men send message to alice" do
5
- send_message(@men, @alice)
6
- @men.sent_messages.size.should be_equal(1)
7
- @alice.received_messages.size.should be_equal(1)
8
- end
9
-
10
- it "messages method should receive all messages connected with user" do
11
- send_message(@men, @alice)
12
- @men.messages.size.should be_equal(1)
13
- end
14
-
15
- it "men send message and receive from alice" do
16
- send_message(@men, @alice)
17
- send_message(@alice, @men)
18
-
19
- @men.messages.size.should be_equal(2)
20
- @men.sent_messages.size.should be_equal(1)
21
- @men.received_messages.size.should be_equal(1)
22
- end
23
- end