Commit Graph

109 Commits

Author SHA1 Message Date
Akira Matsuda
68db6bc431 Let validates_inclusion_of accept Time and DateTime ranges
fixes 4.0.0 regression introduced in 0317b93c17a46d7663a8c36edc26ad0ba3d75f85
2013-10-23 22:10:15 +09:00
Rajarshi Das
782d794c20 use assert_empty in activemodel conditional validation test cases 2013-09-10 17:26:39 +05:30
Charles Bergeron
0317b93c17 Use Range#cover? for Numeric ranges (tests via endpoints) and use Range#include? for non-numeric ranges
added changelog message
2013-05-27 23:54:25 -07:00
Nick Sutterer
7d84c3a2f7 deprecate Validator#setup (to get rid of a respond_to call). validators do their setup in their constructor now. 2013-05-23 10:00:44 -03:00
Patrick Robertson
eebb9ddf9b Convert ActiveModel to 1.9 hash syntax.
I also attempted to fix other styleguide violations such as
{ a: :b } over {a: :b} and foo(b: 'bar') over foo( b: 'bar' ).
2013-05-01 18:01:46 -07:00
Carlos Antonio da Silva
3e47e193c6 Merge pull request #10286 from neerajdotname/fix-wrong-test-name-and-failure-message
fix wrong test description and failure message
2013-04-21 09:22:51 -07:00
Neeraj Singh
2242317fdd fix wrong test description and failure message 2013-04-21 12:00:38 -04:00
Neeraj Singh
cf69d527fe Added tests for if condition in Active Model callbacks 2013-04-21 11:34:12 -04:00
Vipul A M
233737706c fix some typos found in activemodel 2013-03-18 17:20:05 +05:30
Yves Senn
b501ee47fa validates_confirmation_of does not override writer methods. 2013-03-04 18:51:34 +01:00
Rafael Mendonça França
e16110c4b8 Take care of whitespaces and changing the hash syntax 2013-02-04 09:59:22 -02:00
David
6e2cba1c8b test for issue 8931 2013-02-02 13:00:52 +08:00
Rafael Mendonça França
9647d4b6f4 Add CHANGELOG entry for #8622 2012-12-26 19:22:38 -03:00
Rafael Mendonça França
78fd14c8de Revert the change at ActiveModel::Errors#add_on_blank and fix in the
right place.

The EachValidator#validate already handle :allow_blank and :allow_nil,
correctly.

Closes #8622.

Fix #8621.
2012-12-26 18:55:47 -03:00
Colin Kelley
d4c30a0226 Tests and fix for validates_presence of :allow_nil, :allow_blank
Conflicts:
	activemodel/lib/active_model/errors.rb
2012-12-26 18:19:27 -03:00
Roberto Vasquez Angel
d72a07f1d1 Add ActiveModel::Validations::AbsenceValidator, a validator to check the absence of attributes.
Add `ActiveModel::Errors#add_on_present` method. Adds error messages to present attributes.
2012-12-15 16:27:44 -05:00
Michal Zima
ea76e9a312 Length validation handles correctly nil. Fix #7180
When nil or empty string are not allowed, they are not valid.
2012-11-26 12:34:32 +01:00
Vasiliy Ermolovich
70ecf6c518 use Array() instead flatten
* move ActiveModel::Errors tests to errors_test.rb
* add spec coverage for add_on_empty and add_on_blank
2012-11-05 18:29:31 +03:00
Carlos Antonio da Silva
b1fe78e0cb Raise ArgumentError when no attribute is given to AMo::EachValidator
ArgumentError is better suited than RuntimeError for this.
2012-11-04 11:41:05 -02:00
AvnerCohen
77eb1fb22d convert comments to 1.9 hash syntax 2012-10-22 19:34:24 +02:00
kennyj
9063f3729b Fix method redefined warnings. 2012-08-29 02:38:12 +09:00
Gabriel Sobrinho
2f3eb484f2 Accept a symbol for :in option on inclusion and exclusion validators 2012-08-24 15:26:17 -03:00
Accessd
f35f6ab003 fix typo in callbacks test 2012-07-24 12:01:41 +04:00
Rafael Mendonça França
770fa81bba Don't pass :within option to the i18n 2012-07-20 14:10:25 -03:00
Rafael Mendonça França
53edd32684 validates_inclusion_of and validates_exclusion_of now accept
`:within` option as alias of `:in` as documented.

Fix #7118
2012-07-20 13:53:31 -03:00
MrBrdo
bc7c0b5c10 prevent users from unknowingly using bad regexps that can compromise security (http://homakov.blogspot.co.uk/2012/05/saferweb-injects-in-various-ruby.html) 2012-06-14 18:10:49 +02:00
Brian Cardarella
4433b1a99a Support i18n attributes for confirmation 2012-04-24 01:05:41 -04:00
Brian Cardarella
fcc534ed76 confirmation validation error attribute
This will render the error message on :#{attribute}_confirmation instead
of on attribute itself. When rendering confirmation errors inline on the
form with form builders such as SimpleForm and Formtastic it is
confusing to the ender user to see the confirmation error message on the
attribute element. Instead it makes more sense to have this validation
error render on the confirmation field instead.

The i18n message has been updated for the confirmation validator error
message to include the original attribute name.
2012-04-23 17:16:05 -04:00
Niels Ganser
60dad828ae To infinity… and beyond!
Allow infinite values for validates_length_of. Particularly useful
for prettily defining an open ended range such as

validates_length_of :human_stupidity, :within => 0..Float::INFINITY
2012-02-06 12:58:32 +01:00
prasath
bf31d7b224 Removing unwanted method and adding to accessor for getter history 2012-01-25 01:34:04 +05:30
Jakub Kuźma
0fe311a7fc added :other_than => :!= option to numericality validator 2011-12-21 10:54:44 +01:00
José Valim
7ba28d434c Remove dead code from AMo. 2011-12-20 18:38:20 +01:00
Arun Agrawal
4fac64b1cc Fixed test "ArgumentError: wrong number of arguments(1 for 0)" 2011-12-17 16:49:01 +05:30
Antonio Roberto
66e747b461 Fixed bug when error message is an empty string. 2011-12-16 17:17:14 -02:00
Prem Sichanugrist
0e2156d334 Update variable's name in the test case to reflect the class we're testing 2011-11-18 11:51:05 -05:00
Sebastian Martinez
21b61a8ac4 Follow code conventions on some tests 2011-05-10 20:58:36 -03:00
José Valim
df5691aa94 No need to rescue here. Invoking the wrong method in an object can happen anywhere if you are not careful. In other words, test your shit. 2011-04-11 17:47:59 +02:00
José Valim
5bf3d46bec Revert "Add :use_include option to allow user to explicitly use Range#include? method in Ruby 1.9"
Use :with => range.to_a instead.

This reverts commit f6540211b5b9133c9f93c11655a04d613c237e67.
2011-04-11 17:41:33 +02:00
Prem Sichanugrist
f6540211b5 Add :use_include option to allow user to explicitly use Range#include? method in Ruby 1.9
In Ruby 1.9 we're currently use `Range#cover?` to fix the performance problem. However, there might be the case that you want to use `Range#include?` instead. This patch will give you that option.
2011-04-10 18:49:28 +08:00
Prem Sichanugrist
58594be680 Add support for proc or lambda as an option for InclusionValidator, ExclusionValidator, and FormatValidator
You can now use a proc or lambda in :in option for InclusionValidator and ExclusionValidator, and :with, :without option for FormatValidator
2011-04-10 18:49:28 +08:00
Santiago Pastorino
157c37f558 Refactor length validation 2011-03-12 21:12:44 -02:00
Andriy Tyurnikov
f48d3d4df6 length validation for fixnums
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2011-03-12 21:12:44 -02:00
R.T. Lechow
86c15d8b89 Active Model typos. 2011-03-05 11:56:34 +01:00
Santiago Pastorino
a00bed0c48 Revert "Properly interpolate i18n keys in modules [#5572 state:resolved]"
This breaks #6448, you should use :"module/class" as key for namespacing
[#6448 state:committed]

This reverts commit 8d30193b08bd2321a7a78a1f481bd5e4d4d45557.
2011-02-27 21:30:03 -02:00
Frederick Cheung
fbfa30a1ee Change validates inclusion to use cover? for Ranges in ruby 1.9 [#6453 state:committed]
Signed-off-by: Xavier Noria <fxn@hashref.com>
2011-02-18 21:32:28 +01:00
Carl Lerche
cd13fbd8d8 Optionally pass in the attribute being validated to an instance method validator 2011-02-05 16:44:35 -08:00
Carl Lerche
e9e9ed6b60 Be able to pass a validator method to #validates 2011-02-05 16:33:00 -08:00
Carl Lerche
ed7614aa7d Provide a way to specify alternate option keys for validates 2011-02-05 16:00:57 -08:00
Carl Lerche
7176ade35b Do not require that validation attributes be specified as symbols 2011-02-05 15:37:38 -08:00
Samuel Kadolph
972011a2e5 Add support for namespaced validators
Includes test and documentation for new feature

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2010-12-16 01:49:28 +05:30