Registration controller checks number of owned enterpises

This commit is contained in:
Rob Harrington
2014-09-25 12:10:45 +10:00
parent 9520eeeb15
commit 6fa7d9cbcb
2 changed files with 21 additions and 6 deletions

View File

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

View File

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