Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 9ae90f896a0f7498d9e2626675cc94095c0f92b9 1 parent a6e2477
Indrek Juhkam authored August 23, 2011
29  test/polymorphic_test.rb
@@ -2,6 +2,8 @@
2 2
 
3 3
 class Factory; end
4 4
 class Company; end
  5
+class User; end
  6
+class Photo; end
5 7
 
6 8
 class Employee
7 9
   def self.human_name; 'Employee'; end
@@ -11,6 +13,15 @@ class EmployeesController < InheritedResources::Base
11 13
   belongs_to :factory, :company, :polymorphic => true
12 14
 end
13 15
 
  16
+class PhotosController < InheritedResources::Base
  17
+  belongs_to :user, :task, :polymorphic => true
  18
+
  19
+  def index
  20
+    parent
  21
+    # Overwrite index
  22
+  end
  23
+end
  24
+
14 25
 class PolymorphicFactoriesTest < ActionController::TestCase
15 26
   tests EmployeesController
16 27
 
@@ -184,3 +195,21 @@ def mock_employee(stubs={})
184 195
       @mock_employee ||= mock(stubs)
185 196
     end
186 197
 end
  198
+
  199
+class PolymorphicPhotosTest < ActionController::TestCase
  200
+  tests PhotosController
  201
+
  202
+  def setup
  203
+    User.expects(:find).with('37').returns(mock_user)
  204
+  end
  205
+
  206
+  def test_parent_as_instance_variable_on_index_when_method_overwritten
  207
+    get :index, :user_id => '37'
  208
+    assert_equal mock_user, assigns(:user)
  209
+  end
  210
+
  211
+  protected
  212
+    def mock_user(stubs={})
  213
+      @mock_user ||= mock(stubs)
  214
+    end
  215
+end
2  test/url_helpers_test.rb
@@ -668,7 +668,7 @@ def test_url_helpers_on_optional_polymorphic_belongs_to
668 668
     new_bed.stubs(:persisted?).returns(false)
669 669
 
670 670
     controller = BedsController.new
671  
-    controller.instance_variable_set('@parent_type', nil)
  671
+    controller.stubs(:parent_type).returns(nil)
672 672
     controller.instance_variable_set('@bed', bed)
673 673
 
674 674
     [:url, :path].each do |path_or_url|
1  test/views/photos/index.html.erb
... ...
@@ -0,0 +1 @@
  1
+Index HTML

0 notes on commit 9ae90f8

Please sign in to comment.
Something went wrong with that request. Please try again.