<commit_before>require "spec_helper"

feature %q{
    As a Super User
    I want to setup users to manage an enterprise
} do
  include AuthenticationWorkflow
  include WebHelper
  include AdminHelper

  let!(:user) { create_enterprise_user }
  let!(:supplier1) { create(:supplier_enterprise, name: 'Supplier 1') }
  let!(:supplier2) { create(:supplier_enterprise, name: 'Supplier 2') }
  let(:supplier_profile) { create(:supplier_enterprise, name: 'Supplier profile', sells: 'none') }
  let!(:distributor1) { create(:distributor_enterprise, name: 'Distributor 3') }
  let!(:distributor2) { create(:distributor_enterprise, name: 'Distributor 4') }
  let(:distributor_profile) { create(:distributor_enterprise, name: 'Distributor profile', sells: 'none') }

  describe "creating an enterprise user" do
    context "with a limitted number of owned enterprises" do
      scenario "setting the enterprise ownership limit" do
        expect(user.enterprise_limit).to eq 5
        login_to_admin_section
        click_link 'Users'
        click_link user.email

        fill_in "user_enterprise_limit", with: 2

        click_button 'Update'
        user.reload
        expect(user.enterprise_limit).to eq 2
      end
    end
  end

  describe "system management lockdown" do
    before do
      user.enterprise_roles.create!(enterprise: supplier1)
      login_to_admin_as user
    end

    scenario "should not be able to see system configuration" do
      visit spree.edit_admin_general_settings_path
      page.should have_content 'Unauthorized'
    end

    scenario "should not be able to see user management" do
      visit spree.admin_users_path<commit_msg>Speed up enterprise user spec<commit_after>require "spec_helper"

feature %q{
    As a Super User
    I want to setup users to manage an enterprise
} do
  include AuthenticationWorkflow
  include WebHelper
  include AdminHelper

  let!(:user) { create_enterprise_user }
  let!(:supplier1) { create(:supplier_enterprise, name: 'Supplier 1') }
  let!(:supplier2) { create(:supplier_enterprise, name: 'Supplier 2') }
  let(:supplier_profile) { create(:supplier_enterprise, name: 'Supplier profile', sells: 'none') }
  let!(:distributor1) { create(:distributor_enterprise, name: 'Distributor 3') }
  let!(:distributor2) { create(:distributor_enterprise, name: 'Distributor 4') }
  let(:distributor_profile) { create(:distributor_enterprise, name: 'Distributor profile', sells: 'none') }

  describe "creating an enterprise user" do
    context "with a limitted number of owned enterprises" do
      scenario "setting the enterprise ownership limit" do
        expect(user.enterprise_limit).to eq 5
        login_to_admin_section
        click_link 'Users'
        click_link user.email

        fill_in "user_enterprise_limit", with: 2

        click_button 'Update'
        user.reload
        expect(user.enterprise_limit).to eq 2
      end
    end
  end

  describe "system management lockdown" do
    before do
      user.enterprise_roles.create!(enterprise: supplier1)
      quick_login_as user
    end

    scenario "should not be able to see system configuration" do
      visit spree.edit_admin_general_settings_path
      page.should have_content 'Unauthorized'
    end

    scenario "should not be able to see user management" do
      visit spree.admin_users_path
{'fraction_non_alphanumeric': 0.08355876164712954, 'fraction_numerical': 0.007213706041478809, 'mean_word_length': 3.8023088023088025, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5206483', 'n_tokens_mistral': 1013, 'n_tokens_neox': 966, 'n_words': 289}