Skip to content

Commit 5480c8f

Browse files
committed
spec: speed up api specs
liberal applicataion of once-ler and bulk_insert helpers, reduce runtime from 50min -> 25min Change-Id: I07c1952c4ead0a1c6caafc389de0b9586b27dc68 Reviewed-on: https://gerrit.instructure.com/37794 Reviewed-by: Landon Wilkins <lwilkins@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> Product-Review: Jon Jensen <jon@instructure.com> QA-Review: Jon Jensen <jon@instructure.com>
1 parent 2acbe01 commit 5480c8f

85 files changed

Lines changed: 1290 additions & 1410 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/models/folder.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@ def self.assert_path(path, context)
309309
@@path_lookups[key] = current_folder
310310
end
311311

312+
def self.reset_path_lookups!
313+
@@root_folders = {}
314+
@@path_lookups = {}
315+
end
316+
312317
def self.unfiled_folder(context)
313318
folder = context.folders.find_by_parent_folder_id_and_workflow_state_and_name(Folder.root_folders(context).first.id, 'visible', 'unfiled')
314319
unless folder

spec/apis/auth_spec.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121

2222
describe "API Authentication", type: :request do
2323

24-
before do
24+
before :once do
2525
@key = DeveloperKey.create!
26+
end
27+
28+
before :each do
2629
@client_id = @key.id
2730
@client_secret = @key.api_key
2831
consider_all_requests_local(false)
@@ -72,9 +75,12 @@
7275

7376
describe "should continue to allow developer key + basic auth access" do
7477
# this will continue to be supported until we notify api users and explicitly phase it out
75-
before do
78+
before :once do
7679
user_with_pseudonym(:active_user => true, :username => 'test1@example.com', :password => 'test123')
7780
course_with_teacher(:user => @user)
81+
end
82+
83+
before :each do
7884
post '/login', 'pseudonym_session[unique_id]' => 'test1@example.com', 'pseudonym_session[password]' => 'test123'
7985
end
8086

@@ -469,7 +475,7 @@ def cas.validate_service_ticket(st)
469475
end
470476

471477
describe "access token" do
472-
before do
478+
before :once do
473479
user_with_pseudonym(:active_user => true, :username => 'test1@example.com', :password => 'test123')
474480
course_with_teacher(:user => @user)
475481
@token = @user.access_tokens.create!
@@ -566,7 +572,7 @@ def check_used
566572
end
567573

568574
describe "as_user_id" do
569-
before do
575+
before :once do
570576
course_with_teacher(:active_all => true)
571577
@course1 = @course
572578
course_with_student(:user => @user, :active_all => true)
@@ -722,7 +728,7 @@ def check_used
722728
end
723729

724730
describe "CSRF protection" do
725-
before do
731+
before :once do
726732
course_with_teacher(:active_all => true)
727733
@course1 = @course
728734
course_with_student(:user => @user, :active_all => true)

spec/apis/error_handling_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
require File.expand_path(File.dirname(__FILE__) + '/api_spec_helper')
2020

2121
describe "API Error Handling", type: :request do
22-
before do
22+
before :once do
2323
user_with_pseudonym(:active_all => true)
2424
@token = @user.access_tokens.create!
2525
end

spec/apis/general_api_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def @course.filter_attributes_for_user(hash, user, session)
8282
end
8383

8484
describe "json post format" do
85-
before do
85+
before :once do
8686
course_with_teacher(:user => user_with_pseudonym, :active_all => true)
8787
@token = @user.access_tokens.create!(:purpose => "specs")
8888
end

spec/apis/locked_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def verify_locked(*lock_info_extra)
3939
lock_info_extra.each { |attribute| lock_info[attribute.to_s].should_not be_nil, "expected lock_info to contain '#{attribute.to_s}'" }
4040
end
4141

42-
before(:each) do
42+
before(:once) do
4343
course_with_student(:active_all => true)
4444
end
4545

spec/apis/lti/grade_passback_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
require File.expand_path(File.dirname(__FILE__) + '/../api_spec_helper')
2020

2121
describe LtiApiController, type: :request do
22-
before do
22+
before :once do
2323
course_with_student(:active_all => true)
2424
@student = @user
2525
@course.enroll_teacher(user_with_pseudonym(:active_all => true))

spec/apis/user_content_spec.rb

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
require File.expand_path(File.dirname(__FILE__) + '/api_spec_helper')
2020

2121
describe UserContent, type: :request do
22-
it "should translate course file download links to directly-downloadable urls" do
23-
course_with_teacher_logged_in(:active_all => true)
22+
before :once do
23+
course_with_teacher(:active_all => true)
2424
attachment_model
25+
end
26+
27+
it "should translate course file download links to directly-downloadable urls" do
2528
@assignment = @course.assignments.create!(:title => "first assignment", :description => <<-HTML)
2629
<p>
2730
Hello, students.<br>
@@ -39,7 +42,6 @@
3942
end
4043

4144
it "should translate group file download links to directly-downloadable urls" do
42-
course_with_teacher_logged_in(:active_all => true)
4345
@group = @course.groups.create!(:name => "course group")
4446
attachment_model(:context => @group)
4547
@group.add_user(@teacher)
@@ -60,8 +62,6 @@
6062
end
6163

