Permalink
Browse files

Fix update to scope that was defined with an enum (#281)

This is a non-issue with activesupport 5.0, but prior to that, when
check_scope is assigning the attributes hash, the assignment of an enum
is invalid and results in a value of 0 being assigned as the scope.
Assigning with the enum's setter instead.

Fixes #277
  • Loading branch information...
scottmalone authored and brendon committed Jun 14, 2017
1 parent 6d50054 commit 0adb6e806e1da03f1645e5aa251c40882d0a579d
Showing with 8 additions and 2 deletions.
  1. +2 −2 lib/acts_as_list/active_record/acts/list.rb
  2. +6 −0 test/test_list.rb
@@ -432,9 +432,9 @@ def check_scope
if internal_scope_changed?
cached_changes = changes
cached_changes.each { |attribute, values| self[attribute] = values[0] }
cached_changes.each { |attribute, values| send("#{attribute}=", values[0]) }
send('decrement_positions_on_lower_items') if lower_item
cached_changes.each { |attribute, values| self[attribute] = values[1] }
cached_changes.each { |attribute, values| send("#{attribute}=", values[1]) }
send("add_to_list_#{add_new_at}") if add_new_at.present?
end
View
@@ -641,6 +641,12 @@ def test_positions
assert_equal [1], EnumArrayScopeListMixin.where(:parent_id => 2, :state => EnumArrayScopeListMixin.states['active']).map(&:pos)
assert_equal [1], EnumArrayScopeListMixin.where(:parent_id => 2, :state => EnumArrayScopeListMixin.states['archived']).map(&:pos)
end
def test_update_state
active_item = EnumArrayScopeListMixin.find_by(:parent_id => 2, :state => EnumArrayScopeListMixin.states['active'])
active_item.update(state: EnumArrayScopeListMixin.states['archived'])
assert_equal [1, 2], EnumArrayScopeListMixin.where(:parent_id => 2, :state => EnumArrayScopeListMixin.states['archived']).map(&:pos).sort
end
end
end

0 comments on commit 0adb6e8

Please sign in to comment.