Commit Graph

672 Commits

Author SHA1 Message Date
Rafael França
8fd69db783 Merge pull request #29788 from kamipo/remove_unused_mutex_m
Remove unused `Mutex_m` in Active Model
2017-07-17 13:54:37 -04:00
Kir Shatrov
d7b1521db8 Use frozen string literal in activemodel/ 2017-07-16 20:11:16 +03:00
Ryuta Kamizono
12e6cba9cf Make generated_attribute_methods to private
Because `generated_attribute_methods` is an internal API.
2017-07-14 13:26:45 +09:00
Jahfer Husain
3650ca983c Add ActiveModel::Errors#merge!
ActiveModel::Errors#merge! allows ActiveModel::Errors to append errors from
a separate ActiveModel::Errors instance onto their own.

Example:

    person = Person.new
    person.errors.add(:name, :blank)

    errors = ActiveModel::Errors.new(Person.new)
    errors.add(:name, :invalid)

    person.errors.merge!(errors)
    puts person.errors.messages
    # => { name: ["can't be blank", "is invalid"] }
2017-07-07 14:32:59 -04:00
Matthew Draper
87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing
changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
2017-07-02 02:15:17 +09:30
Matthew Draper
3420a14590 Merge pull request #29540 from kirs/rubocop-frozen-string
Enforce frozen string in Rubocop
2017-07-02 01:11:50 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Pat Allan
4ff30d9bb6 Make ActiveModel frozen string literal friendly.
Includes two external changes because they're referenced within the ActiveModel test suite.
2017-06-20 18:35:44 +10:00
Ryuta Kamizono
0d17168289 Replace \Z to \z
\Z was a mistake of \z. Replace \Z to \z to prevent newly \Z added.
2017-04-24 21:22:12 +09:00
Ryuta Kamizono
faca40dfd4 ✂️
[ci skip]
2017-04-13 07:15:04 +09:00
Matthew Draper
8de7df5b22 Don't freeze input strings
See 34321e4a433bb7eef48fd743286601403f8f7d82 for background on
ImmutableString vs String.

Our String type cannot delegate typecasting to ImmutableString, because
the latter freezes its input: duplicating the value after that gives us
an unfrozen result, but still mutates the originally passed object.
2017-04-12 03:14:09 +09:30
bogdanvlviv
01269aede3 Fix ActiveModel::Errors #keys, #values
Before:
  person.errors.keys    # => []
  person.errors.values  # => []
  person.errors[:name]  # => []
  person.errors.keys    # => [:name]
  person.errors.values  # => [[]]

After:
  person.errors.keys   # => []
  person.errors.values # => []
  person.errors[:name] # => []
  person.errors.keys   # => []
  person.errors.values # => []

Related to #23468
2017-03-28 18:48:56 +03:00
Rafael Mendonça França
9426bd7a19
Merge pull request #28050 from namusyaka/avoid-converting-int-into-float
Avoid converting integer as a string into float
2017-03-27 18:23:56 -04:00
John Hawthorn
68926798a5
Fix invalid string Decimal casting under ruby 2.4
In Ruby 2.4, BigDecimal(), as used by the Decimal cast, was changed so
that it will raise ArgumentError when passed an invalid string, in order
to be more consistent with Integer(), Float(), etc. The other numeric
types use ex. to_i and to_f.

Unfortunately, we can't simply change BigDecimal() to to_d. String#to_d
raises errors like BigDecimal(), unlike all the other to_* methods (this
should probably be filed as a ruby bug).

Instead, this simulates the existing behaviour and the behaviour of the
other to_* methods by finding a numeric string at the start of the
passed in value, and parsing that using BigDecimal().

See also
https://bugs.ruby-lang.org/issues/10286
3081a627ce
2017-02-24 19:41:23 -05:00
namusyaka
b0be7792ad
Avoid converting integer as a string into float 2017-02-18 19:04:48 +09:00
Rafael Mendonça França
3a25cdca3e
Remove deprecated behavior that halts callbacks when the return is false 2017-02-07 12:19:37 -03:00
Rafael França
d7bbe075f9 Merge pull request #27608 from kamipo/remove_deprecated_passing_string_to_define_callback
Remove deprecated passing string to define callback
2017-02-07 10:33:28 -03:00
yuuji.yaginuma
4f8d86c822 Remove ActiveModel::TestCase from lib
`ActiveModel::TestCase` is used only for the test of Active Model.
Also, it is a private API and can not be used in applications.
Therefore, it is not necessary to include it in lib.
2017-02-07 07:46:52 +09:00
Ryuta Kamizono
09525527a5 Deprecate passing string to :if and :unless conditional options on set_callback and skip_callback 2017-02-04 20:48:29 +09:00
Ryuta Kamizono
f8d3fed167 Remove deprecated passing string to define callback
And raise `ArgumentError` when passing string to define callback.
2017-02-04 20:48:29 +09:00
Akira Matsuda
146e928800 Don't pollute Object with rubinius_skip and jruby_skip
we call them only in the tests
2017-01-17 18:51:50 +09:00
Akira Matsuda
50dabf9198 Missing require for strip_heredoc 2017-01-17 03:47:31 +09:00
Akira Matsuda
e8ba0c0f21 "Use assert_nil if expecting nil. This will fail in minitest 6." 2016-12-25 02:29:52 +09:00
Akira Matsuda
21e5fd4a2a Describe what we are protecting 2016-12-23 23:48:54 +09:00
Akira Matsuda
414484f68d Missing require "yaml" 2016-12-12 22:32:04 +09:00
Rafael Mendonça França
0951306ca5
Make ActiveModel::Errors backward compatible with 4.2
If a Error object was serialized in the database as YAML in the Rails
4.2 version, if we load in the Rails 5.0 version it will miss the
@details instance variable so methods like #clear and #add will start to
fail.
2016-12-08 16:27:47 -05:00
Sean Griffin
ef76f83f4c Merge pull request #26696 from iainbeeston/only-ruby-types-in-activemodel
Moved database-specific ActiveModel types into ActiveRecord
2016-12-08 13:45:47 -05:00
Kenichi Kamiya
9f566aba32 Allow indifferent access in ActiveModel::Errors
`#[]` has already applied indifferent access, but some methods does not.

  `#include?`, `#has_key?`, `#key?`, `#delete` and `#full_messages_for`.
