Refactor .show_gke_cluster_integration_callout?

This commit is contained in:
Matija Čupić 2018-02-05 14:33:49 +01:00
parent c1e1f8070b
commit a85b85e1d8
No known key found for this signature in database
GPG Key ID: 4BAF84FFACD2E5DE
2 changed files with 12 additions and 20 deletions

View File

@ -2,8 +2,8 @@ module UserCalloutsHelper
GKE_CLUSTER_INTEGRATION = 'gke_cluster_integration'.freeze GKE_CLUSTER_INTEGRATION = 'gke_cluster_integration'.freeze
def show_gke_cluster_integration_callout?(project) 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 end
private private

View File

@ -12,20 +12,29 @@ describe UserCalloutsHelper do
subject { helper.show_gke_cluster_integration_callout?(project) } 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 context 'when user can create a cluster' do
before do before do
allow(helper).to receive(:can?).with(anything, :create_cluster, anything) allow(helper).to receive(:can?).with(anything, :create_cluster, anything)
.and_return(true) .and_return(true)
end end
context 'when user has not dismissed' do
before do
allow(helper).to receive(:user_dismissed?).and_return(false)
end
it { is_expected.to be true } it { is_expected.to be true }
end end
context 'when user dismissed' do
before do
allow(helper).to receive(:user_dismissed?).and_return(true)
end
it { is_expected.to be false }
end
end
context 'when user can not create a cluster' do context 'when user can not create a cluster' do
before do before do
allow(helper).to receive(:can?).with(anything, :create_cluster, anything) allow(helper).to receive(:can?).with(anything, :create_cluster, anything)
@ -35,21 +44,4 @@ describe UserCalloutsHelper do
it { is_expected.to be false } it { is_expected.to be false }
end end
end end
context 'when user dismissed' do
before do
allow(helper).to receive(:user_dismissed?).and_return(true)
end
it { is_expected.to be false }
end
context 'when the user is not logged in' do
before do
allow(helper).to receive(:current_user).and_return(nil)
end
it { is_expected.to be_falsey }
end
end
end end