Skip to content

Commit 36d4ea6

Browse files
authored
Merge pull request #617 from juanmanuelramallo/ruby-3-support-migration-extension
Ruby 3 support
2 parents cac3e2b + 9cd0042 commit 36d4ea6

File tree

6 files changed

+19
-10
lines changed

6 files changed

+19
-10
lines changed

.github/workflows/ruby.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
runs-on: ubuntu-latest
2020
strategy:
2121
matrix:
22-
ruby-version: ['2.6', '2.7']
22+
ruby-version: ['2.6', '2.7', '3.0']
2323
mongodb-version: ['4.4']
2424
sqlite-version: ['3.0']
2525

Rakefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ namespace :spec do
5555
framework, version = file_name.split(/(\d+)/)
5656
major, minor = version.split(//)
5757

58+
# Ruby 3 exclusions
59+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
60+
# Rails 5 does not support ruby-3.0.0 https://github.com/rails/rails/issues/40938#issuecomment-751569171
61+
# Mongoid gem does not yet support ruby-3.0.0 https://github.com/mongodb/mongoid#compatibility
62+
next if framework == 'mongoid' || (framework == 'rails' && version == "5")
63+
end
64+
5865
frameworks_versions[framework] ||= []
5966
frameworks_versions[framework] << file_name
6067

lib/money-rails/active_model/validator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ def add_error!(record, attr, details)
7979
attr_name = attr.to_s.tr('.', '_').humanize
8080
attr_name = record.class.human_attribute_name(attr, default: attr_name)
8181

82-
record.errors.add(attr, :invalid_currency, {
82+
record.errors.add(attr, :invalid_currency,
8383
thousands: details.thousands_separator,
8484
decimal: details.decimal_mark,
8585
currency: details.abs_raw_value,
8686
attribute: attr_name
87-
})
87+
)
8888
end
8989

9090
def value_has_too_many_decimal_points(details)

lib/money-rails/active_record/migration_extensions/schema_statements_pg_rails4.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ module SchemaStatements
55
def add_monetize(table_name, accessor, options={})
66
[:amount, :currency].each do |attribute|
77
column_present, *opts = OptionsExtractor.extract attribute, table_name, accessor, options
8-
add_column(*opts) if column_present
8+
constraints = opts.pop
9+
add_column(*opts, **constraints) if column_present
910
end
1011
end
1112

lib/money-rails/active_record/migration_extensions/table_pg_rails4.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ module Table
55
def monetize(accessor, options={})
66
[:amount, :currency].each do |attribute|
77
column_present, _, *opts = OptionsExtractor.extract attribute, :no_table, accessor, options
8-
column(*opts) if column_present
8+
constraints = opts.pop
9+
column(*opts, **constraints) if column_present
910
end
1011
end
1112

spec/dummy/db/schema.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
# of editing this file, please use the migrations feature of Active Record to
33
# incrementally modify your database, and then regenerate this schema definition.
44
#
5-
# Note that this schema.rb definition is the authoritative source for your
6-
# database schema. If you need to create the application database on another
7-
# system, you should be using db:schema:load, not running all the migrations
8-
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
9-
# you'll amass, the slower it'll run and the greater likelihood for issues).
5+
# This file is the source Rails uses to define your schema when running `bin/rails
6+
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7+
# be faster and is potentially less error prone than running all of your
8+
# migrations from scratch. Old migrations may fail to apply correctly if those
9+
# migrations use external dependencies or application code.
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

0 commit comments

Comments
 (0)