Skip to content

Commit

Permalink
Support Rails 6.1 (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlarraz authored Aug 4, 2021
1 parent e0489d1 commit 9bfa804
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ jobs:
- '2.6'
- '2.7'
activerecord:
- '5.2'
- '6.1'
- '6.0'
- '5.2'
services:
postgres:
image: postgres:12
Expand Down
2 changes: 1 addition & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--colour
--force-color
2 changes: 1 addition & 1 deletion amountable.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
gem.require_paths = ['lib']
gem.required_ruby_version = '>= 2.6'

gem.add_dependency 'activerecord', '>= 5.2', '< 6.1'
gem.add_dependency 'activerecord', '>= 5.2', '< 7'
gem.add_dependency 'activerecord-import', '>= 0.19.1'
gem.add_dependency 'money-rails', '>=1.7.0'
gem.add_dependency 'monetize'
Expand Down
5 changes: 5 additions & 0 deletions gemfiles/activerecord_6.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "https://rubygems.org"

gemspec path: "../"

gem "activerecord", "~> 6.1.0"
17 changes: 1 addition & 16 deletions lib/amountable/amount.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,6 @@

module Amountable
class Amount < ActiveRecord::Base
class_attribute :columns
self.columns = []

def self.column(name, sql_type = nil, default = nil, null = true)
type = "ActiveRecord::Type::#{sql_type.to_s.camelize}".constantize.new
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, type, null)
end

column :amountable_type, :string, nil, false
column :amountable_id, :integer, nil, false
column :value_currency, :string, nil, true
column :value_cents, :integer, 0, false
column :name, :string, nil, false

include Amountable::Operations

belongs_to :amountable, polymorphic: true
Expand All @@ -31,6 +17,5 @@ def save
raise StandardError.new("Can't persist amount to database") if persistable == false
super
end

end
end
end
4 changes: 2 additions & 2 deletions spec/amountable/amountable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
expect(amount.persisted?).to be true
end
expect do
expect(order.update_attributes(sub_total: Money.new(200)))
expect(order.update(sub_total: Money.new(200)))
end.not_to change { Amountable::Amount.count }
end

Expand Down Expand Up @@ -80,7 +80,7 @@
expect { subscription.save }.not_to change { Amountable::Amount.count }
expect(amount.persisted?).to be false
end
subscription.update_attributes(sub_total: Money.new(200))
subscription.update(sub_total: Money.new(200))
expect(subscription.sub_total).to eq(Money.new(200))
expect(subscription.total).to eq(Money.new(200))
subscription.sub_total = Money.zero
Expand Down
2 changes: 1 addition & 1 deletion spec/support/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ActiveRecord::Base.default_timezone = :utc
ActiveRecord::Base.configurations = YAML.load_file(database_yml)
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), '../debug.log'))
ActiveRecord::Base.logger.level = ENV['TRAVIS'] ? ::Logger::ERROR : ::Logger::DEBUG
ActiveRecord::Base.logger.level = ENV['CI'] ? ::Logger::ERROR : ::Logger::DEBUG
config = ActiveRecord::Base.configurations[db_name]

begin
Expand Down

0 comments on commit 9bfa804

Please sign in to comment.