Skip to content

Commit

Permalink
Spec for Tag field when the group filter expression is edited
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalis committed Jan 30, 2018
1 parent b113412 commit 85b9521
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/views/layouts/exp_atom/_editor.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
- if @expkey == :filter_expression
- opts = [[_('Tag'), 'tags']]
- @edit[@expkey][:exp_typ] = 'tags'
-else
- else
- opts += exptypes
- else
- opts += exptypes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,40 @@
post :automate_button_field_changed, :params => {:id => 'new', :instance_name => "Request"}
expect(assigns(:sb)[:active_tab]).to eq("ab_advanced_tab")
end

it "uses available expression fields when editing the custom buttons expressions" do
allow(MiqAeClass).to receive_messages(:find_distinct_instances_across_domains => [double(:name => "foo")])

e_exp = MiqExpression.new("=" => {:field => "MiqGroup.name", :value => "TestEnablementExpression"}, :token => 1)

@sb = {:active_tree => :ab_tree,
:trees => {:ab_tree => {:tree => :ab_tree}},
:params => {:instance_name => 'CustomButton_1'}}
controller.instance_variable_set(:@sb, @sb)
controller.instance_variable_set(:@breadcrumbs, [])

edit = {:new => {:button_images => %w(01 02 03), :available_dialogs => {:id => '01', :name => '02'},
:instance_name => 'CustomButton_1',
:attrs => [%w(Attr1 01), %w(Attr2 02), %w(Attr3 03), %w(Attr4 04), %w(Attr5 05)],
:enablement_expression => e_exp.exp},
:instance_names => %w(CustomButton_1 CustomButton_2),
:exp_key => 'foo',
:ansible_playbooks => [],
:current => {}}
edit[:enablement_expression] ||= ApplicationController::Filter::Expression.new
edit[:enablement_expression][:expression] = {:test => "foo", :token => 1}
edit[:new][:enablement_expression] = copy_hash(edit[:enablement_expression][:expression])
edit[:enablement_expression].history.reset(edit[:enablement_expression][:expression])
controller.instance_variable_set(:@edit, edit)
controller.instance_variable_set(:@expkey, :enablement_expression)
edit[:enablement_expression][:exp_table] = controller.send(:exp_build_table, edit[:enablement_expression][:expression])
edit[:enablement_expression][:exp_model] = 'MiqGroup'
session[:edit] = edit
session[:expkey] = :enablement_expression
controller.instance_variable_set(:@edit, edit)
post :exp_token_pressed, :params => {:id => 'new', :token => 1}
@edit = controller.instance_variable_get(:@edit)
expect(@edit[:enablement_expression][:exp_typ]).to be_nil
end
end
end
37 changes: 37 additions & 0 deletions spec/controllers/ops_controller/ops_rbac_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,43 @@

render_views

it "uses tags field only when editing the group filter_expression" do
new = {:use_filter_expression => true,
:name => 'Name',
:description => "Test",
:role => @role.id,
:filter_expression => @exp.exp,
:exp_key => 'foo',
:belongsto => {},
:filters => {'managed/env' => '/managed/env'}}
allow(controller).to receive(:replace_right_cell)
controller.instance_variable_set(:@_params, :use_filter_expression => "true", :id => "new")

edit = {:key => "rbac_group_edit__new",
:new => new,
:current => new,
:edit_exp => {:key => '???'}}
edit[:filter_expression] ||= ApplicationController::Filter::Expression.new
edit[:filter_expression][:expression] = {:test => "foo", :token => 1}
edit[:new][:filter_expression] = copy_hash(edit[:filter_expression][:expression])
edit[:filter_expression].history.reset(edit[:filter_expression][:expression])
controller.instance_variable_set(:@edit, edit)
controller.instance_variable_set(:@expkey, :filter_expression)
edit[:filter_expression][:exp_table] = controller.send(:exp_build_table, edit[:filter_expression][:expression])
edit[:filter_expression][:exp_model] = @group.class.to_s
session[:edit] = edit
session[:expkey] = :filter_expression
controller.instance_variable_set(:@edit, edit)
session[:sandboxes] = {"ops" => {:active_tree => :rbac_tree}}
allow(controller).to receive(:replace_right_cell)

post :tree_select, :params => { :id => 'root', :format => :js }
expect(MiqExpression).to receive(:tag_details)
post :exp_token_pressed, :params => {:id => 'new', :use_filter_expression => "true", :token => 1}
@edit = controller.instance_variable_get(:@edit)
expect(@edit[:filter_expression][:exp_typ]).to eq('tags')
end

it "calls MiqExpression.tag_details to get only the My Company type tag categories" do
new = {:use_filter_expression => true,
:name => 'Name',
Expand Down

0 comments on commit 85b9521

Please sign in to comment.