From 9791bd13b9613d63b34079f7f657723a168324ce Mon Sep 17 00:00:00 2001 From: oleg dashevskii Date: Thu, 26 Aug 2010 11:22:27 +0700 Subject: [PATCH] Fix unwanted implicit readonly in Model.has_many_throughs.find(id) #first and #last methods were also affected. ReadOnlyTest now also loads all needed fixtures (:people and :readers were forgotten). The bug is a regression from 3.0.0 RC. --- .../associations/association_collection.rb | 2 +- activerecord/test/cases/readonly_test.rb | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 132e9cf..963aae9 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -58,7 +58,7 @@ module ActiveRecord merge_options_from_reflection!(options) construct_find_options!(options) - find_scope = construct_scope[:find].slice(:conditions, :order) + find_scope = construct_scope[:find].slice(:conditions, :order, :select) with_scope(:find => find_scope) do relation = @reflection.klass.send(:construct_finder_arel, options, @reflection.klass.send(:current_scoped_methods)) diff --git a/activerecord/test/cases/readonly_test.rb b/activerecord/test/cases/readonly_test.rb index 98011f4..47e5eb5 100644 --- a/activerecord/test/cases/readonly_test.rb +++ b/activerecord/test/cases/readonly_test.rb @@ -12,7 +12,7 @@ def Project.foo() find :first end class ReadOnlyTest < ActiveRecord::TestCase - fixtures :posts, :comments, :developers, :projects, :developers_projects + fixtures :posts, :comments, :developers, :projects, :developers_projects, :people, :readers def test_cant_save_readonly_record dev = Developer.find(1) @@ -68,9 +68,25 @@ class ReadOnlyTest < ActiveRecord::TestCase def test_has_many_with_through_is_not_implicitly_marked_readonly assert people = Post.find(1).people + assert !people.empty? assert !people.any?(&:readonly?) end + def test_has_many_with_through_is_not_implicitly_marked_readonly_while_finding_by_id + assert person = Post.find(1).people.find(1) + assert !person.readonly? + end + + def test_has_many_with_through_is_not_implicitly_marked_readonly_while_finding_first + assert person = Post.find(1).people.first + assert !person.readonly? + end + + def test_has_many_with_through_is_not_implicitly_marked_readonly_while_finding_last + assert person = Post.find(1).people.first + assert !person.readonly? + end + def test_readonly_scoping Post.send(:with_scope, :find => { :conditions => '1=1' }) do assert !Post.find(1).readonly? -- 1.7.0.4