Commit Graph

51 Commits

Author SHA1 Message Date
Vipul A M
29dcf096b0 Small typos here and there. 2013-03-15 11:55:03 +05:30
Carlos Antonio da Silva
b3a31e9363 Fix AMo code example indent, add missing author to entry [ci skip] 2013-03-09 14:57:31 -03:00
Yves Senn
8c1687bbf8 has_secure_password is not invalid when assigning empty Strings.
Closes #9535.

With 692b3b6 the `password=` setter does no longer set blank passwords.
This triggered validation errors when assigning empty Strings to `password`
and `password_confirmation`.

This patch only sets the confirmation if it is not `blank?`.
2013-03-04 18:56:05 +01:00
Yves Senn
b501ee47fa validates_confirmation_of does not override writer methods. 2013-03-04 18:51:34 +01:00
Rafael Mendonça França
0f75e2c51f Update CHANGELOGS 2013-02-26 13:45:57 -03:00
David Heinemeier Hansson
c0bc9ce38c Preparing for 4.0.0.beta1 release 2013-02-25 08:31:50 -06:00
Xavier Noria
05857ec30e did a pass over the AM changelog [ci skip] 2013-02-24 20:37:15 +01:00
Rafael Mendonça França
b05819fd28 This change doesn't need a CHANGELOG entry.
[ci skip]
2012-12-26 20:39:32 -03: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
bda1937f28 Remove CHANGELOG entry for ActiveModel::Errors#add_on_present 2012-12-21 17:10:41 -03:00
Carlos Antonio da Silva
42b555dcf3 Fix Action Mailer changelog indenation to match other changelogs
Also some minor improvements to other changelogs. [ci skip]
2012-12-19 23:09:04 -02:00
Carlos Antonio da Silva
05b80a1cce Improve AMo changelog example to not rely on AR [ci skip] 2012-12-19 23:03:32 -02: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
Carlos Antonio da Silva
df9f9b7f3e Convert changelogs to 1.9 hash style and fix some formatting [ci skip] 2012-12-14 20:25:22 -02:00
Renato Mascarenhas
cf7ab6056a Reset attributes should not report changes.
When resetting an attribute, you expect it to return to the state it was
before any changes. Namely, this fixes this unexpected behavior:

~~~ruby
model.name = "Bob"
model.reset_name!
model.name_changed? #=> true
~~~
2012-12-01 16:58:09 -02:00
Rafael Mendonça França
ec17f0d352 Add CHANGELOG entries for the observes extraction
[ci skip]
2012-11-29 01:08:36 -02:00
Steve Klabnik
9504b44cf6 Specify type of singular association during serialization
When serialising a class, specify the type of any singular associations, if
necessary. Rails already correctly specifies the :type of any enumerable
association (e.g. a has_many association), but made no attempt to do so for
non-enumerables (e.g. a has_one association).
We must specify the :type of any STI association. A has_one
association to a class which uses single-table inheritance is an example of
this type of association.

Fixes #7471
2012-11-28 11:48:32 -08:00
Rafael Mendonça França
5658923daa Merge pull request #7282 from xHire/validates_length_of_fix
Length validation handles correctly nil. Fix #7180

Conflicts:
	activemodel/CHANGELOG.md
2012-11-26 18:44:07 -02: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
Yves Senn
22598ee599 cleanup, removed dispensable require statements from ActiveModel 2012-11-25 17:08:57 +01:00
Trevor Turk
06faa6da80 Use BCrypt's MIN_COST in the test environment for speedier tests 2012-11-14 09:42:54 -06:00
Jan Berdajs
a774354dfe add credit to committer of pull request #6569 2012-10-18 16:29:17 +02:00
Rafael Mendonça França
86062005a7 Revert "Merge pull request #7826 from sikachu/master-validators-kind"
This reverts commit 4e9f53f9736544f070e75e516c71137b7eb49a7a, reversing
changes made to 6b802cdb4f5b84e1bf49aaeb0e994b3be6028af9.

Revert "Don't use tap in this case."

This reverts commit 454d820bf0a18fe1db4c55b0145197d70fef1f82.

Reason: Is not a good idea to add options to this method since we can do
the same thing using method composition.

    Person.validators_on(:name).select { |v| v.kind == :presence }

Also it avoids to change the method again to add more options.
2012-10-02 23:57:00 -03:00
Prem Sichanugrist
4f9b59dba0 Make .validators_on accept :kind option
This will filter out the validators on a particular attribute based on
its kind.
2012-10-02 22:09:06 -04:00
Guillermo Iguaran
1f4c89fbde Update changelogs to add entries about strong_parameters integration 2012-09-19 17:50:39 -05:00
Carlos Antonio da Silva
0180e090ab Update Active Model xml serialization test to reflect a change in builder
Due to a change in builder, nil values and empty strings now generates
closed tags, so instead of this:

    <pseudonyms nil=\"true\"></pseudonyms>

It generates this:

    <pseudonyms nil=\"true\"/>

Document this change in Rails so that people can track it down easily if
necessary.
2012-09-07 13:08:30 -03:00
Xavier Noria
810a50dacf CHANGELOGs are now per branch
Changes in old branches needed to be manually synched in CHANGELOGs of newer ones.
This has proven to be brittle, sometimes one just forgets this manual step.
With this commit we switch to CHANGELOGs per branch. When a new major version is
cut from master, the CHANGELOGs in master start being blank.

A link to the CHANGELOG of the previous branch allows anyone interested to
follow the history.
2012-08-28 21:15:16 +02:00
Gabriel Sobrinho
2f3eb484f2 Accept a symbol for :in option on inclusion and exclusion validators 2012-08-24 15:26:17 -03:00
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
Rafael Mendonça França
8781b266b9 Sync CHANGELOGs [ci skip] 2012-08-11 13:13:58 -03:00
Bogdan Gusiev
2e4f7986b8 AM::Validation#validates: ability to pass custom exception to :strict option 2012-08-06 13:45:27 +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
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
Rafael Mendonça França
3449b757da Sync CHANGLOG with the 3-2-stable branch 2012-06-01 11:41:30 -03: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
Brian Cardarella
3a749a9bd1 Reordered changelog entry 2012-04-23 21:30:24 -04:00
Brian Cardarella
d32cbee2b3 Updated CHANGELOG 2012-04-23 21:04:10 -04:00
Rafael Mendonça França
d804790634 Fix my name in the CHANGELOG to follow the convention
Also add missing entries and use the formating convention
2012-03-09 00:54:21 -03:00
Vijay Dev
db6542178c changelog updates for Rails 4 [ci skip] 2012-03-09 02:22:17 +05:30
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
claudiob
05c6caf48c Add release dates to documentation
Set "March 1, 2012" as the release date for 3.2.2, 3.1.4, 3.0.12
2012-03-01 11:20:03 -08:00
Paco Guzman
152a393d4f Update changelogs with rails 3.0-stable branch info 2012-02-25 13:50:08 +01:00
Bogdan Gusiev
534dc4ca1a AM::Errors: allow :full_messages parameter for #as_json 2012-02-20 11:17:11 +02:00
José Valim
a17d047a73 Trim down Active Model API by removing valid? and errors.full_messages 2012-02-07 23:10:43 +01:00
claudiob
6d426b1035 Add release date of Rails 3.2.0 to documentation 2012-01-26 01:53:38 -08: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
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
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
696d01f7f4 Add docs to serializers. Update CHANGELOGs. 2011-11-25 09:49:54 +00:00