Skip to content

Commit

Permalink
added test coverage when calling ServiceTemplate#custom_actions with …
Browse files Browse the repository at this point in the history
…parameter
  • Loading branch information
yrudman committed Jan 15, 2018
1 parent 4eed7a0 commit a9a8d4f
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions spec/models/service_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,65 @@
expect(service_template.custom_actions).to match(expected)
end

context "expression evaluation" do
let(:service_template) { FactoryGirl.create(:service_template, :prov_type=> "vmware") }
let(:service) { FactoryGirl.create(:service, :name => "foo", :service_template => service_template) }
let(:true_expression_on_template) do
MiqExpression.new("=" => {"field" => "ServiceTemplate-prov_type", "value" => "vmware"})
end
let(:false_expression_on_template) do
MiqExpression.new("=" => {"field" => "ServiceTemplate-prov_type", "value" => "not_vmware"})
end
let(:true_expression_on_service) do
MiqExpression.new("=" => {"field" => "Service-name", "value" => "foo"})
end
let(:false_expression_on_service) do
MiqExpression.new("=" => {"field" => "Service-name", "value" => "not_foo"})
end

before do
FactoryGirl.create(:custom_button,
:name => "visible button on service",
:applies_to_class => "Service",
:visibility_expression => true_expression_on_service)
FactoryGirl.create(:custom_button,
:name => "hidden button on service",
:applies_to_class => "Service",
:visibility_expression => false_expression_on_service)
FactoryGirl.create(:custom_button,
:name => "visible button on template",
:applies_to_class => "ServiceTemplate",
:applies_to_id => service_template.id,
:visibility_expression => true_expression_on_template)
FactoryGirl.create(:custom_button,
:name => "hidden visible button on template",
:applies_to_class => "ServiceTemplate",
:applies_to_id => service_template.id,
:visibility_expression => false_expression_on_template)
end

it "uses ServiceTemplate object to evaluate expression defined on Service Template if no parameter passed" do
expected = {
:buttons => [
a_hash_including("name" => "visible button on template")
],
:button_groups => []
}
expect(service_template.custom_actions).to match(expected)
end

it "uses passed object for expression defined on that object and ServiceTemplate for expression on template" do
expected = {
:buttons => a_collection_containing_exactly(
a_hash_including("name" => "visible button on service"),
a_hash_including("name" => "visible button on template")
),
:button_groups => []
}
expect(service_template.custom_actions(service)).to match(expected)
end
end

it "serializes the enablement" do
service_template = FactoryGirl.create(:service_template, :name => "foo")
true_expression = MiqExpression.new("=" => {"field" => "ServiceTemplate-name", "value" => "foo"})
Expand Down

0 comments on commit a9a8d4f

Please sign in to comment.