Skip to content

Commit

Permalink
Remove the rest of Ruby 2.7 deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
onshi committed Oct 4, 2020
1 parent 8a7e57e commit 27cf364
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 22 deletions.
14 changes: 11 additions & 3 deletions lib/activity_notification/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ def self.resolve_value(context, thing, *args)
when Symbol
symbol_method = context.method(thing)
if symbol_method.arity > 1
symbol_method.call(ActivityNotification.get_controller, *args)
if args.last.kind_of?(Hash)
symbol_method.call(ActivityNotification.get_controller, *args[0...-1], **args[-1])
else
symbol_method.call(ActivityNotification.get_controller, *args)
end
elsif symbol_method.arity > 0
symbol_method.call(ActivityNotification.get_controller)
else
Expand Down Expand Up @@ -74,7 +78,11 @@ def resolve_value(thing, *args)
when Symbol
symbol_method = method(thing)
if symbol_method.arity > 0
symbol_method.call(*args)
if args.last.kind_of?(Hash)
symbol_method.call(*args[0...-1], **args[-1])
else
symbol_method.call(*args)
end
else
symbol_method.call
end
Expand Down Expand Up @@ -128,4 +136,4 @@ def printable_name
"#{self.printable_type} (#{id})"
end
end
end
end
4 changes: 2 additions & 2 deletions lib/activity_notification/renderable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def text(params = {})
)

# Generate the :default fallback key without using pluralization key :count
default = I18n.t(k, attrs)
I18n.t(k, attrs.merge(count: group_notification_count, default: default))
default = I18n.t(k, **attrs)
I18n.t(k, **attrs.merge(count: group_notification_count, default: default))
end

# Renders notification from views.
Expand Down
17 changes: 14 additions & 3 deletions spec/concerns/common_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def custom_method(controller)
test_instance.extend(AdditionalMethods)
expect(ActivityNotification.resolve_value(test_instance, :custom_method)).to eq(1)
end

it "returns specified symbol with controller and additional arguments" do
module AdditionalMethods
def custom_method(controller, key)
Expand All @@ -45,6 +45,17 @@ def custom_method(controller, key)
expect(ActivityNotification.resolve_value(test_instance, :custom_method, 'test1.key')).to eq(1)
expect(ActivityNotification.resolve_value(test_instance, :custom_method, 'test2.key')).to eq(0)
end

it "returns specified symbol with controller and additional arguments including hash as last argument" do
module AdditionalMethods
def custom_method(controller, key, options:)
controller == 'StubController' and key == 'test1.key' ? 1 : 0
end
end
test_instance.extend(AdditionalMethods)
expect(ActivityNotification.resolve_value(test_instance, :custom_method, 'test1.key', options: 1)).to eq(1)
expect(ActivityNotification.resolve_value(test_instance, :custom_method, 'test2.key', options: 1)).to eq(0)
end
end

context "with Proc" do
Expand All @@ -62,7 +73,7 @@ def custom_method(controller, key)
test_proc = ->(controller, model){ controller == 'StubController' and model == test_instance ? 1 : 0 }
expect(ActivityNotification.resolve_value(test_instance, test_proc)).to eq(1)
end

it "returns specified lambda with controller, context(model) and additional arguments" do
test_proc = ->(controller, model, key){ controller == 'StubController' and model == test_instance and key == 'test1.key' ? 1 : 0 }
expect(ActivityNotification.resolve_value(test_instance, test_proc, 'test1.key')).to eq(1)
Expand Down Expand Up @@ -188,4 +199,4 @@ def custom_method
end
end

end
end
10 changes: 5 additions & 5 deletions spec/concerns/renderable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
expect(I18n.t("notification.#{target_type_key}.#{params_text_key}.text"))
.to eq(params_text_original)
expect(I18n.t("notification.#{target_type_key}.#{params_text_key}.text",
{article_title: article_title}))
article_title: article_title))
.to eq(params_text_embedded)
end

it "has key configured with embedded params including group_member_count and group_notification_count" do
expect(I18n.t("notification.#{target_type_key}.#{group_text_key}.text"))
.to eq(group_text_original)
expect(I18n.t("notification.#{target_type_key}.#{group_text_key}.text",
{notifier_name: notifier_name, group_member_count: group_member_count, group_notification_count: group_notification_count}))
**{ notifier_name: notifier_name, group_member_count: group_member_count, group_notification_count: group_notification_count }))
.to eq(group_text_embedded)
end

Expand All @@ -50,10 +50,10 @@
expect(I18n.t("notification.#{target_type_key}.#{plural_text_key}.text")[:other])
.to eq(plural_text_original_other)
expect(I18n.t("notification.#{target_type_key}.#{plural_text_key}.text",
{article_title: article_title, notifier_name: notifier_name, count: 1}))
**{ article_title: article_title, notifier_name: notifier_name, count: 1 }))
.to eq(plural_text_embedded_one)
expect(I18n.t("notification.#{target_type_key}.#{plural_text_key}.text",
{article_title: article_title, notifier_name: notifier_name, count: group_notification_count}))
**{ article_title: article_title, notifier_name: notifier_name, count: group_notification_count }))
.to eq(plural_text_embedded_other)
end
end
Expand Down Expand Up @@ -126,4 +126,4 @@
# #layout_path

end
end
end
18 changes: 9 additions & 9 deletions spec/controllers/controller_spec_utility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ module CommitteeUtility
def api_path
"/#{root_path}/#{target_type}/#{test_target.id}"
end

def schema_path
Rails.root.join('..', 'openapi.json')
Rails.root.join('..', 'openapi.json')
end

def write_schema_file(schema_json)
File.open(schema_path, "w") { |file| file.write(schema_json) }
end

def read_schema_file
JSON.parse(File.read(schema_path))
end
Expand All @@ -97,31 +97,31 @@ def get_with_compatibility path, options = {}
if Rails::VERSION::MAJOR <= 4
get path, options[:params], options[:headers]
else
get path, options
get path, **options
end
end

def post_with_compatibility path, options = {}
if Rails::VERSION::MAJOR <= 4
post path, options[:params], options[:headers]
else
post path, options
post path, **options
end
end

def put_with_compatibility path, options = {}
if Rails::VERSION::MAJOR <= 4
put path, options[:params], options[:headers]
else
put path, options
put path, **options
end
end

def delete_with_compatibility path, options = {}
if Rails::VERSION::MAJOR <= 4
delete path, options[:params], options[:headers]
else
delete path, options
delete path, **options
end
end

Expand All @@ -133,4 +133,4 @@ def assert_all_schema_confirm(response, status)
end
end
end
end
end

0 comments on commit 27cf364

Please sign in to comment.