mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-31 21:37:16 +00:00
Fix entreprise missing issue on Persons controller
This commit is contained in:
@@ -32,10 +32,13 @@ module DfcProvider
|
||||
|
||||
def current_enterprise
|
||||
@current_enterprise ||=
|
||||
if params[enterprise_id_param_name] == 'default'
|
||||
current_user.enterprises.first!
|
||||
case params[enterprise_id_param_name]
|
||||
when 'default'
|
||||
return current_user.enterprises.first!
|
||||
when nil
|
||||
return nil
|
||||
else
|
||||
current_user.enterprises.find(params[enterprise_id_param_name])
|
||||
return current_user.enterprises.find(params[enterprise_id_param_name])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ describe DfcProvider::Api::CatalogItemsController, type: :controller do
|
||||
before { api_get :index, enterprise_id: 'default' }
|
||||
|
||||
it 'is successful' do
|
||||
expect(response.status).to eq 200
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it 'renders the required content' do
|
||||
@@ -47,7 +47,7 @@ describe DfcProvider::Api::CatalogItemsController, type: :controller do
|
||||
|
||||
it 'returns not_found head' do
|
||||
api_get :index, enterprise_id: enterprise.id
|
||||
expect(response.status).to eq 404
|
||||
expect(response).to be_not_found
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -75,7 +75,7 @@ describe DfcProvider::Api::CatalogItemsController, type: :controller do
|
||||
|
||||
it 'is not found' do
|
||||
api_get :index, enterprise_id: 'default'
|
||||
expect(response.status).to eq 404
|
||||
expect(response).to be_not_found
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -87,7 +87,7 @@ describe DfcProvider::Api::CatalogItemsController, type: :controller do
|
||||
.and_return(nil)
|
||||
|
||||
api_get :index, enterprise_id: 'default'
|
||||
expect(response.status).to eq 401
|
||||
expect(response.response_code).to eq(401)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -95,7 +95,7 @@ describe DfcProvider::Api::CatalogItemsController, type: :controller do
|
||||
context 'without an authorization token' do
|
||||
it 'returns unprocessable_entity head' do
|
||||
api_get :index, enterprise_id: enterprise.id
|
||||
expect(response.status).to eq 422
|
||||
expect(response).to be_unprocessable
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -120,7 +120,7 @@ describe DfcProvider::Api::CatalogItemsController, type: :controller do
|
||||
end
|
||||
|
||||
it 'is successful' do
|
||||
expect(response.status).to eq 200
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it 'renders the required content' do
|
||||
@@ -137,7 +137,7 @@ describe DfcProvider::Api::CatalogItemsController, type: :controller do
|
||||
end
|
||||
|
||||
it 'is not found' do
|
||||
expect(response.status).to eq 404
|
||||
expect(response).to be_not_found
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,7 +27,7 @@ describe DfcProvider::Api::EnterprisesController, type: :controller do
|
||||
before { api_get :show, id: 'default' }
|
||||
|
||||
it 'is successful' do
|
||||
expect(response.status).to eq 200
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it 'renders the required content' do
|
||||
@@ -44,7 +44,7 @@ describe DfcProvider::Api::EnterprisesController, type: :controller do
|
||||
before { api_get :show, id: 999 }
|
||||
|
||||
it 'is not found' do
|
||||
expect(response.status).to eq 404
|
||||
expect(response).to be_not_found
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,7 +24,7 @@ describe DfcProvider::Api::PersonsController, type: :controller do
|
||||
before { api_get :show, id: user.id }
|
||||
|
||||
it 'is successful' do
|
||||
expect(response.status).to eq 200
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it 'renders the required content' do
|
||||
@@ -36,7 +36,7 @@ describe DfcProvider::Api::PersonsController, type: :controller do
|
||||
before { api_get :show, id: create(:user).id }
|
||||
|
||||
it 'is not found' do
|
||||
expect(response.status).to eq 404
|
||||
expect(response).to be_not_found
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -30,7 +30,7 @@ describe DfcProvider::Api::SuppliedProductsController, type: :controller do
|
||||
end
|
||||
|
||||
it 'is successful' do
|
||||
expect(response.status).to eq 200
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it 'renders the required content' do
|
||||
@@ -39,10 +39,10 @@ describe DfcProvider::Api::SuppliedProductsController, type: :controller do
|
||||
end
|
||||
|
||||
context 'given with a wrong id' do
|
||||
before { api_get :show, id: 999 }
|
||||
before { api_get :show, enterprise_id: 'default', id: 999 }
|
||||
|
||||
it 'is not found' do
|
||||
expect(response.status).to eq 404
|
||||
expect(response).to be_not_found
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user