facteur 0.3.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 1.0.0
@@ -59,10 +59,10 @@ module Facteur
59
59
  options[:body] = message
60
60
  if options[:to].is_a? Array
61
61
  options[:to].each do |addressee|
62
- send_message_to(addressee, options[:in], options[:body])
62
+ send_message_to(addressee, options[:in], options[:body], options[:subject])
63
63
  end
64
64
  else
65
- send_message_to(options[:to], options[:in], options[:body])
65
+ send_message_to(options[:to], options[:in], options[:body], options[:subject])
66
66
  end
67
67
  end
68
68
 
@@ -84,14 +84,10 @@ module Facteur
84
84
  def create_mailbox(name, options={})
85
85
  mailbox = Mailbox.new(:name => name.to_s)
86
86
  mailbox.addressee = self
87
+ mailbox.default = options[:default]
87
88
  return false if mailbox.save == false
88
89
 
89
90
  @default_mailbox = name if options[:default]
90
- self.class.class_eval do
91
- define_method(name) do
92
- self.mailboxes.where(:name => name.to_s).first
93
- end
94
- end
95
91
  true
96
92
  end
97
93
 
@@ -103,6 +99,12 @@ module Facteur
103
99
  self.send "#{name}"
104
100
  end
105
101
 
102
+ def method_missing(method, *args, &block)
103
+ mailbox = Mailbox.find(:first, :conditions => {:name => method.to_s, :addressee_id => self.attributes["id"], :addressee_type => self.class.to_s})
104
+ return mailbox if not mailbox.nil?
105
+ super
106
+ end
107
+
106
108
  private
107
109
 
108
110
  # creates the mailboxes defined in the configuration
@@ -115,7 +117,7 @@ module Facteur
115
117
  end
116
118
 
117
119
  # send a message to an addressee
118
- def send_message_to(addressee, mailbox_name, contents)
120
+ def send_message_to(addressee, mailbox_name, contents, subject=nil)
119
121
  return false if addressee.nil? or contents.nil?
120
122
 
121
123
  mailbox_name = @default_mailbox if mailbox_name.nil?
@@ -125,6 +127,7 @@ module Facteur
125
127
  message.author = self
126
128
  message.mailbox = addressee.send(mailbox_name)
127
129
  message.body = contents
130
+ message.subject = subject
128
131
  message.save
129
132
  end
130
133
  end
data/spec/facteur_spec.rb CHANGED
@@ -29,55 +29,17 @@ describe Facteur::AddresseeModel do
29
29
  end
30
30
 
31
31
  it "creates the addressee's mailboxes" do
32
- @john.mailboxes.where(:name => 'private_mailbox').first.should_not be_nil
33
- @john.mailboxes.where(:name => 'public_mailbox').first.should_not be_nil
34
-
35
- @peter.mailboxes.where(:name => 'private_mailbox').first.should_not be_nil
36
- @peter.mailboxes.where(:name => 'public_mailbox').first.should_not be_nil
37
-
38
- @james.mailboxes.where(:name => 'private_mailbox').first.should_not be_nil
39
- @james.mailboxes.where(:name => 'public_mailbox').first.should_not be_nil
40
-
41
- @mary.mailboxes.where(:name => 'private_mailbox').first.should_not be_nil
42
- @mary.mailboxes.where(:name => 'public_mailbox').first.should_not be_nil
43
-
44
- @jane.mailboxes.where(:name => 'private_mailbox').first.should_not be_nil
45
- @jane.mailboxes.where(:name => 'public_mailbox').first.should_not be_nil
46
-
47
- @victoria.mailboxes.where(:name => 'private_mailbox').first.should_not be_nil
48
- @victoria.mailboxes.where(:name => 'public_mailbox').first.should_not be_nil
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
49
36
  end
50
37
 
51
38
  it "defines the mailboxes accessors" do
