Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions resources/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@
description: 'Additional helper modules to include in the site template',
coerce: proc { |p| p.is_a?(Array) ? p : [p] }

def config_file
::File.join(conf_dir, "#{name}.conf")
Comment on lines +66 to +67
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract this to the helpers.rb

end

action_class do
include Nginx::Cookbook::ResourceHelpers

def config_file
::File.join(new_resource.conf_dir, "#{new_resource.name}.conf")
end

def config_file_disabled
"#{config_file}.disabled"
end
Expand Down
24 changes: 24 additions & 0 deletions spec/unit/resources/site_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,28 @@

it { is_expected.to delete_file('/etc/nginx/conf.http.d/default.conf') }
end

context 'config_file method accessibility' do
recipe do
nginx_install 'distro'

site = nginx_site 'test-site' do
conf_dir '/etc/nginx/sites-available'
action :create
end

# This tests the new functionality - accessing config_file on the resource instance
ruby_block 'test_config_file_access' do
block do
expected_path = '/etc/nginx/sites-available/test-site.conf'
actual_path = site.config_file
raise "Expected #{expected_path}, got #{actual_path}" unless actual_path == expected_path
end
action :run
end
end

it { is_expected.to create_template('/etc/nginx/sites-available/test-site.conf') }
it { is_expected.to run_ruby_block('test_config_file_access') }
end
end