mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Registration controller checks number of owned enterpises
This commit is contained in:
@@ -20,6 +20,8 @@ class RegistrationController < BaseController
|
||||
def check_user
|
||||
if spree_current_user.nil?
|
||||
redirect_to registration_auth_path(anchor: "signup?after_login=#{request.env['PATH_INFO']}")
|
||||
elsif !spree_current_user.can_own_more_enterprises?
|
||||
render :limit_reached
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe RegistrationController do
|
||||
include AuthenticationWorkflow
|
||||
describe "redirecting when user not logged in" do
|
||||
it "index" do
|
||||
get :index
|
||||
@@ -13,26 +14,38 @@ describe RegistrationController do
|
||||
end
|
||||
end
|
||||
|
||||
describe "loading data when user is logged in" do
|
||||
let!(:user) { double(:user) }
|
||||
describe "redirecting when user has reached enterprise ownership limit" do
|
||||
let!(:user) { create_enterprise_user( enterprise_limit: 1 ) }
|
||||
let!(:enterprise) { create(:distributor_enterprise, owner: user) }
|
||||
|
||||
before do
|
||||
controller.stub spree_current_user: user
|
||||
end
|
||||
|
||||
it "index" do
|
||||
get :index
|
||||
response.should render_template :limit_reached
|
||||
end
|
||||
end
|
||||
|
||||
describe "loading data when user is logged in" do
|
||||
let!(:user) { create_enterprise_user }
|
||||
|
||||
before do
|
||||
controller.stub spree_current_user: user
|
||||
user.stub spree_api_key: '12345'
|
||||
user.stub last_incomplete_spree_order: nil
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
it "loads the spree api key" do
|
||||
get :index
|
||||
expect(assigns(:spree_api_key)).to eq '12345'
|
||||
expect(assigns(:spree_api_key)).to eq user.spree_api_key
|
||||
end
|
||||
end
|
||||
|
||||
describe "store" do
|
||||
it "loads the spree api key" do
|
||||
get :store
|
||||
expect(assigns(:spree_api_key)).to eq '12345'
|
||||
expect(assigns(:spree_api_key)).to eq user.spree_api_key
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user