mongoid_orderable 6.0.3 → 6.0.4

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: 8882038ec4e57486bd693bc1732f935f2d01f949aeedc7f71b3c54bca5ac0b44
4
- data.tar.gz: c0c82c4802280dfe6005e89122e9f7905fabcdf261bc9b3864016d10a70c112c
3
+ metadata.gz: a2babceab2f835fc658b2b41350208c65cc0aba49449b72a73e7275c84583479
4
+ data.tar.gz: ffdda4411505dc18f660dea2567a3d6d5e59aa40c6d95e9ef1a7404e4455c625
5
5
  SHA512:
6
- metadata.gz: 64332b6ae9d7786864d238accdd3ec81c8defa059ff1d7e1763e487a271c2dffb2f25b3a1a2332947a3b262ecc6cb8da33aae0acdab0cd04bd3ac6e0a2a2ca44
7
- data.tar.gz: 918ea29f2b71caf6cfba5cdc7e145bba69d0d90d2561e1983676fa13a3517f87eaabd7f66d628fbae1ec45df56fe82a11a723de632bbd1650697f39939d10534
6
+ metadata.gz: 41e8f1cae5a56384b9f5b2a953218c1a11de6b66d5b3ef1459d7fa4404d97ccb1151127eaefba3027c83f0d701b74630ff31c4aa329d48b0067cab683122d9b4
7
+ data.tar.gz: f7f3195f9c63bb9daba132b83d7afa973e58c9afe743a69ea261621eb89454b669f497dc33b69e0d4eefc0e1245523b6da2c97797906dbf98469ab69d2c94e21
data/CHANGELOG.md CHANGED
@@ -1,11 +1,16 @@
1
- ### 6.0.4 (Next)
1
+ ### 6.0.5 (Next)
2
2
 
3
3
  * Your contribution here.
4
4
 
