8000 arel-ify specs · csseditor/canvas-lms@6dbb42e · GitHub
Skip to content

Commit 6dbb42e

Browse files
committed
arel-ify specs
refs CNVS-4707 Change-Id: I3b559e6c80d817760e78df47d6c1d7c88f464f2b Reviewed-on: https://gerrit.instructure.com/18984 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com> Product-Review: Cody Cutrer <cody@instructure.com> QA-Review: Cody Cutrer <cody@instructure.com>
1 parent 79fad58 commit 6dbb42e

75 files changed

Lines changed: 254 additions & 259 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.

spec/apis/file_uploads_spec_helper.rb

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def attachment_json(attachment)
4545
local_storage!
4646
# step 1, preflight
4747
json = preflight({ :name => filename })
48-
attachment = Attachment.last(:order => :id)
48+
attachment = Attachment.order(:id).last
4949
exemption_string = has_query_exemption? ? ("?quota_exemption=" + attachment.quota_exemption_key) : ""
5050
json['upload_url'].should == "http://www.example.com/files_api#{exemption_string}"
5151

@@ -56,7 +56,7 @@ def attachment_json(attachment)
5656
post_params = json["upload_params"].merge({"file" => tmpfile})
5757
send_multipart(json["upload_url"], post_params)
5858

59-
attachment = Attachment.last(:order => :id)
59+
attachment = Attachment.order(:id).last
6060
attachment.should be_deleted
6161
exemption_string = has_query_exemption? ? ("quota_exemption=" + attachment.quota_exemption_key + "&") : ""
6262
response.should redirect_to("http://www.example.com/api/v1/files/#{attachment.id}/create_success?#{exemption_string}uuid=#{attachment.uuid}")
@@ -98,7 +98,7 @@ def attachment_json(attachment)
9898
# step 1, preflight
9999
json = preflight({ :name => filename })
100100
json['upload_url'].should == "http://no-bucket.s3.amazonaws.com/"
101-
attachment = Attachment.last(:order => :id)
101+
attachment = Attachment.order(:id).last
102102
redir = json['upload_params']['success_action_redirect']
103103
exemption_string = has_query_exemption? ? ("quota_exemption=" + attachment.quota_exemption_key + "&") : ""
104104
redir.should == "http://www.example.com/api/v1/files/#{attachment.id}/create_success?#{exemption_string}uuid=#{attachment.uuid}"
@@ -130,7 +130,7 @@ def attachment_json(attachment)
130130
local_storage!
131131
# step 1, preflight
132132
json = preflight({ :name => filename, :size => 20, :url => "http://www.example.com/images/delete.png" })
133-
attachment = Attachment.last(:order => :id)
133+
attachment = Attachment.order(:id).last
134134
attachment.file_state.should == 'deleted'
135135
status_url = json['status_url']
136136
status_url.should == "http://www.example.com/api/v1/files/#{attachment.id}/#{attachment.uuid}/status"
@@ -158,7 +158,7 @@ def attachment_json(attachment)
158158
local_storage!
159159
# step 1, preflight
160160
json = preflight({ :name => filename, :size => 20, :url => '#@$YA#Y#AGWREG' })
161-
attachment = Attachment.last(:order => :id)
161+
attachment = Attachment.order(:id).last
162162
json['status_url'].should == "http://www.example.com/api/v1/files/#{attachment.id}/#{attachment.uuid}/status"
163163

164164
# step 2, download
@@ -175,7 +175,7 @@ def attachment_json(attachment)
175175
local_storage!
176176
# step 1, preflight
177177
json = preflight({ :name => filename, :size => 20, :url => '/images/delete.png' })
178-
attachment = Attachment.last(:order => :id)
178+
attachment = Attachment.order(:id).last
179179
json['status_url'].should == "http://www.example.com/api/v1/files/#{attachment.id}/#{attachment.uuid}/status"
180180

181181
# step 2, download
@@ -194,7 +194,7 @@ def attachment_json(attachment)
194194
# step 1, preflight
195195
Canvas::HTTP.expects(:get).with(url).yields(FakeHttpResponse.new(404))
196196
json = preflight({ :name => filename, :size => 20, :url => url })
197-
attachment = Attachment.last(:order => :id)
197+
attachment = Attachment.order(:id).last
198198
json['status_url'].should == "http://www.example.com/api/v1/files/#{attachment.id}/#{attachment.uuid}/status"
199199

