Commit Graph

544 Commits

Author SHA1 Message Date
Wojciech Wnętrzak
cb74473db6 Add ActiveModel::Errors#details
To be able to return type of validator, one can now call `details`
on Errors instance:

```ruby
class User < ActiveRecord::Base
  validates :name, presence: true
end
```

```ruby
user = User.new; user.valid?; user.errors.details
=> {name: [{error: :blank}]}
```
2015-01-20 22:33:42 +01:00
Sean Griffin
72570ea289 Merge pull request #18439 from mokhan/validates-acceptance-of-array
allow '1' or true for acceptance validation.
2015-01-12 12:06:00 -07:00
Carlos Antonio da Silva
8ee052cf84 Merge pull request #18454 from claudiob/test-on-option-for-amv-callbacks
Add test for AM::Validation::Callbacks with :on
2015-01-11 19:13:34 -02:00
claudiob
d3927c8d18 Remove unused "deprecated_reload" method
The method was introduced in 66d0a01535 (diff-8cec05860729a3851ceb756f4dd90370R49)
for the "reset_changes is deprecated" test, but this test was successively
removed in 37175a24bd
2015-01-11 12:32:26 -08:00
claudiob
684cbee473 Add test for AM::Validation::Callbacks with :on
`before_validation` and `after_validation` from
ActiveModel::Validation::Callbacks accept an optional `:on` parameter
that was not previously documented or tested. For instance given

    before_validation :do_something, on: :create

then `object.valid?(:create)` will invoke `:do_something` while
`object.valid?` or `object.valid?(:anything_else)` will not.
2015-01-11 12:29:39 -08:00
mo khan
140557e85f allow '1' or true for acceptance validation. 2015-01-10 22:47:47 -07:00
Rafael Mendonça França
37175a24bd Remove deprecated ActiveModel::Dirty#reset_#{attribute} and ActiveModel::Dirty#reset_changes. 2015-01-04 11:58:42 -03:00
claudiob
91b8129320 Deprecate false as the way to halt AM callbacks
Before this commit, returning `false` in an ActiveModel `before_` callback
such as `before_create` would halt the callback chain.

After this commit, the behavior is deprecated: will still work until
the next release of Rails but will also display a deprecation warning.

The preferred way to halt a callback chain is to explicitly `throw(:abort)`.
2015-01-02 15:31:56 -08:00
claudiob
f767981286 Deprecate false as the way to halt AM validation callbacks
Before this commit, returning `false` in an ActiveModel validation
callback such as `before_validation` would halt the callback chain.

After this commit, the behavior is deprecated: will still work until
the next release of Rails but will also display a deprecation warning.

The preferred way to halt a callback chain is to explicitly `throw(:abort)`.
2015-01-02 15:31:56 -08:00
Vipul A M
732bba8d4c - Fixed unused variable
- Changed test to verify complete message instead of verifying if message contains text.
2014-12-21 13:28:20 +05:30
claudiob
b7bd7ffa63 Add AM test: after/around callback returning false
This stems from https://github.com/rails/rails/pull/17227#discussion_r21641358

It's simply a clarification of the current behavior by which if an
`after_` or `around_` ActiveModel callback returns +false+, then the callback
chain **is not halted**.

The callback chain in ActiveModel is only halted when a `before_`
callback returns `false`.
2014-12-14 21:20:49 -08:00
claudiob
9a6f20e8f0 Add AM test for after_validation returning false
This stems from https://github.com/rails/rails/pull/17227#discussion_r21641358

It's simply a clarification of the current behavior by which if an
`after_validation` ActiveModel callback returns +false+, then further
`after_` callbacks **are not halted**.
2014-12-14 21:18:31 -08:00
Godfrey Chan
4a19b3dea6 Pass through the prepend option to AS::Callback
I'm not sure what's the use case for this, but apparently it broke some apps.
Since it was not the intended result from #16210 I fixed it to not raise an
exception anymore. However, I didn't add documentation for it because I don't
know if this should be officially supported without knowing how it's meant to
be used.

In general, validations should be side-effect-free (other than adding to the
error message to `@errors`). Order-dependent validations seems like a bad idea.

Fixes #18002
2014-12-12 14:51:02 -08:00
Erik Michaels-Ober
d1374f99bf Pass symbol as an argument instead of a block 2014-11-29 11:53:24 +01:00
Adam89
52720b46ea Remove redundant require of file
This file was required inside 'test/validators/namespace/email_validator.rb'
that's already required here. Therefore I removed the redundant required.
2014-11-01 19:00:12 +00:00
Garry Shutler
6c8cf21584 Add #key? to ActiveModel::Errors
Mirror Ruby's Hash#key?
2014-10-14 09:53:26 +01:00
Prathamesh Sonpatki
a7ed62987c Added test for exception message for validate method
- Test case for https://github.com/rails/rails/pull/16851
2014-09-23 14:36:15 +09:00
Godfrey Chan
2b41343c34 Default to sorting user's test cases for now
Goals:

1. Default to :random for newly generated applications
2. Default to :sorted for existing applications with a warning
3. Only show the warning once
4. Only show the warning if the app actually uses AS::TestCase

Fixes #16769
2014-09-08 05:32:16 -07:00
Matthew Draper
2f52f96988 Leave all our tests as order_dependent! for now
We're seeing too many failures to believe otherwise.

This reverts commits bc116a55ca3dd9f63a1f1ca7ade3623885adcc57,
cbde413df3839e06dd14e3c220e9800af91e83ab,
bf0a67931dd8e58f6f878b9510ae818ae1f29a3a, and
2440933fe2c27b27bcafcd9019717800db2641aa.
2014-09-02 23:55:34 +09:30
Akira Matsuda
b23365fe5c Move model definition to test/models for test order indenendency 2014-08-28 16:56:53 +09:00
ankit1910
5284f98d79 [ci skip] make assert messages consistent 2014-08-25 22:07:27 +05:30
Akira Matsuda
bc116a55ca AM, AP, AV, and AMo tests are already order_independent! 2014-08-13 21:25:10 +09:00
Rafael Mendonça França
e81f3c210e Nobody sucks so nobody should call this awful method name 2014-08-12 10:51:41 -03:00
Akira Matsuda
6ffb29d24e users_dont_suck_but_only_we_suck_and_only_our_tests_are_order_dependent!
Calling ActiveSupport::TestCase.i_suck_and_my_tests_are_order_dependent! in AS::TestCase makes
everyone's tests order dependent, which should never be done by the framework.
2014-08-12 19:37:04 +09:00
Yevhene Shemet
f8dcb365df Allow password to contain spaces only. 2014-08-06 22:11:06 +03:00
Rafael Mendonça França
74c31ac5fe Merge pull request #15959 from aditya-kapoor/remove-unneeded-cases
remove unneeded test model for ActiveModel test cases.
2014-07-29 18:08:07 -03:00
Rafael Mendonça França
08754f12e6 Merge branch 'rm-remove-mocha'
Conflicts:
	actionpack/test/abstract_unit.rb
2014-07-19 18:17:13 -03:00
Rafael Mendonça França
fd6aaaa0c3 Stop requiring mocha automatically
We are planning to remove mocha from our test suite because of
performance problems. To make this possible we should stop require mocha
on ActionSupport::TestCase.

This should not affect applications since users still need to add mocha
to Gemfile and this already load mocha.

Added FIXME notes to place that still need mocha removal
2014-07-19 17:35:12 -03:00
Matthew Draper
e213b37fc1 Merge pull request #16210 from sonnym/assert_valid_keys_in_validate
Check for valid options in validate method
2014-07-18 07:10:49 +09:30
sonnym
0950d409b0 check for valid options in validate method
This change prevents a certain class of user error which results when
mistakenly using the `validate` class method instead of the `validates`
class method.

