<commit_before>describe CatalogController do
  let(:user) { FactoryGirl.create(:user_with_group) }
  before(:each) do
    set_user_privileges user
  end

  # some methods should not be accessible through the legacy routes
  # either by being private or through the hide_action mechanism
  it 'should not allow call of hidden/private actions' do
    expect do
      post :process_sts<commit_msg>Spec for Service Template and cases with not self-service user (transferred from ManageIQ/manageiq@58284d2ca5c21f07715ae4fd70040ada05b6594d)<commit_after>describe CatalogController do
  let(:user)                { FactoryGirl.create(:user_with_group) }
  let(:admin_user)          { FactoryGirl.create(:user, :role => "super_administrator") }
  let(:root_tenant)         { user.current_tenant }
  let(:tenant_role)         { FactoryGirl.create(:miq_user_role) }
  let(:child_tenant)        { FactoryGirl.create(:tenant, :parent => root_tenant) }
  let(:child_tenant_group)  { FactoryGirl.create(:miq_group, :tenant => child_tenant, :miq_user_role => tenant_role) }
  let(:child_tenant_user)   { FactoryGirl.create(:user, :miq_groups => [child_tenant_group]) }

  let!(:service_template_with_root_tenant) { FactoryGirl.create(:service_template, :tenant => root_tenant) }
  let!(:service_template_with_child_tenant) do
    FactoryGirl.create(:service_template, :miq_group => child_tenant_group, :tenant => child_tenant)
  end

  before(:each) do
    set_user_privileges user
    controller.instance_variable_set(:@settings, {})
    allow_any_instance_of(ApplicationController).to receive(:fetch_path)
  end

  it "returns all catalog items related to current tenant and root tenant when non-self service user is logged" do
    login_as child_tenant_user
    view, _pages = controller.send(:get_view, ServiceTemplate, {})
    expect(view.table.data.count).to eq(2)
  end

  it "returns all catalog items related to current user's groups when self service user is logged" do
    allow_any_instance_of(MiqGroup).to receive_messages(:self_service? => true)
    login_as child_tenant_user
    view, _pages = controller.send(:get_view, ServiceTemplate, {})
    expect(view.table.data.count).to eq(1)
  end

  it "returns all catalog items when admin user is logged" do
    login_as admin_user
    view, _pages = controller.send(:get_view, ServiceTemplate, {})
    expect(view.table.data.count).to eq(2)
  end

  # some methods should not be accessible through the legacy routes
  # either by being private or through the hide_action mechanism
  it 'should not allow call of hidden/private actions' do
    expect do
      post :process_sts
{'fraction_non_alphanumeric': 0.09032012195121951, 'fraction_numerical': 0.011051829268292682, 'mean_word_length': 4.573248407643312, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '1204626', 'n_tokens_mistral': 807, 'n_tokens_neox': 792, 'n_words': 209}