-
Notifications
You must be signed in to change notification settings - Fork 125
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
Conversation
aca0836
to
9349223
Compare
9349223
to
d06e6e0
Compare
serialize :options | ||
end | ||
|
||
def up |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
d06e6e0
to
2d0a7f2
Compare
Merging this will probably break the tests in the ui-classic repo, but this should fix it: ManageIQ/manageiq-ui-classic#1685 |
@jameswnl can you take a look please? |
@@ -0,0 +1,144 @@ | |||
class CustomButtonToClasses < ActiveRecord::Migration[5.0] |
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
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 😉
There was a problem hiding this comment.
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) } |
There was a problem hiding this comment.
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} } } |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
- the
let
s are not easy to follow, plus not saving too much code - 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) } |
There was a problem hiding this comment.
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'} } |
There was a problem hiding this comment.
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}
2d0a7f2
to
474a948
Compare
@jameswnl adjusted specs! |
custom_button.reload | ||
|
||
expect(params).to have_key(:button_icon) | ||
expect(params).not_to have_key(:button_color) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this one...
There was a problem hiding this 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
a5894a5
to
3384922
Compare
@jameswnl all fixed |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 to ask more ...)
you can move the context text into the it
statement.
@jameswnl I have a feeling that you haven't read http://www.betterspecs.org/ 😉, if I drop the |
@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 So I'll LGTM if you want to keep it that way. |
3384922
to
b641025
Compare
Checked commit skateman@b641025 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
@jameswnl added the suggested |
@Fryguy can you please merge this? |
@Fryguy @chessbyte can we get this reviewed/merged soon? The ui-classic feature PR is dependent on this |
@Fryguy @chessbyte bump! |
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