Skip to content

Commit

Permalink
Merge pull request #4239 from ChrisBr/28/bugfix/attributes
Browse files Browse the repository at this point in the history
[api] Fix attribute creation
  • Loading branch information
DavidKang committed Dec 19, 2017
2 parents 947d514 + 83d3fef commit fb13c8d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ReleaseNotes-2.8.5
Expand Up @@ -19,4 +19,4 @@ Changes:
Bugfixes:
=========

*
* Fix Attribute creation via API
2 changes: 1 addition & 1 deletion src/api/app/mixins/has_attributes.rb
Expand Up @@ -52,7 +52,7 @@ def store_attribute(namespace, name, values, issues, binary = nil)
a.package = self if is_a? Package
if a.attrib_type.value_count
a.attrib_type.value_count.times do |i|
a.values.build(position: i, value: "")
a.values.build(position: i, value: values[i])
end
end
if a.save
Expand Down
30 changes: 30 additions & 0 deletions src/api/test/functional/attributes_test.rb
Expand Up @@ -131,6 +131,36 @@ def test_create_type
assert_response :success
get "/attribute/TEST/Dummy/_meta"
assert_response :success
# use it
attrib_data = "<attributes>
<attribute namespace='TEST' name='Dummy' >
<value>M</value>
<value>A</value>
</attribute>
</attributes>"
post "/source/home:adrian/_attribute", params: attrib_data
assert_response 400
assert_match(/Values Value ('|")M('|") is not allowed./, @response.body)
get "/source/home:adrian/_attribute"
assert_response :success
attrib_data = "<attributes>
<attribute namespace='TEST' name='Dummy' >
<value>A</value>
<value>B</value>
</attribute>
</attributes>"
post "/source/home:adrian/_attribute", params: attrib_data

assert_response :success
get "/source/home:adrian/_attribute"
assert_response :success
assert_xml_tag tag: 'value', content: "A"
assert_xml_tag tag: 'value', content: "B"
# cleanup
login_Iggy
delete "/attribute/TEST/Dummy/_meta"
assert_response 403
login_adrian
delete "/attribute/TEST/Dummy"
assert_response :success
get "/attribute/TEST/Dummy/_meta"
Expand Down

0 comments on commit fb13c8d

Please sign in to comment.