-
Notifications
You must be signed in to change notification settings - Fork 8
Tests
JP Barbosa edited this page Jul 23, 2015
·
2 revisions
nano test/controllers/articles_controller_test.rb
...
test "should create article" do
assert_difference('Article.count') do
post :create, article: { content: @article.content, title: @article.title }
end
assert_redirected_to articles_path
end
...
rake test test
nano test/controllers/articles_controller_test.rb
...
setup do
@article = articles(:one)
@article_2 = articles(:two)
end
...
test "should not create article with too short title" do
assert_no_difference('Article.count') do
post :create, article: { content: @article_2.content, title: @article_2.title }
end
assert_template :new
end
...
rake test test
nano test/controllers/recommendations_controller_test.rb
require 'test_helper'
class RecommendationsControllerTest < ActionController::TestCase
include ActiveJob::TestHelper
setup do
@article = articles(:one)
@recommendation = Recommendation.new({
article: @article,
email: '[email protected]'
})
@recommendation_2 = Recommendation.new({
article: @article,
email: 'invalid_email_address'
})
end
test "should get new" do
get :new, article_id: @article.id
assert_response :success
end
end
rake test test
nano test/controllers/recommendations_controller_test.rb
...
test "should not create recommendation with invalid email" do
assert_enqueued_jobs 0 do
post :create, article_id: @article.id, recommendation: {
email: @recommendation_2.email,
title: @recommendation_2.article
}
end
assert_template :new
end
test "should create recommendation" do
assert_enqueued_jobs 1 do
post :create, article_id: @article.id, recommendation: {
email: @recommendation.email,
title: @recommendation.article
}
end
assert_redirected_to articles_path
end
...
rake test test
git add .
git commit -m "Add basic tests"