Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

beginning of tests

  • Loading branch information...
commit 04498a9881b35f5a914c9e61f74bce56e1c9e991 1 parent 7102d61
@blg002 authored
View
52 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
View
4 test/test_helper.rb
@@ -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
View
30 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
Please sign in to comment.
Something went wrong with that request. Please try again.