Skip to content

Commit

Permalink
Merge pull request #85 from openstax/🍕
Browse files Browse the repository at this point in the history
sort answers by id
  • Loading branch information
jpslav committed Dec 1, 2015
2 parents c6ac40e + 46082ed commit daaf5d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/representers/api/v1/question_representer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class QuestionRepresenter < Roar::Decorator
decorator: AnswerRepresenter,
writeable: true,
readable: true,
getter: ->(*) {
answers.sort_by{ |answer| answer.id }
},
schema_info: {
required: true
}
Expand Down
5 changes: 4 additions & 1 deletion spec/representers/api/v1/question_representer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,20 @@ module Api::V1
context 'answers' do
it 'can be read' do
answer_1 = instance_spy(Answer)
allow(answer_1).to receive(:id).and_return(2)
allow(answer_1).to receive(:as_json).and_return(answer_1)
allow(answer_1).to receive(:question).and_return(question)
allow(answer_1).to receive(:content).and_return('Yes')
answer_2 = instance_spy(Answer)
allow(answer_2).to receive(:id).and_return(1)
allow(answer_2).to receive(:as_json).and_return(answer_2)
allow(answer_2).to receive(:question).and_return(question)
allow(answer_2).to receive(:content).and_return('No')
answers = [answer_1, answer_2]
answer_representations = answers.collect{ |answer| AnswerRepresenter.new(answer).to_hash }
reverse_answer_representations = answer_representations.reverse()
allow(question).to receive(:answers).and_return(answers)
expect(representation).to include('answers' => answer_representations)
expect(representation).to include('answers' => reverse_answer_representations)
end

xit 'can be written' do
Expand Down

0 comments on commit daaf5d2

Please sign in to comment.