Permalink
Browse files

Don't allow api users to specify template.

  • Loading branch information...
JDutil committed Jul 20, 2015
1 parent d38f6fd commit ec813a8733cc6c332f4e361152e3e757dd5dbbf0
@@ -13,7 +13,7 @@ def to_format
end
def template
request.headers['X-Spree-Template'] || controller.params[:template] || options[:default_template]
options[:default_template]
end
def api_behavior
@@ -67,45 +67,6 @@ module Spree
expect(json_response["per_page"]).to eq(Kaminari.config.default_per_page)
end
context "specifying a rabl template for a custom action" do
before do
described_class.class_eval do
def custom_show
@product = find_product(params[:id])
respond_with(@product)
end
end
end
def set_custom_route
@routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
r.draw { get 'custom_show' => 'spree/api/v1/products#custom_show' }
end
end
it "uses the specified custom template through the request header" do
set_custom_route
request.headers['X-Spree-Template'] = 'show'
api_get :custom_show, :id => product.id
expect(response).to render_template('spree/api/v1/products/show')
end
it "uses the specified custom template through the template URL parameter" do
set_custom_route
api_get :custom_show, :id => product.id, :template => 'show'
expect(response).to render_template('spree/api/v1/products/show')
end
it "falls back to the default template if the specified template does not exist" do
request.headers['X-Spree-Template'] = 'invoice'
api_get :show, :id => product.id
expect(response).to render_template('spree/api/v1/products/show')
end
end
context "product has more than one price" do
before { product.master.prices.create currency: "EUR", amount: 22 }
@@ -38,32 +38,6 @@ module Spree
expect(json_response['zone_members'].size).to eq @zone.zone_members.count
end
context "specifying a rabl template to use" do
before do
described_class.class_eval do
def custom_show
respond_with(zone)
end
end
end
it "uses the specified template" do
@routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
r.draw { get 'custom_show' => 'spree/api/v1/zones#custom_show' }
end
request.headers['X-Spree-Template'] = 'show'
api_get :custom_show, :id => @zone.id
expect(response).to render_template('spree/api/v1/zones/show')
end
it "falls back to the default template if the specified template does not exist" do
request.headers['X-Spree-Template'] = 'invoice'
api_get :show, :id => @zone.id
expect(response).to render_template('spree/api/v1/zones/show')
end
end
context "as an admin" do
sign_in_as_admin!

0 comments on commit ec813a8

Please sign in to comment.