mongoid-sortable 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/lib/mongoid-sortable/version.rb +1 -1
- data/lib/mongoid-sortable.rb +8 -8
- data/mongoid-sortable.gemspec +5 -4
- data/spec/db/mongoid.yml +2 -4
- data/spec/mongoid_sortable_spec.rb +15 -15
- data/spec/spec_helper.rb +3 -1
- data/spec/support/factories.rb +4 -4
- data/spec/support/models.rb +1 -1
- metadata +38 -35
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: da72b915a704d043d55b506f68ab12d0a0903281483e4437ada2ce8b66f179ea
|
4
|
+
data.tar.gz: a2b10e5d93af6d26a737b74f2eeba2a603d12fd89e7ff60646318335df3ee8b0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aca840ab8fbd86a318eeadf3ffda3224dca661457f6b3d7e0e6f296719d6852d316fed695935300e713b1d50118a1960e2e9006cd3ee1dec4f235a53b4cc1db8
|
7
|
+
data.tar.gz: c9f00bac825c850551e499ca3f13952d76403d4741fb9bbf368c5d1b9f06a6841865f5b48d2ce75b7b94d4b6738fe5236dab19aefad12ef0df53e182b0f53be6
|
data/.gitignore
CHANGED
data/lib/mongoid-sortable.rb
CHANGED
@@ -38,15 +38,15 @@ module Mongoid
|
|
38
38
|
def reorder(ids)
|
39
39
|
ids.map!(&:to_s) # ensure entities are strings
|
40
40
|
ids.each_with_index do |id, index|
|
41
|
-
position_scope.find(id).set(:
|
41
|
+
position_scope.find(id).set(position: index + 1)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
def position_at(new_position)
|
46
|
-
position_scope.gt(position: position).each{|d| d.inc(:
|
47
|
-
set(:
|
48
|
-
position_scope.gte(position: new_position).each{|d| d.inc(:
|
49
|
-
set(:
|
46
|
+
position_scope.gt(position: position).each{|d| d.inc(position: -1) }
|
47
|
+
set(position: nil)
|
48
|
+
position_scope.gte(position: new_position).each{|d| d.inc(position: 1) }
|
49
|
+
set(position: new_position)
|
50
50
|
end
|
51
51
|
|
52
52
|
def set_position
|
@@ -54,11 +54,11 @@ module Mongoid
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def set_sibling_positions
|
57
|
-
position_scope.gt(position: position).each{|d| d.inc(:
|
57
|
+
position_scope.gt(position: position).each{|d| d.inc(position: -1) }
|
58
58
|
end
|
59
59
|
|
60
60
|
def relation
|
61
|
-
(embedded? ? send(self.
|
61
|
+
(embedded? ? send(self._association.inverse).send(self._association.name) : self.class).unscoped.scoped
|
62
62
|
end
|
63
63
|
|
64
64
|
def position_scope(options = {})
|
@@ -68,4 +68,4 @@ module Mongoid
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
71
|
-
end
|
71
|
+
end
|
data/mongoid-sortable.gemspec
CHANGED
@@ -3,9 +3,9 @@ require File.expand_path('../lib/mongoid-sortable/version', __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Elliott Pogue"]
|
6
|
-
gem.email = ["
|
6
|
+
gem.email = ["github@tnypxl.com"]
|
7
7
|
# gem.description = %q{TODO: Write a gem description}
|
8
|
-
gem.summary = %q{A Mongoid
|
8
|
+
gem.summary = %q{A Mongoid 7.0 module for sorting}
|
9
9
|
gem.homepage = "https://github.com/epogue/mongoid-sortable"
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
@@ -15,9 +15,10 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = Mongoid::Sortable::VERSION
|
17
17
|
|
18
|
-
gem.add_dependency 'mongoid', '~>
|
18
|
+
gem.add_dependency 'mongoid', '~> 7.0.5'
|
19
19
|
|
20
20
|
gem.add_development_dependency 'rspec'
|
21
21
|
gem.add_development_dependency 'database_cleaner'
|
22
|
-
gem.add_development_dependency '
|
22
|
+
gem.add_development_dependency 'factory_bot', '~> 5.0.2'
|
23
|
+
gem.add_development_dependency 'byebug'
|
23
24
|
end
|
data/spec/db/mongoid.yml
CHANGED
@@ -2,10 +2,10 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "MongoidSortable" do
|
4
4
|
describe "sortable items" do
|
5
|
-
let(:parent) {
|
6
|
-
let!(:document1) {
|
7
|
-
let!(:document2) {
|
8
|
-
let!(:document3) {
|
5
|
+
let(:parent) { FactoryBot.create(:parent_document) }
|
6
|
+
let!(:document1) { FactoryBot.create(:document, parent_document: parent) }
|
7
|
+
let!(:document2) { FactoryBot.create(:document, parent_document: parent) }
|
8
|
+
let!(:document3) { FactoryBot.create(:document, parent_document: parent) }
|
9
9
|
|
10
10
|
it_should_behave_like 'a sortable item'
|
11
11
|
|
@@ -14,12 +14,12 @@ describe "MongoidSortable" do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
context "with distinct parents" do
|
17
|
-
let(:parent1) {
|
18
|
-
let(:parent2) {
|
19
|
-
let!(:p1_doc1) {
|
20
|
-
let!(:p1_doc2) {
|
21
|
-
let!(:p2_doc1) {
|
22
|
-
let!(:p2_doc2) {
|
17
|
+
let(:parent1) { FactoryBot.create(:parent_document) }
|
18
|
+
let(:parent2) { FactoryBot.create(:parent_document) }
|
19
|
+
let!(:p1_doc1) { FactoryBot.create(:document, parent_document: parent1) }
|
20
|
+
let!(:p1_doc2) { FactoryBot.create(:document, parent_document: parent1) }
|
21
|
+
let!(:p2_doc1) { FactoryBot.create(:document, parent_document: parent2) }
|
22
|
+
let!(:p2_doc2) { FactoryBot.create(:document, parent_document: parent2) }
|
23
23
|
|
24
24
|
it "should have their proper positions" do
|
25
25
|
p1_doc1.position.should == 1
|
@@ -46,11 +46,11 @@ describe "MongoidSortable" do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
describe "sortable embedded documents" do
|
49
|
-
let(:parent) {
|
50
|
-
let!(:document1) {
|
51
|
-
let!(:document2) {
|
52
|
-
let!(:document3) {
|
53
|
-
|
49
|
+
let(:parent) { FactoryBot.create(:document) }
|
50
|
+
let!(:document1) { FactoryBot.create(:embedded_document, document: parent) }
|
51
|
+
let!(:document2) { FactoryBot.create(:embedded_document, document: parent) }
|
52
|
+
let!(:document3) { FactoryBot.create(:embedded_document, document: parent) }
|
53
|
+
|
54
54
|
it_should_behave_like 'a sortable item'
|
55
55
|
|
56
56
|
it "should properly sort" do
|
data/spec/spec_helper.rb
CHANGED
@@ -11,11 +11,13 @@ require 'active_support'
|
|
11
11
|
require 'active_model'
|
12
12
|
require 'mongoid'
|
13
13
|
|
14
|
+
require 'byebug'
|
15
|
+
|
14
16
|
Dir["./spec/support/**/*.rb"].each {|f| require f}
|
15
17
|
|
16
18
|
ENV["MONGOID_ENV"] = "test"
|
17
19
|
Mongoid.load!(plugin_test_dir + "/db/mongoid.yml")
|
18
20
|
|
19
21
|
RSpec.configure do |config|
|
20
|
-
config.
|
22
|
+
config.expect_with(:rspec) { |c| c.syntax = :should }
|
21
23
|
end
|
data/spec/support/factories.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require '
|
1
|
+
require 'factory_bot'
|
2
2
|
|
3
|
-
|
3
|
+
FactoryBot.define do
|
4
4
|
factory :parent_document do
|
5
5
|
trait :with_documents do
|
6
6
|
after(:create) do |parent, evaluator|
|
7
|
-
3.times {
|
7
|
+
3.times { FactoryBot.create(:document, parent_document: parent) }
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
@@ -12,7 +12,7 @@ FactoryGirl.define do
|
|
12
12
|
factory :document do
|
13
13
|
trait :with_embedded_docs do
|
14
14
|
after(:create) do |parent, evaluator|
|
15
|
-
3.times {
|
15
|
+
3.times { FactoryBot.create(:embedded_document, document: parent) }
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
data/spec/support/models.rb
CHANGED
metadata
CHANGED
@@ -1,89 +1,94 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-sortable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Elliott Pogue
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2020-02-25 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: mongoid
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: 7.0.5
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
26
|
+
version: 7.0.5
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: database_cleaner
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
56
|
+
name: factory_bot
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- - ~>
|
59
|
+
- - "~>"
|
68
60
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
61
|
+
version: 5.0.2
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- - ~>
|
66
|
+
- - "~>"
|
76
67
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
68
|
+
version: 5.0.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
78
83
|
description:
|
79
84
|
email:
|
80
|
-
-
|
85
|
+
- github@tnypxl.com
|
81
86
|
executables: []
|
82
87
|
extensions: []
|
83
88
|
extra_rdoc_files: []
|
84
89
|
files:
|
85
|
-
- .gitignore
|
86
|
-
- .rspec
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
87
92
|
- Gemfile
|
88
93
|
- LICENSE
|
89
94
|
- README.md
|
@@ -100,28 +105,26 @@ files:
|
|
100
105
|
- spec/support/shared_examples_for_a_sortable_item.rb
|
101
106
|
homepage: https://github.com/epogue/mongoid-sortable
|
102
107
|
licenses: []
|
108
|
+
metadata: {}
|
103
109
|
post_install_message:
|
104
110
|
rdoc_options: []
|
105
111
|
require_paths:
|
106
112
|
- lib
|
107
113
|
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
-
none: false
|
109
114
|
requirements:
|
110
|
-
- -
|
115
|
+
- - ">="
|
111
116
|
- !ruby/object:Gem::Version
|
112
117
|
version: '0'
|
113
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
-
none: false
|
115
119
|
requirements:
|
116
|
-
- -
|
120
|
+
- - ">="
|
117
121
|
- !ruby/object:Gem::Version
|
118
122
|
version: '0'
|
119
123
|
requirements: []
|
120
|
-
|
121
|
-
rubygems_version: 1.8.23
|
124
|
+
rubygems_version: 3.0.3
|
122
125
|
signing_key:
|
123
|
-
specification_version:
|
124
|
-
summary: A Mongoid
|
126
|
+
specification_version: 4
|
127
|
+
summary: A Mongoid 7.0 module for sorting
|
125
128
|
test_files:
|
126
129
|
- spec/db/mongoid.yml
|
127
130
|
- spec/mongoid_sortable_spec.rb
|