Commit Graph

119 Commits

Author SHA1 Message Date
Dmitry Polushkin
86e3b047ba Validate multiple contexts on valid? and invalid? at once.
Example:

```ruby
class Person
  include ActiveModel::Validations

  attr_reader :name, :title
  validates_presence_of :name, on: :create
  validates_presence_of :title, on: :update
end

person = Person.new
person.valid?([:create, :update])    # => true
person.errors.messages               # => {:name=>["can't be blank"], :title=>["can't be blank"]}
```
2015-07-30 10:05:29 +01:00
karanarora
0750330941 Spelling/typo/grammatical fixes [ci skip]
spelling fix [ci skip]

example to be consistent [ci skip]

grammatical fix

typo fixes [ci skip]
2015-05-23 03:01:33 +05:30
Jay Elaraj
b2967999ae ensure method_missing called for non-existing methods passed to
`ActiveModel::Serialization#serializable_hash`
2015-04-28 21:06:30 -04:00
Yves Senn
cdbf685994 pass over CHANGELOGs. [ci skip] 2015-04-22 14:44:30 +02:00
Fernando Tapia Rico
f072db8e4f Add ActiveModel::Dirty#[attr_name]_previously_changed? and
`ActiveModel::Dirty#[attr_name]_previous_change` to improve access
to recorded changes after the model has been saved.

It makes the dirty-attributes query methods consistent before and after
saving.
2015-04-21 19:30:46 +02:00
Robin Dupret
9cc41c36f7 Fix a few typos [ci skip] 2015-04-05 15:58:43 +02:00
Sean Griffin
1c341eb7cb Deprecate the :tokenizer option to validates_length_of
As demonstrated by #19570, this option is severely limited, and
satisfies an extremely specific use case. Realistically, there's not
much reason for this option to exist. Its functionality can be trivially
replicated with a normal Ruby method. Let's deprecate this option, in
favor of the simpler solution.
2015-03-29 16:34:01 -06:00
Yves Senn
e71f5dad4e some indenting and punctuation fixes. [ci skip] 2015-02-23 16:54:40 +01:00
Wojciech Wnętrzak
fd38838f29 Deprecate ActiveModel::Errors add_on_empty and add_on_blank methods
without replacement.
2015-02-19 14:10:38 +01:00
Rafael Mendonça França
3c750c4c6c Merge pull request #18634 from morgoth/deprecate-some-errors-methods
Deprecate `ActiveModel::Errors` `get`, `set` and `[]=` methods.
2015-02-18 18:58:28 -02:00
Rafael Mendonça França
7919c29d50 Merge pull request #16381 from kakipo/validate-length-tokenizer
Allow symbol as values for `tokenizer` of `LengthValidator`
2015-02-13 12:09:36 -02:00
Carlos Antonio da Silva
fdeef19833 Move required error message and changelog to Active Record
The new association error belongs to Active Record, not Active Model.
See #18700 for reference.
2015-02-01 10:31:54 -02:00
Wojciech Wnętrzak
6ec8ba16d8 Deprecate ActiveModel::Errors get, set and []= methods.
They have inconsistent behaviour currently.
2015-02-01 13:14:00 +01:00
Aaron Patterson
6b4a5952d3 Merge pull request #18700 from nygrenh/better-required-message
Provide a better error message on :required association
2015-01-31 14:10:23 -08:00
Yves Senn
afe402dac7 unify CHANGELOG format. [ci skip] 2015-01-31 11:54:00 +01:00
Henrik Nygren
9a6c6c6f09 Provide a better error message on :required association
Fixes #18696.
2015-01-28 11:32:10 +02:00
Eugene Gilburg
5bdb42159e use attribute assignment module logic during active model initialization 2015-01-23 14:42:47 -08:00
Sean Griffin
a225d4bec5 ✂️ and 💅 for #10776
Minor style changes across the board. Changed an alias to an explicit
method declaration, since the alias will not be documented otherwise.
2015-01-23 14:51:59 -07:00
Bogdan Gusiev
2606fb3397 Extracted ActiveRecord::AttributeAssignment to ActiveModel::AttributesAssignment
Allows to use it for any object as an includable module.
2015-01-23 23:43:22 +02:00
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
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
9c65c539e2 Add config to halt callback chain on return false
This stems from [a comment](rails#17227 (comment)) by @dhh.
In summary:

* New Rails 5.0 apps will not accept `return false` as a way to halt callback chains, and will not display a deprecation warning.
* Existing apps ported to Rails 5.0 will still accept `return false` as a way to halt callback chains, albeit with a deprecation warning.

For this purpose, this commit introduces a Rails configuration option:

```ruby
config.active_support.halt_callback_chains_on_return_false
```

For new Rails 5.0 apps, this option will be set to `false` by a new initializer
`config/initializers/callback_terminator.rb`:

```ruby
Rails.application.config.active_support.halt_callback_chains_on_return_false = false
```

For existing apps ported to Rails 5.0, the initializers above will not exist.
Even running `rake rails:update` will not create this initializer.

Since the default value of `halt_callback_chains_on_return_false` is set to
`true`, these apps will still accept `return true` as a way to halt callback
chains, displaying a deprecation warning.

Developers will be able to switch to the new behavior (and stop the warning)
by manually adding the line above to their `config/application.rb`.

A gist with the suggested release notes to add to Rails 5.0 after this
commit is available at https://gist.github.com/claudiob/614c59409fb7d11f2931
2015-01-02 15:31:56 -08: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
Rafael Mendonça França
f25ad07f5a Start Rails 5 development 🎉
We will support only Ruby >= 2.1.

But right now we don't accept pull requests with syntax changes to drop
support to Ruby 1.9.
2014-11-28 15:00:06 -02:00
Akshay Vishnoi
57a893b54a [ci skip] ActiveModel CHANGELOG docs fixes 2014-09-18 02:57:13 +05:30
Carlos Antonio da Silva
9a0e0594ab Fix typo [ci skip] 2014-08-07 09:17:23 -03:00
Yevhene Shemet
f8dcb365df Allow password to contain spaces only. 2014-08-06 22:11:06 +03:00
kakipo
c3fa5c3d25 Allow symbol as values for tokenize of LengthValidator 2014-08-03 14:50:09 +09: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
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
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
b34f7c1706 Add CHANGELOG entry for #14861 and document private methods on the API 2014-06-30 15:41:41 -03:00
Robin Mehner
64a05a928c only_integer of NumericalityValidator now allows procs and symbols 2014-06-22 12:22:27 +02:00
Godfrey Chan
c416bb8729 Added changelog for #15708 [ci skip] 2014-06-14 00:32:31 -07:00
Vijay Dev
4aa25d4c76 fix typo in changelog [ci skip] 2014-06-11 15:01:28 +05:30
Yves Senn
daaf62c16b Merge pull request #15635 from kuldeepaggarwal/add-missing-changelog
add missing changelog entry. refer [#16db90d] [ci skip]
2014-06-11 09:05:18 +02:00
Kuldeep Aggarwal
aec4127fa1 add missing changelog entry. refer [#16db90d] [ci skip] 2014-06-11 11:38:06 +05:30
Yves Senn
8109dc8067 formatting pass through CHANGELOGS. [ci skip] 2014-05-16 09:03:26 +02:00
Abd ar-Rahman Hamidi
6604ce63e8 Add singular and plural form for some validation messages 2014-05-02 18:32:11 +02:00
Robin Dupret
5c87c95a71 Enhance a bit a few changelog entries [ci skip] 2014-05-02 11:56:03 +02:00
Rafael Mendonça França
eddcdb0f1d Add CHANGELOG to Active Model too [ci skip] 2014-03-27 14:16:57 -03:00
Carlos Antonio da Silva
71b3910a7d Point master changelogs to 4-1-stable branch
Remove 4-1 related entries from master [ci skip]
2014-02-25 09:14:36 -03:00
Yves Senn
7d196cf360 #to_param returns nil if to_key returns nil. Closes #11399.
The documentation of `#to_key` (http://api.rubyonrails.org/classes/ActiveModel/Conversion.html#method-i-to_key)
states that it returns `nil` if there are no key attributes. `to_param` needs
to be aware of that fact and return `nil` as well.

Previously it raised the following exception:

```
  1) Error:
ConversionTest#test_to_param_returns_nil_if_to_key_is_nil:
NoMethodError: undefined method `join' for nil:NilClass
    /Users/senny/Projects/rails/activemodel/lib/active_model/conversion.rb:65:in `to_param'
    /Users/senny/Projects/rails/activemodel/test/cases/conversion_test.rb:34:in `block in <class:ConversionTest>'
```
2014-02-04 10:27:46 +01:00
Yves Senn
02f9f33142 tidy CHANGELOGs [ci skip] 2014-01-30 11:12:46 +01:00
Vince Puzzella
8855163bdb Ability to specify multiple contexts when defining a validation.
Example:

validates_presence_of :name, on: [:update, :custom_validation_context]
2014-01-27 03:26:27 -05:00
Carlos Antonio da Silva
3a33e8ea85 Use a better method name to check the requirement of password confirmation
Also improve changelog entries related to secure password to proper
highlight.
2014-01-07 07:59:44 -02:00