solidus_webhooks 0.2.0 → 0.3.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: d71609325f0e59694111c1efee4a131a283af6dfac87d9102a9e405dfca918ea
4
- data.tar.gz: b9f80ecd1f6652d83915b2a49c083285df3e7e17c63b01414c273857daeadd44
3
+ metadata.gz: '081615f05564d22cc05bc064b5593dbe09d2ec9342cae1b656fa909e6cf0bd53'
4
+ data.tar.gz: 84cb7dfd9a491681f8e823747e5221159869946c5de0fa4427d338eff8a9b814
5
5
  SHA512:
6
- metadata.gz: 826c8abe905a3a69d7ea642b72a047534282db7bb60c3cdced93f897c2d62f887d72807aff7cb57cc5ec1082966b9602908c97d7ba2d866ad3ffb8aeb0f09ce1
7
- data.tar.gz: 8fab3c87b593ca5743818ed8551296b85709813341fa5bba3ddd2561992138fc92ba984525b3080a5c30fd9d2b64f35f99d610cdcd885115f1732eadccbe4780
6
+ metadata.gz: 3a87662271d388322037918856a947ba390fc81cf4f6ddbfb46d6dde9910e527f3c4d8fa07da71f8abd1dd3680f8cf72c9cd1b684085b1b5a9e74bdf428389f2
7
+ data.tar.gz: 73562c98cffb0857666f9f4dba5336918c807c983548ee4b9b8eee4034d9f8629ac2c38cc59687ca13c4c98dc8f60e6478a85ab174c4c2a0dc763bda65521bcd
@@ -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:
@@ -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
@@ -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
@@ -1,7 +1,11 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
1
3
  require:
2
4
  - solidus_dev_support/rubocop
3
5
 
4
6
  AllCops:
7
+ NewCops: enable
5
8
  Exclude:
6
9
  - sandbox/**/*
7
10
  - spec/dummy/**/*
