acts-as-messageable 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ -fd -color
data/.travis.yml CHANGED
@@ -3,4 +3,3 @@ rvm:
3
3
  - 1.9.2
4
4
  - rbx
5
5
  - ree
6
- - jruby
data/Gemfile CHANGED
@@ -4,9 +4,8 @@ gem "activerecord", "~> 3.0.0"
4
4
  gem "ancestry", "~> 1.2.4"
5
5
 
6
6
  group :development do
7
- gem "rspec", "~> 2.3.0"
7
+ gem "rspec", "~> 2.6.0"
8
8
  gem "bundler", "~> 1.0.0"
9
9
  gem "jeweler", "~> 1.6.0"
10
- gem "rcov", ">= 0"
11
10
  gem "sqlite3-ruby"
12
11
  end
data/README.rdoc CHANGED
@@ -57,6 +57,7 @@ or
57
57
  == Conversation
58
58
  @message = @alice.send_message(@bob, "Hello bob!", "How are you?")
59
59
  @reply_message = @bob.reply_to(@message, "Re: Hello bob!", "I'm fine!")
60
+ # or @bob.reply_to(@message, :topic => "Re: Hello bob!", :body => "I'm fine!")
60
61
 
61
62
  @message.conversation #=> [@message, @reply_message]
62
63
  @reply_message.conversation #=> [@message, @reply_message]
data/Rakefile CHANGED
@@ -25,22 +25,8 @@ Jeweler::RubygemsDotOrgTasks.new
25
25
  require 'rspec/core'
26
26
  require 'rspec/core/rake_task'
27
27
  RSpec::Core::RakeTask.new(:spec) do |spec|
28
+ spec.rspec_opts = ['-fd -c']
28
29
  spec.pattern = FileList['spec/**/*_spec.rb']
29
30
  end
30
31
 
31
- RSpec::Core::RakeTask.new(:rcov) do |spec|
32
- spec.pattern = 'spec/**/*_spec.rb'
33
- spec.rcov = true
34
- end
35
-
36
32
  task :default => :spec
37
-
38
- require 'rake/rdoctask'
39
- Rake::RDocTask.new do |rdoc|
40
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
-
42
- rdoc.rdoc_dir = 'rdoc'
43
- rdoc.title = "acts-as-messageable #{version}"
44
- rdoc.rdoc_files.include('README*')
45
- rdoc.rdoc_files.include('lib/**/*.rb')
46
- end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -5,16 +5,17 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{acts-as-messageable}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
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 = %q{2011-05-31}
12
+ s.date = %q{2011-07-02}
13
13
  s.email = %q{piotr.nielacny@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.rdoc"
16
16
  ]
17
17
  s.files = [
18
+ ".rspec",
18
19
  ".travis.yml",
19
20
  "Gemfile",
20
21
  "MIT-LICENSE",
@@ -30,6 +31,7 @@ Gem::Specification.new do |s|
30
31
  "lib/generators/acts-as-messageable/migration/templates/migration.rb",
31
32
  "rails/init.rb",
32
33
  "spec/acts-as-messageable_spec.rb",
34
+ "spec/custom-required_spec.rb",
33
35
  "spec/spec_helper.rb",
34
36
  "spec/support/user.rb"
35
37
  ]
@@ -44,27 +46,24 @@ Gem::Specification.new do |s|
44
46
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
47
  s.add_runtime_dependency(%q<activerecord>, ["~> 3.0.0"])
46
48
  s.add_runtime_dependency(%q<ancestry>, ["~> 1.2.4"])
47
- s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
49
+ s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
48
50
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
51
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
50
- s.add_development_dependency(%q<rcov>, [">= 0"])
51
52
  s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
52
53
  else
53
54
  s.add_dependency(%q<activerecord>, ["~> 3.0.0"])
54
55
  s.add_dependency(%q<ancestry>, ["~> 1.2.4"])
55
- s.add_dependency(%q<rspec>, ["~> 2.3.0"])
56
+ s.add_dependency(%q<rspec>, ["~> 2.6.0"])
56
57
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
58
  s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
58
- s.add_dependency(%q<rcov>, [">= 0"])
59
59
  s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
60
60
  end
61
61
  else
62
62
  s.add_dependency(%q<activerecord>, ["~> 3.0.0"])
63
63
  s.add_dependency(%q<ancestry>, ["~> 1.2.4"])
64
- s.add_dependency(%q<rspec>, ["~> 2.3.0"])
64
+ s.add_dependency(%q<rspec>, ["~> 2.6.0"])
65
65
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
66
66
  s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
67
- s.add_dependency(%q<rcov>, [">= 0"])
68
67
  s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
69
68
  end
70
69
  end
@@ -1,7 +1,10 @@
1
1
  require "active_record"
2
- require 'acts-as-messageable/message'
3
2
  require 'acts-as-messageable/acts-as-messageable'
4
- require 'acts-as-messageable/relation'
3
+
4
+ module ActsAsMessageable
5
+ autoload :Message, "acts-as-messageable/message"
6
+ autoload :Relation, "acts-as-messageable/relation"
7
+ end
5
8
 
6
9
  if defined?(ActiveRecord::Base)
7
10
  ActiveRecord::Base.send :include, ActsAsMessageable::Model
@@ -21,7 +21,16 @@ module ActsAsMessageable
21
21
 
22
22
  ActsAsMessageable::Message.set_table_name(options[:table_name] || "messages")
23
23
  ActsAsMessageable::Message.validates_presence_of(options[:required] || [:topic ,:body])
24
- ActsAsMessageable::Message.required = options[:required] || [:topic, :body]
24
+
25
+ if options[:required].is_a? Symbol
26
+ ActsAsMessageable::Message.required = [options[:required]]
27
+ elsif options[:required].is_a? Array
28
+ ActsAsMessageable::Message.required = options[:required]
29
+ else
30
+ ActsAsMessageable::Message.required = [:topic, :body]
31
+ end
32
+
33
+ ActsAsMessageable::Message.validates_presence_of ActsAsMessageable::Message.required
25
34
 
26
35
  include ActsAsMessageable::Model::InstanceMethods
27
36
  end
@@ -67,8 +76,8 @@ module ActsAsMessageable
67
76
  message
68
77
  end
69
78
 
70
- def reply_to(message, topic, body)
71
- reply_message = send_message(self, topic, body)
79
+ def reply_to(message, *args)
80
+ reply_message = send_message(message.from, *args)
72
81
  reply_message.parent = message
73
82
  reply_message.save
74
83
 
@@ -24,7 +24,7 @@ module ActsAsMessageable
24
24
  # Sample documentation for scope
25
25
  scope :are_from, lambda { |*args| where("sent_messageable_id = :sender", :sender => args.first) }
26
26
  scope :are_to, lambda { |*args| where("received_messageable_id = :receiver", :receiver => args.first) }
27
- scope :with_id, lambda { |*args| where("id = :id", :id => args.first) }
27
+ scope :with_id, lambda { |*args| where("id = :id", :id => args.first) }
28
28
 
