Skip to content

Commit

Permalink
Add spec for the fix for creating group after validation message
Browse files Browse the repository at this point in the history
  • Loading branch information
Hilda Stastna committed Mar 20, 2019
1 parent e7b0336 commit bc5c29e
Showing 1 changed file with 41 additions and 25 deletions.
66 changes: 41 additions & 25 deletions spec/controllers/ops_controller/ops_rbac_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe OpsController do
render_views

context "::Tenants" do
describe "::Tenants" do
before do
Tenant.seed
MiqRegion.seed
Expand Down Expand Up @@ -34,7 +34,7 @@
end
let(:four_terabytes) { 4096 * 1024 * 1024 * 1024 }

context "#tree_select" do
describe "#tree_select" do
it "renders rbac_details tab when rbac_tree root node is selected" do
session[:sandboxes] = {"ops" => {:active_tree => :rbac_tree}}
post :tree_select, :params => { :id => 'root', :format => :js }
Expand Down Expand Up @@ -87,15 +87,15 @@
end
end

context "#rbac_tenant_get_details" do
describe "#rbac_tenant_get_details" do
it "sets @tenant record" do
t = FactoryBot.create(:tenant, :parent => Tenant.root_tenant, :subdomain => "foo")
controller.send(:rbac_tenant_get_details, t.id)
expect(assigns(:tenant)).to eq(t)
end
end

context "#rbac_tenant_delete" do
describe "#rbac_tenant_delete" do
before do
allow(ApplicationHelper).to receive(:role_allows?).and_return(true)
@t = FactoryBot.create(:tenant, :parent => Tenant.root_tenant)
Expand Down Expand Up @@ -151,7 +151,7 @@
end
end

context "#rbac_tenants_list" do
describe "#rbac_tenants_list" do
it "gets the list of tenants by calling get_view with correct args" do
controller.instance_variable_set(:@sb, {})
controller.instance_variable_set(:@settings, {})
Expand All @@ -173,13 +173,13 @@
end
end

context "#rbac_tenant_manage_quotas" do
describe "#rbac_tenant_manage_quotas" do
before do
@tenant = FactoryBot.create(:tenant,
:name => "OneTenant",
:parent => Tenant.root_tenant,
:domain => "test",
:subdomain => "test")
:name => "OneTenant",
:parent => Tenant.root_tenant,
:domain => "test",
:subdomain => "test")
sb_hash = {
:trees => {:rbac_tree => {:active_node => "tn-#{@tenant.id}"}},
:active_tree => :rbac_tree,
Expand All @@ -188,6 +188,7 @@
controller.instance_variable_set(:@sb, sb_hash)
allow(ApplicationHelper).to receive(:role_allows?).and_return(true)
end

it "resets tenant manage quotas" do
controller.instance_variable_set(:@_params, :id => @tenant.id, :button => "reset")
expect(controller).to receive(:render)
Expand Down Expand Up @@ -232,10 +233,10 @@
let!(:user) { stub_user(:features => :all) }
before do
@tenant = FactoryBot.create(:tenant,
:name => "OneTenant",
:parent => Tenant.root_tenant,
:domain => "test",
:subdomain => "test")
:name => "OneTenant",
:parent => Tenant.root_tenant,
:domain => "test",
:subdomain => "test")
sb_hash = { :trees => {:rbac_tree => {:active_node => "tn-#{@tenant.id}"}},
:active_tree => :rbac_tree,
:active_tab => "rbac_details"}
Expand All @@ -244,11 +245,11 @@
allow(@tenant).to receive(:tagged_with).with(:cat => user.userid).and_return("my tags")
classification = FactoryBot.create(:classification, :name => "department", :description => "Department")
@tag1 = FactoryBot.create(:classification_tag,
:name => "tag1",
:parent => classification)
:name => "tag1",
:parent => classification)
@tag2 = FactoryBot.create(:classification_tag,
:name => "tag2",
:parent => classification)
:name => "tag2",
:parent => classification)
allow(Classification).to receive(:find_assigned_entries).with(@tenant).and_return([@tag1, @tag2])
controller.instance_variable_set(:@sb,
:trees => {:rbac_tree => {:active_node => "root"}},
Expand All @@ -264,9 +265,7 @@
session[:edit] = edit
end

after(:each) do
expect(response.status).to eq(200)
end
after { expect(response.status).to eq(200) }

it "builds tagging screen" do
EvmSpecHelper.create_guid_miq_server_zone
Expand Down Expand Up @@ -301,7 +300,7 @@
end
end

context "::MiqGroup" do
describe "::MiqGroup" do
before do
MiqUserRole.seed
MiqGroup.seed
Expand Down Expand Up @@ -436,9 +435,25 @@
expect(controller.instance_variable_get(:@group).name).to eq(@group.name)
expect(controller.instance_variable_get(:@tags_tree)).to_not be_nil
end

context 'setting group record variables to new values' do
before do
controller.instance_variable_set(:@edit, :new => {:use_filter_expression => false,
:description => "Test",
:role => @role.id,
:filter_expression => @exp.exp,
:belongsto => {},
:filters => {}})
end

it 'resets filter expression variable to default value' do
controller.send(:rbac_group_set_record_vars, @group)
expect(controller.instance_variable_get(:@edit)[:new][:filter_expression]).to eq({})
end
end
end

context "rbac_role_edit" do
describe "#rbac_role_edit" do
before do
MiqUserRole.seed
MiqGroup.seed
Expand All @@ -461,7 +476,7 @@
end
end

context "rbac_role_set_form_vars" do
describe "#rbac_role_set_form_vars" do
before do
MiqUserRole.seed
MiqGroup.seed
Expand Down Expand Up @@ -493,7 +508,7 @@

render_views

context "::MiqRegion" do
describe "::MiqRegion" do
before do
EvmSpecHelper.local_miq_server
root_tenant = Tenant.seed
Expand Down Expand Up @@ -602,6 +617,7 @@
end
let!(:group_in_inactive_region) { FactoryBot.create(:miq_group, :in_other_region, :other_region => inactive_region) }
let(:admin_user) { FactoryBot.create(:user, :role => "super_administrator") }

it 'counts only Tenants in active region' do
allow(controller).to receive(:x_node).and_return('root')
controller.send(:rbac_get_info)
Expand Down

0 comments on commit bc5c29e

Please sign in to comment.