dm-persevere-adapter 0.41.0 → 0.42.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/persevere_adapter.rb +8 -4
- data/spec/persevere_adapter_spec.rb +32 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.42.0
|
data/lib/persevere_adapter.rb
CHANGED
@@ -387,11 +387,11 @@ module DataMapper
|
|
387
387
|
|
388
388
|
# This won't work if the RegExp is nested more then 1 layer deep.
|
389
389
|
if query.conditions.class == DataMapper::Query::Conditions::AndOperation
|
390
|
-
|
390
|
+
regexp_conds = query.conditions.operands.select{ |obj| obj.is_a?(DataMapper::Query::Conditions::RegexpComparison) ||
|
391
391
|
(obj.is_a?(DataMapper::Query::Conditions::NotOperation) && obj.operand.is_a?(DataMapper::Query::Conditions::RegexpComparison))}
|
392
|
-
|
392
|
+
regexp_conds.each{|cond| resources = resources.select{|resource| cond.matches?(resource)} }
|
393
393
|
|
394
|
-
|
394
|
+
end
|
395
395
|
# query.match_records(resources)
|
396
396
|
resources
|
397
397
|
end
|
@@ -706,7 +706,11 @@ module DataMapper
|
|
706
706
|
"[=#{field.target.name}]"
|
707
707
|
end
|
708
708
|
else
|
709
|
-
|
709
|
+
if field.name.to_s.match(/\d/) != nil
|
710
|
+
fields << "'#{field.name}':'#{field.name}'"
|
711
|
+
else
|
712
|
+
fields << "#{field.name}:#{field.name}"
|
713
|
+
end
|
710
714
|
end
|
711
715
|
end
|
712
716
|
|
@@ -38,6 +38,15 @@ describe DataMapper::Adapters::PersevereAdapter do
|
|
38
38
|
property :name, String
|
39
39
|
end
|
40
40
|
|
41
|
+
class ::Mukatron
|
42
|
+
include DataMapper::Resource
|
43
|
+
|
44
|
+
property :id, Serial
|
45
|
+
property :street1, String
|
46
|
+
property :b8te, String
|
47
|
+
property :name, String
|
48
|
+
end
|
49
|
+
|
41
50
|
@test_schema_hash = {
|
42
51
|
'id' => 'Vanilla',
|
43
52
|
'properties' => {
|
@@ -221,6 +230,7 @@ describe DataMapper::Adapters::PersevereAdapter do
|
|
221
230
|
describe 'finding models' do
|
222
231
|
before(:each) do
|
223
232
|
Bozon.auto_migrate!
|
233
|
+
Mukatron.auto_migrate!
|
224
234
|
end
|
225
235
|
|
226
236
|
it "should find simple strings" do
|
@@ -243,8 +253,30 @@ describe DataMapper::Adapters::PersevereAdapter do
|
|
243
253
|
Bozon.all(:created_at => time).length.should eql(1)
|
244
254
|
end
|
245
255
|
|
256
|
+
it "should be able to pull one field" do
|
257
|
+
Bozon.create(:title => 'Story')
|
258
|
+
Bozon.create(:title => 'Tail')
|
259
|
+
Bozon.all(:fields => [:title]).length.should == 2
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should retrieve properties that end in a number" do
|
263
|
+
Mukatron.create(:street1 => "11th", :b8te => 'true', :name => 'Porky')
|
264
|
+
Mukatron.create(:street1 => "12th", :b8te => 'false', :name => 'Porky')
|
265
|
+
Mukatron.all.length.should == 2
|
266
|
+
Mukatron.all(:fields => [:id,:street1]).length.should == 2
|
267
|
+
end
|
268
|
+
require 'ruby-debug'
|
269
|
+
it "should retrieve properties that have a number in the middle" do
|
270
|
+
Mukatron.create(:street1 => "11th", :b8te => 'true', :name => 'Porky')
|
271
|
+
Mukatron.create(:street1 => "12th", :b8te => 'false', :name => 'Porky')
|
272
|
+
# /mukatron/[/id][={'b8te':'b8te'}]
|
273
|
+
debugger
|
274
|
+
Mukatron.all(:fields => [:b8te]).length.should == 2
|
275
|
+
end
|
276
|
+
|
246
277
|
after(:all) do
|
247
278
|
Bozon.auto_migrate_down!
|
279
|
+
Mukatron.auto_migrate_down!
|
248
280
|
end
|
249
281
|
end
|
250
282
|
end
|