mailboxer-without-notification 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/.travis.yml +11 -0
- data/.yardopts +2 -0
- data/Appraisals +19 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +298 -0
- data/Rakefile +11 -0
- data/app/mailers/message_mailer.rb +37 -0
- data/app/models/conversation.rb +179 -0
- data/app/models/mailbox.rb +122 -0
- data/app/models/message.rb +218 -0
- data/app/models/receipt.rb +176 -0
- data/app/uploaders/attachment_uploader.rb +3 -0
- data/app/views/message_mailer/new_message_email.html.erb +20 -0
- data/app/views/message_mailer/new_message_email.text.erb +10 -0
- data/app/views/message_mailer/reply_message_email.html.erb +20 -0
- data/app/views/message_mailer/reply_message_email.text.erb +10 -0
- data/config/locales/en.yml +7 -0
- data/config/locales/fr.yml +7 -0
- data/db/migrate/20110511145103_create_mailboxer.rb +61 -0
- data/db/migrate/20110719110700_add_notified_object.rb +17 -0
- data/db/migrate/20110912163911_add_notification_code.rb +13 -0
- data/db/migrate/20111204163911_add_attachments.rb +9 -0
- data/db/migrate/20120813110712_rename_receipts_read.rb +9 -0
- data/db/migrate/20130305144212_add_global_notification_support.rb +9 -0
- data/db/migrate/20131003144212_change_table_notification.rb +10 -0
- data/db/migrate/20131003214212_change_relations.rb +6 -0
- data/gemfiles/rails3.0.gemfile +8 -0
- data/gemfiles/rails3.1.gemfile +8 -0
- data/gemfiles/rails3.2.gemfile +8 -0
- data/gemfiles/rails4.0.gemfile +8 -0
- data/lib/generators/mailboxer/install_generator.rb +35 -0
- data/lib/generators/mailboxer/templates/initializer.rb +17 -0
- data/lib/generators/mailboxer/views_generator.rb +9 -0
- data/lib/mailboxer.rb +37 -0
- data/lib/mailboxer/concerns/configurable_mailer.rb +13 -0
- data/lib/mailboxer/engine.rb +17 -0
- data/lib/mailboxer/models/messageable.rb +225 -0
- data/mailboxer.gemspec +49 -0
- data/spec/dummy/.gitignore +5 -0
- data/spec/dummy/Gemfile +33 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/home_controller.rb +4 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/cylon.rb +7 -0
- data/spec/dummy/app/models/duck.rb +11 -0
- data/spec/dummy/app/models/user.rb +6 -0
- data/spec/dummy/app/views/home/index.html.haml +7 -0
- data/spec/dummy/app/views/layouts/application.html.haml +11 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +42 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +24 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +26 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +33 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mailboxer.rb +17 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/config/sunspot.yml +17 -0
- data/spec/dummy/db/migrate/20110228120600_create_users.rb +14 -0
- data/spec/dummy/db/migrate/20110306002940_create_ducks.rb +14 -0
- data/spec/dummy/db/migrate/20110306015107_create_cylons.rb +14 -0
- data/spec/dummy/db/migrate/20120305103200_create_mailboxer.rb +61 -0
- data/spec/dummy/db/migrate/20120305103201_add_notified_object.rb +17 -0
- data/spec/dummy/db/migrate/20120305103202_add_notification_code.rb +13 -0
- data/spec/dummy/db/migrate/20120305103203_add_attachments.rb +5 -0
- data/spec/dummy/db/migrate/20120813110712_rename_receipts_read.rb +9 -0
- data/spec/dummy/db/migrate/20130305144212_add_global_notification_support.rb +11 -0
- data/spec/dummy/db/migrate/20131003144212_change_table_notification.rb +10 -0
- data/spec/dummy/db/migrate/20131003214212_change_relations.rb +6 -0
- data/spec/dummy/db/schema.rb +74 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/index.html +239 -0
- data/spec/dummy/public/robots.txt +5 -0
- data/spec/dummy/public/uploads/testfile.txt +1 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories/cylon.rb +10 -0
- data/spec/factories/duck.rb +10 -0
- data/spec/factories/user.rb +10 -0
- data/spec/integration/message_and_receipt_spec.rb +903 -0
- data/spec/integration/navigation_spec.rb +9 -0
- data/spec/mailboxer/concerns/configurable_mailer_spec.rb +27 -0
- data/spec/mailboxer_spec.rb +7 -0
- data/spec/mailers/message_mailer_spec.rb +109 -0
- data/spec/models/conversation_spec.rb +154 -0
- data/spec/models/mailbox_spec.rb +160 -0
- data/spec/models/mailboxer_models_messageable_spec.rb +324 -0
- data/spec/models/message_spec.rb +222 -0
- data/spec/models/receipt_spec.rb +56 -0
- data/spec/spec_helper.rb +36 -0
- data/spec/testfile.txt +1 -0
- metadata +301 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Concerns::ConfigurableMailer do
|
3
|
+
|
4
|
+
#describe "Notification instance#get_mailer" do
|
5
|
+
# before { @obj = Notification.new }
|
6
|
+
# it "returns default_mailer" do
|
7
|
+
# @obj.get_mailer.should eq NotificationMailer
|
8
|
+
# end
|
9
|
+
# it "returns 'foo' from Mailerbox.notification_mailer" do
|
10
|
+
# Mailboxer.notification_mailer = 'foo'
|
11
|
+
# @obj.get_mailer.should eq 'foo'
|
12
|
+
# end
|
13
|
+
# after { Mailboxer.notification_mailer = nil }
|
14
|
+
#end
|
15
|
+
|
16
|
+
describe "Message instance#get_mailer" do
|
17
|
+
before { @obj = Message.new }
|
18
|
+
it "returns default_mailer" do
|
19
|
+
@obj.get_mailer.should eq MessageMailer
|
20
|
+
end
|
21
|
+
it "returns 'foo' from Mailerbox.message_mailer" do
|
22
|
+
Mailboxer.message_mailer = 'foo'
|
23
|
+
@obj.get_mailer.should eq 'foo'
|
24
|
+
end
|
25
|
+
after { Mailboxer.message_mailer = nil }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MessageMailer do
|
4
|
+
shared_examples 'message_mailer' do
|
5
|
+
let(:sender) { FactoryGirl.create(:user) }
|
6
|
+
let(:entity1) { FactoryGirl.create(:user) }
|
7
|
+
let(:entity2) { FactoryGirl.create(:duck) }
|
8
|
+
let(:entity3) { FactoryGirl.create(:cylon) }
|
9
|
+
|
10
|
+
def sent_to?(entity)
|
11
|
+
ActionMailer::Base.deliveries.any? do |email|
|
12
|
+
email.to.first.to_s == entity.email
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "when sending new message" do
|
17
|
+
before do
|
18
|
+
@receipt1 = sender.send_message([entity1, entity2, entity3], "Body", "Subject")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should send emails when should_email? is true (1 out of 3)" do
|
22
|
+
ActionMailer::Base.deliveries.should_not be_empty
|
23
|
+
ActionMailer::Base.deliveries.should have(1).item
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should send an email to user entity" do
|
27
|
+
sent_to?(entity1).should be_true
|
28
|
+
end
|
29
|
+
|
30
|
+
it "shouldn't send an email to duck entity" do
|
31
|
+
sent_to?(entity2).should be_false
|
32
|
+
end
|
33
|
+
|
34
|
+
it "shouldn't send an email to cylon entity" do
|
35
|
+
sent_to?(entity3).should be_false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "when replying" do
|
40
|
+
before do
|
41
|
+
@receipt1 = sender.send_message([entity1, entity2, entity3], "Body", "Subject")
|
42
|
+
@receipt2 = sender.reply_to_all(@receipt1, "Body")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should send emails when should_email? is true (1 out of 3)" do
|
46
|
+
ActionMailer::Base.deliveries.should_not be_empty
|
47
|
+
ActionMailer::Base.deliveries.should have(2).items
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should send an email to user entity" do
|
51
|
+
sent_to?(entity1).should be_true
|
52
|
+
end
|
53
|
+
|
54
|
+
it "shouldn't send an email to duck entity" do
|
55
|
+
sent_to?(entity2).should be_false
|
56
|
+
end
|
57
|
+
|
58
|
+
it "shouldn't send an email to cylon entity" do
|
59
|
+
sent_to?(entity3).should be_false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "when mailer_wants_array is false" do
|
65
|
+
it_behaves_like 'message_mailer'
|
66
|
+
end
|
67
|
+
|
68
|
+
context "mailer_wants_array is true" do
|
69
|
+
class ArrayMailer < MessageMailer
|
70
|
+
default template_path: 'message_mailer'
|
71
|
+
|
72
|
+
def new_message_email(message, receivers)
|
73
|
+
receivers.each { |receiver| super(message, receiver) if receiver.mailboxer_email(message).present? }
|
74
|
+
end
|
75
|
+
|
76
|
+
def reply_message_email(message, receivers)
|
77
|
+
receivers.each { |receiver| super(message, receiver) if receiver.mailboxer_email(message).present? }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
before :all do
|
82
|
+
Mailboxer.mailer_wants_array = true
|
83
|
+
Mailboxer.message_mailer = ArrayMailer
|
84
|
+
end
|
85
|
+
|
86
|
+
after :all do
|
87
|
+
Mailboxer.mailer_wants_array = false
|
88
|
+
Mailboxer.message_mailer = MessageMailer
|
89
|
+
end
|
90
|
+
|
91
|
+
it_behaves_like 'message_mailer'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def print_emails
|
96
|
+
ActionMailer::Base.deliveries.each do |email|
|
97
|
+
puts "----------------------------------------------------"
|
98
|
+
puts email.to
|
99
|
+
puts "---"
|
100
|
+
puts email.from
|
101
|
+
puts "---"
|
102
|
+
puts email.subject
|
103
|
+
puts "---"
|
104
|
+
puts email.body
|
105
|
+
puts "---"
|
106
|
+
puts email.encoded
|
107
|
+
puts "----------------------------------------------------"
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Conversation do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@entity1 = FactoryGirl.create(:user)
|
7
|
+
@entity2 = FactoryGirl.create(:user)
|
8
|
+
@receipt1 = @entity1.send_message(@entity2,"Body","Subject")
|
9
|
+
@receipt2 = @entity2.reply_to_all(@receipt1,"Reply body 1")
|
10
|
+
@receipt3 = @entity1.reply_to_all(@receipt2,"Reply body 2")
|
11
|
+
@receipt4 = @entity2.reply_to_all(@receipt3,"Reply body 3")
|
12
|
+
@message1 = @receipt1.message
|
13
|
+
@message4 = @receipt4.message
|
14
|
+
@conversation = @message1.conversation
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have proper original message" do
|
18
|
+
@conversation.original_message.should==@message1
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have proper originator (first sender)" do
|
22
|
+
@conversation.originator.should==@entity1
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have proper last message" do
|
26
|
+
@conversation.last_message.should==@message4
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should have proper last sender" do
|
30
|
+
@conversation.last_sender.should==@entity2
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should have all conversation users" do
|
34
|
+
@conversation.recipients.count.should==2
|
35
|
+
@conversation.recipients.count.should==2
|
36
|
+
@conversation.recipients.count(@entity1).should==1
|
37
|
+
@conversation.recipients.count(@entity2).should==1
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should be able to be marked as deleted" do
|
41
|
+
@conversation.move_to_trash(@entity1)
|
42
|
+
@conversation.mark_as_deleted(@entity1)
|
43
|
+
@conversation.should be_is_deleted(@entity1)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should be removed from the database once deleted by all participants" do
|
47
|
+
@conversation.mark_as_deleted(@entity1)
|
48
|
+
@conversation.mark_as_deleted(@entity2)
|
49
|
+
Conversation.exists?(@conversation.id).should be_false
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should be able to be marked as read" do
|
53
|
+
#@conversation.move_to_trash(@entity1)
|
54
|
+
@conversation.mark_as_read(@entity1)
|
55
|
+
@conversation.should be_is_read(@entity)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should be able to be marked as unread" do
|
59
|
+
@conversation.mark_as_read(@entity1)
|
60
|
+
@conversation.mark_as_unread(@entity1)
|
61
|
+
@conversation.should be_is_unread(@entity1)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should be able to add a new participant" do
|
65
|
+
new_user = FactoryGirl.create(:user)
|
66
|
+
@conversation.add_participant(new_user)
|
67
|
+
@conversation.participants.count.should == 3
|
68
|
+
@conversation.participants.should include(new_user, @entity1, @entity2)
|
69
|
+
@conversation.receipts_for(new_user).count.should == @conversation.receipts_for(@entity1).count
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should deliver messages to new participants" do
|
73
|
+
new_user = FactoryGirl.create(:user)
|
74
|
+
@conversation.add_participant(new_user)
|
75
|
+
expect{
|
76
|
+
receipt5 = @entity1.reply_to_all(@receipt4,"Reply body 4")
|
77
|
+
}.to change{ @conversation.receipts_for(new_user).count }.by 1
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "scopes" do
|
81
|
+
let(:participant) { FactoryGirl.create(:user) }
|
82
|
+
let!(:inbox_conversation) { @entity1.send_message(participant, "Body", "Subject").message.conversation }
|
83
|
+
let!(:sentbox_conversation) { participant.send_message(@entity1, "Body", "Subject").message.conversation }
|
84
|
+
|
85
|
+
|
86
|
+
describe ".participant" do
|
87
|
+
it "finds conversations with receipts for participant" do
|
88
|
+
Conversation.participant(participant).should == [sentbox_conversation, inbox_conversation]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe ".inbox" do
|
93
|
+
it "finds inbox conversations with receipts for participant" do
|
94
|
+
Conversation.inbox(participant).should == [inbox_conversation]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe ".sentbox" do
|
99
|
+
it "finds sentbox conversations with receipts for participant" do
|
100
|
+
Conversation.sentbox(participant).should == [sentbox_conversation]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe ".trash" do
|
105
|
+
it "finds trash conversations with receipts for participant" do
|
106
|
+
trashed_conversation = @entity1.send_message(participant, "Body", "Subject").message.conversation
|
107
|
+
trashed_conversation.move_to_trash(participant)
|
108
|
+
|
109
|
+
Conversation.trash(participant).should == [trashed_conversation]
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe ".unread" do
|
114
|
+
it "finds unread conversations with receipts for participant" do
|
115
|
+
[sentbox_conversation, inbox_conversation].each {|c| c.mark_as_read(participant) }
|
116
|
+
unread_conversation = @entity1.send_message(participant, "Body", "Subject").message.conversation
|
117
|
+
|
118
|
+
Conversation.unread(participant).should == [unread_conversation]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "#is_completely_trashed?" do
|
124
|
+
it "returns true if all receipts in conversation are trashed for participant" do
|
125
|
+
@conversation.move_to_trash(@entity1)
|
126
|
+
@conversation.is_completely_trashed?(@entity1).should be_true
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "#is_deleted?" do
|
131
|
+
it "returns false if a recipient has not deleted the conversation" do
|
132
|
+
@conversation.is_deleted?(@entity1).should be_false
|
133
|
+
end
|
134
|
+
|
135
|
+
it "returns true if a recipient has deleted the conversation" do
|
136
|
+
@conversation.mark_as_deleted(@entity1)
|
137
|
+
@conversation.is_deleted?(@entity1).should be_true
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe "#is_orphaned?" do
|
142
|
+
it "returns true if both participants have deleted the conversation" do
|
143
|
+
@conversation.mark_as_deleted(@entity1)
|
144
|
+
@conversation.mark_as_deleted(@entity2)
|
145
|
+
@conversation.is_orphaned?.should be_true
|
146
|
+
end
|
147
|
+
|
148
|
+
it "returns false if one has not deleted the conversation" do
|
149
|
+
@conversation.mark_as_deleted(@entity1)
|
150
|
+
@conversation.is_orphaned?.should be_false
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mailbox do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@entity1 = FactoryGirl.create(:user)
|
7
|
+
@entity2 = FactoryGirl.create(:user)
|
8
|
+
@receipt1 = @entity1.send_message(@entity2,"Body","Subject")
|
9
|
+
@receipt2 = @entity2.reply_to_all(@receipt1,"Reply body 1")
|
10
|
+
@receipt3 = @entity1.reply_to_all(@receipt2,"Reply body 2")
|
11
|
+
@receipt4 = @entity2.reply_to_all(@receipt3,"Reply body 3")
|
12
|
+
@message1 = @receipt1.message
|
13
|
+
@message4 = @receipt4.message
|
14
|
+
@conversation = @message1.conversation
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return all conversations" do
|
18
|
+
@conv2 = @entity1.send_message(@entity2,"Body","Subject").conversation
|
19
|
+
@conv3 = @entity2.send_message(@entity1,"Body","Subject").conversation
|
20
|
+
@conv4 = @entity1.send_message(@entity2,"Body","Subject").conversation
|
21
|
+
|
22
|
+
assert @entity1.mailbox.conversations
|
23
|
+
|
24
|
+
@entity1.mailbox.conversations.to_a.count.should==4
|
25
|
+
@entity1.mailbox.conversations.to_a.count(@conversation).should==1
|
26
|
+
@entity1.mailbox.conversations.to_a.count(@conv2).should==1
|
27
|
+
@entity1.mailbox.conversations.to_a.count(@conv3).should==1
|
28
|
+
@entity1.mailbox.conversations.to_a.count(@conv4).should==1
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return all mail" do
|
32
|
+
assert @entity1.mailbox.receipts
|
33
|
+
@entity1.mailbox.receipts.count.should==4
|
34
|
+
@entity1.mailbox.receipts[0].should==Receipt.recipient(@entity1).conversation(@conversation)[0]
|
35
|
+
@entity1.mailbox.receipts[1].should==Receipt.recipient(@entity1).conversation(@conversation)[1]
|
36
|
+
@entity1.mailbox.receipts[2].should==Receipt.recipient(@entity1).conversation(@conversation)[2]
|
37
|
+
@entity1.mailbox.receipts[3].should==Receipt.recipient(@entity1).conversation(@conversation)[3]
|
38
|
+
|
39
|
+
assert @entity2.mailbox.receipts
|
40
|
+
@entity2.mailbox.receipts.count.should==4
|
41
|
+
@entity2.mailbox.receipts[0].should==Receipt.recipient(@entity2).conversation(@conversation)[0]
|
42
|
+
@entity2.mailbox.receipts[1].should==Receipt.recipient(@entity2).conversation(@conversation)[1]
|
43
|
+
@entity2.mailbox.receipts[2].should==Receipt.recipient(@entity2).conversation(@conversation)[2]
|
44
|
+
@entity2.mailbox.receipts[3].should==Receipt.recipient(@entity2).conversation(@conversation)[3]
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return sentbox" do
|
48
|
+
assert @entity1.mailbox.receipts.inbox
|
49
|
+
@entity1.mailbox.receipts.sentbox.count.should==2
|
50
|
+
@entity1.mailbox.receipts.sentbox[0].should==@receipt1
|
51
|
+
@entity1.mailbox.receipts.sentbox[1].should==@receipt3
|
52
|
+
|
53
|
+
assert @entity2.mailbox.receipts.inbox
|
54
|
+
@entity2.mailbox.receipts.sentbox.count.should==2
|
55
|
+
@entity2.mailbox.receipts.sentbox[0].should==@receipt2
|
56
|
+
@entity2.mailbox.receipts.sentbox[1].should==@receipt4
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should return inbox" do
|
60
|
+
assert @entity1.mailbox.receipts.inbox
|
61
|
+
@entity1.mailbox.receipts.inbox.count.should==2
|
62
|
+
@entity1.mailbox.receipts.inbox[0].should==Receipt.recipient(@entity1).inbox.conversation(@conversation)[0]
|
63
|
+
@entity1.mailbox.receipts.inbox[1].should==Receipt.recipient(@entity1).inbox.conversation(@conversation)[1]
|
64
|
+
|
65
|
+
assert @entity2.mailbox.receipts.inbox
|
66
|
+
@entity2.mailbox.receipts.inbox.count.should==2
|
67
|
+
@entity2.mailbox.receipts.inbox[0].should==Receipt.recipient(@entity2).inbox.conversation(@conversation)[0]
|
68
|
+
@entity2.mailbox.receipts.inbox[1].should==Receipt.recipient(@entity2).inbox.conversation(@conversation)[1]
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should understand the read option" do
|
72
|
+
@entity1.mailbox.inbox({:read => false}).count.should_not == 0
|
73
|
+
@conversation.mark_as_read(@entity1)
|
74
|
+
@entity1.mailbox.inbox({:read => false}).count.should == 0
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should return trashed mails" do
|
78
|
+
@entity1.mailbox.receipts.move_to_trash
|
79
|
+
|
80
|
+
assert @entity1.mailbox.receipts.trash
|
81
|
+
@entity1.mailbox.receipts.trash.count.should==4
|
82
|
+
@entity1.mailbox.receipts.trash[0].should==Receipt.recipient(@entity1).conversation(@conversation)[0]
|
83
|
+
@entity1.mailbox.receipts.trash[1].should==Receipt.recipient(@entity1).conversation(@conversation)[1]
|
84
|
+
@entity1.mailbox.receipts.trash[2].should==Receipt.recipient(@entity1).conversation(@conversation)[2]
|
85
|
+
@entity1.mailbox.receipts.trash[3].should==Receipt.recipient(@entity1).conversation(@conversation)[3]
|
86
|
+
|
87
|
+
assert @entity2.mailbox.receipts.trash
|
88
|
+
@entity2.mailbox.receipts.trash.count.should==0
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should delete trashed mails (TODO)" do
|
92
|
+
@entity1.mailbox.receipts.move_to_trash
|
93
|
+
#TODO
|
94
|
+
#@entity1.mailbox.empty_trash
|
95
|
+
|
96
|
+
assert @entity1.mailbox.receipts.trash
|
97
|
+
#@entity1.mailbox.receipts.trash.count.should==0
|
98
|
+
|
99
|
+
assert @entity2.mailbox.receipts
|
100
|
+
@entity2.mailbox.receipts.count.should==4
|
101
|
+
|
102
|
+
assert @entity2.mailbox.receipts.trash
|
103
|
+
@entity2.mailbox.receipts.trash.count.should==0
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should deleted messages are not shown in inbox" do
|
107
|
+
assert @entity1.mailbox.receipts.inbox
|
108
|
+
@entity1.mailbox.inbox.count.should==2
|
109
|
+
@entity1.mailbox.receipts.inbox[0].should==Receipt.recipient(@entity1).inbox.conversation(@conversation)[0]
|
110
|
+
@entity1.mailbox.receipts.inbox[1].should==Receipt.recipient(@entity1).inbox.conversation(@conversation)[1]
|
111
|
+
|
112
|
+
assert @entity1.mailbox.receipts.inbox.mark_as_deleted
|
113
|
+
@entity1.mailbox.inbox.count.should==0
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should deleted messages are not shown in sentbox" do
|
117
|
+
assert @entity1.mailbox.receipts.inbox
|
118
|
+
@entity1.mailbox.receipts.sentbox.count.should==2
|
119
|
+
@entity1.mailbox.receipts.sentbox[0].should==@receipt1
|
120
|
+
@entity1.mailbox.receipts.sentbox[1].should==@receipt3
|
121
|
+
|
122
|
+
assert @entity1.mailbox.receipts.sentbox.mark_as_deleted
|
123
|
+
@entity1.mailbox.sentbox.count.should==0
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should reply for deleted messages return to inbox" do
|
127
|
+
assert @entity1.mailbox.receipts.inbox
|
128
|
+
@entity1.mailbox.inbox.count.should==2
|
129
|
+
@entity1.mailbox.receipts.inbox[0].should==Receipt.recipient(@entity1).inbox.conversation(@conversation)[0]
|
130
|
+
@entity1.mailbox.receipts.inbox[1].should==Receipt.recipient(@entity1).inbox.conversation(@conversation)[1]
|
131
|
+
|
132
|
+
assert @entity1.mailbox.receipts.inbox.mark_as_deleted
|
133
|
+
@entity1.mailbox.inbox.count.should==0
|
134
|
+
|
135
|
+
@entity2.reply_to_all(@receipt1,"Reply body 1")
|
136
|
+
@entity1.mailbox.inbox.count.should==1
|
137
|
+
|
138
|
+
@entity2.reply_to_all(@receipt3,"Reply body 3")
|
139
|
+
@entity1.mailbox.inbox.count.should==2
|
140
|
+
end
|
141
|
+
|
142
|
+
context "STI models" do
|
143
|
+
before do
|
144
|
+
@sti_entity1 = FactoryGirl.create(:user)
|
145
|
+
@sti_entity2 = FactoryGirl.create(:user)
|
146
|
+
@sti_mail = @sti_entity1.send_message(@sti_entity2, "Body", "Subject")
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should add one to senders sentbox" do
|
150
|
+
@sti_entity1.mailbox.sentbox.count.should==1
|
151
|
+
@sti_entity1.mailbox.sentbox.should include(@sti_mail.conversation)
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should add one to recievers inbox" do
|
155
|
+
@sti_entity2.mailbox.inbox.count.should == 1
|
156
|
+
@sti_entity2.mailbox.inbox.should include(@sti_mail.conversation)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|