replace to_json overrides with as_json overrides
refs CNVS-7597 given Object#to_json's default implementation, the old to_json overrides follow from the new as_json overrides. and now we can also call as_json and get the expected non-serialized data. test-plan: N/A Change-Id: Ia57562e0c73752a13023cad4ef6bae9435790bee Reviewed-on: https://gerrit.instructure.com/23647 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Cody Cutrer <cody@instructure.com> Product-Review: Jacob Fugal <jacob@instructure.com> QA-Review: Jacob Fugal <jacob@instructure.com>
This commit is contained in:
parent
34f5a5c1f1
commit
f2a8d4fe6d
|
@ -52,7 +52,7 @@ module Canvas::Oauth
|
|||
@access_token
|
||||
end
|
||||
|
||||
def to_json
|
||||
def as_json(options={})
|
||||
{
|
||||
'access_token' => access_token.full_token,
|
||||
'user' => user.as_json(:only => [:id, :name], :include_root => false),
|
||||
|
|
|
@ -184,7 +184,7 @@ class GradebookImporter
|
|||
student.write_attribute(:submissions, l)
|
||||
end
|
||||
|
||||
def to_json
|
||||
def as_json(options={})
|
||||
{
|
||||
:students => @students.map { |s| student_to_hash(s) },
|
||||
:assignments => @assignments.map { |a| assignment_to_hash(a) },
|
||||
|
@ -194,7 +194,7 @@ class GradebookImporter
|
|||
},
|
||||
:original_submissions => @original_submissions,
|
||||
:unchanged_assignments => @unchanged_assignments
|
||||
}.to_json
|
||||
}
|
||||
end
|
||||
|
||||
protected
|
||||
|
|
|
@ -59,12 +59,12 @@ class UserList
|
|||
|
||||
attr_reader :errors, :addresses, :duplicate_addresses
|
||||
|
||||
def to_json(*options)
|
||||
def as_json(*options)
|
||||
{
|
||||
:users => addresses.map { |a| a.reject { |k, v| k == :shard } },
|
||||
:duplicates => duplicate_addresses,
|
||||
:errored_users => errors
|
||||
}.to_json
|
||||
}
|
||||
end
|
||||
|
||||
def users
|
||||
|
|
|
@ -122,8 +122,8 @@ module Canvas::Oauth
|
|||
end
|
||||
end
|
||||
|
||||
describe '#to_json' do
|
||||
let(:json) { token.to_json }
|
||||
describe '#as_json' do
|
||||
let(:json) { token.as_json }
|
||||
|
||||
it 'includes the access token' do
|
||||
json['access_token'].should be_a String
|
||||
|
|
|
@ -108,27 +108,27 @@ describe GradebookImporter do
|
|||
end
|
||||
|
||||
importer_with_rows(uploaded_csv)
|
||||
hash = ActiveSupport::JSON.decode(@gi.to_json)
|
||||
hash = @gi.as_json
|
||||
|
||||
hash['students'][0]['id'].should == @u1.id
|
||||
hash['students'][0]['original_id'].should == @u1.id
|
||||
hash['students'][0]['name'].should eql(@u1.name)
|
||||
hash[:students][0][:id].should == @u1.id
|
||||
hash[:students][0][:original_id].should == @u1.id
|
||||
hash[:students][0][:name].should eql(@u1.name)
|
||||
|
||||
hash['students'][1]['id'].should == @u2.id
|
||||
hash['students'][1]['original_id'].should == @u2.id
|
||||
hash[:students][1][:id].should == @u2.id
|
||||
hash[:students][1][:original_id].should == @u2.id
|
||||
|
||||
hash['students'][2]['id'].should == @u3.id
|
||||
hash['students'][2]['original_id'].should == @u3.id
|
||||
hash[:students][2][:id].should == @u3.id
|
||||
hash[:students][2][:original_id].should == @u3.id
|
||||
|
||||
# Looking up by login, but there are no active pseudonyms for u4
|
||||
hash['students'][3]['id'].should < 0
|
||||
hash['students'][3]['original_id'].should be_nil
|
||||
hash[:students][3][:id].should < 0
|
||||
hash[:students][3][:original_id].should be_nil
|
||||
|
||||
hash['students'][4]['id'].should == @u5.id
|
||||
hash['students'][4]['original_id'].should == @u5.id
|
||||
hash[:students][4][:id].should == @u5.id
|
||||
hash[:students][4][:original_id].should == @u5.id
|
||||
|
||||
hash['students'][5]['id'].should < 0
|
||||
hash['students'][5]['original_id'].should be_nil
|
||||
hash[:students][5][:id].should < 0
|
||||
hash[:students][5][:original_id].should be_nil
|
||||
end
|
||||
|
||||
it "should allow ids that look like numbers" do
|
||||
|
@ -155,13 +155,13 @@ describe GradebookImporter do
|
|||
end
|
||||
|
||||
importer_with_rows(uploaded_csv)
|
||||
hash = ActiveSupport::JSON.decode(@gi.to_json)
|
||||
hash = @gi.as_json
|
||||
|
||||
hash['students'][0]['id'].should == @u0.id
|
||||
hash['students'][0]['original_id'].should == @u0.id
|
||||
hash[:students][0][:id].should == @u0.id
|
||||
hash[:students][0][:original_id].should == @u0.id
|
||||
|
||||
hash['students'][1]['id'].should == @u1.id
|
||||
hash['students'][1]['original_id'].should == @u1.id
|
||||
hash[:students][1][:id].should == @u1.id
|
||||
hash[:students][1][:original_id].should == @u1.id
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -264,20 +264,20 @@ describe GradebookImporter do
|
|||
end
|
||||
|
||||
it "should have a simplified json output" do
|
||||
hash = ActiveSupport::JSON.decode(@gi.to_json)
|
||||
hash.keys.sort.should eql(["assignments", "missing_objects", "original_submissions", "students", "unchanged_assignments"])
|
||||
students = hash["students"]
|
||||
hash = @gi.as_json
|
||||
hash.keys.sort.should eql([:assignments, :missing_objects, :original_submissions, :students, :unchanged_assignments])
|
||||
students = hash[:students]
|
||||
students.should be_is_a(Array)
|
||||
student = students.first
|
||||
student.keys.sort.should eql(["id", "last_name_first", "name", "original_id", "submissions"])
|
||||
submissions = student["submissions"]
|
||||
student.keys.sort.should eql([:id, :last_name_first, :name, :original_id, :submissions])
|
||||
submissions = student[:submissions]
|
||||
submissions.should be_is_a(Array)
|
||||
submission = submissions.first
|
||||
submission.keys.sort.should eql(["assignment_id", "grade", "original_grade"])
|
||||
assignments = hash["assignments"]
|
||||
assignments = hash[:assignments]
|
||||
assignments.should be_is_a(Array)
|
||||
assignment = assignments.first
|
||||
assignment.keys.sort.should eql(["grading_type", "id", "original_id", "points_possible", "title"])
|
||||
assignment.keys.sort.should eql([:grading_type, :id, :original_id, :points_possible, :title])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue