mongoid-list 0.5.3 → 0.6.0
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/.rspec +1 -0
- data/Guardfile +1 -1
- data/lib/mongoid/list/embedded.rb +11 -4
- data/lib/mongoid/list/version.rb +1 -1
- data/mongoid-list.gemspec +5 -5
- data/spec/mongoid/list/embedded_spec.rb +35 -0
- data/spec/mongoid/list_spec.rb +28 -27
- data/spec/spec_helper.rb +0 -2
- metadata +14 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bc8db58867c8a657789d5531ea6d521a0e03538
|
4
|
+
data.tar.gz: 3612c5394262ee8c7edf085d68dd74e8a15cbbbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7284c34aa95047c45d4e3cd793cf49be0bd87d4f337b31a0e14b087e8dcf9ad5f8430dd83ef287f58197f92007f8aa97e40d1a2e54a64cf77efcf3b6e9ecf4b
|
7
|
+
data.tar.gz: 28bd66e603e0e81c6eef973e03f4ff97f33ca41249431c902218863c64310faa5585b18de1a285ea4995a6734528f8f13e1a332b72429f371b0815463af88418
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Guardfile
CHANGED
@@ -7,13 +7,20 @@ module Mongoid
|
|
7
7
|
class << self
|
8
8
|
|
9
9
|
def update_positions!(binding, elements)
|
10
|
+
root_doc = binding_root(binding)
|
10
11
|
load_list_elements(binding, elements).each_with_index do |element, idx|
|
11
|
-
|
12
|
-
|
12
|
+
# element.set(position: idx+1)
|
13
|
+
root_doc.collection.find(element.atomic_selector).update(
|
14
|
+
{ "$set" => { "#{element.atomic_position}.position" => (idx+1) } }
|
13
15
|
)
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
19
|
+
def binding_root(binding)
|
20
|
+
binding.base._parent || binding.base
|
21
|
+
end
|
22
|
+
|
23
|
+
|
17
24
|
private
|
18
25
|
|
19
26
|
def load_list_elements(binding, elements)
|
@@ -27,10 +34,10 @@ module Mongoid
|
|
27
34
|
|
28
35
|
|
29
36
|
def update_positions!
|
30
|
-
items.
|
37
|
+
items.each_with_index do |item, idx|
|
31
38
|
next unless should_operate_on_item?(item)
|
32
39
|
criteria = item.atomic_selector
|
33
|
-
updates = { '$inc' => { "#{item.atomic_path}
|
40
|
+
updates = { '$inc' => { "#{item.atomic_path}.#{idx}.position" => changes[:by] } }
|
34
41
|
item._root.class.collection.find(criteria).update(updates)
|
35
42
|
end
|
36
43
|
end
|
data/lib/mongoid/list/version.rb
CHANGED
data/mongoid-list.gemspec
CHANGED
@@ -19,11 +19,11 @@ Gem::Specification.new do |s|
|
|
19
19
|
|
20
20
|
s.add_dependency('mongoid', [ '~> 4.0.0' ])
|
21
21
|
|
22
|
-
s.add_development_dependency('rspec', [ '>=
|
23
|
-
s.add_development_dependency('guard', [ '>= 2.
|
22
|
+
s.add_development_dependency('rspec', [ '>= 3.1.0' ])
|
23
|
+
s.add_development_dependency('guard', [ '>= 2.8.0' ])
|
24
24
|
s.add_development_dependency('guard-rspec', [ '>= 4.2.0' ])
|
25
|
-
s.add_development_dependency('guard-spork', [ '>=
|
26
|
-
s.add_development_dependency('listen', [ '>= 2.
|
27
|
-
s.add_development_dependency('database_cleaner', [ '~> 1.
|
25
|
+
s.add_development_dependency('guard-spork', [ '>= 2.0.0' ])
|
26
|
+
s.add_development_dependency('listen', [ '>= 2.8.0' ])
|
27
|
+
s.add_development_dependency('database_cleaner', [ '~> 1.3.0' ])
|
28
28
|
|
29
29
|
end
|
@@ -2,6 +2,41 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Mongoid::List::Embedded do
|
4
4
|
|
5
|
+
describe ".binding_root" do
|
6
|
+
|
7
|
+
subject do
|
8
|
+
Mongoid::List::Embedded
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:root) do
|
12
|
+
Container.create!
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:embedded) do
|
16
|
+
root.items.create!
|
17
|
+
end
|
18
|
+
|
19
|
+
context "w/ Child Embed" do
|
20
|
+
|
21
|
+
it "returns @root" do
|
22
|
+
expect(subject.binding_root(root.items)).to eq root
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
context "w/ Deeply Embedded" do
|
28
|
+
|
29
|
+
let!(:deeply_embedded) { embedded.items.create! }
|
30
|
+
|
31
|
+
it "returns @root" do
|
32
|
+
expect(subject.binding_root(embedded.items)).to eq root
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
|
5
40
|
describe "#initialization" do
|
6
41
|
|
7
42
|
let(:container) do
|
data/spec/mongoid/list_spec.rb
CHANGED
@@ -376,8 +376,8 @@ describe Mongoid::List do
|
|
376
376
|
end
|
377
377
|
|
378
378
|
it "should have moved last items up" do
|
379
|
-
|
380
|
-
|
379
|
+
expect(item1.reload.position).to eq 1
|
380
|
+
expect(item3.reload.position).to eq 2
|
381
381
|
end
|
382
382
|
|
383
383
|
end
|
@@ -466,7 +466,7 @@ describe Mongoid::List do
|
|
466
466
|
context "when unscoped" do
|
467
467
|
|
468
468
|
subject { Simple.create }
|
469
|
-
specify { subject.list_scope_changing?.should
|
469
|
+
specify { subject.list_scope_changing?.should be_falsey }
|
470
470
|
|
471
471
|
end
|
472
472
|
|
@@ -476,14 +476,14 @@ describe Mongoid::List do
|
|
476
476
|
|
477
477
|
context "but no change to :group" do
|
478
478
|
|
479
|
-
specify { subject.list_scope_changing?.should
|
479
|
+
specify { subject.list_scope_changing?.should be_falsey }
|
480
480
|
|
481
481
|
end
|
482
482
|
|
483
483
|
context "with change to :group" do
|
484
484
|
|
485
485
|
before { subject.group = "B" }
|
486
|
-
specify { subject.list_scope_changing?.should
|
486
|
+
specify { subject.list_scope_changing?.should be_truthy }
|
487
487
|
|
488
488
|
end
|
489
489
|
|
@@ -856,18 +856,18 @@ describe Mongoid::List do
|
|
856
856
|
end
|
857
857
|
|
858
858
|
it "should change doc1 from :position of 1 to 2" do
|
859
|
-
doc1.position.
|
860
|
-
doc1.reload.position.
|
859
|
+
expect(doc1.position).to eq 1
|
860
|
+
expect(doc1.reload.position).to eq 2
|
861
861
|
end
|
862
862
|
|
863
863
|
it "should change doc2 from :position of 2 to 1" do
|
864
|
-
doc2.position.
|
865
|
-
doc2.reload.position.
|
864
|
+
expect(doc2.position).to eq 2
|
865
|
+
expect(doc2.reload.position).to eq 1
|
866
866
|
end
|
867
867
|
|
868
868
|
it "should not change doc3 from :position of 3" do
|
869
|
-
doc3.position.
|
870
|
-
doc3.reload.position.
|
869
|
+
expect(doc3.position).to eq 3
|
870
|
+
expect(doc3.reload.position).to eq 3
|
871
871
|
end
|
872
872
|
|
873
873
|
end
|
@@ -885,24 +885,25 @@ describe Mongoid::List do
|
|
885
885
|
end
|
886
886
|
|
887
887
|
it "should change doc1 from :position of 1 to 2" do
|
888
|
-
doc1.position.
|
889
|
-
doc1.reload.position.
|
888
|
+
expect(doc1.position).to eq 1
|
889
|
+
expect(doc1.reload.position).to eq 2
|
890
890
|
end
|
891
891
|
|
892
892
|
it "should change doc2 from :position of 2 to 1" do
|
893
|
-
doc2.position.
|
894
|
-
doc2.reload.position.
|
893
|
+
expect(doc2.position).to eq 2
|
894
|
+
expect(doc2.reload.position).to eq 1
|
895
895
|
end
|
896
896
|
|
897
897
|
it "should change doc3 from :position of 3 to 4" do
|
898
|
-
doc3.position.
|
899
|
-
doc3.reload.position.
|
898
|
+
expect(doc3.position).to eq 3
|
899
|
+
expect(doc3.reload.position).to eq 4
|
900
900
|
end
|
901
901
|
|
902
902
|
it "should change doc4 from :position of 4 to 3" do
|
903
|
-
doc4.position.
|
904
|
-
doc4.reload.position.
|
903
|
+
expect(doc4.position).to eq 4
|
904
|
+
expect(doc4.reload.position).to eq 3
|
905
905
|
end
|
906
|
+
|
906
907
|
end
|
907
908
|
|
908
909
|
context "on a Deeply Embedded Collection" do
|
@@ -925,23 +926,23 @@ describe Mongoid::List do
|
|
925
926
|
end
|
926
927
|
|
927
928
|
it "should change doc1 from :position of 1 to 3" do
|
928
|
-
doc1.position.
|
929
|
-
doc1.reload.position.
|
929
|
+
expect(doc1.position).to eq 1
|
930
|
+
expect(doc1.reload.position).to eq 3
|
930
931
|
end
|
931
932
|
|
932
933
|
it "should change @doc2 from :position of 2 to 4" do
|
933
|
-
doc2.position.
|
934
|
-
doc2.reload.position.
|
934
|
+
expect(doc2.position).to eq 2
|
935
|
+
expect(doc2.reload.position).to eq 4
|
935
936
|
end
|
936
937
|
|
937
938
|
it "should change @doc3 from :position of 3 to 1" do
|
938
|
-
doc3.position.
|
939
|
-
doc3.reload.position.
|
939
|
+
expect(doc3.position).to eq 3
|
940
|
+
expect(doc3.reload.position).to eq 1
|
940
941
|
end
|
941
942
|
|
942
943
|
it "should change @doc4 from :position of 4 to 2" do
|
943
|
-
doc4.position.
|
944
|
-
doc4.reload.position.
|
944
|
+
expect(doc4.position).to eq 4
|
945
|
+
expect(doc4.reload.position).to eq 2
|
945
946
|
end
|
946
947
|
|
947
948
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Krupinski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
@@ -30,28 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 3.1.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 3.1.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: guard
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 2.
|
47
|
+
version: 2.8.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 2.
|
54
|
+
version: 2.8.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: guard-rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,42 +72,42 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 2.0.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 2.0.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: listen
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 2.
|
89
|
+
version: 2.8.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 2.
|
96
|
+
version: 2.8.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: database_cleaner
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 1.
|
103
|
+
version: 1.3.0
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 1.
|
110
|
+
version: 1.3.0
|
111
111
|
description:
|
112
112
|
email: dave@davekrupinski.com
|
113
113
|
executables: []
|
@@ -115,6 +115,7 @@ extensions: []
|
|
115
115
|
extra_rdoc_files: []
|
116
116
|
files:
|
117
117
|
- ".gitignore"
|
118
|
+
- ".rspec"
|
118
119
|
- ".ruby-gemset"
|
119
120
|
- ".ruby-version"
|
120
121
|
- Gemfile
|
@@ -161,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
162
|
version: '0'
|
162
163
|
requirements: []
|
163
164
|
rubyforge_project:
|
164
|
-
rubygems_version: 2.
|
165
|
+
rubygems_version: 2.4.2
|
165
166
|
signing_key:
|
166
167
|
specification_version: 4
|
167
168
|
summary: Simple list behavior for Mongoid
|