Only apply when all arguments are symbols, because some validations use
the `validate` method and pass in additional options, namely the
`LenghValidator` via the `ActiveMode::Validations::validates_with`
method.
2014-07-17 17:32:28 -04:00
Rafael Mendonça França
1a300b6748 Make restore_attributes public
Also make it accept a list of attributes to be changed. This will make
possible to restore only a subset of the changed attributes.

Closes #16203
2014-07-17 14:55:28 -03:00
Rafael Mendonça França
41fb06fa47 Deprecate reset_#{attribute} in favor of restore_#{attribute}.
These methods may cause confusion with the `reset_changes` that
behaves differently
of them.

Also rename undo_changes to restore_changes to match this new set of
methods.
2014-07-15 18:09:38 -03:00
Rafael Mendonça França
66d0a01535 Deprecate ActiveModel::Dirty#reset_changes in favor of #clear_changes_information
This method name is causing confusion with the `reset_#{attribute}`
methods. While `reset_name` set the value of the name attribute for the
previous value the `reset_changes` only discard the changes and previous
changes.
2014-07-15 16:04:31 -03:00
Godfrey Chan
9eb15ed6a0 Only automatically include validations when enabled
This is a follow up to #16024.
2014-07-02 15:07:57 -07:00
Aditya Kapoor
7b1a42c057 automatically include ActiveModel::Validations when include ActiveModel::SecurePassword 2014-07-03 02:51:12 +05:30
Rafael Mendonça França
dc67d3d2a1 Rename rollback_changes to undo_changes
To avoid overload with database rollback
2014-06-30 16:55:01 -03:00
Rafael Mendonça França
bada1d3ed6 Merge pull request #14861 from igor04/dirty-rollback
Added rollback method to ActiveModel::Dirty
2014-06-30 15:37:06 -03:00
Aditya Kapoor
94b6207910 remove unneeded test model for ActiveModel test cases. 2014-06-28 22:27:06 +05:30
Rafael Mendonça França
6099b643e6 Merge pull request #15834 from rmehner/allow_proc_and_symbol_for_only_integer
Allow proc and symbol as values for `only_integer` of `NumericalityValidator`
2014-06-26 07:03:31 -03:00
David Heinemeier Hansson
d5d94a7750 Merge pull request #15871 from yuki24/add-model-name-instance-method
Add #model_name instance method to ActiveModel::Naming
2014-06-24 13:54:58 +02:00
igor04
552d4d85f3 Added rollback method to ActiveModel::Dirty 2014-06-23 23:19:43 +03:00
Aditya Kapoor
d770ec0909 remove unnecessary require for json serialization test cases 2014-06-24 00:03:02 +05:30
Yuki Nishijima
10adc2ee90 Delegate #model_name method to self.class 2014-06-22 19:14:25 -07:00
Robin Mehner
64a05a928c only_integer of NumericalityValidator now allows procs and symbols 2014-06-22 12:22:27 +02:00
Akshay Vishnoi
73dc6d790c Correct typo, add test for validates_absence_of, correct method names 2014-06-16 08:22:11 +05:30
Akshay Vishnoi
9bc91260ac Use @existing_user while updating existing user, fixing - #ee4e86 2014-06-14 14:42:52 +05:30
Godfrey Chan
ee4e86fa4b Cleaned up the has_secure_password test cases
* Grouped the valid test cases in one place
* Make the length of the generated password obvious
* Removed two wrong (copy-and-pasted) test cases
2014-06-14 00:43:47 -07:00
Akshay Vishnoi
cabbc8f6a5 SecurePassword - Validate password must be less than or equal to 72
See #14591, Reason - BCrypt hash function can handle maximum 72 characters.
2014-06-14 12:35:31 +05:30
Aditya Kapoor
2399207789 [ci skip] add tests for ActionModel::Conversion 2014-06-11 23:18:47 +05:30
Kuldeep Aggarwal
e5cc892ce6 remove depricated Validatior#setup 2014-06-10 12:27:17 +05:30