diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-08-03 13:59:34 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-08-03 13:59:34 -0300 |
commit | 31c83534d61cad2203ae57087442caedb4dbf22a (patch) | |
tree | 43f5c75abe5a3169956a47a3c5ca163aea7c0992 | |
parent | 62296a51c80b93fedcae896a534862687c8fef94 (diff) | |
download | rails-31c83534d61cad2203ae57087442caedb4dbf22a.tar.gz rails-31c83534d61cad2203ae57087442caedb4dbf22a.tar.bz2 rails-31c83534d61cad2203ae57087442caedb4dbf22a.zip |
Don't use local vars before testing its conditional.
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 12 | ||||
-rw-r--r-- | activerecord/test/cases/associations/eager_load_nested_include_test.rb | 2 |
2 files changed, 6 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 2b50333682..2f1f6175af 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1068,7 +1068,7 @@ module ActiveRecord #:nodoc: # If the access logic of your application is richer you can use <tt>Hash#except</tt> # or <tt>Hash#slice</tt> to sanitize the hash of parameters before they are # passed to Active Record. - # + # # For example, it could be the case that the list of protected attributes # for a given model depends on the role of the user: # @@ -1116,7 +1116,7 @@ module ActiveRecord #:nodoc: # If the access logic of your application is richer you can use <tt>Hash#except</tt> # or <tt>Hash#slice</tt> to sanitize the hash of parameters before they are # passed to Active Record. - # + # # For example, it could be the case that the list of accessible attributes # for a given model depends on the role of the user: # @@ -2968,14 +2968,14 @@ module ActiveRecord #:nodoc: attrs = {} attribute_names.each do |name| if (column = column_for_attribute(name)) && (include_primary_key || !column.primary) - value = read_attribute(name) if include_readonly_attributes || (!include_readonly_attributes && !self.class.readonly_attributes.include?(name)) - # We need explicit to_yaml because quote() does not properly convert Time/Date fields to YAML. - if value && self.class.serialized_attributes.has_key?(name) && (value.acts_like?(:date) || value.acts_like?(:time)) + value = read_attribute(name) + + if value && ((self.class.serialized_attributes.has_key?(name) && (value.acts_like?(:date) || value.acts_like?(:time))) || value.is_a?(Hash) || value.is_a?(Array)) value = value.to_yaml end - attrs[arel_table[name]] = (value.is_a?(Hash) || value.is_a?(Array)) ? value.to_yaml : value + attrs[arel_table[name]] = value end end end diff --git a/activerecord/test/cases/associations/eager_load_nested_include_test.rb b/activerecord/test/cases/associations/eager_load_nested_include_test.rb index f313a75233..e8db6d5dab 100644 --- a/activerecord/test/cases/associations/eager_load_nested_include_test.rb +++ b/activerecord/test/cases/associations/eager_load_nested_include_test.rb @@ -72,10 +72,8 @@ class EagerLoadPolyAssocsTest < ActiveRecord::TestCase ShapeExpression, NonPolyOne, NonPolyTwo].each do |c| c.delete_all end - end - def generate_test_object_graphs 1.upto(NUM_SIMPLE_OBJS) do [Circle, Square, Triangle, NonPolyOne, NonPolyTwo].map(&:create!) |