Commit Graph

473 Commits

Author SHA1 Message Date
Xavier Noria
5ea6b0df9a load active_support/core_ext/object/inclusion in active_support/rails 2012-08-02 21:59:22 +02:00
Robby Grossman
ad7f9cdf00 has_secure_password should not raise a 'digest missing' error if the calling class has specified for validations to be skipped. 2012-07-31 16:16:21 -04: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
Rafael Mendonça França
fb8cf55868 Merge pull request #6800 from mschneider/dynamic_finders_for_aliased_attributes
Dynamic finders for aliased attributes
2012-06-22 07:51:11 -07:00
Maximilian Schneider
f984b8152f made dynamic finders alias_attribute aware
previously dynamic finders only worked in combination with the actual
column name and not its alias defined with #alias_attribute
2012-06-22 16:44:01 +02:00
Carlos Antonio da Silva
965b779eb2 Add some coverage for AR serialization with serializable_hash
ActiveRecord json/xml serialization should use as base
serializable_hash, provided by ActiveModel. Add some more coverage
around options :only and :except for both json and xml serialization.
2012-06-22 08:28:03 -03:00
Jon Leighton
e030f26ad3 Simplify AR configuration code.
Get rid of ActiveModel::Configuration, make better use of
ActiveSupport::Concern + class_attribute, etc.
2012-06-15 19:15:36 +01: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
Piotr Sarnacki
41d63710f2 Merge pull request #6668 from pomnikita/master
Compact array of values added to PermissionSet instance
2012-06-08 11:35:13 -07:00
Nikita Pomyashchiy
00ff0a6776 Compact array of values added to PermissionSet instance 2012-06-08 01:00:34 +04:00
Francesco Rodriguez
ab11a2780f change AMS::JSON.include_root_in_json default value to false
Changes:

* Update `include_root_in_json` default value to false for default value
  to false for `ActiveModel::Serializers::JSON`.
* Remove unnecessary change to include_root_in_json option in
  wrap_parameters template.
* Update `as_json` documentation.
* Fix JSONSerialization tests.

Problem:

It's confusing that AM serializers behave differently from AR,
even when AR objects include AM serializers module.

    class User < ActiveRecord::Base; end

    class Person
      include ActiveModel::Model
      include ActiveModel::AttributeMethods
      include ActiveModel::Serializers::JSON

      attr_accessor :name, :age

      def attributes
        instance_values
      end
    end

    user.as_json
    => {"id"=>1, "name"=>"Konata Izumi", "age"=>16, "awesome"=>true}
    # root is not included

    person.as_json
    => {"person"=>{"name"=>"Francesco", "age"=>22}}
    # root is included

    ActiveRecord::Base.include_root_in_json
    => false

    Person.include_root_in_json
    => true

    # different default values for include_root_in_json

Proposal:

Change the default value of AM serializers to false, update
the misleading documentation and remove unnecessary change
to false of include_root_in_json option with AR objects.

    class User < ActiveRecord::Base; end

    class Person
      include ActiveModel::Model
      include ActiveModel::AttributeMethods
      include ActiveModel::Serializers::JSON

      attr_accessor :name, :age

      def attributes
        instance_values
      end
    end

    user.as_json
    => {"id"=>1, "name"=>"Konata Izumi", "age"=>16, "awesome"=>true}
    # root is not included

    person.as_json
    => {"name"=>"Francesco", "age"=>22}
    # root is not included

    ActiveRecord::Base.include_root_in_json
    => false

    Person.include_root_in_json
    => false

    # same behaviour, more consistent

Fixes #6578.
2012-06-06 01:11:39 -05:00
José Valim
555d8152c7 Merge pull request #5843 from kuroda/translation_of_deeply_nested_model_attributes
Fix human attribute_name to handle deeply nested attributes
2012-05-29 23:26:26 -07:00
Steve Purcell
b3ccd7b27a Don't enable validations when passing false hash values to ActiveModel.validates
Passing a falsey option value for a validator currently causes that validator to
be enabled, just like "true":

    ActiveModel.validates :foo, :presence => false

This is rather counterintuitive, and makes it inconvenient to wrap `validates` in
methods which may conditionally enable different validators.

