Skip to content

Commit

Permalink
beginning of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
blg002 committed Jan 16, 2012
1 parent 7102d61 commit 04498a9
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/functional/articles_controller_test.rb
@@ -0,0 +1,52 @@
require 'test_helper'

class ArticlesControllerTest < ActionController::TestCase

setup do
@article = articles(:one)
login_as(:brad)
end

test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:articles)
end

test "should get new" do
get :new
assert_response :success
end

test "should create article" do
assert_difference('Article.count') do
post :create, :article => { :title => 'Howdy', :body => 'Some body copy', :author_id => 1 }
end

assert_redirected_to article_path(assigns(:article))
assert_equal 'Article was successfully created.', flash[:notice]
end

test "should show article" do
get :show, id: @article.to_param
assert_response :success
end

test "should get edit" do
get :edit, id: @article.to_param
assert_response :success
end

test "should update article" do
put :update, id: @article.to_param, article: @article.attributes
assert_redirected_to article_path(assigns(:article))
end

test "should destroy article" do
assert_difference('Article.count', -1) do
delete :destroy, id: @article.to_param
end

assert_redirected_to article_path
end
end
4 changes: 4 additions & 0 deletions test/test_helper.rb
Expand Up @@ -10,4 +10,8 @@ class ActiveSupport::TestCase
fixtures :all

# Add more helper methods to be used by all tests here...

def login_as(author)
@request.session[:author_id] = author ? author.id : nil
end
end
30 changes: 30 additions & 0 deletions test/unit/article_test.rb
@@ -0,0 +1,30 @@
require 'test_helper'

class ArticleTest < ActiveSupport::TestCase

def setup
@article = articles(:one)
end

test "create article without requirements" do
article = Article.new
assert !article.save, "Saved an article without any validations"
end

# test "validations" do
# assert(@article.valid?)
#
# @article.title = nil
# assert(!@article.valid?)
#
# @article.title = "A title much longer than 140 character!! A title much longer than 140 character!! A title much longer than 140 character!! A title much longer than 140 character!!"
# assert(!@article.valid?)
#
# @article.author_id = nil
# assert(!@article.valid?)
#
# @article.body = nil
# assert(!@article.valid?)
# end

end

0 comments on commit 04498a9

Please sign in to comment.