facteur 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/.gitignore +23 -0
  2. data/CHANGELOG +4 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +115 -0
  5. data/LICENSE +20 -20
  6. data/README.markdown +135 -137
  7. data/Rakefile +19 -41
  8. data/lib/facteur.rb +25 -14
  9. data/lib/facteur/active_record_addressee_model.rb +12 -0
  10. data/lib/facteur/active_record_mailbox_model.rb +15 -0
  11. data/lib/facteur/active_record_message_model.rb +24 -0
  12. data/lib/facteur/addressee_model.rb +29 -130
  13. data/lib/facteur/base_addressee_model.rb +163 -0
  14. data/lib/facteur/mailbox.rb +16 -0
  15. data/lib/facteur/mailbox_model.rb +9 -6
  16. data/lib/facteur/message.rb +16 -0
  17. data/lib/facteur/message_model.rb +16 -16
  18. data/lib/facteur/mongoid_addressee_model.rb +12 -0
  19. data/lib/facteur/mongoid_mailbox_model.rb +18 -0
  20. data/lib/facteur/mongoid_message_model.rb +19 -0
  21. data/lib/facteur/version.rb +3 -0
  22. data/lib/generators/facteur/install/install_generator.rb +25 -28
  23. data/lib/generators/facteur/install/templates/create_mailboxes.rb +14 -14
  24. data/lib/generators/facteur/install/templates/create_messages.rb +19 -19
  25. data/spec/activerecord/activerecord_spec_helper.rb +11 -0
  26. data/spec/activerecord/facteur_spec.rb +47 -0
  27. data/spec/mongoid/facteur_spec.rb +49 -0
  28. data/spec/mongoid/mongoid_spec_helper.rb +11 -0
  29. data/spec/spec_helper.rb +10 -67
  30. data/spec/support/activerecord/schema.rb +32 -0
  31. data/spec/{facteur_spec.rb → support/facteur_examples.rb} +38 -49
  32. data/spec/support/mongoid/database.rb +12 -0
  33. metadata +139 -20
  34. data/.document +0 -5
  35. data/VERSION +0 -1
  36. data/lib/facteur/rails/tasks/facteur.rake +0 -13
  37. data/lib/generators/facteur/install/templates/mailbox.rb +0 -3
  38. data/lib/generators/facteur/install/templates/message.rb +0 -3
@@ -0,0 +1,32 @@
1
+ ActiveRecord::Base.establish_connection(
2
+ :adapter => 'sqlite3',
3
+ :database => ":memory:"
4
+ )
5
+
6
+ class CreateSchema < ActiveRecord::Migration
7
+ def self.up
8
+ create_table :members, :force => true do |t|
9
+ t.string :name, :null => false
10
+ end
11
+
12
+ create_table :mailboxes, :force => true do |t|
13
+ t.string :name
14
+ t.belongs_to :addressee, :polymorphic => true
15
+ t.boolean :default, :default => :false
16
+ end
17
+
18
+ create_table :messages, :force => true do |t|
19
+ t.string :subject
20
+ t.text :body
21
+ t.belongs_to :mailbox
22
+ t.belongs_to :author
23
+ t.boolean :read, :default => false
24
+ end
25
+
26
+ create_table :messages_addressees, :id => false, :force => true do |t|
27
+ t.references :addressee
28
+ t.references :message
29
+ end
30
+ end
31
+ end
32
+
@@ -1,76 +1,45 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe Facteur::AddresseeModel do
1
+ shared_examples_for "an addressee model" do
4
2
  context "when creating mailboxes" do
5
- before(:each) do
6
- create_users
7
- Message.delete_all
8
- end
9
-
10
3
  it "creates a new mailbox" do
11
- @john.create_mailbox(:news_mailbox).should == true
12
-
13
- lambda { @peter.create_mailbox! :news_mailbox }.should_not raise_error
4
+ mailbox = @john.create_mailbox(:news_mailbox)
5
+ mailbox.should_not == false
6
+ mailbox.addressee.should == @john
7
+ @john.news_mailbox.should == mailbox
14
8
 
15
- mailbox = @victoria.create_mailbox! :news_mailbox
16
- mailbox.addressee.should == @victoria
9
+ lambda { mailbox = @peter.create_mailbox! :news_mailbox }.should_not raise_error
10
+ mailbox.addressee.should == @peter
11
+ @peter.news_mailbox.should == mailbox
17
12
  end
18
13
 
19
14
  it "could not create a mailbox with the name of an existing mailbox" do
15
+ @john.private_mailbox.should_not be_nil
20
16
  @john.create_mailbox(:private_mailbox).should == false
17
+ @peter.private_mailbox.should_not be_nil
21
18
  lambda { mailbox = @peter.create_mailbox! :private_mailbox }.should raise_error
22
19
  end
23
20
  end
24
21
 
