summaryrefslogtreecommitdiff
path: root/engines/support/test/functional
diff options
context:
space:
mode:
Diffstat (limited to 'engines/support/test/functional')
-rw-r--r--engines/support/test/functional/ticket_comments_test.rb18
-rw-r--r--engines/support/test/functional/tickets_controller_test.rb4
-rw-r--r--engines/support/test/functional/tickets_list_test.rb47
3 files changed, 37 insertions, 32 deletions
diff --git a/engines/support/test/functional/ticket_comments_test.rb b/engines/support/test/functional/ticket_comments_test.rb
index c6c143a..826850d 100644
--- a/engines/support/test/functional/ticket_comments_test.rb
+++ b/engines/support/test/functional/ticket_comments_test.rb
@@ -9,7 +9,7 @@ class TicketsCommentsTest < ActionController::TestCase
end
test "add comment to unauthenticated ticket" do
- ticket = FactoryGirl.create :ticket, :created_by => nil
+ ticket = create_ticket :created_by => nil
assert_difference('Ticket.find(ticket.id).comments.count') do
put :update, :id => ticket.id,
@@ -25,7 +25,7 @@ class TicketsCommentsTest < ActionController::TestCase
test "add comment to own authenticated ticket" do
login
- ticket = FactoryGirl.create :ticket, :created_by => @current_user.id
+ ticket = create_ticket :created_by => @current_user.id
#they should be able to comment if it is their ticket:
assert_difference('Ticket.find(ticket.id).comments.count') do
@@ -42,7 +42,7 @@ class TicketsCommentsTest < ActionController::TestCase
test "cannot comment if it is another users ticket" do
other_user = find_record :user
login :is_admin? => false, :email => nil
- ticket = FactoryGirl.create :ticket, :created_by => other_user.id
+ ticket = create_ticket :created_by => other_user.id
# they should *not* be able to comment if it is not their ticket
put :update, :id => ticket.id, :ticket => {:comments_attributes => {"0" => {"body" =>"not allowed comment"}} }
assert_response :redirect
@@ -53,8 +53,8 @@ class TicketsCommentsTest < ActionController::TestCase
test "authenticated comment on an anonymous ticket adds to my tickets" do
login
- ticket = FactoryGirl.create :ticket
- other_ticket = FactoryGirl.create :ticket
+ ticket = create_ticket
+ other_ticket = create_ticket
put :update, :id => ticket.id,
:ticket => {:comments_attributes => {"0" => {"body" =>"NEWER comment"}} }
assert_not_nil assigns(:ticket).comments.last.posted_by
@@ -71,7 +71,7 @@ class TicketsCommentsTest < ActionController::TestCase
admin = find_record :user, @current_user
other_user = find_record :user
- ticket = FactoryGirl.create :ticket, :created_by => other_user.id
+ ticket = create_ticket :created_by => other_user.id
#admin should be able to comment:
assert_difference('Ticket.find(ticket.id).comments.count') do
@@ -84,7 +84,7 @@ class TicketsCommentsTest < ActionController::TestCase
end
test "commenting on a ticket adds to tickets that are mine" do
- testticket = FactoryGirl.create :ticket
+ testticket = create_ticket
user = find_record :admin_user
login user
get :index, {:user_id => user.id, :open_status => "open"}
@@ -98,4 +98,8 @@ class TicketsCommentsTest < ActionController::TestCase
assert_equal assigns(:ticket).comments.last.posted_by, @current_user.id
end
+ def create_ticket(attrs = {})
+ FactoryBot.create :ticket, attrs
+ end
+
end
diff --git a/engines/support/test/functional/tickets_controller_test.rb b/engines/support/test/functional/tickets_controller_test.rb
index 2f1e661..e86ec11 100644
--- a/engines/support/test/functional/tickets_controller_test.rb
+++ b/engines/support/test/functional/tickets_controller_test.rb
@@ -137,7 +137,7 @@ class TicketsControllerTest < ActionController::TestCase
test "close ticket" do
login
- open_ticket = FactoryGirl.create :ticket_with_comment,
+ open_ticket = FactoryBot.create :ticket_with_comment,
created_by: @current_user.id
post :close, id: open_ticket.id
assert !open_ticket.reload.is_open
@@ -145,7 +145,7 @@ class TicketsControllerTest < ActionController::TestCase
test "reopen ticket" do
login
- open_ticket = FactoryGirl.create :ticket_with_comment,
+ open_ticket = FactoryBot.create :ticket_with_comment,
created_by: @current_user.id, is_open: false
post :open, id: open_ticket.id
assert open_ticket.reload.is_open
diff --git a/engines/support/test/functional/tickets_list_test.rb b/engines/support/test/functional/tickets_list_test.rb
index ab76f5f..0e676b8 100644
--- a/engines/support/test/functional/tickets_list_test.rb
+++ b/engines/support/test/functional/tickets_list_test.rb
@@ -12,7 +12,7 @@ class TicketsListTest < ActionController::TestCase
test "tickets by admin" do
other_user = find_record :user
- ticket = FactoryGirl.create :ticket, :created_by => other_user.id
+ ticket = create_ticket :created_by => other_user.id
login :is_admin? => true
@@ -29,7 +29,7 @@ class TicketsListTest < ActionController::TestCase
test "admin_status mine vs all" do
- testticket = FactoryGirl.create :ticket
+ testticket = create_ticket
user = find_record :user
login :is_admin? => true, :email => nil
@@ -40,8 +40,7 @@ class TicketsListTest < ActionController::TestCase
end
test "admin ticket ordering" do
- tickets = FactoryGirl.create_list :ticket, 2
-
+ 2.times { create_ticket }
login :is_admin? => true, :email => nil
get :index, {:admin_status => "all", :open_status => "open", :sort_order => 'created_at_desc'}
@@ -63,9 +62,9 @@ class TicketsListTest < ActionController::TestCase
test "own tickets include tickets commented upon" do
login
- ticket = FactoryGirl.create :ticket
- other_ticket = FactoryGirl.create :ticket
- comment = FactoryGirl.build(:ticket_comment, posted_by: @current_user.id)
+ ticket = create_ticket
+ other_ticket = create_ticket
+ comment = FactoryBot.build :ticket_comment, posted_by: @current_user.id
ticket.comments << comment
ticket.save
@@ -77,20 +76,16 @@ class TicketsListTest < ActionController::TestCase
test "list all tickets created by user" do
login
- ticket = FactoryGirl.create :ticket_with_comment,
- created_by: @current_user.id
- other_ticket = FactoryGirl.create :ticket_with_comment,
- created_by: @current_user.id
+ ticket = create_ticket_with_comment created_by: @current_user.id
+ other_ticket = create_ticket_with_comment created_by: @current_user.id
get :index, {:open_status => "open"}
assert_equal 2, assigns[:all_tickets].count
end
test "closing ticket removes from open tickets list" do
login
- ticket = FactoryGirl.create :ticket_with_comment,
- created_by: @current_user.id
- other_ticket = FactoryGirl.create :ticket_with_comment,
- created_by: @current_user.id
+ ticket = create_ticket_with_comment created_by: @current_user.id
+ other_ticket = create_ticket_with_comment created_by: @current_user.id
other_ticket.reload
other_ticket.close
other_ticket.save
@@ -100,23 +95,29 @@ class TicketsListTest < ActionController::TestCase
test "list closed tickets only" do
login
- open_ticket = FactoryGirl.create :ticket_with_comment,
- created_by: @current_user.id
- closed_ticket = FactoryGirl.create :ticket_with_comment,
- created_by: @current_user.id, is_open: false
+ open_ticket = create_ticket_with_comment created_by: @current_user.id
+ closed_ticket = create_ticket_with_comment created_by: @current_user.id,
+ is_open: false
get :index, {:open_status => "closed"}
assert_equal [closed_ticket], assigns(:all_tickets).all
end
test "list all tickets" do
login
- open_ticket = FactoryGirl.create :ticket_with_comment,
- created_by: @current_user.id
- closed_ticket = FactoryGirl.create :ticket_with_comment,
- created_by: @current_user.id, is_open: false
+ open_ticket = create_ticket_with_comment created_by: @current_user.id
+ closed_ticket = create_ticket_with_comment created_by: @current_user.id,
+ is_open: false
get :index, {:open_status => "all"}
assert_equal 2, assigns(:all_tickets).count
assert assigns(:all_tickets).include?(open_ticket)
assert assigns(:all_tickets).include?(closed_ticket)
end
+
+ def create_ticket(attrs = {})
+ FactoryBot.create :ticket, attrs
+ end
+
+ def create_ticket_with_comment(attrs = {})
+ FactoryBot.create :ticket_with_comment, attrs
+ end
end