-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new tests for votes and stories
Added unit tests to the Story and Vote model to check the association between the models. Added functional tests for the Stories and Votes controller to ensure correct functionality for creating votes and displaying votes.
- Loading branch information
Showing
5 changed files
with
48 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html | ||
|
||
one: | ||
story_id: 1 | ||
first: | ||
story: one | ||
|
||
two: | ||
story_id: 1 | ||
second: | ||
story: one |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
require 'test_helper' | ||
|
||
class VotesControllerTest < ActionController::TestCase | ||
# Replace this with your real tests. | ||
test "the truth" do | ||
assert true | ||
def test_should_accept_vote | ||
assert stories(:two).votes.empty? | ||
post :create, :story_id => stories(:two) | ||
assert !assigns(:story).votes.empty? | ||
end | ||
|
||
def test_should_render_rjs_after_vote_with_ajax | ||
xml_http_request :post, :create, :story_id => stories(:two) | ||
assert_response :success | ||
assert_template 'create' | ||
end | ||
|
||
def test_should_redirect_after_vote_with_http_post | ||
post :create, :story_id => stories(:two) | ||
assert_redirected_to story_path(stories(:two)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
require 'test_helper' | ||
|
||
class VoteTest < ActiveSupport::TestCase | ||
# Replace this with your real tests. | ||
test "the truth" do | ||
assert true | ||
def test_story_association | ||
assert_equal stories(:one), votes(:first).story | ||
end | ||
end |