summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-10-28 20:52:28 -0700
committerJohn Keiser <john@johnkeiser.com>2015-10-28 20:52:28 -0700
commit571891bf67667d0240edd632c36fc84cd0fc8bbe (patch)
treeb7e9c4397a7b1c79789d3350f2407ebd25ded7ec
parentf01f65150cbc21e9a42f42c444d430320aa8ba5a (diff)
downloadchef-jk/custom_properties.tar.gz
Make Property.derive create derived properties of the same typejk/custom_properties
-rw-r--r--lib/chef/property.rb2
-rw-r--r--spec/unit/property_spec.rb48
2 files changed, 49 insertions, 1 deletions
diff --git a/lib/chef/property.rb b/lib/chef/property.rb
index e97d8f9607..3c40c020b6 100644
--- a/lib/chef/property.rb
+++ b/lib/chef/property.rb
@@ -431,7 +431,7 @@ class Chef
modified_options.has_key?(:default)
options = options.reject { |k,v| k == :name_attribute || k == :name_property || k == :default }
end
- Property.new(options.merge(modified_options))
+ self.class.new(options.merge(modified_options))
end
#
diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb
index dc06cb3326..095dcc8e98 100644
--- a/spec/unit/property_spec.rb
+++ b/spec/unit/property_spec.rb
@@ -1099,4 +1099,52 @@ describe "Chef::Resource.property" do
expect { resource_class.property :x, :name_property => true, :name_attribute => true }.to raise_error ArgumentError,
/Cannot specify both name_property and name_attribute together on property x of resource chef_resource_property_spec_(\d+)./
end
+
+ context "with a custom property type" do
+ class CustomPropertyType < Chef::Property
+ end
+
+ with_property ":x, CustomPropertyType.new" do
+ it "creates x with the given type" do
+ expect(resource_class.properties[:x]).to be_kind_of(CustomPropertyType)
+ end
+
+ context "and a subclass" do
+ let(:subresource_class) do
+ new_resource_name = self.class.new_resource_name
+ Class.new(resource_class) do
+ resource_name new_resource_name
+ end
+ end
+ let(:subresource) do
+ subresource_class.new('blah')
+ end
+
+ context "with property :x, default: 10 on the subclass" do
+ before do
+ subresource_class.class_eval do
+ property :x, default: 10
+ end
+ end
+
+ it "x has the given type and default on the subclass" do
+ expect(subresource_class.properties[:x]).to be_kind_of(CustomPropertyType)
+ expect(subresource_class.properties[:x].default).to eq(10)
+ end
+
+ it "x does not have the default on the superclass" do
+ expect(resource_class.properties[:x]).to be_kind_of(CustomPropertyType)
+ expect(resource_class.properties[:x].default).to be_nil
+ end
+ end
+ end
+ end
+
+ with_property ":x, CustomPropertyType.new, default: 10" do
+ it "passes the default to the custom property type" do
+ expect(resource_class.properties[:x]).to be_kind_of(CustomPropertyType)
+ expect(resource_class.properties[:x].default).to eq(10)
+ end
+ end
+ end
end