hertz 1.0.0 → 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.
@@ -1,11 +1,18 @@
1
- example_id | status | run_time |
2
- -------------------------------------------------- | ------ | --------------- |
3
- ./spec/hertz/notifiable_spec.rb[1:1:1] | passed | 0.01387 seconds |
4
- ./spec/hertz/notifiable_spec.rb[1:2:1] | passed | 0.0633 seconds |
5
- ./spec/hertz/notification_deliverer_spec.rb[1:1:1] | passed | 0.01347 seconds |
6
- ./spec/models/hertz/notification_spec.rb[1:1:1] | passed | 0.00661 seconds |
7
- ./spec/models/hertz/notification_spec.rb[1:2:1] | passed | 0.00762 seconds |
8
- ./spec/models/hertz/notification_spec.rb[1:3:1] | passed | 0.0372 seconds |
9
- ./spec/models/hertz/notification_spec.rb[1:4:1] | passed | 0.01552 seconds |
10
- ./spec/models/hertz/notification_spec.rb[1:5:1] | passed | 0.01958 seconds |
11
- ./spec/models/hertz/notification_spec.rb[1:6] | passed | 0.01646 seconds |
1
+ example_id | status | run_time |
2
+ ---------------------------------------------------- | ------ | --------------- |
3
+ ./spec/hertz/hertz_spec.rb[1:1:1] | passed | 0.00819 seconds |
4
+ ./spec/hertz/notifiable_spec.rb[1:1:1] | passed | 0.01368 seconds |
5
+ ./spec/hertz/notifiable_spec.rb[1:2:1] | passed | 0.0345 seconds |
6
+ ./spec/hertz/notification_deliverer_spec.rb[1:1:1] | passed | 0.02577 seconds |
7
+ ./spec/hertz/notification_deliverer_spec.rb[1:1:2:1] | passed | 0.01488 seconds |
8
+ ./spec/hertz/notification_deliverer_spec.rb[1:1:2:2] | passed | 0.01501 seconds |
9
+ ./spec/models/hertz/delivery_spec.rb[1:1] | passed | 0.00778 seconds |
10
+ ./spec/models/hertz/delivery_spec.rb[1:2] | passed | 0.15849 seconds |
11
+ ./spec/models/hertz/notification_spec.rb[1:1:1] | passed | 0.00711 seconds |
12
+ ./spec/models/hertz/notification_spec.rb[1:2:1] | passed | 0.00692 seconds |
13
+ ./spec/models/hertz/notification_spec.rb[1:3:1] | passed | 0.01355 seconds |
14
+ ./spec/models/hertz/notification_spec.rb[1:4:1] | passed | 0.01073 seconds |
15
+ ./spec/models/hertz/notification_spec.rb[1:5:1] | passed | 0.01763 seconds |
16
+ ./spec/models/hertz/notification_spec.rb[1:6:1] | passed | 0.01407 seconds |
17
+ ./spec/models/hertz/notification_spec.rb[1:7:1] | passed | 0.01344 seconds |
18
+ ./spec/models/hertz/notification_spec.rb[1:8] | passed | 0.0093 seconds |
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+ FactoryGirl.define do
3
+ factory :delivery, class: 'Hertz::Delivery' do
4
+ association :notification, strategy: :build
5
+ courier 'test'
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ RSpec.describe Hertz do
3
+ describe '.configure' do
4
+ after(:each) { described_class.common_couriers = [] }
5
+
6
+ it 'configures the module' do
7
+ expect {
8
+ described_class.configure do |config|
9
+ config.common_couriers = [:test]
10
+ end
11
+ }.to change(described_class, :common_couriers).to([:test])
12
+ end
13
+ end
14
+ end
@@ -3,29 +3,64 @@ module Hertz
3
3
  RSpec.describe NotificationDeliverer do
4
4
  subject { described_class }
5
5
 
6
- before(:each) do
6
+ before(:all) do
7
7
  module Courier
8
- module Test
8
+ class Test
9
9
  def self.deliver_notification(_notification)
10
10
  end
11
11
  end
12
12
  end
13
-
14
- class TestNotification < Notification
15
- deliver_by :test
16
- end
17
13
  end
18
14
 
19
15
  describe '#deliver' do
20
- let(:notification) { TestNotification.new }
16
+ let(:notification) do
17
+ Class.new(TestNotification) do
18
+ deliver_by :test
19
+ end.new
20
+ end
21
21
 
22
22
  it 'delivers the notification through the couriers' do
23
23
  expect(Hertz::Courier::Test).to receive(:deliver_notification)
24
- .with(notification)
25
24
  .once
25
+ .with(notification)
26
26
 
27
27
  subject.deliver(notification)
28
28
  end
29
+
30
+ context 'when common couriers are defined' do
31
+ before(:all) do
32
+ module Courier
33
+ class Common
34
+ def self.deliver_notification(_notification)
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ before(:each) do
41
+ allow(Hertz).to receive(:common_couriers)
42
+ .and_return([:common])
43
+
44
+ allow(Hertz::Courier::Test).to receive(:deliver_notification)
45
+ allow(Hertz::Courier::Common).to receive(:deliver_notification)
46
+ end
47
+
48
+ it 'uses common couriers' do
49
+ expect(Hertz::Courier::Test).to receive(:deliver_notification)
50
+ .once
51
+ .with(notification)
52
+
53
+ subject.deliver(notification)
54
+ end
55
+
56
+ it 'uses model-specific couriers' do
57
+ expect(Hertz::Courier::Common).to receive(:deliver_notification)
58
+ .once
59
+ .with(notification)
60
+
61
+ subject.deliver(notification)
62
+ end
63
+ end
29
64
  end
30
65
  end
31
66
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module Hertz
3
+ RSpec.describe Delivery do
4
+ subject { build_stubbed(:delivery) }
5
+
6
+ %w(notification courier).each do |attribute|
7
+ it "validates the presence of #{attribute}" do
8
+ expect(subject).to validate_presence_of(attribute)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -41,6 +41,26 @@ module Hertz
41
41
  end
42
42
  end
43
43
 
44
+ describe '#delivered_with?' do
45
+ subject { create(:notification) }
46
+
47
+ it 'returns whether it has been delivered with that courier' do
48
+ expect {
49
+ create(:delivery, notification: subject, courier: :test)
50
+ }.to change { subject.delivered_with?(:test) }.from(false).to(true)
51
+ end
52
+ end
53
+
54
+ describe '#mark_delivered_with' do
55
+ subject { create(:notification) }
56
+
57
+ it 'creates a delivery for that courier' do
58
+ expect {
59
+ subject.mark_delivered_with(:test)
60
+ }.to change(subject.deliveries, :count).by(1)
61
+ end
62
+ end
63
+
44
64
  describe '.unread' do
45
65
  let!(:unread_notification) { create(:notification) }
46
66
  let!(:read_notification) { create(:notification, :read) }
@@ -12,9 +12,6 @@ require 'rspec/rails'
12
12
  # Load RSpec helpers.
13
13
  Dir[File.join(ENGINE_ROOT, 'spec/support/**/*.rb')].each { |f| require f }
14
14
 
15
- # Load testing libraries.
16
- require 'faker'
17
-
18
15
  # Load migrations from the dummy app.
19
16
  ActiveRecord::Migrator.migrations_paths = File.join(ENGINE_ROOT, 'spec/dummy/db/migrate')
20
17
  ActiveRecord::Migration.maintain_test_schema!
@@ -7,7 +7,7 @@ RSpec.configure do |config|
7
7
  )
8
8
  end
9
9
 
10
- config.before(:each) { DatabaseCleaner.strategy = :transaction }
10
+ config.before(:each) { DatabaseCleaner.strategy = :truncation }
11
11
 
12
12
  config.before(:each, js: true) do
13
13
  DatabaseCleaner.strategy = :truncation,
@@ -0,0 +1 @@
1
+ require 'faker'
@@ -0,0 +1,8 @@
1
+ require 'shoulda-matchers'
2
+
3
+ Shoulda::Matchers.configure do |config|
4
+ config.integrate do |with|
5
+ with.test_framework :rspec
6
+ with.library :rails
7
+ end
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hertz
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Desantis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-08 00:00:00.000000000 Z
11
+ date: 2016-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: shoulda-matchers
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
139
153
  description:
140
154
  email:
141
155
  - desa.alessandro@gmail.com
@@ -150,10 +164,13 @@ files:
150
164
  - app/assets/stylesheets/hertz/application.css
