Class: BelongsToTest

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

Instance Method Summary collapse

Instance Method Details

#setupObject



17
18
19
20
21
22
23
# File 'lib/vendor/plugins/inherited_resources/test/belongs_to_test.rb', line 17

def setup
  Post.expects(:find).with('37').returns(mock_post)
  mock_post.expects(:comments).returns(Comment)

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

#test_expose_a_new_comment_on_newObject



39
40
41
42
43
44
# File 'lib/vendor/plugins/inherited_resources/test/belongs_to_test.rb', line 39

def test_expose_a_new_comment_on_new
  Comment.expects(:build).returns(mock_comment)
  get :new, :post_id => '37'
  assert_equal mock_post, assigns(:post)
  assert_equal mock_comment, assigns(:comment)
end

#test_expose_a_newly_create_comment_on_createObject



53
54
55
56
57
58
# File 'lib/vendor/plugins/inherited_resources/test/belongs_to_test.rb', line 53

def test_expose_a_newly_create_comment_on_create
  Comment.expects(:build).with({'these' => 'params'}).returns(mock_comment(:save => true))
  post :create, :post_id => '37', :comment => {:these => 'params'}
  assert_equal mock_post, assigns(:post)
  assert_equal mock_comment, assigns(:comment)
end

#test_expose_all_comments_as_instance_variable_on_indexObject



25
26
27
28
29
30
# File 'lib/vendor/plugins/inherited_resources/test/belongs_to_test.rb', line 25

def test_expose_all_comments_as_instance_variable_on_index
  Comment.expects(:find).with(:all).returns([mock_comment])
  get :index, :post_id => '37'
  assert_equal mock_post, assigns(:post)
  assert_equal [mock_comment], assigns(:comments)
end

#test_expose_the_resquested_comment_on_editObject



46
47
48
49
50
51
# File 'lib/vendor/plugins/inherited_resources/test/belongs_to_test.rb', line 46

def test_expose_the_resquested_comment_on_edit
  Comment.expects(:find).with('42').returns(mock_comment)
  get :edit, :id => '42', :post_id => '37'
  assert_equal mock_post, assigns(:post)
  assert_equal mock_comment, assigns(:comment)
end

#test_expose_the_resquested_comment_on_showObject



32
33
34
35
36
37
# File 'lib/vendor/plugins/inherited_resources/test/belongs_to_test.rb', line 32

def test_expose_the_resquested_comment_on_show
  Comment.expects(:find).with('42').returns(mock_comment)
  get :show, :id => '42', :post_id => '37'
  assert_equal mock_post, assigns(:post)
  assert_equal mock_comment, assigns(:comment)
end

#test_the_resquested_comment_is_destroyed_on_destroyObject



68
69
70
71
72
73
74
# File 'lib/vendor/plugins/inherited_resources/test/belongs_to_test.rb', line 68

def test_the_resquested_comment_is_destroyed_on_destroy
  Comment.expects(:find).with('42').returns(mock_comment)
  mock_comment.expects(:destroy)
  delete :destroy, :id => '42', :post_id => '37'
  assert_equal mock_post, assigns(:post)
  assert_equal mock_comment, assigns(:comment)
end

#test_update_the_requested_object_on_updateObject



60
61
62
63
64
65
66
# File 'lib/vendor/plugins/inherited_resources/test/belongs_to_test.rb', line 60

def test_update_the_requested_object_on_update
  Comment.expects(:find).with('42').returns(mock_comment)
  mock_comment.expects(:update_attributes).with({'these' => 'params'}).returns(true)
  put :update, :id => '42', :post_id => '37', :comment => {:these => 'params'}
  assert_equal mock_post, assigns(:post)
  assert_equal mock_comment, assigns(:comment)
end