abstract_notifier 0.2.0 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a36463d0a1ed93c6f48229bed9135f6c1ec3e301c76dc5b9edcc28f19d75cc3e
4
- data.tar.gz: 7c56ec837be932967f22c592018b2210912fb2e53a40e5b8526b619dff70c4b1
3
+ metadata.gz: 13fab6c214c70888c9977a9e924d3ede95c09de3b9f0207285967af0c20a5db2
4
+ data.tar.gz: 922c76000a77862e8a3cbf1fe5d6dad49656f39fd8ad8df30cbcc6b0ea705a6a
5
5
  SHA512:
6
- metadata.gz: 4a191cf257f1691d8df1b395ed14610246e2ae8614bde594abd359fea8104fe3c903a9332060545563e289652b45716d76c89d2f763a8bd0c911d305641c594d
7
- data.tar.gz: 888f89197efafc92cbbfffc220959c449fcd405c8fea6932ab3f1dde4ed4f1d726e2c19ce4c43e68ca2021a8cc040a53831506c05a5272ce7f43330e4b054364
6
+ metadata.gz: d58c62166442f76b74b077d85219eb853b83a8453b8e7da9e465e7e6b3217c10f78c1f1bf6a7ce6e7c50d8a12d4274e3fd7fccb592e26ca8d2206b1da0c13437
7
+ data.tar.gz: 37b900f7210fcee8f5201658f6a2ec42e5e81eec289cd5a60537df71b945f9b5d293304b75f70ce2a64fd4e56ce69a5bb03bccd8bcb674b07b1afac082c32e8e
data/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.3.2 (2022-06-02)
6
+
7
+ - Added Minitest assertions. ([@komagata][])
8
+
9
+ ## 0.3.1 (2020-04-09)
10
+
11
+ - Fix loading testing utils. ([@brovikov][])
12
+
13
+ Change the RSpec check to `defined?(RSpec::Core)` to prevent from
14
+ loading testing utils when only `RSpec` module is defined.
15
+
16
+ ## 0.3.0 (2020-03-02)
17
+
18
+ - **Drop Ruby 2.4 support**. ([@palkan][])
19
+
5
20
  ## 0.2.0 (2018-01-11)
6
21
 
7
22
  - Add class-level defaults. ([@palkan][])
@@ -13,3 +28,5 @@
13
28
  Initial version.
14
29
 
15
30
  [@palkan]: https://github.com/palkan
