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.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +20 -0
  3. data/.ruby-gemset +1 -1
  4. data/.scss-lint.yml +7 -0
  5. data/.simplecov +1 -1
  6. data/.travis.yml +1 -1
  7. data/Gemfile +6 -2
  8. data/LICENSE.txt +2 -2
  9. data/README.rdoc +5 -5
  10. data/Rakefile +22 -21
  11. data/VERSION +1 -1
  12. data/app/assets/javascripts/message_train.js +1 -1
  13. data/app/assets/stylesheets/message_train.scss +29 -19
  14. data/app/controllers/concerns/message_train_support.rb +41 -37
  15. data/app/controllers/message_train/application_controller.rb +1 -0
  16. data/app/controllers/message_train/boxes_controller.rb +5 -4
  17. data/app/controllers/message_train/conversations_controller.rb +8 -7
  18. data/app/controllers/message_train/messages_controller.rb +25 -22
  19. data/app/controllers/message_train/participants_controller.rb +27 -23
  20. data/app/controllers/message_train/unsubscribes_controller.rb +37 -23
  21. data/app/helpers/message_train/application_helper.rb +6 -8
  22. data/app/helpers/message_train/attachments_helper.rb +12 -4
  23. data/app/helpers/message_train/boxes_helper.rb +38 -11
  24. data/app/helpers/message_train/collectives_helper.rb +38 -12
  25. data/app/helpers/message_train/conversations_helper.rb +43 -35
  26. data/app/helpers/message_train/messages_helper.rb +32 -25
  27. data/app/mailers/message_train/application_mailer.rb +7 -4
  28. data/app/mailers/message_train/previews/receipt_mailer_preview.rb +2 -3
  29. data/app/mailers/message_train/receipt_mailer.rb +14 -4
  30. data/app/models/message_train/attachment.rb +41 -25
  31. data/app/models/message_train/box.rb +159 -122
  32. data/app/models/message_train/conversation.rb +84 -41
  33. data/app/models/message_train/ignore.rb +8 -2
  34. data/app/models/message_train/message.rb +72 -42
  35. data/app/models/message_train/receipt.rb +30 -17
  36. data/app/models/message_train/unsubscribe.rb +1 -0
  37. data/app/views/application/404.html.haml +1 -1
  38. data/app/views/layouts/mailer.html.haml +2 -2
  39. data/app/views/layouts/mailer.text.haml +1 -1
  40. data/app/views/message_train/application/_attachment_fields.html.haml +1 -1
  41. data/app/views/message_train/application/_widget.html.haml +1 -1
  42. data/app/views/message_train/application/results.json.jbuilder +1 -1
  43. data/app/views/message_train/boxes/_dropdown_list.html.haml +1 -1
  44. data/app/views/message_train/boxes/_list_item.html.haml +1 -1
  45. data/app/views/message_train/boxes/show.html.haml +1 -1
  46. data/app/views/message_train/collectives/_dropdown_list.html.haml +1 -1
  47. data/app/views/message_train/collectives/_list_item.html.haml +1 -1
  48. data/app/views/message_train/conversations/_deleted_toggle.html.haml +1 -1
  49. data/app/views/message_train/conversations/_ignored_toggle.html.haml +2 -2
  50. data/app/views/message_train/conversations/_read_toggle.html.haml +1 -1
  51. data/app/views/message_train/conversations/_toggle.html.haml +1 -1
  52. data/app/views/message_train/conversations/_trashed_toggle.html.haml +1 -1
  53. data/app/views/message_train/conversations/show.html.haml +2 -2
  54. data/app/views/message_train/conversations/show.json.jbuilder +5 -1
  55. data/app/views/message_train/messages/_form.html.haml +1 -1
  56. data/app/views/message_train/messages/_message.html.haml +6 -6
  57. data/app/views/message_train/messages/_toggle.html.haml +1 -1
  58. data/app/views/message_train/messages/show.json.jbuilder +5 -1
  59. data/app/views/message_train/participants/_participant.json.jbuilder +1 -1
  60. data/app/views/message_train/participants/index.json.jbuilder +1 -1
  61. data/app/views/message_train/participants/show.json.jbuilder +1 -1
  62. data/app/views/message_train/receipt_mailer/notification_email.html.haml +1 -1
  63. data/app/views/message_train/receipt_mailer/notification_email.text.haml +1 -1
  64. data/app/views/message_train/unsubscribes/index.html.haml +1 -1
  65. data/config/environment.rb +1 -1
  66. data/config/initializers/date_time.rb +2 -2
  67. data/config/locales/en.yml +1 -1
  68. data/config/routes.rb +37 -15
  69. data/lib/generators/message_train/install/install_generator.rb +26 -11
  70. data/lib/generators/message_train/install/templates/initializer.rb +0 -2
  71. data/lib/generators/message_train/utils.rb +11 -4
  72. data/lib/message_train/configuration.rb +4 -5
  73. data/lib/message_train/engine.rb +1 -7
  74. data/lib/message_train/localization.rb +14 -18
  75. data/lib/message_train/mixin.rb +211 -150
  76. data/lib/message_train/version.rb +1 -0
  77. data/lib/message_train.rb +7 -6
  78. data/message_train.gemspec +24 -11
  79. data/spec/controllers/message_train/boxes_controller_spec.rb +63 -15
  80. data/spec/controllers/message_train/concerns_spec.rb +17 -13
  81. data/spec/controllers/message_train/conversations_controller_spec.rb +44 -12
  82. data/spec/controllers/message_train/messages_controller_spec.rb +87 -40
  83. data/spec/controllers/message_train/participants_controller_spec.rb +10 -4
  84. data/spec/controllers/message_train/unsubscribes_controller_spec.rb +43 -13
  85. data/spec/dummy/Rakefile +2 -1
  86. data/spec/dummy/app/assets/stylesheets/application.css.scss +7 -23
  87. data/spec/dummy/app/controllers/application_controller.rb +7 -7
  88. data/spec/dummy/app/models/group.rb +1 -1
  89. data/spec/dummy/app/models/role.rb +11 -7
  90. data/spec/dummy/app/models/user.rb +6 -5
  91. data/spec/dummy/app/views/layouts/_top_navigation.html.haml +1 -1
  92. data/spec/dummy/app/views/layouts/application.html.haml +1 -1
  93. data/spec/dummy/app/views/pages/index.html.haml +1 -1
  94. data/spec/dummy/config/application.rb +23 -17
  95. data/spec/dummy/config/environments/development.rb +5 -4
  96. data/spec/dummy/config/environments/production.rb +10 -6
  97. data/spec/dummy/config/environments/test.rb +4 -3
  98. data/spec/dummy/config/initializers/assets.rb +2 -1
  99. data/spec/dummy/config/initializers/backtrace_silencers.rb +4 -2
  100. data/spec/dummy/config/initializers/bootstrap_leather.rb +1 -1
  101. data/spec/dummy/config/initializers/devise.rb +63 -44
  102. data/spec/dummy/config/initializers/high_voltage.rb +1 -1
  103. data/spec/dummy/config/initializers/message_train.rb +5 -2
  104. data/spec/dummy/config/initializers/mime_types.rb +1 -1
  105. data/spec/dummy/config/initializers/paperclip.rb +5 -2
  106. data/spec/dummy/config/initializers/rolify.rb +3 -2
  107. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -1
  108. data/spec/dummy/config/routes.rb +1 -3
  109. data/spec/dummy/config/settings.yml +1 -1
  110. data/spec/dummy/db/schema.rb +98 -98
  111. data/spec/dummy/db/seeds/conversations.seeds.rb +160 -160
  112. data/spec/dummy/db/seeds/development/conversations.seeds.rb +6 -2
  113. data/spec/dummy/db/seeds/groups.seeds.rb +11 -12
  114. data/spec/dummy/db/seeds/test/attachments.seeds.rb +13 -3
  115. data/spec/dummy/db/seeds/test/conversations.seeds.rb +6 -2
  116. data/spec/dummy/db/seeds/unsubscribes.seeds.rb +1 -1
  117. data/spec/dummy/db/seeds/users.seeds.rb +47 -42
  118. data/spec/dummy/db/test.sqlite3 +0 -0
  119. data/spec/factories/attachment.rb +6 -2
  120. data/spec/factories/group.rb +1 -4
  121. data/spec/factories/message.rb +29 -23
  122. data/spec/factories/user.rb +6 -4
  123. data/spec/features/boxes_spec.rb +76 -24
  124. data/spec/features/conversations_spec.rb +19 -7
  125. data/spec/features/messages_spec.rb +24 -5
  126. data/spec/features/unsubscribes_spec.rb +36 -9
  127. data/spec/helpers/message_train/application_helper_spec.rb +1 -1
  128. data/spec/helpers/message_train/attachment_helper_spec.rb +27 -12
  129. data/spec/helpers/message_train/boxes_helper_spec.rb +1 -1
  130. data/spec/helpers/message_train/collectives_helper_spec.rb +25 -9
  131. data/spec/helpers/message_train/conversations_helper_spec.rb +239 -120
  132. data/spec/helpers/message_train/messages_helper_spec.rb +137 -81
  133. data/spec/message_train_spec.rb +3 -2
  134. data/spec/models/group_spec.rb +12 -9
  135. data/spec/models/message_train/attachment_spec.rb +33 -30
  136. data/spec/models/message_train/box_spec.rb +243 -60
  137. data/spec/models/message_train/conversation_spec.rb +16 -12
  138. data/spec/models/message_train/ignore_spec.rb +3 -1
  139. data/spec/models/message_train/message_spec.rb +22 -7
  140. data/spec/models/message_train/receipt_spec.rb +14 -4
  141. data/spec/models/role_spec.rb +10 -6
  142. data/spec/models/user_spec.rb +74 -22
  143. data/spec/rails_helper.rb +9 -4
  144. data/spec/spec_helper.rb +6 -54
  145. data/spec/support/controller_behaviors.rb +8 -5
  146. data/spec/support/controller_macros.rb +2 -2
  147. data/spec/support/factory_girl.rb +1 -1
  148. data/spec/support/feature_behaviors.rb +42 -13
  149. data/spec/support/loaded_site/attachments.rb +8 -0
  150. data/spec/support/loaded_site/conversations.rb +73 -0
  151. data/spec/support/{groups.rb → loaded_site/groups.rb} +1 -1
  152. data/spec/support/{loaded_site.rb → loaded_site/loaded_site.rb} +1 -1
  153. data/spec/support/{messages.rb → loaded_site/messages.rb} +13 -5
  154. data/spec/support/{roles.rb → loaded_site/roles.rb} +1 -1
  155. data/spec/support/{users.rb → loaded_site/users.rb} +1 -1
  156. data/spec/support/shared_connection.rb +8 -6
  157. data/spec/support/utilities.rb +10 -10
  158. metadata +67 -10
  159. data/spec/dummy/config/unused/temporary_i18n_debugging.rb +0 -12
  160. data/spec/support/attachments.rb +0 -4
  161. data/spec/support/conversations.rb +0 -23
