1. 24 6月, 2012 3 次提交
  2. 23 6月, 2012 6 次提交
  3. 22 6月, 2012 9 次提交
  4. 16 6月, 2012 2 次提交
  5. 15 6月, 2012 1 次提交
  6. 12 6月, 2012 1 次提交
  7. 10 6月, 2012 1 次提交
  8. 08 6月, 2012 1 次提交
  9. 06 6月, 2012 1 次提交
    • F
      change AMS::JSON.include_root_in_json default value to false · ab11a278
      Francesco Rodriguez 提交于
      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.
      ab11a278
  10. 31 5月, 2012 1 次提交
  11. 28 5月, 2012 1 次提交
    • S
      Don't enable validations when passing false hash values to ActiveModel.validates · b3ccd7b2
      Steve Purcell 提交于
      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.)
      b3ccd7b2
  12. 25 5月, 2012 1 次提交
  13. 24 5月, 2012 1 次提交
    • V
      Revert "Remove blank trailing comments" · 1ad0b378
      Vijay Dev 提交于
      This reverts commit fa6d921e.
      
      Reason: Not a fan of such massive changes. We usually close such changes
      if made to Rails master as a pull request. Following the same principle
      here and reverting.
      
      [ci skip]
      1ad0b378
  14. 23 5月, 2012 1 次提交
  15. 21 5月, 2012 1 次提交
  16. 20 5月, 2012 1 次提交
    • H
      Remove blank trailing comments · fa6d921e
      Henrik Hodne 提交于
      For future reference, this is the regex I used: ^\s*#\s*\n(?!\s*#). Replace
      with the first match, and voilà! Note that the regex matches a little bit too
      much, so you probably want to `git add -i .` and go through every single diff
      to check if it actually should be changed.
      fa6d921e
  17. 18 5月, 2012 1 次提交
  18. 17 5月, 2012 1 次提交
  19. 16 5月, 2012 6 次提交