Project

General

Profile

« Previous | Next » 

Revision 8bd7e408

Added by Dominic Cleal over 8 years ago

fixes #11945 - fix undefined variable in param_true/false helpers

(cherry picked from commit b0de0f653e481cd9ae049c846cc66906c1347e8e)

View differences:

app/models/concerns/host_common.rb
end
def param_true?(name)
params.has_key?(name) && Foreman::Cast.to_bool(value)
params.has_key?(name) && Foreman::Cast.to_bool(params[name])
end
def param_false?(name)
params.has_key?(name) && Foreman::Cast.to_bool(value) == false
params.has_key?(name) && Foreman::Cast.to_bool(params[name]) == false
end
def cg_class_ids
test/unit/host_test.rb
end
end
describe '#param_true?' do
test 'returns false for unknown parameter' do
Foreman::Cast.expects(:to_bool).never
refute FactoryGirl.build(:host).param_true?('unknown')
end
test 'returns false for parameter with false-like value' do
Foreman::Cast.expects(:to_bool).with('0').returns(false)
host = FactoryGirl.create(:host)
FactoryGirl.create(:host_parameter, :host => host, :name => 'host_param', :value => '0')
refute host.reload.param_true?('host_param')
end
test 'returns true for parameter with true-like value' do
Foreman::Cast.expects(:to_bool).with('1').returns(true)
host = FactoryGirl.create(:host)
FactoryGirl.create(:host_parameter, :host => host, :name => 'host_param', :value => '1')
assert host.reload.param_true?('host_param')
end
test 'uses inherited parameters' do
Foreman::Cast.expects(:to_bool).with('1').returns(true)
host = FactoryGirl.create(:host, :with_hostgroup)
FactoryGirl.create(:hostgroup_parameter, :hostgroup => host.hostgroup, :name => 'group_param', :value => '1')
assert host.reload.param_true?('group_param')
end
end
describe '#param_false?' do
test 'returns false for unknown parameter' do
Foreman::Cast.expects(:to_bool).never
refute FactoryGirl.build(:host).param_false?('unknown')
end
test 'returns true for parameter with false-like value' do
Foreman::Cast.expects(:to_bool).with('0').returns(false)
host = FactoryGirl.create(:host)
FactoryGirl.create(:host_parameter, :host => host, :name => 'host_param', :value => '0')
assert host.reload.param_false?('host_param')
end
test 'returns false for parameter with true-like value' do
Foreman::Cast.expects(:to_bool).with('1').returns(true)
host = FactoryGirl.create(:host)
FactoryGirl.create(:host_parameter, :host => host, :name => 'host_param', :value => '1')
refute host.reload.param_false?('host_param')
end
test 'uses inherited parameters' do
Foreman::Cast.expects(:to_bool).with('0').returns(false)
host = FactoryGirl.create(:host, :with_hostgroup)
FactoryGirl.create(:hostgroup_parameter, :hostgroup => host.hostgroup, :name => 'group_param', :value => '0')
assert host.reload.param_false?('group_param')
end
end
private
def parse_json_fixture(relative_path)
test/unit/hostgroup_test.rb
assert_equal cloned.lookup_values.map(&:value), group.lookup_values.map(&:value)
end
end
describe '#param_true?' do
test 'returns false for unknown parameter' do
Foreman::Cast.expects(:to_bool).never
refute FactoryGirl.build(:hostgroup).param_true?('unknown')
end
test 'returns false for parameter with false-like value' do
Foreman::Cast.expects(:to_bool).with('0').returns(false)
group = FactoryGirl.create(:hostgroup)
FactoryGirl.create(:hostgroup_parameter, :hostgroup => group, :name => 'group_param', :value => '0')
refute group.reload.param_true?('group_param')
end
test 'returns true for parameter with true-like value' do
Foreman::Cast.expects(:to_bool).with('1').returns(true)
group = FactoryGirl.create(:hostgroup)
FactoryGirl.create(:hostgroup_parameter, :hostgroup => group, :name => 'group_param', :value => '1')
assert group.reload.param_true?('group_param')
end
test 'uses inherited parameters' do
Foreman::Cast.expects(:to_bool).with('1').returns(true)
group = FactoryGirl.create(:hostgroup, :with_parent)
FactoryGirl.create(:hostgroup_parameter, :hostgroup => group.parent, :name => 'group_param', :value => '1')
assert group.reload.param_true?('group_param')
end
end
describe '#param_false?' do
test 'returns false for unknown parameter' do
Foreman::Cast.expects(:to_bool).never
refute FactoryGirl.build(:hostgroup).param_false?('unknown')
end
test 'returns true for parameter with false-like value' do
Foreman::Cast.expects(:to_bool).with('0').returns(false)
group = FactoryGirl.create(:hostgroup)
FactoryGirl.create(:hostgroup_parameter, :hostgroup => group, :name => 'group_param', :value => '0')
assert group.reload.param_false?('group_param')
end
test 'returns false for parameter with true-like value' do
Foreman::Cast.expects(:to_bool).with('1').returns(true)
group = FactoryGirl.create(:hostgroup)
FactoryGirl.create(:hostgroup_parameter, :hostgroup => group, :name => 'group_param', :value => '1')
refute group.reload.param_false?('group_param')
end
test 'uses inherited parameters' do
Foreman::Cast.expects(:to_bool).with('0').returns(false)
group = FactoryGirl.create(:hostgroup, :with_parent)
FactoryGirl.create(:hostgroup_parameter, :hostgroup => group.parent, :name => 'group_param', :value => '0')
assert group.reload.param_false?('group_param')
end
end
end

Also available in: Unified diff