foreman_puppet 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,49 +9,88 @@ module ForemanPuppet
9
9
  include HostsAndHostgroupsHelper
10
10
 
11
11
  describe 'puppet environment field' do
12
+ let(:fields) { mock('fields_for') }
13
+ let(:f) { mock('form_for') }
14
+ let(:object) { mock('object') }
15
+ let(:puppet_facet) { mock('puppet') }
16
+
12
17
  setup do
13
- @host = mock('host')
14
- puppet = mock('puppet')
15
- @host.stubs(:hostgroup)
16
- @host.stubs(:puppet).returns(puppet)
17
- @host.stubs(:id).returns(999)
18
- @f = mock('f')
19
- @f.stubs(:object).returns(@host)
20
- @fields = mock('fields')
21
- @fields.stubs(:object).returns(puppet)
22
- @f.stubs(:fields_for).yields(@fields)
18
+ f.stubs(:object).returns(object)
19
+ f.stubs(:fields_for).yields(fields)
20
+ fields.stubs(:object).returns(puppet_facet)
23
21
  end
24
22
 
25
- test 'it adds new first level attributes' do
26
- @fields.expects(:collection_select).with do |*attrs|
27
- select_options, html_options = extract_collection_options(attrs)
28
- select_options[:test_select_option] == 'test_value1' &&
29
- html_options[:test_html_option] == 'test_value2'
23
+ describe '#host_puppet_environment_field' do
24
+ let(:object) do
25
+ host = mock('host')
26
+ host.stubs(:hostgroup)
27
+ host.stubs(:puppet).returns(puppet_facet)
28
+ host.stubs(:id).returns(999)
29
+ host
30
30
  end
31
31
 
32
- host_puppet_environment_field(@f, { test_select_option: 'test_value1' }, { test_html_option: 'test_value2' })
33
- end
32
+ test 'it adds new first level attributes' do
33
+ fields.expects(:collection_select).with do |*attrs|
34
+ select_options, html_options = extract_collection_options(attrs)
35
+ select_options[:test_select_option] == 'test_value1' &&
36
+ html_options[:test_html_option] == 'test_value2'
37
+ end
34
38
 
35
- test 'it adds new data attributes' do
36
- @fields.expects(:collection_select).with do |*attrs|
37
- select_options, html_options = extract_collection_options(attrs)
38
- select_options[:test_select_option] == 'test_value1' &&
39
- html_options[:data][:test] == 'test_value2'
39
+ host_puppet_environment_field(f, { test_select_option: 'test_value1' }, { test_html_option: 'test_value2' })
40
40
  end
41
41
 
42
- host_puppet_environment_field(@f, { test_select_option: 'test_value1' }, { data: { test: 'test_value2' } })
42
+ test 'it adds new data attributes' do
43
+ fields.expects(:collection_select).with do |*attrs|
44
+ select_options, html_options = extract_collection_options(attrs)
45
+ select_options[:test_select_option] == 'test_value1' &&
46
+ html_options[:data][:test] == 'test_value2'
47
+ end
48
+
49
+ host_puppet_environment_field(f, { test_select_option: 'test_value1' }, { data: { test: 'test_value2' } })
50
+ end
51
+
52
+ test 'it overrides existing attributes' do
53
+ fields.expects(:collection_select).with do |*attrs|
54
+ html_options = attrs.pop
55
+ html_options[:data][:test] == 'some_test_value' &&
56
+ html_options[:data][:url] == '/test/url'
57
+ end.returns('')
58
+
59
+ html = host_puppet_environment_field(f, { disable_button: false }, { data: { url: '/test/url', test: 'some_test_value' } })
60
+
61
+ assert_no_match(/btn/, html)
62
+ end
43
63
  end
44
64
 
45
- test 'it overrides existing attributes' do
46
- @fields.expects(:collection_select).with do |*attrs|
47
- html_options = attrs.pop
48
- html_options[:data][:test] == 'some_test_value' &&
49
- html_options[:data][:url] == '/test/url'
50
- end.returns('')
65
+ describe '#hostgroup_puppet_environment_field' do
66
+ let(:object) { FactoryBot.build_stubbed(:hostgroup, parent: parent_hg) }
67
+ let(:puppet_facet) { object.puppet || object.build_puppet }
68
+
69
+ context 'parent without puppet' do
70
+ let(:parent_hg) { FactoryBot.create(:hostgroup) }
51
71
 
52
- html = host_puppet_environment_field(@f, { disable_button: false }, { data: { url: '/test/url', test: 'some_test_value' } })
72
+ it 'shows Inherit option with no value' do
73
+ fields.expects(:collection_select).with do |*attrs|
74
+ options = attrs.second
75
+ options.first.to_label == 'Inherit parent (no value)'
76
+ end.returns('')
77
+
78
+ hostgroup_puppet_environment_field(f)
79
+ end
80
+ end
53
81
 
54
- assert_no_match(/btn/, html)
82
+ context 'parent with puppet' do
83
+ let(:parent_hg) { FactoryBot.create(:hostgroup, :with_puppet_enc) }
84
+
85
+ it 'shows Inherit option with no value' do
86
+ fields.expects(:collection_select).with do |*attrs|
87
+ options = attrs.second
88
+ options.first.to_label == "Inherit parent (#{parent_hg.puppet.environment.name})"
89
+ end.returns('')
90
+
91
+ hostgroup_puppet_environment_field(f)
92
+ end
93
+ end
55
94
  end
56
95
  end
57
96
 
@@ -107,7 +107,13 @@ module ForemanPuppet
107
107
  test 'should return empty array if host has no hostgroup' do
108
108
  host = FactoryBot.create(:host, :with_puppet_enc)
109
109
  assert_not host.hostgroup
110
- assert_empty host.puppet.parent_config_groups
110
+ assert_equal [], host.puppet.parent_config_groups
111
+ end
112
+
113
+ test 'should return empty array if hostgroup do not have puppet data' do
114
+ hostgroup = FactoryBot.create(:hostgroup)
115
+ host = FactoryBot.create(:host, :with_puppet_enc, hostgroup: hostgroup)
116
+ assert_equal [], host.puppet.parent_config_groups
111
117
  end
112
118
  end
113
119
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondřej Ezr
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-10-27 00:00:00.000000000 Z
12
+ date: 2021-11-15 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Allow assigning Puppet environmets and classes to the Foreman Hosts.
15
15
  email:
@@ -183,6 +183,7 @@ files:
183
183
  - db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb
184
184
  - db/migrate/20200803113903_migrate_host_type_in_host_config_groups.foreman_puppet.rb
185
185
  - db/migrate/20201125113903_migrate_puppetclasses_to_facets.foreman_puppet.rb
186
+ - db/migrate/20211112130803_cleanup_environment_from_core_tables.foreman_puppet.rb
186
187
  - db/migrate_foreman/20090722141107_create_environments.rb
187
188
  - db/migrate_foreman/20120905095532_create_environment_classes.rb
188
189
  - db/migrate_foreman/20140407161817_create_config_groups.rb
@@ -201,6 +202,8 @@ files:
201
202
  - lib/tasks/foreman_puppet_tasks.rake
202
203
  - locale/Makefile
203
204
  - locale/action_names.rb
205
+ - locale/cs_CZ/foreman_puppet.edit.po
206
+ - locale/cs_CZ/foreman_puppet.po.time_stamp
204
207
  - locale/en/LC_MESSAGES/foreman_puppet.mo
205
208
  - locale/en/foreman_puppet.edit.po
206
209
  - locale/en/foreman_puppet.po