diff options
-rw-r--r-- | Gemfile | 1 | ||||
-rw-r--r-- | Gemfile.lock | 8 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/system_testing/driver.rb | 6 | ||||
-rw-r--r-- | actionpack/test/dispatch/system_testing/driver_test.rb | 4 | ||||
-rw-r--r-- | activemodel/CHANGELOG.md | 4 | ||||
-rw-r--r-- | activemodel/lib/active_model/errors.rb | 12 | ||||
-rw-r--r-- | activemodel/test/cases/errors_test.rb | 12 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 8 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/mysql2/virtual_column_test.rb | 2 | ||||
-rw-r--r-- | guides/source/i18n.md | 22 | ||||
-rw-r--r-- | railties/lib/rails/secrets.rb | 4 | ||||
-rw-r--r-- | railties/test/generators/app_generator_test.rb | 42 | ||||
-rw-r--r-- | railties/test/secrets_test.rb | 18 |
15 files changed, 132 insertions, 17 deletions
@@ -11,6 +11,7 @@ gem "arel", github: "rails/arel" # We need a newish Rake since Active Job sets its test tasks' descriptions. gem "rake", ">= 11.1" +gem "thor", github: "erikhuda/thor" # This needs to be with require false to ensure correct loading order, as it has to # be loaded after loading the test library. diff --git a/Gemfile.lock b/Gemfile.lock index 8bb0956de8..f06b9a32f2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,6 +7,12 @@ GIT pg (>= 0.17, < 0.20) GIT + remote: https://github.com/erikhuda/thor.git + revision: df5ba2b653a28087b3617d6c082b00866b0c0d6c + specs: + thor (0.19.4) + +GIT remote: https://github.com/matthewd/websocket-client-simple.git revision: e161305f1a466b9398d86df3b1731b03362da91b branch: close-race @@ -336,7 +342,6 @@ GEM daemons (~> 1.0, >= 1.0.9) eventmachine (~> 1.0, >= 1.0.4) rack (>= 1, < 3) - thor (0.19.4) thread (0.1.7) thread_safe (0.3.6) tilt (2.0.5) @@ -421,6 +426,7 @@ DEPENDENCIES sqlite3 (~> 1.3.6) stackprof sucker_punch + thor! turbolinks (~> 5) tzinfo-data uglifier (>= 1.3.0) diff --git a/actionpack/lib/action_dispatch/system_testing/driver.rb b/actionpack/lib/action_dispatch/system_testing/driver.rb index 1a027f2e23..81e6f0fc80 100644 --- a/actionpack/lib/action_dispatch/system_testing/driver.rb +++ b/actionpack/lib/action_dispatch/system_testing/driver.rb @@ -9,14 +9,14 @@ module ActionDispatch end def use - register unless rack_test? + register if registerable? setup end private - def rack_test? - @name == :rack_test + def registerable? + [:selenium, :poltergeist, :webkit].include?(@name) end def register diff --git a/actionpack/test/dispatch/system_testing/driver_test.rb b/actionpack/test/dispatch/system_testing/driver_test.rb index 4a1b971da5..34d27671bb 100644 --- a/actionpack/test/dispatch/system_testing/driver_test.rb +++ b/actionpack/test/dispatch/system_testing/driver_test.rb @@ -29,7 +29,7 @@ class DriverTest < ActiveSupport::TestCase assert_equal ({ skip_image_loading: true }), driver.instance_variable_get(:@options) end - test "rack_test? returns false if driver is poltergeist" do - assert_not ActionDispatch::SystemTesting::Driver.new(:poltergeist).send(:rack_test?) + test "registerable? returns false if driver is rack_test" do + assert_not ActionDispatch::SystemTesting::Driver.new(:rack_test).send(:registerable?) end end diff --git a/activemodel/CHANGELOG.md b/activemodel/CHANGELOG.md index 2916e5eabb..048c43f2c4 100644 --- a/activemodel/CHANGELOG.md +++ b/activemodel/CHANGELOG.md @@ -1,3 +1,7 @@ +* Add method `#merge!` for `ActiveModel::Errors`. + + *Jahfer Husain* + * Fix regression in numericality validator when comparing Decimal and Float input values with more scale than the schema. diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 942b4fa9bb..76c23df541 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -93,6 +93,18 @@ module ActiveModel @details = other.details.dup end + # Merges the errors from <tt>other</tt>. + # + # other - The ActiveModel::Errors instance. + # + # Examples + # + # person.errors.merge!(other) + def merge!(other) + @messages.merge!(other.messages) { |_, ary1, ary2| ary1 + ary2 } + @details.merge!(other.details) { |_, ary1, ary2| ary1 + ary2 } + end + # Clear the error messages. # # person.errors.full_messages # => ["name cannot be nil"] diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index 43aee5a814..7383b3e9b0 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -375,6 +375,18 @@ class ErrorsTest < ActiveModel::TestCase assert_equal [:name], person.errors.details.keys end + test "merge errors" do + errors = ActiveModel::Errors.new(Person.new) + errors.add(:name, :invalid) + + person = Person.new + person.errors.add(:name, :blank) + person.errors.merge!(errors) + + assert_equal({ name: ["can't be blank", "is invalid"] }, person.errors.messages) + assert_equal({ name: [{ error: :blank }, { error: :invalid }] }, person.errors.details) + end + test "errors are marshalable" do errors = ActiveModel::Errors.new(Person.new) errors.add(:name, :invalid) diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index c15b4a1a05..06976aa769 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -59,12 +59,12 @@ module ActiveRecord @statements = StatementPool.new(self.class.type_cast_config_to_integer(config[:statement_limit])) if version < "5.1.10" - raise "Your version of MySQL (#{full_version.match(/^\d+\.\d+\.\d+/)[0]}) is too old. Active Record supports MySQL >= 5.1.10." + raise "Your version of MySQL (#{version_string}) is too old. Active Record supports MySQL >= 5.1.10." end end def version #:nodoc: - @version ||= Version.new(full_version.match(/^\d+\.\d+\.\d+/)[0]) + @version ||= Version.new(version_string) end def mariadb? # :nodoc: @@ -854,6 +854,10 @@ module ActiveRecord end end + def version_string + full_version.match(/^(?:5\.5\.5-)?(\d+\.\d+\.\d+)/)[1] + end + class MysqlString < Type::String # :nodoc: def serialize(value) case value diff --git a/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb b/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb index eff96e329f..a46d9f8cbb 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb @@ -53,7 +53,7 @@ module ActiveRecord end def extract_expression_for_virtual_column(column) - if mariadb? + if mariadb? && version < "10.2.5" create_table_info = create_table_info(column.table_name) if %r/#{quote_column_name(column.name)} #{Regexp.quote(column.sql_type)}(?: COLLATE \w+)? AS \((?<expression>.+?)\) #{column.extra}/ =~ create_table_info $~[:expression].inspect diff --git a/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb index a01fbba201..24f8ff6367 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb @@ -73,8 +73,8 @@ module ActiveRecord def new_column_from_field(table_name, field) type_metadata = fetch_type_metadata(field[:Type], field[:Extra]) - if type_metadata.type == :datetime && field[:Default] == "CURRENT_TIMESTAMP" - default, default_function = nil, field[:Default] + if type_metadata.type == :datetime && /\ACURRENT_TIMESTAMP(?:\(\))?\z/i.match?(field[:Default]) + default, default_function = nil, "CURRENT_TIMESTAMP" else default, default_function = field[:Default], nil end diff --git a/activerecord/test/cases/adapters/mysql2/virtual_column_test.rb b/activerecord/test/cases/adapters/mysql2/virtual_column_test.rb index 442a4fb7b5..1c5ef2aa41 100644 --- a/activerecord/test/cases/adapters/mysql2/virtual_column_test.rb +++ b/activerecord/test/cases/adapters/mysql2/virtual_column_test.rb @@ -52,7 +52,7 @@ if ActiveRecord::Base.connection.supports_virtual_columns? def test_schema_dumping output = dump_table_schema("virtual_columns") - assert_match(/t\.virtual\s+"upper_name",\s+type: :string,\s+as: "UPPER\(`name`\)"$/i, output) + assert_match(/t\.virtual\s+"upper_name",\s+type: :string,\s+as: "(?:UPPER|UCASE)\(`name`\)"$/i, output) assert_match(/t\.virtual\s+"name_length",\s+type: :integer,\s+as: "LENGTH\(`name`\)",\s+stored: true$/i, output) end end diff --git a/guides/source/i18n.md b/guides/source/i18n.md index 6c8706bc13..aa2b7d1ba9 100644 --- a/guides/source/i18n.md +++ b/guides/source/i18n.md @@ -701,9 +701,11 @@ end ### Pluralization -In English there are only one singular and one plural form for a given string, e.g. "1 message" and "2 messages". Other languages ([Arabic](http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#ar), [Japanese](http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#ja), [Russian](http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#ru) and many more) have different grammars that have additional or fewer [plural forms](http://cldr.unicode.org/index/cldr-spec/plural-rules). Thus, the I18n API provides a flexible pluralization feature. +In many languages — including English — there are only two forms, a singular and a plural, for +a given string, e.g. "1 message" and "2 messages". Other languages ([Arabic](http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#ar), [Japanese](http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#ja), [Russian](http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#ru) and many more) have different grammars that have additional or fewer [plural forms](http://cldr.unicode.org/index/cldr-spec/plural-rules). Thus, the I18n API provides a flexible pluralization feature. -The `:count` interpolation variable has a special role in that it both is interpolated to the translation and used to pick a pluralization from the translations according to the pluralization rules defined by CLDR: +The `:count` interpolation variable has a special role in that it both is interpolated to the translation and used to pick a pluralization from the translations according to the pluralization rules defined in the +pluralization backend. By default, only the English pluralization rules are applied. ```ruby I18n.backend.store_translations :en, inbox: { @@ -733,6 +735,22 @@ The translation denoted as `:one` is regarded as singular, and the `:other` is u If the lookup for the key does not return a Hash suitable for pluralization, an `I18n::InvalidPluralizationData` exception is raised. +#### Locale-specific rules + +The I18n gem provides a Pluralization backend that can be used to enable locale-specific rules. Include it +to the Simple backend, then add the localized pluralization algorithms to translation store, as `i18n.plural.rule`. + +```ruby +I18n::Backend::Simple.include(I18n::Backend::Pluralization) +I18n.backend.store_translations :pt, i18n: { plural: { rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } +I18n.backend.store_translations :pt, apples: { one: 'one or none', other: 'more than one' } + +I18n.t :apples, count: 0, locale: :pt +# => 'one or none' +``` + +Alternatively, the separate gem [rails-i18n](https://github.com/svenfuchs/rails-i18n) can be used to provide a fuller set of locale-specific pluralization rules. + ### Setting and Passing a Locale The locale can be either set pseudo-globally to `I18n.locale` (which uses `Thread.current` like, e.g., `Time.zone`) or can be passed as an option to `#translate` and `#localize`. diff --git a/railties/lib/rails/secrets.rb b/railties/lib/rails/secrets.rb index c7a8676d7b..955ab096e8 100644 --- a/railties/lib/rails/secrets.rb +++ b/railties/lib/rails/secrets.rb @@ -105,7 +105,9 @@ module Rails yield tmp_path - write(File.read(tmp_path)) + updated_contents = File.read(tmp_path) + + write(updated_contents) if updated_contents != contents ensure FileUtils.rm(tmp_path) if File.exist?(tmp_path) end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 9364f11a98..059c2692be 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -8,32 +8,70 @@ DEFAULT_APP_FILES = %w( Gemfile Rakefile config.ru + app/assets/config/manifest.js + app/assets/images app/assets/javascripts + app/assets/javascripts/application.js + app/assets/javascripts/cable.js + app/assets/javascripts/channels app/assets/stylesheets - app/assets/images + app/assets/stylesheets/application.css + app/channels/application_cable/channel.rb + app/channels/application_cable/connection.rb app/controllers + app/controllers/application_controller.rb app/controllers/concerns app/helpers + app/helpers/application_helper.rb app/mailers + app/mailers/application_mailer.rb app/models + app/models/application_record.rb app/models/concerns app/jobs + app/jobs/application_job.rb app/views/layouts + app/views/layouts/application.html.erb + app/views/layouts/mailer.html.erb + app/views/layouts/mailer.text.erb bin/bundle bin/rails bin/rake bin/setup + bin/update + bin/yarn + config/application.rb + config/boot.rb + config/cable.yml + config/environment.rb config/environments + config/environments/development.rb + config/environments/production.rb + config/environments/test.rb config/initializers + config/initializers/application_controller_renderer.rb + config/initializers/assets.rb + config/initializers/backtrace_silencers.rb + config/initializers/cookies_serializer.rb + config/initializers/filter_parameter_logging.rb + config/initializers/inflections.rb + config/initializers/mime_types.rb + config/initializers/wrap_parameters.rb config/locales - config/cable.yml + config/locales/en.yml config/puma.rb + config/routes.rb + config/secrets.yml config/spring.rb db + db/seeds.rb lib lib/tasks lib/assets log + package.json + public + test/application_system_test_case.rb test/test_helper.rb test/fixtures test/fixtures/files diff --git a/railties/test/secrets_test.rb b/railties/test/secrets_test.rb index 36c8ef1fd9..321b654ae3 100644 --- a/railties/test/secrets_test.rb +++ b/railties/test/secrets_test.rb @@ -111,6 +111,24 @@ class Rails::SecretsTest < ActiveSupport::TestCase end end + test "do not update secrets.yml.enc when secretes do not change" do + run_secrets_generator do + Dir.chdir(app_path) do + Rails::Secrets.read_for_editing do |tmp_path| + File.write(tmp_path, "Empty streets, empty nights. The Downtown Lights.") + end + + FileUtils.cp("config/secrets.yml.enc", "config/secrets.yml.enc.bk") + + Rails::Secrets.read_for_editing do |tmp_path| + File.write(tmp_path, "Empty streets, empty nights. The Downtown Lights.") + end + + assert_equal File.read("config/secrets.yml.enc.bk"), File.read("config/secrets.yml.enc") + end + end + end + private def run_secrets_generator Dir.chdir(app_path) do |