From 12b3eca420c2de46d34a363c91b2263d366f4d6c Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 6 Aug 2010 11:31:05 -0700 Subject: do not rely on arel class structure --- activerecord/lib/active_record/relation.rb | 4 +++- activerecord/test/cases/method_scoping_test.rb | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index deacced627..30be723291 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -319,7 +319,9 @@ module ActiveRecord def scope_for_create @scope_for_create ||= begin @create_with_value || Hash[ - @where_values.grep(Arel::Predicates::Equality).map { |where| + @where_values.find_all { |w| + w.respond_to?(:operator) && w.operator == :== + }.map { |where| [where.operand1.name, where.operand2.respond_to?(:value) ? where.operand2.value : where.operand2] diff --git a/activerecord/test/cases/method_scoping_test.rb b/activerecord/test/cases/method_scoping_test.rb index 774b50e2e4..5256ab8d11 100644 --- a/activerecord/test/cases/method_scoping_test.rb +++ b/activerecord/test/cases/method_scoping_test.rb @@ -208,6 +208,13 @@ class MethodScopingTest < ActiveRecord::TestCase end end + def test_scope_for_create_only_uses_equal + table = VerySpecialComment.arel_table + relation = VerySpecialComment.scoped + relation.where_values << table[:id].not_eq(1) + assert_equal({:type => "VerySpecialComment"}, relation.send(:scope_for_create)) + end + def test_scoped_create new_comment = nil -- cgit v1.2.3 From d082a9a2b803c2cf530c6b6bdb8a5c4f19f36982 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 6 Aug 2010 14:52:33 -0700 Subject: sorry AR, my privates are none of your business --- activerecord/test/cases/relations_test.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index c9313fe7b6..02c8c60873 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -192,13 +192,6 @@ class RelationTest < ActiveRecord::TestCase end end - def test_respond_to_private_arel_methods - relation = Topic.scoped - - assert ! relation.respond_to?(:matching_attributes) - assert relation.respond_to?(:matching_attributes, true) - end - def test_respond_to_dynamic_finders relation = Topic.scoped -- cgit v1.2.3 From e1596be32363122f12777ce09e654ae58f262eb4 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 6 Aug 2010 15:23:11 -0700 Subject: test to ensure that respond_to? delegates to arel --- activerecord/test/cases/relations_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 02c8c60873..ac7b501bb7 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -192,6 +192,25 @@ class RelationTest < ActiveRecord::TestCase end end + def test_respond_to_delegates_to_relation + relation = Topic.scoped + fake_arel = Struct.new(:responds) { + def respond_to? method, access = false + responds << [method, access] + end + }.new [] + + relation.extend(Module.new { attr_accessor :arel }) + relation.arel = fake_arel + + relation.respond_to?(:matching_attributes) + assert_equal [:matching_attributes, false], fake_arel.responds.first + + fake_arel.responds = [] + relation.respond_to?(:matching_attributes, true) + assert_equal [:matching_attributes, true], fake_arel.responds.first + end + def test_respond_to_dynamic_finders relation = Topic.scoped -- cgit v1.2.3 From 334452098e593bb514a9ea2bd74435f2c7b0628e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 6 Aug 2010 16:38:53 -0700 Subject: reduce the number of times current_connection_id is called in with_connection() --- .../connection_adapters/abstract/connection_pool.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb index 9d0251dda3..02a8f4e214 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -103,8 +103,8 @@ module ActiveRecord # Signal that the thread is finished with the current connection. # #release_connection releases the connection-thread association # and returns the connection to the pool. - def release_connection - conn = @reserved_connections.delete(current_connection_id) + def release_connection(with_id = current_connection_id) + conn = @reserved_connections.delete(with_id) checkin conn if conn end @@ -112,10 +112,11 @@ module ActiveRecord # exists checkout a connection, yield it to the block, and checkin the # connection when finished. def with_connection - fresh_connection = true unless @reserved_connections[current_connection_id] + connection_id = current_connection_id + fresh_connection = true unless @reserved_connections[connection_id] yield connection ensure - release_connection if fresh_connection + release_connection(connection_id) if fresh_connection end # Returns true if a connection has already been opened. -- cgit v1.2.3 From aed698a7c8bdafe3a7596a15d320fc5b1175600f Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 7 Aug 2010 01:42:09 +0200 Subject: adds Abstract Controller to the API --- Rakefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Rakefile b/Rakefile index 4e56da5ab3..0e6acb5ac2 100644 --- a/Rakefile +++ b/Rakefile @@ -90,6 +90,7 @@ RDoc::Task.new do |rdoc| rdoc.rdoc_files.include('actionpack/README.rdoc') rdoc.rdoc_files.include('actionpack/CHANGELOG') + rdoc.rdoc_files.include('actionpack/lib/abstract_controller/**/*.rb') rdoc.rdoc_files.include('actionpack/lib/action_controller/**/*.rb') rdoc.rdoc_files.include('actionpack/lib/action_dispatch/**/*.rb') rdoc.rdoc_files.include('actionpack/lib/action_view/**/*.rb') -- cgit v1.2.3 From 0953c04cf57cfc281e6972df450ebe517cfe3a00 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 7 Aug 2010 15:18:22 +0200 Subject: quick hack: hijacks the predicate RDoc::Parser.binary? so that it does not consider a handful of ordinary Ruby files in the Rails tree as binary (and thus excluded from the API) --- Rakefile | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Rakefile b/Rakefile index 0e6acb5ac2..aab4f5f2f5 100644 --- a/Rakefile +++ b/Rakefile @@ -5,6 +5,31 @@ require 'rake' require 'rdoc/task' require 'rake/gempackagetask' +# RDoc skips some files in the Rails tree due to its binary? predicate. This is a quick +# hack for edge docs, until we decide which is the correct way to address this issue. +# If not fixed in RDoc itself, via an option or something, we should probably move this +# to railties and use it also in doc:rails. +def hijack_rdoc! + require "rdoc/parser" + class << RDoc::Parser + def binary?(file) + s = File.read(file, 1024) or return false + + if s[0, 2] == Marshal.dump('')[0, 2] then + true + elsif file =~ /\.erb\.rb$/ then # ORIGINAL is file =~ /erb\.rb$/ + false + elsif s.index("\x00") then # ORIGINAL is s.scan(/<%|%>/).length >= 4 || s.index("\x00") + true + elsif 0.respond_to? :fdiv then + s.count("^ -~\t\r\n").fdiv(s.size) > 0.3 + else # HACK 1.8.6 + (s.count("^ -~\t\r\n").to_f / s.size) > 0.3 + end + end + end +end + PROJECTS = %w(activesupport activemodel actionpack actionmailer activeresource activerecord railties) desc 'Run all tests by default' @@ -63,6 +88,8 @@ end desc "Generate documentation for the Rails framework" RDoc::Task.new do |rdoc| + hijack_rdoc! + rdoc.rdoc_dir = 'doc/rdoc' rdoc.title = "Ruby on Rails Documentation" -- cgit v1.2.3 From 997021eb29869953936434dbaf6fb79fd34f5015 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 7 Aug 2010 20:10:01 +0200 Subject: undoes one of the modifications to RDoc::Parser.binary? --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index aab4f5f2f5..ceb0e832b3 100644 --- a/Rakefile +++ b/Rakefile @@ -17,7 +17,7 @@ def hijack_rdoc! if s[0, 2] == Marshal.dump('')[0, 2] then true - elsif file =~ /\.erb\.rb$/ then # ORIGINAL is file =~ /erb\.rb$/ + elsif file =~ /erb\.rb$/ then false elsif s.index("\x00") then # ORIGINAL is s.scan(/<%|%>/).length >= 4 || s.index("\x00") true -- cgit v1.2.3 From 5598d3ac2ee8d1d5da79a73c91bcf93c9270a124 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 8 Aug 2010 11:28:50 +0200 Subject: updates horo dependency to 1.0.1 --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index c8dbcc0507..71dc1f3e99 100644 --- a/Gemfile +++ b/Gemfile @@ -11,7 +11,7 @@ gem "rails", :path => File.dirname(__FILE__) gem "rake", ">= 0.8.7" gem "mocha", ">= 0.9.8" gem "rdoc", ">= 2.5.9" -gem "horo" +gem "horo", ">= 1.0.1" # AS gem "memcache-client", ">= 1.8.5" -- cgit v1.2.3 From ddeaf6c8877599b18b371232e72ed7150f5bb688 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 8 Aug 2010 18:29:58 +0200 Subject: routing guide: documents the CONTROLLER environment variable understood by the routes task --- railties/guides/source/routing.textile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index 7b665d81e7..625941ba31 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -762,6 +762,12 @@ formatted_users GET /users.:format {:controller=>"users", :action=>"index"} POST /users.:format {:controller=>"users", :action=>"create"} +You may restrict the listing to the routes that map to a particular controller setting the +CONTROLLER+ environment variable: + + +$ CONTROLLER=users rake routes + + TIP: You'll find that the output from +rake routes+ is much more readable if you widen your terminal window until the output lines don't wrap. h4. Testing Routes -- cgit v1.2.3