Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api] expose allowed tags for a request workflow #13379

Merged

Conversation

AparnaKarve
Copy link
Contributor

Created a virtual_column for allowed_tags which is required in order to populate the tags tree in the Request Workflow in SUI

api/requests/<id>?attributes=v_allowed_tags

https://www.pivotaltracker.com/n/projects/1914499/stories/137139937

@AparnaKarve
Copy link
Contributor Author

@imtayadeway Can you please review this when you get a chance? Thanks!

@AparnaKarve
Copy link
Contributor Author

/cc @chriskacerguis

@abellotti
Copy link
Member

In general I'm ok with this, short of the rubocop warning above.

Just curious, could you get that information today without this PR via:

  GET /api/requests/:id?attributes=workflow.allowed_tags

Thanks.

@AparnaKarve
Copy link
Contributor Author

GET /api/requests/:id?attributes=workflow.allowed_tags

@abellotti Interesting! However, that did not work. I got this --

{
  "error": {
    "kind": "internal_server_error",
    "message": "undefined method `has_attribute?' for ManageIQ::Providers::Vmware::InfraManager::ProvisionWorkflow:Class\nDid you mean?  class_attribute",
    "klass": "NoMethodError"
  }
}

@AparnaKarve
Copy link
Contributor Author

@abellotti As far as the rubocop warning goes, I think we could ignore it.
I have deliberately added the spacing for readability like all the other virtual_columns on top that use :uses

 virtual_column  :reason,               :type => :string,   :uses => :miq_approvals
 virtual_column  :v_approved_by,        :type => :string,   :uses => :miq_approvals
 virtual_column  :v_approved_by_email,  :type => :string,   :uses => {:miq_approvals => :stamper}
 virtual_column  :stamped_on,           :type => :datetime, :uses => :miq_approvals

Maybe I could move this newly added virtual column on top with the others that have :uses

@abellotti
Copy link
Member

@AparnaKarve thanks for checking.

This LGTM!!

@imtayadeway thoughts/input ?

@@ -236,6 +237,10 @@ def v_approved_by_email
emails.join(", ")
end

def v_allowed_tags
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could do this in one line:

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that would work 👍 . Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay!

@@ -248,6 +248,31 @@
expect(response.parsed_body).to match(expected)
expect(response).to have_http_status(:ok)
end

it "exposes allowed_tags in the request resources" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit divided over this test, although it is written perfectly well! I'm just thinking that since we should have ample coverage that the API can deliver virtual attributes, is it needed? Perhaps a model test would suffice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what you're saying is, instead of writing a test on the API side we should write it only on the model side? ...which kinda makes sense in this situation.
Although the only reason I added a virtual_column was because I have this requirement to access it via the API. Without this requirement in the picture, the model does not need any changes.

How about we include both tests?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaning towards only making the model test. @abellotti any thoughts here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both good, though my preference is on the API side since that is the intended usage and it tests both model and the API exposing it.

Copy link
Contributor Author

@AparnaKarve AparnaKarve Jan 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abellotti @imtayadeway I have added tests in both places -- model and API.

If having both specs seems redundant, I can get rid of this commit d041b96, which is the model spec.

@miq-bot
Copy link
Member

miq-bot commented Jan 9, 2017

Checked commits AparnaKarve/manageiq@21d9103~...d041b96 with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1
3 files checked, 1 offense detected

app/models/miq_request.rb

@abellotti
Copy link
Member

👍

@abellotti abellotti merged commit d9345d3 into ManageIQ:master Jan 10, 2017
@abellotti abellotti added this to the Sprint 52 Ending Jan 16, 2017 milestone Jan 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants