diff options
-rw-r--r-- | actionpack/lib/action_controller/resources.rb | 6 | ||||
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb | 1 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_association.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb | 6 | ||||
-rw-r--r-- | activerecord/test/cases/associations/has_many_through_associations_test.rb | 6 | ||||
-rw-r--r-- | activerecord/test/models/author.rb | 1 | ||||
-rw-r--r-- | activerecord/test/models/category.rb | 1 | ||||
-rw-r--r-- | activerecord/test/models/person.rb | 2 | ||||
-rw-r--r-- | railties/CHANGELOG | 6 | ||||
-rw-r--r-- | railties/lib/initializer.rb | 8 | ||||
-rw-r--r-- | railties/lib/rails/gem_dependency.rb | 6 | ||||
-rw-r--r-- | railties/lib/rails/plugin.rb | 21 | ||||
-rw-r--r-- | railties/lib/rails/plugin/locator.rb | 7 | ||||
-rw-r--r-- | railties/test/plugin_loader_test.rb | 2 |
15 files changed, 52 insertions, 25 deletions
diff --git a/actionpack/lib/action_controller/resources.rb b/actionpack/lib/action_controller/resources.rb index 9fb1f9fa39..af2fcaf3ad 100644 --- a/actionpack/lib/action_controller/resources.rb +++ b/actionpack/lib/action_controller/resources.rb @@ -72,7 +72,7 @@ module ActionController end def conditions - @conditions = @options[:conditions] || {} + @conditions ||= @options[:conditions] || {} end def path @@ -80,9 +80,9 @@ module ActionController end def new_path - new_action = self.options[:path_names][:new] if self.options[:path_names] + new_action = self.options[:path_names][:new] if self.options[:path_names] new_action ||= Base.resources_path_names[:new] - @new_path ||= "#{path}/#{new_action}" + @new_path ||= "#{path}/#{new_action}" end def member_path diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 5f42b5a459..db99b7165d 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1514,7 +1514,7 @@ module ActiveRecord end def order_tables(options) - order = options[:order] + order = [options[:order], scope(:find, :order) ].join(", ") return [] unless order && order.is_a?(String) order.scan(/([\.\w]+).?\./).flatten end diff --git a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb index 4fa8e9d0a8..918404eac6 100644 --- a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb +++ b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb @@ -87,6 +87,7 @@ module ActiveRecord :joins => @join_sql, :readonly => false, :order => @reflection.options[:order], + :include => @reflection.options[:include], :limit => @reflection.options[:limit] } } end diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index f584a97cbb..295beb2966 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -100,7 +100,7 @@ module ActiveRecord create_scoping = {} set_belongs_to_association_for(create_scoping) { - :find => { :conditions => @finder_sql, :readonly => false, :order => @reflection.options[:order], :limit => @reflection.options[:limit] }, + :find => { :conditions => @finder_sql, :readonly => false, :order => @reflection.options[:order], :limit => @reflection.options[:limit], :include => @reflection.options[:include]}, :create => create_scoping } end diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb index 294b993c55..b29df68d22 100644 --- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb @@ -681,4 +681,10 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase assert_equal developer, project.developers.find(:first) assert_equal project, developer.projects.find(:first) end + + def test_dynamic_find_should_respect_association_include + # SQL error in sort clause if :include is not included + # due to Unknown column 'authors.id' + assert Category.find(1).posts_with_authors_sorted_by_author_id.find_by_title('Welcome to the weblog') + end end diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index 05155f6303..be5170f830 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -187,4 +187,10 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase post.people_with_callbacks.clear assert_equal (%w(Michael David Julian Roger) * 2).sort, log.last(8).collect(&:last).sort end + + def test_dynamic_find_should_respect_association_include + # SQL error in sort clause if :include is not included + # due to Unknown column 'comments.id' + assert Person.find(1).posts_with_comments_sorted_by_comment_id.find_by_title('Welcome to the weblog') + end end diff --git a/activerecord/test/models/author.rb b/activerecord/test/models/author.rb index f63af27403..82e069005a 100644 --- a/activerecord/test/models/author.rb +++ b/activerecord/test/models/author.rb @@ -1,6 +1,7 @@ class Author < ActiveRecord::Base has_many :posts has_many :posts_with_comments, :include => :comments, :class_name => "Post" + has_many :posts_with_comments_sorted_by_comment_id, :include => :comments, :class_name => "Post", :order => 'comments.id' has_many :posts_with_categories, :include => :categories, :class_name => "Post" has_many :posts_with_comments_and_categories, :include => [ :comments, :categories ], :order => "posts.id", :class_name => "Post" has_many :posts_containing_the_letter_a, :class_name => "Post" diff --git a/activerecord/test/models/category.rb b/activerecord/test/models/category.rb index f1d2e4805a..1660c61682 100644 --- a/activerecord/test/models/category.rb +++ b/activerecord/test/models/category.rb @@ -2,6 +2,7 @@ class Category < ActiveRecord::Base has_and_belongs_to_many :posts has_and_belongs_to_many :special_posts, :class_name => "Post" has_and_belongs_to_many :other_posts, :class_name => "Post" + has_and_belongs_to_many :posts_with_authors_sorted_by_author_id, :class_name => "Post", :include => :authors, :order => "authors.id" has_and_belongs_to_many(:select_testing_posts, :class_name => 'Post', diff --git a/activerecord/test/models/person.rb b/activerecord/test/models/person.rb index 4f4d695b24..430d0b38f7 100644 --- a/activerecord/test/models/person.rb +++ b/activerecord/test/models/person.rb @@ -6,5 +6,5 @@ class Person < ActiveRecord::Base has_many :references has_many :jobs, :through => :references has_one :favourite_reference, :class_name => 'Reference', :conditions => ['favourite=?', true] - + has_many :posts_with_comments_sorted_by_comment_id, :through => :readers, :source => :post, :include => :comments, :order => 'comments.id' end diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 913bb365ac..27d4313862 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,11 @@ *Edge* +* Add the gem load paths before the framework is loaded, so certain gems like RedCloth and BlueCloth can be frozen. + +* Fix discrepancies with loading rails/init.rb from gems. + +* Plugins check for the gem init path (rails/init.rb) before the standard plugin init path (init.rb) [Jacek Becela] + * Changed all generated tests to use the test/do declaration style [DHH] * Wrapped Rails.env in StringInquirer so you can do Rails.env.development? [DHH] diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index f0b5e3f257..3d94cedb47 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -113,10 +113,10 @@ module Rails check_ruby_version install_gem_spec_stubs set_load_path - + add_gem_load_paths + require_frameworks set_autoload_paths - add_gem_load_paths add_plugin_load_paths load_environment @@ -242,12 +242,12 @@ module Rails def add_gem_load_paths unless @configuration.gems.empty? require "rubygems" - @configuration.gems.each &:add_load_paths + @configuration.gems.each { |gem| gem.add_load_paths } end end def load_gems - @configuration.gems.each(&:load) + @configuration.gems.each { |gem| gem.load } end def check_gem_dependencies diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb index 4cac7f725a..f8d97840c1 100644 --- a/railties/lib/rails/gem_dependency.rb +++ b/railties/lib/rails/gem_dependency.rb @@ -23,9 +23,13 @@ module Rails @unpack_directory = nil end + def unpacked_paths + Dir[File.join(self.class.unpacked_path, "#{@name}-#{@version || "*"}")] + end + def add_load_paths return if @loaded || @load_paths_added - unpacked_paths = Dir[File.join(self.class.unpacked_path, "#{@name}-#{@version || "*"}")] + unpacked_paths = self.unpacked_paths if unpacked_paths.empty? args = [@name] args << @requirement.to_s if @requirement diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index a54ab85dbe..b8b2b57038 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -95,14 +95,14 @@ module Rails end def evaluate_init_rb(initializer) - if has_init_file? - silence_warnings do - # Allow plugins to reference the current configuration object - config = initializer.configuration - - eval(IO.read(init_path), binding, init_path) - end - end + if has_init_file? + silence_warnings do + # Allow plugins to reference the current configuration object + config = initializer.configuration + + eval(IO.read(init_path), binding, init_path) + end + end end end @@ -111,8 +111,9 @@ module Rails # to Dependencies.load_paths. class GemPlugin < Plugin # Initialize this plugin from a Gem::Specification. - def initialize(spec) - super(File.join(spec.full_gem_path)) + def initialize(spec, gem) + directory = (gem.frozen? && gem.unpacked_paths.first) || File.join(spec.full_gem_path) + super(directory) @name = spec.name end diff --git a/railties/lib/rails/plugin/locator.rb b/railties/lib/rails/plugin/locator.rb index f06a51a572..79c07fccd1 100644 --- a/railties/lib/rails/plugin/locator.rb +++ b/railties/lib/rails/plugin/locator.rb @@ -78,8 +78,9 @@ module Rails # a <tt>rails/init.rb</tt> file. class GemLocator < Locator def plugins - specs = initializer.configuration.gems.map(&:specification) - specs += Gem.loaded_specs.values.select do |spec| + gem_index = initializer.configuration.gems.inject({}) { |memo, gem| memo.update gem.specification => gem } + specs = gem_index.keys + specs += Gem.loaded_specs.values.select do |spec| spec.loaded_from && # prune stubs File.exist?(File.join(spec.full_gem_path, "rails", "init.rb")) end @@ -91,7 +92,7 @@ module Rails deps.add(*specs) unless specs.empty? deps.dependency_order.collect do |spec| - Rails::GemPlugin.new(spec) + Rails::GemPlugin.new(spec, gem_index[spec]) end end end diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb index e5fc0926eb..f429bae15c 100644 --- a/railties/test/plugin_loader_test.rb +++ b/railties/test/plugin_loader_test.rb @@ -94,7 +94,7 @@ uses_mocha "Plugin Loader Tests" do def test_should_add_plugin_load_paths_to_global_LOAD_PATH_array only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] - stubbed_application_lib_index_in_LOAD_PATHS = 5 + stubbed_application_lib_index_in_LOAD_PATHS = 4 @loader.stubs(:application_lib_index).returns(stubbed_application_lib_index_in_LOAD_PATHS) @loader.add_plugin_load_paths |