solidus_webhooks 0.0.1.v0.1.0.beta.1.1 → 0.4.0

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: ee15a8db0ac265823a8f226cabbd4a28881cf04191e27073abf252b4f554097a
4
- data.tar.gz: b3888c9cfd6afa9bb6a513223274f60665013541e2c5a8e5d49970320cb0b258
3
+ metadata.gz: f94eb7d8c956dd983b90ff8ab0d14fde3fbad148400e29222c8be84d403c1baa
4
+ data.tar.gz: fd828061690984b542190754621d8d9b86ba34ae89070f25db9f838a0de22c78
5
5
  SHA512:
6
- metadata.gz: bd1a0767f65439df1ff2273b36c1df0f04c492ccfd31ec04d676f9492eed61bfe2296890bec228fd3d28ad55b53f8032205bfbc07bb40cf966d3fc5031ccd37b
7
- data.tar.gz: a47daaba62f5c9480c2330fd21c261844d35b55d63ff9d057e42fec129a002aee7d842e5e2c8a55eb214b827c2c30dc6c8fa7527c6942d70b74973ee626b2f30
6
+ metadata.gz: 37142b4bd06257070f31083a3a99a8594654c626e52e21d41b95f075c4f3a3adc2064cd9831f2c36de5500fa91805d763e5913ea07b9b7c184ac11f6bb6755a8
7
+ data.tar.gz: f4cb38e4f31a7e7e1c60603c79ccc96b35365b5309b35cd959ff29175f7368ca1f95cd16be32ebdd00a8eeeb92cde2c8d1f00287f2f3e6bab42d0a65987e482a
data/.circleci/config.yml CHANGED
@@ -16,12 +16,18 @@ jobs:
16
16
  executor: solidusio_extensions/mysql
17
17
  steps:
18
18
  - solidusio_extensions/run-tests
19
+ lint-code:
20
+ executor: solidusio_extensions/sqlite-memory
21
+ steps:
22
+ - solidusio_extensions/lint-code
19
23
 
20
24
  workflows:
21
25
  "Run specs on supported Solidus versions":
22
26
  jobs:
23
27
  - run-specs-with-postgres
24
28
  - run-specs-with-mysql
29
+ - lint-code
30
+
25
31
  "Weekly run specs against master":
26
32
  triggers:
27
33
  - schedule:
data/.gem_release.yml CHANGED
@@ -2,4 +2,4 @@ bump:
2
2
  recurse: false
3
3
  file: 'lib/solidus_webhooks/version.rb'
4
4
  message: Bump SolidusWebhooks to %{version}
5
- tag: true
5
+ tag: false
data/.github/stale.yml CHANGED
@@ -1,17 +1,17 @@
1
1
  # Number of days of inactivity before an issue becomes stale
2
2
  daysUntilStale: 60
3
3
  # Number of days of inactivity before a stale issue is closed
4
- daysUntilClose: 7
4
+ daysUntilClose: false
5
5
  # Issues with these labels will never be considered stale
6
6
  exemptLabels:
7
7
  - pinned
8
8
  - security
9
9
  # Label to use when marking an issue as stale
10
- staleLabel: wontfix
10
+ staleLabel: stale
11
11
  # Comment to post when marking an issue as stale. Set to `false` to disable
12
12
  markComment: >
13
13
  This issue has been automatically marked as stale because it has not had
14
- recent activity. It will be closed if no further activity occurs. Thank you
14
+ recent activity. It might be closed if no further activity occurs. Thank you
15
15
  for your contributions.
16
16
  # Comment to post when closing a stale issue. Set to `false` to disable
17
- closeComment: false
17
+ closeComment: false
@@ -0,0 +1,2 @@
1
+ issues=false
2
+ exclude-labels=infrastructure
data/.gitignore CHANGED
@@ -15,3 +15,6 @@ pkg
15
15
  spec/dummy
16
16
  spec/examples.txt
17
17
  /sandbox
18
+ .rvmrc
19
+ .ruby-version
20
+ .ruby-gemset
data/.rubocop.yml CHANGED
@@ -2,6 +2,27 @@ require:
2
2
  - solidus_dev_support/rubocop
3
3
 
4
4
  AllCops:
5
+ NewCops: disable
5
6
  Exclude:
6
7
  - sandbox/**/*
7
8
  - spec/dummy/**/*
