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

Correct disabling method and refactored test for it's class #11054

Conversation

romanblanco
Copy link
Member

@romanblanco romanblanco commented Sep 7, 2016

Purpose or Intent

The same kind of changes as in #10593 + we don't need to test #visible? method for the button that does not change it

Links

Related issue: #10593
https://bugzilla.redhat.com/show_bug.cgi?id=1376595
https://bugzilla.redhat.com/show_bug.cgi?id=1377686
https://bugzilla.redhat.com/show_bug.cgi?id=1330894

@durandom @PanSpagetka can you review?

@durandom
Copy link
Member

durandom commented Sep 8, 2016

I think the code here is also wrong, because it checks the message and not supports_feature?. That said the message could be nil as of now which will be a default string if #10980 is merged.

Also, if you want the test to be complete you should test both, the is_available_now_error_message case and the supports_feature? case. Or, be lazy like me :), and test only the latter one, because thats the future

@durandom
Copy link
Member

cc @gauravaradhye

Copy link
Member

@martinpovolny martinpovolny left a comment

Choose a reason for hiding this comment

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

@romanblanco : will you, please, address the concerns by @durandom ?

@durandom
Copy link
Member

@romanblanco I think this https://bugzilla.redhat.com/show_bug.cgi?id=1377686 is because of the code.

@romanblanco romanblanco changed the title Refactor test to not test same thing as other specs [WIP] Refactor test to not test same thing as other specs Sep 26, 2016
@romanblanco
Copy link
Member Author

@miq-bot add_label wip

@miq-bot miq-bot added the wip label Sep 26, 2016
@romanblanco
Copy link
Member Author

maybe related to #10694

@romanblanco romanblanco force-pushed the refactor_generic_button_with_disable_test branch from 8be4328 to e51a735 Compare September 29, 2016 08:25
@romanblanco romanblanco changed the title [WIP] Refactor test to not test same thing as other specs Correct disabling method and refactored test for it's class Sep 29, 2016
@romanblanco
Copy link
Member Author

@miq-bot remove_label wip

@miq-bot miq-bot removed the wip label Sep 29, 2016
@romanblanco
Copy link
Member Author

@durandom @PanSpagetka can you review the changes? Issues described in BZ should be fixed.

end
return true if @error_message.present?
Copy link
Member

Choose a reason for hiding this comment

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

why not make this return true/false only to make it a true predicate method. The way to do that is to change the line to the simpler:

return @error_message.present?

or the more idiomatic

@error_message.present?

This will return true/false.

Copy link
Member Author

@romanblanco romanblanco Sep 29, 2016

Choose a reason for hiding this comment

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

Sure, that will be better, corrected. thanks 😊

@romanblanco romanblanco force-pushed the refactor_generic_button_with_disable_test branch from e51a735 to 909ef50 Compare September 29, 2016 08:50
@martinpovolny
Copy link
Member

@jzigmund : can you, please, test this one today?

rescue NoMethodError # TODO: remove with deleting AvailabilityMixin module
@error_message = @record.try(:is_available_now_error_message, @feature) if @error_message.nil?
rescue SupportsFeatureMixin::UnknownFeatureError # TODO: remove with deleting AvailabilityMixin module
@error_message = @record.try(:is_available_now_error_message, @feature)
end
rescue
Copy link
Member

Choose a reason for hiding this comment

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

  1. you should query the record if the feature is supported and if its not then query for the reason
  2. I think the second / nested rescue is too broad.
def disabled?
  @error_message = if @record.feature_known?(@feature)
   @record.unsupported_reason(@feature) unless @record.supports?(@feature)
  else
   @record.is_available_now_error_message(@feature)
  end
  @error_message.present?
end

I dont know if @error_message needs to be assigned during the disabled? method, that seems to me like a side effect, but its probably beyond this pr :)

Copy link
Member Author

Choose a reason for hiding this comment

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

