Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
skatkov committed Jun 5, 2024
1 parent 9fe0300 commit 3036eea
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 18 deletions.
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require: standard

AllCops:
TargetRubyVersion: 3.1

inherit_gem:
standard: config/base.yml
# Don't define any actual rubocop config here - this file is only used for
# proper editor support, and not used on CI, formatters, nor anywhere else.
2 changes: 1 addition & 1 deletion .standard.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# For available configuration options, see:
# https://github.com/standardrb/standard
ruby_version: 3.0
ruby_version: 3.1
2 changes: 1 addition & 1 deletion example/config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name")

if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger = ActiveSupport::Logger.new($stdout)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
Expand Down
1 change: 0 additions & 1 deletion lib/munster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require_relative "munster/engine"
require_relative "munster/jobs/processing_job"
require "active_support/configurable"
require_relative "munster/jobs/processing_job"

module Munster
def self.configuration
Expand Down
3 changes: 2 additions & 1 deletion lib/munster/controllers/receive_webhooks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module Munster
class ReceiveWebhooksController < ActionController::API
class HandlerRefused < StandardError
end
class HandlerInactive <StandardError

class HandlerInactive < StandardError
end

def create
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/webhooks_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "test_helper"

class WebhooksControllerTest < ActionDispatch::IntegrationTest
setup { @body_str = received_webhooks(:received_provider_disruption).body}
setup { @body_str = received_webhooks(:received_provider_disruption).body }

test "accepts a customer.io webhook with changed notification preferences" do
post "/munster/test", params: @body_str, headers: {"CONTENT_TYPE" => "application/json"}
Expand Down Expand Up @@ -41,7 +41,7 @@ class WebhooksControllerTest < ActionDispatch::IntegrationTest
end

test "saves only one webhook" do
body = { event_id: SecureRandom.uuid, body: 'test'}.to_json
body = {event_id: SecureRandom.uuid, body: "test"}.to_json

assert_changes_by -> { Munster::ReceivedWebhook.count }, exactly: 1 do
3.times do
Expand Down
2 changes: 1 addition & 1 deletion test/dummy/app/webhooks/extract_id_handler.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ExtractIdHandler < WebhookTestHandler
def extract_event_id_from_request(action_dispatch_request)
JSON.parse(action_dispatch_request.body.read).fetch("event_id")
JSON.parse(action_dispatch_request.body.read).fetch("event_id")
end
end
2 changes: 1 addition & 1 deletion test/dummy/app/webhooks/private_handler.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

class PrivateHandler < WebhookTestHandler
def valid?(request) = false

def expose_errors_to_sender? = false
end
4 changes: 2 additions & 2 deletions test/dummy/bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ require "fileutils"
# path to your application root.
APP_ROOT = File.expand_path("..", __dir__)

def system!(*)
system(*, exception: true)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end

FileUtils.chdir APP_ROOT do
Expand Down
2 changes: 1 addition & 1 deletion test/dummy/config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
config.force_ssl = true

# Log to STDOUT by default
config.logger = ActiveSupport::Logger.new(STDOUT)
config.logger = ActiveSupport::Logger.new($stdout)
.tap { |logger| logger.formatter = ::Logger::Formatter.new }
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }

Expand Down
10 changes: 5 additions & 5 deletions test/dummy/config/initializers/munster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

Munster.configure do |config|
config.active_handlers = {
:test => WebhookTestHandler,
:inactive => InactiveHandler,
:invalid => InvalidHandler,
:private => PrivateHandler,
:extract_id => ExtractIdHandler
test: WebhookTestHandler,
inactive: InactiveHandler,
invalid: InvalidHandler,
private: PrivateHandler,
extract_id: ExtractIdHandler
}
end
2 changes: 1 addition & 1 deletion test/dummy/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Rails.application.routes.draw do
mount Munster::Engine => "/munster", as: "webhooks"
mount Munster::Engine => "/munster", :as => "webhooks"
end
1 change: 0 additions & 1 deletion test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@
t.index ["handler_module_name", "handler_event_id"], name: "webhook_dedup_idx", unique: true
t.index ["status"], name: "index_received_webhooks_on_status"
end

end
19 changes: 19 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,24 @@ def assert_changes_by(expression, message = nil, exactly: nil, at_least: nil, at
at_most = exactly
at_least = exactly
end

# We do not make these an if/else since we allow both at_most and at_least
if at_most
error = "#{expression.inspect} changed by #{delta} which is more than #{at_most}"
error = "#{error}. It was #{before} and became #{after}"
error = "#{message.call}.\n" if message&.respond_to?(:call)
error = "#{message}.\n#{error}" if message && !message.respond_to?(:call)
assert delta <= at_most, error
end

if at_least
error = "#{expression.inspect} changed by #{delta} which is less than #{at_least}"
error = "#{error}. It was #{before} and became #{after}"
error = "#{message.call}.\n" if message&.respond_to?(:call)
error = "#{message}.\n#{error}" if message && !message.respond_to?(:call)
assert delta >= at_least, error
end

retval
end
end

0 comments on commit 3036eea

Please sign in to comment.