notify_on 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +29 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/config/notify_on_manifest.js +2 -0
  6. data/app/assets/javascripts/notify_on/application.js +13 -0
  7. data/app/assets/stylesheets/notify_on/application.css +15 -0
  8. data/app/controllers/notify_on/application_controller.rb +5 -0
  9. data/app/helpers/notify_on/application_helper.rb +4 -0
  10. data/app/helpers/notify_on/mailer_helper.rb +9 -0
  11. data/app/jobs/notify_on/application_job.rb +4 -0
  12. data/app/mailers/notify_on/application_mailer.rb +6 -0
  13. data/app/mailers/notify_on/notification_mailer.rb +26 -0
  14. data/app/models/concerns/notify_on/email_support.rb +97 -0
  15. data/app/models/concerns/notify_on/pusher_support.rb +66 -0
  16. data/app/models/concerns/notify_on/string_interpolation.rb +39 -0
  17. data/app/models/notify_on/application_record.rb +5 -0
  18. data/app/models/notify_on/notification.rb +86 -0
  19. data/app/views/layouts/notify_on/application.html.erb +17 -0
  20. data/app/views/notifications/notify.html.erb +9 -0
  21. data/config/database.travis.yml +4 -0
  22. data/config/routes.rb +2 -0
  23. data/lib/generators/notify_on/install_generator.rb +29 -0
  24. data/lib/generators/templates/notifications.yml +19 -0
  25. data/lib/generators/templates/notify_on.rb +64 -0
  26. data/lib/notify_on.rb +29 -0
  27. data/lib/notify_on/bulk_config.rb +36 -0
  28. data/lib/notify_on/configuration.rb +22 -0
  29. data/lib/notify_on/creator.rb +85 -0
  30. data/lib/notify_on/engine.rb +19 -0
  31. data/lib/notify_on/notify_on.rb +36 -0
  32. data/lib/notify_on/receives_notifications.rb +11 -0
  33. data/lib/notify_on/utilities.rb +13 -0
  34. data/lib/notify_on/version.rb +3 -0
  35. data/lib/tasks/notify_on_tasks.rake +4 -0
  36. data/spec/dummy/Rakefile +6 -0
  37. data/spec/dummy/app/assets/config/manifest.js +5 -0
  38. data/spec/dummy/app/assets/javascripts/application.js +7 -0
  39. data/spec/dummy/app/assets/javascripts/cable.js +13 -0
  40. data/spec/dummy/app/assets/stylesheets/application.scss +28 -0
  41. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  42. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  43. data/spec/dummy/app/controllers/application_controller.rb +7 -0
  44. data/spec/dummy/app/controllers/messages_controller.rb +31 -0
  45. data/spec/dummy/app/helpers/application_helper.rb +8 -0
  46. data/spec/dummy/app/jobs/application_job.rb +2 -0
  47. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  48. data/spec/dummy/app/mailers/notification_mailer.rb +15 -0
  49. data/spec/dummy/app/models/application_record.rb +3 -0
  50. data/spec/dummy/app/models/comment.rb +10 -0
  51. data/spec/dummy/app/models/message.rb +45 -0
  52. data/spec/dummy/app/models/post.rb +11 -0
  53. data/spec/dummy/app/models/user.rb +21 -0
  54. data/spec/dummy/app/views/application/_header.html.erb +44 -0
  55. data/spec/dummy/app/views/application/home.html.erb +1 -0
  56. data/spec/dummy/app/views/layouts/application.html.erb +19 -0
  57. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  58. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  59. data/spec/dummy/app/views/messages/_message.html.erb +6 -0
  60. data/spec/dummy/app/views/messages/index.html.erb +33 -0
  61. data/spec/dummy/app/views/messages/new.html.erb +5 -0
  62. data/spec/dummy/app/views/messages/show.html.erb +7 -0
  63. data/spec/dummy/app/views/notifications/new_message.html.erb +9 -0
  64. data/spec/dummy/bin/bundle +3 -0
  65. data/spec/dummy/bin/rails +4 -0
  66. data/spec/dummy/bin/rake +4 -0
  67. data/spec/dummy/bin/setup +34 -0
  68. data/spec/dummy/bin/update +29 -0
  69. data/spec/dummy/config.ru +5 -0
  70. data/spec/dummy/config/application.rb +35 -0
  71. data/spec/dummy/config/boot.rb +5 -0
  72. data/spec/dummy/config/cable.yml +9 -0
  73. data/spec/dummy/config/database.yml +12 -0
  74. data/spec/dummy/config/environment.rb +5 -0
  75. data/spec/dummy/config/environments/development.rb +58 -0
  76. data/spec/dummy/config/environments/production.rb +86 -0
  77. data/spec/dummy/config/environments/test.rb +42 -0
  78. data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
  79. data/spec/dummy/config/initializers/assets.rb +11 -0
  80. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  81. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  82. data/spec/dummy/config/initializers/devise.rb +274 -0
  83. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  84. data/spec/dummy/config/initializers/inflections.rb +16 -0
  85. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  86. data/spec/dummy/config/initializers/new_framework_defaults.rb +24 -0
  87. data/spec/dummy/config/initializers/notify_on.rb +64 -0
  88. data/spec/dummy/config/initializers/session_store.rb +3 -0
  89. data/spec/dummy/config/initializers/simple_form.rb +165 -0
  90. data/spec/dummy/config/initializers/simple_form_bootstrap.rb +149 -0
  91. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  92. data/spec/dummy/config/locales/devise.en.yml +62 -0
  93. data/spec/dummy/config/locales/en.yml +23 -0
  94. data/spec/dummy/config/locales/simple_form.en.yml +31 -0
  95. data/spec/dummy/config/notifications.yml +20 -0
  96. data/spec/dummy/config/puma.rb +47 -0
  97. data/spec/dummy/config/routes.rb +14 -0
  98. data/spec/dummy/config/secrets.yml +22 -0
  99. data/spec/dummy/config/spring.rb +6 -0
  100. data/spec/dummy/db/migrate/20160801112429_devise_create_users.rb +42 -0
  101. data/spec/dummy/db/migrate/20160801130804_create_messages.rb +11 -0
  102. data/spec/dummy/db/migrate/20160823102904_create_notify_on_notifications.rb +20 -0
  103. data/spec/dummy/db/migrate/20161021100707_create_comments.rb +11 -0
  104. data/spec/dummy/db/migrate/20161021100842_create_posts.rb +11 -0
  105. data/spec/dummy/db/schema.rb +77 -0
  106. data/spec/dummy/db/seeds.rb +4 -0
  107. data/spec/dummy/lib/templates/erb/scaffold/_form.html.erb +13 -0
  108. data/spec/dummy/public/404.html +67 -0
  109. data/spec/dummy/public/422.html +67 -0
  110. data/spec/dummy/public/500.html +66 -0
  111. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  112. data/spec/dummy/public/apple-touch-icon.png +0 -0
  113. data/spec/dummy/public/favicon.ico +0 -0
  114. data/spec/dummy/spec/controllers/messages_controller_spec.rb +5 -0
  115. data/spec/dummy/spec/factories/comments.rb +7 -0
  116. data/spec/dummy/spec/factories/messages.rb +7 -0
  117. data/spec/dummy/spec/factories/posts.rb +6 -0
  118. data/spec/dummy/spec/factories/users.rb +6 -0
  119. data/spec/dummy/spec/features/send_message_spec.rb +25 -0
  120. data/spec/dummy/spec/mailers/notify_on/notification_mailer_spec.rb +30 -0
  121. data/spec/dummy/spec/mailers/previews/notification_mailer_preview.rb +4 -0
  122. data/spec/dummy/spec/models/comment_spec.rb +22 -0
  123. data/spec/dummy/spec/models/message_spec.rb +60 -0
  124. data/spec/dummy/spec/models/post_spec.rb +23 -0
  125. data/spec/dummy/spec/models/user_spec.rb +21 -0
  126. data/spec/factories/notify_on_notifications.rb +10 -0
  127. data/spec/lib/notify_on/configuration_spec.rb +53 -0
  128. data/spec/mailers/notify_on/notification_mailer_spec.rb +6 -0
  129. data/spec/mailers/previews/notify_on/notification_mailer_preview.rb +6 -0
  130. data/spec/models/notify_on/notification_spec.rb +335 -0
  131. data/spec/rails_helper.rb +95 -0
  132. data/spec/spec_helper.rb +103 -0
  133. data/spec/support/feature_helpers.rb +19 -0
  134. data/spec/support/general_helpers.rb +19 -0
  135. metadata +543 -0