52
- @john.should respond_to :private_mailbox
53
- @john.should respond_to :public_mailbox
54
- @john.private_mailbox.should_not be_nil
55
- @john.public_mailbox.should_not be_nil
56
-
57
- @peter.should respond_to :private_mailbox
58
- @peter.should respond_to :public_mailbox
59
- @peter.private_mailbox.should_not be_nil
60
- @peter.public_mailbox.should_not be_nil
61
-
62
- @james.should respond_to :private_mailbox
63
- @james.should respond_to :public_mailbox
64
- @james.private_mailbox.should_not be_nil
65
- @james.public_mailbox.should_not be_nil
66
-
67
- @mary.should respond_to :private_mailbox
68
- @mary.should respond_to :public_mailbox
69
- @mary.private_mailbox.should_not be_nil
70
- @mary.public_mailbox.should_not be_nil
71
-
72
- @jane.should respond_to :private_mailbox
73
- @jane.should respond_to :public_mailbox
74
- @jane.private_mailbox.should_not be_nil
75
- @jane.public_mailbox.should_not be_nil
76
-
77
- @victoria.should respond_to :private_mailbox
78
- @victoria.should respond_to :public_mailbox
79
- @victoria.private_mailbox.should_not be_nil
80
- @victoria.public_mailbox.should_not be_nil
39
+ User.all.each do |user|
40
+ user.private_mailbox.should_not be_nil
41
+ user.public_mailbox.should_not be_nil
42
+ end
81
43
  end
82
44
  end
83
45
 
@@ -95,29 +57,11 @@ describe Facteur::AddresseeModel do
95
57
  end
96
58
 
97
59
  it "should add the new mailbox to all the existing users" do
98
- @john.mailboxes.where(:name => 'private_mailbox').first.should_not be_nil
99
- @john.mailboxes.where(:name => 'public_mailbox').first.should_not be_nil
100
- @john.mailboxes.where(:name => 'added_mailbox').first.should_not be_nil
101
-
102
- @peter.mailboxes.where(:name => 'private_mailbox').first.should_not be_nil
103
- @peter.mailboxes.where(:name => 'public_mailbox').first.should_not be_nil
104
- @peter.mailboxes.where(:name => 'added_mailbox').first.should_not be_nil
105
-
106
- @james.mailboxes.where(:name => 'private_mailbox').first.should_not be_nil
107
- @james.mailboxes.where(:name => 'public_mailbox').first.should_not be_nil
108
- @james.mailboxes.where(:name => 'added_mailbox').first.should_not be_nil
109
-
110
- @mary.mailboxes.where(:name => 'private_mailbox').first.should_not be_nil
111
- @mary.mailboxes.where(:name => 'public_mailbox').first.should_not be_nil
112
- @mary.mailboxes.where(:name => 'added_mailbox').first.should_not be_nil
113
-
114
- @jane.mailboxes.where(:name => 'private_mailbox').first.should_not be_nil
115
- @jane.mailboxes.where(:name => 'public_mailbox').first.should_not be_nil
116
- @jane.mailboxes.where(:name => 'added_mailbox').first.should_not be_nil
117
-
118
- @victoria.mailboxes.where(:name => 'private_mailbox').first.should_not be_nil
119
- @victoria.mailboxes.where(:name => 'public_mailbox').first.should_not be_nil
120
- @victoria.mailboxes.where(:name => 'added_mailbox').first.should_not be_nil
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
64
+ end
121
65
  end
122
66
  end
123
67
 
@@ -132,6 +76,12 @@ describe Facteur::AddresseeModel do
132
76
  message = @peter.private_mailbox.messages.last
133
77
  message.author.should == @john
134
78
  message.body.should == 'message contents'
79
+
80
+ @john.send_message('message contents', :to => @peter, :in => :private_mailbox, :subject => 'test').should == true
81
+ message = @peter.private_mailbox.messages.last
82
+ message.author.should == @john
83
+ message.body.should == 'message contents'
84
+ message.subject.should == 'test'
135
85
  end
136
86
 
137
87
  it "sends the messages in the default mailbox" do
metadata CHANGED
@@ -3,10 +3,10 @@ name: facteur
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
+ - 1
6
7
  - 0
7
- - 3
8
- - 2
9
- version: 0.3.2
8
+ - 0
9
+ version: 1.0.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Rawane ZOSSOU
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-11 00:00:00 +02:00
17
+ date: 2010-09-12 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency