Commit a85b85e1 authored by Matija Čupić's avatar Matija Čupić

Refactor .show_gke_cluster_integration_callout?

parent c1e1f807
......@@ -2,8 +2,8 @@ module UserCalloutsHelper
GKE_CLUSTER_INTEGRATION = 'gke_cluster_integration'.freeze
def show_gke_cluster_integration_callout?(project)
current_user && !user_dismissed?(GKE_CLUSTER_INTEGRATION) &&
can?(current_user, :create_cluster, project)
can?(current_user, :create_cluster, project) &&
!user_dismissed?(GKE_CLUSTER_INTEGRATION)
end
private
......
......@@ -12,28 +12,18 @@ describe UserCalloutsHelper do
subject { helper.show_gke_cluster_integration_callout?(project) }
context 'when user has not dismissed' do
before do
allow(helper).to receive(:user_dismissed?).and_return(false)
end
context 'when user can create a cluster' do
before do
allow(helper).to receive(:can?).with(anything, :create_cluster, anything)
.and_return(true)
end
it { is_expected.to be true }
end
context 'when user can not create a cluster' do
context 'when user has not dismissed' do
before do
allow(helper).to receive(:can?).with(anything, :create_cluster, anything)
.and_return(false)
allow(helper).to receive(:user_dismissed?).and_return(false)
end
it { is_expected.to be false }
end
it { is_expected.to be true }
end
context 'when user dismissed' do
......@@ -43,13 +33,15 @@ describe UserCalloutsHelper do
it { is_expected.to be false }
end
end
context 'when the user is not logged in' do
context 'when user can not create a cluster' do
before do
allow(helper).to receive(:current_user).and_return(nil)
allow(helper).to receive(:can?).with(anything, :create_cluster, anything)
.and_return(false)
end
it { is_expected.to be_falsey }
it { is_expected.to be false }
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment