acts_as_list 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12c682a75d4197c1e22f97b8423db27fbb75efaf8bcdc049a30548946c0dd5f0
4
- data.tar.gz: 0eb3aaba4c6c977dcd7ead96491092774838e1330c91bf1d19a527c1cf3b8c98
3
+ metadata.gz: 2b697b0a1f7de57449d3b08718d3092b4d3415b482ced1e3f8451255f756d8f9
4
+ data.tar.gz: e6450636ddb5a4a581be40b48b85dc540c739f7c04e2dd8a298b4193083d929c
5
5
  SHA512:
6
- metadata.gz: 642f0590fc1c162ef9abac2ef4e1153fbe15e8f7b0db0b39f5771fbe7f76bbb1b4cdd45121d7ab03968ea3391449966a785e6d0a898db6a02b1b57c9bcd0ef8e
7
- data.tar.gz: f878ad669e23e211a543997215f7680b8ed51e66fff568b93cdd3f472a8745ab9fe496c5865e80b516d52989db7110d8809e1a749323d93160afe22152e7c7f8
6
+ metadata.gz: d5167239a2867ebe360247dd874689be782e71377ca484a6fcbeea400fc35e076bf9137db424fdf311370cc965c41f74e1703ea5f6b5ba3f00cfffb235b5c5e2
7
+ data.tar.gz: a19ab76d2c215c735c1d42890a9d322c0cccc95eb594093cf5dd13d4c830a91a02ff7cf74ea2c71072fddfb3f6898415527b28780e70383cd2554a06e171afc0
@@ -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.squeeze
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, :position_id]`. 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).
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.
@@ -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
- foreign_key(name).to_sym
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
@@ -3,7 +3,7 @@
3
3
  module ActiveRecord
4
4
  module Acts
5
5
  module List
6
- VERSION = '1.0.1'
6
+ VERSION = '1.0.2'
7
7
  end
8
8
  end
9
9
  end
@@ -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.1
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-02-26 00:00:00.000000000 Z
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