2016-11-22 04:10:41 +09:00
Kir Shatrov
5abf662959 Do not rely on Ruby implementation in AM test
Now a few tests in ActiveModel rely on Ruby implementation and the fact
that in MRI `97.18` as a float is greater than `97.18` as a BigDecimal.

This is only relevant for MRI. On JRuby, comparing float to BigDecimal
would be conversion of them to the same type and they will be equal.

I'd like the ActiveModel test suite to be Ruby implementation-agnostic.
Here we test ActiveModel, not the Ruby internals.
This PR fixes a couple more JRuby tests.
2016-11-19 21:02:29 -05:00
Andrew White
7305ac20b4 Merge pull request #26935 from y-yagi/fix_ruby_warning
remove warning from big integer test
2016-10-31 07:01:55 +00:00
yuuji.yaginuma
c33c03e80c remove warning from big integer test
This removes the following warnings.

```
activemodel/test/cases/type/big_integer_test.rb:15: warning: ambiguous first argument; put parentheses or a space even after `-' operator
```
2016-10-31 09:10:51 +09:00
Rafael Mendonça França
fe1f4b2ad5
Add more rubocop rules about whitespaces 2016-10-29 01:17:49 -02:00
Xavier Noria
56832e791f let Regexp#match? be globally available
Regexp#match? should be considered to be part of the Ruby core library. We are
emulating it for < 2.4, but not having to require the extension is part of the
illusion of the emulation.
2016-10-27 09:13:55 +02:00
Iain Beeston
894c033843 Refactored ActiveModel::Type tests into their own files 2016-10-15 07:33:22 +01:00
Iain Beeston
994ce87bbd Moved database-specific ActiveModel types into ActiveRecord
ie. DecimalWithoutScale, Text and UnsignedInteger
2016-10-14 20:21:20 +01:00
Rafael Mendonça França
6a78e0ecd6
Removed deprecated :tokenizer in the length validator 2016-10-10 20:29:24 -03:00
Rafael Mendonça França
9de6457ab0
Removed deprecated methods in ActiveModel::Errors
`#get`, `#set`, `[]=`, `add_on_empty` and `add_on_blank`.
2016-10-10 20:22:15 -03:00
Jean Boussier
33fd23e077 Do not leak the Errors default proc when calling to_hash or as_json 2016-09-27 14:33:16 +02:00
Michael Grosser
a9aed2ac94
improve error message when include assertions fail
assert [1, 3].includes?(2) fails with unhelpful "Asserting failed" message

assert_includes [1, 3], 2 fails with "Expected [1, 3] to include 2" which makes it easier to debug and more obvious what went wrong
2016-09-16 12:03:37 -07:00
Ryuta Kamizono
3464cd5c28 Fix broken comments indentation caused by rubocop auto-correct [ci skip]
All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772.
But comments was still kept absolute position. This commit aligns
comments with method definitions for consistency.
2016-09-14 18:26:32 +09:00
Nicolai Reuschling
43f1b23a75 Add test for allow_blank in numericality validation
Signed-off-by: Guillermo Iguaran <guilleiguaran@gmail.com>
2016-08-28 00:29:40 -05:00
Rafael Mendonça França
55f9b8129a
Add three new rubocop rules
Style/SpaceBeforeBlockBraces
Style/SpaceInsideBlockBraces
Style/SpaceInsideHashLiteralBraces

Fix all violations in the repository.
2016-08-16 04:30:11 -03:00
Ryuta Kamizono
f006de5dc5 Fix broken alignments caused by auto-correct commit 411ccbd
Hash syntax auto-correcting breaks alignments. 411ccbdab2608c62aabdb320d52cb02d446bb39c
2016-08-10 06:36:39 +09:00
Xavier Noria
a9dc45459a code gardening: removes redundant selfs
A few have been left for aesthetic reasons, but have made a pass
and removed most of them.

Note that if the method `foo` returns an array, `foo << 1`
is a regular push, nothing to do with assignments, so
no self required.
2016-08-08 01:12:38 +02:00
Ryuta Kamizono
762e3f05f3 Add Style/EmptyLines in .rubocop.yml and remove extra empty lines 2016-08-07 17:50:59 +09:00
Xavier Noria
b326e82dc0 applies remaining conventions across the project 2016-08-06 20:20:22 +02:00
Xavier Noria
80e66cc4d9 normalizes indentation and whitespace across the project 2016-08-06 20:16:27 +02:00
Xavier Noria
411ccbdab2 remove redundant curlies from hash arguments 2016-08-06 19:44:11 +02:00
Xavier Noria
fa911a74e1 modernizes hash syntax in activemodel 2016-08-06 19:37:12 +02:00
Xavier Noria
4c20825457 applies new string literal convention in activemodel/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 18:38:23 +02:00