@@ -12,7 +12,7 @@ class TicketsListTest < ActionController::TestCase
12
12
13
13
test "tickets by admin" do
14
14
other_user = find_record :user
15
- ticket = FactoryGirl . create :ticket , :created_by => other_user . id
15
+ ticket = create_ticket :created_by => other_user . id
16
16
17
17
login :is_admin? => true
18
18
@@ -29,7 +29,7 @@ class TicketsListTest < ActionController::TestCase
29
29
30
30
31
31
test "admin_status mine vs all" do
32
- testticket = FactoryGirl . create :ticket
32
+ testticket = create_ticket
33
33
user = find_record :user
34
34
login :is_admin? => true , :email => nil
35
35
@@ -40,8 +40,7 @@ class TicketsListTest < ActionController::TestCase
40
40
end
41
41
42
42
test "admin ticket ordering" do
43
- tickets = FactoryGirl . create_list :ticket , 2
44
-
43
+ 2 . times { create_ticket }
45
44
login :is_admin? => true , :email => nil
46
45
get :index , { :admin_status => "all" , :open_status => "open" , :sort_order => 'created_at_desc' }
47
46
@@ -63,9 +62,9 @@ class TicketsListTest < ActionController::TestCase
63
62
64
63
test "own tickets include tickets commented upon" do
65
64
login
66
- ticket = FactoryGirl . create :ticket
67
- other_ticket = FactoryGirl . create :ticket
68
- comment = FactoryGirl . build ( :ticket_comment , posted_by : @current_user . id )
65
+ ticket = create_ticket
66
+ other_ticket = create_ticket
67
+ comment = FactoryBot . build :ticket_comment , posted_by : @current_user . id
69
68
ticket . comments << comment
70
69
ticket . save
71
70
@@ -77,20 +76,16 @@ class TicketsListTest < ActionController::TestCase
77
76
78
77
test "list all tickets created by user" do
79
78
login
80
- ticket = FactoryGirl . create :ticket_with_comment ,
81
- created_by : @current_user . id
82
- other_ticket = FactoryGirl . create :ticket_with_comment ,
83
- created_by : @current_user . id
79
+ ticket = create_ticket_with_comment created_by : @current_user . id
80
+ other_ticket = create_ticket_with_comment created_by : @current_user . id
84
81
get :index , { :open_status => "open" }
85
82
assert_equal 2 , assigns [ :all_tickets ] . count
86
83
end
87
84
88
85
test "closing ticket removes from open tickets list" do
89
86
login
90
- ticket = FactoryGirl . create :ticket_with_comment ,
91
- created_by : @current_user . id
92
- other_ticket = FactoryGirl . create :ticket_with_comment ,
93
- created_by : @current_user . id
87
+ ticket = create_ticket_with_comment created_by : @current_user . id
88
+ other_ticket = create_ticket_with_comment created_by : @current_user . id
94
89
other_ticket . reload
95
90
other_ticket . close
96
91
other_ticket . save
@@ -100,23 +95,29 @@ class TicketsListTest < ActionController::TestCase
100
95
101
96
test "list closed tickets only" do
102
97
login
103
- open_ticket = FactoryGirl . create :ticket_with_comment ,
104
- created_by : @current_user . id
105
- closed_ticket = FactoryGirl . create :ticket_with_comment ,
106
- created_by : @current_user . id , is_open : false
98
+ open_ticket = create_ticket_with_comment created_by : @current_user . id
99
+ closed_ticket = create_ticket_with_comment created_by : @current_user . id ,
100
+ is_open : false
107
101
get :index , { :open_status => "closed" }
108
102
assert_equal [ closed_ticket ] , assigns ( :all_tickets ) . all
109
103
end
110
104
111
105
test "list all tickets" do
112
106
login
113
- open_ticket = FactoryGirl . create :ticket_with_comment ,
114
- created_by : @current_user . id
115
- closed_ticket = FactoryGirl . create :ticket_with_comment ,
116
- created_by : @current_user . id , is_open : false
107
+ open_ticket = create_ticket_with_comment created_by : @current_user . id
108
+ closed_ticket = create_ticket_with_comment created_by : @current_user . id ,
109
+ is_open : false
117
110
get :index , { :open_status => "all" }
118
111
assert_equal 2 , assigns ( :all_tickets ) . count
119
112
assert assigns ( :all_tickets ) . include? ( open_ticket )
120
113
assert assigns ( :all_tickets ) . include? ( closed_ticket )
121
114
end
115
+
116
+ def create_ticket ( attrs = { } )
117
+ FactoryBot . create :ticket , attrs
118
+ end
119
+
120
+ def create_ticket_with_comment ( attrs = { } )
121
+ FactoryBot . create :ticket_with_comment , attrs
122
+ end
122
123
end
0 commit comments