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:
Luis Ramos
2019-11-06 13:23:32 +00:00
committed by GitHub
25 changed files with 178 additions and 238 deletions

View File

@@ -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

View File

@@ -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