dm-persevere-adapter 0.60.1 → 0.60.2

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.60.1
1
+ 0.60.2
data/lib/dm/model.rb CHANGED
@@ -27,19 +27,20 @@ module DataMapper
27
27
  case relation
28
28
  when DataMapper::Associations::OneToMany::Relationship, DataMapper::Associations::ManyToMany::Relationship
29
29
  schema_hash['properties'][nom] = { "type" => "array",
30
+ "lazy" => true,
30
31
  "optional" => true,
31
- "items" => {"$ref" => "../#{child.storage_name}"},
32
+ "items" => {"$ref" => "/Class/#{child.storage_name}"},
32
33
  "minItems" => relation.min,
33
34
  }
34
35
 
35
36
  schema_hash['properties'][nom]["maxItems"] = relation.max if relation.max != Infinity
36
37
  when DataMapper::Associations::ManyToOne::Relationship, DataMapper::Associations::OneToOne::Relationship
37
38
  if self == relation.child_model
38
- ref = "../#{parent.storage_name}"
39
+ ref = "/Class/#{parent.storage_name}"
39
40
  else
40
- ref = "../#{child.storage_name}"
41
+ ref = "/Class/#{child.storage_name}"
41
42
  end
42
- schema_hash['properties'][nom] = { "type" => { "$ref" => ref }, "optional" => true }
43
+ schema_hash['properties'][nom] = { "type" => { "$ref" => ref }, "lazy" => true, "optional" => true }
43
44
  end
44
45
  end
45
46
  return schema_hash
data/lib/dm/query.rb CHANGED
@@ -21,18 +21,27 @@ module DataMapper
21
21
 
22
22
  def _fugly_munger(condition, loaded_value)
23
23
  subject = condition.subject
24
+
24
25
  case subject
25
26
  when DataMapper::Associations::ManyToMany::Relationship then
26
27
  return_value = "#{condition.subject.field}.contains(/#{subject.child_model.storage_name}/#{loaded_value.key.first})"
27
28
  when DataMapper::Associations::OneToMany::Relationship then
28
29
  return_value = "#{condition.subject.field}.contains(/#{subject.parent_model.storage_name}/#{loaded_value.key.first})"
29
30
  when DataMapper::Associations::OneToOne::Relationship then
30
- return_value = "#{condition.subject.field}#{condition.__send__(:comparator_string)}/#{subject.parent_model.storage_name}/#{loaded_value.key.first}"
31
+ if loaded_value.nil?
32
+ return_value = "#{condition.subject.field}#{condition.__send__(:comparator_string)}undefined"
33
+ else
34
+ return_value = "#{condition.subject.field}#{condition.__send__(:comparator_string)}/#{subject.parent_model.storage_name}/#{loaded_value.key.first}"
35
+ end
31
36
  when DataMapper::Associations::ManyToOne::Relationship then
32
37
  if self.model != subject.child_model
33
38
  return_value = "#{condition.subject.field}.contains(/#{subject.parent_model.storage_name}/#{loaded_value.key.first})"
34
39
  else
35
- return_value = "#{condition.subject.field}#{condition.__send__(:comparator_string)}/#{subject.parent_model.storage_name}/#{loaded_value.key.first}"
40
+ if loaded_value.nil?
41
+ return_value = "#{condition.subject.field}#{condition.__send__(:comparator_string)}undefined"
42
+ else
43
+ return_value = "#{condition.subject.field}#{condition.__send__(:comparator_string)}/#{subject.parent_model.storage_name}/#{loaded_value.key.first}"
44
+ end
36
45
  end
37
46
  end
38
47
  end
@@ -268,6 +268,7 @@ module DataMapper
268
268
  # We might want to make this a post-to_json_hash cleanup instead
269
269
  payload = resource.to_json_hash(false)
270
270
  # scrub_data(payload)
271
+ DataMapper.logger.debug("--> PATH/PAYLOAD: #{path} #{payload.inspect}")
271
272
  response = @persevere.create(path, payload)
272
273
 
273
274
  # Check the response, this needs to be more robust and raise
@@ -331,6 +332,7 @@ module DataMapper
331
332
  path = "/#{tblname}/#{resource.key.first}"
332
333
  payload = resource.to_json_hash()
333
334
  # scrub_data(payload)
335
+ DataMapper.logger.debug("--> PATH/PAYLOAD: #{path} #{payload.inspect}")
334
336
  result = @persevere.update(path, payload)
335
337
 
336
338
  if result.code == "200"
@@ -9,9 +9,6 @@ require agg_dir / 'spec' / 'public' / 'shared' / 'aggregate_shared_spec'
9
9
 
10
10
  require Pathname(__FILE__).dirname.expand_path.parent + 'lib/persevere_adapter'
11
11
 
12
- require 'ruby-debug'
13
- Debugger.start
14
-
15
12
  describe DataMapper::Adapters::PersevereAdapter do
16
13
  before :all do
17
14
  DataMapper::Logger.new(STDOUT, :debug)
@@ -395,6 +392,28 @@ describe DataMapper::Adapters::PersevereAdapter do
395
392
  Nugaton.first.bozon.id.should eql bozon.id
396
393
  end
397
394
 
395
+ it "should not be required to be in a relationship" do
396
+ Bozon.has(Infinity, :nugatons)
397
+ Nugaton.belongs_to(:bozon, :required => false)
398
+
399
+ Bozon.auto_upgrade!
400
+ Nugaton.auto_upgrade!
401
+
402
+ bozon = Bozon.create(:author => 'Jade', :title => "Jade's the author")
403
+
404
+ nugat1 = Nugaton.new(:name => "numero uno")
405
+ nugat2 = Nugaton.new(:name => "numero duo")
406
+
407
+ bozon.nugatons.push( nugat1 )
408
+ bozon.save
409
+
410
+ nugat2.save
411
+
412
+ Nugaton.all(:bozon => bozon).length.should eql 1
413
+ Nugaton.all(:bozon => nil).length.should eql 1
414
+
415
+ end
416
+
398
417
  it "should create one to many (has n) associations between models" do
399
418
  Bozon.has(Infinity, :nugatons)
400
419
  Nugaton.belongs_to(:bozon)
@@ -499,5 +518,6 @@ describe DataMapper::Adapters::PersevereAdapter do
499
518
 
500
519
  Bozon.first.nugatons.length.should be(1)
501
520
  end
521
+
502
522
  end
503
523
  end
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,10 @@ require 'pathname'
2
2
  require 'rubygems'
3
3
  require 'addressable/uri'
4
4
  require 'spec'
5
-
5
+
6
+ require 'ruby-debug'
7
+ Debugger.start
8
+
6
9
  require 'dm-core'
7
10
 
8
11
  def path_to(gem_name, version=nil)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 60
8
- - 1
9
- version: 0.60.1
8
+ - 2
9
+ version: 0.60.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ivan R. Judson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-02 00:00:00 -06:00
18
+ date: 2010-06-08 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency