Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Returns all Choice or Questions' versions if requested #25

Merged
merged 1 commit into from

2 participants

Vitor Baptista Luke Baker
Vitor Baptista

Hi,

I've added the param version, that can be sent when hitting ChoicesController#show or QuestionsController#show. If it's equal to "all", we include the "versions" association in the response.

There's no way to ask for a specific version, or to revert, but that shouldn't be hard to implement.

What do you think?

Cheers!
Vítor.

Luke Baker
Owner

Vitor, do you anticipate needing to request a specific version or to revert? If so, I think I'd prefer to wait until we have those pieces in this pull request so that we are sure the API parameters / calls are cohesive.

Vitor Baptista
Luke Baker
Owner

Gotcha, if you don't need it. We can merge this as-is.

Luke Baker lukebaker merged commit f408721 into from
Vitor Baptista

Great, Luke! I've just closed the issue #24 and added the new parameter to the API docs. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
8 app/controllers/choices_controller.rb
View
@@ -96,7 +96,13 @@ def update
def show
@question = current_user.questions.find(params[:question_id])
@choice = @question.choices.find(params[:id])
- show!
+ response_options = {}
+ response_options[:include] = :versions if params[:version] == 'all'
+
+ respond_to do |format|
+ format.xml { render :xml => @choice.to_xml(response_options) }
+ format.json { render :json => @choice.to_json(response_options) }
+ end
end
6 app/controllers/questions_controller.rb
View
@@ -23,13 +23,15 @@ def show
@question_optional_information.each do |key, value|
optional_information << Proc.new { |options| options[:builder].tag!(key, value)}
end
+ response_options = { :methods => [:item_count], :procs => optional_information }
+ response_options[:include] = :versions if params[:version] == "all"
respond_to do |format|
format.xml {
- render :xml => @question.to_xml(:methods => [:item_count], :procs => optional_information)
+ render :xml => @question.to_xml(response_options)
}
format.js{
- render :json => @question.to_json(:methods => [:item_count], :procs => optional_information)
+ render :json => @question.to_json(response_options)
}
end
end
21 spec/controllers/choices_controller_spec.rb
View
@@ -125,4 +125,25 @@ def mock_vote(stubs={})
end
end
+ describe "GET show" do
+ it "doesn't returns all versions by default" do
+ question = Factory(:question, :site => @user)
+ choice = Factory(:choice, :question => question)
+
+ get :show, :question_id => question.id, :id => choice.id, :format => "xml"
+
+ response.code.should == "200"
+ response.body.should_not have_tag("versions")
+ end
+
+ it "responds with all versions if requested" do
+ question = Factory(:question, :site => @user)
+ choice = Factory(:choice, :question => question)
+
+ get :show, :question_id => question.id, :id => choice.id, :format => "xml", :version => "all"
+
+ response.code.should == "200"
+ response.body.should have_tag("versions")
+ end
+ end
end
9 spec/controllers/questions_controller_spec.rb
View
@@ -17,6 +17,7 @@ def sign_in_as(user)
assigns[:question].should == @question
@response.body.should have_tag("question")
@response.code.should == "200"
+ @response.body.should_not have_tag("versions")
end
@@ -32,4 +33,12 @@ def sign_in_as(user)
@response.body.should have_tag("visitor_votes")
@response.body.should have_tag("visitor_ideas")
end
+
+ it "responds with all versions if requested" do
+ get :show, :id => @question.id, :format => "xml", :version => "all"
+
+ assigns[:question].should == @question
+ @response.code.should == "200"
+ @response.body.should have_tag("versions")
+ end
end
Something went wrong with that request. Please try again.