acts_as_list 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile +1 -7
- data/gemfiles/rails_3_2.gemfile +0 -6
- data/gemfiles/rails_4_2.gemfile +0 -6
- data/gemfiles/rails_5_0.gemfile +0 -6
- data/lib/acts_as_list/active_record/acts/list.rb +60 -60
- data/lib/acts_as_list/version.rb +1 -1
- data/test/test_list.rb +25 -25
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a58bb02b59b9251aa9959060342f81fe5aa83467
|
4
|
+
data.tar.gz: 6b8f6ba9c5f16cbe5a93cacb754b721b3dd40b56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c25e5a32b9def627747a36a7fe4e232ae946b3cde83039c4a893dfc4e8469808fc6ceefac353b4f6bd5e251eb6b0d28df3b00a0d8c69b7b2b1c96ce81eafb42
|
7
|
+
data.tar.gz: 1494350922d065eab1cf1bd0309b56a9a0246055a0eb61f45401682f3f7fa21060ac8367b138a2e29644ba24de838864061a176d2e89711a676c76469d6e897a
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [v0.8.0](https://github.com/swanandp/acts_as_list/tree/v0.8.0) (2016-08-23)
|
4
|
+
[Full Changelog](https://github.com/swanandp/acts_as_list/compare/v0.7.7...v0.8.0)
|
5
|
+
|
6
|
+
**Closed issues:**
|
7
|
+
|
8
|
+
- Behavior with DB default seems unclear [\#219](https://github.com/swanandp/acts_as_list/issues/219)
|
9
|
+
|
10
|
+
**Merged pull requests:**
|
11
|
+
|
12
|
+
- No longer a need specify additional rbx gems [\#225](https://github.com/swanandp/acts_as_list/pull/225) ([brendon](https://github.com/brendon))
|
13
|
+
- Fix position when no serial positions [\#223](https://github.com/swanandp/acts_as_list/pull/223) ([jpalumickas](https://github.com/jpalumickas))
|
14
|
+
- Bug: Specifying a position with add\_new\_at: :top fails to insert at that position [\#220](https://github.com/swanandp/acts_as_list/pull/220) ([brendon](https://github.com/brendon))
|
15
|
+
|
3
16
|
## [v0.7.7](https://github.com/swanandp/acts_as_list/tree/v0.7.7) (2016-08-18)
|
4
17
|
[Full Changelog](https://github.com/swanandp/acts_as_list/compare/v0.7.6...v0.7.7)
|
5
18
|
|
@@ -70,6 +83,7 @@
|
|
70
83
|
|
71
84
|
**Merged pull requests:**
|
72
85
|
|
86
|
+
- Fix position when no serial positions [\#208](https://github.com/swanandp/acts_as_list/pull/208) ([PoslinskiNet](https://github.com/PoslinskiNet))
|
73
87
|
- Removed duplicated assignment [\#207](https://github.com/swanandp/acts_as_list/pull/207) ([shunwen](https://github.com/shunwen))
|
74
88
|
- Quote all identifiers [\#205](https://github.com/swanandp/acts_as_list/pull/205) ([fabn](https://github.com/fabn))
|
75
89
|
- Start testing Rails 5 [\#203](https://github.com/swanandp/acts_as_list/pull/203) ([brendon](https://github.com/brendon))
|
data/Gemfile
CHANGED
@@ -3,12 +3,6 @@ source "http://rubygems.org"
|
|
3
3
|
gem "sqlite3", platforms: [:ruby]
|
4
4
|
gem "activerecord-jdbcsqlite3-adapter", platforms: [:jruby]
|
5
5
|
|
6
|
-
platforms :rbx do
|
7
|
-
gem "rubysl", "~> 2.0"
|
8
|
-
gem "rubinius-developer_tools"
|
9
|
-
gem "rubysl-test-unit"
|
10
|
-
end
|
11
|
-
|
12
6
|
gem "rack", "~> 1", platforms: [:ruby_19, :ruby_20, :ruby_21, :jruby]
|
13
7
|
|
14
8
|
gemspec
|
@@ -18,6 +12,6 @@ gem "appraisal"
|
|
18
12
|
gem "github_changelog_generator", "1.9.0"
|
19
13
|
|
20
14
|
group :test do
|
21
|
-
|
15
|
+
gem "minitest", "~> 5.0"
|
22
16
|
gem "test_after_commit", "~> 0.4.2"
|
23
17
|
end
|
data/gemfiles/rails_3_2.gemfile
CHANGED
data/gemfiles/rails_4_2.gemfile
CHANGED
data/gemfiles/rails_5_0.gemfile
CHANGED
@@ -42,102 +42,102 @@ module ActiveRecord
|
|
42
42
|
configuration[:scope] = :"#{configuration[:scope]}_id"
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
|
-
scope_methods = %(
|
47
|
-
def scope_condition
|
48
|
-
{ #{configuration[:scope]}: send(:#{configuration[:scope]}) }
|
49
|
-
end
|
50
|
-
|
51
|
-
def scope_changed?
|
52
|
-
changed.include?(scope_name.to_s)
|
53
|
-
end
|
54
|
-
)
|
55
|
-
elsif configuration[:scope].is_a?(Array)
|
56
|
-
scope_methods = %(
|
57
|
-
def scope_condition
|
58
|
-
#{configuration[:scope]}.inject({}) do |hash, column|
|
59
|
-
hash.merge!({ column.to_sym => read_attribute(column.to_sym) })
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def scope_changed?
|
64
|
-
(scope_condition.keys & changed.map(&:to_sym)).any?
|
65
|
-
end
|
66
|
-
)
|
67
|
-
else
|
68
|
-
scope_methods = %(
|
69
|
-
def scope_condition
|
70
|
-
"#{configuration[:scope]}"
|
71
|
-
end
|
72
|
-
|
73
|
-
def scope_changed?() false end
|
74
|
-
)
|
75
|
-
end
|
76
|
-
|
77
|
-
quoted_position_column = connection.quote_column_name(configuration[:column])
|
78
|
-
quoted_position_column_with_table_name = "#{quoted_table_name}.#{quoted_position_column}"
|
45
|
+
caller_class = self
|
79
46
|
|
80
|
-
class_eval
|
81
|
-
|
82
|
-
|
47
|
+
class_eval do
|
48
|
+
define_singleton_method :acts_as_list_top do
|
49
|
+
configuration[:top_of_list].to_i
|
83
50
|
end
|
84
51
|
|
85
|
-
|
86
|
-
|
52
|
+
define_method :acts_as_list_top do
|
53
|
+
configuration[:top_of_list].to_i
|
87
54
|
end
|
88
55
|
|
89
|
-
|
90
|
-
|
56
|
+
define_method :acts_as_list_class do
|
57
|
+
caller_class
|
91
58
|
end
|
92
59
|
|
93
|
-
|
94
|
-
|
60
|
+
define_method :position_column do
|
61
|
+
configuration[:column]
|
95
62
|
end
|
96
63
|
|
97
|
-
|
98
|
-
|
64
|
+
define_method :scope_name do
|
65
|
+
configuration[:scope]
|
99
66
|
end
|
100
67
|
|
101
|
-
|
102
|
-
|
68
|
+
define_method :add_new_at do
|
69
|
+
configuration[:add_new_at]
|
103
70
|
end
|
104
71
|
|
105
|
-
|
106
|
-
write_attribute(
|
72
|
+
define_method :"#{configuration[:column]}=" do |position|
|
73
|
+
write_attribute(configuration[:column], position)
|
107
74
|
@position_changed = true
|
108
75
|
end
|
109
76
|
|
110
|
-
|
77
|
+
if configuration[:scope].is_a?(Symbol)
|
78
|
+
define_method :scope_condition do
|
79
|
+
{ configuration[:scope] => send(:"#{configuration[:scope]}") }
|
80
|
+
end
|
81
|
+
|
82
|
+
define_method :scope_changed? do
|
83
|
+
changed.include?(scope_name.to_s)
|
84
|
+
end
|
85
|
+
elsif configuration[:scope].is_a?(Array)
|
86
|
+
define_method :scope_condition do
|
87
|
+
configuration[:scope].inject({}) do |hash, column|
|
88
|
+
hash.merge!({ column.to_sym => read_attribute(column.to_sym) })
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
define_method :scope_changed? do
|
93
|
+
(scope_condition.keys & changed.map(&:to_sym)).any?
|
94
|
+
end
|
95
|
+
else
|
96
|
+
define_method :scope_condition do
|
97
|
+
eval "%{#{configuration[:scope]}}"
|
98
|
+
end
|
99
|
+
|
100
|
+
define_method :scope_changed? do
|
101
|
+
false
|
102
|
+
end
|
103
|
+
end
|
111
104
|
|
112
105
|
# only add to attr_accessible
|
113
106
|
# if the class has some mass_assignment_protection
|
114
|
-
|
115
107
|
if defined?(accessible_attributes) and !accessible_attributes.blank?
|
116
|
-
attr_accessible
|
108
|
+
attr_accessible :"#{configuration[:column]}"
|
109
|
+
end
|
110
|
+
|
111
|
+
define_singleton_method :quoted_position_column do
|
112
|
+
@_quoted_position_column ||= connection.quote_column_name(configuration[:column])
|
113
|
+
end
|
114
|
+
|
115
|
+
define_singleton_method :quoted_position_column_with_table_name do
|
116
|
+
@_quoted_position_column_with_table_name ||= "#{caller_class.quoted_table_name}.#{quoted_position_column}"
|
117
117
|
end
|
118
118
|
|
119
|
-
scope :in_list, lambda { where(
|
119
|
+
scope :in_list, lambda { where("#{quoted_position_column_with_table_name} IS NOT NULL") }
|
120
120
|
|
121
|
-
|
122
|
-
update_all_with_touch
|
121
|
+
define_singleton_method :decrement_all do
|
122
|
+
update_all_with_touch "#{quoted_position_column} = (#{quoted_position_column_with_table_name} - 1)"
|
123
123
|
end
|
124
124
|
|
125
|
-
|
126
|
-
update_all_with_touch
|
125
|
+
define_singleton_method :increment_all do
|
126
|
+
update_all_with_touch "#{quoted_position_column} = (#{quoted_position_column_with_table_name} + 1)"
|
127
127
|
end
|
128
128
|
|
129
|
-
|
129
|
+
define_singleton_method :update_all_with_touch do |updates|
|
130
130
|
record = new
|
131
131
|
attrs = record.send(:timestamp_attributes_for_update_in_model)
|
132
132
|
now = record.send(:current_time_from_proper_timezone)
|
133
133
|
|
134
|
-
query = attrs.map { |attr|
|
134
|
+
query = attrs.map { |attr| "#{connection.quote_column_name(attr)} = :now" }
|
135
135
|
query.push updates
|
136
136
|
query = query.join(", ")
|
137
137
|
|
138
138
|
update_all([query, now: now])
|
139
139
|
end
|
140
|
-
|
140
|
+
end
|
141
141
|
|
142
142
|
attr_reader :position_changed
|
143
143
|
|
data/lib/acts_as_list/version.rb
CHANGED
data/test/test_list.rb
CHANGED
@@ -228,7 +228,7 @@ class ListTest < ActsAsListTestCase
|
|
228
228
|
ActiveRecord::Base.connection_pool.with_connection do |c|
|
229
229
|
n.times do
|
230
230
|
begin
|
231
|
-
ListMixin.where(parent_id: 1).order(
|
231
|
+
ListMixin.where(parent_id: 1).order('pos').last.insert_at(1)
|
232
232
|
rescue Exception
|
233
233
|
# ignore SQLite3::SQLException due to table locking
|
234
234
|
end
|
@@ -578,19 +578,19 @@ class MultipleListsTest < ActsAsListTestCase
|
|
578
578
|
end
|
579
579
|
|
580
580
|
def test_check_scope_order
|
581
|
-
assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 1).order(
|
582
|
-
assert_equal [5, 6, 7, 8], ListMixin.where(:parent_id => 2).order(
|
581
|
+
assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 1).order('pos').map(&:id)
|
582
|
+
assert_equal [5, 6, 7, 8], ListMixin.where(:parent_id => 2).order('pos').map(&:id)
|
583
583
|
ListMixin.find(4).update_attributes(:parent_id => 2, :pos => 2)
|
584
|
-
assert_equal [1, 2, 3], ListMixin.where(:parent_id => 1).order(
|
585
|
-
assert_equal [5, 4, 6, 7, 8], ListMixin.where(:parent_id => 2).order(
|
584
|
+
assert_equal [1, 2, 3], ListMixin.where(:parent_id => 1).order('pos').map(&:id)
|
585
|
+
assert_equal [5, 4, 6, 7, 8], ListMixin.where(:parent_id => 2).order('pos').map(&:id)
|
586
586
|
end
|
587
587
|
|
588
588
|
def test_check_scope_position
|
589
589
|
assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 1).map(&:pos)
|
590
590
|
assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 2).map(&:pos)
|
591
591
|
ListMixin.find(4).update_attributes(:parent_id => 2, :pos => 2)
|
592
|
-
assert_equal [1, 2, 3], ListMixin.where(:parent_id => 1).order(
|
593
|
-
assert_equal [1, 2, 3, 4, 5], ListMixin.where(:parent_id => 2).order(
|
592
|
+
assert_equal [1, 2, 3], ListMixin.where(:parent_id => 1).order('pos').map(&:pos)
|
593
|
+
assert_equal [1, 2, 3, 4, 5], ListMixin.where(:parent_id => 2).order('pos').map(&:pos)
|
594
594
|
end
|
595
595
|
end
|
596
596
|
|
@@ -622,51 +622,51 @@ class MultipleListsArrayScopeTest < ActsAsListTestCase
|
|
622
622
|
end
|
623
623
|
|
624
624
|
def test_order_after_all_scope_properties_are_changed
|
625
|
-
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order(
|
626
|
-
assert_equal [5, 6, 7, 8], ArrayScopeListMixin.where(:parent_id => 2, :parent_type => 'something').order(
|
625
|
+
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:id)
|
626
|
+
assert_equal [5, 6, 7, 8], ArrayScopeListMixin.where(:parent_id => 2, :parent_type => 'something').order('pos').map(&:id)
|
627
627
|
ArrayScopeListMixin.find(2).update_attributes(:parent_id => 2, :pos => 2,:parent_type => 'something')
|
628
|
-
assert_equal [1, 3, 4], ArrayScopeListMixin.where(:parent_id => 1,:parent_type => 'anything').order(
|
629
|
-
assert_equal [5, 2, 6, 7, 8], ArrayScopeListMixin.where(:parent_id => 2,:parent_type => 'something').order(
|
628
|
+
assert_equal [1, 3, 4], ArrayScopeListMixin.where(:parent_id => 1,:parent_type => 'anything').order('pos').map(&:id)
|
629
|
+
assert_equal [5, 2, 6, 7, 8], ArrayScopeListMixin.where(:parent_id => 2,:parent_type => 'something').order('pos').map(&:id)
|
630
630
|
end
|
631
631
|
|
632
632
|
def test_position_after_all_scope_properties_are_changed
|
633
633
|
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').map(&:pos)
|
634
634
|
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 2, :parent_type => 'something').map(&:pos)
|
635
635
|
ArrayScopeListMixin.find(4).update_attributes(:parent_id => 2, :pos => 2, :parent_type => 'something')
|
636
|
-
assert_equal [1, 2, 3], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order(
|
637
|
-
assert_equal [1, 2, 3, 4, 5], ArrayScopeListMixin.where(:parent_id => 2, :parent_type => 'something').order(
|
636
|
+
assert_equal [1, 2, 3], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:pos)
|
637
|
+
assert_equal [1, 2, 3, 4, 5], ArrayScopeListMixin.where(:parent_id => 2, :parent_type => 'something').order('pos').map(&:pos)
|
638
638
|
end
|
639
639
|
|
640
640
|
def test_order_after_one_scope_property_is_changed
|
641
|
-
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order(
|
642
|
-
assert_equal [9, 10, 11, 12], ArrayScopeListMixin.where(:parent_id => 3, :parent_type => 'anything').order(
|
641
|
+
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:id)
|
642
|
+
assert_equal [9, 10, 11, 12], ArrayScopeListMixin.where(:parent_id => 3, :parent_type => 'anything').order('pos').map(&:id)
|
643
643
|
ArrayScopeListMixin.find(2).update_attributes(:parent_id => 3, :pos => 2)
|
644
|
-
assert_equal [1, 3, 4], ArrayScopeListMixin.where(:parent_id => 1,:parent_type => 'anything').order(
|
645
|
-
assert_equal [9, 2, 10, 11, 12], ArrayScopeListMixin.where(:parent_id => 3,:parent_type => 'anything').order(
|
644
|
+
assert_equal [1, 3, 4], ArrayScopeListMixin.where(:parent_id => 1,:parent_type => 'anything').order('pos').map(&:id)
|
645
|
+
assert_equal [9, 2, 10, 11, 12], ArrayScopeListMixin.where(:parent_id => 3,:parent_type => 'anything').order('pos').map(&:id)
|
646
646
|
end
|
647
647
|
|
648
648
|
def test_position_after_one_scope_property_is_changed
|
649
649
|
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').map(&:pos)
|
650
650
|
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 3, :parent_type => 'anything').map(&:pos)
|
651
651
|
ArrayScopeListMixin.find(4).update_attributes(:parent_id => 3, :pos => 2)
|
652
|
-
assert_equal [1, 2, 3], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order(
|
653
|
-
assert_equal [1, 2, 3, 4, 5], ArrayScopeListMixin.where(:parent_id => 3, :parent_type => 'anything').order(
|
652
|
+
assert_equal [1, 2, 3], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:pos)
|
653
|
+
assert_equal [1, 2, 3, 4, 5], ArrayScopeListMixin.where(:parent_id => 3, :parent_type => 'anything').order('pos').map(&:pos)
|
654
654
|
end
|
655
655
|
|
656
656
|
def test_order_after_moving_to_empty_list
|
657
|
-
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order(
|
658
|
-
assert_equal [], ArrayScopeListMixin.where(:parent_id => 4, :parent_type => 'anything').order(
|
657
|
+
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:id)
|
658
|
+
assert_equal [], ArrayScopeListMixin.where(:parent_id => 4, :parent_type => 'anything').order('pos').map(&:id)
|
659
659
|
ArrayScopeListMixin.find(2).update_attributes(:parent_id => 4, :pos => 1)
|
660
|
-
assert_equal [1, 3, 4], ArrayScopeListMixin.where(:parent_id => 1,:parent_type => 'anything').order(
|
661
|
-
assert_equal [2], ArrayScopeListMixin.where(:parent_id => 4,:parent_type => 'anything').order(
|
660
|
+
assert_equal [1, 3, 4], ArrayScopeListMixin.where(:parent_id => 1,:parent_type => 'anything').order('pos').map(&:id)
|
661
|
+
assert_equal [2], ArrayScopeListMixin.where(:parent_id => 4,:parent_type => 'anything').order('pos').map(&:id)
|
662
662
|
end
|
663
663
|
|
664
664
|
def test_position_after_moving_to_empty_list
|
665
665
|
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').map(&:pos)
|
666
666
|
assert_equal [], ArrayScopeListMixin.where(:parent_id => 4, :parent_type => 'anything').map(&:pos)
|
667
667
|
ArrayScopeListMixin.find(2).update_attributes(:parent_id => 4, :pos => 1)
|
668
|
-
assert_equal [1, 2, 3], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order(
|
669
|
-
assert_equal [1], ArrayScopeListMixin.where(:parent_id => 4, :parent_type => 'anything').order(
|
668
|
+
assert_equal [1, 2, 3], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:pos)
|
669
|
+
assert_equal [1], ArrayScopeListMixin.where(:parent_id => 4, :parent_type => 'anything').order('pos').map(&:pos)
|
670
670
|
end
|
671
671
|
end
|
672
672
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-09-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|