summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/property.rb9
-rw-r--r--spec/unit/property_spec.rb15
2 files changed, 22 insertions, 2 deletions
diff --git a/lib/chef/property.rb b/lib/chef/property.rb
index 437ee10147..68d9b80103 100644
--- a/lib/chef/property.rb
+++ b/lib/chef/property.rb
@@ -129,7 +129,7 @@ class Chef
end
def to_s
- "#{name}#{declared_in ? " of resource #{declared_in.resource_name}" : ""}"
+ "#{name || "<property type>"}#{declared_in ? " of resource #{declared_in.resource_name}" : ""}"
end
#
@@ -463,7 +463,12 @@ class Chef
def validate(resource, value)
# If we have no default value, `nil` is never coerced or validated
unless value.nil? && !has_default?
- (resource || Chef::Mixin::ParamsValidate).validate({ name => value }, { name => validation_options })
+ if resource
+ resource.validate({ name => value }, { name => validation_options })
+ else
+ name = self.name || :property_type
+ (resource || Chef::Mixin::ParamsValidate).validate({ name => value }, { name => validation_options })
+ end
end
end
diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb
index ffdbccf019..2ff266f0ca 100644
--- a/spec/unit/property_spec.rb
+++ b/spec/unit/property_spec.rb
@@ -1096,6 +1096,21 @@ describe "Chef::Resource.property" do
/Cannot specify both name_property and name_attribute together on property x of resource chef_resource_property_spec_(\d+)./
end
+ it "property_types validate their defaults" do
+ expect {
+ module PropertySpecPropertyTypes
+ include Chef::Mixin::Properties
+ property_type(is: [:a, :b], default: :c)
+ end
+ }.to raise_error(Chef::Exceptions::DeprecatedFeatureError, /Default value :c is invalid for property <property type>./)
+ expect {
+ module PropertySpecPropertyTypes
+ include Chef::Mixin::Properties
+ property_type(is: [:a, :b], default: :b)
+ end
+ }.not_to raise_error
+ end
+
context "with a custom property type" do
class CustomPropertyType < Chef::Property
end