@@ -18,19 +18,25 @@ module MessageTrain
18
18
  context 'sets draft to true on a message to no one' do
19
19
  subject { draft_conversation.messages.drafts.first }
20
20
  its(:sender) { should eq first_user }
21
- its(:receipts) { should have_exactly(1).item } # i.e. sender
21
+ its(:receipts) { should have_exactly(1).item } # sender
22
22
  its(:recipients) { should be_empty }
23
23
  its(:draft) { should be true }
24
24
  end
25
25
  context 'generates receipts when present' do
26
26
  subject { sent_message }
27
27
  its(:sender) { should eq first_user }
28
- its(:receipts) { should have_exactly(2).items } # i.e. sender and recipient
28
+ its(:receipts) { should have_exactly(2).items } # sender and recipient
29
29
  its(:recipients) { should include second_user }
30
30
  its(:draft) { should be false }
31
31
  end
32
32
  context 'generates error when recipient_to_save does not exist' do
33
- let(:message) { first_user.box(:in).send_message(subject: 'Message with missing recipient', recipients_to_save: { 'users' => 'missing-user' }, body: 'Foo.') }
33
+ let(:message) do
34
+ first_user.box(:in).send_message(
35
+ subject: 'Message with missing recipient',
36
+ recipients_to_save: { 'users' => 'missing-user' },
37
+ body: 'Foo.'
38
+ )
39
+ end
34
40
  subject { message.errors.full_messages.to_sentence }
35
41
  it { should eq 'Recipient missing-user not found' }
36
42
  end
@@ -62,7 +68,7 @@ module MessageTrain
62
68
  describe '#missing_method' do
63
69
  # Testing super on method_missing
64
70
  it 'raises a NoMethodError' do
65
- expect {unread_message.missing_method}.to raise_error(NoMethodError)
71
+ expect { unread_message.missing_method }.to raise_error(NoMethodError)
66
72
  end
67
73
  end
68
74
  context '.with_receipts_by' do
@@ -74,15 +80,24 @@ module MessageTrain
74
80
  it { should eq unread_message }
75
81
  end
76
82
  context '.with_trashed_to and #is_trashed_to?' do
77
- subject { trashed_conversation.messages.with_trashed_to(first_user).first.is_trashed_to?(first_user) }
83
+ subject do
84
+ trashed_conversation.messages.with_trashed_to(first_user)
85
+ .first.is_trashed_to?(first_user)
86
+ end
78
87
  it { should be true }
79
88
  end
80
89
  context '.with_deleted_to and #is_deleted_to?' do
81
- subject { deleted_conversation.messages.with_deleted_to(first_user).first.is_deleted_to?(first_user) }
90
+ subject do
91
+ deleted_conversation.messages.with_deleted_to(first_user)
92
+ .first.is_deleted_to?(first_user)
93
+ end
82
94
  it { should be true }
83
95
  end
84
96
  context '.with_read_to and #is_read_to?' do
85
- subject { read_conversation.messages.with_read_to(first_user).first.is_read_to?(first_user) }
97
+ subject do
98
+ read_conversation.messages.with_read_to(first_user)
99
+ .first.is_read_to?(first_user)
100
+ end
86
101
  it { should be true }
87
102
  end
88
103
  context '.mark' do
@@ -42,19 +42,29 @@ module MessageTrain
42
42
  its(:count) { should be > 5 }
43
43
  end
44
44
  describe '.trashed_to' do
45
- subject { MessageTrain::Receipt.trashed_to(first_user).first.message.conversation }
45
+ subject do
46
+ MessageTrain::Receipt.trashed_to(first_user)
47
+ .first.message.conversation
48
+ end
46
49
  its(:subject) { should eq 'Membered Group Trashed Conversation' }
47
50
  end
48
51
  describe '.untrashed_to' do
49
- subject { MessageTrain::Receipt.untrashed_to(first_user).first }
52
+ subject do
53
+ MessageTrain::Receipt.untrashed_to(first_user).first
54
+ end
50
55
  its(:marked_trash) { should be false }
51
56
  end
52
57
  describe '.read_to' do
53
- subject { MessageTrain::Receipt.read_to(first_user).first.message.conversation }
58
+ subject do
59
+ MessageTrain::Receipt.read_to(first_user).first.message.conversation
60
+ end
54
61
  its(:subject) { should eq 'Membered Group Read Conversation' }
55
62
  end
56
63
  describe '.deleted_to' do
57
- subject { MessageTrain::Receipt.deleted_to(first_user).first.message.conversation }
64
+ subject do
65
+ MessageTrain::Receipt.deleted_to(first_user)
66
+ .first.message.conversation
67
+ end
58
68
  its(:subject) { should eq 'Membered Group Deleted Conversation' }
59
69
  end
60
70
  describe '.undeleted_to' do
@@ -67,7 +67,9 @@ RSpec.describe Role do
67
67
 
68
68
  describe '#boxes_for_participant' do
69
69
  context 'when participant is a valid sender' do
70
- subject { admin_role.boxes_for_participant(superadmin_user).collect { |x| x.division } }
70
+ subject do
71
+ admin_role.boxes_for_participant(superadmin_user).collect(&:division)
72
+ end
71
73
  it { should_not include :in }
72
74
  it { should include :sent }
73
75
  it { should include :drafts }
@@ -76,7 +78,9 @@ RSpec.describe Role do
76
78
  it { should_not include :ignored }
77
79
  end
78
80
  context 'when participant is a valid recipient' do
79
- subject { admin_role.boxes_for_participant(admin_user).collect { |x| x.division } }
81
+ subject do
82
+ admin_role.boxes_for_participant(admin_user).collect(&:division)
83
+ end
80
84
  it { should include :in }
81
85
  it { should_not include :sent }
82
86
  it { should_not include :drafts }
@@ -92,7 +96,8 @@ RSpec.describe Role do
92
96
  its(:first) { should be_a MessageTrain::Conversation }
93
97
  it { should_not include unread_conversation }
94
98
  it { should include role_conversation }
95
- it { should_not include role_draft } # Because received_through not set on sender receipts
99
+ # Because received_through not set on sender receipts
100
+ it { should_not include role_draft }
96
101
  end
97
102
  context 'when participant is a valid recipient' do
98
103
  subject { admin_role.all_conversations(admin_user) }
@@ -109,7 +114,8 @@ RSpec.describe Role do
109
114
  its(:first) { should be_a MessageTrain::Message }
110
115
  it { should_not include unread_message }
111
116
  it { should include role_message }
112
- it { should_not include role_draft_message } # Because received_through not set on sender receipts
117
+ # Because received_through not set on sender receipts
118
+ it { should_not include role_draft_message }
113
119
  end
114
120
  context 'when participant is a valid recipient' do
115
121
  subject { admin_role.all_messages(admin_user) }
@@ -119,7 +125,5 @@ RSpec.describe Role do
119
125
  it { should_not include role_draft_message }
120
126
  end
121
127
  end
122
-
123
128
  end
124
-
125
129
  end
@@ -13,7 +13,6 @@ RSpec.describe User do
13
13
  end
14
14
 
15
15
  describe 'Scopes and Methods' do
16
-
17
16
  describe '#box' do
18
17
  describe 'with valid number of arguments' do
19
18
  subject { first_user.box }
@@ -23,26 +22,44 @@ RSpec.describe User do
23
22
  its(:participant) { should be first_user }
24
23
  end
25
24
  describe 'with invalid number of arguments' do