200200
# step 2, download
@@ -213,7 +213,7 @@ def attachment_json(attachment)
213213
# step 1, preflight
214214
Canvas::HTTP.expects(:get).with(url).raises(Timeout::Error)
215215
json = preflight({ :name => filename, :size => 20, :url => url })
216-
attachment = Attachment.last(:order => :id)
216+
attachment = Attachment.order(:id).last
217217
json['status_url'].should == "http://www.example.com/api/v1/files/#{attachment.id}/#{attachment.uuid}/status"
218218

219219
# step 2, download
@@ -232,7 +232,7 @@ def attachment_json(attachment)
232232
# step 1, preflight
233233
Canvas::HTTP.expects(:get).with(url).raises(Canvas::HTTP::TooManyRedirectsError)
234234
json = preflight({ :name => filename, :size => 20, :url => url })
235-
attachment = Attachment.last(:order => :id)
235+
attachment = Attachment.order(:id).last
236236
attachment.workflow_state.should == 'unattached'
237237
json['status_url'].should == "http://www.example.com/api/v1/files/#{attachment.id}/#{attachment.uuid}/status"
238238

@@ -256,21 +256,21 @@ def run_download_job
256256

257257
it "should allow specifying a folder with deprecated argument name" do
258258
preflight({ :name => "with_path.txt", :folder => "files/a/b/c/mypath" })
259-
attachment = Attachment.last(:order => :id)
259+
attachment = Attachment.order(:id).last
260260
attachment.folder.should == Folder.assert_path("/files/a/b/c/mypath", context)
261261
end
262262

263263
it "should allow specifying a folder" do
264264
preflight({ :name => "with_path.txt", :parent_folder_path => "files/a/b/c/mypath" })
265-
attachment = Attachment.last(:order => :id)
265+
attachment = Attachment.order(:id).last
266266
attachment.folder.should == Folder.assert_path("/files/a/b/c/mypath", context)
267267
end
268268

269269
it "should allow specifying a parent folder by id" do
270270
root = Folder.root_folders(context).first
271271
sub = root.sub_folders.create!(:name => "folder1", :context => context)
272272
preflight({ :name => "with_path.txt", :parent_folder_id => sub.id.to_param })
273-
attachment = Attachment.last(:order => :id)
273+
attachment = Attachment.order(:id).last
274274
attachment.folder_id.should == sub.id
275275
end
276276

@@ -279,7 +279,7 @@ def run_download_job
279279
@folder.should be_present
280280
@folder.should be_visible
281281
preflight({ :name => "my_essay.doc", :folder => "files/a/b/c/mypath" })
282-
attachment = Attachment.last(:order => :id)
282+
attachment = Attachment.order(:id).last
283283
attachment.folder.should == @folder
284284
end
285285

@@ -296,7 +296,7 @@ def run_download_job
296296
send_multipart(json["upload_url"], post_params)
297297
post response['Location'], {}, { 'Authorization' => "Bearer #{access_token_for_user @user}" }
298298
response.should be_success
299-
attachment = Attachment.last(:order => :id)
299+
attachment = Attachment.order(:id).last
300300
a1.reload.should be_deleted
301301
attachment.reload.should be_available
302302
attachment.display_name.should == "test.txt"
@@ -309,7 +309,7 @@ def run_download_job
309309
@folder = Folder.assert_path("test", context)
310310
a1 = Attachment.create!(:folder => @folder, :context => context, :filename => "test.txt", :uploaded_data => StringIO.new("first"))
311311
json = preflight({ :name => "test.txt", :folder => "test", :url => "http://www.example.com/test" })
312-
attachment = Attachment.last(:order => :id)
312+
attachment = Attachment.order(:id).last
313313
Canvas::HTTP.expects(:get).with("http://www.example.com/test").yields(FakeHttpResponse.new(200, "second"))
314314
run_jobs
315315

