aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
Commit message (Collapse)AuthorAgeFilesLines
* Revert "Revert "Merge pull request #34387 from ↵Kasper Timm Hansen2019-01-081-0/+3
| | | | | | | | yhirano55/rails_info_properties_json"" I reverted the wrong commit. Damn it. This reverts commit f66a977fc7ae30d2a07124ad91924c4ee638a703.
* Revert "Merge pull request #34387 from yhirano55/rails_info_properties_json"Kasper Timm Hansen2019-01-081-3/+0
| | | | | | | | | | | We had a discussion on the Core team and we don't want to expose this information as a JSON endpoint and not by default. It doesn't make sense to expose this JSON locally and this controller is only accessible in dev, so the proposed access from a production app seems off. This reverts commit 8eaffe7e89719ac62ff29c2e4208cfbeb1cd1c38, reversing changes made to b6e4305c3bca4c673996d0af9db0f4cfbf50215e.
* Add `ActiveModel::Errors#of_kind?`bogdanvlviv2019-01-043-10/+113
| | | | Related to https://github.com/rails/rails/pull/34817#issuecomment-451508668
* Bump license years for 2019Arun Agrawal2018-12-312-2/+2
|
* Enable `Style/RedundantBegin` cop to avoid newly adding redundant begin blockRyuta Kamizono2018-12-214-106/+84
| | | | | | | | | | Currently we sometimes find a redundant begin block in code review (e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205). I'd like to enable `Style/RedundantBegin` cop to avoid that, since rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5 (https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with that situation than before.
* Module#{attr,attr_accessor,attr_reader,attr_writer} become public since Ruby 2.5Ryuta Kamizono2018-12-213-5/+5
| | | | https://bugs.ruby-lang.org/issues/14132
* Module#{define_method,alias_method,undef_method,remove_method} become public ↵Ryuta Kamizono2018-12-213-8/+8
| | | | | | since Ruby 2.5 https://bugs.ruby-lang.org/issues/14133
* Use native `Array#append`, `Array#prepend`, `Hash#transform_keys`, and ↵Ryuta Kamizono2018-12-201-2/+0
| | | | | | | | | | `Hash#transform_keys!` Since Rails 6 requires Ruby 2.5. https://github.com/ruby/ruby/blob/ruby_2_5/NEWS Follow up #34754.
* Merge pull request #30973 from k0kubun/prefer-block-parameterRyuta Kamizono2018-12-201-10/+2
|\ | | | | Unify _read_attribute definition to use &block
| * Unify _read_attribute definition to use &blockTakashi Kokubun2018-12-201-10/+2
| | | | | | | | | | | | | | | | Thanks to ko1, passing block parameter to another method is significantly optimized in Ruby 2.5. https://bugs.ruby-lang.org/issues/14045 Thus we no longer need to keep this ugly hack.
* | Require Ruby 2.5 for Rails 6.Kasper Timm Hansen2018-12-192-3/+3
| | | | | | | | | | | | | | | | | | | | Generally followed the pattern for https://github.com/rails/rails/pull/32034 * Removes needless CI configs for 2.4 * Targets 2.5 in rubocop * Updates existing CHANGELOG entries for fewer merge conflicts * Removes Hash#slice extension as that's inlined on Ruby 2.5. * Removes the need for send on define_method in MethodCallAssertions.
* | Prevent infinit method_missing loop on attribute methodsRyuta Kamizono2018-12-151-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | If a klass has acceptance validation and then `klass.undefine_attribute_methods` is happened before an attribute method is called, infinit loop is caused on the `method_missing` defined by the `LazilyDefineAttributes`. https://travis-ci.org/rails/rails/jobs/467053984#L1409 To prevent the infinit loop, the `method_missing` should ensure `klass.define_attribute_methods`.
* | Merge pull request #34693 from ahorek/matchRyuta Kamizono2018-12-131-3/+3
|\ \ | | | | | | | | | [perf] use #match?
| * | use match?pavel2018-12-121-3/+3
|/ /
* | Fix numericality equality validation on floatsGannon McGibbon2018-12-123-10/+34
| |
* | Do not use deprecated Object#!~ in Ruby 2.6Rafael Mendonça França2018-11-261-1/+5
| | | | | | | | Closes #34530.
* | Add slice! method to ActiveModel::ErrorsDaniel Lopez Prat2018-11-213-0/+39
| |
* | Re-add changes_applied docGannon McGibbon2018-11-161-1/+3
| | | | | | | | [ci skip]
* | Merge pull request #34417 from r3trofitted/fix/added_options_checkRafael França2018-11-132-3/+13
|\ \ | | | | | | Fix ignored options in the `#added?` method
| * | Fix ignored options in the `#added?` methodRonan Limon Duparcmeur2018-11-132-3/+13
| | | | | | | | | | | | Fixes #34416
* | | Ensure casting by decimal attribute when queryingRyuta Kamizono2018-11-121-0/+4
|/ / | | | | | | | | | | | | | | | | | | Related 34cc301f03aea2e579d6687a9ea9782afc1089a0. `QueryAttribute#value_for_database` calls only `type.serialize`, and `Decimal#serialize` is a no-op unlike other attribute types. Whether or not `serialize` will invoke `cast` is undefined in our test cases, but it actually does not work properly unless it does so for now.
* | Amend CVE note and security guide section wordingsGannon McGibbon2018-11-061-3/+3
| | | | | | | | | | | | | | Reword first sentence of dep management and CVE section of security guide. Also, reword and move gemspec notes above deps. [ci skip]
* | Add CVE note to security guide and gemspecsGannon McGibbon2018-11-061-0/+3
| | | | | | | | [ci skip]
* | `update_columns` raises if the column is unknownSean Griffin2018-10-301-0/+1
| | | | | | | | | | | | | | | | | | Previosly, `update_columns` would just take whatever keys you gave it and tried to run the update query. Most likely this would result in an error from the database. However, if the column actually did exist, but was in `ignored_columns`, this would result in the method returning successfully when it should have raised, and an attribute that should not exist written to `@attributes`.
* | Fix grammar in changed? docs [ci skip]Alberto Almagro2018-10-281-1/+1
| | | | | | | | See https://english.stackexchange.com/questions/23218/anyone-has-or-anyone-have-seen-them
* | Add new exception message to datetime from hash castwilddima2018-10-212-3/+14
| |
* | Improve model attribute accessor method names for backtracesDylan Thacker-Smith2018-10-122-22/+48
| | | | | | | | | | | | | | | | Ruby uses the original method name, so will show the __temp__ method name in the backtrace. However, in the common case the method name is compatible with the `def` keyword, so we can avoid the __temp__ method name in that case to improve the name shown in backtraces or TracePoint#method_id.
* | Fix call sitesGannon McGibbon2018-10-021-1/+1
| |
* | Fix spellings for 'unmarshall(ing/ed)' & 'marshall(ing/ed)'Sharang Dashputre2018-10-021-1/+1
| |
* | Add `Style/RedundantFreeze` to remove redudant `.freeze`Yasuo Honda2018-09-297-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since Rails 6.0 will support Ruby 2.4.1 or higher `# frozen_string_literal: true` magic comment is enough to make string object frozen. This magic comment is enabled by `Style/FrozenStringLiteralComment` cop. * Exclude these files not to auto correct false positive `Regexp#freeze` - 'actionpack/lib/action_dispatch/journey/router/utils.rb' - 'activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb' It has been fixed by https://github.com/rubocop-hq/rubocop/pull/6333 Once the newer version of RuboCop released and available at Code Climate these exclude entries should be removed. * Replace `String#freeze` with `String#-@` manually if explicit frozen string objects are required - 'actionpack/test/controller/test_case_test.rb' - 'activemodel/test/cases/type/string_test.rb' - 'activesupport/lib/active_support/core_ext/string/strip.rb' - 'activesupport/test/core_ext/string_ext_test.rb' - 'railties/test/generators/actions_test.rb'
* | Merge pull request #30676 from artofhuman/import-assert-attrs-error-messageRafael França2018-09-262-2/+4
|\ \ | | | | | | Improve error message when assign wrong attributes to model
| * | Improve error message when assign wrong attributes to modelSemyon Pupkov2018-04-282-2/+4
| | |
* | | Change the empty block style to have space inside of the blockRafael Mendonça França2018-09-251-1/+1
| | |
* | | Merge pull request #33949 from sjain1107/no-private-defKasper Timm Hansen2018-09-231-8/+10
|\ \ \ | | | | | | | | Remove private def
| * | | Remove private defSakshi Jain2018-09-231-8/+10
| | | |
* | | | Enable `Performance/UnfreezeString` copyuuji.yaginuma2018-09-233-4/+4
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`. ```ruby # frozen_string_literal: true require "bundler/inline" gemfile(true) do source "https://rubygems.org" gem "benchmark-ips" end Benchmark.ips do |x| x.report('+@') { +"" } x.report('dup') { "".dup } x.compare! end ``` ``` $ ruby -v benchmark.rb ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] Warming up -------------------------------------- +@ 282.289k i/100ms dup 187.638k i/100ms Calculating ------------------------------------- +@ 6.775M (± 3.6%) i/s - 33.875M in 5.006253s dup 3.320M (± 2.2%) i/s - 16.700M in 5.032125s Comparison: +@: 6775299.3 i/s dup: 3320400.7 i/s - 2.04x slower ```
* | | Merge pull request #33804 from yskkin/num_stringRyuta Kamizono2018-09-084-4/+14
|\ \ \ | | | | | | | | Fix non_numeric_string?
| * | | Fix non_numeric_string?Yoshiyuki Kinjo2018-09-074-4/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For example, dirty checking was not right for the following case: ``` model.int_column = "+5" model.float_column = "0.5E+1" model.decimal_column = "0.5e-3" ``` It is enough to see whether leading character is a digit for avoiding invalid numeric expression like 'wibble' to be type-casted to 0, as this method's comment says. Fixes #33801
* | | | Merge pull request #33615 from ↵Rafael França2018-09-072-3/+63
|\ \ \ \ | | | | | | | | | | | | | | | | | | | | Larochelle/i18n_full_message_with_nested_attributes `ActiveModel.full_message` interaction with `index_errors`
| * | | | Call human_attribute_name with a string instead of a symboleMartin Larochelle2018-08-162-2/+2
| | | | |
| * | | | `ActiveModel.full_message` interaction with `index_errors`Martin Larochelle2018-08-142-3/+63
| | | | |
* | | | | Formatting CHANGELOGs [ci skip]Ryuta Kamizono2018-09-071-12/+13
| |/ / / |/| | | | | | | | | | | Fixing code block rendering, indentation, backticks, etc.
* | | | Faster time_value.rbschneems2018-08-291-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The multiplication of the value takes a long time when we can instead mutate and use the string value directly. The `microsec` perf increases speed by 27% in the ideal case (which is the most common). ``` original_string = ".443959" require 'benchmark/ips' Benchmark.ips do |x| x.report("multiply") { string = original_string.dup (string.to_r * 1_000_000).to_i } x.report("new ") { string = original_string.dup if string && string.start_with?(".".freeze) && string.length == 7 string[0] = ''.freeze string.to_i end } x.compare! end # Warming up -------------------------------------- # multiply 125.783k i/100ms # new 146.543k i/100ms # Calculating ------------------------------------- # multiply 1.751M (± 3.3%) i/s - 8.805M in 5.033779s # new 2.225M (± 2.1%) i/s - 11.137M in 5.007110s # Comparison: # new : 2225289.7 i/s # multiply: 1751254.2 i/s - 1.27x slower ```
* | | | Fix numericality validator to still use value before type cast except Active ↵Ryuta Kamizono2018-08-244-4/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Record The purpose of fe9547b is to work type casting to value from database. But that was caused not to use the value before type cast even except Active Record. There we never guarantees that the value before type cast was going to the used in this validation, but we should not change the behavior unless there is some particular reason. To restore original behavior, still use the value before type cast if `came_from_user?` is undefined (i.e. except Active Record). Fixes #33651. Fixes #33686.
* | | | Fix numericality validator not to be affected by custom getterRyuta Kamizono2018-08-131-0/+2
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since fe9547b6, numericality validator would parse raw value only when a value came from user to work type casting to a value from database. But that was caused a regression that the validator would work against getter value instead of parsed raw value, a getter is sometimes customized by people. #33550 There we never guarantees that the value before type cast was going to the used in this validation (actually here is only place that getter value might not be used), but we should not change the behavior unless there is some particular reason. The purpose of fe9547b6 is to work type casting to a value from database. We could achieve the purpose by using `read_attribute`, without using getter value. Fixes #33550.
* | | Add changelog entry for #31503 [ci skip]bogdanvlviv2018-08-121-0/+16
| | | | | | | | | | | | Related to #31503
* | | Fix test failurebogdanvlviv2018-08-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ``` ... (snip) ............F Failure: JsonSerializationTest#test_as_json_should_return_a_hash_if_include_root_ in_json_is_true [/home/travis/build/rails/rails/activemodel/test/cases/serializers/json_serialization_test.rb:145]: Expected: 2006-08-01 00:00:00 UTC Actual: "2006-08-01T00:00:00.000Z" rails test home/travis/build/rails/rails/activemodel/test/cases/serializers/json_serialization_test.rb:136 (snip) ... ``` Related to #31503
* | | Merge pull request #31503 from bogdan/timestamp-as-jsonEileen M. Uchitelle2018-08-112-9/+14
|\ \ \ | | | | | | | | Fix AM::Serializers::JSON#as_json method for timestamps
| * | | Fix AM::Serializers::JSON#as_json method for timestampsBogdan Gusiev2017-12-212-9/+14
| | | | | | | | | | | | | | | | | | | | According to doc the method should return non-json compatible types as strings.
* | | | ActiveModel::Naming delegate match? in the same manner as =~ and != (#33466)Bart2018-07-291-1/+17
| | | | | | | | | | | | The purpose of the module seems to quack like a string.