spec: create fewer objects

I’m sure this could improved more, but this works
with a few seconds of work and saves seconds per
run.

test plan
 - specs should pass

Change-Id: If2d8e9c8857c58485fef3745d88ecb22ef51e5c1
Reviewed-on: https://gerrit.instructure.com/151956
Tested-by: Jenkins
Reviewed-by: James Williams  <jamesw@instructure.com>
Product-Review: Rob Orton <rob@instructure.com>
QA-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
Rob Orton 2018-05-30 15:57:14 -06:00
parent 4ba1e44abb
commit 10ee663f3f
1 changed files with 9 additions and 9 deletions

View File

@ -128,7 +128,7 @@ describe AssignmentsApiController, type: :request do
it 'returns all assignments using paging' do it 'returns all assignments using paging' do
group1 = @course.assignment_groups.create!(:name => 'group1') group1 = @course.assignment_groups.create!(:name => 'group1')
41.times do 5.times do
@course.assignments.create!(:title => 'assignment1', @course.assignments.create!(:title => 'assignment1',
:assignment_group => group1). :assignment_group => group1).
update_attribute(:position, 0) update_attribute(:position, 0)
@ -137,21 +137,21 @@ describe AssignmentsApiController, type: :request do
page = 1 page = 1
loop do loop do
json = api_call(:get, json = api_call(:get,
"/api/v1/courses/#{@course.id}/assignments.json?per_page=10&page=#{page}", "/api/v1/courses/#{@course.id}/assignments.json?per_page=2&page=#{page}",
{ {
:controller => 'assignments_api', :controller => 'assignments_api',
:action => 'index', :action => 'index',
:format => 'json', :format => 'json',
:course_id => @course.id.to_s, :course_id => @course.id.to_s,
:per_page => '10', :per_page => '2',
:page => page.to_s :page => page.to_s
}) })
assignment_ids.concat(json.map { |a| a['id'] }) assignment_ids.concat(json.map { |a| a['id'] })
break if json.empty? break if json.length == 1
page +=1 page +=1
end end
expect(assignment_ids.count).to eq(41) expect(assignment_ids.count).to eq(5)
expect(assignment_ids.uniq.count).to eq(41) expect(assignment_ids.uniq.count).to eq(5)
end end
it "sorts the returned list of assignments" do it "sorts the returned list of assignments" do
@ -270,9 +270,9 @@ describe AssignmentsApiController, type: :request do
end end
it "should allow filtering based on assignment_ids[] parameter" do it "should allow filtering based on assignment_ids[] parameter" do
13.times { |i| @course.assignments.create!(title: "a_#{i}") } 5.times { |i| @course.assignments.create!(title: "a_#{i}") }
all_ids = @course.assignments.pluck(:id).map(&:to_s) all_ids = @course.assignments.pluck(:id).map(&:to_s)
some_ids = all_ids.slice(1, 4) some_ids = all_ids.slice(1, 3)
query_string = some_ids.map { |id| "assignment_ids[]=#{id}" }.join('&') query_string = some_ids.map { |id| "assignment_ids[]=#{id}" }.join('&')
json = api_call(:get, json = api_call(:get,
@ -285,7 +285,7 @@ describe AssignmentsApiController, type: :request do
:assignment_ids => some_ids :assignment_ids => some_ids
}) })
expect(json.length).to eq 4 expect(json.length).to eq 3
expect(json.map{|h| h['id']}.map(&:to_s).sort).to eq some_ids.sort expect(json.map{|h| h['id']}.map(&:to_s).sort).to eq some_ids.sort
end end