From c140a27fc55e294a130b874f075748c5cd03de1e Mon Sep 17 00:00:00 2001 From: ayaya Date: Tue, 31 Jan 2012 18:43:54 +0800 Subject: fix `alias_attribute` will raise a syntax error if make an alias on a column that named as a ruby keyword --- activemodel/lib/active_model/attribute_methods.rb | 8 ++++---- activemodel/test/cases/attribute_methods_test.rb | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'activemodel') diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb index 97a83e58af..dc4423d488 100644 --- a/activemodel/lib/active_model/attribute_methods.rb +++ b/activemodel/lib/active_model/attribute_methods.rb @@ -184,7 +184,7 @@ module ActiveModel attribute_method_matchers.each do |matcher| matcher_new = matcher.method_name(new_name).to_s matcher_old = matcher.method_name(old_name).to_s - define_optimized_call self, matcher_new, matcher_old + define_proxy_call false, self, matcher_new, matcher_old end end @@ -226,7 +226,7 @@ module ActiveModel if respond_to?(generate_method, true) send(generate_method, attr_name) else - define_optimized_call generated_attribute_methods, method_name, matcher.method_missing_target, attr_name.to_s + define_proxy_call true, generated_attribute_methods, method_name, matcher.method_missing_target, attr_name.to_s end end end @@ -285,7 +285,7 @@ module ActiveModel # Define a method `name` in `mod` that dispatches to `send` # using the given `extra` args. This fallbacks `define_method` # and `send` if the given names cannot be compiled. - def define_optimized_call(mod, name, send, *extra) #:nodoc: + def define_proxy_call(include_private, mod, name, send, *extra) #:nodoc: if name =~ NAME_COMPILABLE_REGEXP defn = "def #{name}(*args)" else @@ -295,7 +295,7 @@ module ActiveModel extra = (extra.map(&:inspect) << "*args").join(", ") if send =~ CALL_COMPILABLE_REGEXP - target = "#{send}(#{extra})" + target = "#{"self." unless include_private}#{send}(#{extra})" else target = "send(:'#{send}', #{extra})" end diff --git a/activemodel/test/cases/attribute_methods_test.rb b/activemodel/test/cases/attribute_methods_test.rb index 34298d31c2..efbf2db1eb 100644 --- a/activemodel/test/cases/attribute_methods_test.rb +++ b/activemodel/test/cases/attribute_methods_test.rb @@ -76,6 +76,19 @@ private end end +class ModelWithRubyKeywordNamedAttributes + include ActiveModel::AttributeMethods + + def attributes + { :begin => 'value of begin', :end => 'value of end' } + end + +private + def attribute(name) + attributes[name.to_sym] + end +end + class ModelWithoutAttributesMethod include ActiveModel::AttributeMethods end @@ -148,6 +161,15 @@ class AttributeMethodsTest < ActiveModel::TestCase assert_equal "value of foo bar", ModelWithAttributesWithSpaces.new.foo_bar end + test '#alias_attribute works with attributes named as a ruby keyword' do + ModelWithRubyKeywordNamedAttributes.define_attribute_methods([:begin, :end]) + ModelWithRubyKeywordNamedAttributes.alias_attribute(:from, :begin) + ModelWithRubyKeywordNamedAttributes.alias_attribute(:to, :end) + + assert_equal "value of begin", ModelWithRubyKeywordNamedAttributes.new.from + assert_equal "value of end", ModelWithRubyKeywordNamedAttributes.new.to + end + test '#undefine_attribute_methods removes attribute methods' do ModelWithAttributes.define_attribute_methods([:foo]) ModelWithAttributes.undefine_attribute_methods -- cgit v1.2.3 From 42d0b1c8ddab9c3ffa8951bf085f5c758673e94b Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Mon, 2 Apr 2012 16:41:43 +0300 Subject: Call undefine_attribute_methods only when defining new attributes --- activemodel/lib/active_model/attribute_methods.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'activemodel') diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb index 99918fdb96..039cd8bdf3 100644 --- a/activemodel/lib/active_model/attribute_methods.rb +++ b/activemodel/lib/active_model/attribute_methods.rb @@ -102,7 +102,6 @@ module ActiveModel # person.name # => nil def attribute_method_prefix(*prefixes) self.attribute_method_matchers += prefixes.map { |prefix| AttributeMethodMatcher.new :prefix => prefix } - undefine_attribute_methods end # Declares a method available for all attributes with the given suffix. @@ -139,7 +138,6 @@ module ActiveModel # person.name_short? # => true def attribute_method_suffix(*suffixes) self.attribute_method_matchers += suffixes.map { |suffix| AttributeMethodMatcher.new :suffix => suffix } - undefine_attribute_methods end # Declares a method available for all attributes with the given prefix @@ -177,7 +175,6 @@ module ActiveModel # person.name # => 'Gemma' def attribute_method_affix(*affixes) self.attribute_method_matchers += affixes.map { |affix| AttributeMethodMatcher.new :prefix => affix[:prefix], :suffix => affix[:suffix] } - undefine_attribute_methods end @@ -225,6 +222,7 @@ module ActiveModel # end # end def define_attribute_methods(*attr_names) + undefine_attribute_methods attr_names.flatten.each { |attr_name| define_attribute_method(attr_name) } end -- cgit v1.2.3 From 08a5b10eb1c750927c05e50f182e070c1321fb81 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sun, 20 May 2012 11:11:20 -0700 Subject: Revert "Merge pull request #5702 from oscardelben/patch-4" This reverts commit cae1ca7d1be9c79c7ef012a1f62aef9d3bb815f8, reversing changes made to da97cf016a8ffd1f54f804cd881f393e5d6efc18. These changes break the build, it needs more investigation. --- activemodel/lib/active_model/attribute_methods.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activemodel') diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb index 039cd8bdf3..99918fdb96 100644 --- a/activemodel/lib/active_model/attribute_methods.rb +++ b/activemodel/lib/active_model/attribute_methods.rb @@ -102,6 +102,7 @@ module ActiveModel # person.name # => nil def attribute_method_prefix(*prefixes) self.attribute_method_matchers += prefixes.map { |prefix| AttributeMethodMatcher.new :prefix => prefix } + undefine_attribute_methods end # Declares a method available for all attributes with the given suffix. @@ -138,6 +139,7 @@ module ActiveModel # person.name_short? # => true def attribute_method_suffix(*suffixes) self.attribute_method_matchers += suffixes.map { |suffix| AttributeMethodMatcher.new :suffix => suffix } + undefine_attribute_methods end # Declares a method available for all attributes with the given prefix @@ -175,6 +177,7 @@ module ActiveModel # person.name # => 'Gemma' def attribute_method_affix(*affixes) self.attribute_method_matchers += affixes.map { |affix| AttributeMethodMatcher.new :prefix => affix[:prefix], :suffix => affix[:suffix] } + undefine_attribute_methods end @@ -222,7 +225,6 @@ module ActiveModel # end # end def define_attribute_methods(*attr_names) - undefine_attribute_methods attr_names.flatten.each { |attr_name| define_attribute_method(attr_name) } end -- cgit v1.2.3 From 38293ea828ab52043fceecbdc96946b5bc9bb0e5 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 22 May 2012 11:01:16 -0300 Subject: require active_support/lazy_load_hooks where is needed --- activemodel/lib/active_model.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activemodel') diff --git a/activemodel/lib/active_model.rb b/activemodel/lib/active_model.rb index ded1b752df..451f3e4742 100644 --- a/activemodel/lib/active_model.rb +++ b/activemodel/lib/active_model.rb @@ -22,6 +22,7 @@ #++ require 'active_support' +require 'active_support/lazy_load_hooks' require 'active_model/version' module ActiveModel -- cgit v1.2.3 From 344ea048659f2ba47012f0330183ea4a96752732 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 22 May 2012 12:10:35 -0300 Subject: Fix the build --- activemodel/lib/active_model.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'activemodel') diff --git a/activemodel/lib/active_model.rb b/activemodel/lib/active_model.rb index 451f3e4742..ded1b752df 100644 --- a/activemodel/lib/active_model.rb +++ b/activemodel/lib/active_model.rb @@ -22,7 +22,6 @@ #++ require 'active_support' -require 'active_support/lazy_load_hooks' require 'active_model/version' module ActiveModel -- cgit v1.2.3 From 5646d65d01845adf669b9e6c4899b6ac15849bb9 Mon Sep 17 00:00:00 2001 From: Angelo capilleri Date: Wed, 23 May 2012 09:59:13 +0200 Subject: 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 --- activemodel/lib/active_model/serializers/xml.rb | 2 +- activemodel/test/cases/serializers/xml_serialization_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'activemodel') diff --git a/activemodel/lib/active_model/serializers/xml.rb b/activemodel/lib/active_model/serializers/xml.rb index b78f1ff3f3..2b3e9ce134 100644 --- a/activemodel/lib/active_model/serializers/xml.rb +++ b/activemodel/lib/active_model/serializers/xml.rb @@ -172,7 +172,7 @@ module ActiveModel # 1 # David # 16 - # 2011-01-30T22:29:23Z + # 2011-01-30T22:29:23Z # # # The :only and :except options can be used to limit the attributes diff --git a/activemodel/test/cases/serializers/xml_serialization_test.rb b/activemodel/test/cases/serializers/xml_serialization_test.rb index 5fa227e0e0..7eb48abc3c 100644 --- a/activemodel/test/cases/serializers/xml_serialization_test.rb +++ b/activemodel/test/cases/serializers/xml_serialization_test.rb @@ -140,7 +140,7 @@ class XmlSerializationTest < ActiveModel::TestCase end test "should serialize datetime" do - assert_match %r{2006-08-01T00:00:00Z}, @contact.to_xml + assert_match %r{2006-08-01T00:00:00Z}, @contact.to_xml end test "should serialize boolean" do -- cgit v1.2.3 From 6c7b250ac0292001e293ee19157f3d58b7553f41 Mon Sep 17 00:00:00 2001 From: Matt Griffin Date: Fri, 21 Oct 2011 14:24:33 -0400 Subject: Add license field to gemspecs, by Matt Griffin --- activemodel/activemodel.gemspec | 1 + 1 file changed, 1 insertion(+) (limited to 'activemodel') diff --git a/activemodel/activemodel.gemspec b/activemodel/activemodel.gemspec index f2d004fb0a..66f324a1a1 100644 --- a/activemodel/activemodel.gemspec +++ b/activemodel/activemodel.gemspec @@ -8,6 +8,7 @@ Gem::Specification.new do |s| s.description = 'A toolkit for building modeling frameworks like Active Record. Rich support for attributes, callbacks, validations, observers, serialization, internationalization, and testing.' s.required_ruby_version = '>= 1.9.3' + s.license = 'MIT' s.author = 'David Heinemeier Hansson' s.email = 'david@loudthinking.com' -- cgit v1.2.3 From b98a343da5b9fd6a6ffa7eeac42c141f5b64e961 Mon Sep 17 00:00:00 2001 From: Edward Tsech Date: Fri, 25 May 2012 16:34:34 +0200 Subject: Add comment for attr_accessible/attr_protected :as option. [ci skip] --- activemodel/lib/active_model/mass_assignment_security.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activemodel') diff --git a/activemodel/lib/active_model/mass_assignment_security.rb b/activemodel/lib/active_model/mass_assignment_security.rb index 893fbf92c3..cfce1542b1 100644 --- a/activemodel/lib/active_model/mass_assignment_security.rb +++ b/activemodel/lib/active_model/mass_assignment_security.rb @@ -62,7 +62,7 @@ module ActiveModel # Attributes named in this macro are protected from mass-assignment # whenever attributes are sanitized before assignment. A role for the # attributes is optional, if no role is provided then :default is used. - # A role can be defined by using the :as option. + # A role can be defined by using the :as option with a symbol or an array of symbols as the value. # # Mass-assignment to these attributes will simply be ignored, to assign # to them you can use direct writer methods. This is meant to protect @@ -128,7 +128,7 @@ module ActiveModel # # Like +attr_protected+, a role for the attributes is optional, # if no role is provided then :default is used. A role can be defined by - # using the :as option. + # using the :as option with a symbol or an array of symbols as the value. # # This is the opposite of the +attr_protected+ macro: Mass-assignment # will only set attributes in this list, to assign to the rest of -- cgit v1.2.3