mongoid_orderable 4.1.1 → 5.0.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/.rvmrc +1 -1
- data/.travis.yml +3 -9
- data/CHANGELOG.md +5 -0
- data/Gemfile +11 -8
- data/README.md +32 -10
- data/lib/mongoid/orderable/errors/invalid_target_position.rb +1 -1
- data/lib/mongoid/orderable/errors/mongoid_orderable_error.rb +1 -1
- data/lib/mongoid/orderable/orderable_class.rb +1 -1
- data/lib/mongoid_orderable.rb +16 -18
- data/lib/mongoid_orderable/version.rb +1 -1
- data/mongoid_orderable.gemspec +1 -0
- data/spec/mongoid/orderable_spec.rb +50 -45
- data/spec/spec_helper.rb +14 -21
- metadata +29 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a966ef4b59309d05845a832163936ce54e339a1e
|
4
|
+
data.tar.gz: 16b32ccd0fdb0a2ae9a61424d8842de9eba00d4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee3e6de12801d857bb9345dc6035c698c56ee119f9b2e78fc15584caf6108351904487b888fa2091636bc750be62e6076b06bf74f38f44b2bd2fa68bc36611ac
|
7
|
+
data.tar.gz: 5fc8fe3f744fff60b38ac3d0136dcc5c84c069042beda3a7c623c9d6da743e67219e29da920bd983d4a5f506f081cbac9614e14630647dbc58593fa3dfb877d9
|
data/.rspec
CHANGED
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm use 2.
|
1
|
+
rvm use 2.2@mongoid_orderable --create
|
data/.travis.yml
CHANGED
@@ -1,20 +1,14 @@
|
|
1
1
|
rvm:
|
2
|
-
- 1.8.7
|
3
2
|
- 1.9.3
|
4
3
|
- 2.0.0
|
5
|
-
- 2.1
|
4
|
+
- 2.1
|
5
|
+
- 2.2
|
6
6
|
# - rbx
|
7
7
|
|
8
8
|
env:
|
9
9
|
- MONGOID_VERSION=2
|
10
10
|
- MONGOID_VERSION=3
|
11
11
|
- MONGOID_VERSION=4
|
12
|
-
|
13
|
-
matrix:
|
14
|
-
exclude:
|
15
|
-
- rvm: 1.8.7
|
16
|
-
env: MONGOID_VERSION=3
|
17
|
-
- rvm: 1.8.7
|
18
|
-
env: MONGOID_VERSION=4
|
12
|
+
- MONGOID_VERSION=5
|
19
13
|
|
20
14
|
services: mongodb
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -3,13 +3,16 @@ source "http://rubygems.org"
|
|
3
3
|
# Specify your gem's dependencies in mongoid_orderable.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
case version = ENV['MONGOID_VERSION'] ||
|
7
|
-
when /
|
8
|
-
gem
|
9
|
-
when /
|
10
|
-
gem
|
11
|
-
when /
|
12
|
-
gem
|
6
|
+
case version = ENV['MONGOID_VERSION'] || '5.0'
|
7
|
+
when /^5/
|
8
|
+
gem 'mongoid', '~> 5.0'
|
9
|
+
when /^4/
|
10
|
+
gem 'mongoid', '~> 4.0'
|
11
|
+
when /^3/
|
12
|
+
gem 'mongoid', '~> 3.1'
|
13
|
+
when /^2/
|
14
|
+
gem 'mongoid', '~> 2.0'
|
15
|
+
gem 'bson_ext', platforms: :ruby
|
13
16
|
else
|
14
|
-
gem
|
17
|
+
gem 'mongoid', version
|
15
18
|
end
|
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
[](https://badge.fury.io/rb/mongoid_orderable)
|
2
|
+
[](https://travis-ci.org/pyromaniac/mongoid_orderable)
|
2
3
|
|
3
4
|
# What?
|
4
5
|
|
5
|
-
Mongoid::Orderable is a ordered list implementation for your
|
6
|
+
Mongoid::Orderable is a ordered list implementation for your Mongoid 2, 3, 4 and 5 models.
|
6
7
|
|
7
8
|
# Why?
|
8
9
|
|
@@ -14,14 +15,14 @@ Mongoid::Orderable is a ordered list implementation for your mongoid models.
|
|
14
15
|
|
15
16
|
# How?
|
16
17
|
|
17
|
-
```
|
18
|
+
```ruby
|
18
19
|
gem 'mongoid_orderable'
|
19
20
|
```
|
20
21
|
|
21
22
|
Gem has the same api as others. Just include Mongoid::Orderable into your model and call `orderable` method.
|
22
23
|
Embedded objects are automatically scoped by their parent.
|
23
24
|
|
24
|
-
```
|
25
|
+
```ruby
|
25
26
|
class Item
|
26
27
|
include Mongoid::Document
|
27
28
|
include Mongoid::Orderable
|
@@ -42,7 +43,7 @@ end
|
|
42
43
|
|
43
44
|
# Usage
|
44
45
|
|
45
|
-
```
|
46
|
+
```ruby
|
46
47
|
item.move_to 2 # just change position
|
47
48
|
item.move_to! 2 # and save
|
48
49
|
item.move_to = 2 # assignable method
|
@@ -70,7 +71,7 @@ item.previous_item # returns the previous item in the list
|
|
70
71
|
|
71
72
|
You can also define multiple orderable columns for any class including the Mongoid::Orderable module.
|
72
73
|
|
73
|
-
```
|
74
|
+
```ruby
|
74
75
|
class Book
|
75
76
|
include Mongoid::Document
|
76
77
|
include Mongoid::Orderable
|
@@ -83,8 +84,8 @@ end
|
|
83
84
|
The above defines two different orderable_columns on Book - *position* and *serial_no*.
|
84
85
|
The following helpers are generated in this case:
|
85
86
|
|
86
|
-
```
|
87
|
-
item.move_#{column_name}_to
|
87
|
+
```ruby
|
88
|
+
item.move_#{column_name}_to
|
88
89
|
item.move_#{column_name}_to=
|
89
90
|
item.move_#{column_name}_to!
|
90
91
|
|
@@ -104,7 +105,7 @@ item.previous_#{column_name}_item
|
|
104
105
|
|
105
106
|
When a model defines multiple orderable columns, the original helpers are also available and work on the first orderable column.
|
106
107
|
|
107
|
-
```
|
108
|
+
```ruby
|
108
109
|
@book1 = Book.create!
|
109
110
|
@book2 = Book.create!
|
110
111
|
@book2 => #<Book _id: 53a16a2ba1bde4f746000001, serial_no: 1, position: 1>
|
@@ -114,10 +115,31 @@ When a model defines multiple orderable columns, the original helpers are also a
|
|
114
115
|
|
115
116
|
To specify any other orderable column as default pass the **default: true** option with orderable.
|
116
117
|
|
117
|
-
```
|
118
|
+
```ruby
|
118
119
|
orderable column: sno, as: :serial_no, default: true
|
119
120
|
```
|
120
121
|
|
122
|
+
# Embedded documents
|
123
|
+
```ruby
|
124
|
+
class Question
|
125
|
+
include Mongoid::Document
|
126
|
+
include Mongoid::Orderable
|
127
|
+
|
128
|
+
embedded_in :survey
|
129
|
+
|
130
|
+
orderable
|
131
|
+
end
|
132
|
+
```
|
133
|
+
If you bulk import embedded documents without specifying their position, no field `position` will be written.
|
134
|
+
```ruby
|
135
|
+
class Survey
|
136
|
+
include Mongoid::Document
|
137
|
+
|
138
|
+
embeds_many :questions, cascade_callbacks: true
|
139
|
+
end
|
140
|
+
```
|
141
|
+
To ensure the position is written correctly, you will need to provide the cascade callbacks option to the relation.
|
142
|
+
|
121
143
|
# Contributing
|
122
144
|
|
123
145
|
Fork && Patch && Spec && Push && Pull request.
|
@@ -7,7 +7,7 @@ module Mongoid::Orderable
|
|
7
7
|
|
8
8
|
private
|
9
9
|
def _compose_message value
|
10
|
-
if
|
10
|
+
if ::Mongoid::Compatibility::Version.mongoid2?
|
11
11
|
translate 'invalid_target_position', { :value => value.inspect }
|
12
12
|
else
|
13
13
|
compose_message 'invalid_target_position', { :value => value.inspect }
|
@@ -2,7 +2,7 @@ module Mongoid::Orderable
|
|
2
2
|
module Errors
|
3
3
|
class MongoidOrderableError < ::Mongoid::Errors::MongoidError
|
4
4
|
|
5
|
-
if
|
5
|
+
if ::Mongoid::Compatibility::Version.mongoid2?
|
6
6
|
def translate key, options
|
7
7
|
[:message, :summary, :resolution].map do |section|
|
8
8
|
::I18n.translate "#{BASE_KEY}.#{key}.#{section}", options
|
@@ -31,7 +31,7 @@ module Mongoid
|
|
31
31
|
def add_db_index
|
32
32
|
spec = [[configuration[:column], 1]]
|
33
33
|
spec.unshift([configuration[:scope], 1]) if configuration[:scope].is_a?(Symbol)
|
34
|
-
if
|
34
|
+
if ::Mongoid::Compatibility::Version.mongoid2?
|
35
35
|
klass.index(spec)
|
36
36
|
else
|
37
37
|
klass.index(Hash[spec])
|
data/lib/mongoid_orderable.rb
CHANGED
@@ -1,36 +1,34 @@
|
|
1
1
|
require 'active_support'
|
2
|
-
|
2
|
+
|
3
|
+
I18n.enforce_available_locales = false if I18n.respond_to?(:enforce_available_locales)
|
3
4
|
I18n.load_path << File.join(File.dirname(__FILE__), 'config', 'locales', 'en.yml')
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
::Mongoid.const_defined? :Contexts
|
8
|
-
end
|
9
|
-
def self.mongoid3?
|
10
|
-
::Mongoid.const_defined? :Observer
|
11
|
-
end
|
6
|
+
require 'mongoid'
|
7
|
+
require 'mongoid/compatibility'
|
12
8
|
|
13
|
-
|
14
|
-
|
9
|
+
module MongoidOrderable
|
10
|
+
if ::Mongoid::Compatibility::Version.mongoid2? || ::Mongoid::Compatibility::Version.mongoid3?
|
11
|
+
def self.inc instance, attribute, value
|
15
12
|
instance.inc attribute, value
|
16
|
-
else
|
17
|
-
instance.inc(attribute => value)
|
18
13
|
end
|
19
|
-
end
|
20
14
|
|
21
|
-
|
22
|
-
if MongoidOrderable.mongoid2? || MongoidOrderable.mongoid3?
|
15
|
+
def self.metadata instance
|
23
16
|
instance.metadata
|
24
|
-
|
17
|
+
end
|
18
|
+
else
|
19
|
+
def self.inc instance, attribute, value
|
20
|
+
instance.inc(attribute => value)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.metadata instance
|
25
24
|
instance.relation_metadata
|
26
25
|
end
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
30
|
-
require 'mongoid'
|
31
29
|
require 'mongoid_orderable/version'
|
32
30
|
|
33
|
-
if
|
31
|
+
if ::Mongoid::Compatibility::Version.mongoid2?
|
34
32
|
require 'mongoid_orderable/mongoid/contexts/mongo'
|
35
33
|
require 'mongoid_orderable/mongoid/contexts/enumerable'
|
36
34
|
require 'mongoid_orderable/mongoid/criteria'
|
data/mongoid_orderable.gemspec
CHANGED
@@ -137,9 +137,9 @@ describe Mongoid::Orderable do
|
|
137
137
|
end
|
138
138
|
|
139
139
|
it 'should have index on position column' do
|
140
|
-
if
|
140
|
+
if ::Mongoid::Compatibility::Version.mongoid2?
|
141
141
|
expect(SimpleOrderable.index_options[[[:position, 1]]]).not_to be_nil
|
142
|
-
elsif
|
142
|
+
elsif ::Mongoid::Compatibility::Version.mongoid3?
|
143
143
|
expect(SimpleOrderable.index_options[{:position => 1}]).not_to be_nil
|
144
144
|
else
|
145
145
|
expect(SimpleOrderable.index_specifications.detect { |spec| spec.key == {:position => 1} }).not_to be_nil
|
@@ -347,9 +347,9 @@ describe Mongoid::Orderable do
|
|
347
347
|
describe 'index' do
|
348
348
|
|
349
349
|
it 'is not on position alone' do
|
350
|
-
if
|
350
|
+
if ::Mongoid::Compatibility::Version.mongoid2?
|
351
351
|
expect(ScopedOrderable.index_options[[[:position, 1]]]).to be_nil
|
352
|
-
elsif
|
352
|
+
elsif ::Mongoid::Compatibility::Version.mongoid3?
|
353
353
|
expect(ScopedOrderable.index_options[{:position => 1}]).to be_nil
|
354
354
|
else
|
355
355
|
expect(ScopedOrderable.index_specifications.detect { |spec| spec.key == {:position => 1} }).to be_nil
|
@@ -357,9 +357,9 @@ describe Mongoid::Orderable do
|
|
357
357
|
end
|
358
358
|
|
359
359
|
it 'is on compound fields' do
|
360
|
-
if
|
360
|
+
if ::Mongoid::Compatibility::Version.mongoid2?
|
361
361
|
expect(ScopedOrderable.index_options[[[:group_id, 1], [:position, 1]]]).to_not be_nil
|
362
|
-
elsif
|
362
|
+
elsif ::Mongoid::Compatibility::Version.mongoid3?
|
363
363
|
expect(ScopedOrderable.index_options[{:group_id => 1, :position => 1}]).to_not be_nil
|
364
364
|
else
|
365
365
|
expect(ScopedOrderable.index_specifications.detect { |spec| spec.key == {:group_id => 1, :position => 1} }).to_not be_nil
|
@@ -452,14 +452,19 @@ describe Mongoid::Orderable do
|
|
452
452
|
end
|
453
453
|
end
|
454
454
|
|
455
|
-
describe '
|
455
|
+
describe 'utility methods' do
|
456
|
+
|
457
|
+
before do
|
458
|
+
ScopedOrderable.delete_all
|
459
|
+
5.times { ScopedOrderable.create! }
|
460
|
+
end
|
456
461
|
|
457
462
|
it "should return a collection of items lower/higher on the list for next_items/previous_items" do
|
458
|
-
record_1 =
|
459
|
-
record_2 =
|
460
|
-
record_3 =
|
461
|
-
record_4 =
|
462
|
-
record_5 =
|
463
|
+
record_1 = ScopedOrderable.where(:position => 1).first
|
464
|
+
record_2 = ScopedOrderable.where(:position => 2).first
|
465
|
+
record_3 = ScopedOrderable.where(:position => 3).first
|
466
|
+
record_4 = ScopedOrderable.where(:position => 4).first
|
467
|
+
record_5 = ScopedOrderable.where(:position => 5).first
|
463
468
|
expect(record_1.next_items.to_a).to eq([record_2, record_3, record_4, record_5])
|
464
469
|
expect(record_5.previous_items.to_a).to eq([record_1, record_2, record_3, record_4])
|
465
470
|
expect(record_3.previous_items.to_a).to eq([record_1, record_2])
|
@@ -476,9 +481,9 @@ describe Mongoid::Orderable do
|
|
476
481
|
describe StringScopedOrderable do
|
477
482
|
|
478
483
|
it 'uses the foreign key of the relationship as scope' do
|
479
|
-
orderable1 = StringScopedOrderable.create(:some_scope => 1)
|
480
|
-
orderable2 = StringScopedOrderable.create(:some_scope => 1)
|
481
|
-
orderable3 = StringScopedOrderable.create(:some_scope => 2)
|
484
|
+
orderable1 = StringScopedOrderable.create!(:some_scope => 1)
|
485
|
+
orderable2 = StringScopedOrderable.create!(:some_scope => 1)
|
486
|
+
orderable3 = StringScopedOrderable.create!(:some_scope => 2)
|
482
487
|
expect(orderable1.position).to eq 1
|
483
488
|
expect(orderable2.position).to eq 2
|
484
489
|
expect(orderable3.position).to eq 1
|
@@ -535,7 +540,7 @@ describe Mongoid::Orderable do
|
|
535
540
|
describe NoIndexOrderable do
|
536
541
|
|
537
542
|
it 'should not have index on position column' do
|
538
|
-
if
|
543
|
+
if ::Mongoid::Compatibility::Version.mongoid2? || ::Mongoid::Compatibility::Version.mongoid3?
|
539
544
|
expect(NoIndexOrderable.index_options[[[:position, 1]]]).to be_nil
|
540
545
|
else
|
541
546
|
expect(NoIndexOrderable.index_specifications.detect { |spec| spec.key == :position }).to be_nil
|
@@ -714,18 +719,18 @@ describe Mongoid::Orderable do
|
|
714
719
|
end
|
715
720
|
|
716
721
|
it 'with symbol position' do
|
717
|
-
first_apple = Apple.first
|
722
|
+
first_apple = Apple.asc(:_id).first
|
718
723
|
top_pos = first_apple.position
|
719
|
-
bottom_pos = Apple.last.position
|
724
|
+
bottom_pos = Apple.asc(:_id).last.position
|
720
725
|
expect do
|
721
726
|
first_apple.move_to! :bottom
|
722
727
|
end.to change(first_apple, :position).from(top_pos).to bottom_pos
|
723
728
|
end
|
724
729
|
|
725
730
|
it 'with point position' do
|
726
|
-
first_apple = Apple.first
|
731
|
+
first_apple = Apple.asc(:_id).first
|
727
732
|
top_pos = first_apple.position
|
728
|
-
bottom_pos = Apple.last.position
|
733
|
+
bottom_pos = Apple.asc(:_id).last.position
|
729
734
|
expect do
|
730
735
|
first_apple.move_to! bottom_pos
|
731
736
|
end.to change(first_apple, :position).from(top_pos).to bottom_pos
|
@@ -751,9 +756,9 @@ describe Mongoid::Orderable do
|
|
751
756
|
parent_scope1 = ForeignKeyDiffersOrderable.create
|
752
757
|
parent_scope2 = ForeignKeyDiffersOrderable.create
|
753
758
|
expect do
|
754
|
-
orderable1 = ForeignKeyDiffersOrderable.create(:different_scope => parent_scope1)
|
755
|
-
orderable2 = ForeignKeyDiffersOrderable.create(:different_scope => parent_scope1)
|
756
|
-
orderable3 = ForeignKeyDiffersOrderable.create(:different_scope => parent_scope2)
|
759
|
+
orderable1 = ForeignKeyDiffersOrderable.create!(:different_scope => parent_scope1)
|
760
|
+
orderable2 = ForeignKeyDiffersOrderable.create!(:different_scope => parent_scope1)
|
761
|
+
orderable3 = ForeignKeyDiffersOrderable.create!(:different_scope => parent_scope2)
|
757
762
|
end.to_not raise_error
|
758
763
|
expect(orderable1.position).to eq 1
|
759
764
|
expect(orderable2.position).to eq 2
|
@@ -818,7 +823,7 @@ describe Mongoid::Orderable do
|
|
818
823
|
expect(record.serial_no).to eq(4)
|
819
824
|
expect(record.position).to eq(position)
|
820
825
|
end
|
821
|
-
|
826
|
+
|
822
827
|
it 'higher from middle' do
|
823
828
|
record = MultipleColumnsOrderable.where(:serial_no => 3).first
|
824
829
|
position = record.position
|
@@ -827,7 +832,7 @@ describe Mongoid::Orderable do
|
|
827
832
|
expect(record.serial_no).to eq(2)
|
828
833
|
expect(record.position).to eq(position)
|
829
834
|
end
|
830
|
-
|
835
|
+
|
831
836
|
it 'lower from top' do
|
832
837
|
record = MultipleColumnsOrderable.where(:serial_no => 1).first
|
833
838
|
position = record.position
|
@@ -836,7 +841,7 @@ describe Mongoid::Orderable do
|
|
836
841
|
expect(record.serial_no).to eq(2)
|
837
842
|
expect(record.position).to eq(position)
|
838
843
|
end
|
839
|
-
|
844
|
+
|
840
845
|
it 'lower from bottom' do
|
841
846
|
record = MultipleColumnsOrderable.where(:serial_no => 5).first
|
842
847
|
position = record.position
|
@@ -845,7 +850,7 @@ describe Mongoid::Orderable do
|
|
845
850
|
expect(record.serial_no).to eq(5)
|
846
851
|
expect(record.position).to eq(position)
|
847
852
|
end
|
848
|
-
|
853
|
+
|
849
854
|
it 'lower from middle' do
|
850
855
|
record = MultipleColumnsOrderable.where(:serial_no => 3).first
|
851
856
|
position = record.position
|
@@ -896,9 +901,9 @@ describe Mongoid::Orderable do
|
|
896
901
|
end
|
897
902
|
|
898
903
|
it 'should have index on serial_no column' do
|
899
|
-
if
|
904
|
+
if ::Mongoid::Compatibility::Version.mongoid2?
|
900
905
|
expect(MultipleColumnsOrderable.index_options[[[:serial_no, 1]]]).not_to be_nil
|
901
|
-
elsif
|
906
|
+
elsif ::Mongoid::Compatibility::Version.mongoid3?
|
902
907
|
expect(MultipleColumnsOrderable.index_options[{:serial_no => 1}]).not_to be_nil
|
903
908
|
else
|
904
909
|
expect(MultipleColumnsOrderable.index_specifications.detect { |spec| spec.key == {:serial_no => 1} }).not_to be_nil
|
@@ -976,7 +981,7 @@ describe Mongoid::Orderable do
|
|
976
981
|
expect(record.serial_no).to eq(4)
|
977
982
|
expect(record.position).to eq(position)
|
978
983
|
end
|
979
|
-
|
984
|
+
|
980
985
|
it 'higher from middle' do
|
981
986
|
record = MultipleColumnsOrderable.where(:serial_no => 3).first
|
982
987
|
position = record.position
|
@@ -985,7 +990,7 @@ describe Mongoid::Orderable do
|
|
985
990
|
expect(record.serial_no).to eq(2)
|
986
991
|
expect(record.position).to eq(position)
|
987
992
|
end
|
988
|
-
|
993
|
+
|
989
994
|
it 'lower from top' do
|
990
995
|
record = MultipleColumnsOrderable.where(:serial_no => 1).first
|
991
996
|
position = record.position
|
@@ -994,7 +999,7 @@ describe Mongoid::Orderable do
|
|
994
999
|
expect(record.serial_no).to eq(2)
|
995
1000
|
expect(record.position).to eq(position)
|
996
1001
|
end
|
997
|
-
|
1002
|
+
|
998
1003
|
it 'lower from bottom' do
|
999
1004
|
record = MultipleColumnsOrderable.where(:serial_no => 5).first
|
1000
1005
|
position = record.position
|
@@ -1003,7 +1008,7 @@ describe Mongoid::Orderable do
|
|
1003
1008
|
expect(record.serial_no).to eq(5)
|
1004
1009
|
expect(record.position).to eq(position)
|
1005
1010
|
end
|
1006
|
-
|
1011
|
+
|
1007
1012
|
it 'lower from middle' do
|
1008
1013
|
record = MultipleColumnsOrderable.where(:serial_no => 3).first
|
1009
1014
|
position = record.position
|
@@ -1059,9 +1064,9 @@ describe Mongoid::Orderable do
|
|
1059
1064
|
end
|
1060
1065
|
|
1061
1066
|
it 'should have index on position column' do
|
1062
|
-
if
|
1067
|
+
if ::Mongoid::Compatibility::Version.mongoid2?
|
1063
1068
|
expect(MultipleColumnsOrderable.index_options[[[:position, 1]]]).to be_nil
|
1064
|
-
elsif
|
1069
|
+
elsif ::Mongoid::Compatibility::Version.mongoid3?
|
1065
1070
|
expect(MultipleColumnsOrderable.index_options[{:position => 1}]).to be_nil
|
1066
1071
|
else
|
1067
1072
|
expect(MultipleColumnsOrderable.index_specifications.detect { |spec| spec.key == {:position => 1} }).to be_nil
|
@@ -1139,7 +1144,7 @@ describe Mongoid::Orderable do
|
|
1139
1144
|
expect(record.position).to eq(3)
|
1140
1145
|
expect(record.serial_no).to eq(position)
|
1141
1146
|
end
|
1142
|
-
|
1147
|
+
|
1143
1148
|
it 'higher from middle' do
|
1144
1149
|
record = MultipleColumnsOrderable.where(:pos => 3).first
|
1145
1150
|
position = record.serial_no
|
@@ -1148,7 +1153,7 @@ describe Mongoid::Orderable do
|
|
1148
1153
|
expect(record.position).to eq(2)
|
1149
1154
|
expect(record.serial_no).to eq(position)
|
1150
1155
|
end
|
1151
|
-
|
1156
|
+
|
1152
1157
|
it 'lower from top' do
|
1153
1158
|
record = MultipleColumnsOrderable.where(:pos => 0).first
|
1154
1159
|
position = record.serial_no
|
@@ -1157,7 +1162,7 @@ describe Mongoid::Orderable do
|
|
1157
1162
|
expect(record.position).to eq(1)
|
1158
1163
|
expect(record.serial_no).to eq(position)
|
1159
1164
|
end
|
1160
|
-
|
1165
|
+
|
1161
1166
|
it 'lower from bottom' do
|
1162
1167
|
record = MultipleColumnsOrderable.where(:pos => 4).first
|
1163
1168
|
position = record.serial_no
|
@@ -1166,7 +1171,7 @@ describe Mongoid::Orderable do
|
|
1166
1171
|
expect(record.position).to eq(4)
|
1167
1172
|
expect(record.serial_no).to eq(position)
|
1168
1173
|
end
|
1169
|
-
|
1174
|
+
|
1170
1175
|
it 'lower from middle' do
|
1171
1176
|
record = MultipleColumnsOrderable.where(:pos => 3).first
|
1172
1177
|
position = record.serial_no
|
@@ -1264,30 +1269,30 @@ describe Mongoid::Orderable do
|
|
1264
1269
|
end
|
1265
1270
|
|
1266
1271
|
describe 'scope movement' do
|
1267
|
-
|
1272
|
+
|
1268
1273
|
let(:record){ MultipleColumnsOrderable.where(:group_id => 2, :groups => 2).first }
|
1269
|
-
|
1274
|
+
|
1270
1275
|
it 'to a new scope group' do
|
1271
1276
|
record.update_attributes :group_id => 3
|
1272
1277
|
expect(all_groups).to eq([1, 2, 1, 2, 1])
|
1273
1278
|
expect(record.groups).to eq(1)
|
1274
1279
|
end
|
1275
|
-
|
1280
|
+
|
1276
1281
|
context 'when moving to an existing scope group' do
|
1277
|
-
|
1282
|
+
|
1278
1283
|
it 'without a position' do
|
1279
1284
|
record.update_attributes :group_id => 1
|
1280
1285
|
expect(all_groups).to eq([1, 2, 3, 1, 2])
|
1281
1286
|
expect(record.reload.groups).to eq(3)
|
1282
1287
|
end
|
1283
|
-
|
1288
|
+
|
1284
1289
|
it 'with symbol position' do
|
1285
1290
|
record.update_attributes :group_id => 1
|
1286
1291
|
record.move_groups_to! :top
|
1287
1292
|
expect(all_groups).to eq([1, 2, 3, 1, 2])
|
1288
1293
|
expect(record.reload.groups).to eq(1)
|
1289
1294
|
end
|
1290
|
-
|
1295
|
+
|
1291
1296
|
it 'with point position' do
|
1292
1297
|
record.update_attributes :group_id => 1
|
1293
1298
|
record.move_groups_to! 2
|
data/spec/spec_helper.rb
CHANGED
@@ -1,37 +1,30 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
Bundler.require
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
if MongoidOrderable.mongoid2?
|
4
|
+
if ::Mongoid::Compatibility::Version.mongoid2?
|
7
5
|
Mongoid.configure do |config|
|
8
|
-
|
9
|
-
# database.add_user "mongoid", "test"
|
10
|
-
config.master = Mongo::Connection.new.db DATABASE_NAME
|
6
|
+
config.master = Mongo::Connection.new.db 'mongoid_orderable_test'
|
11
7
|
config.logger = nil
|
12
8
|
end
|
13
9
|
else
|
14
10
|
Mongoid.configure do |config|
|
15
|
-
config.connect_to
|
11
|
+
config.connect_to 'mongoid_orderable_test'
|
16
12
|
end
|
17
13
|
end
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
#DatabaseCleaner[:mongoid].strategy = :truncation
|
24
|
-
end
|
25
|
-
|
26
|
-
config.after :each do
|
27
|
-
#DatabaseCleaner[:mongoid].clean
|
28
|
-
end
|
15
|
+
unless Mongoid::Compatibility::Version.mongoid2?
|
16
|
+
Mongoid.logger.level = Logger::INFO
|
17
|
+
Mongo::Logger.logger.level = Logger::INFO if Mongoid::Compatibility::Version.mongoid5?
|
18
|
+
end
|
29
19
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
20
|
+
RSpec.configure do |config|
|
21
|
+
config.after(:all) do
|
22
|
+
if Mongoid::Compatibility::Version.mongoid2?
|
23
|
+
Mongoid.master.connection.drop_database(Mongoid.database.name)
|
24
|
+
elsif Mongoid::Compatibility::Version.mongoid3? || Mongoid::Compatibility::Version.mongoid4?
|
34
25
|
Mongoid.default_session.drop
|
26
|
+
else
|
27
|
+
Mongoid::Clients.default.database.drop
|
35
28
|
end
|
36
29
|
end
|
37
30
|
end
|
metadata
CHANGED
@@ -1,55 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_orderable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pyromaniac
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '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
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: mongoid
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mongoid-compatibility
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
69
|
description: Gem allows mongoid model behave as orderable list
|
@@ -59,10 +73,10 @@ executables: []
|
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
62
|
-
- .gitignore
|
63
|
-
- .rspec
|
64
|
-
- .rvmrc
|
65
|
-
- .travis.yml
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".rvmrc"
|
79
|
+
- ".travis.yml"
|
66
80
|
- CHANGELOG.md
|
67
81
|
- Gemfile
|
68
82
|
- README.md
|
@@ -102,17 +116,17 @@ require_paths:
|
|
102
116
|
- lib
|
103
117
|
required_ruby_version: !ruby/object:Gem::Requirement
|
104
118
|
requirements:
|
105
|
-
- -
|
119
|
+
- - ">="
|
106
120
|
- !ruby/object:Gem::Version
|
107
121
|
version: '0'
|
108
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
123
|
requirements:
|
110
|
-
- -
|
124
|
+
- - ">="
|
111
125
|
- !ruby/object:Gem::Version
|
112
126
|
version: '0'
|
113
127
|
requirements: []
|
114
128
|
rubyforge_project: mongoid_orderable
|
115
|
-
rubygems_version: 2.
|
129
|
+
rubygems_version: 2.4.5.1
|
116
130
|
signing_key:
|
117
131
|
specification_version: 4
|
118
132
|
summary: Acts as list mongoid implementation
|