Skip to content

Commit

Permalink
Support Ruby 3
Browse files Browse the repository at this point in the history
  • Loading branch information
mlarraz committed Oct 1, 2021
1 parent cb3680c commit a1006ce
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ jobs:
strategy:
matrix:
ruby:
- '2.6'
- '3.0'
- '2.7'
- '2.6'
activerecord:
- '6.1'
- '6.0'
Expand Down
2 changes: 2 additions & 0 deletions lib/amountable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def where(opts, *rest)
super
end
end
ruby2_keywords :where if Module.private_method_defined?(:ruby2_keywords)

def where_json(opts, *rest)
values = []
Expand All @@ -136,6 +137,7 @@ def where_json(opts, *rest)
query = [query.join(' AND ')] + values
where(query, *rest).where(opts, *rest)
end
ruby2_keywords :where_json if Module.private_method_defined?(:ruby2_keywords)

def pg_json_field_access(name, field = :cents)
name = name.to_sym
Expand Down
8 changes: 4 additions & 4 deletions lib/amountable/table_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ def set_amount(name, value)
amount.value
end

def save(args = {})
def save(**args)
ActiveRecord::Base.transaction do
save_amounts if super(args)
save_amounts if super
end
end

def save!(args = {})
def save!(**args)
ActiveRecord::Base.transaction do
save_amounts! if super(args)
save_amounts! if super
end
end

Expand Down
6 changes: 6 additions & 0 deletions spec/support/database.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# Copyright 2015-2021, Instacart

require "activerecord-import/base"

db_name = ENV['DB'] || 'postgresql'
spec_dir = Pathname.new(File.dirname(__FILE__)) / '..'
database_yml = spec_dir.join('internal/config/database.yml')

fail "Please create #{database_yml} first to configure your database. Take a look at: #{database_yml}.sample" unless File.exist?(database_yml)

module ActiveRecord::Import::Connection
ruby2_keywords :establish_connection if Module.private_method_defined?(:ruby2_keywords)
end

ActiveRecord::Migration.verbose = false
ActiveRecord::Base.default_timezone = :utc
ActiveRecord::Base.configurations = YAML.load_file(database_yml)
Expand Down

0 comments on commit a1006ce

Please sign in to comment.