Skip to content

Commit

Permalink
Merge pull request #15873 from lpichler/use_custom_buttons_ids_instea…
Browse files Browse the repository at this point in the history
…d_of_set_data#button_order

Use custom buttons ids from relation instead of from CustomButtonSet#set_data[:button_order]
  • Loading branch information
Martin Povolny committed Aug 25, 2017
2 parents 96e94e7 + d4f8dda commit 12e27eb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/custom_button_set.rb
Expand Up @@ -51,7 +51,7 @@ def self.applies_to_all_instances(class_name)
# - filtered custom_button_sets array when all visibilty expression custom buttons have been evaluated to false
def self.filter_with_visibility_expression(custom_button_sets, object)
custom_button_sets.each_with_object([]) do |custom_button_set, ret|
custom_button_from_set = CustomButton.where(:id => custom_button_set.set_data[:button_order]).select(:id, :visibility_expression)
custom_button_from_set = CustomButton.where(:id => custom_button_set.custom_buttons.pluck(:id)).select(:id, :visibility_expression)
filtered_ids = custom_button_from_set.select { |x| x.evaluate_visibility_expression_for(object) }.pluck(:id)
if filtered_ids.present?
custom_button_set.set_data[:button_order] = filtered_ids
Expand Down
4 changes: 4 additions & 0 deletions spec/models/custom_button_set_spec.rb
Expand Up @@ -29,6 +29,10 @@
let(:set_data) { {:applies_to_class => "Vm", :button_order => [custom_button_1.id, custom_button_2.id]} }
let(:custom_button_set) { FactoryGirl.create(:custom_button_set, :name => "set_1", :set_data => set_data) }

before do
[custom_button_1, custom_button_2].each { |x| custom_button_set.add_member(x) }
end

context 'when all CustomButtons#visibility_expression=nil' do
let(:miq_expression) { nil }

Expand Down

0 comments on commit 12e27eb

Please sign in to comment.