acts_as_list_mongoid 0.2.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,12 @@
1
1
  class Item
2
2
  include Mongoid::Document
3
3
  include Mongoid::Timestamps
4
- include ActsAsList::Mongoid
5
-
6
- field :number, :type => Integer
4
+ # include ActsAsList::Mongoid
5
+ # field :number, :type => Integer
6
+ act_as_list
7
7
 
8
8
  embedded_in :list, :inverse_of => :items
9
- end
9
+ end
10
10
 
11
11
  class List
12
12
  include Mongoid::Document
@@ -8,10 +8,13 @@ class Category
8
8
  # field :pos, :type => Integer
9
9
  # acts_as_list :column => :pos
10
10
 
11
- references_many :categories
11
+ #many should below in, or we will get:
12
+ #NoMethodError:
13
+ # undefined method `entries' for #<Category:0x9acbaa8>
12
14
  referenced_in :category
15
+ references_many :categories
13
16
 
14
17
  def scope_condition
15
18
  {:category_id => category.id, :pos.ne => nil}
16
19
  end
17
- end
20
+ end
@@ -1,23 +1,21 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ require 'spec_helper'
2
2
 
3
- require 'acts_as_list_mongoid'
3
+ ActsAsList::Mongoid.default_position_column = :pos
4
4
  require 'embedded_item'
5
5
 
6
- ActsAsList::Mongoid.default_position_column = :pos
6
+ describe 'ActsAsList for Mongoid' do
7
7
 
8
- describe 'ActsAsList for Mongoid' do
9
-
10
- before :each do
8
+ before :each do
11
9
  @list = List.create!
12
10
  @list.items = []
13
- (1..4).each do |counter|
11
+ (1..4).each do |counter|
14
12
  @list.items << Item.new(:number => counter)
15
13
  end
16
14
  @list.save!
17
-
15
+
18
16
  @list.items.init_list!
19
- end
20
-
17
+ end
18
+
21
19
  after :each do
22
20
  Mongoid.database.collections.each do |coll|
23
21
  coll.remove
@@ -25,71 +23,71 @@ describe 'ActsAsList for Mongoid' do
25
23
  end
26
24
 
27
25
  def get_positions list
28
- list.items.sort { |x,y| x.my_position <=> y.my_position }.map(&:number)
26
+ list.items.sort { |x,y| x.my_position <=> y.my_position }.map(&:number)
29
27
  end
30
-
28
+
31
29
  context "4 list items (1,2,3,4) that have parent_id pointing to first list container" do
32
30
  describe '# initial configuration' do
33
- it "should list items 1 to 4 in order" do
31
+ it "should list items 1 to 4 in order" do
34
32
  positions = get_positions @list
35
33
  positions.should == [1, 2, 3, 4]
36
- end
34
+ end
37
35
  end
38
-
36
+
39
37
  describe '#reordering' do
40
38
  it "should move item 2 to position 3" do
41
39
  @list.items[1].increment_position
42
- @list.items[2].decrement_position
40
+ @list.items[2].decrement_position
43
41
  get_positions(@list).should == [1, 3, 2, 4]
44
42
  end
45
-
46
-
47
- it "should move item 2 to position 3" do
43
+
44
+
45
+ it "should move item 2 to position 3" do
48
46
  @list.items.where(:number => 2).first.move_lower
49
47
  get_positions(@list).should == [1, 3, 2, 4]
50
48
  end
51
49
 
52
- it "move :down should move item 2 to position 3" do
50
+ it "move :down should move item 2 to position 3" do
53
51
  @list.items.where(:number => 2).first.move(:down)
54
52
  get_positions(@list).should == [1, 3, 2, 4]
55
53
  end
56
54
 
57
- it "move :lower should move item 2 to position 3" do
55
+ it "move :lower should move item 2 to position 3" do
58
56
  @list.items.where(:number => 2).first.move(:lower)
59
57
  get_positions(@list).should == [1, 3, 2, 4]
60
58
  end
61
-
62
- it "should move item 2 to position 1" do
59
+
60
+ it "should move item 2 to position 1" do
63
61
  @list.items.where(:number => 2).first.move_higher
64
- get_positions(@list).should == [2, 1, 3, 4]
65
- end
62
+ get_positions(@list).should == [2, 1, 3, 4]
63
+ end
66
64
 