9
+ - vendor/bundle/**/*
10
+
11
+
12
+ # This guys are troublemakers
13
+ RSpec/FactoryBot/CreateList:
14
+ Enabled: false
15
+ RSpec/Rails/HttpStatus:
16
+ Enabled: false
17
+
18
+ # Deviations from the standard
19
+ Style/ClassAndModuleChildren:
20
+ Enabled: false
21
+ Style/FrozenStringLiteralComment:
22
+ Enabled: false
23
+ RSpec/Capybara/FeatureMethods:
24
+ Enabled: false
25
+ RSpec/MultipleExpectations:
26
+ Enabled: false
27
+ RSpec/NamedSubject:
28
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,52 @@
1
+ # Changelog
2
+
3
+ ## [v0.3.0](https://github.com/solidusio-contrib/solidus_webhooks/tree/v0.3.0) (2021-04-20)
4
+
5
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_webhooks/compare/v0.3.0...v0.3.0)
6
+
7
+ **Closed issues:**
8
+
9
+ - Prepare Solidus Webhooks for Solidus 3.0 [\#8](https://github.com/solidusio-contrib/solidus_webhooks/issues/8)
10
+
11
+ **Merged pull requests:**
12
+
13
+ - Allow Solidus 3 [\#10](https://github.com/solidusio-contrib/solidus_webhooks/pull/10) ([kennyadsl](https://github.com/kennyadsl))
14
+ - Reconcile master and v0.3.0 [\#7](https://github.com/solidusio-contrib/solidus_webhooks/pull/7) ([elia](https://github.com/elia))
15
+ - Bump solidus\_support to ~\> 0.6 [\#6](https://github.com/solidusio-contrib/solidus_webhooks/pull/6) ([peterberkenbosch](https://github.com/peterberkenbosch))
16
+
17
+ ## [v0.3.0](https://github.com/solidusio-contrib/solidus_webhooks/tree/v0.3.0) (2020-10-20)
18
+
19
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_webhooks/compare/v0.2.0...v0.3.0)
20
+
21
+ **Fixed bugs:**
22
+
23
+ - Fix error classes [\#5](https://github.com/solidusio-contrib/solidus_webhooks/pull/5) ([elia](https://github.com/elia))
24
+
25
+ ## [v0.2.0](https://github.com/solidusio-contrib/solidus_webhooks/tree/v0.2.0) (2020-06-10)
26
+
27
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_webhooks/compare/v0.1.0...v0.2.0)
28
+
29
+ **Implemented enhancements:**
30
+
31
+ - Expose current\_api\_user to webhook handlers [\#4](https://github.com/solidusio-contrib/solidus_webhooks/pull/4) ([elia](https://github.com/elia))
32
+
33
+ ## [v0.1.0](https://github.com/solidusio-contrib/solidus_webhooks/tree/v0.1.0) (2020-05-14)
34
+
35
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_webhooks/compare/v0.1.0.beta.1...v0.1.0)
36
+
37
+ ## [v0.1.0.beta.1](https://github.com/solidusio-contrib/solidus_webhooks/tree/v0.1.0.beta.1) (2020-05-13)
38
+
39
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_webhooks/compare/v0.0.1.v0.1.0.beta.1.1...v0.1.0.beta.1)
40
+
41
+ ## [v0.0.1.v0.1.0.beta.1.1](https://github.com/solidusio-contrib/solidus_webhooks/tree/v0.0.1.v0.1.0.beta.1.1) (2020-05-13)
42
+
43
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_webhooks/compare/9573caa400232ffb44cde7f8cf907171a529ced3...v0.0.1.v0.1.0.beta.1.1)
44
+
45
+ **Merged pull requests:**
46
+
47
+ - Prepare the repo to be moved to @solidusio-contrib [\#2](https://github.com/solidusio-contrib/solidus_webhooks/pull/2) ([elia](https://github.com/elia))
48
+ - Add the ability to register and receive webhooks [\#1](https://github.com/solidusio-contrib/solidus_webhooks/pull/1) ([elia](https://github.com/elia))
49
+
50
+
51
+
52
+ \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
data/README.md CHANGED
@@ -1,10 +1,27 @@
1
- SolidusWebhooks
2
- ===============
1
+ # Solidus Webhooks
3
2
 
4
- Provides comprehensive Webhook support for Solidus, with a simple and powerful way to register them and route payloads to appropriate actions, either synchronous or delayed.
3
+ [![CircleCI](https://circleci.com/gh/solidusio-contrib/solidus_webhooks.svg?style=shield)](https://circleci.com/gh/solidusio-contrib/solidus_webhooks)
4
+ [![codecov](https://codecov.io/gh/solidusio-contrib/solidus_webhooks/branch/master/graph/badge.svg)](https://codecov.io/gh/solidusio-contrib/solidus_webhooks)
5
5
 
6
- Usage
7
- -----
6
+ <!-- Explain what your extension does. -->
7
+
8
+ ## Installation
9
+
10
+ Add solidus_webhooks to your Gemfile:
11
+
12
+ ```ruby
13
+ gem 'solidus_webhooks'
14
+ ```
15
+
16
+ Bundle your dependencies and run the installation generator:
17
+
18
+ ```shell
19
+ bin/rails generate solidus_webhooks:install
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ <!-- Explain how to use your extension once it's been installed. -->
8
25
 
9
26
  A Webhook receiver is just a callable and can be registered in the Solidus configuration as follows:
10
27
 
@@ -33,8 +50,8 @@ The only requirement on handlers is for them to respond to `#call` and accept a
33
50
  Example:
34
51
 
35
52
  ```ruby
36
- class TrackingNumberHandler
37
- def call(payload)
53
+ module TrackingNumberHandler
54
+ def self.call(payload)
38
55
  order = Spree::Order.find_by!(number: payload[:order])
39
56
  shipment = order.shipments.find_by!(number: payload[:shipment])
40
57
  shipment.update!(tracking: payload[:tracking])
@@ -108,29 +125,28 @@ Spree::RoleConfiguration.configure do |config|
108
125
  end
109
126
  ```
110
127
 
111
- Installation
112
- ------------
128
+ ### Accessing the API User
113
129
 
114
- Add solidus_webhooks to your Gemfile:
130
+ If you need to access the API user that is making the call to the webhook, you can just accept an additional argument in the callable handler.
131
+
132
+ Example:
115
133
 
116
134
  ```ruby
117
- gem 'solidus_webhooks'
135
+ SolidusWebhooks.config.register_webhook_handler :tracking_number, -> payload, user {
136
+ Rails.logger.info "Received payload from user #{user.email}: #{payload.to_json}"
137
+ # …
138
+ }
118
139
  ```
119
140
 
120
- Bundle your dependencies and run the installation generator:
121
-
122
- ```shell
123
- bundle
124
- bundle exec rails g solidus_webhooks:install
125
- ```
141
+ ## Development
126
142
 
127
- Testing
128
- -------
143
+ ### Testing the extension
129
144
 
130
- First bundle your dependencies, then run `bin/rake`. `bin/rake` will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using `bin/rake extension:test_app`.
145
+ First bundle your dependencies, then run `bin/rake`. `bin/rake` will default to building the dummy
146
+ app if it does not exist, then it will run specs. The dummy app can be regenerated by using
147
+ `bin/rake extension:test_app`.
131
148
 
132
149
  ```shell
133
- bundle
134
150
  bin/rake
135
151
  ```
136
152
 
@@ -147,16 +163,15 @@ Simply add this require statement to your spec_helper:
147
163
  require 'solidus_webhooks/factories'
148
164
  ```
149
165
 
150
- Sandbox app
151
- -----------
166
+ ### Running the sandbox
152
167
 
153
- To run this extension in a sandboxed Solidus application you can run `bin/sandbox`
154
- The path for the sandbox app is `./sandbox` and `bin/rails` will forward any Rails command
155
- to `sandbox/bin/rails`.
168
+ To run this extension in a sandboxed Solidus application, you can run `bin/sandbox`. The path for
169
+ the sandbox app is `./sandbox` and `bin/rails` will forward any Rails commands to
170
+ `sandbox/bin/rails`.
156
171
 
157
- Example:
172
+ Here's an example:
158
173
 
159
- ```shell
174
+ ```
160
175
  $ bin/rails server
161
176
  => Booting Puma
162
177
  => Rails 6.0.2.1 application starting in development
@@ -164,13 +179,21 @@ $ bin/rails server
164
179
  Use Ctrl-C to stop
165
180
  ```
166
181
 
167
- Releasing
168
- ---------
182
+ ### Updating the changelog
169
183
 
170
- Your new extension version can be released using `gem-release` like this:
184
+ Before and after releases the changelog should be updated to reflect the up-to-date status of
185
+ the project:
171
186
 
172
187
  ```shell
173
- bundle exec gem bump -v VERSION --tag --push --remote upstream && gem release
188
+ bin/rake changelog
189
+ git add CHANGELOG.md
190
+ git commit -m "Update the changelog"
174
191
  ```
175
192
 
176
- Copyright (c) 2020 Nebulab srls, released under the New BSD License
193
+ ### Releasing new versions
194
+
195
+ Please refer to the dedicated [page](https://github.com/solidusio/solidus/wiki/How-to-release-extensions) on Solidus wiki.
196
+
197
+ ## License
198
+
199
+ Copyright (c) 2020 Nebulab srls, released under the New BSD License.
data/Rakefile CHANGED
@@ -1,6 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'solidus_dev_support/rake_tasks'
4
+
5
+ SolidusDevSupport::RakeTasks.class_eval do
6
+ def install_changelog_task
7
+ require 'github_changelog_generator/task'
8
+
9
+ source_code_uri = URI.parse(gemspec.metadata['source_code_uri'])
10
+ user, project = source_code_uri.path.split("/", 3)[1..2]
11
+
12
+ GitHubChangelogGenerator::RakeTask.new(:changelog) do |config|
13
+ config.user = user || 'solidus-contrib'
14
+ config.project = project || gemspec.name
15
+ config.future_release = "v#{gemspec.version}"
16
+ end
17
+ end
18
+ end
19
+
4
20
  SolidusDevSupport::RakeTasks.install
5
21
 
6
22
  task default: 'extension:specs'
@@ -1,13 +1,14 @@
1
1
  class Spree::WebhooksController < Spree::Api::BaseController
2
- rescue_from(Spree::Webhook::WebhookNotFound) { head :not_found }
2
+ rescue_from(SolidusWebhooks::WebhookNotFound) { head :not_found }
3
3
 
4
4
  def receive
5
5
  webhook = Spree::Webhook.find(params[:id])
6
6
  payload = request.request_parameters["webhook"]
7
+ user = current_api_user
7
8
 
8
9
  authorize! :receive, webhook
9
10
 
10
- webhook.receive(payload)
11
+ webhook.receive(payload, user)
11
12
 
12
13
  head :ok
13
14
  end
@@ -1,19 +1,33 @@
1
+ require 'solidus_webhooks/errors'
2
+
1
3
  class Spree::Webhook
2
4
  include ActiveModel::Model
3
5
  attr_accessor :handler, :id
4
6
 
5
- WebhookNotFound = Class.new(StandardError)
6
-
7
- def receive(payload)
8
- handler.call(payload)
7
+ def receive(payload, user)
8
+ if handler_arity == 1
9
+ handler.call(payload)
10
+ else
11
+ handler.call(payload, user)
12
+ end
9
13
  end
10
14
 
11
15
  def self.find(id)
12
16
  id = id.to_sym # normalize incoming ids
13
17
 
14
18
  handler = SolidusWebhooks.config.find_webhook_handler(id) or
15
- raise WebhookNotFound, "Cannot find a webhook handler for #{id.inspect}"
19
+ raise SolidusWebhooks::WebhookNotFound, "Cannot find a webhook handler for #{id.inspect}"
16
20
 
17
21
  new(id: id, handler: handler)
18
22
  end
23
+
24
+ private
25
+
26
+ def handler_arity
27
+ if handler.respond_to?(:arity)
28
+ handler.arity
29
+ else
30
+ handler.method(:call).arity
31
+ end
32
+ end
19
33
  end
data/bin/rails ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if %w[g generate].include? ARGV.first
4
+ exec "#{__dir__}/rails-engine", *ARGV
5
+ else
6
+ exec "#{__dir__}/rails-sandbox", *ARGV
7
+ end
File without changes
@@ -1,13 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # frozen_string_literal: true
4
-
5
3
  app_root = 'sandbox'
6
4
 
7
5
  unless File.exist? "#{app_root}/bin/rails"
8
6
  warn 'Creating the sandbox app...'
9
7
  Dir.chdir "#{__dir__}/.." do
10
- system "#{__dir__}/sandbox" or begin # rubocop:disable Style/AndOr
8
+ system "#{__dir__}/sandbox" or begin
11
9
  warn 'Automatic creation of the sandbox app failed'
12
10
  exit 1
13
11
  end
data/bin/sandbox CHANGED
@@ -72,9 +72,11 @@ unbundled bundle exec rails generate spree:install \
72
72
  --user_class=Spree::User \
73
73
  --enforce_available_locales=true \
74
74
  --with-authentication=false \
75
+ --payment-method=none \
75
76
  $@
76
77
 
77
78
  unbundled bundle exec rails generate solidus:auth:install
79
+ unbundled bundle exec rails generate ${extension_name}:install
78
80
 
79
81
  echo
80
82
  echo "🚀 Sandbox app successfully created for $extension_name!"
@@ -4,15 +4,20 @@ module SolidusWebhooks
4
4
  module Generators
5
5
  class InstallGenerator < Rails::Generators::Base
6
6
  class_option :auto_run_migrations, type: :boolean, default: false
7
+ source_root File.expand_path('templates', __dir__)
8
+
9
+ def copy_initializer
10
+ template 'initializer.rb', 'config/initializers/solidus_webhooks.rb'
11
+ end
7
12
 
8
13
  def add_javascripts
9
- append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_webhooks\n" # rubocop:disable Metrics/LineLength
10
- append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_webhooks\n" # rubocop:disable Metrics/LineLength
14
+ append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_webhooks\n"
15
+ append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_webhooks\n"
11
16
  end
12
17
 
13
18
  def add_stylesheets
14
- inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_webhooks\n", before: %r{\*/}, verbose: true # rubocop:disable Metrics/LineLength
15
- inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_webhooks\n", before: %r{\*/}, verbose: true # rubocop:disable Metrics/LineLength
19
+ inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_webhooks\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
20
+ inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_webhooks\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
16
21
  end
17
22
 
18
23
  def add_migrations
@@ -20,7 +25,7 @@ module SolidusWebhooks
20
25
  end
21
26
 
22
27
  def run_migrations
23
- run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Metrics/LineLength
28
+ run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Layout/LineLength
24
29
  if run_migrations
25
30
  run 'bin/rails db:migrate'
26
31
  else
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ SolidusWebhooks.configure do |config|
4
+ # TODO: Remember to change this with the actual preferences you have implemented!
5
+ # config.sample_preference = 'sample_value'
6
+ end
@@ -3,6 +3,6 @@
3
3
  require 'solidus_core'
4
4
  require 'solidus_support'
5
5
 
6
- require 'solidus_webhooks/version'
7
6
  require 'solidus_webhooks/configuration'
7
+ require 'solidus_webhooks/version'
8
8
  require 'solidus_webhooks/engine'
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'solidus_webhooks/errors'
4
+
1
5
  module SolidusWebhooks
2
6
  class Configuration
3
7
  def initialize
@@ -6,7 +10,7 @@ module SolidusWebhooks
6
10
 
7
11
  def register_webhook_handler(id, handler)
8
12
  unless handler.respond_to? :call
9
- raise Spree::Webhook::InvalidHandler,
13
+ raise SolidusWebhooks::InvalidHandler,
10
14
  "Please provide a handler that responds to #call, got: #{handler.inspect}"
11
15
  end
12
16
 
@@ -18,13 +22,19 @@ module SolidusWebhooks
18
22
  end
19
23
  end
20
24
 
21
- def self.config
22
- @config
23
- end
25
+ class << self
26
+ def configuration
27
+ @configuration ||= Configuration.new
28
+ end
24
29
 
25
- def self.reset_config!
26
- @config = Configuration.new
27
- end
30
+ alias config configuration
28
31
 
29
- reset_config! # initialize the extension
32
+ def reset_config!
33
+ @configuration = nil
34
+ end
35
+
36
+ def configure
37
+ yield configuration
38
+ end
39
+ end
30
40
  end
@@ -0,0 +1,4 @@
1
+ module SolidusWebhooks
2
+ WebhookNotFound = Class.new(StandardError)
3
+ InvalidHandler = Class.new(StandardError)
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusWebhooks
4
- VERSION = '0.0.1.v0.1.0.beta.1.1'
4
+ VERSION = '0.4.0'
5
5
  end
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.metadata['source_code_uri'] = 'https://github.com/solidusio-contrib/solidus_webhooks'
17
17
  spec.metadata['changelog_uri'] = 'https://github.com/solidusio-contrib/solidus_webhooks/releases'
18
18
 
19
- spec.required_ruby_version = Gem::Requirement.new('~> 2.4')
19
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5')
20
20
 
21
21
  # Specify which files should be added to the gem when it is released.
22
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -28,8 +28,8 @@ Gem::Specification.new do |spec|
28
28
  spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ["lib"]
30
30
 
31
- spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 3']
32
- spec.add_dependency 'solidus_support', '~> 0.5.0'
31
+ spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 4']
32
+ spec.add_dependency 'solidus_support', '~> 0.6'
33
33
 
34
- spec.add_development_dependency 'solidus_dev_support'
34
+ spec.add_development_dependency 'solidus_dev_support', '~> 2.2'
35
35
  end
@@ -2,46 +2,73 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.feature "Can register a handler and receive Webhooks", type: :request do
4
4
  background do
5
- SolidusWebhooks.reset_config!
6
- SolidusWebhooks.config.register_webhook_handler :foo, foo_handler
7
- SolidusWebhooks.config.register_webhook_handler :bar, bar_handler
5
+ SolidusWebhooks.config.register_webhook_handler :proc, proc_handler
6
+ SolidusWebhooks.config.register_webhook_handler :method, method_handler
7
+ SolidusWebhooks.config.register_webhook_handler :user, user_handler
8
+ SolidusWebhooks.config.register_webhook_handler :splat, splat_handler
9
+ SolidusWebhooks.config.register_webhook_handler :method_and_user, method_and_user_handler
8
10
  end
9
11
 
10
- let(:foo_payloads) { [] }
11
- let(:bar_payloads) { [] }
12
+ let(:proc_payloads) { [] }
13
+ let(:method_payloads) { [] }
14
+ let(:user_payloads) { [] }
15
+ let(:splat_payloads) { [] }
16
+ let(:method_and_user_payloads) { [] }
12
17
 
13
- let(:foo_handler) { ->(payload) { foo_payloads << payload } }
14
- let(:bar_handler) { ->(payload) { bar_payloads << payload } }
18
+ let(:proc_handler) { ->(payload) { proc_payloads << payload } }
19
+ let(:method_handler) {
20
+ Struct.new(:payloads) { def call(payload) payloads << payload end }.new(method_payloads)
21
+ }
22
+ let(:user_handler) { ->(payload, user) { user_payloads << [payload, user] } }
23
+ let(:splat_handler) { ->(*args) { splat_payloads << args } }
24
+ let(:method_and_user_handler) {
25
+ Struct.new(:payloads) { def call(payload, user) payloads << [payload, user] end }.new(method_and_user_payloads)
26
+ }
15
27
 
16
- let(:token) { create(:admin_user, spree_api_key: "123").spree_api_key }
17
- let(:token_without_permission) { create(:user, spree_api_key: "456").spree_api_key }
28
+ let(:authorized_user) { create(:admin_user, spree_api_key: "123") }
29
+ let(:authorized_token) { authorized_user.spree_api_key }
30
+
31
+ let(:unauthorized_user) { create(:user, spree_api_key: "456") }
32
+ let(:unauthorized_token) { unauthorized_user.spree_api_key }
18
33
 
19
34
  scenario "calls the handler passing the payload" do
20
- post "/webhooks/foo?token=#{token}", as: :json, params: {a: 123}
35
+ post "/webhooks/proc?token=#{authorized_token}", as: :json, params: { a: 123 }
36
+ expect(response).to have_http_status(:ok)
37
+
38
+ post "/webhooks/proc?token=#{authorized_token}", as: :json, params: { b: 456 }
39
+ expect(response).to have_http_status(:ok)
40
+
41
+ post "/webhooks/method?token=#{authorized_token}", as: :json, params: { c: 789 }
42
+ expect(response).to have_http_status(:ok)
43
+
44
+ post "/webhooks/user?token=#{authorized_token}", as: :json, params: { d: 12 }
21
45
  expect(response).to have_http_status(:ok)
22
46
 
23
- post "/webhooks/foo?token=#{token}", as: :json, params: {b: 456}
47
+ post "/webhooks/splat?token=#{authorized_token}", as: :json, params: { e: 345 }
24
48
  expect(response).to have_http_status(:ok)
25
49
 
26
- post "/webhooks/bar?token=#{token}", as: :json, params: {c: 789}
50
+ post "/webhooks/method_and_user?token=#{authorized_token}", as: :json, params: { f: 678 }
27
51
  expect(response).to have_http_status(:ok)
28
52
 
29
- expect(foo_payloads).to eq([{'a' => 123}, {'b' => 456}])
30
- expect(bar_payloads).to eq([{'c' => 789}])
53
+ expect(proc_payloads).to eq([{ 'a' => 123 }, { 'b' => 456 }])
54
+ expect(method_payloads).to eq([{ 'c' => 789 }])
55
+ expect(user_payloads).to eq([[{ 'd' => 12 }, authorized_user]])
56
+ expect(splat_payloads).to eq([[{ 'e' => 345 }, authorized_user]])
57
+ expect(method_and_user_payloads).to eq([[{ 'f' => 678 }, authorized_user]])
31
58
  end
32
59
 
33
60
  scenario "receives a bad handler id" do
34
- post "/webhooks/baz?token=#{token}", as: :json, params: {a: 123}
61
+ post "/webhooks/abc?token=#{authorized_token}", as: :json, params: { a: 123 }
35
62
  expect(response).to have_http_status(:not_found)
36
63
  end
37
64
 
38
65
  scenario "refuses a bad token" do
39
- post "/webhooks/baz?token=b4d-t0k3n", as: :json, params: {a: 123}
66
+ post "/webhooks/user?token=b4d-t0k3n", as: :json, params: { a: 123 }
40
67
  expect(response).to have_http_status(:unauthorized)
41
68
  end
42
69
 
43
70
  scenario "refuses a token without permissions" do
44
- post "/webhooks/foo?token=#{token_without_permission}", as: :json, params: {a: 123}
71
+ post "/webhooks/proc?token=#{unauthorized_token}", as: :json, params: { a: 123 }
45
72
  expect(response).to have_http_status(:unauthorized)
46
73
  end
47
74
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Spree::Webhook do
4
+ describe '.find' do
5
+ before { SolidusWebhooks.config.register_webhook_handler :foo, ->(payload) {} }
6
+
7
+ it 'can find a registered handler' do
8
+ expect(described_class.find(:foo)).to be_a(described_class)
9
+ expect{ described_class.find(:bar) }.to raise_error(SolidusWebhooks::WebhookNotFound)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe SolidusWebhooks::Configuration do
4
+ describe '#register_webhook_handler' do
5
+ it 'only accepts callable' do
6
+ expect{ subject.register_webhook_handler(:foo, Object.new) }.to raise_error(SolidusWebhooks::InvalidHandler)
7
+ expect{ subject.register_webhook_handler(:bar, proc {}) }.not_to raise_error
8
+ end
9
+ end
10
+ end
data/spec/spec_helper.rb CHANGED
@@ -6,19 +6,26 @@ ENV['RAILS_ENV'] = 'test'
6
6
  # Run Coverage report
7
7
  require 'solidus_dev_support/rspec/coverage'
8
8
 
9
- require File.expand_path('dummy/config/environment.rb', __dir__)
9
+ # Create the dummy app if it's still missing.
10
+ dummy_env = "#{__dir__}/dummy/config/environment.rb"
11
+ system 'bin/rake extension:test_app' unless File.exist? dummy_env
12
+ require dummy_env
10
13
 
11
14
  # Requires factories and other useful helpers defined in spree_core.
12
15
  require 'solidus_dev_support/rspec/feature_helper'
13
16
 
14
17
  # Requires supporting ruby files with custom matchers and macros, etc,
15
18
  # in spec/support/ and its subdirectories.
16
- Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
19
+ Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f }
17
20
 
18
- # Requires factories defined in lib/solidus_webhooks/factories.rb
19
- require 'solidus_webhooks/factories'
21
+ # Requires factories defined in lib/solidus_webhooks/testing_support/factories.rb
22
+ require 'solidus_webhooks/testing_support/factories'
20
23
 
21
24
  RSpec.configure do |config|
22
25
  config.infer_spec_type_from_file_location!
23
26
  config.use_transactional_fixtures = false
27
+
28
+ if Spree.solidus_gem_version < Gem::Version.new('2.11')
29
+ config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :system
30
+ end
24
31
  end
@@ -0,0 +1,3 @@
1
+ RSpec.configure do |config|
2
+ config.before { SolidusWebhooks.reset_config! }
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_webhooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.v0.1.0.beta.1.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elia Schito
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-13 00:00:00.000000000 Z
11
+ date: 2021-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 2.0.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '3'
22
+ version: '4'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,36 +29,36 @@ dependencies:
29
29
  version: 2.0.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '3'
32
+ version: '4'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: solidus_support
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 0.5.0
39
+ version: '0.6'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: 0.5.0
46
+ version: '0.6'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: solidus_dev_support
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - ">="
51
+ - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '0'
53
+ version: '2.2'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - ">="
58
+ - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '0'
61
- description:
60
+ version: '2.2'
61
+ description:
62
62
  email: contact@solidus.io
63
63
  executables: []
64
64
  extensions: []
@@ -67,9 +67,11 @@ files:
67
67
  - ".circleci/config.yml"
68
68
  - ".gem_release.yml"
69
69
  - ".github/stale.yml"
70
+ - ".github_changelog_generator"
70
71
  - ".gitignore"
71
72
  - ".rspec"
72
73
  - ".rubocop.yml"
74
+ - CHANGELOG.md
73
75
  - Gemfile
74
76
  - LICENSE
75
77
  - README.md
@@ -81,22 +83,29 @@ files:
81
83
  - app/controllers/spree/webhooks_controller.rb
82
84
  - app/models/spree/webhook.rb
83
85
  - bin/console
84
- - bin/r
86
+ - bin/rails
87
+ - bin/rails-engine
88
+ - bin/rails-sandbox
85
89
  - bin/rake
86
90
  - bin/sandbox
87
- - bin/sandbox_rails
88
91
  - bin/setup
89
92
  - config/locales/en.yml
90
93
  - config/routes.rb
91
94
  - lib/generators/solidus_webhooks/install/install_generator.rb
95
+ - lib/generators/solidus_webhooks/install/templates/initializer.rb
92
96
  - lib/solidus_webhooks.rb
93
97
  - lib/solidus_webhooks/configuration.rb
94
98
  - lib/solidus_webhooks/engine.rb
99
+ - lib/solidus_webhooks/errors.rb
95
100
  - lib/solidus_webhooks/factories.rb
101
+ - lib/solidus_webhooks/testing_support/factories.rb
96
102
  - lib/solidus_webhooks/version.rb
97
103
  - solidus_webhooks.gemspec
98
104
  - spec/features/can_register_a_handler_and_receive_webhooks_spec.rb
105
+ - spec/models/spree/webhook_spec.rb
106
+ - spec/solidus_webhooks/configuration_spec.rb
99
107
  - spec/spec_helper.rb
108
+ - spec/support/reset_config.rb
100
109
  homepage: https://github.com/solidusio-contrib/solidus_webhooks#readme
101
110
  licenses:
102
111
  - BSD-3-Clause
@@ -104,25 +113,28 @@ metadata:
104
113
  homepage_uri: https://github.com/solidusio-contrib/solidus_webhooks#readme
105
114
  source_code_uri: https://github.com/solidusio-contrib/solidus_webhooks
106
115
  changelog_uri: https://github.com/solidusio-contrib/solidus_webhooks/releases
107
- post_install_message:
116
+ post_install_message:
108
117
  rdoc_options: []
109
118
  require_paths:
110
119
  - lib
111
120
  required_ruby_version: !ruby/object:Gem::Requirement
112
121
  requirements:
113
- - - "~>"
122
+ - - ">="
114
123
  - !ruby/object:Gem::Version
115
- version: '2.4'
124
+ version: '2.5'
116
125
  required_rubygems_version: !ruby/object:Gem::Requirement
117
126
  requirements:
118
- - - ">"
127
+ - - ">="
119
128
  - !ruby/object:Gem::Version
120
- version: 1.3.1
129
+ version: '0'
121
130
  requirements: []
122
- rubygems_version: 3.1.2
123
- signing_key:
131
+ rubygems_version: 3.1.4
132
+ signing_key:
124
133
  specification_version: 4
125
134
  summary: Webhooks support for Solidus
126
135
  test_files:
127
136
  - spec/features/can_register_a_handler_and_receive_webhooks_spec.rb
137
+ - spec/models/spree/webhook_spec.rb
138
+ - spec/solidus_webhooks/configuration_spec.rb
128
139
  - spec/spec_helper.rb
140
+ - spec/support/reset_config.rb