Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use given attribute value even if it's falsey #117

Merged
merged 1 commit into from
Mar 31, 2015
Merged
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
2 changes: 1 addition & 1 deletion lib/itamae/resource/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def show_differences
def process_attributes
self.class.defined_attributes.each_pair do |key, details|
@attributes[key] ||= @resource_name if details[:default_name]
@attributes[key] ||= details[:default] if details[:default]
@attributes[key] = details[:default] if details.has_key?(:default) && !@attributes.has_key?(key)

if details[:required] && !@attributes[key]
raise Resource::AttributeMissingError, "'#{key}' attribute is required but it is not set."
Expand Down
12 changes: 12 additions & 0 deletions spec/unit/lib/itamae/resource/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ class DefineAttributeTestResource < Itamae::Resource::Base
end
end

describe "falsey" do
subject do
described_class.new(double(:recipe), 'resource name') do
required_attribute :required_value
default_attribute nil
end
end
it "returns the default value" do
expect(subject.attributes[:default_attribute]).to eq(nil)
end
end

describe "required" do
subject do
described_class.new(double(:recipe), 'resource name') do
Expand Down