Skip to content

Commit

Permalink
Use given attribute value even if it's falsey
Browse files Browse the repository at this point in the history
Fixes #108
  • Loading branch information
sorah committed Mar 31, 2015
1 parent 26837d3 commit 764a729
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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

0 comments on commit 764a729

Please sign in to comment.