Skip to content

Commit

Permalink
Add specs for tree_selected_model method
Browse files Browse the repository at this point in the history
tree_selected_model returns models based on x_node
must be called from tree_selct and explorer
  • Loading branch information
ZitaNemeckova committed Nov 28, 2017
1 parent bf22098 commit 24c784d
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions spec/controllers/ops_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@
expect(response.status).to eq(200)
expect(assigns(:sb)[:active_accord]).to eq(:rbac)
end

it 'calls #tree_selected_model' do
controller.instance_variable_set(:@sb, {})
allow(controller).to receive(:render)
expect(controller).to receive(:tree_selected_model)
controller.send(:explorer)
end
end

context "#replace_explorer_trees" do
Expand Down Expand Up @@ -380,4 +387,72 @@
end
end
end

context "#tree_selected_model" do
it 'sets @tree_model_selected to User for user node' do
allow(controller).to receive(:x_node).and_return('u-42')
controller.tree_selected_model
expect(assigns(:tree_selected_model)).to eq(User)
end

it 'sets @tree_model_selected to Tenant for tenant node' do
allow(controller).to receive(:x_node).and_return('tn-42')
controller.tree_selected_model
expect(assigns(:tree_selected_model)).to eq(Tenant)
end

it 'sets @tree_model_selected to MiqGroup for group node' do
allow(controller).to receive(:x_node).and_return('g-42')
controller.tree_selected_model
expect(assigns(:tree_selected_model)).to eq(MiqGroup)
end

it 'sets @tree_model_selected to MiqUserRole for group node' do
allow(controller).to receive(:x_node).and_return('ur-42')
controller.tree_selected_model
expect(assigns(:tree_selected_model)).to eq(MiqUserRole)
end

it 'sets @tree_model_selected to User for all users node' do
allow(controller).to receive(:x_node).and_return('xx-u')
controller.tree_selected_model
expect(assigns(:tree_selected_model)).to eq(User)
end

it 'sets @tree_model_selected to Tenant for all tenants node' do
allow(controller).to receive(:x_node).and_return('xx-tn')
controller.tree_selected_model
expect(assigns(:tree_selected_model)).to eq(Tenant)
end

it 'sets @tree_model_selected to MiqGroup for all groups node' do
allow(controller).to receive(:x_node).and_return('xx-g')
controller.tree_selected_model
expect(assigns(:tree_selected_model)).to eq(MiqGroup)
end

it 'sets @tree_model_selected to MiqUserRole for all roles node' do
allow(controller).to receive(:x_node).and_return('xx-ur')
controller.tree_selected_model
expect(assigns(:tree_selected_model)).to eq(MiqUserRole)
end

it 'sets @tree_model_selected to MiqRegion for root node' do
allow(controller).to receive(:x_node).and_return('root')
controller.tree_selected_model
expect(assigns(:tree_selected_model)).to eq(MiqRegion)
end
end

context '#tree_select' do
it 'calls #tree_select_model' do
controller.instance_variable_set(:@sb, {})
controller.params[:id] = 'root'
allow(controller).to receive(:set_active_tab)
allow(controller).to receive(:get_node_info)
allow(controller).to receive(:replace_right_cell)
expect(controller).to receive(:tree_selected_model)
controller.send(:tree_select)
end
end
end

0 comments on commit 24c784d

Please sign in to comment.