diff --git a/app/controllers/registration_controller.rb b/app/controllers/registration_controller.rb index 47a1537b57..4fae68bb79 100644 --- a/app/controllers/registration_controller.rb +++ b/app/controllers/registration_controller.rb @@ -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 diff --git a/spec/controllers/registration_controller_spec.rb b/spec/controllers/registration_controller_spec.rb index 13babdf89e..e51a28f73a 100644 --- a/spec/controllers/registration_controller_spec.rb +++ b/spec/controllers/registration_controller_spec.rb @@ -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