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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf7464bb2c953b31ccf95b2e3017ce77cf9e40bc
4
- data.tar.gz: f65a617c773c1c5ebad2b85827fc675da6c23d2c
3
+ metadata.gz: a58bb02b59b9251aa9959060342f81fe5aa83467
4
+ data.tar.gz: 6b8f6ba9c5f16cbe5a93cacb754b721b3dd40b56
5
5
  SHA512:
6
- metadata.gz: 664518e270eafe5380772fe9dab0d661ab6184b526648ba1322f28d4c04040e9d412f00b011abe072eb289d73dc422be0aa411b1e759d2933c5ea05d08ef8773
7
- data.tar.gz: ffd987ff9646c697fe2972ff2516bcc66286d528c71af311e8fe27524568d5eaad6ee774cd351345a2c8aaad8326fd9c42bd83dd9acf77d3f34dfb2a98d99d2d
6
+ metadata.gz: 5c25e5a32b9def627747a36a7fe4e232ae946b3cde83039c4a893dfc4e8469808fc6ceefac353b4f6bd5e251eb6b0d28df3b00a0d8c69b7b2b1c96ce81eafb42
7
+ data.tar.gz: 1494350922d065eab1cf1bd0309b56a9a0246055a0eb61f45401682f3f7fa21060ac8367b138a2e29644ba24de838864061a176d2e89711a676c76469d6e897a
data/.gitignore CHANGED
@@ -9,3 +9,4 @@ pkg/*
9
9
  .ruby-version
10
10
  # Appraisal generated lockfiles
11
11
  *.gemfile.lock
12
+ .DS_Store
@@ -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
- gem "minitest", "~> 5.0"
15
+ gem "minitest", "~> 5.0"
22
16
  gem "test_after_commit", "~> 0.4.2"
23
17
  end
@@ -16,10 +16,4 @@ group :test do
16
16
  gem "after_commit_exception_notification"
17
17
  end
18
18
 
19
- platforms :rbx do
20
- gem "rubysl", "~> 2.0"
21
- gem "rubinius-developer_tools"
22
- gem "rubysl-test-unit"
23
- end
24
-
25
19
  gemspec :path => "../"
@@ -15,10 +15,4 @@ group :test do
15
15
  gem "test_after_commit", "~> 0.4.2"
16
16
  end
17
17
 
18
- platforms :rbx do
19
- gem "rubysl", "~> 2.0"
20
- gem "rubinius-developer_tools"
21
- gem "rubysl-test-unit"
22
- end
23
-
24
18
  gemspec :path => "../"
@@ -15,10 +15,4 @@ group :test do
15
15
  gem "test_after_commit", "~> 0.4.2"
16
16
  end
17
17
 
18
- platforms :rbx do
19
- gem "rubysl", "~> 2.0"
20
- gem "rubinius-developer_tools"
21
- gem "rubysl-test-unit"
22
- end
23
-
24
18
  gemspec :path => "../"
@@ -42,102 +42,102 @@ module ActiveRecord
42
42
  configuration[:scope] = :"#{configuration[:scope]}_id"
43
43
  end
44
44
 
45
- if configuration[:scope].is_a?(Symbol)
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 <<-EOV, __FILE__, __LINE__ + 1
81
- def self.acts_as_list_top
82
- #{configuration[:top_of_list]}.to_i
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
- def acts_as_list_top
86
- #{configuration[:top_of_list]}.to_i
52
+ define_method :acts_as_list_top do
53
+ configuration[:top_of_list].to_i
87
54
  end
88
55
 
89
- def acts_as_list_class
90
- ::#{self.name}
56
+ define_method :acts_as_list_class do
57
+ caller_class
91
58
  end
92
59
 
93
- def position_column
94
- '#{configuration[:column]}'
60
+ define_method :position_column do
61
+ configuration[:column]
95
62
  end
96
63
 
97
- def scope_name
98
- '#{configuration[:scope]}'
64
+ define_method :scope_name do
65
+ configuration[:scope]
99
66
  end
100
67
 
101
- def add_new_at
102
- '#{configuration[:add_new_at]}'
68
+ define_method :add_new_at do
69
+ configuration[:add_new_at]
103
70
  end
104
71
 
105
- def #{configuration[:column]}=(position)
106
- write_attribute(:#{configuration[:column]}, position)
72
+ define_method :"#{configuration[:column]}=" do |position|
73
+ write_attribute(configuration[:column], position)
107
74
  @position_changed = true
108
75
  end
109
76
 
110
- #{scope_methods}
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 :#{configuration[:column]}
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(%q{#{quoted_position_column_with_table_name} IS NOT NULL}) }
119
+ scope :in_list, lambda { where("#{quoted_position_column_with_table_name} IS NOT NULL") }
120
120
 
121
- def self.decrement_all
122
- update_all_with_touch %q(#{quoted_position_column} = (#{quoted_position_column_with_table_name} - 1))
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
- def self.increment_all
126
- update_all_with_touch %q(#{quoted_position_column} = (#{quoted_position_column_with_table_name} + 1))
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
- def self.update_all_with_touch(updates)
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| %(\#{connection.quote_column_name(attr)} = :now) }
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
- EOV
140
+ end
141
141
 
142
142
  attr_reader :position_changed
143
143
 
@@ -1,7 +1,7 @@
1
1
  module ActiveRecord
2
2
  module Acts
3
3
  module List
4
- VERSION = '0.8.0'
4
+ VERSION = '0.8.1'
5
5
  end
6
6
  end
7
7
  end
@@ -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(:pos).last.insert_at(1)
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(:pos).map(&:id)
582
- assert_equal [5, 6, 7, 8], ListMixin.where(:parent_id => 2).order(:pos).map(&:id)
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(:pos).map(&:id)
585
- assert_equal [5, 4, 6, 7, 8], ListMixin.where(:parent_id => 2).order(:pos).map(&:id)
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(:pos).map(&:pos)
593
- assert_equal [1, 2, 3, 4, 5], ListMixin.where(:parent_id => 2).order(:pos).map(&:pos)
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(:pos).map(&:id)
626
- assert_equal [5, 6, 7, 8], ArrayScopeListMixin.where(:parent_id => 2, :parent_type => 'something').order(:pos).map(&:id)
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(:pos).map(&:id)
629
- assert_equal [5, 2, 6, 7, 8], ArrayScopeListMixin.where(:parent_id => 2,:parent_type => 'something').order(:pos).map(&:id)
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(:pos).map(&:pos)
637
- assert_equal [1, 2, 3, 4, 5], ArrayScopeListMixin.where(:parent_id => 2, :parent_type => 'something').order(:pos).map(&:pos)
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(:pos).map(&:id)
642
- assert_equal [9, 10, 11, 12], ArrayScopeListMixin.where(:parent_id => 3, :parent_type => 'anything').order(:pos).map(&:id)
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(:pos).map(&:id)
645
- assert_equal [9, 2, 10, 11, 12], ArrayScopeListMixin.where(:parent_id => 3,:parent_type => 'anything').order(:pos).map(&:id)
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(:pos).map(&:pos)
653
- assert_equal [1, 2, 3, 4, 5], ArrayScopeListMixin.where(:parent_id => 3, :parent_type => 'anything').order(:pos).map(&:pos)
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(:pos).map(&:id)
658
- assert_equal [], ArrayScopeListMixin.where(:parent_id => 4, :parent_type => 'anything').order(:pos).map(&:id)
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(:pos).map(&:id)
661
- assert_equal [2], ArrayScopeListMixin.where(:parent_id => 4,:parent_type => 'anything').order(:pos).map(&:id)
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(:pos).map(&:pos)
669
- assert_equal [1], ArrayScopeListMixin.where(:parent_id => 4, :parent_type => 'anything').order(:pos).map(&:pos)
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.0
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-08-23 00:00:00.000000000 Z
13
+ date: 2016-09-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord