Skip to content

Commit

Permalink
Convert source code to "new" hash format
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosantoniodasilva committed Sep 23, 2019
1 parent a984037 commit a64cee7
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Bundler::GemHelper.install_tasks
require 'rake/testtask'

desc 'Default: run unit tests.'
task :default => :test
task default: :test

desc 'Run tests.'
Rake::TestTask.new(:test) do |t|
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n_alchemy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def localized(attributes = nil)

included do
class_attribute :localized_methods,
:instance_reader => false, :instance_writer => false
instance_reader: false, instance_writer: false
self.localized_methods = {}
end

Expand Down
2 changes: 1 addition & 1 deletion lib/i18n_alchemy/date_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def extract_date(parsed_date)
end

def i18n_format
I18n.t(:default, :scope => [i18n_scope, :formats])
I18n.t(:default, scope: [i18n_scope, :formats])
end

def i18n_scope
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n_alchemy/numeric_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def separator
end

def translate(key)
I18n.t(key, :scope => :"number.format")
I18n.t(key, scope: :"number.format")
end

def valid_for_localization?(value)
Expand Down
12 changes: 6 additions & 6 deletions test/action_view_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class ActionViewTest < I18n::Alchemy::TestCase
def setup
@template = ActionView::Base.respond_to?(:empty) ? ActionView::Base.empty : ActionView::Base.new
@product = Product.new(
:name => "Potato",
:quantity => 10,
:price => 1.99,
:released_at => Date.new(2011, 2, 28),
:last_sale_at => Time.mktime(2011, 2, 28, 13, 25, 30)
name: "Potato",
quantity: 10,
price: 1.99,
released_at: Date.new(2011, 2, 28),
last_sale_at: Time.mktime(2011, 2, 28, 13, 25, 30)
)
@localized = @product.localized

Expand Down Expand Up @@ -48,7 +48,7 @@ def assert_same_text_input(attribute, value)
assert_includes [
text_input_sorted_attributes(attribute, value),
text_input_unsorted_attributes(attribute, value)
], @template.text_field(:product, attribute, :object => @localized)
], @template.text_field(:product, attribute, object: @localized)
end

def text_input_sorted_attributes(attribute_name, value)
Expand Down
4 changes: 2 additions & 2 deletions test/custom_parsers/my_custom_date_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ module MyCustomDateParser
extend self

def localize(value)
I18n.localize value, :format => :custom
I18n.localize value, format: :custom
end

protected

def i18n_format
I18n.t(:custom, :scope => [:date, :formats])
I18n.t(:custom, scope: [:date, :formats])
end
end
4 changes: 2 additions & 2 deletions test/db/test_schema.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:database => ":memory:"
adapter: "sqlite3",
database: ":memory:"
)

ActiveRecord::Schema.define do
Expand Down
28 changes: 14 additions & 14 deletions test/i18n_alchemy/proxy/attributes_parsing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ProxyAttributesParsingTest < I18n::Alchemy::ProxyTestCase
# Attributes
def test_initializes_proxy_with_attributes
@localized = @product.localized(
:name => "Banana", :price => "0,99", :released_at => "28/02/2011")
name: "Banana", price: "0,99", released_at: "28/02/2011")

assert_equal 0.99, @product.price
assert_equal "0,99", @localized.price
Expand All @@ -14,7 +14,7 @@ def test_initializes_proxy_with_attributes
end

def test_assign_attributes
@localized.assign_attributes(:price => '1,99')
@localized.assign_attributes(price: '1,99')
assert_equal "1,99", @localized.price
end

Expand All @@ -31,7 +31,7 @@ def test_assign_attributes_does_not_change_given_attributes_hash
end

def test_attributes_assignment
@localized.attributes = { :price => '1,99' }
@localized.attributes = { price: '1,99' }
assert_equal "1,99", @localized.price
end

Expand All @@ -42,7 +42,7 @@ def test_attributes_assignment_does_not_change_given_attributes_hash
end

def test_update
@localized.update(:price => '2,88')
@localized.update(price: '2,88')
assert_equal '2,88', @localized.price
assert_equal 2.88, @product.reload.price
end
Expand All @@ -54,13 +54,13 @@ def test_update_does_not_change_given_attributes_hash
end

def test_update_attributes
@localized.update_attributes(:price => '2,88')
@localized.update_attributes(price: '2,88')
assert_equal '2,88', @localized.price
assert_equal 2.88, @product.reload.price
end

def test_update!
@localized.update!(:price => '2,88')
@localized.update!(price: '2,88')
assert_equal '2,88', @localized.price
assert_equal 2.88, @product.reload.price
end
Expand All @@ -72,7 +72,7 @@ def test_update_bang_does_not_change_given_attributes_hash
end

def test_update_attributes!
@localized.update_attributes!(:price => '2,88')
@localized.update_attributes!(price: '2,88')
assert_equal '2,88', @localized.price
assert_equal 2.88, @product.reload.price
end
Expand All @@ -85,40 +85,40 @@ def test_update_attribute

# Nested Attributes
def test_should_assign_for_nested_attributes_for_collection_association
@supplier_localized.assign_attributes(:products_attributes => [{:price => '1,99'}, {:price => '2,93'}])
@supplier_localized.assign_attributes(products_attributes: [{ price: '1,99' }, { price: '2,93' }])
assert_equal 2, @supplier_localized.products.size
assert_equal '1,99', @supplier_localized.products.first.localized.price
assert_equal '2,93', @supplier_localized.products.last.localized.price
end

def test_should_assign_for_nested_attributes_passing_a_hash_for_collection_with_unique_keys
@supplier_localized.assign_attributes(:products_attributes => {"0" => {:price => '2,93', "_destroy"=>"false"}, "1" => {:price => '2,85', "_destroy" => "false"}})
@supplier_localized.assign_attributes(products_attributes: { '0' => { price: '2,93', _destroy: 'false' }, '1' => { price: '2,85', _destroy: 'false' }})
prices = @supplier.products.map { |p| p.localized.price }.sort
assert_equal ['2,85', '2,93'], prices
end

def test_should_assign_for_nested_attributes_for_one_to_one_association
@supplier_localized.assign_attributes(:account_attributes => {:account_number => 10, :total_money => '100,87'})
@supplier_localized.assign_attributes(account_attributes: { account_number: 10, total_money: '100,87' })
account = @supplier_localized.account
assert_equal '10', account.account_number.to_s
assert_equal '100,87', account.localized.total_money
end

def test_update_for_nested_attributes
@supplier_localized.update(:account_attributes => {:total_money => '99,87'})
@supplier_localized.update(account_attributes: { total_money: '99,87' })
assert_equal '99,87', @supplier_localized.account.localized.total_money
end

def test_attributes_assignment_for_nested
@supplier_localized.attributes = {:account_attributes => {:total_money => '88,12'}}
@supplier_localized.attributes = { account_attributes: { total_money: '88,12' }}
assert_equal '88,12', @supplier_localized.account.localized.total_money
end

private

def assert_attributes_hash_is_unchanged
attributes = { :quantity => 1 }
attributes = { quantity: 1 }
yield attributes
assert_equal({ :quantity => 1 }, attributes)
assert_equal({ quantity: 1 }, attributes)
end
end
2 changes: 1 addition & 1 deletion test/i18n_alchemy/proxy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class ProxyTest < I18n::Alchemy::ProxyTestCase
def test_delegates_orm_methods_to_target_object
assert @product.new_record?
assert @localized.save!(:name => "foo", :price => 1.99)
assert @localized.save!(name: "foo", price: 1.99)
assert !@product.new_record?
end

Expand Down
8 changes: 4 additions & 4 deletions test/models/product.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class Product < ActiveRecord::Base
include I18n::Alchemy
localize :total, :using => :number
localize :estimated_delivery_at, :using => :date
localize :estimated_last_comission_payment_at, :using => :timestamp
localize :released_month, :using => MyCustomDateParser
localize :total, using: :number
localize :estimated_delivery_at, using: :date
localize :estimated_last_comission_payment_at, using: :timestamp
localize :released_month, using: MyCustomDateParser

belongs_to :supplier

Expand Down
2 changes: 1 addition & 1 deletion test/models/supplier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ class Supplier < ActiveRecord::Base
end

class AnotherSupplier < Supplier
localize :created_at, :using => :timestamp
localize :created_at, using: :timestamp
end
2 changes: 1 addition & 1 deletion test/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ class User
include I18n::Alchemy
attr_accessor :created_at

localize :created_at, :using => :date
localize :created_at, using: :date
end

0 comments on commit a64cee7

Please sign in to comment.