Skip to content

Commit b0f2a4c

Browse files
committed
Add presence validation to AttribValue position
The position column is required in the database, but the model was missing the validation. This commit adds the validation to the model so the constraint is in sync.
1 parent c1dca97 commit b0f2a4c

File tree

5 files changed

+8
-5
lines changed

5 files changed

+8
-5
lines changed

src/api/.database_consistency.todo.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ AttribValue:
6363
id:
6464
PrimaryKeyTypeChecker:
6565
enabled: false
66-
position:
67-
NullConstraintChecker:
68-
enabled: false
6966
value:
7067
LengthConstraintChecker:
7168
enabled: false

src/api/app/controllers/source_attribute_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def update
6161
attrib_type = AttribType.find_by_namespace_and_name!(attr.value('namespace'), attr.value('name'))
6262
attrib = Attrib.new(attrib_type: attrib_type)
6363

64-
attr.elements('value') do |value|
65-
attrib.values.new(value: value)
64+
attr.elements('value').zip(attr.elements('position')).each do |(value, position)|
65+
attrib.values.new(value: value, position: position)
6666
end
6767

6868
attrib.container = @attribute_container

src/api/app/models/attrib_value.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ class AttribValue < ApplicationRecord
22
acts_as_list scope: :attrib
33
belongs_to :attrib, optional: false
44

5+
validates :position, presence: true
6+
57
after_initialize :set_default_value
68
before_validation :universal_newlines
79

src/api/spec/controllers/source_attribute_controller_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<<~XMLATTRIB
4848
<attributes>
4949
<attribute namespace='#{update_project_attrib.namespace}' name='#{update_project_attrib.name}'>
50+
<position>1</position>
5051
<value>1111112</value>
5152
</attribute>
5253
</attributes>

src/api/test/functional/request_controller_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3737,6 +3737,7 @@ def test_ordering_of_requests
37373737
login_king
37383738
post '/source/BaseDistro2.0/_attribute', params: "<attributes><attribute namespace='OBS' name='IncidentPriority' >
37393739
<value>100</value>
3740+
<position>1</position>
37403741
</attribute></attributes>"
37413742
assert_response :success
37423743
get '/search/request', params: { match: "target/@project = 'home:Iggy'" }
@@ -3749,6 +3750,7 @@ def test_ordering_of_requests
37493750
# make the low and important request equal high prio
37503751
post '/source/BaseDistro/_attribute', params: "<attributes><attribute namespace='OBS' name='IncidentPriority' >
37513752
<value>100</value>
3753+
<position>1</position>
37523754
</attribute></attributes>"
37533755
assert_response :success
37543756
get '/search/request', params: { match: "target/@project = 'home:Iggy'" }
@@ -3763,6 +3765,7 @@ def test_ordering_of_requests
37633765
# make the low most important
37643766
post '/source/BaseDistro/_attribute', params: "<attributes><attribute namespace='OBS' name='IncidentPriority' >
37653767
<value>101</value>
3768+
<position>1</position>
37663769
</attribute></attributes>"
37673770
assert_response :success
37683771
get '/search/request', params: { match: "target/@project = 'home:Iggy'" }

0 commit comments

Comments
 (0)