message_train 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +20 -0
- data/.ruby-gemset +1 -1
- data/.scss-lint.yml +7 -0
- data/.simplecov +1 -1
- data/.travis.yml +1 -1
- data/Gemfile +6 -2
- data/LICENSE.txt +2 -2
- data/README.rdoc +5 -5
- data/Rakefile +22 -21
- data/VERSION +1 -1
- data/app/assets/javascripts/message_train.js +1 -1
- data/app/assets/stylesheets/message_train.scss +29 -19
- data/app/controllers/concerns/message_train_support.rb +41 -37
- data/app/controllers/message_train/application_controller.rb +1 -0
- data/app/controllers/message_train/boxes_controller.rb +5 -4
- data/app/controllers/message_train/conversations_controller.rb +8 -7
- data/app/controllers/message_train/messages_controller.rb +25 -22
- data/app/controllers/message_train/participants_controller.rb +27 -23
- data/app/controllers/message_train/unsubscribes_controller.rb +37 -23
- data/app/helpers/message_train/application_helper.rb +6 -8
- data/app/helpers/message_train/attachments_helper.rb +12 -4
- data/app/helpers/message_train/boxes_helper.rb +38 -11
- data/app/helpers/message_train/collectives_helper.rb +38 -12
- data/app/helpers/message_train/conversations_helper.rb +43 -35
- data/app/helpers/message_train/messages_helper.rb +32 -25
- data/app/mailers/message_train/application_mailer.rb +7 -4
- data/app/mailers/message_train/previews/receipt_mailer_preview.rb +2 -3
- data/app/mailers/message_train/receipt_mailer.rb +14 -4
- data/app/models/message_train/attachment.rb +41 -25
- data/app/models/message_train/box.rb +159 -122
- data/app/models/message_train/conversation.rb +84 -41
- data/app/models/message_train/ignore.rb +8 -2
- data/app/models/message_train/message.rb +72 -42
- data/app/models/message_train/receipt.rb +30 -17
- data/app/models/message_train/unsubscribe.rb +1 -0
- data/app/views/application/404.html.haml +1 -1
- data/app/views/layouts/mailer.html.haml +2 -2
- data/app/views/layouts/mailer.text.haml +1 -1
- data/app/views/message_train/application/_attachment_fields.html.haml +1 -1
- data/app/views/message_train/application/_widget.html.haml +1 -1
- data/app/views/message_train/application/results.json.jbuilder +1 -1
- data/app/views/message_train/boxes/_dropdown_list.html.haml +1 -1
- data/app/views/message_train/boxes/_list_item.html.haml +1 -1
- data/app/views/message_train/boxes/show.html.haml +1 -1
- data/app/views/message_train/collectives/_dropdown_list.html.haml +1 -1
- data/app/views/message_train/collectives/_list_item.html.haml +1 -1
- data/app/views/message_train/conversations/_deleted_toggle.html.haml +1 -1
- data/app/views/message_train/conversations/_ignored_toggle.html.haml +2 -2
- data/app/views/message_train/conversations/_read_toggle.html.haml +1 -1
- data/app/views/message_train/conversations/_toggle.html.haml +1 -1
- data/app/views/message_train/conversations/_trashed_toggle.html.haml +1 -1
- data/app/views/message_train/conversations/show.html.haml +2 -2
- data/app/views/message_train/conversations/show.json.jbuilder +5 -1
- data/app/views/message_train/messages/_form.html.haml +1 -1
- data/app/views/message_train/messages/_message.html.haml +6 -6
- data/app/views/message_train/messages/_toggle.html.haml +1 -1
- data/app/views/message_train/messages/show.json.jbuilder +5 -1
- data/app/views/message_train/participants/_participant.json.jbuilder +1 -1
- data/app/views/message_train/participants/index.json.jbuilder +1 -1
- data/app/views/message_train/participants/show.json.jbuilder +1 -1
- data/app/views/message_train/receipt_mailer/notification_email.html.haml +1 -1
- data/app/views/message_train/receipt_mailer/notification_email.text.haml +1 -1
- data/app/views/message_train/unsubscribes/index.html.haml +1 -1
- data/config/environment.rb +1 -1
- data/config/initializers/date_time.rb +2 -2
- data/config/locales/en.yml +1 -1
- data/config/routes.rb +37 -15
- data/lib/generators/message_train/install/install_generator.rb +26 -11
- data/lib/generators/message_train/install/templates/initializer.rb +0 -2
- data/lib/generators/message_train/utils.rb +11 -4
- data/lib/message_train/configuration.rb +4 -5
- data/lib/message_train/engine.rb +1 -7
- data/lib/message_train/localization.rb +14 -18
- data/lib/message_train/mixin.rb +211 -150
- data/lib/message_train/version.rb +1 -0
- data/lib/message_train.rb +7 -6
- data/message_train.gemspec +24 -11
- data/spec/controllers/message_train/boxes_controller_spec.rb +63 -15
- data/spec/controllers/message_train/concerns_spec.rb +17 -13
- data/spec/controllers/message_train/conversations_controller_spec.rb +44 -12
- data/spec/controllers/message_train/messages_controller_spec.rb +87 -40
- data/spec/controllers/message_train/participants_controller_spec.rb +10 -4
- data/spec/controllers/message_train/unsubscribes_controller_spec.rb +43 -13
- data/spec/dummy/Rakefile +2 -1
- data/spec/dummy/app/assets/stylesheets/application.css.scss +7 -23
- data/spec/dummy/app/controllers/application_controller.rb +7 -7
- data/spec/dummy/app/models/group.rb +1 -1
- data/spec/dummy/app/models/role.rb +11 -7
- data/spec/dummy/app/models/user.rb +6 -5
- data/spec/dummy/app/views/layouts/_top_navigation.html.haml +1 -1
- data/spec/dummy/app/views/layouts/application.html.haml +1 -1
- data/spec/dummy/app/views/pages/index.html.haml +1 -1
- data/spec/dummy/config/application.rb +23 -17
- data/spec/dummy/config/environments/development.rb +5 -4
- data/spec/dummy/config/environments/production.rb +10 -6
- data/spec/dummy/config/environments/test.rb +4 -3
- data/spec/dummy/config/initializers/assets.rb +2 -1
- data/spec/dummy/config/initializers/backtrace_silencers.rb +4 -2
- data/spec/dummy/config/initializers/bootstrap_leather.rb +1 -1
- data/spec/dummy/config/initializers/devise.rb +63 -44
- data/spec/dummy/config/initializers/high_voltage.rb +1 -1
- data/spec/dummy/config/initializers/message_train.rb +5 -2
- data/spec/dummy/config/initializers/mime_types.rb +1 -1
- data/spec/dummy/config/initializers/paperclip.rb +5 -2
- data/spec/dummy/config/initializers/rolify.rb +3 -2
- data/spec/dummy/config/initializers/wrap_parameters.rb +2 -1
- data/spec/dummy/config/routes.rb +1 -3
- data/spec/dummy/config/settings.yml +1 -1
- data/spec/dummy/db/schema.rb +98 -98
- data/spec/dummy/db/seeds/conversations.seeds.rb +160 -160
- data/spec/dummy/db/seeds/development/conversations.seeds.rb +6 -2
- data/spec/dummy/db/seeds/groups.seeds.rb +11 -12
- data/spec/dummy/db/seeds/test/attachments.seeds.rb +13 -3
- data/spec/dummy/db/seeds/test/conversations.seeds.rb +6 -2
- data/spec/dummy/db/seeds/unsubscribes.seeds.rb +1 -1
- data/spec/dummy/db/seeds/users.seeds.rb +47 -42
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/factories/attachment.rb +6 -2
- data/spec/factories/group.rb +1 -4
- data/spec/factories/message.rb +29 -23
- data/spec/factories/user.rb +6 -4
- data/spec/features/boxes_spec.rb +76 -24
- data/spec/features/conversations_spec.rb +19 -7
- data/spec/features/messages_spec.rb +24 -5
- data/spec/features/unsubscribes_spec.rb +36 -9
- data/spec/helpers/message_train/application_helper_spec.rb +1 -1
- data/spec/helpers/message_train/attachment_helper_spec.rb +27 -12
- data/spec/helpers/message_train/boxes_helper_spec.rb +1 -1
- data/spec/helpers/message_train/collectives_helper_spec.rb +25 -9
- data/spec/helpers/message_train/conversations_helper_spec.rb +239 -120
- data/spec/helpers/message_train/messages_helper_spec.rb +137 -81
- data/spec/message_train_spec.rb +3 -2
- data/spec/models/group_spec.rb +12 -9
- data/spec/models/message_train/attachment_spec.rb +33 -30
- data/spec/models/message_train/box_spec.rb +243 -60
- data/spec/models/message_train/conversation_spec.rb +16 -12
- data/spec/models/message_train/ignore_spec.rb +3 -1
- data/spec/models/message_train/message_spec.rb +22 -7
- data/spec/models/message_train/receipt_spec.rb +14 -4
- data/spec/models/role_spec.rb +10 -6
- data/spec/models/user_spec.rb +74 -22
- data/spec/rails_helper.rb +9 -4
- data/spec/spec_helper.rb +6 -54
- data/spec/support/controller_behaviors.rb +8 -5
- data/spec/support/controller_macros.rb +2 -2
- data/spec/support/factory_girl.rb +1 -1
- data/spec/support/feature_behaviors.rb +42 -13
- data/spec/support/loaded_site/attachments.rb +8 -0
- data/spec/support/loaded_site/conversations.rb +73 -0
- data/spec/support/{groups.rb → loaded_site/groups.rb} +1 -1
- data/spec/support/{loaded_site.rb → loaded_site/loaded_site.rb} +1 -1
- data/spec/support/{messages.rb → loaded_site/messages.rb} +13 -5
- data/spec/support/{roles.rb → loaded_site/roles.rb} +1 -1
- data/spec/support/{users.rb → loaded_site/users.rb} +1 -1
- data/spec/support/shared_connection.rb +8 -6
- data/spec/support/utilities.rb +10 -10
- metadata +67 -10
- data/spec/dummy/config/unused/temporary_i18n_debugging.rb +0 -12
- data/spec/support/attachments.rb +0 -4
- data/spec/support/conversations.rb +0 -23
@@ -5,15 +5,29 @@ describe MessageTrain::BoxesController do
|
|
5
5
|
include ControllerMacros
|
6
6
|
routes { MessageTrain::Engine.routes }
|
7
7
|
|
8
|
-
let(:valid_params)
|
9
|
-
|
10
|
-
|
8
|
+
let(:valid_params) do
|
9
|
+
{
|
10
|
+
'conversations' => {
|
11
|
+
unread_conversation.id.to_s => unread_conversation.id
|
12
|
+
}
|
13
|
+
}
|
14
|
+
end
|
15
|
+
let(:invalid_params) do
|
16
|
+
{ 'conversations' => { '999' => 999 } }
|
17
|
+
end
|
18
|
+
let(:disallowed_params) do
|
19
|
+
{
|
20
|
+
'conversations' => {
|
21
|
+
someone_elses_conversation.id.to_s => someone_elses_conversation.id
|
22
|
+
}
|
23
|
+
}
|
24
|
+
end
|
11
25
|
|
12
26
|
before do
|
13
27
|
login_user first_user
|
14
28
|
end
|
15
29
|
|
16
|
-
describe
|
30
|
+
describe 'GET #show' do
|
17
31
|
before do
|
18
32
|
get :show, division: 'in'
|
19
33
|
end
|
@@ -31,18 +45,31 @@ describe MessageTrain::BoxesController do
|
|
31
45
|
end
|
32
46
|
end
|
33
47
|
|
34
|
-
describe
|
48
|
+
describe 'PATCH/PUT #update' do
|
35
49
|
describe 'with invalid params' do
|
36
50
|
before do
|
37
|
-
put
|
51
|
+
put(
|
52
|
+
:update,
|
53
|
+
division: 'in',
|
54
|
+
mark_to_set: 'read',
|
55
|
+
objects: invalid_params
|
56
|
+
)
|
38
57
|
end
|
39
58
|
it_should_behave_like 'a 404 Not Found error'
|
40
59
|
end
|
41
60
|
describe 'with disallowed params' do
|
42
61
|
before do
|
43
|
-
put
|
62
|
+
put(
|
63
|
+
:update,
|
64
|
+
division: 'in',
|
65
|
+
mark_to_set: 'read',
|
66
|
+
objects: disallowed_params
|
67
|
+
)
|
44
68
|
end
|
45
|
-
it_should_behave_like
|
69
|
+
it_should_behave_like(
|
70
|
+
'a page with an error message matching',
|
71
|
+
/Access to Conversation \d+ denied/
|
72
|
+
)
|
46
73
|
end
|
47
74
|
describe 'without params' do
|
48
75
|
before do
|
@@ -58,10 +85,15 @@ describe MessageTrain::BoxesController do
|
|
58
85
|
end
|
59
86
|
end
|
60
87
|
|
61
|
-
describe
|
88
|
+
describe 'DELETE #destroy' do
|
62
89
|
describe 'with invalid params' do
|
63
90
|
before do
|
64
|
-
delete
|
91
|
+
delete(
|
92
|
+
:destroy,
|
93
|
+
division: 'in',
|
94
|
+
mark_to_set: 'ignore',
|
95
|
+
objects: invalid_params
|
96
|
+
)
|
65
97
|
end
|
66
98
|
it_should_behave_like 'a 404 Not Found error'
|
67
99
|
end
|
@@ -74,16 +106,32 @@ describe MessageTrain::BoxesController do
|
|
74
106
|
describe 'with valid params' do
|
75
107
|
context 'ignoring' do
|
76
108
|
before do
|
77
|
-
delete
|
109
|
+
delete(
|
110
|
+
:destroy,
|
111
|
+
division: 'in',
|
112
|
+
mark_to_set: 'ignore',
|
113
|
+
objects: valid_params
|
114
|
+
)
|
78
115
|
end
|
79
|
-
it_should_behave_like
|
116
|
+
it_should_behave_like(
|
117
|
+
'a page with a notice message',
|
118
|
+
'Update successful'
|
119
|
+
)
|
80
120
|
end
|
81
121
|
context 'unignoring' do
|
82
122
|
before do
|
83
|
-
delete
|
123
|
+
delete(
|
124
|
+
:destroy,
|
125
|
+
division: 'in',
|
126
|
+
mark_to_set: 'unignore',
|
127
|
+
objects: valid_params
|
128
|
+
)
|
84
129
|
end
|
85
|
-
it_should_behave_like
|
130
|
+
it_should_behave_like(
|
131
|
+
'a page with a notice message',
|
132
|
+
'Update successful'
|
133
|
+
)
|
86
134
|
end
|
87
135
|
end
|
88
136
|
end
|
89
|
-
end
|
137
|
+
end
|
@@ -5,21 +5,17 @@ describe MessageTrain::BoxesController do
|
|
5
5
|
include ControllerMacros
|
6
6
|
routes { MessageTrain::Engine.routes }
|
7
7
|
|
8
|
-
describe
|
9
|
-
# describe 'when not logged in' do
|
10
|
-
# before do
|
11
|
-
# access_anonymous
|
12
|
-
# get :show, division: 'in'
|
13
|
-
# end
|
14
|
-
# it_should_behave_like 'a redirect with error', '/users/sign_in', 'You must sign in or sign up to continue.'
|
15
|
-
# end
|
16
|
-
|
8
|
+
describe 'GET #show' do
|
17
9
|
describe 'when neither sending nor receiving is allowed' do
|
18
10
|
before do
|
19
11
|
login_user third_user
|
20
12
|
get :show, division: 'in', collective_id: 'groups:first-group'
|
21
13
|
end
|
22
|
-
it_should_behave_like
|
14
|
+
it_should_behave_like(
|
15
|
+
'a redirect with error',
|
16
|
+
'/',
|
17
|
+
'Access to that box denied'
|
18
|
+
)
|
23
19
|
end
|
24
20
|
|
25
21
|
describe 'when only sending is allowed' do
|
@@ -27,7 +23,11 @@ describe MessageTrain::BoxesController do
|
|
27
23
|
login_user first_user
|
28
24
|
get :show, division: 'in', collective_id: 'groups:first-group'
|
29
25
|
end
|
30
|
-
it_should_behave_like
|
26
|
+
it_should_behave_like(
|
27
|
+
'a redirect with error',
|
28
|
+
'/collectives/groups:first-group/box/sent',
|
29
|
+
'Access to that box denied'
|
30
|
+
)
|
31
31
|
end
|
32
32
|
|
33
33
|
describe 'when only receiving is allowed' do
|
@@ -35,7 +35,11 @@ describe MessageTrain::BoxesController do
|
|
35
35
|
login_user first_user
|
36
36
|
get :show, division: 'sent', collective_id: 'groups:membered-group'
|
37
37
|
end
|
38
|
-
it_should_behave_like
|
38
|
+
it_should_behave_like(
|
39
|
+
'a redirect with error',
|
40
|
+
'/collectives/groups:membered-group/box/in',
|
41
|
+
'Access to that box denied'
|
42
|
+
)
|
39
43
|
end
|
40
44
|
end
|
41
|
-
end
|
45
|
+
end
|
@@ -5,14 +5,18 @@ describe MessageTrain::ConversationsController do
|
|
5
5
|
include ControllerMacros
|
6
6
|
routes { MessageTrain::Engine.routes }
|
7
7
|
|
8
|
-
let(:valid_params)
|
9
|
-
|
8
|
+
let(:valid_params) do
|
9
|
+
{ 'messages' => { unread_message.id.to_s => unread_message.id } }
|
10
|
+
end
|
11
|
+
let(:invalid_params) do
|
12
|
+
{ 'messages' => { '999999' => 999_999 } }
|
13
|
+
end
|
10
14
|
|
11
15
|
before do
|
12
16
|
login_user first_user
|
13
17
|
end
|
14
18
|
|
15
|
-
describe
|
19
|
+
describe 'GET #show' do
|
16
20
|
before do
|
17
21
|
get :show, box_division: 'in', id: unread_conversation.id
|
18
22
|
end
|
@@ -34,10 +38,16 @@ describe MessageTrain::ConversationsController do
|
|
34
38
|
end
|
35
39
|
end
|
36
40
|
|
37
|
-
describe
|
41
|
+
describe 'PATCH/PUT #update' do
|
38
42
|
describe 'with invalid params' do
|
39
43
|
before do
|
40
|
-
put
|
44
|
+
put(
|
45
|
+
:update,
|
46
|
+
box_division: 'in',
|
47
|
+
id: unread_conversation.id,
|
48
|
+
mark_to_set: 'read',
|
49
|
+
objects: invalid_params
|
50
|
+
)
|
41
51
|
end
|
42
52
|
it_should_behave_like 'a 404 Not Found error'
|
43
53
|
end
|
@@ -49,13 +59,19 @@ describe MessageTrain::ConversationsController do
|
|
49
59
|
end
|
50
60
|
describe 'with valid params' do
|
51
61
|
before do
|
52
|
-
put
|
62
|
+
put(
|
63
|
+
:update,
|
64
|
+
box_division: 'in',
|
65
|
+
id: unread_conversation.id,
|
66
|
+
mark_to_set: 'read',
|
67
|
+
objects: valid_params
|
68
|
+
)
|
53
69
|
end
|
54
70
|
it_should_behave_like 'a page with a notice message', 'Update successful'
|
55
71
|
end
|
56
72
|
end
|
57
73
|
|
58
|
-
describe
|
74
|
+
describe 'DELETE #destroy' do
|
59
75
|
describe 'with invalid params' do
|
60
76
|
before do
|
61
77
|
delete :destroy, box_division: 'in', id: 999, mark_to_set: 'ignore'
|
@@ -71,16 +87,32 @@ describe MessageTrain::ConversationsController do
|
|
71
87
|
describe 'with valid params' do
|
72
88
|
context 'ignoring' do
|
73
89
|
before do
|
74
|
-
delete
|
90
|
+
delete(
|
91
|
+
:destroy,
|
92
|
+
box_division: 'in',
|
93
|
+
id: unread_conversation.id,
|
94
|
+
mark_to_set: 'ignore'
|
95
|
+
)
|
75
96
|
end
|
76
|
-
it_should_behave_like
|
97
|
+
it_should_behave_like(
|
98
|
+
'a page with a notice message',
|
99
|
+
'Update successful'
|
100
|
+
)
|
77
101
|
end
|
78
102
|
context 'unignoring' do
|
79
103
|
before do
|
80
|
-
delete
|
104
|
+
delete(
|
105
|
+
:destroy,
|
106
|
+
box_division: 'in',
|
107
|
+
id: unread_conversation.id,
|
108
|
+
mark_to_set: 'unignore'
|
109
|
+
)
|
81
110
|
end
|
82
|
-
it_should_behave_like
|
111
|
+
it_should_behave_like(
|
112
|
+
'a page with a notice message',
|
113
|
+
'Update successful'
|
114
|
+
)
|
83
115
|
end
|
84
116
|
end
|
85
117
|
end
|
86
|
-
end
|
118
|
+
end
|
@@ -8,23 +8,27 @@ describe MessageTrain::MessagesController do
|
|
8
8
|
# This should return the minimal set of attributes required to create a valid
|
9
9
|
# Dog. As you add validations to Dog, be sure to
|
10
10
|
# adjust the attributes here as well.
|
11
|
-
let(:valid_attributes)
|
12
|
-
{
|
13
|
-
|
11
|
+
let(:valid_attributes) do
|
12
|
+
{
|
13
|
+
subject: 'Test Subject',
|
14
|
+
recipients_to_save: { 'users' => 'second-user, third-user' },
|
15
|
+
draft: false
|
16
|
+
}
|
17
|
+
end
|
14
18
|
|
15
|
-
let(:draft_attributes)
|
16
|
-
{ subject: 'Test Subject', recipients_to_save: {'users' => ''} }
|
17
|
-
|
19
|
+
let(:draft_attributes) do
|
20
|
+
{ subject: 'Test Subject', recipients_to_save: { 'users' => '' } }
|
21
|
+
end
|
18
22
|
|
19
|
-
let(:invalid_attributes)
|
23
|
+
let(:invalid_attributes) do
|
20
24
|
{ subject: nil }
|
21
|
-
|
25
|
+
end
|
22
26
|
|
23
27
|
before do
|
24
28
|
login_user first_user
|
25
29
|
end
|
26
30
|
|
27
|
-
describe
|
31
|
+
describe 'GET #show' do
|
28
32
|
before do
|
29
33
|
get :show, box_division: 'in', id: unread_message.id, format: :json
|
30
34
|
end
|
@@ -41,9 +45,13 @@ describe MessageTrain::MessagesController do
|
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
44
|
-
describe
|
48
|
+
describe 'GET #new' do
|
45
49
|
before do
|
46
|
-
get
|
50
|
+
get(
|
51
|
+
:new,
|
52
|
+
box_division: 'in',
|
53
|
+
conversation_id: unread_message.message_train_conversation_id
|
54
|
+
)
|
47
55
|
end
|
48
56
|
it_should_behave_like 'a successful page', which_renders: 'new'
|
49
57
|
|
@@ -59,7 +67,7 @@ describe MessageTrain::MessagesController do
|
|
59
67
|
end
|
60
68
|
end
|
61
69
|
|
62
|
-
describe
|
70
|
+
describe 'GET #edit' do
|
63
71
|
describe 'as someone other than the owner' do
|
64
72
|
before do
|
65
73
|
get :edit, box_division: 'in', id: someone_elses_message.id
|
@@ -87,7 +95,7 @@ describe MessageTrain::MessagesController do
|
|
87
95
|
end
|
88
96
|
end
|
89
97
|
|
90
|
-
describe
|
98
|
+
describe 'POST #create' do
|
91
99
|
describe 'with valid attributes' do
|
92
100
|
describe 'when draft' do
|
93
101
|
before do
|
@@ -98,7 +106,7 @@ describe MessageTrain::MessagesController do
|
|
98
106
|
|
99
107
|
context "sets the flash with an alert of the messages's draft status" do
|
100
108
|
subject { flash[:alert] }
|
101
|
-
it { should eq 'Message saved as draft.'}
|
109
|
+
it { should eq 'Message saved as draft.' }
|
102
110
|
end
|
103
111
|
end
|
104
112
|
describe 'when not draft' do
|
@@ -110,22 +118,30 @@ describe MessageTrain::MessagesController do
|
|
110
118
|
|
111
119
|
context "sets the flash with a notice of the messages's creation" do
|
112
120
|
subject { flash[:notice] }
|
113
|
-
it { should eq 'Message sent.'}
|
121
|
+
it { should eq 'Message sent.' }
|
114
122
|
end
|
115
123
|
end
|
116
124
|
end
|
117
125
|
describe 'with valid attributes, counting' do
|
118
126
|
it 'results in a new conversation' do
|
119
|
-
expect
|
127
|
+
expect do
|
128
|
+
post(:create, box_division: 'in', message: valid_attributes)
|
129
|
+
end.to change { MessageTrain::Conversation.count }.by(1)
|
120
130
|
end
|
121
131
|
it 'results in a new message' do
|
122
|
-
expect
|
132
|
+
expect do
|
133
|
+
post(:create, box_division: 'in', message: valid_attributes)
|
134
|
+
end.to change { MessageTrain::Message.count }.by(1)
|
123
135
|
end
|
124
136
|
it 'results in new receipts' do
|
125
|
-
expect
|
137
|
+
expect do
|
138
|
+
post(:create, box_division: 'in', message: valid_attributes)
|
139
|
+
end.to change { MessageTrain::Receipt.count }.by(3)
|
126
140
|
end
|
127
141
|
it 'results in email notifications' do
|
128
|
-
expect
|
142
|
+
expect do
|
143
|
+
post(:create, box_division: 'in', message: valid_attributes)
|
144
|
+
end.to change { ActionMailer::Base.deliveries.count }.by(2)
|
129
145
|
end
|
130
146
|
end
|
131
147
|
describe 'with invalid params' do
|
@@ -141,58 +157,76 @@ describe MessageTrain::MessagesController do
|
|
141
157
|
|
142
158
|
context "sets the flash with the message's errors" do
|
143
159
|
subject { flash[:error] }
|
144
|
-
it { should eq "Subject can't be blank"}
|
160
|
+
it { should eq "Subject can't be blank" }
|
145
161
|
end
|
146
162
|
end
|
147
163
|
|
148
164
|
describe 'with invalid params, counting' do
|
149
165
|
it 'does not result in a new message' do
|
150
|
-
expect
|
166
|
+
expect do
|
167
|
+
post :create, box_division: 'in', message: invalid_attributes
|
168
|
+
end.to_not change { MessageTrain::Message.count }
|
151
169
|
end
|
152
170
|
end
|
153
171
|
end
|
154
172
|
|
155
|
-
describe
|
173
|
+
describe 'PUT #update' do
|
156
174
|
describe 'as someone other than the owner' do
|
157
175
|
before do
|
158
|
-
put
|
176
|
+
put(
|
177
|
+
:update,
|
178
|
+
box_division: 'in',
|
179
|
+
id: someone_elses_message.id,
|
180
|
+
message: valid_attributes
|
181
|
+
)
|
159
182
|
end
|
160
183
|
it_should_behave_like 'a 404 Not Found error'
|
161
184
|
end
|
162
185
|
describe 'as the owner' do
|
163
186
|
describe 'with invalid params' do
|
164
187
|
before do
|
165
|
-
put
|
188
|
+
put(
|
189
|
+
:update,
|
190
|
+
box_division: 'in',
|
191
|
+
id: draft_message.id,
|
192
|
+
message: invalid_attributes
|
193
|
+
)
|
166
194
|
end
|
167
195
|
it_should_behave_like 'a successful page', which_renders: 'edit'
|
168
|
-
|
169
196
|
context 'loads the given message into @message' do
|
170
197
|
subject { assigns(:message) }
|
171
198
|
it { should eq draft_message }
|
172
199
|
end
|
173
|
-
|
174
200
|
context 'does not update @message' do
|
175
201
|
subject { draft_message.reload }
|
176
202
|
its(:subject) { should eq 'This should turn into a draft' }
|
177
203
|
end
|
178
|
-
|
179
204
|
context "sets the flash with the message's errors" do
|
180
205
|
subject { flash[:error] }
|
181
|
-
it { should eq "Subject can't be blank"}
|
206
|
+
it { should eq "Subject can't be blank" }
|
182
207
|
end
|
183
208
|
end
|
184
209
|
describe 'with valid params' do
|
185
210
|
describe 'when not a draft' do
|
186
211
|
before do
|
187
|
-
put
|
212
|
+
put(
|
213
|
+
:update,
|
214
|
+
box_division: 'in',
|
215
|
+
id: sent_message.id,
|
216
|
+
message: valid_attributes
|
217
|
+
)
|
188
218
|
end
|
189
219
|
it_should_behave_like 'a 404 Not Found error'
|
190
220
|
end
|
191
221
|
describe 'when a draft' do
|
192
222
|
describe 'and updating to not draft' do
|
193
|
-
|
194
223
|
before do
|
195
|
-
put
|
224
|
+
put(
|
225
|
+
:update,
|
226
|
+
box_division: 'in',
|
227
|
+
id: draft_message.id,
|
228
|
+
message: valid_attributes
|
229
|
+
)
|
196
230
|
end
|
197
231
|
it_should_behave_like 'a redirect to', '/box/sent'
|
198
232
|
it_should_behave_like 'a response without error'
|
@@ -202,22 +236,36 @@ describe MessageTrain::MessagesController do
|
|
202
236
|
its(:subject) { should eq 'Test Subject' }
|
203
237
|
end
|
204
238
|
|
205
|
-
context
|
239
|
+
context 'sets no alert' do
|
206
240
|
subject { flash[:alert] }
|
207
241
|
it { should be nil }
|
208
242
|
end
|
209
243
|
|
210
244
|
context "sets the flash with a notice of the message's update" do
|
211
245
|
subject { flash[:notice] }
|
212
|
-
it { should eq 'Message sent.'}
|
246
|
+
it { should eq 'Message sent.' }
|
213
247
|
end
|
214
248
|
end
|
215
249
|
describe 'and updating but keeping as a draft' do
|
216
|
-
let(:edited_draft_message)
|
250
|
+
let(:edited_draft_message) do
|
251
|
+
{
|
252
|
+
id: draft_message.id,
|
253
|
+
subject: 'Still a draft',
|
254
|
+
draft: 'Save As Draft'
|
255
|
+
}
|
256
|
+
end
|
217
257
|
before do
|
218
|
-
put
|
258
|
+
put(
|
259
|
+
:update,
|
260
|
+
box_division: 'in',
|
261
|
+
id: draft_message.id,
|
262
|
+
message: edited_draft_message
|
263
|
+
)
|
219
264
|
end
|
220
|
-
it_should_behave_like
|
265
|
+
it_should_behave_like(
|
266
|
+
'a redirect matching',
|
267
|
+
%r{/box/in/conversations/\d+}
|
268
|
+
)
|
221
269
|
it_should_behave_like 'a response without error'
|
222
270
|
|
223
271
|
context 'updates @message' do
|
@@ -225,19 +273,18 @@ describe MessageTrain::MessagesController do
|
|
225
273
|
its(:subject) { should eq 'Still a draft' }
|
226
274
|
end
|
227
275
|
|
228
|
-
context
|
276
|
+
context 'sets no notice' do
|
229
277
|
subject { flash[:notice] }
|
230
278
|
it { should be nil }
|
231
279
|
end
|
232
280
|
|
233
281
|
context "sets the flash with a alert of the message's update" do
|
234
282
|
subject { flash[:alert] }
|
235
|
-
it { should eq 'Message saved as draft.'}
|
283
|
+
it { should eq 'Message saved as draft.' }
|
236
284
|
end
|
237
285
|
end
|
238
286
|
end
|
239
287
|
end
|
240
|
-
|
241
288
|
end
|
242
289
|
end
|
243
|
-
end
|
290
|
+
end
|
@@ -9,7 +9,7 @@ describe MessageTrain::ParticipantsController do
|
|
9
9
|
login_user first_user
|
10
10
|
end
|
11
11
|
|
12
|
-
describe
|
12
|
+
describe 'GET #index' do
|
13
13
|
describe 'with model to users' do
|
14
14
|
before do
|
15
15
|
get :index, box_division: 'in', model: 'users', format: :json
|
@@ -56,9 +56,15 @@ describe MessageTrain::ParticipantsController do
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
describe
|
59
|
+
describe 'GET #show' do
|
60
60
|
before do
|
61
|
-
get
|
61
|
+
get(
|
62
|
+
:show,
|
63
|
+
box_division: 'in',
|
64
|
+
model: 'users',
|
65
|
+
id: first_user.id,
|
66
|
+
format: :json
|
67
|
+
)
|
62
68
|
end
|
63
69
|
it_should_behave_like 'a successful page', which_renders: 'show'
|
64
70
|
|
@@ -67,4 +73,4 @@ describe MessageTrain::ParticipantsController do
|
|
67
73
|
it { should eq first_user }
|
68
74
|
end
|
69
75
|
end
|
70
|
-
end
|
76
|
+
end
|
@@ -5,19 +5,19 @@ describe MessageTrain::UnsubscribesController do
|
|
5
5
|
include ControllerMacros
|
6
6
|
routes { MessageTrain::Engine.routes }
|
7
7
|
|
8
|
-
let(:valid_attributes)
|
8
|
+
let(:valid_attributes) do
|
9
9
|
{ from_type: 'Group', from_id: membered_group.id }
|
10
|
-
|
10
|
+
end
|
11
11
|
|
12
|
-
let(:invalid_attributes)
|
12
|
+
let(:invalid_attributes) do
|
13
13
|
{ from_type: 'Group', from_id: empty_group.id }
|
14
|
-
|
14
|
+
end
|
15
15
|
|
16
16
|
before do
|
17
17
|
login_user first_user
|
18
18
|
end
|
19
19
|
|
20
|
-
describe
|
20
|
+
describe 'GET #index' do
|
21
21
|
before do
|
22
22
|
get :index
|
23
23
|
end
|
@@ -30,7 +30,7 @@ describe MessageTrain::UnsubscribesController do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
describe
|
33
|
+
describe 'POST #create' do
|
34
34
|
describe 'with invalid attributes' do
|
35
35
|
before do
|
36
36
|
post :create, unsubscribe: invalid_attributes
|
@@ -41,30 +41,60 @@ describe MessageTrain::UnsubscribesController do
|
|
41
41
|
before do
|
42
42
|
post :create, unsubscribe: valid_attributes
|
43
43
|
end
|
44
|
-
it_should_behave_like
|
44
|
+
it_should_behave_like(
|
45
|
+
'a redirect with a message',
|
46
|
+
'/unsubscribes',
|
47
|
+
notice: 'You are now unsubscribed from Membered Group, which means '\
|
48
|
+
'that you will not be notified by email of any messages received by '\
|
49
|
+
'that Group.'
|
50
|
+
)
|
45
51
|
it_should_behave_like 'a response without error'
|
46
52
|
end
|
47
53
|
describe 'with :all set to true' do
|
48
54
|
before do
|
49
55
|
post :create, all: true
|
50
56
|
end
|
51
|
-
it_should_behave_like
|
57
|
+
it_should_behave_like(
|
58
|
+
'a redirect with a message',
|
59
|
+
'/unsubscribes',
|
60
|
+
notice: 'You have unsubscribed from all messages, which means that '\
|
61
|
+
'you will not be notified by email of any messages received in any '\
|
62
|
+
'of your boxes.'
|
63
|
+
)
|
52
64
|
it_should_behave_like 'a response without error'
|
53
65
|
end
|
54
66
|
end
|
55
67
|
|
56
|
-
describe
|
68
|
+
describe 'DELETE #destroy' do
|
57
69
|
describe 'with an id' do
|
58
70
|
before do
|
59
|
-
delete
|
71
|
+
delete(
|
72
|
+
:destroy,
|
73
|
+
id: first_user.unsubscribes.where(
|
74
|
+
from_type: 'Group',
|
75
|
+
from_id: unsubscribed_group.id
|
76
|
+
).first.id
|
77
|
+
)
|
60
78
|
end
|
61
|
-
it_should_behave_like
|
79
|
+
it_should_behave_like(
|
80
|
+
'a redirect with a message',
|
81
|
+
'/unsubscribes',
|
82
|
+
notice: 'You are no longer unsubscribed from Unsubscribed Group, '\
|
83
|
+
'which means that you will now be notified by email of any '\
|
84
|
+
'messages received in that Group.'
|
85
|
+
)
|
62
86
|
end
|
63
87
|
describe 'with :all set to true' do
|
64
88
|
before do
|
65
89
|
delete :destroy, all: true
|
66
90
|
end
|
67
|
-
it_should_behave_like
|
91
|
+
it_should_behave_like(
|
92
|
+
'a redirect with a message',
|
93
|
+
'/unsubscribes',
|
94
|
+
notice: 'You are no longer unsubscribed from all messages, which '\
|
95
|
+
'means that you will now be notified by email of any messages '\
|
96
|
+
'received in boxes you are subscribed to.'
|
97
|
+
)
|
68
98
|
end
|
69
99
|
end
|
70
|
-
end
|
100
|
+
end
|