Skip to content

Commit

Permalink
Merge pull request #13441 from AparnaKarve/api_expose_wf_class
Browse files Browse the repository at this point in the history
[api] expose Request Workflow class name
  • Loading branch information
abellotti authored Jan 12, 2017
2 parents d557f19 + af354f5 commit 1d2698f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
2 changes: 2 additions & 0 deletions app/models/miq_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ class MiqRequest < ApplicationRecord
virtual_column :v_approved_by_email, :type => :string, :uses => {:miq_approvals => :stamper}
virtual_column :stamped_on, :type => :datetime, :uses => :miq_approvals
virtual_column :v_allowed_tags, :type => :string, :uses => :workflow
virtual_column :v_workflow_class, :type => :string, :uses => :workflow
virtual_column :request_type_display, :type => :string
virtual_column :resource_type, :type => :string
virtual_column :state, :type => :string

delegate :allowed_tags, :to => :workflow, :prefix => :v
delegate :class, :to => :workflow, :prefix => :v_workflow

virtual_has_one :workflow

Expand Down
34 changes: 10 additions & 24 deletions spec/requests/api/requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,27 +229,7 @@
expect(response).to have_http_status(:ok)
end

it "exposes workflow in the request resources" do
ems = FactoryGirl.create(:ems_vmware)
vm_template = FactoryGirl.create(:template_vmware, :name => "template1", :ext_management_system => ems)
request = FactoryGirl.create(:miq_provision_request,
:requester => @user,
:src_vm_id => vm_template.id,
:options => {:owner_email => '[email protected]'})
FactoryGirl.create(:miq_dialog,
:name => "miq_provision_dialogs",
:dialog_type => MiqProvisionWorkflow)

api_basic_authorize action_identifier(:requests, :read, :resource_actions, :get)
run_get requests_url(request.id), :attributes => "workflow"

expected = a_hash_including("id" => request.id, "workflow" => a_hash_including("values"))

expect(response.parsed_body).to match(expected)
expect(response).to have_http_status(:ok)
end

it "exposes allowed_tags in the request resources" do
it "exposes various attributes in the request resources" do
ems = FactoryGirl.create(:ems_vmware)
vm_template = FactoryGirl.create(:template_vmware, :name => "template1", :ext_management_system => ems)
request = FactoryGirl.create(:miq_provision_request,
Expand All @@ -266,11 +246,17 @@
request.add_tag(t.name, t.children.first.name)

api_basic_authorize action_identifier(:requests, :read, :resource_actions, :get)
run_get requests_url(request.id), :attributes => "v_allowed_tags"
run_get requests_url(request.id), :attributes => "workflow,v_allowed_tags,v_workflow_class"

expected = a_hash_including("id" => request.id, "v_allowed_tags" => [a_hash_including("children")])
expected_response = a_hash_including(
"id" => request.id,
"workflow" => a_hash_including("values"),
"v_allowed_tags" => [a_hash_including("children")],
"v_workflow_class" => a_hash_including(
"instance_logger" => a_hash_including("klass" => request.workflow.class.to_s))
)

expect(response.parsed_body).to match(expected)
expect(response.parsed_body).to match(expected_response)
expect(response).to have_http_status(:ok)
end
end
Expand Down

0 comments on commit 1d2698f

Please sign in to comment.