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

Custom fonticons and colors in the CustomButton(Set) model #39

Merged
merged 1 commit into from
Jul 26, 2017

Conversation

skateman
Copy link
Member

@skateman skateman commented Jul 11, 2017

This migration converts the old custom button icons to the new format where we specify a button class and a color instead of a number.

https://www.pivotaltracker.com/story/show/147779325

@skateman skateman changed the title [WIP] Custom fonticons and colors in the CustomButton model Custom fonticons and colors in the CustomButton model Jul 11, 2017
@skateman skateman changed the title Custom fonticons and colors in the CustomButton model [WIP] Custom fonticons and colors in the CustomButton model Jul 11, 2017
@miq-bot miq-bot added the wip label Jul 11, 2017
serialize :options
end

def up
Copy link
Contributor

Choose a reason for hiding this comment

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

how about an enclosing say_with_time?

next unless btn.options[:button_image]
icon = {}

case btn.options[:button_image].to_i
Copy link
Contributor

Choose a reason for hiding this comment

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

(Minor) Is to_i needed?

custom_button.reload

expect(custom_button.options).to have_key(:button_image_class)
expect(custom_button.options).not_to have_key(:button_image)
Copy link
Contributor

Choose a reason for hiding this comment

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

how about add a case (another button) where you will have both :button_image_class and :button_image_color?

expect(custom_button.options).to have_key(:button_image)
expect(custom_button.options).not_to have_key(:button_image_class)
expect(custom_button.options).not_to have_key(:button_image_color)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

add another button case which has no : button_image_color?

Copy link
Member Author

Choose a reason for hiding this comment

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

@jameswnl button_image_color is optional

@skateman skateman changed the title [WIP] Custom fonticons and colors in the CustomButton model [WIP] Custom fonticons and colors in the CustomButton(Set) model Jul 13, 2017
@skateman skateman changed the title [WIP] Custom fonticons and colors in the CustomButton(Set) model Custom fonticons and colors in the CustomButton(Set) model Jul 13, 2017
@skateman
Copy link
Member Author

Merging this will probably break the tests in the ui-classic repo, but this should fix it: ManageIQ/manageiq-ui-classic#1685

@miq-bot miq-bot removed the wip label Jul 13, 2017
@skateman
Copy link
Member Author

@jameswnl can you take a look please?

@@ -0,0 +1,144 @@
class CustomButtonToClasses < ActiveRecord::Migration[5.0]
Copy link
Contributor

@lpichler lpichler Jul 14, 2017

Choose a reason for hiding this comment

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

maybe more explanatory naming?
something like:
migrate_<something>_to_<something>

Copy link
Member Author

Choose a reason for hiding this comment

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

migrate -> implicit enough from the folder name
everything else is there 😉 :trollface:

Copy link
Member

Choose a reason for hiding this comment

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

To @lpichler's point, almost all of the migrations start with a verb, so ConvertCustomButtonToClasses?


context 'CustomButton' do
let(:params) { custom_button.options }
let!(:custom_button) { migration_stub(:CustomButton).create!(create_params) }
Copy link
Contributor

Choose a reason for hiding this comment

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

you probably intended to use custom_button_stub which is already defined for this stub, right?

let!(:custom_button) { migration_stub(:CustomButton).create!(create_params) }

migration_context :up do
let(:create_params) { {:options => {:button_image => 1} } }
Copy link
Contributor

Choose a reason for hiding this comment

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

for this {:button_image => 1}, can we check for expect(params).to have_key(:button_color)?

Can we add one more case {:button_image => 6}, which we would check for expect(params).not_to have_key(:button_color)?

let(:custom_button_stub) { migration_stub(:CustomButton) }
let(:miq_set_stub) { migration_stub(:MiqSet) }

shared_examples 'migrate up' do
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice to use shared_example. However IMHO, in this case, I'd rather not to use it because

  1. the lets are not easy to follow, plus not saving too much code
  2. you won't be able to test the 2nd cases that I suggested.


