summaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/billing/test/broken/admin_customer_test.rb4
-rw-r--r--engines/billing/test/broken/customer_creation_test.rb6
-rw-r--r--engines/billing/test/broken/subscription_test.rb2
-rw-r--r--engines/billing/test/factories.rb2
-rw-r--r--engines/support/test/factories.rb4
-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
-rw-r--r--engines/support/test/integration/create_ticket_test.rb8
-rw-r--r--engines/support/test/unit/account_extension_test.rb2
-rw-r--r--engines/support/test/unit/ticket_test.rb21
11 files changed, 68 insertions, 50 deletions
diff --git a/engines/billing/test/broken/admin_customer_test.rb b/engines/billing/test/broken/admin_customer_test.rb
index df92a0d..2fb80ca 100644
--- a/engines/billing/test/broken/admin_customer_test.rb
+++ b/engines/billing/test/broken/admin_customer_test.rb
@@ -4,8 +4,8 @@ require 'fake_braintree'
class AdminCustomerTest < BraintreeIntegrationTest
setup do
- @admin = User.find_by_login('admin') || FactoryGirl.create(:user, login: 'admin')
- @user = FactoryGirl.create(:user)
+ @admin = User.find_by_login('admin') || FactoryBot.create(:user, login: 'admin')
+ @user = FactoryBot.create(:user)
end
teardown do
diff --git a/engines/billing/test/broken/customer_creation_test.rb b/engines/billing/test/broken/customer_creation_test.rb
index 90319a9..da171c4 100644
--- a/engines/billing/test/broken/customer_creation_test.rb
+++ b/engines/billing/test/broken/customer_creation_test.rb
@@ -4,7 +4,7 @@ require 'fake_braintree'
class CustomerCreationTest < BraintreeIntegrationTest
setup do
- @user = FactoryGirl.create(:user)
+ @user = FactoryBot.create(:user)
login_as @user
end
@@ -38,7 +38,7 @@ class CustomerCreationTest < BraintreeIntegrationTest
# for a broken customer
test "successfully confirms customer creation" do
response = post_transparent_redirect :create_customer_data,
- customer: FactoryGirl.attributes_for(:braintree_customer),
+ customer: FactoryBot.attributes_for(:braintree_customer),
redirect_url: confirm_customer_url
assert_difference("Customer.count") do
@@ -57,7 +57,7 @@ class CustomerCreationTest < BraintreeIntegrationTest
FakeBraintree.decline_all_cards!
response = post_transparent_redirect :create_customer_data,
- customer: FactoryGirl.attributes_for(:broken_customer),
+ customer: FactoryBot.attributes_for(:broken_customer),
redirect_url: confirm_customer_url
assert FakeBraintree.decline_all_cards?
diff --git a/engines/billing/test/broken/subscription_test.rb b/engines/billing/test/broken/subscription_test.rb
index cd010bd..dd9bba9 100644
--- a/engines/billing/test/broken/subscription_test.rb
+++ b/engines/billing/test/broken/subscription_test.rb
@@ -6,7 +6,7 @@ class SubscriptionTest < BraintreeIntegrationTest
include StubRecordHelper
setup do
- @admin = User.find_by_login('admin') || FactoryGirl.create(:user, login: 'admin')
+ @admin = User.find_by_login('admin') || FactoryBot.create(:user, login: 'admin')
@customer = stub_customer
@braintree_customer = @customer.braintree_customer
response = Braintree::Subscription.create plan_id: '5',
diff --git a/engines/billing/test/factories.rb b/engines/billing/test/factories.rb
index 6352211..572da48 100644
--- a/engines/billing/test/factories.rb
+++ b/engines/billing/test/factories.rb
@@ -1,4 +1,4 @@
-FactoryGirl.define do
+FactoryBot.define do
TEST_CC_NUMBER = %w(4111 1111 1111 1111).join
diff --git a/engines/support/test/factories.rb b/engines/support/test/factories.rb
index 3fc28b3..7bc2ec7 100644
--- a/engines/support/test/factories.rb
+++ b/engines/support/test/factories.rb
@@ -1,4 +1,4 @@
-FactoryGirl.define do
+FactoryBot.define do
factory :ticket do
subject { Faker::Lorem.sentence }
@@ -14,7 +14,7 @@ FactoryGirl.define do
end
factory :ticket_with_creator do
- created_by { FactoryGirl.create(:user).id }
+ created_by { FactoryBot.create(:user).id }
end
end
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
diff --git a/engines/support/test/integration/create_ticket_test.rb b/engines/support/test/integration/create_ticket_test.rb
index fcdc6b8..cccd2b2 100644
--- a/engines/support/test/integration/create_ticket_test.rb
+++ b/engines/support/test/integration/create_ticket_test.rb
@@ -34,7 +34,9 @@ class CreateTicketTest < BrowserIntegrationTest
end
test "prefills fields" do
- login FactoryGirl.create(:premium_user, :invite_code => @testcode.invite_code)
+ user = FactoryBot.create :premium_user,
+ :invite_code => @testcode.invite_code
+ login user
visit '/'
click_on "Support Tickets"
click_on "New Ticket"
@@ -53,7 +55,9 @@ class CreateTicketTest < BrowserIntegrationTest
end
test "cleared email field should remain clear" do
- login FactoryGirl.create(:premium_user, :invite_code => @testcode.invite_code)
+ user = FactoryBot.create :premium_user,
+ :invite_code => @testcode.invite_code
+ login user
visit '/'
click_on "Support Tickets"
click_on "New Ticket"
diff --git a/engines/support/test/unit/account_extension_test.rb b/engines/support/test/unit/account_extension_test.rb
index 1b97062..88dc681 100644
--- a/engines/support/test/unit/account_extension_test.rb
+++ b/engines/support/test/unit/account_extension_test.rb
@@ -7,7 +7,7 @@ class AccountExtensionTest < ActiveSupport::TestCase
end
test "destroying an account triggers ticket destruction" do
- t = FactoryGirl.create :ticket_with_creator
+ t = FactoryBot.create :ticket_with_creator
u = t.created_by_user
Account.new(u).destroy
assert_nil Ticket.find(t.id)
diff --git a/engines/support/test/unit/ticket_test.rb b/engines/support/test/unit/ticket_test.rb
index 048704c..78c81bd 100644
--- a/engines/support/test/unit/ticket_test.rb
+++ b/engines/support/test/unit/ticket_test.rb
@@ -7,22 +7,22 @@ class TicketTest < ActiveSupport::TestCase
end
test "ticket with default attribs is valid" do
- t = FactoryGirl.build :ticket
+ t = build_ticket
assert t.valid?, t.errors.full_messages.to_sentence
end
test "ticket without email is valid" do
- t = FactoryGirl.build :ticket, email: ""
+ t = build_ticket email: ""
assert t.valid?, t.errors.full_messages.to_sentence
end
test "ticket validates email format" do
- t = FactoryGirl.build :ticket, email: "invalid email"
+ t = build_ticket email: "invalid email"
assert !t.valid?
end
test "ticket open states" do
- t = FactoryGirl.build :ticket
+ t = build_ticket
assert t.is_open
t.close
assert !t.is_open
@@ -31,7 +31,7 @@ class TicketTest < ActiveSupport::TestCase
end
test "creation validated" do
- user = FactoryGirl.create :user
+ user = create_user
@sample = Ticket.new
assert !@sample.is_creator_validated?
@sample.created_by = user.id
@@ -39,7 +39,7 @@ class TicketTest < ActiveSupport::TestCase
end
test "destroy all tickets from a user" do
- t = FactoryGirl.create :ticket_with_creator
+ t = FactoryBot.create :ticket_with_creator
u = t.created_by_user
Ticket.destroy_all_from(u)
assert_nil Ticket.find(t.id)
@@ -89,4 +89,13 @@ class TicketTest < ActiveSupport::TestCase
assert_equal [], Ticket.by_includes_post_by.key('123').all;
end
+ protected
+
+ def build_ticket(attrs = {})
+ FactoryBot.build :ticket, attrs
+ end
+
+ def create_user
+ FactoryBot.create :user
+ end
end