67
- it "move :up should move item 2 to position 1" do
65
+ it "move :up should move item 2 to position 1" do
68
66
  @list.items.where(:number => 2).first.move(:up)
69
- get_positions(@list).should == [2, 1, 3, 4]
70
- end
67
+ get_positions(@list).should == [2, 1, 3, 4]
68
+ end
71
69
 
72
- it "move :higher should move item 2 to position 1" do
70
+ it "move :higher should move item 2 to position 1" do
73
71
  @list.items.where(:number => 2).first.move(:higher)
74
- get_positions(@list).should == [2, 1, 3, 4]
75
- end
76
-
77
- it "should move item 1 to bottom" do
72
+ get_positions(@list).should == [2, 1, 3, 4]
73
+ end
74
+
75
+ it "should move item 1 to bottom" do
78
76
  @list.items.where(:number => 1).first.move_to_bottom
79
- get_positions(@list).should == [2, 3, 4, 1]
77
+ get_positions(@list).should == [2, 3, 4, 1]
80
78
  end
81
79
 
82
- it "move :lowest should move item 1 to bottom" do
80
+ it "move :lowest should move item 1 to bottom" do
83
81
  @list.items.where(:number => 1).first.move(:lowest)
84
82
  get_positions(@list).should == [2, 3, 4, 1]
85
83
  end
86
-
87
- it "should move item 1 to top" do
84
+
85
+ it "should move item 1 to top" do
88
86
  @list.items.where(:number => 1).first.move_to_top
89
87
  get_positions(@list).should == [1, 2, 3, 4]
90
88
  end
91
89
 
92
- it "move :highest should move item 1 to top" do
90
+ it "move :highest should move item 1 to top" do
93
91
  @list.items.where(:number => 1).first.move(:highest)
94
92
  get_positions(@list).should == [1, 2, 3, 4]
95
93
  end
@@ -98,82 +96,80 @@ describe 'ActsAsList for Mongoid' do
98
96
  lambda {@list.items.where(:number => 1).first.move(:unknown)}.should raise_error
99
97
  end
100
98
 
101
-
102
- it "should move item 2 to bottom" do
99
+ it "should move item 2 to bottom" do
103
100
  @list.items.where(:number => 2).first.move_to_bottom
104
- get_positions(@list).should == [1, 3, 4, 2]
101
+ get_positions(@list).should == [1, 3, 4, 2]
105
102
  end
106
-
107
- it "should move item 4 to top" do
103
+
104
+ it "should move item 4 to top" do
108
105
  @list.items.where(:number => 4).first.move_to_top
109
- get_positions(@list).should == [4, 1, 2, 3]
110
- end
111
-
106
+ get_positions(@list).should == [4, 1, 2, 3]
107
+ end
108
+
112
109
  it "should move item 3 to bottom" do
113
110
  @list.items.where(:number => 3).first.move_to_bottom
114
- get_positions(@list).should == [1, 2, 4, 3]
115
-
116
- end
111
+ get_positions(@list).should == [1, 2, 4, 3]
112
+ end
117
113
 
118
- it "items[2].move_to(4) should move item 2 to position 4" do
114
+ it "items[2].move_to(4) should move item 2 to position 4" do
119
115
  @list.items.where(:number => 2).first.move_to(4)
120
- get_positions(@list).should == [1, 3, 4, 2]
121
- end
116
+ get_positions(@list).should == [1, 3, 4, 2]
117
+ end
122
118
 
123
- it "items[2].insert_at(3) should move item 2 to position 3" do
119
+ it "items[2].insert_at(3) should move item 2 to position 3" do
124
120
  @list.items.where(:number => 2).first.insert_at(3)
125
- get_positions(@list).should == [1, 3, 2, 4]
121
+ get_positions(@list).should == [1, 3, 2, 4]
126
122
  end
127
123
 
