Permalink
Browse files

add a test to show that parent can't be used like resource

  • Loading branch information...
1 parent a6e2477 commit 9ae90f896a0f7498d9e2626675cc94095c0f92b9 @indrekj indrekj committed Aug 23, 2011
Showing with 31 additions and 1 deletion.
  1. +29 −0 test/polymorphic_test.rb
  2. +1 −1 test/url_helpers_test.rb
  3. +1 −0 test/views/photos/index.html.erb
View
@@ -2,6 +2,8 @@
class Factory; end
class Company; end
+class User; end
+class Photo; end
class Employee
def self.human_name; 'Employee'; end
@@ -11,6 +13,15 @@ class EmployeesController < InheritedResources::Base
belongs_to :factory, :company, :polymorphic => true
end
+class PhotosController < InheritedResources::Base
+ belongs_to :user, :task, :polymorphic => true
+
+ def index
+ parent
+ # Overwrite index
+ end
+end
+
class PolymorphicFactoriesTest < ActionController::TestCase
tests EmployeesController
@@ -184,3 +195,21 @@ def mock_employee(stubs={})
@mock_employee ||= mock(stubs)
end
end
+
+class PolymorphicPhotosTest < ActionController::TestCase
+ tests PhotosController
+
+ def setup
+ User.expects(:find).with('37').returns(mock_user)
+ end
+
+ def test_parent_as_instance_variable_on_index_when_method_overwritten
+ get :index, :user_id => '37'
+ assert_equal mock_user, assigns(:user)
+ end
+
+ protected
+ def mock_user(stubs={})
+ @mock_user ||= mock(stubs)
+ end
+end
View
@@ -668,7 +668,7 @@ def test_url_helpers_on_optional_polymorphic_belongs_to
new_bed.stubs(:persisted?).returns(false)
controller = BedsController.new
- controller.instance_variable_set('@parent_type', nil)
+ controller.stubs(:parent_type).returns(nil)
controller.instance_variable_set('@bed', bed)
[:url, :path].each do |path_or_url|
@@ -0,0 +1 @@
+Index HTML

0 comments on commit 9ae90f8

Please sign in to comment.