@@ -333,7 +333,7 @@ def run_download_job
333333
send_multipart(json["upload_url"], post_params)
334334
post response['Location'], {}, { 'Authorization' => "Bearer #{access_token_for_user @user}" }
335335
response.should be_success
336-
attachment = Attachment.last(:order => :id)
336+
attachment = Attachment.order(:id).last
337337
a1.reload.should be_available
338338
attachment.reload.should be_available
339339
a1.display_name.should == "test.txt"
@@ -346,7 +346,7 @@ def run_download_job
346346
@folder = Folder.assert_path("test", context)
347347
a1 = Attachment.create!(:folder => @folder, :context => context, :filename => "test.txt", :uploaded_data => StringIO.new("first"))
348348
json = preflight({ :name => "test.txt", :folder => "test", :on_duplicate => 'rename', :url => "http://www.example.com/test" })
349-
attachment = Attachment.last(:order => :id)
349+
attachment = Attachment.order(:id).last
350350
Canvas::HTTP.expects(:get).with("http://www.example.com/test").yields(FakeHttpResponse.new(200, "second"))
351351
run_jobs
352352

@@ -364,7 +364,7 @@ def run_download_job
364364
json = preflight({ :name => "test.txt", :folder => "test", :on_duplicate => 'rename' })
365365

366366
redir = json['upload_params']['success_action_redirect']
367-
attachment = Attachment.last(:order => :id)
367+
attachment = Attachment.order(:id).last
368368
AWS::S3::S3Object.any_instance.expects(:head).returns({
369369
:content_type => 'application/msword',
370370
:content_length => 1234,
@@ -387,7 +387,7 @@ def run_download_job
387387
@context.write_attribute(:storage_quota, 5.megabytes)
388388
@context.save!
389389
json = preflight({ :name => "test.txt", :size => 3.megabytes })
390-
attachment = Attachment.last(:order => :id)
390+
attachment = Attachment.order(:id).last
391391
attachment.workflow_state.should == 'unattached'
392392
attachment.filename.should == 'test.txt'
393393
end
@@ -458,7 +458,7 @@ def run_download_job
458458
@context.save!
459459
json = preflight({ :name => "test.txt", :url => "http://www.example.com/test" })
460460
status_url = json['status_url']
461-
attachment = Attachment.last(:order => :id)
461+
attachment = Attachment.order(:id).last
462462
Canvas::HTTP.expects(:get).with("http://www.example.com/test").yields(FakeHttpResponse.new(200, (" " * 2.megabytes)))
463463
run_jobs
464464

@@ -474,15 +474,15 @@ def run_download_job
474474
@context.write_attribute(:storage_quota, 0)
475475
@context.save!
476476
json = preflight({ :name => "test.txt", :size => 1.megabyte })
477-
attachment = Attachment.last(:order => :id)
477+
attachment = Attachment.order(:id).last
478478
json['upload_url'].should match(/#{attachment.quota_exemption_key}/)
479479
end
480480
it "should ignore context-related quotas in preflight" do
481481
s3_storage!
482482
@context.write_attribute(:storage_quota, 0)
483483
@context.save!
484484
json = preflight({ :name => "test.txt", :size => 1.megabyte })
485-
attachment = Attachment.last(:order => :id)
485+
attachment = Attachment.order(:id).last
486486
json['upload_params']['success_action_redirect'].should match(/#{attachment.quota_exemption_key}/)
487487
end
488488
end

spec/apis/general_api_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def @course.filter_attributes_for_user(hash, user, session)
6666
response.should be_success
6767
response.header['content-type'].should == 'application/json; charset=utf-8'
6868

69-
@assignment = @course.assignments.last(:order => :id)
69+
@assignment = @course.assignments.order(:id).last
7070
@assignment.title.should == "test assignment"
7171
@assignment.points_possible.should == 15
7272
end
@@ -77,7 +77,7 @@ def @course.filter_attributes_for_user(hash, user, session)
7777
response.should be_success
7878
response.header['content-type'].should == 'application/json; charset=utf-8'
7979

80-
@assignment = @course.assignments.last(:order => :id)
80+
@assignment = @course.assignments.order(:id).last
8181
@assignment.title.should == "test assignment"
8282
@assignment.points_possible.should == 15
8383
end

spec/apis/v1/assignments_api_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@
489489
find_or_create_by_notification_id(@notification.id).
490490
update_attribute(:frequency, 'immediately')
491491
@assignment = @course.assignments.create!
492-
Assignment.update_all({:created_at => Time.zone.now - 1.day}, {:id => @assignment.id})
492+
Assignment.where(:id => @assignment).update_all(:created_at => Time.zone.now - 1.day)
493493
@adhoc_due_at = 5.days.from_now
494494
@section_due_at = 7.days.from_now
495495
@params = {

spec/apis/v1/collections_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
:name => "test3",
3737
:visibility => 'public',
3838
})
39-
@c3 = Collection.last(:order => :id)
39+
@c3 = Collection.order(:id).last
4040
json.should == collection_json(@c3).merge({
4141
'id' => @c3.id,
4242
'name' => 'test3',
@@ -241,15 +241,15 @@ def item_json(item, upvoted_by_user = false)
241241
describe "item creation" do
242242
it "should allow creating from a http url" do
243243
json = api_call(:post, @c1_items_path, @c1_items_path_options.merge(:action => "create"), { :link_url => "http://www.example.com/a/b/c", :user_comment => 'new item' })
244-
new_item = @c1.collection_items.last(:order => :id)
244+
new_item = @c1.collection_items.order(:id).last
245245
new_item.collection_item_data.link_url.should == "http://www.example.com/a/b/c"
246246
new_item.user.should == @user
247247
end
248248

249249
it "should allow cloning an existing item" do
250250
json = api_call(:post, @c1_items_path, @c1_items_path_options.merge(:action => "create"), { :link_url => "http://localhost/api/v1/collections/items/#{@i3.id}", :user_comment => 'cloned' })
251251
json['post_count'].should == 3
252-
new_item = @c1.collection_items.last(:order => :id)
252+
new_item = @c1.collection_items.order(:id).last
253253
new_item.collection_item_data.should == @i3.collection_item_data
254254
new_item.user.should == @user
255255
end
@@ -604,7 +604,7 @@ def item_json(item, upvoted_by_user = false)
604604

605605
it "should allow creating a new item" do
606606
json = api_call(:post, @c1_items_path, @c1_items_path_options.merge(:action => "create"), { :link_url => "http://www.example.com/a/b/c", :user_comment => 'new item' })
607-
new_item = @c1.collection_items.last(:order => :id)
607+
new_item = @c1.collection_items.order(:id).last
608608
new_item.collection_item_data.link_url.should == "http://www.example.com/a/b/c"
609609
new_item.user.should == @user
610610
end

spec/apis/v1/conversations_api_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def verify_filter(filter)
395395
p.delete("avatar_url")
396396
}
397397
}
398-
conversation = @me.all_conversations.scoped(:order => "conversation_id DESC").first
398+
conversation = @me.all_conversations.order("conversation_id DESC").first
399399
json.should eql [
400400
{
401401
"id" => conversation.conversation_id,
@@ -436,7 +436,7 @@ def verify_filter(filter)
436436
p.delete("avatar_url")
437437
}
438438
}
439-
conversation = @me.all_conversations.scoped(:order => "conversation_id DESC").first
439+
conversation = @me.all_conversations.order("conversation_id DESC").first
440440
json.should eql [
441441
{
442442
"id" => conversation.conversation_id,
@@ -568,7 +568,7 @@ def verify_filter(filter)
568568
p.delete("avatar_url")
569569
}
570570
}
571-
conversation = @me.all_conversations.scoped(:order => "last_message_at DESC, conversation_id DESC").first
571+
conversation = @me.all_conversations.order("last_message_at DESC, conversation_id DESC").first
572572
json.should eql [
573573
{
574574
"id" => conversation.conversation_id,

spec/apis/v1/courses_api_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,7 @@ def run_copy(to_id=nil, from_id=nil, options={})
15931593
{ :controller => 'content_imports', :action => 'copy_course_content', :course_id => to_id, :format => 'json' },
15941594
{:source_course => from_id}.merge(options))
15951595

1596-
cm = ContentMigration.last(:order => :id)
1596+
cm = ContentMigration.order(:id).last
15971597
data.should == {
15981598
'id' => cm.id,
15991599
'progress' => nil,

spec/apis/v1/discussion_topics_api_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def blank_fallback
104104
api_call(:post, "/api/v1/courses/#{@course.id}/discussion_topics",
105105
{ :controller => "discussion_topics", :action => "create", :format => "json", :course_id => @course.to_param },
106106
{ :title => "test title", :message => "test <b>message</b>" })
107-
@topic = @course.discussion_topics.last(:order => :id)
107+
@topic = @course.discussion_topics.order(:id).last
108108
@topic.title.should == "test title"
109109
@topic.message.should == "test <b>message</b>"
110110
@topic.threaded?.should be_false
@@ -118,7 +118,7 @@ def blank_fallback
118118
api_call(:post, "/api/v1/courses/#{@course.id}/discussion_topics",
119119
{ :controller => "discussion_topics", :action => "create", :format => "json", :course_id => @course.to_param },
120120
{ :title => "test title", :message => "test <b>message</b>", :is_announcement => true })
121-
@topic = @course.announcements.last(:order => :id)
121+
@topic = @course.announcements.order(:id).last
122122
@topic.title.should == "test title"
123123
@topic.message.should == "test <b>message</b>"
124124
end
@@ -128,7 +128,7 @@ def blank_fallback
128128
api_call(:post, "/api/v1/courses/#{@course.id}/discussion_topics",
129129
{ :controller => &q 4E3B uot;discussion_topics", :action => "create", :format => "json", :course_id => @course.to_param },
130130
{ :title => "test title", :message => "test <b>message</b>", :discussion_type => "threaded", :delayed_post_at => post_at.as_json, :podcast_has_student_posts => '1', :require_initial_post => '1' })
131-
@topic = @course.discussion_topics.last(:order => :id)
131+
@topic = @course.discussion_topics.order(:id).last
132132
@topic.title.should == "test title"
133133
@topic.message.should == "test <b>message</b>"
134134
@topic.threaded?.should == true
@@ -144,7 +144,7 @@ def blank_fallback
144144
api_call(:post, "/api/v1/courses/#{@course.id}/discussion_topics",
145145
{ :controller => "discussion_topics", :action => "create", :format => "json", :course_id => @course.to_param },
146146
{ :title => "test title", :message => "test <b>message</b>", :assignment => { :points_possible => 15, :grading_type => "percent", :due_at => due_date.as_json, :name => "override!" } })
147-
@topic = @course.discussion_topics.last(:order => :id)
147+
@topic = @course.discussion_topics.order(:id).last
148148
@topic.title.should == "test title"
149149
@topic.assignment.should be_present
150150
@topic.assignment.points_possible.should == 15
@@ -158,7 +158,7 @@ def blank_fallback
158158
api_call(:post, "/api/v1/courses/#{@course.id}/discussion_topics",
159159
{ :controller => "discussion_topics", :action => "create", :format => "json", :course_id => @course.to_param },
160160
{ :title => "test title", :message => "test <b>message</b>", :assignment => { :set_assignment => 'false' } })
161-
@topic = @course.discussion_topics.last(:order => :id)
161+
@topic = @course.discussion_topics.order(:id).last
162162
@topic.title.should == "test title"
163163
@topic.assignment.should be_nil
164164
end
@@ -1231,7 +1231,7 @@ def call_mark_entry_unread(course, topic, entry)
12311231
{ :controller => "discussion_topics_api", :action => "add_reply", :format => "json", :course_id => @course.id.to_s, :topic_id => @topic.id.to_s, :entry_id => @sub2.id.to_s },
12321232
{ :message => "ohai" })
12331233
json['parent_id'].should == @sub2.id
1234-
@sub4 = DiscussionEntry.last(:order => :id)
1234+
@sub4 = DiscussionEntry.order(:id).last
12351235
@sub4.id.should == json['id']
12361236

12371237
json = api_call(:get, "/api/v1/courses/#{@course.id}/discussion_topics/#{@topic.id}/entries/#{@entry.id}/replies",
@@ -1507,7 +1507,7 @@ def call_mark_entry_unread(course, topic, entry)
15071507
end
15081508

15091509
it "should mark entries as read on a collection item" do
1510-
Collection.update_all({ :visibility => 'public' }, { :id => @collection.id })
1510+
Collection.where(:id => @collection).update_all(:visibility => 'public')
15111511
@collection.reload
15121512
topic = @item.discussion_topic
15131513
topic.save!

0 commit comments

Comments
 (0)