As an example, one is currently forced to write:

      def has_slug(source_field, options={:unique => true})
        slugger = Proc.new { |r| r[:slug] = self.class.sluggify(r[source_field]) if r[:slug].blank? }
        before_validation slugger
        validations = { :presence => true, :slug => true }
        if options[:unique]
          validations[:uniqueness] = true
        end
        validates :slug, validations
      end

because the following reasonable-looking alternative fails to work as expected:

      def has_slug(source_field, options={:unique => true})
        slugger = Proc.new { |r| r[:slug] = self.class.sluggify(r[source_field]) if r[:slug].blank? }
        before_validation slugger
        validates :slug, :presence => true, :slug => true, :uniqueness => options[:unique]
      end

(This commit includes a test, and all activemodel and activerecord tests pass as before.)
2012-05-28 15:02:02 +01:00
José Valim
56417b4092 Merge pull request #4785 from ayamomiji/add-self-to-allow-method-name-using-ruby-keyword
add `self.` to allow method name using ruby keyword
2012-05-25 00:29:07 -07:00
Angelo capilleri
5646d65d01 changed xml type datetime to dateTime, fixes #6328
XmlMini define the xml 'datatime', but according to
http://www.w3.org/TR/xmlschema-2/#dateTime could be better
change this to 'dateTime' with upper case letter 'T.
So 'DateTime' and 'Time' are redefined from 'datetime' to 'dateTime'

add the changing to the changelog
2012-05-23 14:45:56 +02:00
Aaron Patterson
1b604c73f1 Merge pull request #6215 from erichmenge/fix_has_secure_password
Fix has secure password
2012-05-17 10:32:15 -07:00
Naoto Takai
80a2c9e5db Improve logging of ActiveModel::MassAssignmentSecurity::Sanitizer 2012-05-17 06:55:41 +09:00
Tsutomu Kuroda
b0e2fc843b Fix human attribute_name to handle deeply nested attributes
When a model nests another model that also nests yet another model
using accepts_nested_attributes_for method, its Errors object can
have an attribute name with "contacts.addresses.street" style.

In this case, the dots within the namespace should be substituted
with slashes so that we can provide the translation under the
"activemodel.attributes.person/contacts/addresses.street" key.