26
- it "should raise" do
27
- expect{ first_user.box(:in, first_user, 'extra argument') }.to raise_error(RuntimeError, "Wrong number of arguments for User (expected 0..2, got 3)")
25
+ it 'should raise' do
26
+ expect do
27
+ first_user.box(:in, first_user, 'extra argument')
28
+ end.to(
29
+ raise_error(
30
+ RuntimeError,
31
+ 'Wrong number of arguments for User (expected 0..2, got 3)'
32
+ )
33
+ )
28
34
  end
29
35
  end
30
36
  end
31
37
 
32
38
  describe '#collective_boxes' do
33
39
  describe 'with 0 arguments' do
34
- subject { first_user.collective_boxes[:groups].collect { |x| x.parent } }
40
+ subject do
41
+ first_user.collective_boxes[:groups].collect(&:parent)
42
+ end
35
43
  it { should include membered_group }
36
44
  it { should include first_group }
37
45
  end
38
46
  describe 'with 1 argument' do
39
- subject { first_user.collective_boxes(:in)[:groups].collect { |x| x.parent } }
47
+ subject do
48
+ first_user.collective_boxes(:in)[:groups].collect(&:parent)
49
+ end
40
50
  it { should include membered_group }
41
51
  it { should include first_group }
42
52
  end
43
53
  describe 'with 3 arguments' do
44
- it "should raise" do
45
- expect{ first_user.collective_boxes(:in, first_user, 'extra argument') }.to raise_error(RuntimeError, "Wrong number of arguments for User (expected 0..2, got 3)")
54
+ it 'should raise' do
55
+ expect do
56
+ first_user.collective_boxes(:in, first_user, 'extra argument')
57
+ end.to(
58
+ raise_error(
59
+ RuntimeError,
60
+ 'Wrong number of arguments for User (expected 0..2, got 3)'
61
+ )
62
+ )
46
63
  end
47
64
  end
48
65
  end
@@ -63,37 +80,61 @@ RSpec.describe User do
63
80
  end
64
81
  end
65
82
  describe 'with 2 arguments' do
66
- it "should raise" do
67
- expect{ first_user.all_boxes(first_user, 'extra argument') }.to raise_error(RuntimeError, "Wrong number of arguments for User (expected 0..1, got 2)")
83
+ it 'should raise' do
84
+ expect do
85
+ first_user.all_boxes(first_user, 'extra argument')
86
+ end.to(
87
+ raise_error(
88
+ RuntimeError,
89
+ 'Wrong number of arguments for User (expected 0..1, got 2)'
90
+ )
91
+ )
68
92
  end
69
93
  end
70
94
  end
71
95
 
72
96
  describe '#conversations' do
73
97
  context 'with division not set' do
74
- subject { first_user.conversations.first.includes_receipts_to?(first_user) }
98
+ subject do
99
+ first_user.conversations.first.includes_receipts_to?(first_user)
100
+ end
75
101
  it { should be true }
76
102
  end
77
103
  context 'with division as :in' do
78
- subject { first_user.conversations(:in).first.includes_receipts_to?(first_user) }
104
+ subject do
105
+ first_user.conversations(:in).first.includes_receipts_to?(first_user)
106
+ end
79
107
  it { should be true }
80
108
  end
81
109
  context 'with division as :sent' do
82
- subject { first_user.conversations(:sent).first.includes_receipts_by?(first_user) }
110
+ subject do
111
+ first_user.conversations(:sent)
112
+ .first.includes_receipts_by?(first_user)
113
+ end
83
114
  it { should be true }
84
115
  end
85
116
  context 'with division as :trash' do
86
- subject { first_user.conversations(:trash).first.includes_trashed_for?(first_user) }
87
- it { should be true}
117
+ subject do
118
+ first_user.conversations(:trash)
119
+ .first.includes_trashed_for?(first_user)
120
+ end
121
+ it { should be true }
88
122
  end
89
123
  describe 'with 23 arguments' do
90
- it "should raise" do
91
- expect{ first_user.conversations(:in, first_user, 'extra argument') }.to raise_error(RuntimeError, "Wrong number of arguments for User (expected 0..2, got 3)")
124
+ it 'should raise' do
125
+ expect do
126
+ first_user.conversations(:in, first_user, 'extra argument')
127
+ end.to(
128
+ raise_error(
129
+ RuntimeError,
130
+ 'Wrong number of arguments for User (expected 0..2, got 3)'
131
+ )
132
+ )
92
133
  end
93
134
  end
94
135
  context 'with impossible division' do
95
136
  subject { first_user.conversations(:impossible).nil? }
96
- it { should be true}
137
+ it { should be true }
97
138
  end
98
139
  end
99
140
 
@@ -123,8 +164,15 @@ RSpec.describe User do
123
164
  end
124
165
  end
125
166
  describe 'with 2 arguments' do
