Skip to content

Commit

Permalink
[api] Allow to resort attribute values
Browse files Browse the repository at this point in the history
update_with_associations ignored values that were the same
after sorting, but this makes manual resorting impossible
  • Loading branch information
coolo committed Jun 26, 2018
1 parent 5e73c20 commit f392f32
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/api/app/models/attrib.rb
Expand Up @@ -96,7 +96,7 @@ def update_with_associations(values = [], issues = [])
end

#--- update values ---#
if values.sort != self.values.map(&:value).sort
if values != self.values.map(&:value)
logger.debug "Attrib.update_with_associations: Values for #{fullname} changed, updating."
will_save = true
self.values.delete_all
Expand Down
12 changes: 12 additions & 0 deletions src/api/spec/models/attrib_spec.rb
Expand Up @@ -101,6 +101,18 @@
it { expect(subject).to be true }
it { expect { subject }.to change { attribute.values.count }.by(1) }
end

context 'values list' do
let(:values1) { ['blue', 'green'] }
let(:values2) { ['green', 'blue'] }

it 'resorts attribute values' do
expect(attribute.update_with_associations(values1, [])).to be true
expect(attribute.values.map(&:value)).to eq(values1)
expect(attribute.update_with_associations(values2, [])).to be true
expect(attribute.values.map(&:value)).to eq(values2)
end
end
end
end

Expand Down

0 comments on commit f392f32

Please sign in to comment.