5
+ ### 6.0.4 (Next)
6
+
7
+ * [#75](https://github.com/mongoid/mongoid_orderable/pull/75): Fix: Setting #move_to should mark an orderable object as changed so that callbacks are triggered.
8
+
5
9
  ### 6.0.3 (2021/06/27)
6
10
 
7
11
  * [#72](https://github.com/mongoid/mongoid_orderable/pull/72): Feature: Add :if and :unless conditions which disable callbacks.
8
12
  * [#71](https://github.com/mongoid/mongoid_orderable/pull/71): Fix: Add TTL index to locks table.
13
+ * [#73](https://github.com/mongoid/mongoid_orderable/pull/73): Refactor: Replace Travis CI with Github Actions.
9
14
 
10
15
  ### 6.0.2 (2021/01/26)
11
16
 
@@ -48,6 +48,7 @@ module Orderable
48
48
  klass.send :include, Mixins::Callbacks
49
49
  klass.send :include, Mixins::Movable
50
50
  klass.send :include, Mixins::Listable
51
+ klass.send :prepend, Mixins::Cascadeable if klass.embedded?
51
52
  end
52
53
 
53
54
  def generate_all_helpers
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mongoid
4
+ module Orderable
5
+ module Mixins
6
+ # This is required to trigger callbacks on embedded objects.
7
+ # Otherwise, the #move_to parameter won't work when saving the parent.
8
+ module Cascadeable
9
+ def in_callback_state?(kind)
10
+ super || move_all.present?
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Mongoid
4
4
  module Orderable
5
- VERSION = '6.0.3'
5
+ VERSION = '6.0.4'
6
6
  end
7
7
  end
@@ -18,6 +18,7 @@ require 'mongoid/orderable/mixins/helpers'
18
18
  require 'mongoid/orderable/mixins/callbacks'
19
19
  require 'mongoid/orderable/mixins/listable'
20
20
  require 'mongoid/orderable/mixins/movable'
21
+ require 'mongoid/orderable/mixins/cascadeable'
21
22
  require 'mongoid/orderable/generators/base'
22
23
  require 'mongoid/orderable/generators/listable'
23
24
  require 'mongoid/orderable/generators/lock_collection'
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mongoid::Orderable::Mixins::Cascadeable do
4
+
5
+ it do
6
+ eo = EmbedsOrderable.create!
7
+ orderable = eo.embedded_orderables.create!
8
+ expect(orderable.in_callback_state?(:update)).to eq false
9
+ orderable.move_to = 2
10
+ expect(orderable.in_callback_state?(:update)).to eq true
11
+ end
12
+ end
@@ -19,11 +19,33 @@ describe EmbeddedOrderable do
19
19
  expect(positions).to eq([[1, 2], [1, 2, 3]])
20
20
  end
21
21
 
22
- it 'moves an item returned by a query to position' do
23
- embedded_orderable1 = EmbedsOrderable.first.embedded_orderables.where(position: 1).first
24
- embedded_orderable2 = EmbedsOrderable.first.embedded_orderables.where(position: 2).first
25
- embedded_orderable1.move_to! 2
26
- expect(embedded_orderable2.reload.position).to eq(1)
22
+ it 'move_to! moves an item returned by a query to position' do
23
+ parent = EmbedsOrderable.first
24
+ child1 = parent.embedded_orderables.where(position: 1).first
25
+ child2 = parent.embedded_orderables.where(position: 2).first
26
+ child1.move_to!(2)
27
+ expect(child1.reload.position).to eq(2)
28
+ expect(child2.reload.position).to eq(1)
29
+ end
30
+
31
+ it 'move_to moves an item returned by a query to position when saving the parent' do
32
+ parent = EmbedsOrderable.first
33
+ child1 = parent.embedded_orderables.where(position: 1).first
34
+ child2 = parent.embedded_orderables.where(position: 2).first
35
+ child1.move_to(2)
36
+ parent.save!
37
+ expect(child1.reload.position).to eq(2)
38
+ expect(child2.reload.position).to eq(1)
39
+ end
40
+
41
+ it 'move_to= moves an item returned by a query to position when saving the parent' do
42
+ parent = EmbedsOrderable.first
43
+ child1 = parent.embedded_orderables.where(position: 1).first
44
+ child2 = parent.embedded_orderables.where(position: 2).first
45
+ child1.move_to = 2
46
+ parent.save!
47
+ expect(child1.reload.position).to eq(2)
48
+ expect(child2.reload.position).to eq(1)
27
49
  end
28
50
  end
29
51
 
@@ -53,7 +53,7 @@ end
53
53
  class EmbedsOrderable
54
54
  include Mongoid::Document
55
55
 
56
- embeds_many :embedded_orderables
56
+ embeds_many :embedded_orderables, cascade_callbacks: true
57
57
  end
58
58
 
59
59
  class EmbeddedOrderable
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_orderable
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.3
4
+ version: 6.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - pyromaniac
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-28 00:00:00.000000000 Z
11
+ date: 2023-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -111,11 +111,13 @@ files:
111
111
  - lib/mongoid/orderable/handlers/transaction.rb
112
112
  - lib/mongoid/orderable/installer.rb
113
113
  - lib/mongoid/orderable/mixins/callbacks.rb
114
+ - lib/mongoid/orderable/mixins/cascadeable.rb
114
115
  - lib/mongoid/orderable/mixins/helpers.rb
115
116
  - lib/mongoid/orderable/mixins/listable.rb
116
117
  - lib/mongoid/orderable/mixins/movable.rb
117
118
  - lib/mongoid/orderable/version.rb
118
119
  - lib/mongoid_orderable.rb
120
+ - spec/integration/cascadeable_spec.rb
119
121
  - spec/integration/concurrency_spec.rb
120
122
  - spec/integration/conditional_spec.rb
121
123
  - spec/integration/customized_spec.rb
@@ -135,7 +137,7 @@ homepage: https://github.com/mongoid/mongoid_orderable
135
137
  licenses:
136
138
  - MIT
137
139
  metadata: {}
138
- post_install_message:
140
+ post_install_message:
139
141
  rdoc_options: []
140
142
  require_paths:
141
143
  - lib
@@ -150,11 +152,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
152
  - !ruby/object:Gem::Version
151
153
  version: '0'
152
154
  requirements: []
153
- rubygems_version: 3.2.9
154
- signing_key:
155
+ rubygems_version: 3.4.4
156
+ signing_key:
155
157
  specification_version: 4
156
158
  summary: Mongoid orderable list implementation
157
159
  test_files:
160
+ - spec/integration/cascadeable_spec.rb
158
161
  - spec/integration/concurrency_spec.rb
159
162
  - spec/integration/conditional_spec.rb
160
163
  - spec/integration/customized_spec.rb