context 'CustomButtonSet' do
let(:params) { custom_button.set_data }
let!(:custom_button) { migration_stub(:MiqSet).create!(create_params) }
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, use miq_set_stub

let!(:custom_button) { migration_stub(:MiqSet).create!(create_params) }

migration_context :up do
let(:create_params) { {:set_data => {:button_image => 1}, :set_type => 'CustomButtonSet'} }
Copy link
Contributor

Choose a reason for hiding this comment

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

similarly here, nice to test for the case of {:button_image => 6}

@skateman
Copy link
Member Author

@jameswnl adjusted specs!

custom_button.reload

expect(params).to have_key(:button_icon)
expect(params).not_to have_key(:button_color)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd keep expect(params).not_to have_key(:button_image) here as well

Copy link
Contributor

Choose a reason for hiding this comment

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

How about this one?
You can also replace these key checking lines by 1 line
expect(params.keys).to match_array([:button_icon])

migrate
custom_button.reload

expect(params).to have_key(:button_icon)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd add expect(params).to have_key(:button_color) here

migrate
custom_button.reload

expect(params).to have_key(:button_icon)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd add expect(params).to have_key(:button_color)

custom_button.reload

expect(params).to have_key(:button_icon)
expect(params).not_to have_key(:button_color)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd add expect(params).not_to have_key(:button_image) here.
So it'll be very obvious to readers the difference between the 2 cases. Will be helpful to readers like me.

Copy link
Contributor

Choose a reason for hiding this comment

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

and this one...

Copy link
Contributor

@jameswnl jameswnl left a comment

Choose a reason for hiding this comment

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

Pretty close. a couple more suggestions

@skateman skateman force-pushed the custom-button-fonticons branch 2 times, most recently from a5894a5 to 3384922 Compare July 18, 2017 08:03
@skateman
Copy link
Member Author

@jameswnl all fixed

Copy link
Contributor

@jameswnl jameswnl left a comment

Choose a reason for hiding this comment

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

almost there...

And about time to get @Fryguy 's attention...

expect(params).not_to have_key(:button_image)
end

context 'button set with default color' do
Copy link
Contributor

Choose a reason for hiding this comment

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

similarly here with the context ...

expect(params).not_to have_key(:button_image)
end

context 'button with default color' do
Copy link
Contributor

Choose a reason for hiding this comment

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

context is good for grouping multiple specs. So here is only 1 spec, may get flagged by other reviewers (I am feeling like a :trollface: to ask more ...)
you can move the context text into the it statement.

@skateman
Copy link
Member Author

@jameswnl I have a feeling that you haven't read http://www.betterspecs.org/ :trollface: 😉, if I drop the context, I can't use the let(:create_params) and I don't really want to give up that 😉

@jameswnl
Copy link
Contributor

@skateman 😭 I admit that I haven't read that plus a ton of others.

Yeah, and according to that and a bunch other docs, you would want to start your context with [when|with|without].
I also found someone in that particular point arguing against the 1 it in 1 context. But it's pretty common that people are very opinionated on spec styles (even arguing between When vs when). My goal is to keep specs clean and easy to read and I try to avoid iron-fisting those things.

So I'll LGTM if you want to keep it that way.

@miq-bot
Copy link
Member

miq-bot commented Jul 19, 2017

Checked commit skateman@b641025 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks fine. 👍

@skateman
Copy link
Member Author

@jameswnl added the suggested when. I was always planning to write some spec guidelines (at least for ui-classic), but never had the time and I got stuck with reviewing everyone else's tests 😉

@skateman
Copy link
Member Author

@Fryguy can you please merge this?

@dclarizio
Copy link

@miq-bot assign @Fryguy

@dclarizio
Copy link

@Fryguy @chessbyte can we get this reviewed/merged soon? The ui-classic feature PR is dependent on this

@dclarizio
Copy link

@Fryguy @chessbyte bump!

@Fryguy Fryguy merged commit e3543ba into ManageIQ:master Jul 26, 2017
@Fryguy Fryguy added this to the Sprint 66 Ending Aug 7, 2017 milestone Jul 26, 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.

7 participants