Commit Graph

146 Commits

Author SHA1 Message Date
Charlie Somerville
6a5c4448bf respond_to? 2014-03-19 21:11:45 +11:00
Zach Moazeni
477f0e7981 Methods that return nil should not be considered YAML
This is a direct port of @jaw6's pull request
https://github.com/rails/rails/pull/492. His cleanly applied to Rails
v3.1 and v3.2, and this cleanly applies to v3.0.

With yesterday's security patches
http://weblog.rubyonrails.org/2013/1/8/Rails-3-2-11-3-1-10-3-0-19-and-2-3-15-have-been-released/
there is now an issue with Rails v3.0 serving XML to any of the latest
versions of ActiveResource.

Without this, Rails v3.0 can serve XML to ActiveResource consumers that
will see `Hash::DisallowedType: Disallowed type attribute: "yaml"`
2013-01-09 17:34:43 -05:00
John Firebaugh
5b8dbb0eee Support both conventions for translations for namespaced models.
3.0.0 - 3.0.1 required 'namespace/model'
3.0.2 - 3.0.5 required 'namespace.model' (nested). It has the advantage of
keeping the i18n file DRY when multiple models are in the same namespace,
but can lead to translation key conflicts if models are nested within
models.

[#6448, #5572]
2011-03-30 22:21:52 -07:00
Santiago Pastorino
7717fc375e Do not in place modify what table_name returns 2011-03-22 20:17:44 -03:00
Santiago Pastorino
691530a19d Sync attribute_methods.rb with master code, tests added
[#6580 state:committed]
2011-03-17 23:18:10 -03:00
Santiago Pastorino
1cbade35f9 Refactor length validation 2011-03-16 11:49:56 -03:00
Andriy Tyurnikov
01cb81a66f length validation for fixnums
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2011-03-12 21:15:01 -02:00
Santiago Pastorino
f80eea3bf3 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 8d14fa8959.
2011-02-27 21:47:12 -02:00
Santiago Pastorino
d043d20eb0 failing test for i18n key collision with namespaced models 2011-02-27 21:44:26 -02:00
Frederick Cheung
d7b539aae2 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:01 +01:00
Aaron Patterson
4dc5505e18 psych does not emit a space after the type 2011-02-11 14:44:00 -08:00
Hemant Kumar
05da752847 fix difference between behaviour of blank and empty
Signed-off-by: José Valim <jose.valim@gmail.com>
2011-01-05 13:18:58 +01:00
Thilo Utke
d321e78646 ActiveModel::Errors.to_hash returns plain OrderedHash and used in to_json serialization to properly handle multiple errors per attribute
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-12-01 12:03:13 +01:00
Aaron Patterson
0d055de8b6 do not require ruby-debug automatically. please require it if you have declared it as a dependency 2010-11-19 16:29:57 -08:00
Carl Lerche
dd3afdd33b Raise an ArgumentError when passing an invalid argument to a validator 2010-11-18 22:33:45 -08:00
Neeraj Singh
9e32b1cbe5 after_create in ActiveModel should in the order specified
[#5650 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-09-27 23:18:05 +02:00
Rodrigo Rosenfeld Rosas
8d14fa8959 Properly interpolate i18n keys in modules [#5572 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-09-24 20:49:33 +02:00
Jeremy Kemper
33b954005c fixed some issues with JSON encoding
- as_json in ActiveModel should return a hash
  and handle :only/:except/:methods options
- Array and Hash should call as_json on their elements
- json methods should not modify options argument

[#5374 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>

Conflicts:

	activemodel/lib/active_model/serialization.rb
2010-09-07 11:33:46 -07:00
Neeraj Singh
8f72ddc12b after_validation should be called irrespective of the result of validation.
I confirmed that this is the behavior on 2.3.x .

[5419 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-08-20 11:24:58 -03:00
Xavier Noria
5f5c508444 code gardening: we have assert_(nil|blank|present), more concise, with better default failure messages - let's use them 2010-08-17 03:31:39 +02:00
Subba Rao Pasupuleti
76c91a237c Adding missing required statement
[#5056 state:resolved]

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2010-08-14 06:28:54 -03:00
Santiago Pastorino
3270c58ebb Deletes trailing whitespaces (over text files only find * -type f -exec sed 's/[ \t]*$//' -i {} \;) 2010-08-14 04:20:06 -03:00
Subba Rao Pasupuleti
fe2d65864e no callbacks should be created for empty array [#5289 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-08-12 13:13:41 -03:00
Greg Campbell
d03a1249a0 Add missing ActiveModel::Validations require
[#5311 state: resolved]

ActiveModel::Validations uses Hash#except, but does not require it from
ActiveSupport.  (This wasn't showing up in the tests, because it was
required in the helper, and was also required in
ActiveModel::Serialization).

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-08-12 13:13:33 -03:00
rohit
257e9c4ec4 Failing test for validates_length_of, when both too_short and too_long messages are set [#5283 state:open]
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-08-03 15:37:17 +02:00
Tore Darell
2c8a4a53a8 Remove or fix non-working examples and add a few tests to Dirty [#5185 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-08-03 10:47:30 +02:00
Neeraj Singh
fb2b8fec24 adding test cases for ActiveModel::Errors
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-08-03 10:46:16 +02:00
Alex Le
aeaab06c79 ActiveModel::Errors json serialization to work as Rails 3b4 [#5254 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-08-02 16:26:32 +02:00
José Valim
53310614d7 Reuse already existing classes for ActiveModel tests. 2010-07-21 13:00:56 +02:00
Piotr Sarnacki
6807b08099 Moved a few methods from RecordIdentifier to ActiveModel::Naming
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-07-21 11:29:58 +02:00
Santiago Pastorino
16c14f7465 Avoid interpreted as grouped expression warnings 2010-07-11 02:55:38 -03:00
Josh Kalderimis
4b66aab00f mass_assignment_security moved from AR to AMo, and minor test cleanup
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-07-08 18:28:45 +02:00
Jeremy Kemper
d15256af6c Missing BigDecimal dependency 2010-06-27 16:28:04 -07:00
José Valim
7bd85a8fc2 Work around the fact the JSON gem was overwriting to_json implementation for all Ruby core classes.
This is required because the JSON gem is incompatible with Rails behavior and was not allowing ActiveModel::Errors to be serialized.
So we need to ensure Rails implementation is the one triggered. [#4890 state:resolved]
2010-06-26 12:01:13 +02:00
Josh Kalderimis
e8c064bbe0 Regression with how base errors messages are added to a model. Works correctly for both string error messages and symbol translated messages.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-06-23 14:45:55 +02:00
Neeraj Singh
c0fc084e93 should be able to run ActiveModel validations_test [#4933 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-06-22 21:38:27 +02:00
Santiago Pastorino
6ea967729f Avoid method redefined warning
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-06-22 15:09:01 +02:00
Jeroen van Dijk
26392c4ac5 Make ActiveModel::Errors#add_on_blank and #add_on_empty accept an options hash and make various Validators pass their (filtered) options.
This makes it possible to pass additional options through Validators to message generation. E.g. plugin authors want to add validates_presence_of :foo, :format => "some format".

Also, cleanup the :default vs :message options confusion in ActiveModel validation message generation.

Also, deprecate ActiveModel::Errors#add_on_blank(attributes, custom_message) in favor of ActiveModel::Errors#add_on_blank(attributes, options).

Also, refactoring of ActiveModel and ActiveRecord Validation tests. Test are a lot more DRY now. Better test coverage as well now.

The first four points were reapplied from an older patch of Sven Fuchs which didn't apply cleanly anymore and was not complete yet.

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-06-21 11:55:21 +02:00
José Valim
0247995d05 ActiveModel::Validations::Callbacks should not be required by default. 2010-06-19 18:20:02 +02:00
Neeraj Singh
51739d3228 moving before_validation and after_validation functionality from ActiveRecord to ActiveModel
[#4653 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-06-19 17:59:52 +02:00
José Valim
a04060fb6f Really make include_root_in_json default to true [#3770 state:resolved] 2010-06-08 01:02:45 +02:00
Anil Wadghule
bdb2871df7 Fix xml serialization test [#4650 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-05-19 13:02:13 +02:00
Neeraj Singh
b462952886 Use better assertion methods for testing
[#4645 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-05-19 10:18:36 +02:00
rohit
05e3fb45ee Add a valid hex that shouldn't be valid to ActiveModel numericality tests [#4622 state:commited]
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-05-18 03:10:55 +02:00
Jeremy Kemper
5371242384 Valid hex strings aren't valid float column values, to match the integer restriction. [#4622 state:resolved] 2010-05-17 07:58:26 -07:00
Santiago Pastorino
fdfebb7782 Make use of assert_equal to test equallity between object assert expects and object and a message of error
[#4611 state:committed]

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-05-16 16:06:28 +02:00
José Valim
d6cbb27e7b Revert "Make ActiveModel::Errors#add_on_blank and #add_on_empty accept an options hash and make various Validators pass their (filtered) options."
Having a huge array to whitelist options is not the proper way to handle this case. This means that the ActiveModel::Errors object should know about the options given in *all* validators and break the extensibility added by the validators itself. If the intent is to whitelist options before sending them to I18n, each validator should clean its respective options instead of throwing the responsibility to the Errors object.

This reverts commit bc1c8d58ec.
2010-05-15 21:55:16 +02:00
Jeroen van Dijk
bc1c8d58ec Make ActiveModel::Errors#add_on_blank and #add_on_empty accept an options hash and make various Validators pass their (filtered) options.
This makes it possible to pass additional options through Validators to message
generation. E.g. plugin authors want to add validates_presence_of :foo, :format
=> "some format".

Also, cleanup the :default vs :message options confusion in ActiveModel
validation message generation.

Also, deprecate ActiveModel::Errors#add_on_blank(attributes, custom_message) in
favor of ActiveModel::Errors#add_on_blank(attributes, options).

Original patch by Sven Fuchs, some minor changes and has been changed to be applicable to master again

[#4057 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-05-15 11:17:58 -07:00
Josh Kalderimis
9131a88bb8 validation macros can now be used within an instance 2010-05-13 13:57:37 -07:00
Santiago Pastorino
6334006b81 Revert "Refactor of active_model/naming.rb and allow collection and element to be writable"
This reverts commit f7862b2c34.

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-05-12 21:02:16 +02:00