mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Merge pull request #4057 from luisramos0/remove_spree_api_2
Remove dependency to spree_api - step 2 - routes and views
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::Api::BaseController do
|
||||
describe Api::BaseController do
|
||||
render_views
|
||||
controller(Spree::Api::BaseController) do
|
||||
controller(Api::BaseController) do
|
||||
skip_authorization_check only: :index
|
||||
|
||||
def index
|
||||
render text: { "products" => [] }.to_json
|
||||
end
|
||||
@@ -23,13 +25,15 @@ describe Spree::Api::BaseController do
|
||||
end
|
||||
end
|
||||
|
||||
context "cannot make a request to the API" do
|
||||
context "can make an anonymous request to the API" do
|
||||
it "without an API key" do
|
||||
api_get :index
|
||||
expect(json_response).to eq( "error" => "You must specify an API key." )
|
||||
expect(response.status).to eq(401)
|
||||
expect(json_response["products"]).to eq []
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
end
|
||||
|
||||
context "cannot make a request to the API" do
|
||||
it "with an invalid API key" do
|
||||
request.env["X-Spree-Token"] = "fake_key"
|
||||
get :index, {}
|
||||
@@ -46,19 +50,15 @@ describe Spree::Api::BaseController do
|
||||
it 'handles exceptions' do
|
||||
expect(subject).to receive(:authenticate_user).and_return(true)
|
||||
expect(subject).to receive(:index).and_raise(Exception.new("no joy"))
|
||||
get :index, token: "fake_key"
|
||||
get :index
|
||||
expect(json_response).to eq( "exception" => "no joy" )
|
||||
end
|
||||
|
||||
it "maps symantec keys to nested_attributes keys" do
|
||||
klass = double(nested_attributes_options: { line_items: {},
|
||||
bill_address: {} })
|
||||
attributes = { 'line_items' => { id: 1 },
|
||||
'bill_address' => { id: 2 },
|
||||
'name' => 'test order' }
|
||||
|
||||
mapped = subject.map_nested_attributes_keys(klass, attributes)
|
||||
expect(mapped.key?('line_items_attributes')).to be_truthy
|
||||
expect(mapped.key?('name')).to be_truthy
|
||||
it 'handles record not found' do
|
||||
expect(subject).to receive(:authenticate_user).and_return(true)
|
||||
expect(subject).to receive(:index).and_raise(ActiveRecord::RecordNotFound.new)
|
||||
get :index
|
||||
expect(json_response).to eq( "error" => "The resource you were looking for could not be found." )
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
end
|
||||
@@ -49,12 +49,14 @@ describe UserRegistrationsController, type: :controller do
|
||||
end
|
||||
|
||||
it "sets user.locale from cookie on create" do
|
||||
original_i18n_locale = I18n.locale
|
||||
original_locale_cookie = cookies[:locale]
|
||||
|
||||
cookies[:locale] = "pt"
|
||||
|
||||
xhr :post, :create, spree_user: user_params, use_route: :spree
|
||||
|
||||
expect(assigns[:user].locale).to eq("pt")
|
||||
|
||||
I18n.locale = original_i18n_locale
|
||||
cookies[:locale] = original_locale_cookie
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user