Class: PolymorphicCompanyTest

Inherits:
ActionController::TestCase
  • Object
show all
Defined in:
lib/vendor/plugins/inherited_resources/test/polymorphic_test.rb

Instance Method Summary collapse

Instance Method Details

#setupObject



104
105
106
107
108
109
110
# File 'lib/vendor/plugins/inherited_resources/test/polymorphic_test.rb', line 104

def setup
  Company.expects(:find).with('37').returns(mock_company)
  mock_company.expects(:employees).returns(Employee)

  @controller.stubs(:resource_url).returns('/')
  @controller.stubs(:collection_url).returns('/')
end

#test_expose_a_new_employee_on_newObject



126
127
128
129
130
131
# File 'lib/vendor/plugins/inherited_resources/test/polymorphic_test.rb', line 126

def test_expose_a_new_employee_on_new
  Employee.expects(:build).returns(mock_employee)
  get :new, :company_id => '37'
  assert_equal mock_company, assigns(:company)
  assert_equal mock_employee, assigns(:employee)
end

#test_expose_a_newly_create_employee_on_createObject



141
142
143
144
145
146
# File 'lib/vendor/plugins/inherited_resources/test/polymorphic_test.rb', line 141

def test_expose_a_newly_create_employee_on_create
  Employee.expects(:build).with({'these' => 'params'}).returns(mock_employee(:save => true))
  post :create, :company_id => '37', :employee => {:these => 'params'}
  assert_equal mock_company, assigns(:company)
  assert_equal mock_employee, assigns(:employee)
end

#test_expose_all_employees_as_instance_variable_on_indexObject



112
113
114
115
116
117
# File 'lib/vendor/plugins/inherited_resources/test/polymorphic_test.rb', line 112

def test_expose_all_employees_as_instance_variable_on_index
  Employee.expects(:find).with(:all).returns([mock_employee])
  get :index, :company_id => '37'
  assert_equal mock_company, assigns(:company)
  assert_equal [mock_employee], assigns(:employees)
end

#test_expose_the_resquested_employee_on_editObject



133
134
135
136
137
138
139
# File 'lib/vendor/plugins/inherited_resources/test/polymorphic_test.rb', line 133

def test_expose_the_resquested_employee_on_edit
  Employee.expects(:find).with('42').returns(mock_employee)
  get :edit, :id => '42', :company_id => '37'
  assert_equal mock_company, assigns(:company)
  assert_equal mock_employee, assigns(:employee)
  assert_response :success
end

#test_expose_the_resquested_employee_on_showObject



119
120
121
122
123
124
# File 'lib/vendor/plugins/inherited_resources/test/polymorphic_test.rb', line 119

def test_expose_the_resquested_employee_on_show
  Employee.expects(:find).with('42').returns(mock_employee)
  get :show, :id => '42', :company_id => '37'
  assert_equal mock_company, assigns(:company)
  assert_equal mock_employee, assigns(:employee)
end

#test_polymorphic_helpersObject



164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/vendor/plugins/inherited_resources/test/polymorphic_test.rb', line 164

def test_polymorphic_helpers
  mock_company.stubs(:class).returns(Company)

  Employee.expects(:find).with(:all).returns([mock_employee])
  get :index, :company_id => '37'

  assert @controller.send(:parent?)
  assert_equal :company, assigns(:parent_type)
  assert_equal :company, @controller.send(:parent_type)
  assert_equal Company, @controller.send(:parent_class)
  assert_equal mock_company, assigns(:company)
  assert_equal mock_company, @controller.send(:parent)
end

#test_the_resquested_employee_is_destroyed_on_destroyObject



156
157
158
159
160
161
162
# File 'lib/vendor/plugins/inherited_resources/test/polymorphic_test.rb', line 156

def test_the_resquested_employee_is_destroyed_on_destroy
  Employee.expects(:find).with('42').returns(mock_employee)
  mock_employee.expects(:destroy)
  delete :destroy, :id => '42', :company_id => '37'
  assert_equal mock_company, assigns(:company)
  assert_equal mock_employee, assigns(:employee)
end

#test_update_the_requested_object_on_updateObject



148
149
150
151
152
153
154
# File 'lib/vendor/plugins/inherited_resources/test/polymorphic_test.rb', line 148

def test_update_the_requested_object_on_update
  Employee.expects(:find).with('42').returns(mock_employee)
  mock_employee.expects(:update_attributes).with({'these' => 'params'}).returns(true)
  put :update, :id => '42', :company_id => '37', :employee => {:these => 'params'}
  assert_equal mock_company, assigns(:company)
  assert_equal mock_employee, assigns(:employee)
end