Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz committed Dec 17, 2024
1 parent 5df20ca commit 1c101d6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/insights_cloud/settings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module InsightsCloud
class SettingsController < ::ApplicationController
def show
if SETTINGS[:insights][:use_insights_on_premise]
if ForemanRhCloud.with_insights_on_premise?
render json: {
error: _('This Foreman is configured to use Insights on Premise. Syncing to Insights Cloud is disabled.'),
}, status: :unprocessable_entity
Expand Down
6 changes: 5 additions & 1 deletion lib/foreman_rh_cloud/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def self.register_scheduled_task(task_class, cronline)
url: '/foreman_rh_cloud/inventory_upload',
url_hash: { controller: :react, action: :index },
parent: :configure_menu,
if: -> { !SETTINGS[:insights][:use_insights_on_premise] }
if: -> { !ForemanRhCloud.with_insights_on_premise? }
menu :top_menu, :insights_hits, caption: N_('Recommendations'), url: '/foreman_rh_cloud/insights_cloud', url_hash: { controller: :react, action: :index }, parent: :configure_menu

register_facet InsightsFacet, :insights do
Expand Down Expand Up @@ -199,4 +199,8 @@ def self.register_scheduled_task(task_class, cronline)
end
end
end

def self.with_insights_on_premise?
SETTINGS&.[](:insights)&.[](:use_insights_on_premise) || false
end
end
13 changes: 13 additions & 0 deletions test/controllers/insights_sync/settings_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

class SettingsControllerTest < ActionController::TestCase
tests InsightsCloud::SettingsController
def setup
ForemanRhCloud.stubs(:with_insights_on_premise?).returns(false)
end

test 'should return error if insights on premise' do
ForemanRhCloud.stubs(:with_insights_on_premise?).returns(true)

get :show, session: set_session_user

assert_response :unprocessable_entity
actual = JSON.parse(response.body)
assert_equal 'This Foreman is configured to use Insights on Premise. Syncing to Insights Cloud is disabled.', actual['error']
end

test 'should return allow_auto_insights_sync setting' do
Setting[:allow_auto_insights_sync] = false
Expand Down

0 comments on commit 1c101d6

Please sign in to comment.