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

fixes bug where downloading a cookbook version would break if the coo… #1452

Merged
merged 4 commits into from
Oct 12, 2016

Conversation

nellshamrell
Copy link
Contributor

…kbook version had one metric but not the other associated with it

Signed-off-by: Nell Shamrell [email protected]

…kbook version had one metric but not the other associated with it

Signed-off-by: Nell Shamrell <[email protected]>
json.failed collaborator_num_metric_result(cookbook_version).failure
json.feedback collaborator_num_metric_result(cookbook_version).feedback
end
json.quality_metrics @cookbook_version_metrics do |metric|
Copy link
Contributor

@robbkidd robbkidd Oct 11, 2016

Choose a reason for hiding this comment

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

I think the iteration done by the builder thingie used here alone will take care of the !nil? and any? case. If @cookbook_version_metrics is nil or [], the iteration will be a no-op.

Whether that is correct or not, I suggest the if above also include (or only be) a feature flag check for fieri being enabled. (Under the philosophy that if fieri is disabled, like in the human UI, don't show metrics regardless of their presence.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, will add that and test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Contributor

@robbkidd robbkidd left a comment

Choose a reason for hiding this comment

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

The fix looks good and I've got a few recommendations for the tests.

context 'when the cookbook has only the foodcritic metric' do
before do
collab_result.destroy
expect(cookbook_version.metric_results.count).to eq(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

A couple of thoughts here:

  1. An expectation in a before setup block is a little ..er.. unexpected. I can understand putting this in during development as a confirmation that the setup has achieved the desired test start state, but I recommend we not keep this line.
  2. If we do keep this line, we could protect all tests in this context from breaking when we have 3 or more metrics in the system if we expect a change in the count instead of a hard-coded count.
expect {
  collab_result.destroy
}.to change {
  cookbook_version.metric_results.count
}.by(-1)

... but then that ends up looking even more like something that is odd to put in a before setup block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was meant for development only, removing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

expect(signature(json_body)).to include(quality_metrics)
it 'does not return quality metrics for the cookbook version' do
get "/api/v1/cookbooks/#{cookbook.name}/versions/#{cookbook_version.version}"
expect(JSON.parse(response.body)).to_not include(quality_metrics)
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about making this only check for a key named "quality_metrics" in the returned JSON so that the test does not depend on the whole structure of the results?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could do that...but I think that this is a little clearer and I don't think it costs us much in terms of time and memory.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK.

@robbkidd
Copy link
Contributor

👍 Pending test success.

@chef-delivery chef-delivery merged commit e15cc09 into master Oct 12, 2016
@robbkidd robbkidd mentioned this pull request Oct 13, 2016
48 tasks
@robbkidd robbkidd deleted the fix-api-view branch November 11, 2016 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants