summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/resource.rb5
-rw-r--r--spec/unit/property/state_spec.rb15
2 files changed, 18 insertions, 2 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index ac6f5e8923..dca0033409 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -779,6 +779,7 @@ class Chef
def self.property(name, type=NOT_PASSED, **options)
name = name.to_sym
+ options[:instance_variable_name] = :"@#{name}" if !options.has_key?(:instance_variable_name)
options.merge!(name: name, declared_in: self)
if type == NOT_PASSED
@@ -1002,8 +1003,8 @@ class Chef
end
end
- # If state_attrs *excludes* something which is currently part of the
- # identity, mark it as identity: false.
+ # If identity_properties *excludes* something which is currently part of
+ # the identity, mark it as identity: false.
properties.each do |name,property|
if property.identity? && !names.include?(name)
self.property name, identity: false
diff --git a/spec/unit/property/state_spec.rb b/spec/unit/property/state_spec.rb
index bf2de178c9..e7fee0387f 100644
--- a/spec/unit/property/state_spec.rb
+++ b/spec/unit/property/state_spec.rb
@@ -369,6 +369,21 @@ describe "Chef::Resource#identity and #state" do
end
end
+ context "When state_properties happens before properties are declared" do
+ before do
+ resource_class.class_eval do
+ state_properties :x
+ property :x
+ end
+ end
+ it "the property works and is in state_properties" do
+ expect(resource_class.state_properties).to include(resource_class.properties[:x])
+ resource.x = 1
+ expect(resource.x).to eq 1
+ expect(resource.state_for_resource_reporter).to eq(x: 1)
+ end
+ end
+
with_property ":x, Integer, identity: true" do
it "state_properties(:x) leaves the property in desired_state" do
resource_class.state_properties(:x)