This commit is related to #3859.
2012-05-16 08:39:48 +09:00
Carlos Antonio da Silva
9b4f5041d2 Kill whitespaces ✂️ 2012-05-15 13:38:29 -03:00
Carlos Antonio da Silva
3d1b078a5b Merge pull request #6284 from acapilleri/dup_validation
clean the erros if an object that includes validation  is duped.
2012-05-15 05:20:57 -07:00
Francesco Rodriguez
00c94d7d94 updating define_attribute_methods documentation 2012-05-14 11:38:23 -05:00
Francesco Rodriguez
05234b358f allow define_attribute_methods to pass multiple values 2012-05-14 11:35:15 -05:00
Angelo Capilleri
f9ae1baa0a clean the erros if an object that includes validations errors is duped. Fixes #5953 2012-05-13 23:24:05 +02:00
ayaya
c140a27fc5 fix alias_attribute will raise a syntax error if make an alias on a
column that named as a ruby keyword
2012-05-14 00:57:29 +08:00
Santiago Pastorino
36dd1857dc Remove useless load path modifications 2012-05-11 19:00:35 -03:00
Jon Leighton
a8637cf493 Use respond_to?(:to_ary) rather than is_a?(Enumerable) to detect collection-thing. 2012-05-11 20:11:04 +01:00
Erich Menge
f021377358 Updated tests for has_secure_password. 2012-05-08 18:08:55 -05:00
Marc-Andre Lafortune
dc74f0cb1b notify_observers should be public 2012-04-30 22:13:26 -04:00
Aaron Patterson
206b43a954 Merge pull request #6063 from marcandre/observer_extra_args
Allow extra arguments for Observers
2012-04-30 16:43:22 -07:00
Marc-Andre Lafortune
24c068d67d Allow extra arguments for Observers 2012-04-30 18:10:03 -04:00
Arun Agrawal
7f248076a3 build fix for observing_test.rb
introduced here 17c990b153f8635874c006a7460ee95817543fc1
2012-04-30 15:27:18 +05:30
Santiago Pastorino
4cff1a2809 Merge pull request #6072 from marcandre/observer_simplify_test
Observer: simplify tests
2012-04-30 00:15:51 -07:00
Jeremy Kemper
0393c7cd51 Merge pull request #6071 from marcandre/observer_redef
Fix Observer by acting on singleton class. Fixes #3505.
2012-04-29 21:10:15 -07:00
Marc-Andre Lafortune
17c990b153 Observer: simplify tests 2012-04-29 22:02:02 -04:00
Marc-Andre Lafortune
bad44e4f8f Fix Observer by acting on singleton class [#3505]
Also [issue #1034] [pull #6068]
2012-04-29 21:51:50 -04:00
Aaron Patterson
f975a8663e Merge pull request #5942 from bcardarella/confirmation_error_message_on_confirmation_attribute
confirmation validation error attribute
2012-04-29 16:29:33 -07:00
Marc-Andre Lafortune
569fb1fffb Generate appropriate error more judiciously 2012-04-29 00:51:56 -04:00
Carlos Antonio da Silva
cafe6a38f5 Do not modify options hash in human_attribute_name, remove reverse_merge 2012-04-28 11:23:29 -03:00
José Valim
cd556c9388 Merge pull request #5841 from oscardelben/rename_count_observers
Rename Observing#count_observers to Observing#observers_count
2012-04-24 23:09:48 -07:00
Oscar Del Ben
692b3b6b6a Fix secure_password setter 2012-04-24 19:16:01 +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
Oscar Del Ben
27d6ccd8c8 Rename Observing#count_observers to Observing#observers_count 2012-04-14 10:48:53 +02:00
Aaron Patterson
6289f455ae test against ruby features in order to fix tests on Ruby 2.0 2012-03-26 11:32:21 -07:00
José Valim
35e8de6344 Merge pull request #5374 from nertzy/remove_deprecated_partial_path_from_active_model_naming
Remove ActiveModel::Naming#partial_path
2012-03-23 05:57:35 -07:00
José Valim
eb8f0ddb67 Revert "AM::MassAssingmentSecurity: improve performance"
It introduces backwards incompatible changes in the API.

This reverts commit 7d1379ffdbbaf01e99833dc06611b7e4f3799522.
2012-03-15 18:41:54 +01:00
Bogdan Gusiev
7d1379ffdb AM::MassAssingmentSecurity: improve performance 2012-03-14 14:11:52 +02:00
Grant Hutchins
bf8d7574bf Remove ActiveModel::Naming#partial_path
It was deprecated in 3.2
2012-03-10 18:02:36 -05:00
Grant Hutchins
e78c5eeba1 Fix comments about to_partial_path 2012-03-10 17:40:27 -05:00
Carlos Antonio da Silva
10c3304db6 Make sure serializable hash with :include always returns string keys 2012-03-09 21:51:12 -03:00
Carlos Antonio da Silva
cb9d03f0d4 Add docs with usage examples for ActiveModel::Model
Also add test to ensure basic model does not explode when
initialized with nil.
2012-03-03 04:45:30 -03:00
Guillermo Iguaran
3b822e91d1 Add ActiveModel::Model, a mixin to make Ruby objects to work with AP inmediatly 2012-03-02 23:59:55 -05:00
Bogdan Gusiev
534dc4ca1a AM::Errors: allow :full_messages parameter for #as_json 2012-02-20 11:17:11 +02:00
Fabio Yamate
d204918f91 Fix sanitize_for_mass_assigment when role is nil
There is an example in Rails documentation that suggests implementing
assign_attributes method for ActiveModel interface, that by default
sends option role with nil. Since mass_assignment_authorizer never
is called without args, we can move the default value internally.
2012-02-15 11:13:54 -02:00
Carlos Antonio da Silva
ad9f968c4a Make sure serializable hash with :methods option returns always string keys 2012-02-13 11:22:59 -02:00
Carlos Antonio da Silva
5bcb4e3c18 Cleanup extra spaces 2012-02-13 11:20:19 -02:00
prasath
848ee296ec test title changed corresponding to the test 2012-02-09 02:11:36 +05:30
Aaron Patterson
06b9c905a9 Merge pull request #4930 from ask4prasath/ordered_hash_replaced
Replacing ordered hash to ruby hash on active model
2012-02-08 08:59:00 -08:00
José Valim
a17d047a73 Trim down Active Model API by removing valid? and errors.full_messages 2012-02-07 23:10:43 +01:00
prasath
47628ec128 replacing ordered hash to ruby hash 2012-02-08 00:34:47 +05:30
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
Carlos Antonio da Silva
26861e9506 Generate strict validation error messages with attribute name 2012-02-01 11:34:17 -02:00
prasath
f4d9ba0296 Removed unwanted intializer and replaced with ruby default collect method 2012-01-27 00:13:46 +05:30
prasath
bf31d7b224 Removing unwanted method and adding to accessor for getter history 2012-01-25 01:34:04 +05:30
dreamfall
e84998cc21 validates method should not change options argument 2012-01-17 13:18:58 +03:00
Paweł Kondzior
5313eab695 Fix ActiveModel::Errors#dup
Since ActiveModel::Errors instance keeps all error messages as hash
we should duplicate this object as well.

Previously ActiveModel::Errors was a subclass of ActiveSupport::OrderedHash,
which results in different behavior on `dup`, this may result in regression for
people relying on it.
2012-01-16 23:22:51 -08:00
Piotr Sarnacki
8e8982cf3b Add ActiveModel::Errors#delete, which was not available after move to use delegation 2012-01-16 17:23:40 +01:00
Carlos Antonio da Silva
e5df4f9255 Fix test class name that should read Without 2012-01-16 00:00:57 +01:00
Piotr Sarnacki
b164e81c11 Fix stack level too deep when model does not have attributes method.
Without that patch when using ActiveModel::AttributeMethods
in a class that does not respond to `attributes` method,
stack level too deep error will be raised on non existing
method. While documentation is clear that you need to define
`attributes` method in order to use AttributeMethods module,
`stack level too deep` is rather obscure and hard to debug,
therefore we should try to not break `method_missing` if
someone forgets about defining `attributes`.
2012-01-15 15:54:59 +01:00
Aaron Patterson
fec6f1ba82 Merge pull request #4360 from rafaelfranca/patch-1
Remove more references to Test::Unit
2012-01-06 16:43:18 -08:00
Aaron Patterson
b15d2c0708 require minitest rather than test/unit 2012-01-06 15:50:47 -08:00
Rafael Mendonça França
3d4754f131 Use ActiveModel::TestCase instead of Test::Unit:TestCase 2012-01-06 20:43:08 -03:00
Jon Leighton
93c1f11c0a Support configuration on ActiveRecord::Model.
The problem: We need to be able to specify configuration in a way that
can be inherited to models that include ActiveRecord::Model. So it is
no longer sufficient to put 'top level' config on ActiveRecord::Base,
but we do want configuration specified on ActiveRecord::Base and
descendants to continue to work.

So we need something like class_attribute that can be defined on a
module but that is inherited when ActiveRecord::Model is included.

The solution: added ActiveModel::Configuration module which provides a
config_attribute macro. It's a bit specific hence I am not putting this
in Active Support or making it a 'public API' at present.
2011-12-28 18:27:41 +00:00
Sergey Nartimov
9813c62330 remove deprecated define_attr_method from ActiveModel::AttributeMethods 2011-12-24 21:26:15 +03:00
Karunakar (Ruby)
ed1b4ea3f9 Changed the require path for logger 2011-12-21 19:42:44 +05:30
Karunakar (Ruby)
f7d3db71fc removed deprecated loggers 2011-12-21 19:30:45 +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
José Valim
7280787a53 Improve cache on route_key lookup. 2011-12-08 19:53:16 +01:00
Marc-Andre Lafortune
d834755dad ActiveModel::Name#i18n_key: Fix doc and add tests 2011-12-05 22:02:53 -05:00
José Valim
d4964b3386 Namespaced attribute lookup now works as 'model/association.attribute'. 2011-12-05 15:39:41 +01:00
José Valim
2985151000 Merge pull request #3859 from kuroda/human_attribute_name
Fix human_attribute_name to handle names with dots
2011-12-05 06:09:33 -08:00
Tsutomu Kuroda
dff19f7be2 Fix human_attribute_name to handle names with dots
Nested I18n namespace lookup under activerecord.models is deprecated now (c19bd4f).
But when a model uses accepts_nested_attributes_for, its Errors object can have
an attribute name with "addresses.street" style. In this case, the dots should be
substituted with slashes so that we can provide the translation under the
"activemodel.attributes.person.addresses/street" key.
2011-12-05 22:57:47 +09:00
José Valim
5b2eb64ceb Revert "Implement ArraySerializer and move old serialization API to a new namespace."
This reverts commit 8896b4fdc8a543157cdf4dfc378607ebf6c10ab0.

Conflicts:

	activemodel/lib/active_model.rb
	activemodel/lib/active_model/serializable.rb
	activemodel/lib/active_model/serializer.rb
	activemodel/test/cases/serializer_test.rb
2011-11-30 18:48:17 +01:00
lest
6ce924fa9f fix method redefined warning in activemodel 2011-11-30 18:57:17 +03:00
Jon Leighton
8df787d428 Deprecated define_attr_method in ActiveModel::AttributeMethods
This only existed to support methods like `set_table_name` in Active
Record, which are themselves being deprecated.
2011-11-29 20:13:37 +00:00
Arun Agrawal
9817a8b7d6 Warning removed unused variable 2011-11-26 19:30:11 +05:30
José Valim
0a4035b12a Revert the serializers API as other alternatives are now also under discussion 2011-11-25 19:29:39 +00:00
José Valim
fcacc6986a Merge branch 'serializers'
This implements the ActiveModel::Serializer object. Includes code, tests, generators and guides.

From José and Yehuda with love.

Conflicts:
	railties/CHANGELOG.md
2011-11-25 09:59:35 +00:00
Jakub Kuźma
dc39af0a9a make ActiveModel::Name fail gracefully with anonymous classes 2011-11-24 15:50:21 +01:00
José Valim
28bcda4098 Rename UserSerializer to DefaultUserSerializer in tests. 2011-11-23 23:53:20 +00:00
José Valim
7fcc8c0a1f Rely solely on active_model_serializer and remove the fancy constant lookup. 2011-11-23 23:45:27 +00:00
José Valim
8896b4fdc8 Implement ArraySerializer and move old serialization API to a new namespace.
The following constants were renamed:

  ActiveModel::Serialization     => ActiveModel::Serializable
  ActiveModel::Serializers::JSON => ActiveModel::Serializable::JSON
  ActiveModel::Serializers::Xml  => ActiveModel::Serializable::XML

The main motivation for such a change is that `ActiveModel::Serializers::JSON`
was not actually a serializer, but a module that when included allows the target to be serializable to JSON.

With such changes, we were able to clean up the namespace to add true serializers as the ArraySerializer.
2011-11-23 23:18:15 +00:00
José Valim
e62de52aa3 Merge branch 'master' into serializers 2011-11-23 20:43:06 +00:00
José Valim
fd86a1b6b0 Rely on a public contract between railties instead of accessing railtie methods directly. 2011-11-23 19:06:45 +00: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
Jon Leighton
f140445b1d Revert "Merge pull request #2378 from cesario/remove_warnings_activemodel"
This reverts commit 6aaae3de277b572f37e09f16ae12737c3c87dfb7, reversing
changes made to fdbc4e5f4e5746ebf558485348c841b33f038fda.

Reason: build failure.
2011-11-05 17:21:58 +00:00
Vijay Dev
6aaae3de27 Merge pull request #2378 from cesario/remove_warnings_activemodel
Remove warnings by calling remove_method
2011-11-05 08:44:16 -07:00
Martin Svalin
c9ca86c29d New #added? method on ActiveModel::Errors
The #added? method makes it possible to check if a specific error has been added, using the same parameters as for #add.
2011-10-19 21:29:20 +02:00
Vijay Dev
8dffc62a9b use variables from test setup 2011-10-17 19:15:24 +05:30
Martin Svalin
180d4137ca ActiveModel::Errors#generate_message without i18n_scope, and more test cases for #add 2011-10-17 09:22:08 +02:00
Jose and Yehuda
afd7140b66 Remove 1.9 Hash syntax - tests passing on 1.8.7 2011-10-15 22:33:58 +02:00
Jose and Yehuda
2abb2e617a Add initial support for embed API 2011-10-15 19:22:16 +02:00
Jose and Yehuda
a230f040ff Add support for the root attribute 2011-10-15 18:56:47 +02:00
Jose and Yehuda
7a28498b55 Fix nil has_one association 2011-10-15 18:40:38 +02:00
Jose and Yehuda
322f47898e Add association_ids 2011-10-15 18:40:38 +02:00
Jose and Yehuda
22c322f056 Add support for overriding associations, mostly used for authorization 2011-10-15 18:40:38 +02:00
Jose and Yehuda
776da539d7 Add support for implicit serializers 2011-10-15 18:40:38 +02:00
Jose and Yehuda
2a4aaae72a Added has_one and has_many 2011-10-15 18:40:37 +02:00
Jose and Yehuda
e407dfb9bf Don't require serializable_hash to take options. 2011-10-15 18:40:37 +02:00
Jose and Yehuda
c3de52d7ed Initial implementation of ActiveModel::Serializer 2011-10-15 18:40:37 +02:00
zhengjia
1adf5662b5 Fixed serialization issues with multiple includes with options 2011-10-11 11:09:43 -05:00
Uģis Ozols
4015080efd One of the activemodel naming tests wasn't asserting anything. 2011-10-07 16:42:44 +03:00
José Valim
d4457dc32b Provide read_attribute_for_serialization as the API to serialize attributes. 2011-09-30 14:20:41 +02:00
Nicolás Hock Isaza
da914fa35c Fixing as_json method for ActiveRecord models.
When you've got an AR Model and you override the `as_json` method,
you should be able to add default options to the renderer, like this:

    class User < ActiveRecord::Base
      def as_json(options = {})
        super(options.merge(:except => [:password_digest]))
      end
    end

This was not possible before this commit. See the added test case.
2011-09-29 21:44:23 -05:00
Jon Leighton
a15424b92c Make serializable_hash take attr values directly from attributes hash.
Previously, it would use send() to get the attribute. In Active
Resource, this would rely on hitting method missing. If a method with
the same name was defined further up the ancestor chain, that method
would wrongly be called.

This change fixes test_to_xml_with_private_method_name_as_attribute in
activeresource/test/cases/base_test.rb, which was broken after
51bef9d8fb0b4da7a104425ab8545e9331387743, because that change made
to_xml use serializable_hash.
2011-09-26 12:40:03 +01:00
Matt Aimonetti
6e78bbea90 fixed a bug with the json serialization when the class setting is set to not include the root, but an instance is serialized with the root option passed as true 2011-09-22 14:05:25 -07:00
José Valim
51bef9d8fb to_xml should also rely on serializable hash. 2011-09-18 09:09:01 -07:00
Jon Leighton
778c82bea6 Generate attribute method unless it's already in the module.
There's no harm in generating a method name that's already defined on
the host class, since we're generating the attribute methods in a module
that gets included. In fact, this is desirable as it allows the host
class to call super.
2011-09-14 00:00:37 +01:00
Jon Leighton
c89e1c7bde Add an attribute_missing method to ActiveModel::AttributeMethods.
This can be overloaded by implementors if necessary.
2011-09-13 00:02:33 +01:00
Jon Leighton
ac687ed651 Let Ruby deal with method visibility.
Check respond_to_without_attributes? in method_missing. If there is any
method that responds (even private), let super handle it and raise
NoMethodError if necessary.
2011-09-13 00:01:58 +01:00
Jon Leighton
99bd6b53da Add deprecation for doing attribute_method_suffix '' 2011-09-13 00:01:57 +01:00
Jon Leighton
8b8b7143ef Use an empty AttributeMethodMatcher by default.
This means that attribute methods which don't exist will get generated
when define_attribute_methods is called, so we don't have to use hacks
like `attribute_method_suffix ''`.
2011-09-13 00:01:57 +01:00
Lawrence Pit
8817796167 Added test for obj.errors.as_json 2011-09-09 18:34:13 +10:00
Lawrence Pit
f5a944f662 Add ability to get an individual full error message + test for full_messages. 2011-09-09 18:28:25 +10:00
Damien Mathieu
e0335e2ccb add has_key? to ActiveModel::Errors 2011-09-06 18:36:18 +02:00
José Valim
d15069316f Merge pull request #2563 from bogdan/internal_validation
Implemented strict validation concept
2011-08-25 07:10:16 -07:00
Anand
56e32ad40f added more tests for only-include and except-include options in serialization 2011-08-23 16:03:58 +05:30
Bogdan Gusiev
8620bf90c5 Implemented strict validation concept
In order to deliver debug information to dev team
instead of display error message to end user
Implemented strict validation concept
that suppose to define validation that always raise exception when fails
2011-08-17 17:26:00 +03:00
Myron Marston
d3c15a1d31 Allow ActiveRecord observers to be disabled.
We have to use Observer#update rather than Observer#send since the enabled state is checked in #update before forwarding the method call on.
2011-08-12 20:48:44 -07:00
José Valim
6b3af028ac Merge pull request #2385 from bogdan/test_default_sanitizer2
MassAssignmentProtection: consider 'id' insensetive in StrictSanitizer
2011-08-01 04:50:06 -07:00
José Valim
dc8773b19f Rename new method to_path to to_partial_path to avoid conflicts with File#to_path and similar. 2011-08-01 11:42:00 +02:00
Franck Verrot
325fdfc928 Remove warnings by calling remove_method 2011-07-31 20:05:58 +02:00
Bogdan Gusiev
b93a918337 MassAssignmentProtection: consider 'id' insensetive in StrictSanitizer
In order to use StrictSanitizer in test mode
Consider :id as not sensetive attribute that can be filtered from
mass assignement without exception.
2011-07-28 11:56:08 +03:00
José Valim
1b7db58a06 Merge pull request #2034 from Casecommons/to_path
Allow ActiveModel-compatible instances to define their own partial paths
2011-07-28 00:50:07 -07:00
thedarkone
efe4cbe5f2 Handle the empty array correctly. 2011-07-27 18:07:47 +02:00
Grant Hutchins & Peter Jaros
bf812074fd Let ActiveModel instances define partial paths.
Deprecate ActiveModel::Name#partial_path. Now you
should call #to_path directly on ActiveModel
instances.
2011-07-25 16:05:24 -04:00
John Firebaugh
4860143ee4 ActiveModel support for the :include serialization option
This commit moves support for the :include serialization option for
serializing associated objects out of ActiveRecord in into ActiveModel.
The following methods support the :include option:

  * serializable_hash
  * to_json
  * to_xml

Instances must respond to methods named by the values of the :includes
array (or keys of the :includes hash). If an association method returns
an object that is_a?(Enumerable) (which AR has_many associations do), it
is assumed to be a collection association, and its elements must respond
to :serializable_hash. Otherwise it must respond to :serializable_hash
itself.

While here, fix #858, XmlSerializer should not singularize already
singular association names.
2011-07-17 11:34:07 -07:00
John Firebaugh
2a9a10f5e3 Add a test 2011-07-17 11:34:06 -07:00
John Firebaugh
da4e1faf6f serializable_hash(:only => [], :methods => [:foo]) should work 2011-07-17 11:34:06 -07:00
Joe Fiorini
ac5e691153 Enable passing root: false to #to_json 2011-07-01 23:00:13 -04:00
Ian Stewart
eafa174bfd changing an attribute multiple times retains the correct original value 2011-06-28 22:18:24 -07:00
Alexander Uvarov
528f405cdc Allow to specify mass-assignment roles as array 2011-06-23 12:56:39 +06:00
Santiago Pastorino
5599e3fa0c Merge pull request #1654 from ganeshkumar/test_cases
removed duplicate code in tests
2011-06-13 05:45:47 -07:00
ganesh
7c3094626d removed duplicate code 2011-06-11 21:49:12 +05:30
José Valim
410a42860b Get rid of the alternate namespace lookup. 2011-06-11 18:01:26 +02:00