6264
it "should translate file download links to directly-downloadable urls for deleted and replaced files" do
63-
course_with_teacher_logged_in(:active_all => true)
64-
attachment_model
6565
@attachment.destroy
6666
attachment2 = Attachment.create!(:folder => @attachment.folder, :context => @attachment.context, :filename => @attachment.filename, :uploaded_data => StringIO.new("first"))
6767
@context.attachments.find(@attachment.id).id.should == attachment2.id
@@ -83,7 +83,6 @@
8383
end
8484

8585
it "should not corrupt absolute links" do
86-
course_with_teacher_logged_in
8786
attachment_model(:context => @course)
8887
@topic = @course.discussion_topics.create!(:title => "course topic", :user => @teacher, :message => <<-HTML)
8988
<p>
@@ -100,8 +99,6 @@
10099
end
101100

102101
it "should translate file preview links to directly-downloadable preview urls" do
103-
course_with_teacher_logged_in(:active_all => true)
104-
attachment_model
105102
@assignment = @course.assignments.create!(:title => "first assignment", :description => <<-HTML)
106103
<p>
107104
Hello, students.<br>
@@ -119,8 +116,6 @@
119116
end
120117

121118
it "should translate media comment links to embedded video tags" do
122-
course_with_teacher_logged_in(:active_all => true)
123-
attachment_model
124119
@assignment = @course.assignments.create!(:title => "first assignment", :description => <<-HTML)
125120
<p>
126121
Hello, students.<br>
@@ -149,8 +144,6 @@
149144
end
150145

151146
it "should translate media comment audio tags" do
152-
course_with_teacher_logged_in(:active_all => true)
153-
attachment_model
154147
@assignment = @course.assignments.create!(:title => "first assignment", :description => <<-HTML)
155148
<p>
156149
Hello, students.<br>
@@ -175,8 +168,6 @@
175168
end
176169

177170
it "should not translate links in content not viewable by user" do
178-
course_with_teacher_logged_in(:active_all => true)
179-
attachment_model
180171
@assignment = @course.assignments.create!(:title => "first assignment", :description => <<-HTML)
181172
<p>
182173
Hello, students.<br>
@@ -201,7 +192,6 @@
201192
end
202193

203194
it "should prepend the hostname to all absolute-path links" do
204-
course_with_teacher_logged_in(:active_all => true)
205195
@assignment = @course.assignments.create!(:title => "first assignment", :description => <<-HTML)
206196
<p>
207197
Hello, students.<br>
@@ -229,7 +219,6 @@
229219
end
230220

231221
it "should not choke on funny email addresses" do
232-
course_with_teacher_logged_in(:active_all => true)
233222
@wiki_page = @course.wiki.front_page
234223
@wiki_page.body = "<a href='mailto:djmankiewicz@homestarrunner,com'>e-nail</a>"
235224
@wiki_page.workflow_state = 'active'
@@ -242,7 +231,6 @@
242231
context "data api endpoints" do
243232
context "course context" do
244233
it "should process links to each type of object" do
245-
course_with_teacher_logged_in(:active_all => true)
246234
@wiki_page = @course.wiki.front_page
247235
@wiki_page.body = <<-HTML
248236
<p>
@@ -322,7 +310,6 @@
322310

323311
context "user context" do
324312
it "should process links to each type of object" do
325-
course_with_teacher_logged_in(:active_all => true)
326313
@topic = @course.discussion_topics.create!(:message => <<-HTML)
327314
<a href='/users/#{@teacher.id}/files'>file index</a>
328315
<a href='/users/#{@teacher.id}/files/789/preview'>file</a>
@@ -409,7 +396,6 @@ class Tester
409396

410397
describe ".api_bulk_load_user_content_attachments" do
411398
it "returns a hash of assignment_id => assignment" do
412-
course_with_teacher_logged_in(:active_all => true)
413399
a1, a2, a3 = attachment_model, attachment_model, attachment_model
414400
html1, html2 = <<-HTML1, <<-HTML2
415401
<a href="/courses/#{@course.id}/files/#{a1.id}/download">uh...</a>

spec/apis/v1/account_authorization_configs_api_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
require File.expand_path(File.dirname(__FILE__) + '/../api_spec_helper')
2020

2121
describe "AccountAuthorizationConfigs API", type: :request do
22-
before do
22+
before :once do
2323
@account = account_model(:name => 'root')
2424
user_with_pseudonym(:active_all => true, :account => @account)
2525
@account.account_users.create!(user: @user)
@@ -366,7 +366,7 @@ def call_destroy(id, status = 200)
366366
end
367367

368368
context "discovery url" do
369-
append_before do
369+
before :once do
370370
@account.auth_discovery_url = "http://example.com/auth"
371371
@account.save!
372372
end

spec/apis/v1/account_authorization_configs_deprecated_api_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
require File.expand_path(File.dirname(__FILE__) + '/../api_spec_helper')
2121

2222
describe "AccountAuthorizationConfigs API", type: :request do
23-
before do
23+
before :once do
2424
@account = account_model(:name => 'root')
2525
user_with_pseudonym(:active_all => true, :account => @account)
2626
@account.account_users.create!(user: @user)

spec/apis/v1/account_reports_api_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
require File.expand_path(File.dirname(__FILE__) + '/../api_spec_helper')
2020

2121
describe 'Account Reports API', type: :request do
22-
before do
22+
before :once do
2323
@admin = account_admin_user
2424
user_with_pseudonym(:user => @admin)
2525
@report = AccountReport.new

0 commit comments

Comments
 (0)