126
- it "should raise" do
127
- expect{ first_user.all_conversations(first_user, 'extra argument') }.to raise_error(RuntimeError, "Wrong number of arguments for User (expected 0..1, got 2)")
167
+ it 'should raise' do
168
+ expect do
169
+ first_user.all_conversations(first_user, 'extra argument')
170
+ end.to(
171
+ raise_error(
172
+ RuntimeError,
173
+ 'Wrong number of arguments for User (expected 0..1, got 2)'
174
+ )
175
+ )
128
176
  end
129
177
  end
130
178
  context 'when empty' do
@@ -159,8 +207,13 @@ RSpec.describe User do
159
207
  end
160
208
  end
161
209
  describe 'with 2 arguments' do
162
- it "should raise" do
163
- expect{ first_user.all_messages(first_user, 'extra argument') }.to raise_error(RuntimeError, "Wrong number of arguments for User (expected 0..1, got 2)")
210
+ it 'should raise' do
211
+ expect { first_user.all_messages(first_user, 'extra argument') }.to(
212
+ raise_error(
213
+ RuntimeError,
214
+ 'Wrong number of arguments for User (expected 0..1, got 2)'
215
+ )
216
+ )
164
217
  end
165
218
  end
166
219
  context 'when empty' do
@@ -193,5 +246,4 @@ RSpec.describe User do
193
246
  it { should have_at_least(3).items }
194
247
  end
195
248
  end
196
-
197
249
  end
data/spec/rails_helper.rb CHANGED
@@ -5,7 +5,9 @@ Coveralls.wear!
5
5
  ENV['RAILS_ENV'] ||= 'test'
6
6
  require File.expand_path('../dummy/config/environment', __FILE__)
7
7
  # Prevent database truncation if the environment is production
8
- abort("The Rails environment is running in production mode!") if Rails.env.production?
8
+ abort(
9
+ 'The Rails environment is running in production mode!'
10
+ ) if Rails.env.production?
9
11
  require 'spec_helper'
10
12
  require 'rspec/rails'
11
13
  # Add additional requires below this line. Rails is not loaded until this point!
@@ -29,7 +31,10 @@ require 'rake'
29
31
  # directory. Alternatively, in the individual `*_spec.rb` files, manually
30
32
  # require only the support files necessary.
31
33
  #
32
- Dir[MessageTrain::Engine.root.join('spec/support/**/*.rb')].each { |f| require f }
34
+ Dir[MessageTrain::Engine.root.join('spec/support/**/*.rb')]
35
+ .each { |f| require f }
36
+ Dir[MessageTrain::Engine.root.join('spec/support/**/**/*.rb')]
37
+ .each { |f| require f }
33
38
 
34
39
  # Checks for pending migrations before tests are run.
35
40
  # If you are not using ActiveRecord, you can remove this line.
@@ -64,7 +69,7 @@ RSpec.configure do |config|
64
69
  # You can disable this behaviour by removing the line below, and instead
65
70
  # explicitly tag your specs with their type, e.g.:
66
71
  #
67
- # RSpec.describe UsersController, :type => :controller do
72
+ # RSpec.describe UsersController, type: :controller do
68
73
  # # ...
69
74
  # end
70
75
  #
@@ -75,7 +80,7 @@ RSpec.configure do |config|
75
80
  config.expect_with(:rspec) { |c| c.syntax = [:should, :expect] }
76
81
  config.mock_with(:rspec) { |c| c.syntax = [:should, :expect] }
77
82
 
78
- config.before(:each) { @routes = MessageTrain::Engine.routes }
83
+ config.before(:each) { @routes = MessageTrain::Engine.routes }
79
84
  config.include MessageTrain::Engine.routes.url_helpers
80
85
 
81
86
  config.include Warden::Test::Helpers
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,7 @@
1
- # This file was generated by the `rails generate rspec:install` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
1
+ # This file was generated by the `rails generate rspec:install` command.
2
+ # Conventionally, all specs live under a `spec` directory, which RSpec adds to
3
+ # the `$LOAD_PATH`.
4
+ #
3
5
  # The generated `.rspec` file contains `--require spec_helper` which will cause
4
6
  # this file to always be loaded, without a need to explicitly require it in any
5
7
  # files.
@@ -25,9 +27,9 @@ RSpec.configure do |config|
25
27
  # and `failure_message` of custom matchers include text for helper methods
26
28
  # defined using `chain`, e.g.:
27
29
  # be_bigger_than(2).and_smaller_than(4).description
28
- # # => "be bigger than 2 and smaller than 4"
30
+ # # => 'be bigger than 2 and smaller than 4'
29
31
  # ...rather than:
30
- # # => "be bigger than 2"
32
+ # # => 'be bigger than 2'
31
33
  expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
34
  end
33
35
 
@@ -39,54 +41,4 @@ RSpec.configure do |config|
39
41
  # `true` in RSpec 4.