128
- it "items[2].move(:to => 3) should move item 2 to position 3" do
129
- @list.items.where(:number => 2).first.move(:to => 3)
130
- get_positions(@list).should == [1, 3, 2, 4]
124
+ it "items[2].move(:to => 3) should move item 2 to position 3" do
125
+ @list.items.where(:number => 2).first.move(:to => 3
126
+ get_positions(@list).should == [1, 3, 2, 4]
131
127
  end
132
128
 
133
- it "items[1].move_below(item[2]) should move item 1 to position 2" do
129
+ it "items[1].move_below(item[2]) should move item 1 to position 2" do
134
130
  item2 = @list.items.where(:number => 2).first
135
131
  @list.items.where(:number => 1).first.move_below(item2)
136
- get_positions(@list).should == [2, 1, 3, 4]
132
+ get_positions(@list).should == [2, 1, 3, 4]
137
133
  end
138
134
 
139
- it "items[3].move_below(item[1]) should move item 3 to position 2" do
135
+ it "items[3].move_below(item[1]) should move item 3 to position 2" do
140
136
  item1 = @list.items.where(:number => 1).first
141
137
  @list.items.where(:number => 3).first.move_below(item1)
142
- get_positions(@list).should == [1, 3, 2, 4]
138
+ get_positions(@list).should == [1, 3, 2, 4]
143
139
  end
144
140
 
145
- it "items[3].move_above(item[2]) should move item 3 to position 2" do
141
+ it "items[3].move_above(item[2]) should move item 3 to position 2" do
146
142
  item2 = @list.items.where(:number => 2).first
147
143
  @list.items.where(:number => 3).first.move_above(item2)
148
- get_positions(@list).should == [1, 3, 2, 4]
144
+ get_positions(@list).should == [1, 3, 2, 4]
149
145
  end
150
146
 
151
- it "items[1].move_above(item[3]) should move item 1 to position 2" do
147
+ it "items[1].move_above(item[3]) should move item 1 to position 2" do
152
148
  item3 = @list.items.where(:number => 3).first
153
149
  @list.items.where(:number => 1).first.move_above(item3)
154
- get_positions(@list).should == [2, 1, 3, 4]
150
+ get_positions(@list).should == [2, 1, 3, 4]
155
151
  end
156
152
 
157
153
  end
158
-
154
+
159
155
  describe 'relative position queries' do
160
156
  it "should find item 2 to be lower item of item 1" do
161
157
  expected = @list.items.where(:pos => 2).first
162
158
  @list.items.where(:pos => 1).first.lower_item.should == expected
163
159
  end
164
-
160
+
165
161
  it "should not find any item higher than nr 1" do
166
162
  @list.items.where(:pos => 1).first.higher_item.should == nil
167
163
  end
168
-
169
- it "should find item 3 to be higher item of item 4" do
164
+
165
+ it "should find item 3 to be higher item of item 4" do
170
166
  expected = @list.items.where(:pos => 3).first
171
167
  @list.items.where(:pos => 4).first.higher_item.should == expected
172
168
  end
173
-
174
- it "should not find item lower than item 4" do
169
+
170
+ it "should not find item lower than item 4" do
175
171
  @list.items.where(:pos => 4).first.lower_item.should == nil
176
172
  end
177
- end
173
+ end
178
174
  end
179
175
  end
@@ -1,10 +1,10 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ require 'spec_helper'
2
2
 
3
- require 'acts_as_list_mongoid'
3
+ ActsAsList::Mongoid.default_position_column = :pos
4
4
  require 'referenced_category'
5
5
 
6
6
  describe 'ActsAsList for Mongoid' do
7
-
7
+
8
8
  before :each do
9
9
  @category = Category.create!
10
10
  @category.categories = []
@@ -12,20 +12,20 @@ describe 'ActsAsList for Mongoid' do
12
12
  @category.categories << Category.new(:number => counter)
13
13
  end
14
14
  @category.save!
15
-
15
+
16
16
  @category.categories.init_list!
17
17
  end
18
-
18
+
19
19
  after :each do
20
20
  Mongoid.database.collections.each do |coll|
21
21
  coll.remove
22
22
  end
23
23
  end
24
24
 
25
- def get_positions category
25
+ def get_positions(category)
26
26
  category.reload.categories.sort { |x,y| x.my_position <=> y.my_position }.map(&:number)
27
27
  end
28
-
28
+
29
29
  context "4 category categories (1,2,3,4) that have parent_id pointing to first category container" do
30
30
  describe '# initial configuration' do
31
31
  it "should category categories 1 to 4 in order" do
@@ -33,15 +33,15 @@ describe 'ActsAsList for Mongoid' do
33
33
  positions.should == [1, 2, 3, 4]
34
34
  end
35
35
  end
36
-
36
+
37
37
  describe '#reordering' do
38
38
  it "should move item 2 to position 3" do
39
39
  @category.categories[1].increment_position
40
40
  @category.categories[2].decrement_position
41
41
  get_positions(@category).should == [1, 3, 2, 4]
42
42
  end
43
-
44
-
43
+
44
+
45
45
  it "should move item 2 to position 3 directly" do
46
46
  Category.where(:number => 2).first.move_lower
47
47
  get_positions(@category).should == [1, 3, 2, 4]
@@ -56,7 +56,7 @@ describe 'ActsAsList for Mongoid' do
56
56
  Category.where(:number => 2).first.move(:lower)
57
57
  get_positions(@category).should == [1, 3, 2, 4]
58
58
  end
59
-
59
+
60
60
  it "should move item 2 to position 1" do
61
61
  Category.where(:number => 2).first.move_higher
62
62
  get_positions(@category).should == [2, 1, 3, 4]
@@ -71,7 +71,7 @@ describe 'ActsAsList for Mongoid' do
71
71
  Category.where(:number => 2).first.move(:higher)
72
72
  get_positions(@category).should == [2, 1, 3, 4]
73
73
  end
74
-
74
+
75
75
  it "should move item 1 to bottom" do
76
76
  Category.where(:number => 1).first.move_to_bottom
77
77
  get_positions(@category).should == [2, 3, 4, 1]
@@ -81,7 +81,7 @@ describe 'ActsAsList for Mongoid' do
81
81
  Category.where(:number => 1).first.move(:lowest)
82
82
  get_positions(@category).should == [2, 3, 4, 1]
83
83
  end
84
-
84
+
85
85
  it "should move item 1 to top" do
86
86
  Category.where(:number => 1).first.move_to_top
87
87
  get_positions(@category).should == [1, 2, 3, 4]
@@ -96,21 +96,19 @@ describe 'ActsAsList for Mongoid' do
96
96
  lambda {Category.where(:number => 1).first.move(:unknown)}.should raise_error
97
97
  end
98
98
 
99
-
100
99
  it "should move item 2 to bottom" do
101
100
  Category.where(:number => 2).first.move_to_bottom
102
101
  get_positions(@category).should == [1, 3, 4, 2]
103
102
  end
104
-
103
+
105
104
  it "should move item 4 to top" do
106
105
  Category.where(:number => 4).first.move_to_top
107
106
  get_positions(@category).should == [4, 1, 2, 3]
108
107
  end
109
-
108
+
110
109
  it "should move item 3 to bottom" do
111
110
  Category.where(:number => 3).first.move_to_bottom
112
111
  get_positions(@category).should == [1, 2, 4, 3]
113
-
114
112
  end
115
113
 
116
114
  it "categories[2].move_to(4) should move item 2 to position 4" do
@@ -153,25 +151,25 @@ describe 'ActsAsList for Mongoid' do
153
151
  end
154
152
 
155
153
  end
156
-
154
+
157
155
  describe 'relative position queries' do
158
156
  it "should find item 2 to be lower item of item 1" do
159
157
  expected = Category.where(:pos => 2).first
160
158
  Category.where(:pos => 1).first.lower_item.should == expected
161
159
  end
162
-
160
+
163
161
  it "should not find any item higher than nr 1" do
164
162
  Category.where(:pos => 1).first.higher_item.should == nil
165
163
  end
166
-
164
+
167
165
  it "should find item 3 to be higher item of item 4" do
168
166
  expected = Category.where(:pos => 3).first
169
167
  Category.where(:pos => 4).first.higher_item.should == expected
170
168
  end
171
-
169
+
172
170
  it "should not find item lower than item 4" do
173
171
  Category.where(:pos => 4).first.lower_item.should == nil
174
172
  end
175
173
  end
176
174
  end
177
- end
175
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,10 +2,12 @@ require 'rspec'
2
2
  require 'rspec/autorun'
3
3
  require 'mongoid'
4
4
  require 'mongoid_embedded_helper'
5
- require 'mongoid_adjust'
5
+ # require 'mongoid_adjust'
6
+ require 'acts_as_list_mongoid'
7
+
6
8
 
7
9
  $:.unshift "#{File.dirname(__FILE__)}/../model/"
8
-
10
+
9
11
  Mongoid.configure.master = Mongo::Connection.new.db('acts_as_list-test')
10
12
 
11
13
 
metadata CHANGED
@@ -1,67 +1,114 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: acts_as_list_mongoid
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 2
8
- - 2
9
- version: 0.2.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.4
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Kristian Mandrup
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-11-27 00:00:00 +01:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2011-09-30 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: mongoid
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2154755760 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 2
30
- - 0
31
- - 0
32
- - beta
33
- - 14
34
- version: 2.0.0.beta.14
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.1
35
22
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: mongoid_embedded_helper
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2154755760
25
+ - !ruby/object:Gem::Dependency
26
+ name: mongoid_embedded_helper
27
+ requirement: &2154754820 !ruby/object:Gem::Requirement
41
28
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- segments:
46
- - 0
47
- - 2
48
- - 5
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
49
32
  version: 0.2.5
50
33
  type: :runtime
51
- version_requirements: *id002
52
- description: |-
53
- Make your Mongoid model acts as a list. This acts_as extension provides the capabilities for sorting and reordering a number of objects in a list.
54
- The instances that take part in the list should have a +position+ field of type Integer.
34
+ prerelease: false
35
+ version_requirements: *2154754820
36
+ - !ruby/object:Gem::Dependency
37
+ name: shoulda
38
+ requirement: &2154747620 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2154747620
47
+ - !ruby/object:Gem::Dependency
48
+ name: cutter
49
+ requirement: &2154745540 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2154745540
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ requirement: &2154743880 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '2.5'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2154743880
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: &2154742360 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 1.0.10
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *2154742360
80
+ - !ruby/object:Gem::Dependency
81
+ name: jeweler
82
+ requirement: &2154739580 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 1.6.4
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *2154739580
91
+ - !ruby/object:Gem::Dependency
92
+ name: rcov
93
+ requirement: &2154727240 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *2154727240
102
+ description: ! "Make your Mongoid model acts as a list. This acts_as extension provides
103
+ the capabilities for sorting and reordering a number of objects in a list.\n The
104
+ instances that take part in the list should have a +position+ field of type Integer."
55
105
  email: kmandrup@gmail.com
56
106
  executables: []
57
-
58
107
  extensions: []
59
-
60
- extra_rdoc_files:
108
+ extra_rdoc_files:
61
109
  - README.markdown
62
- files:
110
+ files:
63
111
  - .DS_Store
64
- - .gitignore
65
112
  - .rspec
66
113
  - Gemfile
67
114
  - README.markdown
@@ -80,39 +127,31 @@ files:
80
127
  - spec/acts_as_list/embedded_item_spec.rb
81
128
  - spec/acts_as_list/referenced_category_spec.rb
82
129
  - spec/spec_helper.rb
83
- has_rdoc: true
84
130
  homepage: http://github.com/rails/acts_as_list
85
131
  licenses: []
86
-
87
132
  post_install_message:
88
- rdoc_options:
89
- - --charset=UTF-8
90
- require_paths:
133
+ rdoc_options: []
134
+ require_paths:
91
135
  - lib
92
- required_ruby_version: !ruby/object:Gem::Requirement
136
+ required_ruby_version: !ruby/object:Gem::Requirement
93
137
  none: false
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- segments:
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ segments:
98
143
  - 0
99
- version: "0"
100
- required_rubygems_version: !ruby/object:Gem::Requirement
144
+ hash: 101423400668737337
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
146
  none: false
102
- requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- segments:
106
- - 0
107
- version: "0"
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
108
151
  requirements: []
109
-
110
152
  rubyforge_project:
111
- rubygems_version: 1.3.7
153
+ rubygems_version: 1.8.10
112
154
  signing_key:
113
155
  specification_version: 3
114
156
  summary: acts_as_list for Mongoid
115
- test_files:
116
- - spec/acts_as_list/embedded_item_spec.rb
117
- - spec/acts_as_list/referenced_category_spec.rb
118
- - spec/spec_helper.rb
157
+ test_files: []