acts_as_list 1.0.1 → 1.0.2
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/CHANGELOG.md +13 -0
- data/README.md +2 -2
- data/acts_as_list.gemspec +0 -1
- data/lib/acts_as_list/active_record/acts/scope_method_definer.rb +7 -3
- data/lib/acts_as_list/version.rb +1 -1
- data/test/test_scope_with_user_defined_foreign_key.rb +42 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b697b0a1f7de57449d3b08718d3092b4d3415b482ced1e3f8451255f756d8f9
|
4
|
+
data.tar.gz: e6450636ddb5a4a581be40b48b85dc540c739f7c04e2dd8a298b4193083d929c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5167239a2867ebe360247dd874689be782e71377ca484a6fcbeea400fc35e076bf9137db424fdf311370cc965c41f74e1703ea5f6b5ba3f00cfffb235b5c5e2
|
7
|
+
data.tar.gz: a19ab76d2c215c735c1d42890a9d322c0cccc95eb594093cf5dd13d4c830a91a02ff7cf74ea2c71072fddfb3f6898415527b28780e70383cd2554a06e171afc0
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## Unreleased
|
8
|
+
|
9
|
+
## v1.0.2 - 2020-09-14
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
- Get foreign key from reflections when possible [\#383](https://github.com/brendon/acts_as_list/pull/383) ([jefftsang])
|
13
|
+
|
14
|
+
### Removed
|
15
|
+
- gemspec: Drop defunct `rubyforge_project` directive [\#373](https://github.com/brendon/acts_as_list/pull/373) ([olleolleolle])
|
16
|
+
|
17
|
+
[olleolleolle]: https://github.com/olleolleolle
|
18
|
+
[jefftsang]: https://github.com/jefftsang
|
19
|
+
|
7
20
|
## v1.0.1 - 2020-02-27
|
8
21
|
|
9
22
|
### Fixed
|
data/README.md
CHANGED
@@ -108,7 +108,7 @@ end
|
|
108
108
|
When using PostgreSQL, it is also possible to leave this migration up to the database layer. Inside of the `change` block you could write:
|
109
109
|
|
110
110
|
```ruby
|
111
|
-
execute <<~SQL.
|
111
|
+
execute <<~SQL.squish
|
112
112
|
UPDATE todo_items
|
113
113
|
SET position = mapping.new_position
|
114
114
|
FROM (
|
@@ -282,7 +282,7 @@ All versions `0.1.5` onwards require Rails 3.0.x and higher.
|
|
282
282
|
|
283
283
|
We often hear complaints that `position` values are repeated, incorrect etc. For example, #254. To ensure data integrity, you should rely on your database. There are two things you can do:
|
284
284
|
|
285
|
-
1. Use constraints. If you model `Item` that `belongs_to` an `Order`, and it has a `position` column, then add a unique constraint on `items` with `[:order_id, :
|
285
|
+
1. Use constraints. If you model `Item` that `belongs_to` an `Order`, and it has a `position` column, then add a unique constraint on `items` with `[:order_id, :position]`. Think of it as a list invariant. What are the properties of your list that don't change no matter how many items you have in it? One such propery is that each item has a distinct position. Another _could be_ that position is always greater than 0. It is strongly recommended that you rely on your database to enforce these invariants or constraints. Here are the docs for [PostgreSQL](https://www.postgresql.org/docs/9.5/static/ddl-constraints.html) and [MySQL](https://dev.mysql.com/doc/refman/8.0/en/alter-table.html).
|
286
286
|
2. Use mutexes or row level locks. At its heart the duplicate problem is that of handling concurrency. Adding a contention resolution mechanism like locks will solve it to some extent. But it is not a solution or replacement for constraints. Locks are also prone to deadlocks.
|
287
287
|
|
288
288
|
As a library, `acts_as_list` may not always have all the context needed to apply these tools. They are much better suited at the application level.
|
data/acts_as_list.gemspec
CHANGED
@@ -13,7 +13,6 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.summary = "A gem adding sorting, reordering capabilities to an active_record model, allowing it to act as a list"
|
14
14
|
s.description = 'This "acts_as" extension provides the capabilities for sorting and reordering a number of objects in a list. The class that has this specified needs to have a "position" column defined as an integer on the mapped database table.'
|
15
15
|
s.license = "MIT"
|
16
|
-
s.rubyforge_project = "acts_as_list"
|
17
16
|
s.required_ruby_version = ">= 2.4.7"
|
18
17
|
|
19
18
|
if s.respond_to?(:metadata)
|
@@ -4,7 +4,7 @@ module ActiveRecord::Acts::List::ScopeMethodDefiner #:nodoc:
|
|
4
4
|
extend ActiveSupport::Inflector
|
5
5
|
|
6
6
|
def self.call(caller_class, scope)
|
7
|
-
scope = idify(scope) if scope.is_a?(Symbol)
|
7
|
+
scope = idify(caller_class, scope) if scope.is_a?(Symbol)
|
8
8
|
|
9
9
|
caller_class.class_eval do
|
10
10
|
define_method :scope_name do
|
@@ -64,9 +64,13 @@ module ActiveRecord::Acts::List::ScopeMethodDefiner #:nodoc:
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
def self.idify(name)
|
67
|
+
def self.idify(caller_class, name)
|
68
68
|
return name if name.to_s =~ /_id$/
|
69
69
|
|
70
|
-
|
70
|
+
if caller_class.reflections.key?(name.to_s)
|
71
|
+
caller_class.reflections[name.to_s].foreign_key.to_sym
|
72
|
+
else
|
73
|
+
foreign_key(name).to_sym
|
74
|
+
end
|
71
75
|
end
|
72
76
|
end
|
data/lib/acts_as_list/version.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Checklist < ActiveRecord::Base
|
4
|
+
has_many :checklist_items, foreign_key: 'list_id', inverse_of: :checklist
|
5
|
+
end
|
6
|
+
|
7
|
+
class ChecklistItem < ActiveRecord::Base
|
8
|
+
belongs_to :checklist, foreign_key: 'list_id', inverse_of: :checklist_items
|
9
|
+
acts_as_list scope: :checklist
|
10
|
+
end
|
11
|
+
|
12
|
+
class ScopeWithUserDefinedForeignKeyTest < Minitest::Test
|
13
|
+
def setup
|
14
|
+
ActiveRecord::Base.connection.create_table :checklists do |t|
|
15
|
+
end
|
16
|
+
|
17
|
+
ActiveRecord::Base.connection.create_table :checklist_items do |t|
|
18
|
+
t.column :list_id, :integer
|
19
|
+
t.column :position, :integer
|
20
|
+
end
|
21
|
+
|
22
|
+
ActiveRecord::Base.connection.schema_cache.clear!
|
23
|
+
[Checklist, ChecklistItem].each(&:reset_column_information)
|
24
|
+
super
|
25
|
+
end
|
26
|
+
|
27
|
+
def teardown
|
28
|
+
teardown_db
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_scope_with_user_defined_foreign_key
|
33
|
+
checklist = Checklist.create
|
34
|
+
checklist_item_1 = checklist.checklist_items.create
|
35
|
+
checklist_item_2 = checklist.checklist_items.create
|
36
|
+
checklist_item_3 = checklist.checklist_items.create
|
37
|
+
|
38
|
+
assert_equal 1, checklist_item_1.position
|
39
|
+
assert_equal 2, checklist_item_2.position
|
40
|
+
assert_equal 3, checklist_item_3.position
|
41
|
+
end
|
42
|
+
end
|
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: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Swanand Pagnis
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-09-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- test/test_no_update_for_extra_classes.rb
|
95
95
|
- test/test_no_update_for_scope_destruction.rb
|
96
96
|
- test/test_no_update_for_subclasses.rb
|
97
|
+
- test/test_scope_with_user_defined_foreign_key.rb
|
97
98
|
homepage: http://github.com/brendon/acts_as_list
|
98
99
|
licenses:
|
99
100
|
- MIT
|
@@ -138,3 +139,4 @@ test_files:
|
|
138
139
|
- test/test_no_update_for_extra_classes.rb
|
139
140
|
- test/test_no_update_for_scope_destruction.rb
|
140
141
|
- test/test_no_update_for_subclasses.rb
|
142
|
+
- test/test_scope_with_user_defined_foreign_key.rb
|