@@ -0,0 +1,6 @@
1
+ module NotifyOn
2
+ # Preview all emails at http://localhost:3000/rails/mailers/notification_mailer
3
+ class NotificationMailerPreview < ActionMailer::Preview
4
+
5
+ end
6
+ end
@@ -0,0 +1,335 @@
1
+ require 'rails_helper'
2
+
3
+ module NotifyOn
4
+ RSpec.describe Notification, :type => :model do
5
+
6
+ before(:each) do
7
+ @message = create(:message)
8
+ @n = first_notification
9
+ end
10
+
11
+ describe 'self#mark_read_for, self#unread' do
12
+ it 'will mark read by a single recipient and trigger' do
13
+ NotifyOn::Notification.mark_read_for(@message.user, @message)
14
+ expect(@n.reload.unread?).to eq(false)
15
+ end
16
+ it 'will mark read those matching an array of recipients and triggers' do
17
+ Message.destroy_all
18
+ messages = create_list(:message, 10)
19
+ read_msgs = messages.first(5)
20
+ unread_msgs = messages - read_msgs
21
+ recipients = read_msgs.collect(&:user)
22
+ NotifyOn::Notification.mark_read_for(recipients, read_msgs)
23
+ read_msgs.each { |m| expect(m.notifications[0].unread?).to eq(false) }
24
+ unread_msgs.each { |m| expect(m.notifications[0].unread?).to eq(true) }
25
+ unread = unread_msgs.collect(&:notifications).flatten
26
+ expect(NotifyOn::Notification.unread.to_a).to match_array(unread)
27
+ end
28
+ end
29
+
30
+ describe '#read?, #read!' do
31
+ it 'sets unread to false' do
32
+ expect(@n.unread?).to eq(true)
33
+ expect(@n.read?).to eq(false)
34
+ @n.read!
35
+ expect(@n.reload.unread?).to eq(false)
36
+ expect(@n.read?).to eq(true)
37
+ end
38
+ end
39
+
40
+ describe '#link' do
41
+ it 'caches an interpolated link and returns it' do
42
+ expect(@n.link_cached).to eq("/messages/#{@message.id}")
43
+ expect(@n.link).to eq(@n.link_cached)
44
+ end
45
+ it 'falls back to converting the raw link when not cached' do
46
+ @n.update_columns(:link_cached => nil)
47
+ expect(@n.reload.link_cached).to eq(nil)
48
+ expect(@n.link).to eq("/messages/#{@message.id}")
49
+ end
50
+ it 'returns nil when both raw and cached are missing' do
51
+ @n.update_columns(:link_cached => nil, :link_raw => nil)
52
+ expect(@n.reload.link).to eq(nil)
53
+ end
54
+ end
55
+
56
+ describe '#description' do
57
+ before(:each) { @desc = "#{@message.author.email} sent you a message." }
58
+ it 'caches an interpolated description and returns it' do
59
+ expect(@n.description_cached).to eq(@desc)
60
+ expect(@n.description).to eq(@n.description_cached)
61
+ end
62
+ it 'falls back to converting the raw description when not cached' do
63
+ @n.update_columns(:description_cached => nil)
64
+ expect(@n.reload.description_cached).to eq(nil)
65
+ expect(@n.description).to eq(@desc)
66
+ end
67
+ it 'returns nil when both raw and cached are missing' do
68
+ @n.update_columns(:description_cached => nil, :description_raw => nil)
69
+ expect(@n.reload.description).to eq(nil)
70
+ end
71
+ end
72
+
73
+ describe '#opts' do
74
+ it 'uses method_missing to convert "options" to Hashie::Mash' do
75
+ expect(@n.opts).to eq(Hashie::Mash.new(@n.options))
76
+ end
77
+ it 'returns a blank Mash when options is nil' do
78
+ @n.update_columns(:options => nil)
79
+ expect(@n.opts).to eq(Hashie::Mash.new)
80
+ end
81
+ end
82
+
83
+ # ---------------------------------------- String Interpolation
84
+
85
+ describe 'StringInterpolation' do
86
+ let(:n) { build(:notification) }
87
+ describe '#convert_string' do
88
+ it 'returns nil when given nil' do
89
+ expect(n.send(:convert_string, nil)).to eq(nil)
90
+ end
91
+ it 'returns the string if given as plain text' do
92
+ str = Faker::Lorem.sentence
93
+ expect(n.send(:convert_string, str)).to eq(str)
94
+ end
95
+ it 'interpolates the environment' do
96
+ str = Faker::Lorem.sentence
97
+ expect(n.send(:convert_string, "#{str} {:env}")).to eq("#{str} test")
98
+ end
99
+ it "interpolates the recipient's id" do
100
+ input = "#{str = Faker::Lorem.sentence} {:recipient_id}"
101
+ output = "#{str} #{n.recipient.id}"
102
+ expect(n.send(:convert_string, input)).to eq(output)
103
+ end
104
+ it 'interpolates methods on the trigger' do
105
+ input = 'Message #{id}: {content}'
106
+ output = "Message ##{n.trigger.id}: #{n.trigger.content}"
107
+ expect(n.send(:convert_string, input)).to eq(output)
108
+ end
109
+ it 'falls back to notification methods when undefined on trigger' do
110
+ input = 'Message #{id}: {description}'
111
+ output = "Message ##{n.trigger.id}: #{n.description}"
112
+ expect(n.send(:convert_string, input)).to eq(output)
113
+ end
114
+ it 'throws an error when method does not exist on trigger or self' do
115
+ input = '{blah_blah}'
116
+ expect { n.send(:convert_string, input) }.to raise_error(NoMethodError)
117
+ end
118
+ it 'supports daisy-chaining methods' do
119
+ input = 'Message From: {author.email}'
120
+ output = "Message From: #{n.trigger.author.email}"
121
+ expect(n.send(:convert_string, input)).to eq(output)
122
+ end
123
+ end
124
+ describe '#convert_link' do
125
+ it 'returns nil when given nil' do
126
+ expect(n.send(:convert_link, nil)).to eq(nil)
127
+ end
128
+ it 'resolves multiple arguments' do
129
+ input = 'user_message_path(:author, :self)'
130
+ output = "/users/#{n.trigger.author.id}/messages/#{n.trigger.id}"
131
+ expect(n.send(:convert_link, input)).to eq(output)
132
+ end
133
+ it 'leaves argument strings alone' do
134
+ input = 'user_message_path(author, :self)'
135
+ output = "/users/author/messages/#{n.trigger.id}"
136
+ expect(n.send(:convert_link, input)).to eq(output)
137
+ end
138
+ end
139
+ end
140
+
141
+ # ---------------------------------------- Pusher Support
142
+
143
+ describe 'PusherSupport' do
144
+ let(:n) { create(:notification) }
145
+
146
+ context 'can not push' do
147
+ describe '#can_push?' do
148
+ it 'returns false' do
149
+ NotifyOn.configure { |config| config.use_pusher_by_default = false }
150
+ expect(n.send(:can_push?)).to eq(false)
151
+ end
152
+ it 'would return true if we change the default config' do
153
+ NotifyOn.configure { |config| config.use_pusher_by_default = true }
154
+ expect(n.send(:can_push?)).to eq(true)
155
+ NotifyOn.configure { |config| config.use_pusher_by_default = false }
156
+ end
157
+ end
158
+ describe '#pusher_channel_name' do
159
+ it 'returns nil' do
160
+ expect(n.pusher_channel_name).to eq(nil)
161
+ end
162
+ end
163
+ describe '#pusher_event_name' do
164
+ it 'returns nil' do
165
+ expect(n.pusher_event_name).to eq(nil)
166
+ end
167
+ end
168
+ describe '#pusher_attrs' do
169
+ it 'returns nil' do
170
+ expect(n.pusher_attrs).to eq(nil)
171
+ end
172
+ end
173
+ end
174
+
175
+ context 'can push' do
176
+ before(:each) do
177
+ opts = n.options
178
+ opts[:pusher] = {
179
+ :channel => 'presence-{:env}-message-{id}',
180
+ :event => :new_message
181
+ }
182
+ n.options = opts
183
+ n.save!
184
+ end
185
+ describe '#pusher_channel_name' do
186
+ it 'uses string interpolation to build channel name' do
187
+ exp_channel_name = "presence-test-message-#{n.trigger.id}"
188
+ expect(n.pusher_channel_name).to eq(exp_channel_name)
189
+ end
190
+ end
191
+ describe '#pusher_event_name' do
192
+ it 'uses the specified option' do
193
+ expect(n.pusher_event_name).to eq('new_message')
194
+ end
195
+ end
196
+ describe '#pusher_attrs' do
197
+ it 'sets up default attributes' do
198
+ attrs = {
199
+ :notification => n.to_json,
200
+ :trigger => n.trigger.to_json,
201
+ :data => nil
202
+ }
203
+ expect(n.pusher_attrs).to eq(attrs)
204
+ end
205
+ it 'will define custom variables' do
206
+ n.options[:pusher][:data] = { :is_chat => true }
207
+ n.save!
208
+ attrs = {
209
+ :notification => n.to_json,
210
+ :trigger => n.trigger.to_json,
211
+ :data => { :is_chat => true }
212
+ }
213
+ expect(n.pusher_attrs).to eq(attrs)
214
+ end
215
+ end
216
+ end
217
+
218
+ end
219
+
220
+ # ---------------------------------------- Email Support
221
+
222
+ describe 'EmailSupport' do
223
+ let(:n) { build(:notification) }
224
+
225
+ def update_email_config(config)
226
+ n.options[:email] = config
227
+ n.save!
228
+ end
229
+
230
+ describe '#email_config, #email_enabled?, #email_disabled?, #email_config?' do
231
+ it 'is disabled if no config' do
232
+ update_email_config(nil)
233
+ expect(n.send(:email_config)).to eq(nil)
234
+ expect(n.send(:email_config?)).to eq(false)
235
+ expect(n.send(:email_enabled?)).to eq(false)
236
+ expect(n.send(:email_disabled?)).to eq(true)
237
+ end
238
+ it 'is enabled if only set to "true"' do
239
+ update_email_config(true)
240
+ expect(n.send(:email_config)).to eq(Hashie::Mash.new)
241
+ expect(n.send(:email_config?)).to eq(true)
242
+ expect(n.send(:email_enabled?)).to eq(true)
243
+ expect(n.send(:email_disabled?)).to eq(false)
244
+ end
245
+ it 'is enabled if given arguments' do
246
+ update_email_config(:template => 'new_message')
247
+ expect(n.send(:email_config))
248
+ .to eq(Hashie::Mash.new(:template => 'new_message'))
249
+ expect(n.send(:email_config?)).to eq(true)
250
+ expect(n.send(:email_enabled?)).to eq(true)
251
+ expect(n.send(:email_disabled?)).to eq(false)
252
+ end
253
+ end
254
+
255
+ describe '#can_send_email?' do
256
+ it 'returns false if email is disabled' do
257
+ update_email_config(false)
258
+ expect(n.send(:can_send_email?)).to eq(false)
259
+ end
260
+ it 'returns true if email enabled and "unless" not specified' do
261
+ update_email_config(true)
262
+ expect(n.send(:can_send_email?)).to eq(true)
263
+ end
264
+ it 'returns false if "unless" resolves to true' do
265
+ n.define_singleton_method(:unless_method?) do
266
+ true
267
+ end
268
+ update_email_config(:unless => :unless_method?)
269
+ expect(n.send(:can_send_email?)).to eq(false)
270
+ end
271
+ it 'returns true if "unless" resolves to false' do
272
+ n.define_singleton_method(:unless_method?) do
273
+ false
274
+ end
275
+ update_email_config(:unless => :unless_method?)
276
+ expect(n.send(:can_send_email?)).to eq(true)
277
+ end
278
+ end
279
+
280
+ describe '#email_template' do
281
+ it 'returns nil if there is no config' do
282
+ update_email_config(nil)
283
+ expect(n.email_template).to eq(nil)
284
+ end
285
+ it 'returns "notify" if email config exists, but template is missing' do
286
+ update_email_config(true)
287
+ expect(n.email_template).to eq('notify')
288
+ end
289
+ it 'returns the template if specified' do
290
+ update_email_config({ :template => 'new_message' })
291
+ expect(n.email_template).to eq('new_message')
292
+ end
293
+ end
294
+
295
+ describe '#email_from, #email_from_raw' do
296
+ it 'returns the default address if email is disabled' do
297
+ update_email_config(nil)
298
+ expect(n.email_from).to eq('NotifyOn <noreply@example.com>')
299
+ end
300
+ it 'returns the address if specified' do
301
+ update_email_config(:from => 'Paul McCartney <paul@thebeatles.com>')
302
+ expect(n.email_from).to eq('Paul McCartney <paul@thebeatles.com>')
303
+ end
304
+ end
305
+
306
+ describe '#email_subject' do
307
+ it 'falls back to the description' do
308
+ update_email_config(nil)
309
+ expect(n.email_subject).to eq(n.description)
310
+ end
311
+ it 'returns the subject if specified' do
312
+ update_email_config(:subject => (subj = Faker::Lorem.sentence))
313
+ expect(n.email_subject).to eq(subj)
314
+ end
315
+ end
316
+
317
+ describe '#email_attachments' do
318
+ it 'resolves the calls to methods on the trigger' do
319
+ update_email_config(:attachments => { :pdf_filename => :pdf_file })
320
+ attachment = { :name => 'myfile.pdf', :file => n.trigger.pdf_file }
321
+ expect(n.email_attachments).to match_array([attachment])
322
+ end
323
+ it 'throws an error when the file method does not exist' do
324
+ update_email_config(:attachments => { :pdf_filename => :wrong! })
325
+ expect { n.email_attachments }.to raise_error(RuntimeError)
326
+ end
327
+ it 'falls back to a string when the filename method does not exist' do
328
+ update_email_config(:attachments => { :wrong => :pdf_file })
329
+ expect(n.email_attachments[0][:name]).to eq('wrong')
330
+ end
331
+ end
332
+ end
333
+
334
+ end
335
+ end
@@ -0,0 +1,95 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV['RAILS_ENV'] ||= 'test'
3
+ require File.expand_path("../dummy/config/environment", __FILE__)
4
+ # Prevent database truncation if the environment is production
5
+ abort("The Rails environment is running in production mode!") if Rails.env.production?
6
+ require 'faker'
7
+ require 'database_cleaner'
8
+ require 'spec_helper'
9
+ require 'rspec/rails'
10
+ # Add additional requires below this line. Rails is not loaded until this point!
11
+
12
+ # Requires supporting ruby files with custom matchers and macros, etc, in
13
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
14
+ # run as spec files by default. This means that files in spec/support that end
15
+ # in _spec.rb will both be required and run as specs, causing the specs to be
16
+ # run twice. It is recommended that you do not name files matching this glob to
17
+ # end with _spec.rb. You can configure this pattern with the --pattern
18
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
19
+ #
20
+ # The following line is provided for convenience purposes. It has the downside
21
+ # of increasing the boot-up time by auto-requiring all files in the support
22
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
23
+ # require only the support files necessary.
24
+ #
25
+ Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }
26
+
27
+ # Checks for pending migration and applies them before tests are run.
28
+ # If you are not using ActiveRecord, you can remove this line.
29
+ ActiveRecord::Migration.maintain_test_schema!
30
+
31
+ RSpec.configure do |config|
32
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
33
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
34
+
35
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
36
+ # examples within a transaction, remove the following line or assign false
37
+ # instead of true.
38
+ config.use_transactional_fixtures = true
39
+
40
+ # RSpec Rails can automatically mix in different behaviours to your tests
41
+ # based on their file location, for example enabling you to call `get` and
42
+ # `post` in specs under `spec/controllers`.
43
+ #
44
+ # You can disable this behaviour by removing the line below, and instead
45
+ # explicitly tag your specs with their type, e.g.:
46
+ #
47
+ # RSpec.describe UsersController, :type => :controller do
48
+ # # ...
49
+ # end
50
+ #
51
+ # The different available types are documented in the features, such as in
52
+ # https://relishapp.com/rspec/rspec-rails/docs
53
+ config.infer_spec_type_from_file_location!
54
+
55
+ # Filter lines from Rails gems in backtraces.
56
+ config.filter_rails_from_backtrace!
57
+ # arbitrary gems may also be filtered via:
58
+ # config.filter_gems_from_backtrace("gem name")
59
+
60
+ config.before(:suite) do
61
+ FactoryGirl.definition_file_paths << File
62
+ .expand_path("../dummy/spec/factories", __FILE__)
63
+ # puts FactoryGirl.definition_file_paths.class.to_s
64
+ FactoryGirl.find_definitions
65
+ end
66
+
67
+ config.before(:suite) do
68
+ Warden.test_mode!
69
+ DatabaseCleaner.clean_with(:truncation)
70
+ end
71
+
72
+ config.before(:each) do
73
+ # DatabaseCleaner.strategy = :transaction
74
+ end
75
+
76
+ config.before(:each, :js => true) do
77
+ DatabaseCleaner.strategy = :truncation
78
+ page.driver.resize(1600, 1200)
79
+ end
80
+
81
+ config.before(:each) do
82
+ DatabaseCleaner.start
83
+ ActionMailer::Base.deliveries = []
84
+ end
85
+
86
+ config.after(:each) do
87
+ DatabaseCleaner.clean
88
+ Warden.test_reset!
89
+ end
90
+
91
+ config.include Devise::Test::ControllerHelpers, :type => :controller
92
+ config.include Warden::Test::Helpers, :type => :feature
93
+ config.include FeatureHelpers, :type => :feature
94
+ config.include GeneralHelpers
95
+ end
@@ -0,0 +1,103 @@
1
+ require 'factory_girl'
2
+
3
+ # This file was generated by the `rails generate rspec:install` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
6
+ # this file to always be loaded, without a need to explicitly require it in any
7
+ # files.
8
+ #
9
+ # Given that it is always loaded, you are encouraged to keep this file as
10
+ # light-weight as possible. Requiring heavyweight dependencies from this file
11
+ # will add to the boot time of your test suite on EVERY test run, even for an
12
+ # individual file that may not need all of that loaded. Instead, consider making
13
+ # a separate helper file that requires the additional dependencies and performs
14
+ # the additional setup, and require it from the spec files that actually need
15
+ # it.
16
+ #
17
+ # The `.rspec` file also contains a few flags that are not defaults but that
18
+ # users commonly want.
19
+ #
20
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
+ RSpec.configure do |config|
22
+ # rspec-expectations config goes here. You can use an alternate
23
+ # assertion/expectation library such as wrong or the stdlib/minitest
24
+ # assertions if you prefer.
25
+ config.expect_with :rspec do |expectations|
26
+ # This option will default to `true` in RSpec 4. It makes the `description`
27
+ # and `failure_message` of custom matchers include text for helper methods
28
+ # defined using `chain`, e.g.:
29
+ # be_bigger_than(2).and_smaller_than(4).description
30
+ # # => "be bigger than 2 and smaller than 4"
31
+ # ...rather than:
32
+ # # => "be bigger than 2"
33
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34
+ end
35
+
36
+ # rspec-mocks config goes here. You can use an alternate test double
37
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
38
+ config.mock_with :rspec do |mocks|
39
+ # Prevents you from mocking or stubbing a method that does not exist on
40
+ # a real object. This is generally recommended, and will default to
41
+ # `true` in RSpec 4.
42
+ mocks.verify_partial_doubles = true
43
+ end
44
+
45
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
46
+ # have no way to turn it off -- the option exists only for backwards
47
+ # compatibility in RSpec 3). It causes shared context metadata to be
48
+ # inherited by the metadata hash of host groups and examples, rather than
49
+ # triggering implicit auto-inclusion in groups with matching metadata.
50
+ config.shared_context_metadata_behavior = :apply_to_host_groups
51
+
52
+ # The settings below are suggested to provide a good initial experience
53
+ # with RSpec, but feel free to customize to your heart's content.
54
+ =begin
55
+ # This allows you to limit a spec run to individual examples or groups
56
+ # you care about by tagging them with `:focus` metadata. When nothing
57
+ # is tagged with `:focus`, all examples get run. RSpec also provides
58
+ # aliases for `it`, `describe`, and `context` that include `:focus`
59
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
60
+ config.filter_run_when_matching :focus
61
+
62
+ # Allows RSpec to persist some state between runs in order to support
63
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
64
+ # you configure your source control system to ignore this file.
65
+ config.example_status_persistence_file_path = "spec/examples.txt"
66
+
67
+ # Limits the available syntax to the non-monkey patched syntax that is
68
+ # recommended. For more details, see:
69
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
70
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
71
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
72
+ config.disable_monkey_patching!
73
+
74
+ # Many RSpec users commonly either run the entire suite or an individual
75
+ # file, and it's useful to allow more verbose output when running an
76
+ # individual spec file.
77
+ if config.files_to_run.one?
78
+ # Use the documentation formatter for detailed output,
79
+ # unless a formatter has already been configured
80
+ # (e.g. via a command-line flag).
81
+ config.default_formatter = 'doc'
82
+ end
83
+
84
+ # Print the 10 slowest examples and example groups at the
85
+ # end of the spec run, to help surface which specs are running
86
+ # particularly slow.
87
+ config.profile_examples = 10
88
+
89
+ # Run specs in random order to surface order dependencies. If you find an
90
+ # order dependency and want to debug it, you can fix the order by providing
91
+ # the seed, which is printed after each run.
92
+ # --seed 1234
93
+ config.order = :random
94
+
95
+ # Seed global randomization in this process using the `--seed` CLI option.
96
+ # Setting this allows you to use `--seed` to deterministically reproduce
97
+ # test failures related to randomization by passing the same `--seed` value
98
+ # as the one that triggered the failure.
99
+ Kernel.srand config.seed
100
+ =end
101
+
102
+ config.include FactoryGirl::Syntax::Methods
103
+ end