From b6d57bd32baa96aa8f496efbcaea52e5d3e50eb4 Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Tue, 10 Jan 2017 19:26:00 -0800 Subject: [PATCH 1/4] Consolidate the request wf attributes specs --- spec/requests/api/requests_spec.rb | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/spec/requests/api/requests_spec.rb b/spec/requests/api/requests_spec.rb index cd0a1019b32..e0fae5103a0 100644 --- a/spec/requests/api/requests_spec.rb +++ b/spec/requests/api/requests_spec.rb @@ -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 => 'tester@example.com'}) - 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, @@ -266,11 +246,13 @@ 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" - expected = a_hash_including("id" => request.id, "v_allowed_tags" => [a_hash_including("children")]) + expected_workflow = a_hash_including("id" => request.id, "workflow" => a_hash_including("values")) + expected_tags = a_hash_including("id" => request.id, "v_allowed_tags" => [a_hash_including("children")]) - expect(response.parsed_body).to match(expected) + expect(response.parsed_body).to match(expected_workflow) + expect(response.parsed_body).to match(expected_tags) expect(response).to have_http_status(:ok) end end From 891fe8364a20ac6571a88b8fdc022fd90fc3dbe7 Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Tue, 10 Jan 2017 19:28:44 -0800 Subject: [PATCH 2/4] Add a virtual column for v_class to return the request wf class --- app/models/miq_request.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/miq_request.rb b/app/models/miq_request.rb index 685a33e431c..46137841d1e 100644 --- a/app/models/miq_request.rb +++ b/app/models/miq_request.rb @@ -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_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 virtual_has_one :workflow From d6749566aa9b8e9eb4bcf69762f97f0a8f565a3c Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Tue, 10 Jan 2017 19:34:27 -0800 Subject: [PATCH 3/4] spec to test v_class attribute --- spec/requests/api/requests_spec.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/requests/api/requests_spec.rb b/spec/requests/api/requests_spec.rb index e0fae5103a0..2014193ee63 100644 --- a/spec/requests/api/requests_spec.rb +++ b/spec/requests/api/requests_spec.rb @@ -246,13 +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 => "workflow,v_allowed_tags" + run_get requests_url(request.id), :attributes => "workflow,v_allowed_tags,v_class" expected_workflow = a_hash_including("id" => request.id, "workflow" => a_hash_including("values")) expected_tags = a_hash_including("id" => request.id, "v_allowed_tags" => [a_hash_including("children")]) + expected_class = a_hash_including( + "id" => request.id, + "v_class" => {"instance_logger" => a_hash_including("klass" => request.workflow.class.to_s)}) expect(response.parsed_body).to match(expected_workflow) expect(response.parsed_body).to match(expected_tags) + expect(response.parsed_body).to match(expected_class) expect(response).to have_http_status(:ok) end end From af354f503409294b7d75466ba01782777dcb2106 Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Thu, 12 Jan 2017 08:18:48 -0800 Subject: [PATCH 4/4] PR feedback -- rename the virtual column and consolidate the test --- app/models/miq_request.rb | 4 ++-- spec/requests/api/requests_spec.rb | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/models/miq_request.rb b/app/models/miq_request.rb index 46137841d1e..9e2a96fa93b 100644 --- a/app/models/miq_request.rb +++ b/app/models/miq_request.rb @@ -34,13 +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_class, :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 + delegate :class, :to => :workflow, :prefix => :v_workflow virtual_has_one :workflow diff --git a/spec/requests/api/requests_spec.rb b/spec/requests/api/requests_spec.rb index 2014193ee63..ca03dcb181f 100644 --- a/spec/requests/api/requests_spec.rb +++ b/spec/requests/api/requests_spec.rb @@ -246,17 +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 => "workflow,v_allowed_tags,v_class" + run_get requests_url(request.id), :attributes => "workflow,v_allowed_tags,v_workflow_class" - expected_workflow = a_hash_including("id" => request.id, "workflow" => a_hash_including("values")) - expected_tags = a_hash_including("id" => request.id, "v_allowed_tags" => [a_hash_including("children")]) - expected_class = a_hash_including( - "id" => request.id, - "v_class" => {"instance_logger" => a_hash_including("klass" => request.workflow.class.to_s)}) + 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_workflow) - expect(response.parsed_body).to match(expected_tags) - expect(response.parsed_body).to match(expected_class) + expect(response.parsed_body).to match(expected_response) expect(response).to have_http_status(:ok) end end