@durandom Wow, I didn't know about feature_known?, thanks! 👍

@romanblanco romanblanco force-pushed the refactor_generic_button_with_disable_test branch 2 times, most recently from ea065fe to 78ff3f7 Compare September 29, 2016 15:14
@jzigmund
Copy link

@martinpovolny @romanblanco the power buttons are enabled, works as expected, ACK

@miq-bot
Copy link
Member

miq-bot commented Sep 29, 2016

<pr_mergeability_checker />This pull request is not mergeable. Please rebase and repush.

@romanblanco romanblanco force-pushed the refactor_generic_button_with_disable_test branch from 78ff3f7 to 8178c54 Compare September 30, 2016 11:23
@romanblanco romanblanco force-pushed the refactor_generic_button_with_disable_test branch from 8178c54 to bc2f2cb Compare September 30, 2016 14:24
@miq-bot
Copy link
Member

miq-bot commented Sep 30, 2016

Checked commits romanblanco/manageiq@682f363~...bc2f2cb with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1
2 files checked, 0 offenses detected
Everything looks good. 🏆

@martinpovolny martinpovolny merged commit 2892437 into ManageIQ:master Oct 3, 2016
@martinpovolny martinpovolny added this to the Sprint 47 Ending Oct 3, 2016 milestone Oct 3, 2016
@romanblanco romanblanco deleted the refactor_generic_button_with_disable_test branch October 3, 2016 14:01
@chessbyte
Copy link
Member

Euwe Backport conflict:

$ git cherry-pick -e -x -m 1  2892437 
error: could not apply 2892437... Merge pull request #11054 from romanblanco/refactor_generic_button_with_disable_test
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

$ git status
On branch euwe
Your branch is up-to-date with 'upstream/euwe'.
You are currently cherry-picking commit 2892437.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:

    modified:   app/helpers/application_helper/button/generic_feature_button_with_disable.rb

Unmerged paths:
  (use "git add <file>..." to mark resolution)

    both modified:   spec/helpers/application_helper/buttons/generic_feature_button_with_disable_spec.rb

$ git diff
diff --cc spec/helpers/application_helper/buttons/generic_feature_button_with_disable_spec.rb
index 4e4d7c9,dd59678..0000000
--- a/spec/helpers/application_helper/buttons/generic_feature_button_with_disable_spec.rb
+++ b/spec/helpers/application_helper/buttons/generic_feature_button_with_disable_spec.rb
@@@ -1,46 -1,31 +1,48 @@@
  describe ApplicationHelper::Button::GenericFeatureButtonWithDisable do
++<<<<<<< HEAD
 +  [:start, :stop, :suspend, :reset, :reboot_guest,
 +   :collect_running_processes, :shutdown_guest].each do |feature|
 +    describe '#visible?' do
 +      context "when vm supports feature #{feature}" do
 +        before do
 +          @record = FactoryGirl.create(:vm_vmware)
 +          allow(@record).to receive(:is_available?).with(feature).and_return(true)
 +        end
 +
 +        it "will not be skipped for this vm" do
 +          view_context = setup_view_context_with_sandbox({})
 +          button = described_class.new(view_context, {}, {'record' => @record}, {:options => {:feature => feature}})
 +          expect(button.visible?).to be_truthy
 +        end
++=======
+   describe '#disabled?' do
+     context "when record has an error message" do
+       it "disables the button and returns the stop error message" do
+         record = double
+         message = "xx stop message"
+         allow(record).to receive(:feature_known?).with(:some_feature).and_return(true)
+         allow(record).to receive(:supports?).with(:some_feature).and_return(false)
+         allow(record).to receive(:unsupported_reason).with(:some_feature).and_return(message)
+         view_context = setup_view_context_with_sandbox({})
+         button = described_class.new(view_context, {}, {'record' => record}, {:options => {:feature => :some_feature}})
+         expect(button.disabled?).to be_truthy
+         button.calculate_properties
+         expect(button[:title]).to eq(message)
++>>>>>>> 2892437... Merge pull request #11054 from romanblanco/refactor_generic_button_with_disable_test
        end

-       context "when instance does not support feature #{feature}" do
-         before do
-           @record = FactoryGirl.create(:vm_vmware)
-           allow(@record).to receive(:is_available?).with(feature).and_return(false)
-         end
- 
-         it "will be skipped for this vm" do
-           view_context = setup_view_context_with_sandbox({})
-           button = described_class.new(view_context, {}, {'record' => @record}, {:options => {:feature => feature}})
-           expect(button.visible?).to be_falsey
-         end
-       end
-     end
-     describe '#disabled?' do
-       context "when record has an error message" do
-         before do
-           @record = FactoryGirl.create(:vm_vmware)
-           message = "xx stop message"
-           allow(@record).to receive(:is_available_now_error_message).with(feature).and_return(message)
-         end
- 
-         it "disables the button and returns the stop error message" do
-           view_context = setup_view_context_with_sandbox({})
-           button = described_class.new(view_context, {}, {'record' => @record}, {:options => {:feature => feature}})
-           expect(button.disabled?).to be_truthy
-         end
+       it "disables the button and returns the stop error message" do
+         # TODO: remove with deleting AvailabilityMixin module
+         record = double
+         message = "xx stop message"
+         allow(record).to receive(:feature_known?).with(:some_feature).and_return(false)
+         allow(record).to receive(:is_available?).with(:some_feature).and_return(false)
+         allow(record).to receive(:is_available_now_error_message).with(:some_feature).and_return(message)
+         view_context = setup_view_context_with_sandbox({})
+         button = described_class.new(view_context, {}, {'record' => record}, {:options => {:feature => :some_feature}})
+         expect(button.disabled?).to be_truthy
+         button.calculate_properties
+         expect(button[:title]).to eq(message)
        end
      end
    end

@durandom
Copy link
Member

durandom commented Oct 5, 2016

@chessbyte once #11075 is backported this one should merge without conflict

chessbyte pushed a commit that referenced this pull request Oct 5, 2016
…th_disable_test

Correct disabling method and refactored test for it's class
(cherry picked from commit 2892437)
@chessbyte
Copy link
Member

Euwe Backport details:

$ git log
commit 71397f3a798731c3302cbb39504d26830b866192
Author: Martin Povolny <mpovolny@redhat.com>
Date:   Mon Oct 3 15:54:49 2016 +0200

    Merge pull request #11054 from romanblanco/refactor_generic_button_with_disable_test

    Correct disabling method and refactored test for it's class
    (cherry picked from commit 28924370cb82529cc0148cc3b483f38dcf32cc26)

carbonin added a commit to carbonin/manageiq that referenced this pull request Jan 7, 2020
This was a problem for the EventCatcher when sync_config was called
as a part of worker initialization. The EventCatcher uses its ems
hostname as a part of its log prefix, but the ems isn't set up until
after the first call to sync_config.

This was leading to errors when the worker was starting:
[----] I, [2019-12-19T17:51:48.407958 ManageIQ#11054:2ab1a6d9a5f8]  INFO -- : Starting ManageIQ::Providers::Vmware::InfraManager::EventCatcher with runner options {:ems_id=>"2", :guid=>"43a315ba-39ff-4326-99a6-89b3af48b1ee"}
[----] I, [2019-12-19T17:51:48.451836 ManageIQ#11054:2ab1a6d9a5f8]  INFO -- : Deleting worker record for ManageIQ::Providers::Vmware::InfraManager::EventCatcher, id 310
/home/ncarboni/Source/manageiq/app/models/manageiq/providers/base_manager/event_catcher/runner.rb:63:in `log_prefix': undefined method `hostname' for nil:NilClass (NoMethodError)
        from /home/ncarboni/Source/manageiq/app/models/miq_worker/runner.rb:242:in `sync_config'
        from /home/ncarboni/Source/manageiq/app/models/miq_worker/runner.rb:52:in `worker_initialization'
        from /home/ncarboni/Source/manageiq/app/models/miq_worker/runner.rb:42:in `initialize'
        from /home/ncarboni/Source/manageiq/lib/workers/bin/run_single_worker.rb:113:in `new'
        from /home/ncarboni/Source/manageiq/lib/workers/bin/run_single_worker.rb:113:in `<main>'
carbonin added a commit to carbonin/manageiq that referenced this pull request Jan 10, 2020
This was a problem for the EventCatcher when sync_config was called
as a part of worker initialization. The EventCatcher uses its ems
hostname as a part of its log prefix, but the ems isn't set up until
after the first call to sync_config.

This was leading to errors when the worker was starting:
[----] I, [2019-12-19T17:51:48.407958 ManageIQ#11054:2ab1a6d9a5f8]  INFO -- : Starting ManageIQ::Providers::Vmware::InfraManager::EventCatcher with runner options {:ems_id=>"2", :guid=>"43a315ba-39ff-4326-99a6-89b3af48b1ee"}
[----] I, [2019-12-19T17:51:48.451836 ManageIQ#11054:2ab1a6d9a5f8]  INFO -- : Deleting worker record for ManageIQ::Providers::Vmware::InfraManager::EventCatcher, id 310
/home/ncarboni/Source/manageiq/app/models/manageiq/providers/base_manager/event_catcher/runner.rb:63:in `log_prefix': undefined method `hostname' for nil:NilClass (NoMethodError)
        from /home/ncarboni/Source/manageiq/app/models/miq_worker/runner.rb:242:in `sync_config'
        from /home/ncarboni/Source/manageiq/app/models/miq_worker/runner.rb:52:in `worker_initialization'
        from /home/ncarboni/Source/manageiq/app/models/miq_worker/runner.rb:42:in `initialize'
        from /home/ncarboni/Source/manageiq/lib/workers/bin/run_single_worker.rb:113:in `new'
        from /home/ncarboni/Source/manageiq/lib/workers/bin/run_single_worker.rb:113:in `<main>'
aufi pushed a commit to aufi/manageiq that referenced this pull request Jan 29, 2020
This was a problem for the EventCatcher when sync_config was called
as a part of worker initialization. The EventCatcher uses its ems
hostname as a part of its log prefix, but the ems isn't set up until
after the first call to sync_config.

This was leading to errors when the worker was starting:
[----] I, [2019-12-19T17:51:48.407958 ManageIQ#11054:2ab1a6d9a5f8]  INFO -- : Starting ManageIQ::Providers::Vmware::InfraManager::EventCatcher with runner options {:ems_id=>"2", :guid=>"43a315ba-39ff-4326-99a6-89b3af48b1ee"}
[----] I, [2019-12-19T17:51:48.451836 ManageIQ#11054:2ab1a6d9a5f8]  INFO -- : Deleting worker record for ManageIQ::Providers::Vmware::InfraManager::EventCatcher, id 310
/home/ncarboni/Source/manageiq/app/models/manageiq/providers/base_manager/event_catcher/runner.rb:63:in `log_prefix': undefined method `hostname' for nil:NilClass (NoMethodError)
        from /home/ncarboni/Source/manageiq/app/models/miq_worker/runner.rb:242:in `sync_config'
        from /home/ncarboni/Source/manageiq/app/models/miq_worker/runner.rb:52:in `worker_initialization'
        from /home/ncarboni/Source/manageiq/app/models/miq_worker/runner.rb:42:in `initialize'
        from /home/ncarboni/Source/manageiq/lib/workers/bin/run_single_worker.rb:113:in `new'
        from /home/ncarboni/Source/manageiq/lib/workers/bin/run_single_worker.rb:113:in `<main>'
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