25
- context "when initialized" do
26
- before(:each) do
27
- create_users
28
- Message.delete_all
29
- end
30
-
31
- it "creates the addressee's mailboxes" do
32
- User.all.each do |user|
33
- user.mailboxes.where(:name => 'private_mailbox').first.should_not be_nil
34
- user.mailboxes.where(:name => 'public_mailbox').first.should_not be_nil
35
- end
36
- end
37
-
38
- it "defines the mailboxes accessors" do
39
- User.all.each do |user|
40
- user.private_mailbox.should_not be_nil
41
- user.public_mailbox.should_not be_nil
42
- end
43
- end
44
- end
45
-
46
22
  context "When adding a new mailbox" do
47
23
  before(:all) do
48
- create_users
49
- class User < ActiveRecord::Base
24
+ Member.class_exec do
50
25
  mailbox :added_mailbox
51
26
  end
52
- User.update_addressees_mailboxes
53
27
  end
54
28
 
55
29
  it "should add the new mailbox to the class mailboxes" do
56
- User.mailboxes.should include({:name=>:added_mailbox})
30
+ Member.mailboxes.should include({:name=>:added_mailbox})
57
31
  end
58
32
 
59
33
  it "should add the new mailbox to all the existing users" do
60
- User.all.each do |user|
61
- user.mailboxes.where(:name => 'private_mailbox').first.should_not be_nil
62
- user.mailboxes.where(:name => 'public_mailbox').first.should_not be_nil
63
- user.mailboxes.where(:name => 'added_mailbox').first.should_not be_nil
34
+ Member.all.each do |user|
35
+ user.private_mailbox.should_not be_nil
36
+ user.public_mailbox.should_not be_nil
37
+ user.added_mailbox.should_not be_nil
64
38
  end
65
39
  end
66
40
  end
67
41
 
68
- context "when sending message" do
69
- before(:each) do
70
- create_users
71
- Message.delete_all
72
- end
73
-
42
+ context "when sending message" do
74
43
  it "sends a message to another addressee" do
75
44
  message = @john.send_message('message contents', :to => @peter, :in => :private_mailbox)
76
45
  message.author.should == @john
@@ -113,6 +82,26 @@ describe Facteur::AddresseeModel do
113
82
  message.author.should == @john
114
83
  message.body.should == 'message contents'
115
84
  end
85
+
86
+ it "saves the messages sent" do
87
+ @victoria.sent_messages.delete_all
88
+ @victoria.send_message('message contents', :to => @john)
89
+ @victoria.sent_messages.count.should == 1
90
+ @victoria.sent_messages.first.body.should == 'message contents'
91
+ @victoria.sent_messages.first.author.should == @victoria
92
+ @victoria.sent_messages.first.addressees.should == [@john]
93
+ @victoria.send_message('message contents', :to => @peter)
94
+ @victoria.sent_messages.count.should == 2
95
+ @victoria.sent_messages.last.body.should == 'message contents'
96
+ @victoria.sent_messages.last.author.should == @victoria
97
+ @victoria.sent_messages.last.addressees.should == [@peter]
98
+
99
+ @victoria.sent_messages.delete_all
100
+ @victoria.send_message('message contents', :to => [@peter, @james, @jane])
101
+ @victoria.sent_messages.count.should == 1
102
+ @victoria.sent_messages.first.body.should == 'message contents'
103
+ @victoria.sent_messages.first.author.should == @victoria
104
+ @victoria.sent_messages.first.addressees.should == [@peter, @james, @jane]
105
+ end
116
106
  end
117
-
118
107
  end
@@ -0,0 +1,12 @@
1
+ module Database
2
+ def self.connect
3
+ Mongoid.configure do |config|
4
+ name = "facteur_test"
5
+ host = "localhost"
6
+ config.master = Mongo::Connection.new.db(name)
7
+ config.slaves = [
8
+ Mongo::Connection.new(host, 27017, :slave_ok => true).db(name)
9
+ ]
10
+ end
11
+ end
12
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: facteur
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.1
5
+ version: 1.3.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rawane ZOSSOU
@@ -10,48 +10,160 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-21 00:00:00 +01:00
14
- default_executable:
13
+ date: 2011-04-23 00:00:00 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
- name: rspec
16
+ name: bundler
18
17
  prerelease: false
19
18
  requirement: &id001 !ruby/object:Gem::Requirement
20
19
  none: false
21
20
  requirements:
22
- - - ">="
21
+ - - ~>
23
22
  - !ruby/object:Gem::Version
24
- version: 1.2.9
23
+ version: 1.0.12
25
24
  type: :development
26
25
  version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 2.5.0
35
+ type: :development
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: rails
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 3.0.7
46
+ type: :development
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: activesupport
50
+ prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 3.0.7
57
+ type: :development
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: activerecord
61
+ prerelease: false
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: 3.0.7
68
+ type: :development
69
+ version_requirements: *id005
70
+ - !ruby/object:Gem::Dependency
71
+ name: sqlite3
72
+ prerelease: false
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 1.3.2
79
+ type: :development
80
+ version_requirements: *id006
81
+ - !ruby/object:Gem::Dependency
82
+ name: mongoid
83
+ prerelease: false
84
+ requirement: &id007 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 2.0.0
90
+ type: :development
91
+ version_requirements: *id007
92
+ - !ruby/object:Gem::Dependency
93
+ name: bson_ext
94
+ prerelease: false
95
+ requirement: &id008 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ~>
99
+ - !ruby/object:Gem::Version
100
+ version: "1.3"
101
+ type: :development
102
+ version_requirements: *id008
103
+ - !ruby/object:Gem::Dependency
104
+ name: fuubar
105
+ prerelease: false
106
+ requirement: &id009 !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ version: 0.0.4
112
+ type: :development
113
+ version_requirements: *id009
114
+ - !ruby/object:Gem::Dependency
115
+ name: awesome_print
116
+ prerelease: false
117
+ requirement: &id010 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ~>
121
+ - !ruby/object:Gem::Version
122
+ version: 0.3.2
123
+ type: :development
124
+ version_requirements: *id010
27
125
  description: Facteur allows you add a messaging system in your Rails 3. You can create many mailboxes for your users. They will be able to send and receive messages.
28
- email: dev@raw1z.fr
126
+ email:
127
+ - dev@raw1z.fr
29
128
  executables: []
30
129
 
31
130
  extensions: []
32
131
 
33
- extra_rdoc_files:
34
- - LICENSE
35
- - README.markdown
132
+ extra_rdoc_files: []
133
+
36
134
  files:
37
- - .document
135
+ - .gitignore
136
+ - CHANGELOG
137
+ - Gemfile
138
+ - Gemfile.lock
38
139
  - LICENSE
39
140
  - README.markdown
40
141
  - Rakefile
41
- - VERSION
42
142
  - lib/facteur.rb
143
+ - lib/facteur/active_record_addressee_model.rb
144
+ - lib/facteur/active_record_mailbox_model.rb
145
+ - lib/facteur/active_record_message_model.rb
43
146
  - lib/facteur/addressee_model.rb
147
+ - lib/facteur/base_addressee_model.rb
148
+ - lib/facteur/mailbox.rb
44
149
  - lib/facteur/mailbox_model.rb
150
+ - lib/facteur/message.rb
45
151
  - lib/facteur/message_model.rb
46
- - lib/facteur/rails/tasks/facteur.rake
152
+ - lib/facteur/mongoid_addressee_model.rb
153
+ - lib/facteur/mongoid_mailbox_model.rb
154
+ - lib/facteur/mongoid_message_model.rb
155
+ - lib/facteur/version.rb
47
156
  - lib/generators/facteur/install/install_generator.rb
48
157
  - lib/generators/facteur/install/templates/create_mailboxes.rb
49
158
  - lib/generators/facteur/install/templates/create_messages.rb
50
- - lib/generators/facteur/install/templates/mailbox.rb
51
- - lib/generators/facteur/install/templates/message.rb
52
- - spec/facteur_spec.rb
159
+ - spec/activerecord/activerecord_spec_helper.rb
160
+ - spec/activerecord/facteur_spec.rb
161
+ - spec/mongoid/facteur_spec.rb
162
+ - spec/mongoid/mongoid_spec_helper.rb
53
163
  - spec/spec_helper.rb
54
- has_rdoc: true
164
+ - spec/support/activerecord/schema.rb
165
+ - spec/support/facteur_examples.rb
166
+ - spec/support/mongoid/database.rb
55
167
  homepage: http://github.com/raw1z/facteur
56
168
  licenses: []
57
169
 
@@ -74,11 +186,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
186
  version: "0"
75
187
  requirements: []
76
188
 
77
- rubyforge_project:
78
- rubygems_version: 1.5.2
189
+ rubyforge_project: facteur
190
+ rubygems_version: 1.7.2
79
191
  signing_key:
80
192
  specification_version: 3
81
193
  summary: Messaging system for Rails 3
82
194
  test_files:
83
- - spec/facteur_spec.rb
195
+ - spec/activerecord/activerecord_spec_helper.rb
196
+ - spec/activerecord/facteur_spec.rb
197
+ - spec/mongoid/facteur_spec.rb
198
+ - spec/mongoid/mongoid_spec_helper.rb
84
199
  - spec/spec_helper.rb
200
+ - spec/support/activerecord/schema.rb
201
+ - spec/support/facteur_examples.rb
202
+ - spec/support/mongoid/database.rb
203
+ has_rdoc:
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.2.1
@@ -1,13 +0,0 @@
1
- def obtain_class
2
- class_name = ENV['CLASS'] || ENV['class']
3
- raise "Must specify CLASS" unless class_name
4
- @klass = Object.const_get(class_name)
5
- end
6
-
7
- namespace :facteur do
8
- desc "Regenerates the mailboxes. The existing ones are not destroyed"
9
- task :update => :environment do
10
- klass = obtain_class
11
- klass.update_addressees_mailboxes
12
- end
13
- end
@@ -1,3 +0,0 @@
1
- class Mailbox < ActiveRecord::Base
2
- include Facteur::MailboxModel
3
- end
@@ -1,3 +0,0 @@
1
- class Message < ActiveRecord::Base
2
- include Facteur::MessageModel
3
- end