151
165
  - app/controllers/hertz/application_controller.rb
152
166
  - app/helpers/hertz/application_helper.rb
167
+ - app/models/hertz/delivery.rb
153
168
  - app/models/hertz/notification.rb
154
169
  - app/views/layouts/hertz/application.html.erb
155
170
  - config/routes.rb
156
171
  - db/migrate/20160415174901_create_hertz_notifications.rb
172
+ - db/migrate/20160627084018_create_hertz_notification_deliveries.rb
173
+ - db/migrate/20160628084342_rename_notification_deliveries_to_deliveries.rb
157
174
  - lib/generators/hertz/install_generator.rb
158
175
  - lib/generators/hertz/templates/initializer.rb
159
176
  - lib/hertz.rb
@@ -200,6 +217,8 @@ files:
200
217
  - spec/dummy/db/migrate/20160415175837_create_users.rb
201
218
  - spec/dummy/db/migrate/20160418122437_add_email_to_users.rb
202
219
  - spec/dummy/db/migrate/20160508094342_remove_email_from_users.rb
220
+ - spec/dummy/db/migrate/20160627084119_create_hertz_notification_deliveries.hertz.rb
221
+ - spec/dummy/db/migrate/20160628084413_rename_notification_deliveries_to_deliveries.hertz.rb
203
222
  - spec/dummy/db/schema.rb
204
223
  - spec/dummy/log/development.log
205
224
  - spec/dummy/log/test.log
@@ -208,15 +227,20 @@ files:
208
227
  - spec/dummy/public/500.html
209
228
  - spec/dummy/public/favicon.ico
210
229
  - spec/examples.txt
230
+ - spec/factories/hertz/deliveries.rb
211
231
  - spec/factories/hertz/notifications.rb
212
232
  - spec/factories/users.rb
233
+ - spec/hertz/hertz_spec.rb
213
234
  - spec/hertz/notifiable_spec.rb
214
235
  - spec/hertz/notification_deliverer_spec.rb
236
+ - spec/models/hertz/delivery_spec.rb
215
237
  - spec/models/hertz/notification_spec.rb
216
238
  - spec/rails_helper.rb
217
239
  - spec/spec_helper.rb
218
240
  - spec/support/database_cleaner.rb
219
241
  - spec/support/factory_girl.rb
242
+ - spec/support/faker.rb
243
+ - spec/support/shoulda.rb
220
244
  homepage: https://github.com/alessandro1997/hertz
221
245
  licenses:
222
246
  - MIT
@@ -243,58 +267,65 @@ specification_version: 4
243
267
  summary: A Rails engine for in-app notifications.
244
268
  test_files:
245
269
  - spec/spec_helper.rb
246
- - spec/hertz/notifiable_spec.rb
247
- - spec/hertz/notification_deliverer_spec.rb
248
- - spec/factories/hertz/notifications.rb
249
- - spec/factories/users.rb
250
- - spec/support/factory_girl.rb
251
- - spec/support/database_cleaner.rb
252
- - spec/models/hertz/notification_spec.rb
253
- - spec/examples.txt
254
270
  - spec/rails_helper.rb
271
+ - spec/dummy/db/schema.rb
272
+ - spec/dummy/db/migrate/20160418122437_add_email_to_users.rb
273
+ - spec/dummy/db/migrate/20160415175358_create_hertz_notifications.hertz.rb
255
274
  - spec/dummy/db/migrate/20160415175837_create_users.rb
275
+ - spec/dummy/db/migrate/20160628084413_rename_notification_deliveries_to_deliveries.hertz.rb
276
+ - spec/dummy/db/migrate/20160627084119_create_hertz_notification_deliveries.hertz.rb
256
277
  - spec/dummy/db/migrate/20160508094342_remove_email_from_users.rb
