diff options
| author | Brice Figureau <brice-puppet@daysofwonder.com> | 2009-03-13 23:30:03 +0100 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2009-05-02 09:08:42 +1000 |
| commit | d51d87e1f04b643f4efb5c6453a2c1fc9a1ca8e5 (patch) | |
| tree | 108e00dc3263ed3101e40f034e1c229cb7ccf467 /spec/unit | |
| parent | a1c0ae0fe3c4bef6f21240c4d0a8da985cc7c8af (diff) | |
| download | puppet-d51d87e1f04b643f4efb5c6453a2c1fc9a1ca8e5.tar.gz puppet-d51d87e1f04b643f4efb5c6453a2c1fc9a1ca8e5.tar.xz puppet-d51d87e1f04b643f4efb5c6453a2c1fc9a1ca8e5.zip | |
Add an unmunge capability to type parameters and properties
Unmunge is the reverse of munge.
While munge allows the type to return a different parameter value
or properties should than the one it was created with, unmunge
does the reverse.
It can be used for instance to store a value in a different
representation but still be able to return genuine value to the
outside world.
Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'spec/unit')
| -rwxr-xr-x | spec/unit/parameter.rb | 10 | ||||
| -rwxr-xr-x | spec/unit/property.rb | 16 |
2 files changed, 26 insertions, 0 deletions
diff --git a/spec/unit/parameter.rb b/spec/unit/parameter.rb index 94f5cfd7b..42d3103bd 100755 --- a/spec/unit/parameter.rb +++ b/spec/unit/parameter.rb @@ -46,6 +46,16 @@ describe Puppet::Parameter do @parameter.value.should == "bar" end + it "should unmunge the value when accessing the actual value" do + @parameter.class.unmunge do |value| value.to_sym end + @parameter.value = "foo" + @parameter.value.should == :foo + end + + it "should return the actual value by default when unmunging" do + @parameter.unmunge("bar").should == "bar" + end + it "should return any set value" do @parameter.value = "foo" @parameter.value.should == "foo" diff --git a/spec/unit/property.rb b/spec/unit/property.rb index e2ba83303..f09549ddc 100755 --- a/spec/unit/property.rb +++ b/spec/unit/property.rb @@ -129,6 +129,22 @@ describe Puppet::Property do it "should default to :first array_matching" do @class.array_matching.should == :first end + + it "should unmunge the returned value if :array_matching is set to :first" do + @property.class.unmunge do |v| v.to_sym end + @class.array_matching = :first + @property.should = %w{one two} + + @property.should.must == :one + end + + it "should unmunge all the returned values if :array_matching is set to :all" do + @property.class.unmunge do |v| v.to_sym end + @class.array_matching = :all + @property.should = %w{one two} + + @property.should.must == [:one, :two] + end end describe "when validating values" do |
