Skip to content

Commit

Permalink
Resolve function arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
orien committed Feb 7, 2024
1 parent eb310f5 commit 1a0c79b
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 23 deletions.
7 changes: 4 additions & 3 deletions app/models/concerns/attr_encrypted_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ def self.included(base)
base.extend ClassMethods
end

def as_json(except: [], **options)
except += [
def as_json(options = {})
options[:except] ||= []
options[:except] += [
:encryption_key_sha,
*self.class.encrypted_attributes.keys.flat_map do |column|
[column, :"encrypted_#{column}_iv", :"encrypted_#{column}"]
end
]
super(except: except, **options)
super(options)
end

private
Expand Down
4 changes: 2 additions & 2 deletions lib/samson/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ def only_callbacks_for_plugin(plugin_name, hook_name)
end

# use
def fire(name, *args)
traced(name) { hooks(name).map { |hook| hook.call(*args) } }
def fire(name, *args, **kwarags)
traced(name) { hooks(name).map { |hook| hook.call(*args, **kwargs) } }
end

def render_views(name, view, *args)
Expand Down
2 changes: 1 addition & 1 deletion lib/samson/secrets/vault_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def sync!(other)

def create_client
VaultClientWrapper.new(
DEFAULT_CLIENT_OPTIONS.merge(
**DEFAULT_CLIENT_OPTIONS.merge(
address: address,
ssl_cert_store: cert_store,
ssl_verify: tls_verify,
Expand Down
4 changes: 2 additions & 2 deletions plugins/datadog/test/models/datadog_deploy_event_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
let(:deploy) { deploys(:succeeded_test) }

describe '.deliver' do
def deliver(*args)
DatadogDeployEvent.deliver(deploy, *args)
def deliver(**args)
DatadogDeployEvent.deliver(deploy, **args)
end

def expected_body(overrides = {})
Expand Down
4 changes: 2 additions & 2 deletions plugins/datadog/test/models/datadog_monitor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def assert_datadog_timeout(&block)
end

it "shows Alert when groups are alerting" do
assert_datadog alerting_groups do
assert_datadog(**alerting_groups) do
monitor.state(groups).must_equal "Alert"
end
end
Expand Down Expand Up @@ -110,7 +110,7 @@ def assert_datadog_timeout(&block)
it "produces no extra sql queries" do
stage = stages(:test_production) # preload
assert_sql_queries 1 do # group-stage and groups
assert_datadog alerting_groups do
assert_datadog(**alerting_groups) do
monitor.state(stage.deploy_groups)
end
end
Expand Down
3 changes: 2 additions & 1 deletion plugins/env/app/models/environment_variable_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def variable_names
environment_variables.sort_by(&:id).map(&:name).uniq
end

def as_json(methods: [], **options)
def as_json(options = {})
methods = options.delete(:methods) || []
super({methods: [:variable_names] + methods}.merge(options))
end

Expand Down
4 changes: 2 additions & 2 deletions plugins/env/lib/samson_env/samson_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def write_dotenv(base_file, groups)
end

# TODO: use for write_env_files
Samson::Hooks.callback :deploy_env do |*args|
EnvironmentVariable.env(*args)
Samson::Hooks.callback :deploy_env do |*args, **kwargs|
EnvironmentVariable.env(*args, **kwargs)
end

Samson::Hooks.callback(:link_parts_for_resource) do
Expand Down
2 changes: 1 addition & 1 deletion plugins/sentry/lib/samson_sentry/samson_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ class SamsonPlugin < Rails::Engine

Samson::Hooks.callback :error do |exception, **options|
sentry_options = options.slice(:contexts, :extra, :tags, :user, :level, :fingerprint)
Sentry.capture_exception(exception, sentry_options)
Sentry.capture_exception(exception, **sentry_options)
end
4 changes: 2 additions & 2 deletions test/lib/samson/form_builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ def fake_erb_rendering

# NOTE: ideally don't use a plugin model, but we need something with accepts_nested_attributes_for
describe '#fields_for_many' do
def render(*args)
def render(*args, **kwargs)
project.rollbar_dashboards_settings.build # TODO: this does not get rendered
builder.fields_for_many(*args) do |p|
builder.fields_for_many(*args, **kwargs) do |p|
p.text_field :base_url, placeholder: 'thing!'
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/lib/samson/secrets/vault_client_wrapper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
it 'calls Vault::Client initialize with other arguments' do
client_args = {versioned_kv: true, use_ssl: true, timeout: 543, ssl_timeout: 345}

client = Samson::Secrets::VaultClientWrapper.new(client_args)
client = Samson::Secrets::VaultClientWrapper.new(**client_args)

client.instance_variable_get(:@ssl_verify).must_equal true
client.instance_variable_get(:@timeout).must_equal 543
Expand Down
2 changes: 1 addition & 1 deletion test/models/image_builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

def call(options = {})
defaults = {tag_as_latest: false, dockerfile: 'Dockerfile', tag: 'tag', cache_from: 'cache'}
ImageBuilder.build_image("foo", build, executor, defaults.merge(options))
ImageBuilder.build_image("foo", build, executor, **defaults.merge(options))
end

it "builds and pushes" do
Expand Down
6 changes: 3 additions & 3 deletions test/presenters/user_csv_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@

def csv_completeness_test(options = {}, expected = {})
meta_rows = 3
UserCsvPresenter.to_csv(options).split("\n").size.must_equal expected + meta_rows
UserCsvPresenter.to_csv(options).split("\n")[-2].split(",")[-1].to_i.must_equal expected
UserCsvPresenter.to_csv(**options).split("\n").size.must_equal expected + meta_rows
UserCsvPresenter.to_csv(**options).split("\n")[-2].split(",")[-1].to_i.must_equal expected
end

# on updating #csv_line this test helper may need to be updated
# This tests the optimized logic against the non-optimized logic.
def csv_accuracy_test(options = {})
actual = CSV.parse(UserCsvPresenter.to_csv(options))
actual = CSV.parse(UserCsvPresenter.to_csv(**options))
actual.shift
actual.pop(2)
actual.each do |csv_row|
Expand Down
4 changes: 2 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ def warden

# catch warden throw ... which would normally go into warden middleware and then be an unauthorized response
prepend(Module.new do
def process(*args)
catch(:warden) { return super }
def process(...)
catch(:warden) { return super(...) }
response.status = :unauthorized
response.body = ":warden caught in test_helper.rb"
response
Expand Down

0 comments on commit 1a0c79b

Please sign in to comment.