Commit Graph

358 Commits

Author SHA1 Message Date
Rafael Mendonça França
cfd7f4e9a0 Merge pull request #7024 from bogdan/strict_validation_custom_exception
AM::Validation#validates: custom exception for :strict option

Conflicts:
	activemodel/CHANGELOG.md
2012-08-16 16:59:04 -03:00
Anthony
78f5874c82 Following the false issue reporting I did here : https://github.com/rails/rails/issues/6958
- Enable propagation of :skip_types, :dasherize and :camelize on included models by default
- Adding the option to override this propagation on a per-include basis (:include => { :model => { :dasherize => false } }
- Enough tests to prove it works
- Updated activemodel CHANGELOG.md

Squashed my commits
2012-08-13 19:14:24 -07:00
Bogdan Gusiev
2e4f7986b8 AM::Validation#validates: ability to pass custom exception to :strict option 2012-08-06 13:45:27 +03:00
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