Commit 9199d30a authored by Matija Čupić's avatar Matija Čupić

Add can_toggle_cluster? helper

parent ce704a95
module ClustersHelper
def can_toggle_cluster?(cluster)
can?(current_user, :update_cluster, cluster) && cluster.created?
end
end
......@@ -13,7 +13,7 @@
.table-mobile-header{ role: "rowheader" }
.table-mobile-content
%button{ type: "button",
class: "js-toggle-cluster-list project-feature-toggle #{'is-checked' unless !cluster.enabled?} #{'is-disabled' unless can?(current_user, :update_cluster, cluster) && cluster.provider_gcp&.created?}",
class: "js-toggle-cluster-list project-feature-toggle #{'is-checked' if cluster.enabled?} #{'is-disabled' if can_toggle_cluster?(cluster)}",
"aria-label": s_("ClusterIntegration|Toggle Cluster"),
disabled: !can?(current_user, :update_cluster, cluster),
data: { "enabled-text": s_("ClusterIntegration|Active"),
......
require 'spec_helper'
describe ClustersHelper do
let(:cluster) { create(:cluster) }
describe '.can_toggle_cluster' do
let(:user) { create(:user) }
before do
allow(helper).to receive(:current_user).and_return(user)
end
subject { helper.can_toggle_cluster?(cluster) }
context 'when user can update' do
before do
allow(helper).to receive(:can?).with(any_args).and_return(true)
end
context 'when cluster is created' do
before do
allow(cluster).to receive(:created?).and_return(true)
end
it { is_expected.to eq(true) }
end
context 'when cluster is not created' do
before do
allow(cluster).to receive(:created?).and_return(false)
end
it { is_expected.to eq(false) }
end
end
context 'when user can not update' do
before do
allow(helper).to receive(:can?).with(any_args).and_return(false)
end
it { is_expected.to eq(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