Permalink
Browse files

Functional testing

  • Loading branch information...
1 parent 0e1b3b5 commit 8cdc37495eaf7df2641ab6d0e4539aac306f0a2d Lee Smith committed Sep 5, 2010
@@ -1,4 +1,9 @@
Factory.define :ticket do |t|
t.title Faker::Lorem.sentence(word_count=15)
t.details Faker::Lorem.paragraphs(paragraph_count=1)
+ t.association :creator, :factory => :user
+ t.association :group
+ t.association :status
+ t.association :priority
+ t.association :contact
end
@@ -1,8 +1,13 @@
require 'test_helper'
class AdminControllerTest < ActionController::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
+ test "admin index route" do
+ assert_routing '/admin', { :controller => "admin", :action => "index" }
+ end
+
+ test "index without user" do
+ get :index
+ assert_redirected_to root_path
+ assert_not_nil flash[:error]
end
end
@@ -1,45 +1,8 @@
require 'test_helper'
class CommentsControllerTest < ActionController::TestCase
- test "should get index" do
- get :index
- assert_response :success
- assert_not_nil assigns(:comments)
- end
-
- test "should get new" do
- get :new
- assert_response :success
- end
-
- test "should create comment" do
- assert_difference('Comment.count') do
- post :create, :comment => { }
- end
-
- assert_redirected_to comment_path(assigns(:comment))
- end
-
- test "should show comment" do
- get :show, :id => comments(:one).id
- assert_response :success
- end
-
- test "should get edit" do
- get :edit, :id => comments(:one).id
- assert_response :success
- end
-
- test "should update comment" do
- put :update, :id => comments(:one).id, :comment => { }
- assert_redirected_to comment_path(assigns(:comment))
- end
-
- test "should destroy comment" do
- assert_difference('Comment.count', -1) do
- delete :destroy, :id => comments(:one).id
- end
-
- assert_redirected_to comments_path
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
end
end
@@ -1,6 +1,12 @@
require 'test_helper'
class ContactsControllerTest < ActionController::TestCase
+ setup :activate_authlogic
+
+ def setup
+ UserSession.create Factory.build(:user)
+ end
+
test "should get index" do
get :index
assert_response :success
@@ -12,34 +18,13 @@ class ContactsControllerTest < ActionController::TestCase
assert_response :success
end
- test "should create contact" do
- assert_difference('Contact.count') do
- post :create, :contact => { }
- end
-
- assert_redirected_to contact_path(assigns(:contact))
- end
-
test "should show contact" do
- get :show, :id => contacts(:one).to_param
+ get :show, :id => Factory(:contact).id
assert_response :success
end
test "should get edit" do
- get :edit, :id => contacts(:one).to_param
+ get :edit, :id => Factory(:contact).id
assert_response :success
end
-
- test "should update contact" do
- put :update, :id => contacts(:one).to_param, :contact => { }
- assert_redirected_to contact_path(assigns(:contact))
- end
-
- test "should destroy contact" do
- assert_difference('Contact.count', -1) do
- delete :destroy, :id => contacts(:one).to_param
- end
-
- assert_redirected_to contacts_path
- end
end
@@ -1,8 +1,13 @@
require 'test_helper'
class DashboardControllerTest < ActionController::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
+ test "dashboard index route" do
+ assert_routing '/', { :controller => 'dashboard', :action => 'index' }
+ end
+
+ test "index without user" do
+ get :index
+ assert_redirected_to login_path
+ assert_not_nil flash[:error]
end
end
@@ -1,45 +1,8 @@
require 'test_helper'
class TicketsControllerTest < ActionController::TestCase
- test "should get index" do
- get :index
- assert_response :success
- assert_not_nil assigns(:tickets)
- end
-
- test "should get new" do
- get :new
- assert_response :success
- end
-
- test "should create ticket" do
- assert_difference('Ticket.count') do
- post :create, :ticket => { }
- end
-
- assert_redirected_to ticket_path(assigns(:ticket))
- end
-
- test "should show ticket" do
- get :show, :id => tickets(:one).id
- assert_response :success
- end
-
- test "should get edit" do
- get :edit, :id => tickets(:one).id
- assert_response :success
- end
-
- test "should update ticket" do
- put :update, :id => tickets(:one).id, :ticket => { }
- assert_redirected_to ticket_path(assigns(:ticket))
- end
-
- test "should destroy ticket" do
- assert_difference('Ticket.count', -1) do
- delete :destroy, :id => tickets(:one).id
- end
-
- assert_redirected_to tickets_path
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
end
end
@@ -1,7 +1,10 @@
require 'test_helper'
class UsersControllerTest < ActionController::TestCase
+ setup :activate_authlogic
+
test "should get index" do
+ UserSession.create Factory.build(:user)
get :index
assert_response :success
assert_not_nil assigns(:users)
@@ -12,34 +15,14 @@ class UsersControllerTest < ActionController::TestCase
assert_response :success
end
- test "should create user" do
- assert_difference('User.count') do
- post :create, :user => { }
- end
-
- assert_redirected_to user_path(assigns(:user))
- end
-
test "should show user" do
- get :show, :id => users(:one).id
+ get :show, :id => Factory(:user).id
assert_response :success
end
test "should get edit" do
- get :edit, :id => users(:one).id
+ get :edit, :id => Factory(:user).id
assert_response :success
end
- test "should update user" do
- put :update, :id => users(:one).id, :user => { }
- assert_redirected_to user_path(assigns(:user))
- end
-
- test "should destroy user" do
- assert_difference('User.count', -1) do
- delete :destroy, :id => users(:one).id
- end
-
- assert_redirected_to users_path
- end
end
View
@@ -34,7 +34,7 @@ class ActiveSupport::TestCase
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting
- fixtures :all
+ # fixtures :all
# Add more helper methods to be used by all tests here...
-end
+end
View
@@ -1,8 +1,19 @@
require 'test_helper'
class TicketTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
+ test "invalid with empty attributes" do
+ ticket = Ticket.new
+ assert !ticket.valid?
+ assert ticket.errors.invalid?(:title)
+ assert ticket.errors.invalid?(:group_id)
+ assert ticket.errors.invalid?(:status_id)
+ assert ticket.errors.invalid?(:priority_id)
+ assert ticket.errors.invalid?(:contact_id)
+ assert ticket.errors.invalid?(:created_by)
+ end
+
+ test "valid ticket" do
+ ticket = Factory.build(:ticket)
+ assert ticket.valid?
end
end

0 comments on commit 8cdc374

Please sign in to comment.