diff options
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | actionpack/CHANGELOG | 10 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 29 | ||||
-rw-r--r-- | actionpack/lib/action_view/test_case.rb | 14 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 39 | ||||
-rw-r--r-- | actionpack/test/template/test_case_test.rb | 4 | ||||
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/active_schema_test_mysql.rb | 8 | ||||
-rw-r--r-- | activerecord/test/cases/active_schema_test_postgresql.rb | 1 | ||||
-rwxr-xr-x | activerecord/test/cases/base_test.rb | 17 |
11 files changed, 44 insertions, 86 deletions
@@ -32,7 +32,7 @@ if mri || RUBY_ENGINE == "rbx" gem "sqlite3-ruby", "~> 1.3.0", :require => 'sqlite3' group :db do - # gem "pg", ">= 0.9.0" + gem "pg", ">= 0.9.0" gem "mysql", ">= 2.8.1" end elsif RUBY_ENGINE == "jruby" diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index c3609958bc..1796d11dcd 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,15 +1,5 @@ *Rails 3.0.0 [beta 4] (June 8th, 2010)* -* Add shallow routes back to the new router [Diego Carrion] - - resources :posts do - shallow do - resources :comments - end - end - - You can now use comment_path for /comments/1 instead of post_comment_path for /posts/1/comments/1. - * Remove middleware laziness [José Valim] * Make session stores rely on request.cookie_jar and change set_session semantics to return the cookie value instead of a boolean. [José Valim] diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index e91a72cbe5..6db8d1aacc 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -350,10 +350,6 @@ module ActionDispatch scope(:constraints => constraints) { yield } end - def shallow - scope(:shallow => true) { yield } - end - def defaults(defaults = {}) scope(:defaults => defaults) { yield } end @@ -378,21 +374,12 @@ module ActionDispatch @scope_options ||= private_methods.grep(/^merge_(.+)_scope$/) { $1.to_sym } end - def merge_shallow_scope(parent, child) - parent or child - end - def merge_path_scope(parent, child) - parent_path = (@scope[:shallow] and child.eql?(':id')) ? parent.split('/').last : parent - Mapper.normalize_path "#{parent_path}/#{child}" + Mapper.normalize_path("#{parent}/#{child}") end def merge_name_prefix_scope(parent, child) - if @scope[:shallow] - child - else - parent ? "#{parent}_#{child}" : child - end + parent ? "#{parent}_#{child}" : child end def merge_module_scope(parent, child) @@ -535,10 +522,6 @@ module ActionDispatch options["#{singular}_id".to_sym] = id_constraint if id_constraint? options end - - def shallow? - options[:shallow] - end end class SingletonResource < Resource #:nodoc: @@ -620,12 +603,8 @@ module ActionDispatch resource = Resource.new(resources.pop, options) - scope(:path => resource.path, :controller => resource.controller, :shallow => resource.shallow?) do + scope(:path => resource.path, :controller => resource.controller) do with_scope_level(:resources, resource) do - if @scope[:shallow] && @scope[:name_prefix] - @scope[:path] = "/#{@scope[:name_prefix].pluralize}/:#{@scope[:name_prefix]}_id/#{resource.path}" - end - yield if block_given? with_scope_level(:collection) do @@ -639,8 +618,6 @@ module ActionDispatch with_scope_level(:member) do scope(':id') do scope(resource.options) do - @scope[:name_prefix] = nil if @scope[:shallow] - get :show if resource.actions.include?(:show) put :update if resource.actions.include?(:update) delete :destroy if resource.actions.include?(:destroy) diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index 4dbbd2eb6a..15d424be74 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -131,12 +131,14 @@ module ActionView end def _view - view = ActionView::Base.new(ActionController::Base.view_paths, _assigns, @controller) - view.singleton_class.send :include, _helpers - view.singleton_class.send :include, @controller._router.url_helpers - view.singleton_class.send :delegate, :alert, :notice, :to => "request.flash" - view.output_buffer = self.output_buffer - view + @_view ||= begin + view = ActionView::Base.new(ActionController::Base.view_paths, _assigns, @controller) + view.singleton_class.send :include, _helpers + view.singleton_class.send :include, @controller._router.url_helpers + view.singleton_class.send :delegate, :alert, :notice, :to => "request.flash" + view.output_buffer = self.output_buffer + view + end end EXCLUDE_IVARS = %w{ diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index a294535e88..5c46f9b971 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -34,33 +34,6 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - resources :users do - shallow do - resources :photos do - resources :types do - member do - post :preview - end - collection do - delete :erase - end - end - end - end - end - - shallow do - resources :teams do - resources :players - end - - resources :countries do - resources :cities do - resources :places - end - end - end - match 'account/logout' => redirect("/logout"), :as => :logout_redirect match 'account/login', :to => redirect("/login") @@ -779,18 +752,6 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - def test_shallow_routes - with_test_routes do - assert_equal '/photos/4', photo_path(4) - assert_equal '/types/10/edit', edit_type_path(10) - assert_equal '/types/5/preview', preview_type_path(5) - assert_equal '/photos/2/types', photo_types_path(2) - assert_equal '/cities/1/places', url_for(:controller => :places, :action => :index, :city_id => 1, :only_path => true) - assert_equal '/teams/new', url_for(:controller => :teams, :action => :new, :only_path => true) - assert_equal '/photos/11/types/erase', url_for(:controller => :types, :action => :erase, :photo_id => 11, :only_path => true) - end - end - def test_update_project_person with_test_routes do get '/projects/1/people/2/update' diff --git a/actionpack/test/template/test_case_test.rb b/actionpack/test/template/test_case_test.rb index 16e5ee4f72..9b50ea8a42 100644 --- a/actionpack/test/template/test_case_test.rb +++ b/actionpack/test/template/test_case_test.rb @@ -37,6 +37,10 @@ module ActionView include SharedTests test_case = self + test "memoizes the _view" do + assert_same _view, _view + end + test "works without testing a helper module" do assert_equal 'Eloy', render('developers/developer', :developer => stub(:name => 'Eloy')) end diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 348248e849..e47d291eb3 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *Rails 3.0.0 [beta 4] (June 8th, 2010)* +* Fixed that ActiveRecord::Base.compute_type would swallow NoMethodError #4751 [Andrew Bloomgarden, Andrew White] + * Add index length support for MySQL. #1852 [Emili Parreno, Pratik Naik] Example: diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index aa2826fb33..7cff6d9f1a 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1219,7 +1219,9 @@ module ActiveRecord #:nodoc: begin constant = candidate.constantize return constant if candidate == constant.to_s - rescue NameError + rescue NameError => e + # We don't want to swallow NoMethodError < NameError errors + raise e unless e.instance_of?(NameError) rescue ArgumentError end end diff --git a/activerecord/test/cases/active_schema_test_mysql.rb b/activerecord/test/cases/active_schema_test_mysql.rb index 3526f49afd..d7431e5158 100644 --- a/activerecord/test/cases/active_schema_test_mysql.rb +++ b/activerecord/test/cases/active_schema_test_mysql.rb @@ -4,6 +4,7 @@ class ActiveSchemaTest < ActiveRecord::TestCase def setup ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do alias_method :execute_without_stub, :execute + remove_method :execute def execute(sql, name = nil) return sql end end end @@ -66,7 +67,7 @@ class ActiveSchemaTest < ActiveRecord::TestCase assert_equal "DROP TABLE `otherdb`.`people`", drop_table('otherdb.people') end - def test_add_timestamps + def test_add_timestamps with_real_execute do begin ActiveRecord::Base.connection.create_table :delete_me do |t| @@ -79,8 +80,8 @@ class ActiveSchemaTest < ActiveRecord::TestCase end end end - - def test_remove_timestamps + + def test_remove_timestamps with_real_execute do begin ActiveRecord::Base.connection.create_table :delete_me do |t| @@ -106,6 +107,7 @@ class ActiveSchemaTest < ActiveRecord::TestCase ensure #before finishing, we restore the alias to the mock-up method ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do + remove_method :execute alias_method :execute, :execute_with_stub end end diff --git a/activerecord/test/cases/active_schema_test_postgresql.rb b/activerecord/test/cases/active_schema_test_postgresql.rb index af80f724f2..4f04c6735c 100644 --- a/activerecord/test/cases/active_schema_test_postgresql.rb +++ b/activerecord/test/cases/active_schema_test_postgresql.rb @@ -4,6 +4,7 @@ class PostgresqlActiveSchemaTest < Test::Unit::TestCase def setup ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do alias_method :real_execute, :execute + remove_method :execute def execute(sql, name = nil) sql end end end diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 36c572b5e7..5c175de6d4 100755 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -2334,6 +2334,23 @@ class BasicsTest < ActiveRecord::TestCase assert !Minimalistic.new.freeze.dup.frozen? end + def test_compute_type_success + assert_equal Author, ActiveRecord::Base.send(:compute_type, 'Author') + end + + def test_compute_type_nonexistent_constant + assert_raises NameError do + ActiveRecord::Base.send :compute_type, 'NonexistentModel' + end + end + + def test_compute_type_no_method_error + String.any_instance.stubs(:constantize).raises(NoMethodError) + assert_raises NoMethodError do + ActiveRecord::Base.send :compute_type, 'InvalidModel' + end + end + protected def with_env_tz(new_tz = 'US/Eastern') old_tz, ENV['TZ'] = ENV['TZ'], new_tz |