40
42
  mocks.verify_partial_doubles = true
41
43
  end
42
-
43
- # The settings below are suggested to provide a good initial experience
44
- # with RSpec, but feel free to customize to your heart's content.
45
- =begin
46
- # These two settings work together to allow you to limit a spec run
47
- # to individual examples or groups you care about by tagging them with
48
- # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
- # get run.
50
- config.filter_run :focus
51
- config.run_all_when_everything_filtered = true
52
-
53
- # Allows RSpec to persist some state between runs in order to support
54
- # the `--only-failures` and `--next-failure` CLI options. We recommend
55
- # you configure your source control system to ignore this file.
56
- config.example_status_persistence_file_path = "spec/examples.txt"
57
-
58
- # Limits the available syntax to the non-monkey patched syntax that is
59
- # recommended. For more details, see:
60
- # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
61
- # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
62
- # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
63
- config.disable_monkey_patching!
64
-
65
- # Many RSpec users commonly either run the entire suite or an individual
66
- # file, and it's useful to allow more verbose output when running an
67
- # individual spec file.
68
- if config.files_to_run.one?
69
- # Use the documentation formatter for detailed output,
70
- # unless a formatter has already been configured
71
- # (e.g. via a command-line flag).
72
- config.default_formatter = 'doc'
73
- end
74
-
75
- # Print the 10 slowest examples and example groups at the
76
- # end of the spec run, to help surface which specs are running
77
- # particularly slow.
78
- config.profile_examples = 10
79
-
80
- # Run specs in random order to surface order dependencies. If you find an
81
- # order dependency and want to debug it, you can fix the order by providing
82
- # the seed, which is printed after each run.
83
- # --seed 1234
84
- config.order = :random
85
-
86
- # Seed global randomization in this process using the `--seed` CLI option.
87
- # Setting this allows you to use `--seed` to deterministically reproduce
88
- # test failures related to randomization by passing the same `--seed` value
89
- # as the one that triggered the failure.
90
- Kernel.srand config.seed
91
- =end
92
44
  end
@@ -37,7 +37,7 @@ end
37
37
  shared_examples_for 'a redirect with a message' do |path, options|
38
38
  it_behaves_like 'a redirect matching', path
39
39
  options.each do |key, value|
40
- context "sets #{key.to_s} message" do
40
+ context "sets #{key} message" do
41
41
  subject { flash[key] }
42
42
  it { should eq value }
43
43
  end
@@ -57,7 +57,7 @@ end
57
57
  shared_examples_for 'a page with a message' do |options|
58
58
  it_behaves_like 'a successful page'
59
59
  options.each do |key, value|
60
- context "sets #{key.to_s} message" do
60
+ context "sets #{key} message" do
61
61
  subject { flash[key] }
62
62
  it { should eq value }
63
63
  end
@@ -66,7 +66,7 @@ end
66
66
  shared_examples_for 'a page with a message matching' do |options|
67
67
  it_behaves_like 'a successful page'
68
68
  options.each do |key, value|
69
- context "sets #{key.to_s} message" do
69
+ context "sets #{key} message" do
70
70
  subject { flash[key] }
71
71
  it { should match value }
72
72
  end
@@ -85,7 +85,10 @@ shared_examples_for 'a page with an error message matching' do |message|
85
85
  it_behaves_like 'a page with a message matching', error: message
86
86
  end
87
87
  shared_examples_for 'a 403 Forbidden error' do
88
- it_should_behave_like 'an error response with message', 'You are not authorized to access this page.'
88
+ it_should_behave_like(
89
+ 'an error response with message',
90
+ 'You are not authorized to access this page.'
91
+ )
89
92
  end
90
93
  shared_examples_for 'a redirect with error' do |path, message|
91
94
  it_behaves_like 'a redirect to', path
@@ -113,4 +116,4 @@ shared_examples_for 'a response without error' do
113
116
  subject { flash[:error] }
114
117
  it { should be nil }
115
118
  end
116
- end
119
+ end
@@ -6,8 +6,8 @@ module ControllerMacros
6
6
 
7
7
  def login_user(user)
8
8
  @request ||= controller.request
9
- @request.env["devise.mapping"] = Devise.mappings[:user]
9
+ @request.env['devise.mapping'] = Devise.mappings[:user]
10
10
  sign_in user
11
11
  user
12
12
  end
13
- end
13
+ end
@@ -1,3 +1,3 @@
1
1
  RSpec.configure do |config|
2
2
  config.include FactoryGirl::Syntax::Methods
3
- end
3
+ end
@@ -3,7 +3,11 @@ shared_examples_for 'an authenticated section' do |path|
3
3
  before do
4
4
  visit path
5
5
  end
