You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ruby 2.7.2 RHEL7 (but this bug seem agnostic to ruby/OS version)
Scenario:
Create a new object derived from Artifactory::Resource::Base that has some attributes defined (e.g. PermssionTarget), and modify that object's attribute values. When creating a new object of the same type, the default attribute values are now the same as the first object.
Steps to Reproduce:
Example rspec tests:
require'rspec'require'artifactory'describeArtifactory::Resource::PermissionTargetdoit'does not modify default attribute principals'doa=Artifactory::Resource::PermissionTarget.newa.users['user_a']=%w[read]b=Artifactory::Resource::PermissionTarget.newexpect(b.users).toeq({})endit'does not modify default attribute includes_pattern'doa=Artifactory::Resource::PermissionTarget.newtmp=a.includes_patterntmp.gsub!(/\*\*/,'new_pattern')b=Artifactory::Resource::PermissionTarget.newexpect(b.includes_pattern).toeq('**')endit'does not modify default attribute excludes_pattern'doa=Artifactory::Resource::PermissionTarget.newtmp=a.excludes_patterntmp.replace'new_pattern'b=Artifactory::Resource::PermissionTarget.newexpect(b.excludes_pattern).toeq('')endend
Expected Result:
I expect those rspec tests to pass.
Actual Result:
>rspec 'tests/artifactory_test.rb'FFFFailures: 1) Artifactory::Resource::PermissionTarget does not modify default attribute principals Failure/Error: expect(b.users).to eq({}) expected: {} got: {"user_a"=>["read"]} (compared using ==) Diff: @@ -1 +1,2 @@ +"user_a" => ["read"], # ./tests/artifactory_test.rb:12:in `block (2 levels) in <top (required)>' 2) Artifactory::Resource::PermissionTarget does not modify default attribute includes_pattern Failure/Error: expect(b.includes_pattern).to eq('**') expected: "**" got: "new_pattern" (compared using ==) # ./tests/artifactory_test.rb:20:in `block (2 levels) in <top (required)>' 3) Artifactory::Resource::PermissionTarget does not modify default attribute excludes_pattern Failure/Error: expect(b.excludes_pattern).to eq('') expected: "" got: "new_pattern" (compared using ==) # ./tests/artifactory_test.rb:28:in `block (2 levels) in <top (required)>'Finished in 0.02337 seconds (files took 0.24672 seconds to load)3 examples, 3 failuresFailed examples:rspec ./tests/artifactory_test.rb:8 # Artifactory::Resource::PermissionTarget does not modify default attribute principalsrspec ./tests/artifactory_test.rb:15 # Artifactory::Resource::PermissionTarget does not modify default attribute includes_patternrspec ./tests/artifactory_test.rb:23 # Artifactory::Resource::PermissionTarget does not modify default attribute excludes_pattern
The text was updated successfully, but these errors were encountered:
Either freeze them, in the case of Strings or empty Hash/Array,
or call a proc to return a unique instance of a mutable object
(mostly relevant for the 'principals' attribute of PermissionTarget).
Receiving a FrozenError in this case may be unexpected for users,
but it will force them into the preferred method of setting attributes
(i.e. using the "#{name}=" setter).
Fixes issue chef#174.
mblythe86
added a commit
to mblythe86/artifactory-client
that referenced
this issue
Nov 26, 2024
Either freeze them, in the case of Strings or empty Hash/Array,
or call a proc to return a unique instance of a mutable object
(mostly relevant for the 'principals' attribute of PermissionTarget).
Receiving a FrozenError in this case may be unexpected for users,
but it will force them into the preferred method of setting attributes
(i.e. using the "#{name}=" setter).
Fixes issue chef#174.
Signed-off-by: Matthew Blythe <[email protected]>
Version:
Artifactory gem version 3.0.17
Environment:
ruby 2.7.2 RHEL7 (but this bug seem agnostic to ruby/OS version)
Scenario:
Create a new object derived from
Artifactory::Resource::Base
that has someattribute
s defined (e.g.PermssionTarget
), and modify that object's attribute values. When creating a new object of the same type, the default attribute values are now the same as the first object.Steps to Reproduce:
Example
rspec
tests:Expected Result:
I expect those
rspec
tests to pass.Actual Result:
The text was updated successfully, but these errors were encountered: