datamapper 0.2.5 → 0.3.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/CHANGELOG +5 -1
- data/FAQ +96 -0
- data/QUICKLINKS +12 -0
- data/README +57 -155
- data/environment.rb +61 -43
- data/example.rb +30 -12
- data/lib/data_mapper.rb +6 -1
- data/lib/data_mapper/adapters/abstract_adapter.rb +0 -57
- data/lib/data_mapper/adapters/data_object_adapter.rb +203 -97
- data/lib/data_mapper/adapters/mysql_adapter.rb +4 -0
- data/lib/data_mapper/adapters/postgresql_adapter.rb +7 -1
- data/lib/data_mapper/adapters/sql/coersion.rb +3 -2
- data/lib/data_mapper/adapters/sql/commands/load_command.rb +29 -10
- data/lib/data_mapper/adapters/sql/mappings/associations_set.rb +4 -0
- data/lib/data_mapper/adapters/sql/mappings/column.rb +13 -9
- data/lib/data_mapper/adapters/sql/mappings/conditions.rb +172 -0
- data/lib/data_mapper/adapters/sql/mappings/table.rb +43 -17
- data/lib/data_mapper/adapters/sqlite3_adapter.rb +9 -2
- data/lib/data_mapper/associations.rb +75 -3
- data/lib/data_mapper/associations/belongs_to_association.rb +70 -36
- data/lib/data_mapper/associations/has_and_belongs_to_many_association.rb +195 -86
- data/lib/data_mapper/associations/has_many_association.rb +168 -61
- data/lib/data_mapper/associations/has_n_association.rb +23 -3
- data/lib/data_mapper/attributes.rb +73 -0
- data/lib/data_mapper/auto_migrations.rb +2 -6
- data/lib/data_mapper/base.rb +5 -9
- data/lib/data_mapper/database.rb +4 -3
- data/lib/data_mapper/embedded_value.rb +66 -30
- data/lib/data_mapper/identity_map.rb +1 -3
- data/lib/data_mapper/is/tree.rb +121 -0
- data/lib/data_mapper/migration.rb +155 -0
- data/lib/data_mapper/persistence.rb +532 -218
- data/lib/data_mapper/property.rb +306 -0
- data/lib/data_mapper/query.rb +164 -0
- data/lib/data_mapper/support/blank.rb +2 -2
- data/lib/data_mapper/support/connection_pool.rb +5 -6
- data/lib/data_mapper/support/enumerable.rb +3 -3
- data/lib/data_mapper/support/errors.rb +10 -1
- data/lib/data_mapper/support/inflector.rb +174 -238
- data/lib/data_mapper/support/object.rb +54 -0
- data/lib/data_mapper/support/serialization.rb +19 -1
- data/lib/data_mapper/support/string.rb +7 -16
- data/lib/data_mapper/support/symbol.rb +3 -15
- data/lib/data_mapper/support/typed_set.rb +68 -0
- data/lib/data_mapper/types/base.rb +44 -0
- data/lib/data_mapper/types/string.rb +34 -0
- data/lib/data_mapper/validations/number_validator.rb +40 -0
- data/lib/data_mapper/validations/string_validator.rb +20 -0
- data/lib/data_mapper/validations/validator.rb +13 -0
- data/performance.rb +26 -1
- data/profile_data_mapper.rb +1 -1
- data/rakefile.rb +42 -2
- data/spec/acts_as_tree_spec.rb +11 -3
- data/spec/adapters/data_object_adapter_spec.rb +31 -0
- data/spec/associations/belongs_to_association_spec.rb +98 -0
- data/spec/associations/has_and_belongs_to_many_association_spec.rb +377 -0
- data/spec/associations/has_many_association_spec.rb +337 -0
- data/spec/attributes_spec.rb +23 -1
- data/spec/auto_migrations_spec.rb +86 -29
- data/spec/callbacks_spec.rb +107 -0
- data/spec/column_spec.rb +5 -2
- data/spec/count_command_spec.rb +33 -1
- data/spec/database_spec.rb +18 -0
- data/spec/dependency_spec.rb +4 -2
- data/spec/embedded_value_spec.rb +8 -8
- data/spec/fixtures/people.yaml +1 -1
- data/spec/fixtures/projects.yaml +10 -1
- data/spec/fixtures/tasks.yaml +6 -0
- data/spec/fixtures/tasks_tasks.yaml +2 -0
- data/spec/fixtures/tomatoes.yaml +1 -0
- data/spec/is_a_tree_spec.rb +149 -0
- data/spec/load_command_spec.rb +71 -9
- data/spec/magic_columns_spec.rb +17 -2
- data/spec/migration_spec.rb +267 -0
- data/spec/models/animal.rb +1 -1
- data/spec/models/candidate.rb +8 -0
- data/spec/models/career.rb +1 -1
- data/spec/models/chain.rb +8 -0
- data/spec/models/comment.rb +1 -1
- data/spec/models/exhibit.rb +1 -1
- data/spec/models/fence.rb +7 -0
- data/spec/models/fruit.rb +2 -2
- data/spec/models/job.rb +8 -0
- data/spec/models/person.rb +2 -3
- data/spec/models/post.rb +1 -1
- data/spec/models/project.rb +21 -1
- data/spec/models/section.rb +1 -1
- data/spec/models/serializer.rb +1 -1
- data/spec/models/task.rb +9 -0
- data/spec/models/tomato.rb +27 -0
- data/spec/models/user.rb +8 -2
- data/spec/models/zoo.rb +2 -7
- data/spec/paranoia_spec.rb +1 -1
- data/spec/{base_spec.rb → persistence_spec.rb} +207 -18
- data/spec/postgres_spec.rb +48 -6
- data/spec/property_spec.rb +90 -9
- data/spec/query_spec.rb +71 -5
- data/spec/save_command_spec.rb +11 -0
- data/spec/spec_helper.rb +14 -11
- data/spec/support/blank_spec.rb +8 -0
- data/spec/support/inflector_spec.rb +41 -0
- data/spec/support/object_spec.rb +9 -0
- data/spec/{serialization_spec.rb → support/serialization_spec.rb} +1 -1
- data/spec/support/silence_spec.rb +15 -0
- data/spec/{support_spec.rb → support/string_spec.rb} +3 -3
- data/spec/support/struct_spec.rb +12 -0
- data/spec/support/typed_set_spec.rb +66 -0
- data/spec/table_spec.rb +3 -3
- data/spec/types/string.rb +81 -0
- data/spec/validates_uniqueness_of_spec.rb +17 -0
- data/spec/validations/number_validator.rb +59 -0
- data/spec/validations/string_validator.rb +14 -0
- metadata +59 -17
- data/do_performance.rb +0 -153
- data/lib/data_mapper/support/active_record_impersonation.rb +0 -103
- data/lib/data_mapper/support/weak_hash.rb +0 -46
- data/spec/active_record_impersonation_spec.rb +0 -129
- data/spec/associations_spec.rb +0 -232
- data/spec/conditions_spec.rb +0 -49
- data/spec/has_many_association_spec.rb +0 -173
- data/spec/models/animals_exhibit.rb +0 -8
data/spec/conditions_spec.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
-
|
3
|
-
describe DataMapper::Adapters::Sql::Commands::LoadCommand do
|
4
|
-
|
5
|
-
def conditions_for(klass, options = {})
|
6
|
-
database_context = database(:mock)
|
7
|
-
DataMapper::Adapters::Sql::Commands::LoadCommand.new(
|
8
|
-
database_context.adapter, database_context, klass, options
|
9
|
-
).conditions
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'empty? should be false if conditions are present' do
|
13
|
-
conditions_for(Zoo, :name => 'Galveston').should_not be_empty
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should map implicit option names to field names' do
|
17
|
-
conditions_for(Zoo, :name => 'Galveston').should eql([["`name` = ?", 'Galveston']])
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'should qualify with table name when using a join' do
|
21
|
-
conditions_for(Zoo, :name => 'Galveston', :include => :exhibits).should eql([["`zoos`.`name` = ?", 'Galveston']])
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'should use Symbol::Operator to determine operator' do
|
25
|
-
conditions_for(Person, :age.gt => 28).should eql([["`age` > ?", 28]])
|
26
|
-
conditions_for(Person, :age.gte => 28).should eql([["`age` >= ?", 28]])
|
27
|
-
|
28
|
-
conditions_for(Person, :age.lt => 28).should eql([["`age` < ?", 28]])
|
29
|
-
conditions_for(Person, :age.lte => 28).should eql([["`age` <= ?", 28]])
|
30
|
-
|
31
|
-
conditions_for(Person, :age.not => 28).should eql([["`age` <> ?", 28]])
|
32
|
-
conditions_for(Person, :age.eql => 28).should eql([["`age` = ?", 28]])
|
33
|
-
|
34
|
-
conditions_for(Person, :name.like => 'S%').should eql([["`name` LIKE ?", 'S%']])
|
35
|
-
|
36
|
-
conditions_for(Person, :age.in => [ 28, 29 ]).should eql([["`age` IN ?", [ 28, 29 ]]])
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'should use an IN clause for an Array' do
|
40
|
-
conditions_for(Person, :age => [ 28, 29 ]).should eql([["`age` IN ?", [ 28, 29 ]]])
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should use "not" for not-equal operations' do
|
44
|
-
conditions_for(Person, :name.not => 'Bob').should eql([["`name` <> ?", 'Bob']])
|
45
|
-
conditions_for(Person, :name.not => nil).should eql([["`name` IS NOT ?", nil]])
|
46
|
-
conditions_for(Person, :name.not => ['Sam', 'Bob']).should eql([["`name` NOT IN ?", ['Sam', 'Bob']]])
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
@@ -1,173 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
-
|
3
|
-
describe DataMapper::Associations::HasManyAssociation do
|
4
|
-
|
5
|
-
before(:all) do
|
6
|
-
fixtures(:zoos)
|
7
|
-
fixtures(:exhibits)
|
8
|
-
fixtures(:fruit)
|
9
|
-
fixtures(:animals)
|
10
|
-
end
|
11
|
-
|
12
|
-
after(:all) do
|
13
|
-
fixtures(:fruit)
|
14
|
-
fixtures(:animals)
|
15
|
-
end
|
16
|
-
|
17
|
-
before(:each) do
|
18
|
-
@zoo = Zoo.new(:name => "ZOO")
|
19
|
-
@zoo.save
|
20
|
-
end
|
21
|
-
|
22
|
-
after(:each) do
|
23
|
-
@zoo.destroy!
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should return an empty Enumerable for new objects" do
|
27
|
-
project = Project.new
|
28
|
-
project.sections.should be_a_kind_of(Enumerable)
|
29
|
-
project.sections.should be_empty
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should display correctly when inspected" do
|
33
|
-
Zoo.first(:name => 'Dallas').exhibits.inspect.should match(/\#\<Exhibit\:0x.{7}/)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should lazily-load the association when Enumerable methods are called' do
|
37
|
-
database do |db|
|
38
|
-
san_diego = Zoo.first(:name => 'San Diego')
|
39
|
-
san_diego.exhibits.size.should == 2
|
40
|
-
san_diego.exhibits.should include(Exhibit.first(:name => 'Monkey Mayhem'))
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'should eager-load associations for an entire set' do
|
45
|
-
database do
|
46
|
-
zoos = Zoo.all
|
47
|
-
zoos.each do |zoo|
|
48
|
-
zoo.exhibits.each do |exhibit|
|
49
|
-
exhibit.zoo.should == zoo
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should be dirty even when clean objects are associated" do
|
56
|
-
zoo = Zoo.first(:name => 'New York')
|
57
|
-
zoo.exhibits << Exhibit.first
|
58
|
-
zoo.should be_dirty
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should proxy associations on the associated type" do
|
62
|
-
Zoo.first(:name => 'Miami').exhibits.animals.size.should == 1
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should have a valid zoo setup for testing" do
|
66
|
-
@zoo.should be_valid
|
67
|
-
@zoo.should_not be_a_new_record
|
68
|
-
@zoo.id.should_not be_nil
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should generate the SQL for a join statement" do
|
72
|
-
exhibits_association = database(:mock).schema[Zoo].associations.find { |a| a.name == :exhibits }
|
73
|
-
|
74
|
-
exhibits_association.to_sql.should == <<-EOS.compress_lines
|
75
|
-
JOIN `exhibits` ON `exhibits`.`zoo_id` = `zoos`.`id`
|
76
|
-
EOS
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should add an item to an association" do
|
80
|
-
bear = Exhibit.new( :name => "Bear")
|
81
|
-
@zoo.exhibits << bear
|
82
|
-
@zoo.exhibits.should include(bear)
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should build a new item" do
|
86
|
-
bear = @zoo.exhibits.build( :name => "Bear" )
|
87
|
-
bear.should be_kind_of(Exhibit)
|
88
|
-
@zoo.exhibits.should include(bear)
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should not save the item when building" do
|
92
|
-
bear = @zoo.exhibits.build( :name => "Bear" )
|
93
|
-
bear.should be_new_record
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should create a new item" do
|
97
|
-
bear = @zoo.exhibits.create( :name => "Bear" )
|
98
|
-
bear.should be_kind_of(Exhibit)
|
99
|
-
@zoo.exhibits.should include(bear)
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should save the item when creating" do
|
103
|
-
bear = @zoo.exhibits.create( :name => "Bear" )
|
104
|
-
bear.should_not be_new_record
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should set the association to a saved target when added with <<" do
|
108
|
-
pirahna = Exhibit.new(:name => "Pirahna")
|
109
|
-
pirahna.zoo_id.should be_nil
|
110
|
-
|
111
|
-
@zoo.exhibits << pirahna
|
112
|
-
pirahna.zoo.should == @zoo
|
113
|
-
end
|
114
|
-
|
115
|
-
it "should set the association to a non-saved target when added with <<" do
|
116
|
-
zoo = Zoo.new(:name => "My Zoo")
|
117
|
-
kangaroo = Exhibit.new(:name => "Kangaroo")
|
118
|
-
zoo.exhibits << kangaroo
|
119
|
-
kangaroo.zoo.should == zoo
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should set the id of the exhibit when the associated zoo is saved" do
|
123
|
-
snake = Exhibit.new(:name => "Snake")
|
124
|
-
@zoo.exhibits << snake
|
125
|
-
@zoo.save
|
126
|
-
@zoo.id.should == snake.zoo_id
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should set the id of an already saved exibit if it's added to a different zoo" do
|
130
|
-
beaver = Exhibit.new(:name => "Beaver")
|
131
|
-
beaver.save
|
132
|
-
beaver.should_not be_a_new_record
|
133
|
-
@zoo.exhibits << beaver
|
134
|
-
@zoo.save
|
135
|
-
beaver.zoo.should == @zoo
|
136
|
-
beaver.zoo_id.should == @zoo.id
|
137
|
-
end
|
138
|
-
|
139
|
-
it "should set the size of the assocation" do
|
140
|
-
@zoo.exhibits << Exhibit.new(:name => "anonymous")
|
141
|
-
@zoo.exhibits.size.should == 1
|
142
|
-
end
|
143
|
-
|
144
|
-
it "should give the association when an inspect is done on it" do
|
145
|
-
whale = Exhibit.new(:name => "Whale")
|
146
|
-
@zoo.exhibits << whale
|
147
|
-
@zoo.exhibits.should_not == "nil"
|
148
|
-
@zoo.exhibits.inspect.should_not be_nil
|
149
|
-
end
|
150
|
-
|
151
|
-
it "should generate the SQL for a join statement" do
|
152
|
-
fruit_association = database(:mock).schema[Animal].associations.find { |a| a.name == :favourite_fruit }
|
153
|
-
|
154
|
-
fruit_association.to_sql.should == <<-EOS.compress_lines
|
155
|
-
JOIN `fruit` ON `fruit`.`devourer_id` = `animals`.`id`
|
156
|
-
EOS
|
157
|
-
end
|
158
|
-
|
159
|
-
it "is assigned a devourer_id" do
|
160
|
-
bob = Animal.new(:name => 'bob')
|
161
|
-
fruit = Fruit.first
|
162
|
-
bob.favourite_fruit = fruit
|
163
|
-
|
164
|
-
bob.save
|
165
|
-
|
166
|
-
bob.reload!
|
167
|
-
fruit.devourer_id.should eql(bob.id)
|
168
|
-
bob.favourite_fruit.should == fruit
|
169
|
-
|
170
|
-
fruit.reload!
|
171
|
-
fruit.devourer_of_souls.should == bob
|
172
|
-
end
|
173
|
-
end
|
@@ -1,8 +0,0 @@
|
|
1
|
-
# This is just here to get around the fact I use a Class to load
|
2
|
-
# fixtures right now.
|
3
|
-
class AnimalsExhibit #< DataMapper::Base
|
4
|
-
include DataMapper::Persistence
|
5
|
-
|
6
|
-
property :animal_id, :integer, :key => true
|
7
|
-
property :exhibit_id, :integer, :key => true
|
8
|
-
end
|