Skip to content

Commit

Permalink
added support for /posts routes on Answer
Browse files Browse the repository at this point in the history
this adds calls for suggested edits and revisions for answers
  • Loading branch information
thomas-mcdonald committed Feb 20, 2012
1 parent 9338794 commit f53af23
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 26 deletions.
8 changes: 8 additions & 0 deletions lib/serel/answer.rb
Expand Up @@ -12,5 +12,13 @@ def comments
def question def question
type(:question, :singular).url("questions/#{question_id}").request type(:question, :singular).url("questions/#{question_id}").request
end end

def revisions
type(:revision).url("posts/#{id}/revisions")
end

def suggested_edits
type(:suggested_edit).url("posts/#{id}/suggested-edits")
end
end end
end end
111 changes: 111 additions & 0 deletions spec/cassettes/answer-revisions.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 92 additions & 0 deletions spec/cassettes/answer-suggested-edits.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 46 additions & 26 deletions spec/serel/answer_spec.rb
@@ -1,41 +1,61 @@
require 'spec_helper' require 'spec_helper'


describe Serel::Answer do describe Serel::Answer do
context 'the class' do it 'should support finding an answer and accessing its attributes' do
it 'should support finding an answer and accessing its attributes' do VCR.use_cassette('answer-find') do
VCR.use_cassette('answer-find') do # Pick a random awesome answer
# Pick a random awesome answer answer = Serel::Answer.find(16573)
answer = Serel::Answer.find(16573) answer.should be_a(Serel::Answer)
answer.should be_a(Serel::Answer)


answer.id.should == 16573 answer.id.should == 16573
answer.answer_id.should == 16573 answer.answer_id.should == 16573
answer.question_id.should == 16568 answer.question_id.should == 16568
answer.is_accepted.should == true answer.is_accepted.should == true
answer.score.should == 23 answer.score.should == 23


answer.owner.should be_a(Serel::User) answer.owner.should be_a(Serel::User)
end
end

it 'should get the question the answer is on' do
VCR.use_cassette('answer-question') do
answer = Serel::Answer.find(16573)
question = answer.question
question.should be_a(Serel::Question)
answer.question_id.should == question.id
end
end

it 'should get the comments on an answer' do
VCR.use_cassette('answer-comments') do
# Random awesome answer with comments
answer = Serel::Answer.find(29552)
comments = answer.comments.request
comments.should be_a(Array)
comments.each do |comment|
comment.should be_a(Serel::Comment)
end end
end end
end end


context 'an instance' do it 'should get the revisions on an answer' do
it 'should have a comments scope' do VCR.use_cassette('answer-revisions') do
VCR.use_cassette('answer-comments') do answer = Serel::Answer.find(14545)
# Random awesome answer with comments revisions = answer.revisions.request
answer = Serel::Answer.find(29552) revisions.should be_a(Array)
comments = answer.comments.request revisions.each do |rev|
comments.should be_a(Array) rev.should be_a(Serel::Revision)
comments.first.should be_a(Serel::Comment)
end end
end end
end


it 'should be able to get the question' do it 'should get the suggested edits on an answer' do
VCR.use_cassette('answer-question') do VCR.use_cassette('answer-suggested-edits') do
answer = Serel::Answer.find(16573) answer = Serel::Answer.find(14264)
question = answer.question edits = answer.suggested_edits.request
question.should be_a(Serel::Question) edits.should be_a(Array)
answer.question_id.should == question.id edits.each do |edit|
edit.should be_a(Serel::SuggestedEdit)
end end
end end
end end
Expand Down

0 comments on commit f53af23

Please sign in to comment.