Commit 538a8ecc authored by Sean Arnold's avatar Sean Arnold

Fix helper and add more specs

parent 90e14fc5
...@@ -22,8 +22,8 @@ module OperationsHelper ...@@ -22,8 +22,8 @@ module OperationsHelper
def status_page_settings_data(status_page_setting) def status_page_settings_data(status_page_setting)
{ {
'user-can-enable-status-page' => can?(current_user, :admin_operations, project).to_s, 'user-can-enable-status-page' => can?(current_user, :admin_operations, @project).to_s,
'setting-enabled' => status_page_setting&.enabled?, 'setting-enabled' => status_page_setting&.enabled?.to_s,
'setting-aws-access-key' => status_page_setting&.aws_access_key, 'setting-aws-access-key' => status_page_setting&.aws_access_key,
'setting-masked-aws-secret-key' => status_page_setting&.masked_aws_secret_key, 'setting-masked-aws-secret-key' => status_page_setting&.masked_aws_secret_key,
'setting-aws-region' => status_page_setting&.aws_region, 'setting-aws-region' => status_page_setting&.aws_region,
......
...@@ -4,10 +4,16 @@ require 'spec_helper' ...@@ -4,10 +4,16 @@ require 'spec_helper'
describe OperationsHelper do describe OperationsHelper do
describe '#status_page_settings_data' do describe '#status_page_settings_data' do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :private) }
subject { helper.status_page_settings_data(status_page_setting) } subject { helper.status_page_settings_data(status_page_setting) }
before do before do
allow(helper).to receive(:can?) { true } helper.instance_variable_set(:@project, project)
allow(helper).to receive(:current_user).and_return(user)
allow(helper)
.to receive(:can?).with(user, :admin_operations, project) { true }
end end
context 'setting does not exist' do context 'setting does not exist' do
...@@ -25,8 +31,19 @@ describe OperationsHelper do ...@@ -25,8 +31,19 @@ describe OperationsHelper do
) )
end end
it 'returns nil for the values' do it 'returns nil or true for the values' do
expect(subject.values.uniq).to contain_exactly(nil) expect(subject.values.uniq).to contain_exactly('true', nil)
end
context 'user does not have permission' do
before do
allow(helper)
.to receive(:can?).with(user, :admin_operations, project) { false }
end
it 'returns nil or true for the values' do
expect(subject.values.uniq).to contain_exactly('false', nil)
end
end end
end end
...@@ -35,6 +52,7 @@ describe OperationsHelper do ...@@ -35,6 +52,7 @@ describe OperationsHelper do
it 'returns the correct values' do it 'returns the correct values' do
aggregate_failures do aggregate_failures do
expect(subject['user-can-enable-status-page']).to eq('true')
expect(subject['setting-enabled']).to eq(status_page_setting.enabled) expect(subject['setting-enabled']).to eq(status_page_setting.enabled)
expect(subject['setting-aws-access-key']).to eq(status_page_setting.aws_access_key) expect(subject['setting-aws-access-key']).to eq(status_page_setting.aws_access_key)
expect(subject['setting-masked-aws-secret-key']).to eq(status_page_setting.masked_aws_secret_key) expect(subject['setting-masked-aws-secret-key']).to eq(status_page_setting.masked_aws_secret_key)
......
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