public
Rubygem
Description: Extras for DataMapper, including bridges to DataObjects::Migrations and Merb::DataMapper
Homepage: http://datamapper.org
Clone URL: git://github.com/sam/dm-more.git
Updated :initial to be converted to a string, to keep databases happy, and 
to make behavior consistent.
Tue Jul 22 10:33:30 -0700 2008
Aadithya Deshpande (committer)
Tue Jul 22 14:17:49 -0700 2008
commit  d56396603a99c0355b4b6d8fec649cd7f997c984
tree    c8dd9a26501cd464335b944b95eb823a53fea523
parent  5bc8aec61d07d063bcd52f503872b2cc9d67bbb8
...
54
55
56
 
 
57
58
59
...
54
55
56
57
58
59
60
61
0
@@ -54,6 +54,8 @@ module DataMapper
0
               aggregate_field_statement(repository, property.operator, property.target, qualify)
0
             when Property
0
               original_property_to_column_name(repository, property, qualify)
0
+ when Query::Path
0
+ original_property_to_column_name(repository, property, qualify)
0
             else
0
               raise ArgumentError, "+property+ must be a DataMapper::Query::Operator or a DataMapper::Property, but was a #{property.class} (#{property.inspect})"
0
           end
...
5
6
7
 
 
 
 
 
 
 
8
9
10
...
15
16
17
 
 
18
19
 
20
21
22
...
31
32
33
34
 
35
36
37
38
39
40
41
 
 
 
 
 
42
43
44
...
306
307
308
309
 
 
 
 
 
 
 
 
310
311
...
5
6
7
8
9
10
11
12
13
14
15
16
17
...
22
23
24
25
26
27
28
29
30
31
32
...
41
42
43
 
44
45
46
47
48
49
 
 
50
51
52
53
54
55
56
57
...
319
320
321
 
322
323
324
325
326
327
328
329
330
331
0
@@ -5,6 +5,13 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
0
   describe 'DataMapper::Resource' do
0
     before :all do
0
       # A simplistic example, using with an Integer property
0
+ class Knight
0
+ include DataMapper::Resource
0
+
0
+ property :id, Serial
0
+ property :name, String
0
+ end
0
+
0
       class Dragon
0
         include DataMapper::Resource
0
 
0
@@ -15,8 +22,11 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
0
         property :birth_at, DateTime
0
         property :birth_on, Date
0
         property :birth_time, Time
0
+
0
+ belongs_to :knight
0
       end
0
 
0
+
0
       # A more complex example, with BigDecimal and Float properties
0
       # Statistics taken from CIA World Factbook:
0
       # https://www.cia.gov/library/publications/the-world-factbook/
0
@@ -31,14 +41,17 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
0
         property :gold_reserve_value, BigDecimal, :precision => 15, :scale => 1 # approx. value in USD
0
       end
0
 
0
- [ Dragon, Country ].each { |m| m.auto_migrate! }
0
+ [ Dragon, Country, Knight ].each { |m| m.auto_migrate! }
0
 
0
       @birth_at = DateTime.now
0
       @birth_on = Date.parse(@birth_at.to_s)
0
       @birth_time = Time.parse(@birth_at.to_s)
0
 
0
- Dragon.create(:name => 'George', :is_fire_breathing => false, :toes_on_claw => 3, :birth_at => @birth_at, :birth_on => @birth_on, :birth_time => @birth_time)
0
- Dragon.create(:name => 'Puff', :is_fire_breathing => true, :toes_on_claw => 4, :birth_at => @birth_at, :birth_on => @birth_on, :birth_time => @birth_time)
0
+ @chuck = Knight.create( :name => 'Chuck' )
0
+ @larry = Knight.create( :name => 'Larry')
0
+
0
+ Dragon.create(:name => 'George', :is_fire_breathing => false, :toes_on_claw => 3, :birth_at => @birth_at, :birth_on => @birth_on, :birth_time => @birth_time, :knight => @chuck )
0
+ Dragon.create(:name => 'Puff', :is_fire_breathing => true, :toes_on_claw => 4, :birth_at => @birth_at, :birth_on => @birth_on, :birth_time => @birth_time, :knight => @larry )
0
       Dragon.create(:name => nil, :is_fire_breathing => true, :toes_on_claw => 5, :birth_at => nil, :birth_on => nil, :birth_time => nil)
0
 
0
       gold_kilo_price = 277738.70
0
@@ -306,6 +319,13 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
0
           end
0
         end
0
       end
0
- end
0
+
0
+ describe "query path issue" do
0
+ it "should not break when a query path is specified" do
0
+ dragon = Dragon.first(Dragon.knight.name => 'Chuck')
0
+ dragon.name.should == 'George'
0
+ end
0
+ end
0
+ end
0
   end
0
 end
...
31
32
33
34
 
35
36
37
...
31
32
33
 
34
35
36
37
0
@@ -31,7 +31,7 @@ module DataMapper
0
         # ===== Setup context =====
0
         options = { :column => :state, :initial => nil }.merge(options)
0
         column = options[:column]
0
- initial = options[:initial]
0
+ initial = options[:initial].to_s
0
         unless properties.detect { |p| p.name == column }
0
           property column, String, :default => initial
0
         end
...
21
22
23
24
 
25
26
27
...
45
46
47
48
 
49
50
51
...
99
100
101
102
 
103
104
105
...
21
22
23
 
24
25
26
27
...
45
46
47
 
48
49
50
51
...
99
100
101
 
102
103
104
105
0
@@ -21,7 +21,7 @@ describe TrafficLight do
0
   end
0
 
0
   it "should start off in the green state" do
0
- @t.color.should == :green
0
+ @t.color.should == "green"
0
   end
0
 
0
   it "should allow the color to be set" do
0
@@ -45,7 +45,7 @@ describe TrafficLight do
0
     end
0
 
0
     it "should transition to :yellow, :red, :green" do
0
- @t.color.should == :green
0
+ @t.color.should == "green"
0
       @t.forward!
0
       @t.color.should == "yellow"
0
       @t.log.should == %w(G Y)
0
@@ -99,7 +99,7 @@ describe TrafficLight do
0
     end
0
 
0
     it "should transition to :red, :yellow, :green" do
0
- @t.color.should == :green
0
+ @t.color.should == "green"
0
       @t.log.should == %w(G)
0
       @t.backward!
0
       @t.color.should == "red"

Comments

  • dkubb Tue Jul 22 15:51:02 -0700 2008

    Whoa, not to be too picky, but the indent formatting for some of this patch is way off.