11
+ - vendor/bundle/**/*
@@ -0,0 +1,107 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2020-10-19 16:38:34 UTC using RuboCop version 0.93.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 6
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: EnabledMethods.
12
+ Capybara/FeatureMethods:
13
+ Exclude:
14
+ - 'spec/features/can_register_a_handler_and_receive_webhooks_spec.rb'
15
+
16
+ # Offense count: 2
17
+ # Cop supports --auto-correct.
18
+ Layout/BlockEndNewline:
19
+ Exclude:
20
+ - 'spec/features/can_register_a_handler_and_receive_webhooks_spec.rb'
21
+
22
+ # Offense count: 2
23
+ # Cop supports --auto-correct.
24
+ Layout/MultilineBlockLayout:
25
+ Exclude:
26
+ - 'spec/features/can_register_a_handler_and_receive_webhooks_spec.rb'
27
+
28
+ # Offense count: 2
29
+ # Cop supports --auto-correct.
30
+ # Configuration parameters: EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
31
+ # SupportedStyles: space, no_space
32
+ # SupportedStylesForEmptyBraces: space, no_space
33
+ Layout/SpaceInsideBlockBraces:
34
+ EnforcedStyle: space
35
+
36
+ # Offense count: 30
37
+ # Cop supports --auto-correct.
38
+ # Configuration parameters: EnforcedStyleForEmptyBraces.
39
+ # SupportedStyles: space, no_space, compact
40
+ # SupportedStylesForEmptyBraces: space, no_space
41
+ Layout/SpaceInsideHashLiteralBraces:
42
+ EnforcedStyle: space
43
+
44
+ # Offense count: 1
45
+ # Cop supports --auto-correct.
46
+ Lint/RedundantCopDisableDirective:
47
+ Exclude:
48
+ - 'bin/sandbox_rails'
49
+
50
+ # Offense count: 1
51
+ # Cop supports --auto-correct.
52
+ # Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods.
53
+ Lint/UnusedMethodArgument:
54
+ Exclude:
55
+ - 'spec/features/can_register_a_handler_and_receive_webhooks_spec.rb'
56
+
57
+ # Offense count: 3
58
+ RSpec/MultipleExpectations:
59
+ Max: 11
60
+
61
+ # Offense count: 1
62
+ # Configuration parameters: AllowSubject.
63
+ RSpec/MultipleMemoizedHelpers:
64
+ Max: 14
65
+
66
+ # Offense count: 2
67
+ # Configuration parameters: IgnoreSharedExamples.
68
+ RSpec/NamedSubject:
69
+ Exclude:
70
+ - 'spec/solidus_webhooks/configuration_spec.rb'
71
+
72
+ # Offense count: 2
73
+ # Cop supports --auto-correct.
74
+ # Configuration parameters: EnforcedStyle.
75
+ # SupportedStyles: nested, compact
76
+ Style/ClassAndModuleChildren:
77
+ Exclude:
78
+ - 'app/controllers/spree/webhooks_controller.rb'
79
+ - 'app/models/spree/webhook.rb'
80
+
81
+ # Offense count: 4
82
+ # Cop supports --auto-correct.
83
+ # Configuration parameters: EnforcedStyle.
84
+ # SupportedStyles: always, always_true, never
85
+ Style/FrozenStringLiteralComment:
86
+ Exclude:
87
+ - 'spec/**/*'
88
+ - 'db/migrate/**/*'
89
+ - 'bin/**/*'
90
+ - 'app/controllers/spree/webhooks_controller.rb'
91
+ - 'app/models/spree/webhook.rb'
92
+ - 'lib/solidus_webhooks/configuration.rb'
93
+ - 'lib/solidus_webhooks/errors.rb'
94
+
95
+ # Offense count: 2
96
+ # Cop supports --auto-correct.
97
+ # Configuration parameters: EnforcedOctalStyle.
98
+ # SupportedOctalStyles: zero_with_o, zero_only
99
+ Style/NumericLiteralPrefix:
100
+ Exclude:
101
+ - 'spec/features/can_register_a_handler_and_receive_webhooks_spec.rb'
102
+
103
+ # Offense count: 1
104
+ # Cop supports --auto-correct.
105
+ Style/Proc:
106
+ Exclude:
107
+ - 'spec/solidus_webhooks/configuration_spec.rb'
@@ -0,0 +1,38 @@
1
+ # Changelog
2
+
3
+ ## [v0.3.0](https://github.com/solidusio-contrib/solidus_webhooks/tree/v0.3.0) (2020-10-20)
4
+
5
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_webhooks/compare/v0.2.0...v0.3.0)
6
+
7
+ **Fixed bugs:**
8
+
9
+ - Fix error classes [\#5](https://github.com/solidusio-contrib/solidus_webhooks/pull/5) ([elia](https://github.com/elia))
10
+
11
+ ## [v0.2.0](https://github.com/solidusio-contrib/solidus_webhooks/tree/v0.2.0) (2020-06-10)
12
+
13
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_webhooks/compare/v0.1.0...v0.2.0)
14
+
15
+ **Implemented enhancements:**
16
+
17
+ - Expose current\_api\_user to webhook handlers [\#4](https://github.com/solidusio-contrib/solidus_webhooks/pull/4) ([elia](https://github.com/elia))
18
+
19
+ ## [v0.1.0](https://github.com/solidusio-contrib/solidus_webhooks/tree/v0.1.0) (2020-05-14)
20
+
21
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_webhooks/compare/v0.1.0.beta.1...v0.1.0)
22
+
23
+ ## [v0.1.0.beta.1](https://github.com/solidusio-contrib/solidus_webhooks/tree/v0.1.0.beta.1) (2020-05-13)
24
+
25
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_webhooks/compare/v0.0.1.v0.1.0.beta.1.1...v0.1.0.beta.1)
26
+
27
+ ## [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)
28
+
29
+ [Full Changelog](https://github.com/solidusio-contrib/solidus_webhooks/compare/9573caa400232ffb44cde7f8cf907171a529ced3...v0.0.1.v0.1.0.beta.1.1)
30
+
31
+ **Merged pull requests:**
32
+
33
+ - Prepare the repo to be moved to @solidusio-contrib [\#2](https://github.com/solidusio-contrib/solidus_webhooks/pull/2) ([elia](https://github.com/elia))
34
+ - Add the ability to register and receive webhooks [\#1](https://github.com/solidusio-contrib/solidus_webhooks/pull/1) ([elia](https://github.com/elia))
35
+
36
+
37
+
38
+ \* *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,23 @@
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
+ ## Installation
7
+
8
+ Add solidus_webhooks to your Gemfile:
9
+
10
+ ```ruby
11
+ gem 'solidus_webhooks'
12
+ ```
13
+
14
+ Bundle your dependencies and run the installation generator:
15
+
16
+ ```shell
17
+ bin/rails generate solidus_webhooks:install
18
+ ```
19
+
20
+ ## Usage
8
21
 
9
22
  A Webhook receiver is just a callable and can be registered in the Solidus configuration as follows:
10
23
 
@@ -33,8 +46,8 @@ The only requirement on handlers is for them to respond to `#call` and accept a
33
46
  Example:
34
47
 
35
48
  ```ruby
36
- class TrackingNumberHandler
37
- def call(payload)
49
+ module TrackingNumberHandler
50
+ def self.call(payload)
38
51
  order = Spree::Order.find_by!(number: payload[:order])
39
52
  shipment = order.shipments.find_by!(number: payload[:shipment])
40
53
  shipment.update!(tracking: payload[:tracking])
@@ -121,30 +134,15 @@ SolidusWebhooks.config.register_webhook_handler :tracking_number, -> payload, us
121
134
  }
122
135
  ```
123
136
 
137
+ ## Development
124
138
 
125
- Installation
126
- ------------
127
-
128
- Add solidus_webhooks to your Gemfile:
139
+ ### Testing the extension
129
140
 
130
- ```ruby
131
- gem 'solidus_webhooks'
132
- ```
133
-
134
- Bundle your dependencies and run the installation generator:
135
-
136
- ```shell
137
- bundle
138
- bundle exec rails g solidus_webhooks:install
139
- ```
140
-
141
- Testing
142
- -------
143
-
144
- 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`.
141
+ First bundle your dependencies, then run `bin/rake`. `bin/rake` will default to building the dummy
142
+ app if it does not exist, then it will run specs. The dummy app can be regenerated by using
143
+ `bin/rake extension:test_app`.
145
144
 
146
145
  ```shell
147
- bundle
148
146
  bin/rake
149
147
  ```
150
148
 
@@ -161,16 +159,15 @@ Simply add this require statement to your spec_helper:
161
159
  require 'solidus_webhooks/factories'
162
160
  ```
163
161
 
164
- Sandbox app
165
- -----------
162
+ ### Running the sandbox
166
163
 
167
- To run this extension in a sandboxed Solidus application you can run `bin/sandbox`
168
- The path for the sandbox app is `./sandbox` and `bin/rails` will forward any Rails command
169
- to `sandbox/bin/rails`.
164
+ To run this extension in a sandboxed Solidus application, you can run `bin/sandbox`. The path for
165
+ the sandbox app is `./sandbox` and `bin/rails` will forward any Rails commands to
166
+ `sandbox/bin/rails`.
170
167
 
171
- Example:
168
+ Here's an example:
172
169
 
173
- ```shell
170
+ ```
174
171
  $ bin/rails server
175
172
  => Booting Puma
176
173
  => Rails 6.0.2.1 application starting in development
@@ -178,13 +175,31 @@ $ bin/rails server
178
175
  Use Ctrl-C to stop
179
176
  ```
180
177
 
181
- Releasing
182
- ---------
178
+ ### Updating the changelog
179
+
180
+ Before and after releases the changelog should be updated to reflect the up-to-date status of
181
+ the project:
182
+
183
+ ```shell
184
+ bin/rake changelog
185
+ git add CHANGELOG.md
186
+ git commit -m "Update the changelog"
187
+ ```
188
+
189
+ ### Releasing new versions
183
190
 
184
191
  Your new extension version can be released using `gem-release` like this:
185
192
 
186
193
  ```shell
187
- bundle exec gem bump -v VERSION --tag --push --remote upstream && gem release
194
+ bundle exec gem bump -v 1.6.0
195
+ bin/rake changelog
196
+ git add CHANGELOG.md
197
+ git commit --amend --no-edit
198
+ gem tag
199
+ git push --tags
200
+ bundle exec gem release
188
201
  ```
189
202
 
190
- Copyright (c) 2020 Nebulab srls, released under the New BSD License
203
+ ## License
204
+
205
+ 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,5 +1,5 @@
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])
@@ -1,9 +1,9 @@
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
7
  def receive(payload, user)
8
8
  if handler_arity == 1
9
9
  handler.call(payload)
@@ -16,7 +16,7 @@ class Spree::Webhook
16
16
  id = id.to_sym # normalize incoming ids
17
17
 
18
18
  handler = SolidusWebhooks.config.find_webhook_handler(id) or
19
- raise WebhookNotFound, "Cannot find a webhook handler for #{id.inspect}"
19
+ raise SolidusWebhooks::WebhookNotFound, "Cannot find a webhook handler for #{id.inspect}"
20
20
 
21
21
  new(id: id, handler: handler)
22
22
  end
@@ -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
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ app_root = 'sandbox'
4
+
5
+ unless File.exist? "#{app_root}/bin/rails"
6
+ warn 'Creating the sandbox app...'
7
+ Dir.chdir "#{__dir__}/.." do
8
+ system "#{__dir__}/sandbox" or begin
9
+ warn 'Automatic creation of the sandbox app failed'
10
+ exit 1
11
+ end
12
+ end
13
+ end
14
+
15
+ Dir.chdir app_root
16
+ exec 'bin/rails', *ARGV
@@ -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,24 @@
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'
9
+
10
+ module SolidusWebhooks
11
+ class << self
12
+ def configuration
13
+ @configuration ||= Configuration.new
14
+ end
15
+
16
+ alias config configuration
17
+
18
+ def reset_config!
19
+ @configuration = nil
20
+ end
21
+
22
+ def configure
23
+ yield configuration
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,5 @@
1
+ require 'solidus_webhooks/errors'
2
+
1
3
  module SolidusWebhooks
2
4
  class Configuration
3
5
  def initialize
@@ -6,7 +8,7 @@ module SolidusWebhooks
6
8
 
7
9
  def register_webhook_handler(id, handler)
8
10
  unless handler.respond_to? :call
9
- raise Spree::Webhook::InvalidHandler,
11
+ raise SolidusWebhooks::InvalidHandler,
10
12
  "Please provide a handler that responds to #call, got: #{handler.inspect}"
11
13
  end
12
14
 
@@ -17,14 +19,4 @@ module SolidusWebhooks
17
19
  @handlers[id.to_sym]
18
20
  end
19
21
  end
20
-
21
- def self.config
22
- @config
23
- end
24
-
25
- def self.reset_config!
26
- @config = Configuration.new
27
- end
28
-
29
- reset_config! # initialize the extension
30
22
  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.2.0'
4
+ VERSION = '0.3.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.
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ["lib"]
30
30
 
31
31
  spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 3']
32
- spec.add_dependency 'solidus_support', '~> 0.5.0'
32
+ spec.add_dependency 'solidus_support', '~> 0.5'
33
33
 
34
- spec.add_development_dependency 'solidus_dev_support'
34
+ spec.add_development_dependency 'solidus_dev_support', '~> 2.1'
35
35
  end
@@ -2,7 +2,6 @@ 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
5
  SolidusWebhooks.config.register_webhook_handler :proc, proc_handler
7
6
  SolidusWebhooks.config.register_webhook_handler :method, method_handler
8
7
  SolidusWebhooks.config.register_webhook_handler :user, user_handler
@@ -33,43 +32,43 @@ RSpec.feature "Can register a handler and receive Webhooks", type: :request do
33
32
  let(:unauthorized_token) { unauthorized_user.spree_api_key }
34
33
 
35
34
  scenario "calls the handler passing the payload" do
36
- post "/webhooks/proc?token=#{authorized_token}", as: :json, params: {a: 123}
35
+ post "/webhooks/proc?token=#{authorized_token}", as: :json, params: { a: 123 }
37
36
  expect(response).to have_http_status(:ok)
38
37
 
39
- post "/webhooks/proc?token=#{authorized_token}", as: :json, params: {b: 456}
38
+ post "/webhooks/proc?token=#{authorized_token}", as: :json, params: { b: 456 }
40
39
  expect(response).to have_http_status(:ok)
41
40
 
42
- post "/webhooks/method?token=#{authorized_token}", as: :json, params: {c: 789}
41
+ post "/webhooks/method?token=#{authorized_token}", as: :json, params: { c: 789 }
43
42
  expect(response).to have_http_status(:ok)
44
43
 
45
- post "/webhooks/user?token=#{authorized_token}", as: :json, params: {d: 012}
44
+ post "/webhooks/user?token=#{authorized_token}", as: :json, params: { d: 012 }
46
45
  expect(response).to have_http_status(:ok)
47
46
 
48
- post "/webhooks/splat?token=#{authorized_token}", as: :json, params: {e: 345}
47
+ post "/webhooks/splat?token=#{authorized_token}", as: :json, params: { e: 345 }
49
48
  expect(response).to have_http_status(:ok)
50
49
 
51
- post "/webhooks/method_and_user?token=#{authorized_token}", as: :json, params: {f: 678}
50
+ post "/webhooks/method_and_user?token=#{authorized_token}", as: :json, params: { f: 678 }
52
51
  expect(response).to have_http_status(:ok)
53
52
 
54
- expect(proc_payloads).to eq([{'a' => 123}, {'b' => 456}])
55
- expect(method_payloads).to eq([{'c' => 789}])
56
- expect(user_payloads).to eq([[{'d' => 012}, authorized_user]])
57
- expect(splat_payloads).to eq([[{'e' => 345}, authorized_user]])
58
- expect(method_and_user_payloads).to eq([{'f' => 678}])
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' => 012 }, authorized_user]])
56
+ expect(splat_payloads).to eq([[{ 'e' => 345 }, authorized_user]])
57
+ expect(method_and_user_payloads).to eq([{ 'f' => 678 }])
59
58
  end
60
59
 
61
60
  scenario "receives a bad handler id" do
62
- post "/webhooks/abc?token=#{authorized_token}", as: :json, params: {a: 123}
61
+ post "/webhooks/abc?token=#{authorized_token}", as: :json, params: { a: 123 }
63
62
  expect(response).to have_http_status(:not_found)
64
63
  end
65
64
 
66
65
  scenario "refuses a bad token" do
67
- post "/webhooks/user?token=b4d-t0k3n", as: :json, params: {a: 123}
66
+ post "/webhooks/user?token=b4d-t0k3n", as: :json, params: { a: 123 }
68
67
  expect(response).to have_http_status(:unauthorized)
69
68
  end
70
69
 
71
70
  scenario "refuses a token without permissions" do
72
- post "/webhooks/proc?token=#{unauthorized_token}", as: :json, params: {a: 123}
71
+ post "/webhooks/proc?token=#{unauthorized_token}", as: :json, params: { a: 123 }
73
72
  expect(response).to have_http_status(:unauthorized)
74
73
  end
75
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.new {}) }.not_to raise_error
8
+ end
9
+ end
10
+ end
@@ -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.2.0
4
+ version: 0.3.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-06-10 00:00:00.000000000 Z
11
+ date: 2020-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -36,29 +36,29 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 0.5.0
39
+ version: '0.5'
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.5'
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.1'
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.1'
61
+ description:
62
62
  email: contact@solidus.io
63
63
  executables: []
64
64
  extensions: []
@@ -67,9 +67,12 @@ 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
+ - ".rubocop_todo.yml"
75
+ - CHANGELOG.md
73
76
  - Gemfile
74
77
  - LICENSE
75
78
  - README.md
@@ -81,7 +84,9 @@ files:
81
84
  - app/controllers/spree/webhooks_controller.rb
82
85
  - app/models/spree/webhook.rb
83
86
  - bin/console
84
- - bin/r
87
+ - bin/rails
88
+ - bin/rails-engine
89
+ - bin/rails-sandbox
85
90
  - bin/rake
86
91
  - bin/sandbox
87
92
  - bin/sandbox_rails
@@ -89,14 +94,20 @@ files:
89
94
  - config/locales/en.yml
90
95
  - config/routes.rb
91
96
  - lib/generators/solidus_webhooks/install/install_generator.rb
97
+ - lib/generators/solidus_webhooks/install/templates/initializer.rb
92
98
  - lib/solidus_webhooks.rb
93
99
  - lib/solidus_webhooks/configuration.rb
94
100
  - lib/solidus_webhooks/engine.rb
101
+ - lib/solidus_webhooks/errors.rb
95
102
  - lib/solidus_webhooks/factories.rb
103
+ - lib/solidus_webhooks/testing_support/factories.rb
96
104
  - lib/solidus_webhooks/version.rb
97
105
  - solidus_webhooks.gemspec
98
106
  - spec/features/can_register_a_handler_and_receive_webhooks_spec.rb
107
+ - spec/models/spree/webhook_spec.rb
108
+ - spec/solidus_webhooks/configuration_spec.rb
99
109
  - spec/spec_helper.rb
110
+ - spec/support/reset_config.rb
100
111
  homepage: https://github.com/solidusio-contrib/solidus_webhooks#readme
101
112
  licenses:
102
113
  - BSD-3-Clause
@@ -104,7 +115,7 @@ metadata:
104
115
  homepage_uri: https://github.com/solidusio-contrib/solidus_webhooks#readme
105
116
  source_code_uri: https://github.com/solidusio-contrib/solidus_webhooks
106
117
  changelog_uri: https://github.com/solidusio-contrib/solidus_webhooks/releases
107
- post_install_message:
118
+ post_install_message:
108
119
  rdoc_options: []
109
120
  require_paths:
110
121
  - lib
@@ -112,17 +123,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
123
  requirements:
113
124
  - - "~>"
114
125
  - !ruby/object:Gem::Version
115
- version: '2.4'
126
+ version: '2.5'
116
127
  required_rubygems_version: !ruby/object:Gem::Requirement
117
128
  requirements:
118
129
  - - ">="
119
130
  - !ruby/object:Gem::Version
120
131
  version: '0'
121
132
  requirements: []
122
- rubygems_version: 3.1.2
123
- signing_key:
133
+ rubygems_version: 3.1.4
134
+ signing_key:
124
135
  specification_version: 4
125
136
  summary: Webhooks support for Solidus
126
137
  test_files:
127
138
  - spec/features/can_register_a_handler_and_receive_webhooks_spec.rb
139
+ - spec/models/spree/webhook_spec.rb
140
+ - spec/solidus_webhooks/configuration_spec.rb
128
141
  - spec/spec_helper.rb
142
+ - spec/support/reset_config.rb