29
29
  scope :connected_with, lambda { |*args| where("(sent_messageable_type = :sent_type and
30
30
  sent_messageable_id = :sent_id and
@@ -1,6 +1,15 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
+ class User < ActiveRecord::Base
4
+ acts_as_messageable
5
+ end
6
+
3
7
  describe "ActsAsMessageable" do
8
+
9
+ before(:all) do
10
+ User.acts_as_messageable
11
+ end
12
+
4
13
  it "should be two users in database" do
5
14
  User.count.should == 2
6
15
  end
@@ -0,0 +1,51 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "custom require" do
4
+ before(:each) do
5
+ # Use clean version of Message class
6
+ ActsAsMessageable.instance_eval { remove_const "Message" }
7
+ load "acts-as-messageable/message.rb"
8
+ end
9
+
10
+ it "should work with non-array require" do
11
+ User.acts_as_messageable :required => :body
12
+ ActsAsMessageable::Message.required.should == ([:body])
13
+ end
14
+
15
+ it "should work with array require" do
16
+ User.acts_as_messageable :required => [:body, :topic]
17
+ ActsAsMessageable::Message.required.should == ([:body, :topic])
18
+ end
19
+
20
+ context "only body" do
21
+ before(:each) do
22
+ User.acts_as_messageable :required => :body
23
+ end
24
+
25
+ it "alice should able to send message to bob only with body" do
26
+ @alice.send_message(@bob, "Hello bob!")
27
+ @alice.messages.first.body.should == "Hello bob!"
28
+ @bob.received_messages.first.body.should == "Hello bob!"
29
+ end
30
+
31
+ it "alice should able to send message to bob with hash" do
32
+ @alice.send_message(@bob, :body => "Hi Bob! I'm hash master")
33
+ @alice.messages.first.body.should == "Hi Bob! I'm hash master"
34
+ end
35
+
36
+ it "alice send message to bob with body and bob reply to alice" do
37
+ @alice.send_message(@bob, "Hi Bob!")
38
+ @message_from_alice = @bob.received_messages.first
39
+ @message_from_alice.body.should == "Hi Bob!"
40
+ @bob.reply_to(@message_from_alice, "Hi Alice!")
41
+ @alice.received_messages.first.body.should == "Hi Alice!"
42
+ end
43
+
44
+ it "alice send message to bob and bob reply with hash" do
45
+ @message_from_alice = @alice.send_message(@bob, "Hi Bob!")
46
+ @bob.reply_to(@message_from_alice, :body => "Hi Alice!")
47
+ @alice.received_messages.first.body.should == "Hi Alice!"
48
+ end
49
+ end
50
+
51
+ end
data/spec/spec_helper.rb CHANGED
@@ -3,10 +3,10 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rspec'
4
4
  require 'acts-as-messageable'
5
5
 
6
- # Requires supporting files with custom matchers and macros, etc,
7
- # in ./support/ and its subdirectories.
8
6
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
7
 
8
+ ActiveRecord::Migration.verbose = false
9
+
10
10
  RSpec.configure do |config|
11
11
  config.before(:all) do
12
12
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
data/spec/support/user.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'ancestry'
2
-
3
1
  class User < ActiveRecord::Base
4
2
  acts_as_messageable
5
3
  end
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.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-05-31 00:00:00.000000000 +02:00
12
+ date: 2011-07-02 00:00:00.000000000 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
17
- requirement: &5338400 !ruby/object:Gem::Requirement
17
+ requirement: &22115060 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 3.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *5338400
25
+ version_requirements: *22115060
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: ancestry
28
- requirement: &5337340 !ruby/object:Gem::Requirement
28
+ requirement: &22114520 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,21 +33,21 @@ dependencies:
33
33
  version: 1.2.4
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *5337340
36
+ version_requirements: *22114520
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &5335900 !ruby/object:Gem::Requirement
39
+ requirement: &22113940 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
43
43
  - !ruby/object:Gem::Version
44
- version: 2.3.0
44
+ version: 2.6.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *5335900
47
+ version_requirements: *22113940
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: bundler
50
- requirement: &5334660 !ruby/object:Gem::Requirement
50
+ requirement: &22113380 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 1.0.0
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *5334660
58
+ version_requirements: *22113380
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: jeweler
61
- requirement: &5333300 !ruby/object:Gem::Requirement
61
+ requirement: &22112860 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,21 +66,10 @@ dependencies:
66
66
  version: 1.6.0
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *5333300
70
- - !ruby/object:Gem::Dependency
71
- name: rcov
72
- requirement: &5331960 !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- type: :development
79
- prerelease: false
80
- version_requirements: *5331960
69
+ version_requirements: *22112860
81
70
  - !ruby/object:Gem::Dependency
82
71
  name: sqlite3-ruby
83
- requirement: &5251020 !ruby/object:Gem::Requirement
72
+ requirement: &22112200 !ruby/object:Gem::Requirement
84
73
  none: false
85
74
  requirements:
86
75
  - - ! '>='
@@ -88,7 +77,7 @@ dependencies:
88
77
  version: '0'
89
78
  type: :development
90
79
  prerelease: false
91
- version_requirements: *5251020
80
+ version_requirements: *22112200
92
81
  description:
93
82
  email: piotr.nielacny@gmail.com
94
83
  executables: []
@@ -96,6 +85,7 @@ extensions: []
96
85
  extra_rdoc_files:
97
86
  - README.rdoc
98
87
  files:
88
+ - .rspec
99
89
  - .travis.yml
100
90
  - Gemfile
101
91
  - MIT-LICENSE
@@ -111,6 +101,7 @@ files:
111
101
  - lib/generators/acts-as-messageable/migration/templates/migration.rb
112
102
  - rails/init.rb
113
103
  - spec/acts-as-messageable_spec.rb
104
+ - spec/custom-required_spec.rb
114
105
  - spec/spec_helper.rb
115
106
  - spec/support/user.rb
116
107
  has_rdoc: true
@@ -128,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
119
  version: '0'
129
120
  segments:
130
121
  - 0
131
- hash: 4035680522358941194
122
+ hash: -1671763449284017363
132
123
  required_rubygems_version: !ruby/object:Gem::Requirement
133
124
  none: false
134
125
  requirements: