dm-persevere-adapter 0.45.0 → 0.46.0

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.45.0
1
+ 0.46.0
@@ -2,7 +2,7 @@ module DataMapper
2
2
  module Model
3
3
  # module Json
4
4
  def to_json_schema(repository_name = default_repository_name)
5
- to_json_schema_compatible_hash(repository_name, prefix).to_json
5
+ to_json_schema_compatible_hash(repository_name).to_json
6
6
  end
7
7
 
8
8
  #TODO: Add various options in.
@@ -12,7 +12,7 @@ module DataMapper
12
12
  schema_hash['id'] = self.storage_name(repository_name)
13
13
  properties_hash = {}
14
14
  usable_properties.each do |p|
15
- properties_hash[p.name] = p.to_json_schema_hash(repository_name)
15
+ properties_hash[p.field] = p.to_json_schema_hash(repository_name)
16
16
  end
17
17
  schema_hash['properties'] = properties_hash
18
18
  schema_hash['prototype'] = {}
@@ -147,7 +147,7 @@ module DataMapper
147
147
  if success = create_model_storage(model)
148
148
  return properties
149
149
  end
150
-
150
+
151
151
  new_schema_hash = model.to_json_schema_compatible_hash()
152
152
  current_schema_hash = get_schema(new_schema_hash['id'])[0]
153
153
  # Diff of what is there and what will be added.
@@ -157,7 +157,7 @@ module DataMapper
157
157
  prop_type = property.type
158
158
  next if prop_name == 'id' ||
159
159
  (current_schema_hash['properties'].has_key?(prop_name) &&
160
- new_schema_hash['properties'][prop_name.to_sym]['type'] == current_schema_hash['properties'][prop_name]['type'] )
160
+ new_schema_hash['properties'][prop_name]['type'] == current_schema_hash['properties'][prop_name]['type'] )
161
161
  property
162
162
  end.compact
163
163
 
@@ -640,7 +640,7 @@ module DataMapper
640
640
  # without regular expressions, the like operator is inordinately challenging hence we pass it back
641
641
  # when :regexp then "RegExp(\"#{condition.value.source}\").test(#{condition.subject.name})"
642
642
  when DataMapper::Query::Conditions::RegexpComparison then []
643
- when DataMapper::Query::Conditions::LikeComparison then "#{condition.subject.name.to_s}='#{condition.loaded_value.gsub('%', '*')}'"
643
+ when DataMapper::Query::Conditions::LikeComparison then "#{condition.subject.field}='#{condition.loaded_value.gsub('%', '*')}'"
644
644
  when DataMapper::Query::Conditions::AndOperation then
645
645
  inside = condition.operands.map { |op| process_condition(op) }.flatten
646
646
  inside.empty? ? [] : "(#{inside.join("&")})"
@@ -655,7 +655,7 @@ module DataMapper
655
655
  cond = "\"#{cond}\"" if cond.is_a?(String)
656
656
  cond = "date(%10.f)" % (Time.parse(cond.to_s).to_f * 1000) if cond.is_a?(DateTime)
657
657
  cond = 'undefined' if cond.nil?
658
- "#{condition.subject.name.to_s}=#{cond}"
658
+ "#{condition.subject.field}=#{cond}"
659
659
  when DataMapper::Query::Conditions::NullOperation then []
660
660
  when Array then
661
661
  old_statement, bind_values = condition
@@ -684,29 +684,29 @@ module DataMapper
684
684
  field_ops << case field.operator
685
685
  when :count then
686
686
  if field.target.is_a?(DataMapper::Property)
687
- "[?#{field.target.name}!=undefined].length"
687
+ "[?#{field.target.field}!=undefined].length"
688
688
  else # field.target is all.
689
689
  ".length"
690
690
  end
691
691
  when :min
692
692
  if field.target.type == DateTime || field.target.type == Time || field.target.type == Date
693
- "[=#{field.target.name}]"
693
+ "[=#{field.target.field}]"
694
694
  else
695
- ".min(?#{field.target.name})"
695
+ ".min(?#{field.target.field})"
696
696
  end
697
697
  when :max
698
698
  if field.target.type == DateTime || field.target.type == Time || field.target.type == Date
699
- "[=#{field.target.name}]"
699
+ "[=#{field.target.field}]"
700
700
  else
701
- ".max(?#{field.target.name})"
701
+ ".max(?#{field.target.field})"
702
702
  end
703
703
  when :sum
704
- ".sum(?#{field.target.name})"
704
+ ".sum(?#{field.target.field})"
705
705
  when :avg
706
- "[=#{field.target.name}]"
706
+ "[=#{field.target.field}]"
707
707
  end
708
708
  else
709
- fields << "'#{field.name}':#{field.name}"
709
+ fields << "'#{field.field}':#{field.field}"
710
710
  end
711
711
  end
712
712
 
@@ -47,6 +47,13 @@ describe DataMapper::Adapters::PersevereAdapter do
47
47
  property :name, String
48
48
  end
49
49
 
50
+ class ::Pantsarator
51
+ include DataMapper::Resource
52
+
53
+ property :id, String, :key => true
54
+ property :pants, Boolean, :field => 'trousers'
55
+ end
56
+
50
57
  @test_schema_hash = {
51
58
  'id' => 'Vanilla',
52
59
  'properties' => {
@@ -231,6 +238,7 @@ describe DataMapper::Adapters::PersevereAdapter do
231
238
  before(:each) do
232
239
  Bozon.auto_migrate!
233
240
  Mukatron.auto_migrate!
241
+ Pantsarator.auto_migrate!
234
242
  end
235
243
 
236
244
  it "should find simple strings" do
@@ -279,9 +287,22 @@ describe DataMapper::Adapters::PersevereAdapter do
279
287
  Mukatron.all(:fields => [:b8te]).length.should == 2
280
288
  end
281
289
 
290
+ it "should works with fields and properties that have different names" do
291
+ Pantsarator.create(:id => 'pants', :pants => true)
292
+ Pantsarator.create(:id => 'underware', :pants => false)
293
+
294
+ result = @adapter.get_schema("pantsarator")
295
+ result.should_not be_false
296
+ result[0]['properties'].keys.should include('trousers')
297
+
298
+ Pantsarator.all(:pants => true).length.should eql 1
299
+
300
+ end
301
+
282
302
  after(:all) do
283
303
  Bozon.auto_migrate_down!
284
304
  Mukatron.auto_migrate_down!
305
+ Pantsarator.auto_migrate_down!
285
306
  end
286
307
  end
287
308
 
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 45
7
+ - 46
8
8
  - 0
9
- version: 0.45.0
9
+ version: 0.46.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ivan R. Judson