pubsub_notifier 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +9 -3
- data/lib/generators/rails/templates/notifier.tt +2 -1
- data/lib/generators/rspec/notifier_generator.rb +1 -1
- data/lib/pubsub_notifier/proxy.rb +1 -1
- data/lib/pubsub_notifier/version.rb +1 -1
- data/spec/integration_spec.rb +15 -0
- data/spec/lib/acts_as_notifier_spec.rb +38 -0
- data/spec/lib/base_spec.rb +55 -0
- data/spec/lib/broadcasters/active_job_broadcaster_spec.rb +33 -0
- data/spec/lib/broadcasters_spec.rb +21 -0
- data/spec/lib/client_spec.rb +33 -0
- data/spec/lib/config_spec.rb +7 -0
- data/spec/lib/proxy_spec.rb +60 -0
- data/spec/lib/pubsub_spec.rb +14 -0
- data/spec/lib/slack_client_spec.rb +22 -0
- data/spec/pubsub_notifier_spec.rb +38 -20
- data/spec/rails/rails-4.2.9/README.rdoc +28 -0
- data/spec/rails/rails-4.2.9/Rakefile +6 -0
- data/spec/rails/rails-4.2.9/app/assets/javascripts/application.js +16 -0
- data/spec/rails/rails-4.2.9/app/assets/stylesheets/application.css +15 -0
- data/spec/rails/rails-4.2.9/app/controllers/application_controller.rb +5 -0
- data/spec/rails/rails-4.2.9/app/helpers/application_helper.rb +2 -0
- data/spec/rails/rails-4.2.9/app/mailers/application_mailer.rb +4 -0
- data/spec/rails/rails-4.2.9/app/mailers/post_mailer.rb +13 -0
- data/spec/rails/rails-4.2.9/app/mailers/user_mailer.rb +13 -0
- data/spec/rails/rails-4.2.9/app/models/post.rb +6 -0
- data/spec/rails/rails-4.2.9/app/models/register.rb +9 -0
- data/spec/rails/rails-4.2.9/app/models/user.rb +6 -0
- data/spec/{support → rails/rails-4.2.9/app}/notifiers/application_notifier.rb +0 -0
- data/spec/rails/rails-4.2.9/app/notifiers/post_notifier.rb +12 -0
- data/spec/rails/rails-4.2.9/app/notifiers/user_notifier.rb +12 -0
- data/spec/rails/rails-4.2.9/app/views/layouts/application.html.erb +14 -0
- data/spec/rails/rails-4.2.9/app/views/layouts/mailer.html.erb +5 -0
- data/spec/rails/rails-4.2.9/app/views/layouts/mailer.text.erb +1 -0
- data/spec/rails/rails-4.2.9/app/views/post_mailer/failure.html.erb +5 -0
- data/spec/rails/rails-4.2.9/app/views/post_mailer/failure.text.erb +3 -0
- data/spec/rails/rails-4.2.9/app/views/user_mailer/success.html.erb +5 -0
- data/spec/rails/rails-4.2.9/app/views/user_mailer/success.text.erb +3 -0
- data/spec/rails/rails-4.2.9/bin/bundle +3 -0
- data/spec/rails/rails-4.2.9/bin/rails +4 -0
- data/spec/rails/rails-4.2.9/bin/rake +4 -0
- data/spec/rails/rails-4.2.9/bin/setup +29 -0
- data/spec/rails/rails-4.2.9/config.ru +4 -0
- data/spec/rails/rails-4.2.9/config/application.rb +35 -0
- data/spec/rails/rails-4.2.9/config/boot.rb +3 -0
- data/spec/rails/rails-4.2.9/config/database.yml +25 -0
- data/spec/rails/rails-4.2.9/config/environment.rb +8 -0
- data/spec/rails/rails-4.2.9/config/environments/development.rb +28 -0
- data/spec/rails/rails-4.2.9/config/environments/production.rb +67 -0
- data/spec/rails/rails-4.2.9/config/environments/test.rb +43 -0
- data/spec/rails/rails-4.2.9/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails/rails-4.2.9/config/initializers/cookies_serializer.rb +3 -0
- data/spec/rails/rails-4.2.9/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/rails/rails-4.2.9/config/initializers/inflections.rb +16 -0
- data/spec/rails/rails-4.2.9/config/initializers/mime_types.rb +4 -0
- data/spec/rails/rails-4.2.9/config/initializers/pubsub_notifier.rb +10 -0
- data/spec/rails/rails-4.2.9/config/initializers/session_store.rb +3 -0
- data/spec/rails/rails-4.2.9/config/initializers/to_time_preserves_timezone.rb +10 -0
- data/spec/rails/rails-4.2.9/config/initializers/wrap_parameters.rb +14 -0
- data/spec/rails/rails-4.2.9/config/locales/en.yml +23 -0
- data/spec/rails/rails-4.2.9/config/routes.rb +56 -0
- data/spec/rails/rails-4.2.9/config/secrets.yml +22 -0
- data/spec/rails/rails-4.2.9/db/migrate/20170714092725_create_users.rb +9 -0
- data/spec/rails/rails-4.2.9/db/migrate/20170714092727_create_posts.rb +9 -0
- data/spec/rails/rails-4.2.9/db/schema.rb +28 -0
- data/spec/rails/rails-4.2.9/db/seeds.rb +7 -0
- data/spec/rails/rails-4.2.9/db/test.sqlite3 +0 -0
- data/spec/rails/rails-4.2.9/log/test.log +272 -0
- data/spec/rails/rails-4.2.9/public/404.html +67 -0
- data/spec/rails/rails-4.2.9/public/422.html +67 -0
- data/spec/rails/rails-4.2.9/public/500.html +66 -0
- data/spec/rails/rails-4.2.9/public/favicon.ico +0 -0
- data/spec/rails/rails-4.2.9/public/robots.txt +5 -0
- data/spec/rails/rails-5.0.4/README.md +24 -0
- data/spec/rails/rails-5.0.4/Rakefile +6 -0
- data/spec/rails/rails-5.0.4/app/assets/config/manifest.js +3 -0
- data/spec/rails/rails-5.0.4/app/assets/javascripts/application.js +15 -0
- data/spec/rails/rails-5.0.4/app/assets/javascripts/cable.js +13 -0
- data/spec/rails/rails-5.0.4/app/assets/stylesheets/application.css +15 -0
- data/spec/rails/rails-5.0.4/app/channels/application_cable/channel.rb +4 -0
- data/spec/rails/rails-5.0.4/app/channels/application_cable/connection.rb +4 -0
- data/spec/rails/rails-5.0.4/app/controllers/application_controller.rb +3 -0
- data/spec/rails/rails-5.0.4/app/helpers/application_helper.rb +2 -0
- data/spec/rails/rails-5.0.4/app/jobs/application_job.rb +2 -0
- data/spec/rails/rails-5.0.4/app/mailers/application_mailer.rb +4 -0
- data/spec/rails/rails-5.0.4/app/mailers/post_mailer.rb +14 -0
- data/spec/rails/rails-5.0.4/app/mailers/user_mailer.rb +14 -0
- data/spec/rails/rails-5.0.4/app/models/application_record.rb +3 -0
- data/spec/rails/rails-5.0.4/app/models/post.rb +6 -0
- data/spec/rails/rails-5.0.4/app/models/register.rb +9 -0
- data/spec/rails/rails-5.0.4/app/models/user.rb +6 -0
- data/spec/rails/rails-5.0.4/app/notifiers/application_notifier.rb +2 -0
- data/spec/rails/rails-5.0.4/app/notifiers/post_notifier.rb +12 -0
- data/spec/rails/rails-5.0.4/app/notifiers/user_notifier.rb +12 -0
- data/spec/rails/rails-5.0.4/app/views/layouts/application.html.erb +14 -0
- data/spec/rails/rails-5.0.4/app/views/layouts/mailer.html.erb +13 -0
- data/spec/rails/rails-5.0.4/app/views/layouts/mailer.text.erb +1 -0
- data/spec/rails/rails-5.0.4/app/views/post_mailer/failure.html.erb +5 -0
- data/spec/rails/rails-5.0.4/app/views/post_mailer/failure.text.erb +3 -0
- data/spec/rails/rails-5.0.4/app/views/user_mailer/success.html.erb +5 -0
- data/spec/rails/rails-5.0.4/app/views/user_mailer/success.text.erb +3 -0
- data/spec/rails/rails-5.0.4/bin/bundle +3 -0
- data/spec/rails/rails-5.0.4/bin/rails +4 -0
- data/spec/rails/rails-5.0.4/bin/rake +4 -0
- data/spec/rails/rails-5.0.4/bin/setup +34 -0
- data/spec/rails/rails-5.0.4/bin/update +29 -0
- data/spec/rails/rails-5.0.4/config.ru +5 -0
- data/spec/rails/rails-5.0.4/config/application.rb +25 -0
- data/spec/rails/rails-5.0.4/config/boot.rb +3 -0
- data/spec/rails/rails-5.0.4/config/cable.yml +9 -0
- data/spec/rails/rails-5.0.4/config/database.yml +25 -0
- data/spec/rails/rails-5.0.4/config/environment.rb +8 -0
- data/spec/rails/rails-5.0.4/config/environments/development.rb +47 -0
- data/spec/rails/rails-5.0.4/config/environments/production.rb +78 -0
- data/spec/rails/rails-5.0.4/config/environments/test.rb +43 -0
- data/spec/rails/rails-5.0.4/config/initializers/application_controller_renderer.rb +6 -0
- data/spec/rails/rails-5.0.4/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails/rails-5.0.4/config/initializers/cookies_serializer.rb +5 -0
- data/spec/rails/rails-5.0.4/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/rails/rails-5.0.4/config/initializers/inflections.rb +16 -0
- data/spec/rails/rails-5.0.4/config/initializers/mime_types.rb +4 -0
- data/spec/rails/rails-5.0.4/config/initializers/new_framework_defaults.rb +26 -0
- data/spec/rails/rails-5.0.4/config/initializers/pubsub_notifier.rb +10 -0
- data/spec/rails/rails-5.0.4/config/initializers/session_store.rb +3 -0
- data/spec/rails/rails-5.0.4/config/initializers/wrap_parameters.rb +14 -0
- data/spec/rails/rails-5.0.4/config/locales/en.yml +23 -0
- data/spec/rails/rails-5.0.4/config/puma.rb +47 -0
- data/spec/rails/rails-5.0.4/config/routes.rb +3 -0
- data/spec/rails/rails-5.0.4/config/secrets.yml +22 -0
- data/spec/rails/rails-5.0.4/db/migrate/20170714092740_create_users.rb +9 -0
- data/spec/rails/rails-5.0.4/db/migrate/20170714092741_create_posts.rb +9 -0
- data/spec/rails/rails-5.0.4/db/schema.rb +27 -0
- data/spec/rails/rails-5.0.4/db/seeds.rb +7 -0
- data/spec/rails/rails-5.0.4/db/test.sqlite3 +0 -0
- data/spec/rails/rails-5.0.4/log/test.log +723 -0
- data/spec/rails/rails-5.0.4/public/404.html +67 -0
- data/spec/rails/rails-5.0.4/public/422.html +67 -0
- data/spec/rails/rails-5.0.4/public/500.html +66 -0
- data/spec/rails/rails-5.0.4/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/rails/rails-5.0.4/public/apple-touch-icon.png +0 -0
- data/spec/rails/rails-5.0.4/public/favicon.ico +0 -0
- data/spec/rails/rails-5.0.4/public/robots.txt +5 -0
- data/spec/rails/rails-5.1.2/README.md +24 -0
- data/spec/rails/rails-5.1.2/Rakefile +6 -0
- data/spec/rails/rails-5.1.2/app/assets/config/manifest.js +3 -0
- data/spec/rails/rails-5.1.2/app/assets/javascripts/application.js +15 -0
- data/spec/rails/rails-5.1.2/app/assets/javascripts/cable.js +13 -0
- data/spec/rails/rails-5.1.2/app/assets/stylesheets/application.css +15 -0
- data/spec/rails/rails-5.1.2/app/channels/application_cable/channel.rb +4 -0
- data/spec/rails/rails-5.1.2/app/channels/application_cable/connection.rb +4 -0
- data/spec/rails/rails-5.1.2/app/controllers/application_controller.rb +3 -0
- data/spec/rails/rails-5.1.2/app/helpers/application_helper.rb +2 -0
- data/spec/rails/rails-5.1.2/app/jobs/application_job.rb +2 -0
- data/spec/rails/rails-5.1.2/app/mailers/application_mailer.rb +4 -0
- data/spec/rails/rails-5.1.2/app/mailers/post_mailer.rb +14 -0
- data/spec/rails/rails-5.1.2/app/mailers/user_mailer.rb +14 -0
- data/spec/rails/rails-5.1.2/app/models/application_record.rb +3 -0
- data/spec/rails/rails-5.1.2/app/models/post.rb +6 -0
- data/spec/rails/rails-5.1.2/app/models/register.rb +9 -0
- data/spec/rails/rails-5.1.2/app/models/user.rb +6 -0
- data/spec/rails/rails-5.1.2/app/notifiers/application_notifier.rb +2 -0
- data/spec/rails/rails-5.1.2/app/notifiers/post_notifier.rb +12 -0
- data/spec/rails/rails-5.1.2/app/notifiers/user_notifier.rb +12 -0
- data/spec/rails/rails-5.1.2/app/views/layouts/application.html.erb +14 -0
- data/spec/rails/rails-5.1.2/app/views/layouts/mailer.html.erb +13 -0
- data/spec/rails/rails-5.1.2/app/views/layouts/mailer.text.erb +1 -0
- data/spec/rails/rails-5.1.2/app/views/post_mailer/failure.html.erb +5 -0
- data/spec/rails/rails-5.1.2/app/views/post_mailer/failure.text.erb +3 -0
- data/spec/rails/rails-5.1.2/app/views/user_mailer/success.html.erb +5 -0
- data/spec/rails/rails-5.1.2/app/views/user_mailer/success.text.erb +3 -0
- data/spec/rails/rails-5.1.2/bin/bundle +3 -0
- data/spec/rails/rails-5.1.2/bin/rails +4 -0
- data/spec/rails/rails-5.1.2/bin/rake +4 -0
- data/spec/rails/rails-5.1.2/bin/setup +38 -0
- data/spec/rails/rails-5.1.2/bin/update +29 -0
- data/spec/rails/rails-5.1.2/bin/yarn +11 -0
- data/spec/rails/rails-5.1.2/config.ru +5 -0
- data/spec/rails/rails-5.1.2/config/application.rb +31 -0
- data/spec/rails/rails-5.1.2/config/boot.rb +3 -0
- data/spec/rails/rails-5.1.2/config/cable.yml +10 -0
- data/spec/rails/rails-5.1.2/config/database.yml +25 -0
- data/spec/rails/rails-5.1.2/config/environment.rb +8 -0
- data/spec/rails/rails-5.1.2/config/environments/development.rb +47 -0
- data/spec/rails/rails-5.1.2/config/environments/production.rb +83 -0
- data/spec/rails/rails-5.1.2/config/environments/test.rb +43 -0
- data/spec/rails/rails-5.1.2/config/initializers/application_controller_renderer.rb +6 -0
- data/spec/rails/rails-5.1.2/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails/rails-5.1.2/config/initializers/cookies_serializer.rb +5 -0
- data/spec/rails/rails-5.1.2/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/rails/rails-5.1.2/config/initializers/inflections.rb +16 -0
- data/spec/rails/rails-5.1.2/config/initializers/mime_types.rb +4 -0
- data/spec/rails/rails-5.1.2/config/initializers/pubsub_notifier.rb +10 -0
- data/spec/rails/rails-5.1.2/config/initializers/wrap_parameters.rb +14 -0
- data/spec/rails/rails-5.1.2/config/locales/en.yml +33 -0
- data/spec/rails/rails-5.1.2/config/puma.rb +56 -0
- data/spec/rails/rails-5.1.2/config/routes.rb +3 -0
- data/spec/rails/rails-5.1.2/config/secrets.yml +32 -0
- data/spec/rails/rails-5.1.2/db/migrate/20170714092754_create_users.rb +9 -0
- data/spec/rails/rails-5.1.2/db/migrate/20170714092755_create_posts.rb +9 -0
- data/spec/rails/rails-5.1.2/db/schema.rb +27 -0
- data/spec/rails/rails-5.1.2/db/seeds.rb +7 -0
- data/spec/rails/rails-5.1.2/db/test.sqlite3 +0 -0
- data/spec/rails/rails-5.1.2/log/test.log +917 -0
- data/spec/rails/rails-5.1.2/package.json +5 -0
- data/spec/rails/rails-5.1.2/public/404.html +67 -0
- data/spec/rails/rails-5.1.2/public/422.html +67 -0
- data/spec/rails/rails-5.1.2/public/500.html +66 -0
- data/spec/rails/rails-5.1.2/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/rails/rails-5.1.2/public/apple-touch-icon.png +0 -0
- data/spec/rails/rails-5.1.2/public/favicon.ico +0 -0
- data/spec/rails/rails-5.1.2/public/robots.txt +1 -0
- data/spec/spec_helper.rb +43 -7
- data/spec/support/rails_template.rb +57 -0
- metadata +413 -11
- data/spec/support/models/member.rb +0 -6
- data/spec/support/models/user.rb +0 -6
- data/spec/support/notifiers/admin_notifier.rb +0 -13
- data/spec/support/notifiers/user_notifier.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13e73599289fcded1fd12387534077d115c28d31
|
4
|
+
data.tar.gz: 4337c6889ec8b6529f3d17460094fee035e3e0f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 231a15d1f6b997f1810b7d33052c563a8d82abb8cfabfcc7e441c22ec7c3d2d2a8635ce4b0d0f8586b45d1860b57e3deccae3496ef606c508e172fc1b5cbb158
|
7
|
+
data.tar.gz: fd4dbf254a6540e1d7088e07a3d9d6e02cd3db1fbd2e344140cf777a9738f1aa1bee4a0bf6afcad0cc1e63ddeb23f64f197b3785bb8d7ec06d7a7fd468be8a89
|
data/Rakefile
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
-
require "rspec/core/rake_task"
|
3
2
|
|
4
|
-
|
3
|
+
desc "Creates a test rails app for the specs to run against"
|
4
|
+
task :setup do
|
5
|
+
require "rails/version"
|
6
|
+
system("mkdir spec/rails") unless File.exist?("spec/rails")
|
7
|
+
system "bundle exec rails new spec/rails/rails-#{Rails::VERSION::STRING} -m spec/support/rails_template.rb -T -B --skip-spring --skip-listen --skip-sprockets"
|
8
|
+
end
|
5
9
|
|
6
|
-
|
10
|
+
require "rspec/core/rake_task"
|
11
|
+
RSpec::Core::RakeTask.new(:spec)
|
12
|
+
task default: :spec
|
@@ -1,6 +1,7 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
2
|
class <%= class_name %>Notifier < ApplicationNotifier
|
3
|
-
use :
|
3
|
+
use :logger
|
4
|
+
# use :slack, channel: '#general', username: 'username', icon_emoji: ':grinning:'
|
4
5
|
|
5
6
|
def success(recipient)
|
6
7
|
notify_success("#{self.class}##{__method__} called with #{recipient.class}.")
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "integration test" do
|
4
|
+
describe "broadcasting" do
|
5
|
+
let(:user) { create(:user) }
|
6
|
+
|
7
|
+
it "broadcast to all subscribers" do
|
8
|
+
expect { user.broadcast(:success) }.not_to raise_error
|
9
|
+
end
|
10
|
+
|
11
|
+
it "broadcast to a part of subscribers" do
|
12
|
+
expect { user.broadcast(:failure) }.not_to raise_error
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "pubsub_notifier/acts_as_notifier"
|
3
|
+
|
4
|
+
RSpec.describe PubsubNotifier::ActsAsNotifier do
|
5
|
+
let(:dummy) do
|
6
|
+
Class.new do
|
7
|
+
include PubsubNotifier::ActsAsNotifier
|
8
|
+
acts_as_notifier
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def action_methods
|
12
|
+
%w[welcome]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
before do
|
19
|
+
allow_any_instance_of(ActionMailer::MessageDelivery).to receive(:deliver)
|
20
|
+
end
|
21
|
+
|
22
|
+
describe ".method_missing" do
|
23
|
+
subject { dummy.send(method_name) }
|
24
|
+
|
25
|
+
context "when method_name is included one of actions" do
|
26
|
+
let(:method_name) { :welcome }
|
27
|
+
it { is_expected.to be_a ActionMailer::MessageDelivery }
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when method_name is not included one of actions" do
|
31
|
+
let(:method_name) { :hello }
|
32
|
+
|
33
|
+
it "returns raise error" do
|
34
|
+
expect { subject }.to raise_error(NoMethodError)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe PubsubNotifier::Base do
|
4
|
+
let(:client) do
|
5
|
+
Class.new do
|
6
|
+
attr_reader :name, :options
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
@name = :client
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:logger) do
|
16
|
+
Class.new do
|
17
|
+
attr_reader :name, :options
|
18
|
+
|
19
|
+
def initialize(options = {})
|
20
|
+
@name = :logger
|
21
|
+
@options = options
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:name) { :dummy }
|
27
|
+
let(:options) { { superman: 12345 } }
|
28
|
+
|
29
|
+
before do
|
30
|
+
configuration = double(:configuration, clients: { name => client, :logger => logger })
|
31
|
+
allow(PubsubNotifier).to receive(:config).and_return(configuration)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "sets client" do
|
35
|
+
described_class.use(name, options)
|
36
|
+
expect(described_class.client).to be_a client
|
37
|
+
expect(described_class.client.name).to eq :client
|
38
|
+
expect(described_class.client.options).to eq options
|
39
|
+
|
40
|
+
described_class.use(:logger, options)
|
41
|
+
expect(described_class.client).to be_a logger
|
42
|
+
expect(described_class.client.name).to eq :logger
|
43
|
+
expect(described_class.client.options).to eq options
|
44
|
+
|
45
|
+
described_class.use(:undefined, options)
|
46
|
+
expect(described_class.client).to be_a logger
|
47
|
+
expect(described_class.client.name).to eq :logger
|
48
|
+
expect(described_class.client.options).to eq options
|
49
|
+
end
|
50
|
+
|
51
|
+
it "returns client" do
|
52
|
+
expect(described_class.client).not_to be_nil
|
53
|
+
expect(described_class.client).not_to be logger
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe PubsubNotifier::Broadcasters::ActiveJobBroadcaster do
|
4
|
+
let(:broadcaster) { described_class.new }
|
5
|
+
let(:configured_job) { double(:configured_job) }
|
6
|
+
|
7
|
+
let(:subscriber) do
|
8
|
+
Struct.new(:name) do
|
9
|
+
attr_reader :name
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
subject { broadcaster.broadcast(subscriber.new(name: :sub), nil, nil, nil) }
|
14
|
+
|
15
|
+
context "when global_id is not blank" do
|
16
|
+
before do
|
17
|
+
allow(broadcaster).to receive(:configured_job).and_return(configured_job)
|
18
|
+
allow(configured_job).to receive(:perform_later).and_return(:perform_later)
|
19
|
+
end
|
20
|
+
|
21
|
+
it { is_expected.to eq :perform_later }
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when global_id is blank" do
|
25
|
+
before do
|
26
|
+
allow(broadcaster).to receive(:configured_job).and_return(configured_job)
|
27
|
+
allow(configured_job).to receive(:perform_later).and_raise(::ActiveJob::SerializationError)
|
28
|
+
allow(configured_job).to receive(:perform_now).and_return(:perform_now)
|
29
|
+
end
|
30
|
+
|
31
|
+
it { is_expected.to eq :perform_now }
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe PubsubNotifier::Broadcasters::Base do
|
4
|
+
let(:broadcaster) { described_class.new }
|
5
|
+
|
6
|
+
describe "#configure" do
|
7
|
+
before { broadcaster.configure(x: 1, y: -> { 2 }) }
|
8
|
+
|
9
|
+
it "sets option with value" do
|
10
|
+
expect(broadcaster.options[:x]).to eq 1
|
11
|
+
end
|
12
|
+
|
13
|
+
it "sets option with proc" do
|
14
|
+
expect(broadcaster.options[:y]).to eq 2
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#broadcast" do
|
19
|
+
it { expect { broadcaster.broadcast(nil, nil, nil) }.to raise_error(NotImplementedError) }
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe PubsubNotifier::Client::Base do
|
4
|
+
let(:client) { described_class.new }
|
5
|
+
|
6
|
+
describe ".configure" do
|
7
|
+
it { expect { described_class.configure(&:object_id) }.to raise_error(NameError) }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".config" do
|
11
|
+
it { expect { described_class.config }.to raise_error(NameError) }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#notify_success" do
|
15
|
+
it { expect { client.notify_success("message") }.to raise_error(NotImplementedError) }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#notify_failure" do
|
19
|
+
it { expect { client.notify_failure("message") }.to raise_error(NotImplementedError) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
RSpec.describe PubsubNotifier::Client::LoggerClient do
|
24
|
+
let(:client) { described_class.new }
|
25
|
+
|
26
|
+
describe "#notify_success" do
|
27
|
+
it { expect { client.notify_success("message") }.not_to raise_error }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#notify_failure" do
|
31
|
+
it { expect { client.notify_failure("message") }.not_to raise_error }
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe PubsubNotifier::Proxy do
|
4
|
+
let(:model) do
|
5
|
+
Class.new do
|
6
|
+
include PubsubNotifier::Proxy
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:instance) { model.new }
|
11
|
+
|
12
|
+
describe ".subscribe" do
|
13
|
+
subject { model.subscribe(subscriber_name) }
|
14
|
+
|
15
|
+
context "when subscriber_name exists" do
|
16
|
+
let(:subscriber_name) { :Hash }
|
17
|
+
it { expect { subject }.not_to raise_error }
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when subscriber_name does not exists" do
|
21
|
+
let(:subscriber_name) { :Undefined }
|
22
|
+
it { expect { subject }.to raise_error(NameError) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe ".pubsub" do
|
27
|
+
subject { model.pubsub }
|
28
|
+
it { is_expected.to be_a PubsubNotifier::Pubsub }
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#broadcast" do
|
32
|
+
subject { instance.broadcast(event) }
|
33
|
+
|
34
|
+
context "when model has subscribed" do
|
35
|
+
before do
|
36
|
+
model.subscribe :Hash
|
37
|
+
model.subscribe :String
|
38
|
+
end
|
39
|
+
|
40
|
+
context "with calling exist event" do
|
41
|
+
let(:event) { :eql? }
|
42
|
+
it { expect { subject }.not_to raise_error }
|
43
|
+
end
|
44
|
+
|
45
|
+
context "with calling not exist event" do
|
46
|
+
let(:event) { :undefined_method_event }
|
47
|
+
it { expect { subject }.not_to raise_error }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when model has not subscribed" do
|
52
|
+
let(:event) { :object_id }
|
53
|
+
it { expect { subject }.not_to raise_error }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#publish" do
|
58
|
+
it { expect(instance).to be_respond_to(:publish) }
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe PubsubNotifier::Pubsub do
|
4
|
+
describe "#call" do
|
5
|
+
let(:pubsub) { described_class.new }
|
6
|
+
|
7
|
+
subject { pubsub.call(:event) }
|
8
|
+
|
9
|
+
it "calls broadcast" do
|
10
|
+
expect(pubsub).to receive(:broadcast).and_return(true)
|
11
|
+
is_expected.to be true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe PubsubNotifier::SlackClient do
|
4
|
+
let(:client) { described_class.new }
|
5
|
+
let(:message) { "message" }
|
6
|
+
let(:webhook_url) { "https://hooks.slack.com/services/_____/_____/______" }
|
7
|
+
|
8
|
+
before do
|
9
|
+
expect(client).to receive(:webhook_url).and_return(webhook_url)
|
10
|
+
expect(Net::HTTP).to receive(:post_form).and_return(true)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#notify_success" do
|
14
|
+
subject { client.notify_success(message) }
|
15
|
+
it { is_expected.to be true }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#notify_failure" do
|
19
|
+
subject { client.notify_failure(message) }
|
20
|
+
it { is_expected.to be true }
|
21
|
+
end
|
22
|
+
end
|
@@ -1,32 +1,50 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
RSpec.describe PubsubNotifier do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
describe ".configure" do
|
5
|
+
subject { described_class.configure(&:logger) }
|
6
|
+
it { is_expected.to be_a Logger }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ".config" do
|
10
|
+
subject { described_class.config }
|
11
|
+
it { is_expected.to be_an_instance_of described_class::Config }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe ".register_client" do
|
15
|
+
let(:name) { :client }
|
16
|
+
let(:klass) { Object }
|
17
|
+
|
18
|
+
before do
|
19
|
+
described_class.register_client(name, klass)
|
20
|
+
end
|
21
|
+
|
22
|
+
after do
|
23
|
+
described_class.config.clients.delete(name)
|
12
24
|
end
|
13
25
|
|
14
|
-
it "
|
15
|
-
|
16
|
-
member.broadcast(:success)
|
17
|
-
member.broadcast(:failure)
|
26
|
+
it "registers notification client" do
|
27
|
+
expect(described_class.config.clients.has_key?(name)).to be true
|
18
28
|
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe ".register_broadcaster" do
|
32
|
+
let(:name) { :client }
|
33
|
+
let(:klass) { Object }
|
19
34
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
35
|
+
subject { described_class.register_broadcaster(name, klass) }
|
36
|
+
|
37
|
+
before do
|
38
|
+
config = double("configuration", broadcaster: true)
|
39
|
+
allow(Wisper).to receive(:configuration).and_return(config)
|
24
40
|
end
|
25
41
|
|
26
|
-
it "
|
27
|
-
|
28
|
-
expect_any_instance_of(AdminNotifier).not_to receive(:only_user).once
|
29
|
-
member.broadcast(:only_user)
|
42
|
+
it "register broadcaster" do
|
43
|
+
is_expected.to be true
|
30
44
|
end
|
31
45
|
end
|
46
|
+
|
47
|
+
describe ".init!" do
|
48
|
+
it { expect { described_class.init! }.not_to raise_error }
|
49
|
+
end
|
32
50
|
end
|