dm-ambition 1.0.0 → 1.1.0.rc1
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.
- data/Gemfile +77 -0
- data/LICENSE +1 -1
- data/README.rdoc +15 -6
- data/Rakefile +3 -9
- data/TODO +13 -0
- data/dm-ambition.gemspec +70 -56
- data/lib/dm-ambition/collection.rb +18 -48
- data/lib/dm-ambition/model.rb +1 -0
- data/lib/dm-ambition/query/filter_processor.rb +149 -255
- data/lib/dm-ambition/query.rb +4 -5
- data/lib/dm-ambition/version.rb +1 -1
- data/lib/dm-ambition.rb +7 -0
- data/spec/public/collection_spec.rb +102 -68
- data/spec/public/model_spec.rb +8 -11
- data/spec/public/shared/filter_shared_spec.rb +45 -9
- data/spec/semipublic/query_spec.rb +283 -67
- data/spec/spec_helper.rb +9 -41
- data/tasks/local_gemfile.rake +16 -0
- data/tasks/spec.rake +0 -3
- metadata +82 -63
- data/.gitignore +0 -35
@@ -18,32 +18,97 @@ require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
|
18
18
|
property :admin, Boolean, :default => false
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
DataMapper.auto_migrate!
|
23
|
-
end
|
21
|
+
@model = User
|
24
22
|
end
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@query = DataMapper::Query.new(@repository, @model)
|
24
|
+
supported_by :all do
|
25
|
+
before :all do
|
26
|
+
@query = DataMapper::Query.new(@repository, @model)
|
30
27
|
|
31
|
-
|
32
|
-
|
28
|
+
@user = @model.create(:name => 'Dan Kubb', :admin => true)
|
29
|
+
@other = @model.create(:name => 'Sam Smoot')
|
33
30
|
|
34
|
-
|
35
|
-
|
36
|
-
|
31
|
+
@subject = @model.all(@query)
|
32
|
+
@subject.to_a if loaded
|
33
|
+
end
|
34
|
+
|
35
|
+
it_should_behave_like 'it has public filter methods'
|
36
|
+
|
37
|
+
unless loaded
|
38
|
+
[ :select, :find_all ].each do |method|
|
39
|
+
describe "##{method}", '(unloaded)' do
|
40
|
+
context 'when matching resource prepended' do
|
41
|
+
before :all do
|
42
|
+
@other.update(:admin => true)
|
43
|
+
@subject.unshift(@other)
|
44
|
+
@return = @subject.send(method) { |u| u.admin == true }
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should return a Collection' do
|
48
|
+
@return.should be_kind_of(DataMapper::Collection)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should not return self' do
|
52
|
+
@return.should_not equal(@subject)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should not be a kicker' do
|
56
|
+
@return.should_not be_loaded
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should return expected values' do
|
60
|
+
@return.should == [ @other, @user ]
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should include the exact prepended resource' do
|
64
|
+
@return.first.should equal(@other)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should return the same as Array##{method}" do
|
68
|
+
@return.should == @subject.to_a.send(method) { |u| u.admin == true }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'when matching resource appended' do
|
73
|
+
before :all do
|
74
|
+
@other.update(:admin => true)
|
75
|
+
@subject << @other
|
76
|
+
@return = @subject.send(method) { |u| u.admin == true }
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should return a Collection' do
|
80
|
+
@return.should be_kind_of(DataMapper::Collection)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should not return self' do
|
84
|
+
@return.should_not equal(@subject)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should not be a kicker' do
|
88
|
+
@return.should_not be_loaded
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should return expected values' do
|
92
|
+
@return.should == [ @user, @other ]
|
93
|
+
end
|
37
94
|
|
38
|
-
|
95
|
+
it 'should include the exact appended resource' do
|
96
|
+
@return.last.should equal(@other)
|
97
|
+
end
|
39
98
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
99
|
+
it "should return the same as Array##{method}" do
|
100
|
+
@return.should == @subject.to_a.send(method) { |u| u.admin == true }
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe '#reject', '(unloaded)' do
|
107
|
+
context 'when matching resource prepended' do
|
44
108
|
before :all do
|
109
|
+
@other.update(:admin => true)
|
45
110
|
@subject.unshift(@other)
|
46
|
-
@return = @subject.
|
111
|
+
@return = @subject.reject { |u| u.admin != true }
|
47
112
|
end
|
48
113
|
|
49
114
|
it 'should return a Collection' do
|
@@ -59,14 +124,23 @@ require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
|
59
124
|
end
|
60
125
|
|
61
126
|
it 'should return expected values' do
|
62
|
-
@return.should == [ @user ]
|
127
|
+
@return.should == [ @other, @user ]
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should include the exact prepended resource' do
|
131
|
+
@return.first.should equal(@other)
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'should return the same as Array#reject' do
|
135
|
+
@return.should == @subject.to_a.reject { |u| u.admin != true }
|
63
136
|
end
|
64
137
|
end
|
65
138
|
|
66
|
-
|
139
|
+
context 'when matching resource appended' do
|
67
140
|
before :all do
|
141
|
+
@other.update(:admin => true)
|
68
142
|
@subject << @other
|
69
|
-
@return = @subject.
|
143
|
+
@return = @subject.reject { |u| u.admin != true }
|
70
144
|
end
|
71
145
|
|
72
146
|
it 'should return a Collection' do
|
@@ -82,56 +156,16 @@ require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
|
82
156
|
end
|
83
157
|
|
84
158
|
it 'should return expected values' do
|
85
|
-
@return.should == [ @user ]
|
159
|
+
@return.should == [ @user, @other ]
|
86
160
|
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe '#reject', '(unloaded)' do
|
92
|
-
describe 'when matching resource prepended' do
|
93
|
-
before :all do
|
94
|
-
@subject.unshift(@other)
|
95
|
-
@return = @subject.reject { |u| u.admin != true }
|
96
|
-
end
|
97
161
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
it 'should not return self' do
|
103
|
-
@return.should_not equal(@subject)
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'should not be a kicker' do
|
107
|
-
@return.should_not be_loaded
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'should return expected values' do
|
111
|
-
@return.should == [ @user ]
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
describe 'when matching resource appended' do
|
116
|
-
before :all do
|
117
|
-
@subject << @other
|
118
|
-
@return = @subject.reject { |u| u.admin != true }
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'should return a Collection' do
|
122
|
-
@return.should be_kind_of(DataMapper::Collection)
|
123
|
-
end
|
124
|
-
|
125
|
-
it 'should not return self' do
|
126
|
-
@return.should_not equal(@subject)
|
127
|
-
end
|
128
|
-
|
129
|
-
it 'should not be a kicker' do
|
130
|
-
@return.should_not be_loaded
|
131
|
-
end
|
162
|
+
it 'should include the exact appended resource' do
|
163
|
+
@return.last.should equal(@other)
|
164
|
+
end
|
132
165
|
|
133
|
-
|
134
|
-
|
166
|
+
it 'should return the same as Array#reject' do
|
167
|
+
@return.should == @subject.to_a.reject { |u| u.admin != true }
|
168
|
+
end
|
135
169
|
end
|
136
170
|
end
|
137
171
|
end
|
data/spec/public/model_spec.rb
CHANGED
@@ -15,20 +15,17 @@ describe DataMapper::Ambition::Model do
|
|
15
15
|
property :admin, Boolean, :default => false
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
DataMapper.auto_migrate!
|
20
|
-
end
|
18
|
+
@model = User
|
21
19
|
end
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
supported_by :all do
|
22
|
+
before :all do
|
23
|
+
@user = @model.create(:name => 'Dan Kubb', :admin => true)
|
24
|
+
@other = @model.create(:name => 'Sam Smoot')
|
26
25
|
|
27
|
-
|
28
|
-
|
26
|
+
@subject = @model
|
27
|
+
end
|
29
28
|
|
30
|
-
|
29
|
+
it_should_behave_like 'it has public filter methods'
|
31
30
|
end
|
32
|
-
|
33
|
-
it_should_behave_like 'it has public filter methods'
|
34
31
|
end
|
@@ -3,7 +3,7 @@ share_examples_for 'it has public filter methods' do
|
|
3
3
|
it { @subject.should respond_to(method) }
|
4
4
|
|
5
5
|
describe "##{method}", ('(loaded)' if loaded) do
|
6
|
-
|
6
|
+
context 'with simple conditions' do
|
7
7
|
before :all do
|
8
8
|
@return = @subject.send(method) { |u| u.name == 'Dan Kubb' }
|
9
9
|
end
|
@@ -25,9 +25,13 @@ share_examples_for 'it has public filter methods' do
|
|
25
25
|
it 'should return expected values' do
|
26
26
|
@return.should == [ @user ]
|
27
27
|
end
|
28
|
+
|
29
|
+
it "should return the same as Array##{method}" do
|
30
|
+
@return.should == @subject.to_a.send(method) { |u| u.name == 'Dan Kubb' }
|
31
|
+
end
|
28
32
|
end
|
29
33
|
|
30
|
-
|
34
|
+
context 'with OR + AND conditions' do
|
31
35
|
before :all do
|
32
36
|
@return = @subject.send(method) { |u| (u.name == 'Dan Kubb' || u.name == 'Sam Smoot') && u.admin == true }
|
33
37
|
end
|
@@ -49,9 +53,13 @@ share_examples_for 'it has public filter methods' do
|
|
49
53
|
it 'should return expected values' do
|
50
54
|
@return.should == [ @user ]
|
51
55
|
end
|
56
|
+
|
57
|
+
it "should return the same as Array##{method}" do
|
58
|
+
@return.should == @subject.to_a.send(method) { |u| (u.name == 'Dan Kubb' || u.name == 'Sam Smoot') && u.admin == true }
|
59
|
+
end
|
52
60
|
end
|
53
61
|
|
54
|
-
|
62
|
+
context 'with AND + OR conditions' do
|
55
63
|
before :all do
|
56
64
|
@return = @subject.send(method) { |u| (u.admin == true && u.name == 'Dan Kubb') || u.name == 'Sam Smoot' }
|
57
65
|
end
|
@@ -73,6 +81,10 @@ share_examples_for 'it has public filter methods' do
|
|
73
81
|
it 'should return expected values' do
|
74
82
|
@return.should == [ @user, @other ]
|
75
83
|
end
|
84
|
+
|
85
|
+
it "should return the same as Array##{method}" do
|
86
|
+
@return.should == @subject.to_a.send(method) { |u| (u.admin == true && u.name == 'Dan Kubb') || u.name == 'Sam Smoot' }
|
87
|
+
end
|
76
88
|
end
|
77
89
|
end
|
78
90
|
end
|
@@ -81,7 +93,7 @@ share_examples_for 'it has public filter methods' do
|
|
81
93
|
it { @subject.should respond_to(method) }
|
82
94
|
|
83
95
|
describe "##{method}", ('(loaded)' if loaded) do
|
84
|
-
|
96
|
+
context 'with simple conditions' do
|
85
97
|
before :all do
|
86
98
|
@return = @subject.send(method) { |u| u.name == 'Dan Kubb' }
|
87
99
|
end
|
@@ -99,9 +111,13 @@ share_examples_for 'it has public filter methods' do
|
|
99
111
|
it 'should return expected value' do
|
100
112
|
@return.should == @user
|
101
113
|
end
|
114
|
+
|
115
|
+
it "should return the same as Array##{method}" do
|
116
|
+
@return.should == @subject.to_a.send(method) { |u| u.name == 'Dan Kubb' }
|
117
|
+
end
|
102
118
|
end
|
103
119
|
|
104
|
-
|
120
|
+
context 'with OR + AND conditions' do
|
105
121
|
before :all do
|
106
122
|
@return = @subject.send(method) { |u| (u.name == 'Dan Kubb' || u.name == 'Sam Smoot') && u.admin == true }
|
107
123
|
end
|
@@ -119,9 +135,13 @@ share_examples_for 'it has public filter methods' do
|
|
119
135
|
it 'should return expected value' do
|
120
136
|
@return.should == @user
|
121
137
|
end
|
138
|
+
|
139
|
+
it "should return the same as Array##{method}" do
|
140
|
+
@return.should == @subject.to_a.send(method) { |u| (u.name == 'Dan Kubb' || u.name == 'Sam Smoot') && u.admin == true }
|
141
|
+
end
|
122
142
|
end
|
123
143
|
|
124
|
-
|
144
|
+
context 'with AND + OR conditions' do
|
125
145
|
before :all do
|
126
146
|
@return = @subject.send(method) { |u| (u.admin == true && u.name == 'Dan Kubb') || u.name == 'Sam Smoot' }
|
127
147
|
end
|
@@ -139,6 +159,10 @@ share_examples_for 'it has public filter methods' do
|
|
139
159
|
it 'should return expected value' do
|
140
160
|
@return.should == @user
|
141
161
|
end
|
162
|
+
|
163
|
+
it "should return the same as Array##{method}" do
|
164
|
+
@return.should == @subject.to_a.send(method) { |u| (u.admin == true && u.name == 'Dan Kubb') || u.name == 'Sam Smoot' }
|
165
|
+
end
|
142
166
|
end
|
143
167
|
end
|
144
168
|
end
|
@@ -146,7 +170,7 @@ share_examples_for 'it has public filter methods' do
|
|
146
170
|
it { @subject.should respond_to(:reject) }
|
147
171
|
|
148
172
|
describe '#reject', ('(loaded)' if loaded) do
|
149
|
-
|
173
|
+
context 'with simple conditions' do
|
150
174
|
before :all do
|
151
175
|
@return = @subject.reject { |u| u.name != 'Dan Kubb' }
|
152
176
|
end
|
@@ -168,9 +192,13 @@ share_examples_for 'it has public filter methods' do
|
|
168
192
|
it 'should return expected values' do
|
169
193
|
@return.should == [ @user ]
|
170
194
|
end
|
195
|
+
|
196
|
+
it 'should return the same as Array#reject' do
|
197
|
+
@return.should == @subject.to_a.reject { |u| u.name != 'Dan Kubb' }
|
198
|
+
end
|
171
199
|
end
|
172
200
|
|
173
|
-
|
201
|
+
context 'with OR + AND conditions' do
|
174
202
|
before :all do
|
175
203
|
@return = @subject.reject { |u| (u.name == 'Dan Kubb' || u.name == 'Sam Smoot') && u.admin == true }
|
176
204
|
end
|
@@ -192,9 +220,13 @@ share_examples_for 'it has public filter methods' do
|
|
192
220
|
it 'should return expected values' do
|
193
221
|
@return.should == [ @other ]
|
194
222
|
end
|
223
|
+
|
224
|
+
it 'should return the same as Array#reject' do
|
225
|
+
@return.should == @subject.to_a.reject { |u| (u.name == 'Dan Kubb' || u.name == 'Sam Smoot') && u.admin == true }
|
226
|
+
end
|
195
227
|
end
|
196
228
|
|
197
|
-
|
229
|
+
context 'with AND + OR conditions' do
|
198
230
|
before :all do
|
199
231
|
@return = @subject.reject { |u| (u.admin == true && u.name == 'Dan Kubb') || u.name == 'Sam Smoot' }
|
200
232
|
end
|
@@ -216,6 +248,10 @@ share_examples_for 'it has public filter methods' do
|
|
216
248
|
it 'should return expected values' do
|
217
249
|
@return.should == []
|
218
250
|
end
|
251
|
+
|
252
|
+
it 'should return the same as Array#reject' do
|
253
|
+
@return.should == @subject.to_a.reject { |u| (u.admin == true && u.name == 'Dan Kubb') || u.name == 'Sam Smoot' }
|
254
|
+
end
|
219
255
|
end
|
220
256
|
end
|
221
257
|
end
|