257
- - spec/dummy/db/migrate/20160415175358_create_hertz_notifications.hertz.rb
258
- - spec/dummy/db/migrate/20160418122437_add_email_to_users.rb
259
- - spec/dummy/db/schema.rb
260
- - spec/dummy/bin/rake
261
- - spec/dummy/bin/rails
262
- - spec/dummy/bin/setup
263
- - spec/dummy/bin/bundle
264
- - spec/dummy/app/views/hertz/notification_mailer/test_notification.html.erb
265
- - spec/dummy/app/views/layouts/application.html.erb
266
- - spec/dummy/app/models/user.rb
267
- - spec/dummy/app/models/test_notification.rb
268
- - spec/dummy/app/helpers/application_helper.rb
269
- - spec/dummy/app/controllers/application_controller.rb
270
- - spec/dummy/app/assets/stylesheets/application.css
271
- - spec/dummy/app/assets/javascripts/application.js
278
+ - spec/dummy/README.rdoc
279
+ - spec/dummy/public/500.html
272
280
  - spec/dummy/public/422.html
273
281
  - spec/dummy/public/favicon.ico
274
- - spec/dummy/public/500.html
275
282
  - spec/dummy/public/404.html
276
- - spec/dummy/README.rdoc
277
- - spec/dummy/config.ru
283
+ - spec/dummy/bin/setup
284
+ - spec/dummy/bin/rails
285
+ - spec/dummy/bin/rake
286
+ - spec/dummy/bin/bundle
287
+ - spec/dummy/config/database.example.yml
288
+ - spec/dummy/config/environments/production.rb
289
+ - spec/dummy/config/environments/development.rb
290
+ - spec/dummy/config/environments/test.rb
278
291
  - spec/dummy/config/boot.rb
292
+ - spec/dummy/config/environment.rb
293
+ - spec/dummy/config/database.yml
279
294
  - spec/dummy/config/initializers/inflections.rb
295
+ - spec/dummy/config/initializers/hertz.rb
296
+ - spec/dummy/config/initializers/assets.rb
280
297
  - spec/dummy/config/initializers/backtrace_silencers.rb
298
+ - spec/dummy/config/initializers/mime_types.rb
281
299
  - spec/dummy/config/initializers/cookies_serializer.rb
282
- - spec/dummy/config/initializers/session_store.rb
283
- - spec/dummy/config/initializers/assets.rb
284
300
  - spec/dummy/config/initializers/wrap_parameters.rb
285
- - spec/dummy/config/initializers/mime_types.rb
286
- - spec/dummy/config/initializers/hertz.rb
287
301
  - spec/dummy/config/initializers/filter_parameter_logging.rb
288
- - spec/dummy/config/application.rb
302
+ - spec/dummy/config/initializers/session_store.rb
289
303
  - spec/dummy/config/secrets.yml
290
- - spec/dummy/config/environments/development.rb
291
- - spec/dummy/config/environments/production.rb
292
- - spec/dummy/config/environments/test.rb
293
304
  - spec/dummy/config/locales/en.yml
294
- - spec/dummy/config/database.yml
295
- - spec/dummy/config/environment.rb
296
- - spec/dummy/config/database.example.yml
305
+ - spec/dummy/config/application.rb
297
306
  - spec/dummy/config/routes.rb
298
- - spec/dummy/Rakefile
299
- - spec/dummy/log/test.log
307
+ - spec/dummy/config.ru
300
308
  - spec/dummy/log/development.log
309
+ - spec/dummy/log/test.log
310
+ - spec/dummy/app/helpers/application_helper.rb
311
+ - spec/dummy/app/controllers/application_controller.rb
312
+ - spec/dummy/app/models/user.rb
313
+ - spec/dummy/app/models/test_notification.rb
314
+ - spec/dummy/app/assets/javascripts/application.js
315
+ - spec/dummy/app/assets/stylesheets/application.css
316
+ - spec/dummy/app/views/layouts/application.html.erb
317
+ - spec/dummy/app/views/hertz/notification_mailer/test_notification.html.erb
318
+ - spec/dummy/Rakefile
319
+ - spec/support/database_cleaner.rb
320
+ - spec/support/faker.rb
321
+ - spec/support/shoulda.rb
322
+ - spec/support/factory_girl.rb
323
+ - spec/hertz/notification_deliverer_spec.rb
324
+ - spec/hertz/notifiable_spec.rb
325
+ - spec/hertz/hertz_spec.rb
326
+ - spec/models/hertz/delivery_spec.rb
327
+ - spec/models/hertz/notification_spec.rb
328
+ - spec/examples.txt
329
+ - spec/factories/hertz/deliveries.rb
330
+ - spec/factories/hertz/notifications.rb
331
+ - spec/factories/users.rb