test/polymorphic_test.rb in inherited_resources-1.3.0 vs test/polymorphic_test.rb in inherited_resources-1.3.1
- old
+ new
@@ -1,18 +1,29 @@
require File.expand_path('test_helper', File.dirname(__FILE__))
class Factory; end
class Company; end
+class User; end
+class Photo; end
class Employee
def self.human_name; 'Employee'; end
end
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
def setup
Factory.expects(:find).with('37').returns(mock_factory)
@@ -180,7 +191,25 @@
@mock_company ||= mock(stubs)
end
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