31
+ [@brovikov]: https://github.com/brovikov
32
+ [@komagata]: https://github.com/komagata
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/abstract_notifier.svg)](https://badge.fury.io/rb/abstract_notifier)
2
- [![Build Status](https://travis-ci.org/palkan/abstract_notifier.svg?branch=master)](https://travis-ci.org/palkan/abstract_notifier)
2
+ [![Build](https://github.com/palkan/abstract_notifier/workflows/Build/badge.svg)](https://github.com/palkan/abstract_notifier/actions)
3
3
 
4
4
  # Abstract Notifier
5
5
 
@@ -7,11 +7,13 @@ Abstract Notifier is a tool which allows you to describe/model any text-based no
7
7
 
8
8
  Abstract Notifier (as the name states) doesn't provide any specific implementation for sending notifications. Instead, it offers tools to organize your notification-specific code and make it easily testable.
9
9
 
10
+ 📖 Read the introduction post: ["Crafting user notifications in Rails with Active Delivery"](https://evilmartians.com/chronicles/crafting-user-notifications-in-rails-with-active-delivery)
11
+
10
12
  <a href="https://evilmartians.com/?utm_source=action_policy">
11
13
  <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54"></a>
12
14
 
13
15
  Requirements:
14
- - Ruby ~> 2.3
16
+ - Ruby ~> 2.4
15
17
 
16
18
  **NOTE**: although most of the examples in this readme are Rails-specific, this gem could be used without Rails/ActiveSupport.
17
19
 
@@ -20,7 +22,7 @@ Requirements:
20
22
  Add this line to your application's Gemfile:
21
23
 
22
24
  ```ruby
23
- gem 'abstract_notifier'
25
+ gem "abstract_notifier"
24
26
  ```
25
27
 
26
28
  And then execute:
@@ -103,10 +105,9 @@ You can also specify a block or a method name as the default params _generator_.
103
105
  This could be useful in combination with the `#notification_name` method to generate dynamic payloads:
104
106
 
105
107
  ```ruby
106
- class ApplicationNotifier < AbstractNofitier::Base
108
+ class ApplicationNotifier < AbstractNotifier::Base
107
109
  default :build_defaults_from_locale
108
110
 
109
-
110
111
  private
111
112
 
112
113
  def build_defaults_from_locale
@@ -159,15 +160,14 @@ For test/development purposes there are two special _global_ delivery modes:
159
160
  # config/environments/test.rb
160
161
  AbstractNotifier.delivery_mode = :test
161
162
 
162
-
163
163
  # If you don't want to trigger notifications in development,
164
164
  # you can make Abstract Notifier no-op.
165
165
  #
166
166
  # config/environments/development.rb
167
- ActionNotifier.delivery_mode = :noop
167
+ AbstractNotifier.delivery_mode = :noop
168
168
 
169
169
  # Default delivery mode is "normal"
170
- ActionNotifier.delivery_mode = :normal
170
+ AbstractNotifier.delivery_mode = :normal
171
171
  ```
172
172
 
173
173
  **NOTE:** we set `delivery_mode = :test` if `RAILS_ENV` or `RACK_ENV` env variable is equal to "test".
@@ -181,14 +181,36 @@ Abstract Notifier provides two convinient RSpec matchers:
181
181
 
182
182
  ```ruby
183
183
  # for testing sync notifications (sent with `notify_now`)
184
- expect { EventsNotifier.with(profile: profile).canceled(event).notify_now }.
185
- to have_sent_notification(identify: '123', body: 'Alarma!')
184
+ expect { EventsNotifier.with(profile: profile).canceled(event).notify_now }
185
+ .to have_sent_notification(identify: "123", body: "Alarma!")
186
186
 
187
187
  # for testing async notifications (sent with `notify_later`)
188
- expect { EventsNotifier.with(profile: profile).canceled(event).notify_later}.
189
- to have_enqueued_notification(identify: '123', body: 'Alarma!')
188
+ expect { EventsNotifier.with(profile: profile).canceled(event).notify_later }
189
+ .to have_enqueued_notification(identify: "123", body: "Alarma!")
190
+ ```
191
+
192
+ Abstract Notifier provides two convinient minitest assertions:
193
+
194
+ ```ruby
195
+ require 'abstract_notifier/testing/minitest'
196
+
197
+ class EventsNotifierTestCase < Minitest::Test
198
+ include AbstractNotifier::TestHelper
199
+
200
+ test 'canceled' do
201
+ assert_notifications_sent 1, identify: "123", body: "Alarma!" do
202
+ EventsNotifier.with(profile: profile).canceled(event).notify_now
203
+ end
204
+
205
+ assert_notifications_enqueued 1, identify: "123", body: "Alarma!" do
206
+ EventsNotifier.with(profile: profile).canceled(event).notify_later
207
+ end
208
+ end
209
+ end
190
210
  ```
191
211
 
212
+ **NOTE:** test mode activated automatically if `RAILS_ENV` or `RACK_ENV` env variable is equal to "test". Otherwise add `require "abstract_notifier/testing/rspec"` to your `spec_helper.rb` / `rails_helper.rb` manually. This is also required if you're using Spring in test environment (e.g. with help of [spring-commands-rspec](https://github.com/jonleighton/spring-commands-rspec)).
213
+
192
214
  ## Related projects
193
215
 
194
216
  ### [`active_delivery`](https://github.com/palkan/active_delivery)
@@ -203,7 +225,7 @@ class ApplicationDelivery < ActiveDelivery::Base
203
225
  register_line :notifier, ActiveDelivery::Lines::Notifier,
204
226
  # you may provide a resolver, which infers notifier class
205
227
  # from delivery name (resolver is a callable).
206
- resolver: ->(name) { resolve_somehow(name) }
228
+ resolver: ->(name) { resolve_somehow(name) }
207
229
  end
208
230
  ```
209
231
 
@@ -7,7 +7,7 @@ module AbstractNotifier
7
7
  return adapter unless adapter.is_a?(Symbol)
8
8
 
9
9
  adapter_class_name = adapter.to_s.split("_").map(&:capitalize).join
10
- AsyncAdapters.const_get(adapter_class_name).new(options || {})
10
+ AsyncAdapters.const_get(adapter_class_name).new(**(options || {}))
11
11
  rescue NameError => e
12
12
  raise e.class, "Notifier async adapter :#{adapter} haven't been found", e.backtrace
13
13
  end
@@ -34,8 +34,12 @@ module AbstractNotifier
34
34
  end
35
35
 
36
36
  # rubocop:disable Style/MethodMissingSuper
37
- def method_missing(method_name, *args)
38
- notifier_class.new(method_name, params).public_send(method_name, *args)
37
+ def method_missing(method_name, *args, **kwargs)
38
+ if kwargs.empty?
39
+ notifier_class.new(method_name, **params).public_send(method_name, *args)
40
+ else
41
+ notifier_class.new(method_name, **params).public_send(method_name, *args, **kwargs)
42
+ end
39
43
  end
40
44
  # rubocop:enable Style/MethodMissingSuper
41
45
 
@@ -75,8 +79,8 @@ module AbstractNotifier
75
79
  end
76
80
  end
77
81
 
78
- def default(method_name = nil, **hargs)
79
- return @defaults_generator = Proc.new if block_given?
82
+ def default(method_name = nil, **hargs, &block)
83
+ return @defaults_generator = block if block
80
84
 
81
85
  return @defaults_generator = proc { send(method_name) } unless method_name.nil?
82
86
 
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbstractNotifier
4
+ module TestHelper
5
+ def assert_notifications_sent(count, params)
6
+ yield
7
+ assert_equal deliveries.count, count
8
+ count.times do |i|
9
+ delivery = deliveries[0 - i]
10
+ msg = message(msg) { "Expected #{mu_pp(delivery)} to include #{mu_pp(params)}" }
11
+ assert hash_include?(delivery, params), msg
12
+ end
13
+ end
14
+
15
+ def assert_notifications_enqueued(count, params)
16
+ yield
17
+ assert_equal enqueued_deliveries.count, count
18
+ count.times do |i|
19
+ delivery = enqueued_deliveries[0 - i]
20
+ msg = message(msg) { "Expected #{mu_pp(delivery)} to include #{mu_pp(params)}" }
21
+ assert hash_include?(delivery, params), msg
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def deliveries
28
+ AbstractNotifier::Testing::Driver.deliveries
29
+ end
30
+
31
+ def enqueued_deliveries
32
+ AbstractNotifier::Testing::Driver.enqueued_deliveries
33
+ end
34
+
35
+ def hash_include?(haystack, needle)
36
+ needle.all? do |k, v|
37
+ haystack.key?(k) && haystack[k] == v
38
+ end
39
+ end
40
+ end
41
+ end
@@ -129,7 +129,7 @@ module AbstractNotifier
129
129
  end
130
130
  end
131
131
 
132
- class HaveEqueuedNotification < HaveSentNotification
132
+ class HaveEnqueuedNotification < HaveSentNotification
133
133
  private
134
134
 
135
135
  def deliveries
@@ -153,7 +153,7 @@ RSpec.configure do |config|
153
153
  end
154
154
 
155
155
  def have_enqueued_notification(*args)
156
- AbstractNotifier::HaveEqueuedNotification.new(*args)
156
+ AbstractNotifier::HaveEnqueuedNotification.new(*args)
157
157
  end
158
158
  end)
159
159
  end
@@ -45,4 +45,5 @@ end
45
45
 
46
46
  AbstractNotifier::Notification.prepend AbstractNotifier::Testing::Notification
47
47
 
48
- require "abstract_notifier/testing/rspec" if defined?(RSpec)
48
+ require "abstract_notifier/testing/rspec" if defined?(RSpec::Core)
49
+ require "abstract_notifier/testing/minitest" if defined?(Minitest::Assertions)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AbstractNotifier
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.2"
5
5
  end
@@ -11,9 +11,9 @@ module ActiveDelivery
11
11
  class Notifier < ActiveDelivery::Lines::Base
12
12
  DEFAULT_RESOLVER = ->(name) { name.gsub(/Delivery$/, "Notifier").safe_constantize }
13
13
 
14
- def initialize(*)
14
+ def initialize(**opts)
15
15
  super
16
- @resolver = options[:resolver]
16
+ @resolver = opts[:resolver]
17
17
  end
18
18
 
19
19
  def resolve_class(name)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abstract_notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-12 00:00:00.000000000 Z
11
+ date: 2022-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_delivery
@@ -28,58 +28,44 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.16'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.16'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '10.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '10.0'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
45
+ - - ">="
60
46
  - !ruby/object:Gem::Version
61
- version: '3.0'
47
+ version: '13.0'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - "~>"
52
+ - - ">="
67
53
  - !ruby/object:Gem::Version
68
- version: '3.0'
54
+ version: '13.0'
69
55
  - !ruby/object:Gem::Dependency
70
- name: standard
56
+ name: rspec-rails
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - "~>"
59
+ - - ">="
74
60
  - !ruby/object:Gem::Version
75
- version: 0.0.12
61
+ version: '4.0'
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - "~>"
66
+ - - ">="
81
67
  - !ruby/object:Gem::Version
82
- version: 0.0.12
68
+ version: '4.0'
83
69
  description: ActionMailer-like interface for any type of notifications
84
70
  email:
85
71
  - dementiev.vm@gmail.com
@@ -87,33 +73,30 @@ executables: []
87
73
  extensions: []
88
74
  extra_rdoc_files: []
89
75
  files:
90
- - ".gitignore"
91
- - ".rspec"
92
- - ".rubocop.yml"
93
- - ".travis.yml"
94
76
  - CHANGELOG.md
95
- - Gemfile
96
77
  - LICENSE.txt
97
78
  - README.md
98
- - Rakefile
99
- - abstract_notifier.gemspec
100
79
  - bin/console
101
80
  - bin/setup
102
- - gemfiles/rails42.gemfile
103
- - gemfiles/railsmaster.gemfile
104
81
  - lib/abstract_notifier.rb
105
82
  - lib/abstract_notifier/async_adapters.rb
106
83
  - lib/abstract_notifier/async_adapters/active_job.rb
107
84
  - lib/abstract_notifier/base.rb
108
85
  - lib/abstract_notifier/testing.rb
86
+ - lib/abstract_notifier/testing/minitest.rb
109
87
  - lib/abstract_notifier/testing/rspec.rb
110
88
  - lib/abstract_notifier/version.rb
111
89
  - lib/active_delivery/lines/notifier.rb
112
90
  homepage: https://github.com/palkan/abstract_notifier
113
91
  licenses:
114
92
  - MIT
115
- metadata: {}
116
- post_install_message:
93
+ metadata:
94
+ bug_tracker_uri: http://github.com/palkan/abstract_notifier/issues
95
+ changelog_uri: https://github.com/palkan/abstract_notifier/blob/master/CHANGELOG.md
96
+ documentation_uri: http://github.com/palkan/abstract_notifier
97
+ homepage_uri: http://github.com/palkan/abstract_notifier
98
+ source_code_uri: http://github.com/palkan/abstract_notifier
99
+ post_install_message:
117
100
  rdoc_options: []
118
101
  require_paths:
119
102
  - lib
@@ -121,16 +104,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
104
  requirements:
122
105
  - - ">="
123
106
  - !ruby/object:Gem::Version
124
- version: '0'
107
+ version: '2.4'
125
108
  required_rubygems_version: !ruby/object:Gem::Requirement
126
109
  requirements:
127
110
  - - ">="
128
111
  - !ruby/object:Gem::Version
129
112
  version: '0'
130
113
  requirements: []
131
- rubyforge_project:
132
- rubygems_version: 2.7.6
133
- signing_key:
114
+ rubygems_version: 3.3.7
115
+ signing_key:
134
116
  specification_version: 4
135
117
  summary: ActionMailer-like interface for any type of notifications
136
118
  test_files: []
data/.gitignore DELETED
@@ -1,10 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- Gemfile.lock
10
- Gemfile.local
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/.rubocop.yml DELETED
@@ -1,29 +0,0 @@
1
- require:
2
- - standard/cop/semantic_blocks
3
-
4
- inherit_gem:
5
- standard: config/base.yml
6
-
7
- AllCops:
8
- Exclude:
9
- - 'bin/*'
10
- - 'tmp/**/*'
11
- - 'Gemfile'
12
- - 'node_modules/**/*'
13
- - 'vendor/**/*'
14
- DisplayCopNames: true
15
-
16
- Standard/SemanticBlocks:
17
- Enabled: false
18
-
19
- Style/FrozenStringLiteralComment:
20
- Enabled: true
21
-
22
- Style/TrailingCommaInArrayLiteral:
23
- EnforcedStyleForMultiline: no_comma
24
-
25
- Style/TrailingCommaInHashLiteral:
26
- EnforcedStyleForMultiline: no_comma
27
-
28
- Layout/AlignParameters:
29
- EnforcedStyle: with_first_parameter
data/.travis.yml DELETED
@@ -1,26 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.5.1
5
-
6
- notifications:
7
- email: false
8
-
9
- matrix:
10
- fast_finish: true
11
- include:
12
- - rvm: ruby-head
13
- gemfile: gemfiles/railsmaster.gemfile
14
- - rvm: 2.5.1
15
- gemfile: Gemfile
16
- - rvm: 2.5.1
17
- gemfile: Gemfile
18
- env:
19
- - NO_RAILS=1
20
- - rvm: 2.4.3
21
- gemfile: Gemfile
22
- - rvm: 2.3.1
23
- gemfile: gemfiles/rails42.gemfile
24
- allow_failures:
25
- - rvm: ruby-head
26
- gemfile: gemfiles/railsmaster.gemfile
data/Gemfile DELETED
@@ -1,15 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in abstract_notifier.gemspec
4
- gemspec
5
-
6
- gem "pry-byebug"
7
- gem "rspec-rails"
8
-
9
- local_gemfile = File.join(__dir__, "Gemfile.local")
10
-
11
- if File.exist?(local_gemfile)
12
- eval(File.read(local_gemfile)) # rubocop:disable Security/Eval
13
- else
14
- gem "rails", "~> 5.2"
15
- end
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
5
- require "rubocop/rake_task"
6
-
7
- RuboCop::RakeTask.new
8
- RSpec::Core::RakeTask.new(:spec)
9
-
10
- task default: [:rubocop, :spec]
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- lib = File.expand_path("../lib", __FILE__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require "abstract_notifier/version"
6
-
7
- Gem::Specification.new do |spec|
8
- spec.name = "abstract_notifier"
9
- spec.version = AbstractNotifier::VERSION
10
- spec.authors = ["Vladimir Dementyev"]
11
- spec.email = ["dementiev.vm@gmail.com"]
12
-
13
- spec.summary = "ActionMailer-like interface for any type of notifications"
14
- spec.description = "ActionMailer-like interface for any type of notifications"
15
- spec.homepage = "https://github.com/palkan/abstract_notifier"
16
- spec.license = "MIT"
17
-
18
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_development_dependency "active_delivery"
22
-
23
- spec.add_development_dependency "bundler", "~> 1.16"
24
- spec.add_development_dependency "rake", "~> 10.0"
25
- spec.add_development_dependency "rspec", "~> 3.0"
26
- spec.add_development_dependency "standard", "~> 0.0.12"
27
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 4.2"
6
-
7
- gemspec path: ".."
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", github: "rails/rails"
6
- gem "rubocop", github: "rubocop-hq/rubocop"
7
-
8
- gemspec path: ".."