6
- it_behaves_like 'a bootstrap page with an alert', 'danger', 'You must sign in or sign up to continue.'
6
+ it_behaves_like(
7
+ 'a bootstrap page with an alert',
8
+ 'danger',
9
+ 'You must sign in or sign up to continue.'
10
+ )
7
11
  context 'displays a login form' do
8
12
  subject { page }
9
13
  it { should have_selector 'form.new_user input#user_email' }
@@ -20,15 +24,26 @@ shared_examples_for 'a bootstrap page' do |options = {}|
20
24
  it { should have_title html_escape(options[:title]) }
21
25
  it { should have_xpath '//h1', text: options[:title] }
22
26
  end
23
- it { should have_selector '.navbar .navbar-header .navbar-brand', text: BootstrapLeather.configuration.application_title }
27
+ it do
28
+ should(
29
+ have_selector(
30
+ '.navbar .navbar-header .navbar-brand',
31
+ text: BootstrapLeather.configuration.application_title
32
+ )
33
+ )
34
+ end
24
35
  end
25
36
  end
26
37
 
27
- shared_examples_for 'a bootstrap page with a dropdown navigation list' do |options|
38
+ shared_examples_for(
39
+ 'a bootstrap page with a dropdown navigation list'
40
+ ) do |options|
28
41
  if options[:text]
29
- it { should have_selector 'li.dropdown a.dropdown-toggle', text: options[:text]}
42
+ it do
43
+ should have_selector 'li.dropdown a.dropdown-toggle', text: options[:text]
44
+ end
30
45
  else
31
- it { should have_selector 'li.dropdown a.dropdown-toggle'}
46
+ it { should have_selector 'li.dropdown a.dropdown-toggle' }
32
47
  end
33
48
  end
34
49
 
@@ -42,20 +57,30 @@ shared_examples_for 'a bootstrap page without an alert' do |type|
42
57
  it { should_not have_selector ".alert.alert-#{type}" }
43
58
  end
44
59
 
45
- shared_examples_for 'a bootstrap page listing a collection of items' do |object, options={}|
60
+ shared_examples_for(
61
+ 'a bootstrap page listing a collection of items'
62
+ ) do |object, options = {}|
46
63
  options[:minimum] ||= 1
47
64
  options[:plural_title] ||= object.model_name.human.pluralize(2)
48
65
  options[:plural_name] ||= object.table_name
49
- collection_css_id = options[:plural_name].gsub('_', '-')
66
+ collection_css_id = options[:plural_name].tr('_', '-')
50
67
  member_css_class = options[:plural_name].singularize
51
68
  it_behaves_like 'a bootstrap page', title: options[:plural_title].titlecase
52
69
  context "displays a list of ##{collection_css_id} in .#{member_css_class}" do
53
70
  subject { page }
54
- it { should have_css("##{collection_css_id} .#{member_css_class}", minimum: options[:minimum]) }
71
+ it do
72
+ should(
73
+ have_css(
74
+ "##{collection_css_id} .#{member_css_class}",
75
+ minimum: options[:minimum])
76
+ )
77
+ end
55
78
  end
56
79
  end
57
80
 
58
- shared_examples_for 'a bootstrap page showing an item' do |object, title, options={}|
81
+ shared_examples_for(
82
+ 'a bootstrap page showing an item'
83
+ ) do |object, title, options = {}|
59
84
  options[:css_id] ||= object.table_name.singularize
60
85
  it_behaves_like 'a bootstrap page', title: title
61
86
  context "displays an item at ##{options[:css_id]}" do
@@ -66,11 +91,15 @@ end
66
91
 
67
92
  shared_examples_for 'a bootstrap form with errors' do |error_fields|
68
93
  subject { page }
69
- for field in error_fields
70
- it_behaves_like 'a bootstrap page with an alert', 'danger', "#{field.to_s.humanize} can't be blank"
94
+ error_fields.each do |field|
95
+ it_behaves_like(
96
+ 'a bootstrap page with an alert',
97
+ 'danger',
98
+ "#{field.to_s.humanize} can't be blank"
99
+ )
71
100
  context 'shows which field has errors' do
72
101
  subject { page }
73
- it { should have_css('.form-group.has-error', text: field.to_s.humanize)}
102
+ it { should have_css('.form-group.has-error', text: field.to_s.humanize) }
74
103
  end
75
104
  end
76
- end
105
+ end
@@ -0,0 +1,8 @@
1
+ shared_context 'attachments' do
2
+ let(:image_attachment) do
3
+ MessageTrain::Attachment.find_by_attachment_file_name('image-sample.jpg')
4
+ end
5
+ let(:pdf_attachment) do
6
+ MessageTrain::Attachment.find_by_attachment_file_name('pdf-sample.pdf')
7
+ end
8
+ end