datamapper 0.3.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +0 -0
- data/Manifest.txt +5 -0
- data/README.txt +11 -0
- data/Rakefile +70 -0
- data/lib/datamapper.rb +8 -0
- metadata +152 -319
- data/CHANGELOG +0 -145
- data/FAQ +0 -96
- data/MIT-LICENSE +0 -22
- data/QUICKLINKS +0 -12
- data/README +0 -105
- data/environment.rb +0 -62
- data/example.rb +0 -156
- data/lib/data_mapper.rb +0 -88
- data/lib/data_mapper/adapters/abstract_adapter.rb +0 -43
- data/lib/data_mapper/adapters/data_object_adapter.rb +0 -480
- data/lib/data_mapper/adapters/mysql_adapter.rb +0 -72
- data/lib/data_mapper/adapters/postgresql_adapter.rb +0 -258
- data/lib/data_mapper/adapters/sql/coersion.rb +0 -134
- data/lib/data_mapper/adapters/sql/commands/load_command.rb +0 -545
- data/lib/data_mapper/adapters/sql/mappings/associations_set.rb +0 -34
- data/lib/data_mapper/adapters/sql/mappings/column.rb +0 -279
- data/lib/data_mapper/adapters/sql/mappings/conditions.rb +0 -172
- data/lib/data_mapper/adapters/sql/mappings/schema.rb +0 -60
- data/lib/data_mapper/adapters/sql/mappings/table.rb +0 -459
- data/lib/data_mapper/adapters/sql/quoting.rb +0 -24
- data/lib/data_mapper/adapters/sqlite3_adapter.rb +0 -159
- data/lib/data_mapper/associations.rb +0 -106
- data/lib/data_mapper/associations/belongs_to_association.rb +0 -160
- data/lib/data_mapper/associations/has_and_belongs_to_many_association.rb +0 -437
- data/lib/data_mapper/associations/has_many_association.rb +0 -283
- data/lib/data_mapper/associations/has_n_association.rb +0 -143
- data/lib/data_mapper/associations/reference.rb +0 -47
- data/lib/data_mapper/attributes.rb +0 -73
- data/lib/data_mapper/auto_migrations.rb +0 -36
- data/lib/data_mapper/base.rb +0 -17
- data/lib/data_mapper/callbacks.rb +0 -107
- data/lib/data_mapper/context.rb +0 -112
- data/lib/data_mapper/database.rb +0 -234
- data/lib/data_mapper/dependency_queue.rb +0 -28
- data/lib/data_mapper/embedded_value.rb +0 -145
- data/lib/data_mapper/identity_map.rb +0 -47
- data/lib/data_mapper/is/tree.rb +0 -121
- data/lib/data_mapper/migration.rb +0 -155
- data/lib/data_mapper/persistence.rb +0 -852
- data/lib/data_mapper/property.rb +0 -310
- data/lib/data_mapper/query.rb +0 -164
- data/lib/data_mapper/support/blank.rb +0 -35
- data/lib/data_mapper/support/connection_pool.rb +0 -117
- data/lib/data_mapper/support/enumerable.rb +0 -35
- data/lib/data_mapper/support/errors.rb +0 -16
- data/lib/data_mapper/support/inflector.rb +0 -265
- data/lib/data_mapper/support/object.rb +0 -54
- data/lib/data_mapper/support/serialization.rb +0 -96
- data/lib/data_mapper/support/silence.rb +0 -10
- data/lib/data_mapper/support/string.rb +0 -72
- data/lib/data_mapper/support/struct.rb +0 -7
- data/lib/data_mapper/support/symbol.rb +0 -82
- data/lib/data_mapper/support/typed_set.rb +0 -65
- data/lib/data_mapper/types/base.rb +0 -44
- data/lib/data_mapper/types/string.rb +0 -34
- data/lib/data_mapper/validatable_extensions/errors.rb +0 -12
- data/lib/data_mapper/validatable_extensions/macros.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validatable_instance_methods.rb +0 -62
- data/lib/data_mapper/validatable_extensions/validation_base.rb +0 -18
- data/lib/data_mapper/validatable_extensions/validations/formats/email.rb +0 -43
- data/lib/data_mapper/validatable_extensions/validations/validates_acceptance_of.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_confirmation_of.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_each.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_format_of.rb +0 -28
- data/lib/data_mapper/validatable_extensions/validations/validates_length_of.rb +0 -15
- data/lib/data_mapper/validatable_extensions/validations/validates_numericality_of.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_presence_of.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_true_for.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_uniqueness_of.rb +0 -40
- data/lib/data_mapper/validations.rb +0 -20
- data/lib/data_mapper/validations/number_validator.rb +0 -40
- data/lib/data_mapper/validations/string_validator.rb +0 -20
- data/lib/data_mapper/validations/validator.rb +0 -13
- data/performance.rb +0 -307
- data/plugins/can_has_sphinx/LICENSE +0 -23
- data/plugins/can_has_sphinx/README +0 -4
- data/plugins/can_has_sphinx/REVISION +0 -1
- data/plugins/can_has_sphinx/Rakefile +0 -22
- data/plugins/can_has_sphinx/init.rb +0 -1
- data/plugins/can_has_sphinx/install.rb +0 -1
- data/plugins/can_has_sphinx/lib/acts_as_sphinx.rb +0 -123
- data/plugins/can_has_sphinx/lib/sphinx.rb +0 -460
- data/plugins/can_has_sphinx/scripts/sphinx.sh +0 -47
- data/plugins/can_has_sphinx/tasks/acts_as_sphinx_tasks.rake +0 -41
- data/profile_data_mapper.rb +0 -40
- data/rakefile.rb +0 -159
- data/spec/acts_as_tree_spec.rb +0 -67
- data/spec/adapters/data_object_adapter_spec.rb +0 -31
- data/spec/associations/belongs_to_association_spec.rb +0 -98
- data/spec/associations/has_and_belongs_to_many_association_spec.rb +0 -377
- data/spec/associations/has_many_association_spec.rb +0 -337
- data/spec/attributes_spec.rb +0 -52
- data/spec/auto_migrations_spec.rb +0 -101
- data/spec/callbacks_spec.rb +0 -186
- data/spec/can_has_sphinx.rb +0 -5
- data/spec/coersion_spec.rb +0 -41
- data/spec/column_spec.rb +0 -114
- data/spec/count_command_spec.rb +0 -45
- data/spec/database_spec.rb +0 -18
- data/spec/dataobjects_spec.rb +0 -27
- data/spec/delete_command_spec.rb +0 -11
- data/spec/dependency_spec.rb +0 -29
- data/spec/embedded_value_spec.rb +0 -161
- data/spec/fixtures/animals.yaml +0 -33
- data/spec/fixtures/animals_exhibits.yaml +0 -2
- data/spec/fixtures/careers.yaml +0 -5
- data/spec/fixtures/comments.yaml +0 -1
- data/spec/fixtures/exhibits.yaml +0 -90
- data/spec/fixtures/fruit.yaml +0 -6
- data/spec/fixtures/people.yaml +0 -37
- data/spec/fixtures/posts.yaml +0 -3
- data/spec/fixtures/projects.yaml +0 -13
- data/spec/fixtures/sections.yaml +0 -5
- data/spec/fixtures/serializers.yaml +0 -6
- data/spec/fixtures/tasks.yaml +0 -6
- data/spec/fixtures/tasks_tasks.yaml +0 -2
- data/spec/fixtures/tomatoes.yaml +0 -1
- data/spec/fixtures/users.yaml +0 -1
- data/spec/fixtures/zoos.yaml +0 -24
- data/spec/is_a_tree_spec.rb +0 -149
- data/spec/legacy_spec.rb +0 -16
- data/spec/load_command_spec.rb +0 -322
- data/spec/magic_columns_spec.rb +0 -26
- data/spec/migration_spec.rb +0 -267
- data/spec/mock_adapter.rb +0 -20
- data/spec/models/animal.rb +0 -12
- data/spec/models/candidate.rb +0 -8
- data/spec/models/career.rb +0 -7
- data/spec/models/chain.rb +0 -8
- data/spec/models/comment.rb +0 -6
- data/spec/models/exhibit.rb +0 -14
- data/spec/models/fence.rb +0 -7
- data/spec/models/fruit.rb +0 -8
- data/spec/models/job.rb +0 -8
- data/spec/models/person.rb +0 -30
- data/spec/models/post.rb +0 -14
- data/spec/models/project.rb +0 -41
- data/spec/models/sales_person.rb +0 -5
- data/spec/models/section.rb +0 -8
- data/spec/models/serializer.rb +0 -5
- data/spec/models/task.rb +0 -9
- data/spec/models/tomato.rb +0 -27
- data/spec/models/user.rb +0 -12
- data/spec/models/zoo.rb +0 -13
- data/spec/natural_key_spec.rb +0 -36
- data/spec/paranoia_spec.rb +0 -38
- data/spec/persistence_spec.rb +0 -479
- data/spec/postgres_spec.rb +0 -96
- data/spec/property_spec.rb +0 -151
- data/spec/query_spec.rb +0 -77
- data/spec/save_command_spec.rb +0 -94
- data/spec/schema_spec.rb +0 -8
- data/spec/serialize_spec.rb +0 -19
- data/spec/single_table_inheritance_spec.rb +0 -43
- data/spec/spec_helper.rb +0 -45
- data/spec/support/blank_spec.rb +0 -8
- data/spec/support/inflector_spec.rb +0 -41
- data/spec/support/object_spec.rb +0 -9
- data/spec/support/serialization_spec.rb +0 -61
- data/spec/support/silence_spec.rb +0 -15
- data/spec/support/string_spec.rb +0 -7
- data/spec/support/struct_spec.rb +0 -12
- data/spec/support/typed_set_spec.rb +0 -66
- data/spec/symbolic_operators_spec.rb +0 -27
- data/spec/table_spec.rb +0 -79
- data/spec/types/string.rb +0 -81
- data/spec/validates_confirmation_of_spec.rb +0 -55
- data/spec/validates_format_of_spec.rb +0 -78
- data/spec/validates_length_of_spec.rb +0 -117
- data/spec/validates_uniqueness_of_spec.rb +0 -92
- data/spec/validations/number_validator.rb +0 -59
- data/spec/validations/string_validator.rb +0 -14
- data/spec/validations_spec.rb +0 -141
- data/tasks/fixtures.rb +0 -53
data/spec/fixtures/posts.yaml
DELETED
data/spec/fixtures/projects.yaml
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
---
|
2
|
-
- id: 1
|
3
|
-
title: Test
|
4
|
-
description: test
|
5
|
-
- id: 2
|
6
|
-
title: The Empire State Building
|
7
|
-
description: "The Empire State Building is a 102-story Art Deco skyscraper in New York City, New York"
|
8
|
-
- id: 3
|
9
|
-
title: World Trade Center
|
10
|
-
description: "The World Trade Center in New York City, United States"
|
11
|
-
- id: 4
|
12
|
-
title: The Statue Of Liberty
|
13
|
-
description: "Liberty Enlightening the World (French: La liberte eclairant le monde), known more commonly as the Statue of Liberty"
|
data/spec/fixtures/sections.yaml
DELETED
data/spec/fixtures/tasks.yaml
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
- name: task_relax
|
2
|
-
notes: I am the relaxed task an should be related to task_vacation
|
3
|
-
- name: task_drink_heartily
|
4
|
-
notes: I am the drink heartily task and should be related to task_relax
|
5
|
-
- name: task_vacation
|
6
|
-
notes: I am the vacation task and should be related to task_relax
|
data/spec/fixtures/tomatoes.yaml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--- []
|
data/spec/fixtures/users.yaml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--- []
|
data/spec/fixtures/zoos.yaml
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
- name: Dallas
|
2
|
-
notes: Keep Dallas Pretentious?
|
3
|
-
- name: San Diego
|
4
|
-
- name: Miami
|
5
|
-
- name: Ft. Lauderdale
|
6
|
-
- name: Ft. Worth
|
7
|
-
- name: New Orleans
|
8
|
-
- name: San Antonio
|
9
|
-
notes: The most sprawling city I've ever seen. It's insane.
|
10
|
-
- name: Galveston
|
11
|
-
notes: A friendly place. It's like Hotel California for Houston's homeless though. (No way out without a car.)
|
12
|
-
- name: Austin
|
13
|
-
notes: People in Austin like to drive around with "Save Mother Earth" stickers on their SUVs and proclaim "Keep Austin Weird" while sipping on Starbucks.
|
14
|
-
- name: Brownsville
|
15
|
-
- name: Los Angeles
|
16
|
-
- name: Phillidelphia
|
17
|
-
- name: New York
|
18
|
-
- name: Seattle
|
19
|
-
- name: Houston
|
20
|
-
- name: Corpus Christi
|
21
|
-
- name: Sacramento
|
22
|
-
- name: Pensacola
|
23
|
-
- name: Santa Francisco
|
24
|
-
- name: Orlando
|
data/spec/is_a_tree_spec.rb
DELETED
@@ -1,149 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
-
|
3
|
-
class DataMapper::MockBase
|
4
|
-
include DataMapper::Is::Tree
|
5
|
-
end
|
6
|
-
|
7
|
-
class DefaultTree < DataMapper::MockBase
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "DataMapper::Is::Tree receiving various is_a_tree configurations" do
|
11
|
-
setup do
|
12
|
-
DefaultTree.stub!(:has_many)
|
13
|
-
DefaultTree.stub!(:belongs_to)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should setup a belongs_to relationship with the parent with the default configurations" do
|
17
|
-
DefaultTree.should_receive(:belongs_to).with(:parent, :foreign_key => "parent_id", :counter_cache => nil,
|
18
|
-
:class_name => "DefaultTree")
|
19
|
-
DefaultTree.send(:is_a_tree)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should setup a has_many relationship with the children with default configurations" do
|
23
|
-
DefaultTree.should_receive(:has_many).with(:children, :foreign_key => "parent_id", :order => nil,
|
24
|
-
:class_name => "DefaultTree")
|
25
|
-
DefaultTree.send(:is_a_tree)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should setup a belongs_to relationship with the correct foreign key" do
|
29
|
-
DefaultTree.should_receive(:belongs_to).with(:parent, :foreign_key => "something_id", :counter_cache => nil,
|
30
|
-
:class_name => "DefaultTree")
|
31
|
-
DefaultTree.send(:is_a_tree, :foreign_key => "something_id")
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should setup a has_many relationship with the children with the correct foreign key" do
|
35
|
-
DefaultTree.should_receive(:has_many).with(:children, :foreign_key => "something_id", :order => nil,
|
36
|
-
:class_name => "DefaultTree")
|
37
|
-
DefaultTree.send(:is_a_tree, :foreign_key => "something_id")
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should setup a has_many relationship with the children with the correct order" do
|
41
|
-
DefaultTree.should_receive(:has_many).with(:children, :foreign_key => "parent_id", :order => 'position',
|
42
|
-
:class_name => "DefaultTree")
|
43
|
-
DefaultTree.send(:is_a_tree, :order => 'position')
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "Default DataMapper::Is::Tree class methods" do
|
48
|
-
setup do
|
49
|
-
DefaultTree.stub!(:has_many)
|
50
|
-
DefaultTree.stub!(:belongs_to)
|
51
|
-
DefaultTree.send(:can_has_tree)
|
52
|
-
DefaultTree.stub!(:all).and_return([])
|
53
|
-
DefaultTree.stub!(:first).and_return(nil)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should return an empty array for .roots" do
|
57
|
-
DefaultTree.roots.should == []
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should find with the correct options on .roots" do
|
61
|
-
DefaultTree.should_receive(:all).with(:parent_id => nil, :order => nil)
|
62
|
-
DefaultTree.roots
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should return nil for .first_root" do
|
66
|
-
DefaultTree.root.should be_nil
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should find with the correct options on .first_root" do
|
70
|
-
DefaultTree.should_receive(:first).with(:parent_id => nil, :order => nil)
|
71
|
-
DefaultTree.first_root
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe "Configured DataMapper::Is::Tree class methods" do
|
76
|
-
setup do
|
77
|
-
DefaultTree.stub!(:has_many)
|
78
|
-
DefaultTree.stub!(:belongs_to)
|
79
|
-
DefaultTree.send(:can_has_tree, :foreign_key => 'mew_id', :order => 'mew')
|
80
|
-
DefaultTree.stub!(:all).and_return([])
|
81
|
-
DefaultTree.stub!(:first).and_return(nil)
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should return an empty array for .roots" do
|
85
|
-
DefaultTree.roots.should == []
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should find with the correct options on .roots" do
|
89
|
-
DefaultTree.should_receive(:all).with(:mew_id => nil, :order => 'mew')
|
90
|
-
DefaultTree.roots
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should return nil for .first_root" do
|
94
|
-
DefaultTree.root.should be_nil
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should find with the correct options on .first_root" do
|
98
|
-
DefaultTree.should_receive(:first).with(:mew_id => nil, :order => 'mew')
|
99
|
-
DefaultTree.first_root
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
describe "Default DataMapper::Is::Tree instance methods" do
|
104
|
-
setup do
|
105
|
-
DefaultTree.stub!(:has_many)
|
106
|
-
DefaultTree.stub!(:belongs_to)
|
107
|
-
DefaultTree.send(:is_a_tree)
|
108
|
-
@root = DefaultTree.new
|
109
|
-
@child = DefaultTree.new
|
110
|
-
@grandchild1 = DefaultTree.new
|
111
|
-
@grandchild2 = DefaultTree.new
|
112
|
-
|
113
|
-
# Mocking the belongs_to & has_many relationships (part of the not-needing-a-db-to-test plan)
|
114
|
-
@root.stub!(:parent).and_return nil
|
115
|
-
@child.stub!(:parent).and_return @root
|
116
|
-
@grandchild1.stub!(:parent).and_return(@child)
|
117
|
-
@grandchild2.stub!(:parent).and_return(@child)
|
118
|
-
@child.stub!(:children).and_return([@grandchild1, @grandchild2])
|
119
|
-
@root.stub!(:children).and_return([@child])
|
120
|
-
@grandchild1.stub!(:children).and_return []
|
121
|
-
@grandchild2.stub!(:children).and_return []
|
122
|
-
end
|
123
|
-
|
124
|
-
it "should return an array of parents, furthest parent first, for #ancestors" do
|
125
|
-
@grandchild1.ancestors.should == [@root, @child]
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should return an array of siblings for #siblings" do
|
129
|
-
@grandchild1.siblings.should == [@grandchild2]
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should return all children of the node's parent for #generation" do
|
133
|
-
@grandchild1.generation.should == [@grandchild1, @grandchild2]
|
134
|
-
end
|
135
|
-
|
136
|
-
it "should return roots on #generation when there is no parent" do
|
137
|
-
DefaultTree.should_receive(:roots).and_return [@root]
|
138
|
-
@root.generation.should == [@root]
|
139
|
-
end
|
140
|
-
|
141
|
-
it "should return the top-most parent on #root" do
|
142
|
-
@grandchild1.root.should == @root
|
143
|
-
end
|
144
|
-
|
145
|
-
it "should return self on #root if self has no parent" do
|
146
|
-
@root.root.should == @root
|
147
|
-
end
|
148
|
-
|
149
|
-
end
|
data/spec/legacy_spec.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
-
|
3
|
-
describe 'Legacy mappings' do
|
4
|
-
|
5
|
-
it('should allow models to map with custom attribute names') do
|
6
|
-
Fruit.first.name.should == 'Kiwi'
|
7
|
-
end
|
8
|
-
|
9
|
-
it('should allow custom foreign-key mappings') do
|
10
|
-
database do
|
11
|
-
Fruit.first(:name => 'Watermelon').devourer_of_souls.should == Animal.first(:name => 'Cup')
|
12
|
-
Animal.first(:name => 'Cup').favourite_fruit.should == Fruit.first(:name => 'Watermelon')
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
data/spec/load_command_spec.rb
DELETED
@@ -1,322 +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
|
50
|
-
|
51
|
-
describe DataMapper::Adapters::Sql::Commands::LoadCommand do
|
52
|
-
|
53
|
-
before(:all) do
|
54
|
-
fixtures(:zoos)
|
55
|
-
fixtures(:animals)
|
56
|
-
fixtures(:people)
|
57
|
-
end
|
58
|
-
|
59
|
-
after(:all) do
|
60
|
-
fixtures(:people)
|
61
|
-
end
|
62
|
-
|
63
|
-
def loader_for(klass, options = {})
|
64
|
-
database_context = database(:mock)
|
65
|
-
DataMapper::Adapters::Sql::Commands::LoadCommand.new(database_context.adapter, database_context, klass, options)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should return a Struct for custom queries" do
|
69
|
-
results = database.query("SELECT * FROM zoos WHERE name = ?", 'Galveston')
|
70
|
-
zoo = results.first
|
71
|
-
zoo.class.superclass.should == Struct
|
72
|
-
zoo.name.should == "Galveston"
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should return a simple select statement for a given class" do
|
76
|
-
loader_for(Zoo).to_parameterized_sql.first.should == 'SELECT `id`, `name`, `updated_at` FROM `zoos`'
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should include only the columns specified in the statement" do
|
80
|
-
loader_for(Zoo, :select => [:name]).to_parameterized_sql.first.should == 'SELECT `name` FROM `zoos`'
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should optionally include lazy-loaded columns in the statement" do
|
84
|
-
loader_for(Zoo, :include => :notes).to_parameterized_sql.first.should == 'SELECT `id`, `name`, `updated_at`, `notes` FROM `zoos`'
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should join associations in the statement" do
|
88
|
-
loader_for(Zoo, :include => :exhibits).to_parameterized_sql.first.should == <<-EOS.compress_lines
|
89
|
-
SELECT `zoos`.`id`, `zoos`.`name`, `zoos`.`updated_at`,
|
90
|
-
`exhibits`.`id`, `exhibits`.`name`, `exhibits`.`zoo_id`
|
91
|
-
FROM `zoos`
|
92
|
-
JOIN `exhibits` ON `exhibits`.`zoo_id` = `zoos`.`id`
|
93
|
-
EOS
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should join has and belongs to many associtions in the statement" do
|
97
|
-
loader_for(Animal, :include => :exhibits).to_parameterized_sql.first.should == <<-EOS.compress_lines
|
98
|
-
SELECT `animals`.`id`, `animals`.`name`, `animals`.`nice`,
|
99
|
-
`exhibits`.`id`, `exhibits`.`name`, `exhibits`.`zoo_id`,
|
100
|
-
`animals_exhibits`.`animal_id`, `animals_exhibits`.`exhibit_id`
|
101
|
-
FROM `animals`
|
102
|
-
JOIN `animals_exhibits` ON `animals_exhibits`.`animal_id` = `animals`.`id`
|
103
|
-
JOIN `exhibits` ON `exhibits`.`id` = `animals_exhibits`.`exhibit_id`
|
104
|
-
EOS
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should shallow-join unmapped tables for has-and-belongs-to-many in the statement" do
|
108
|
-
loader_for(Animal, :shallow_include => :exhibits).to_parameterized_sql.first.should == <<-EOS.compress_lines
|
109
|
-
SELECT `animals`.`id`, `animals`.`name`, `animals`.`nice`,
|
110
|
-
`animals_exhibits`.`animal_id`, `animals_exhibits`.`exhibit_id`
|
111
|
-
FROM `animals`
|
112
|
-
JOIN `animals_exhibits` ON `animals_exhibits`.`animal_id` = `animals`.`id`
|
113
|
-
EOS
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should allow multiple implicit conditions" do
|
117
|
-
expected_sql = <<-EOS.compress_lines
|
118
|
-
SELECT `id`, `name`, `age`, `occupation`,
|
119
|
-
`type`, `street`, `city`, `state`, `zip_code`
|
120
|
-
FROM `people`
|
121
|
-
WHERE (`name` = ?) AND (`age` = ?)
|
122
|
-
EOS
|
123
|
-
|
124
|
-
# NOTE: I'm actually not sure how to test this since the order of the parameters isn't gauranteed.
|
125
|
-
# Maybe an ugly OrderedHash passed as the options...
|
126
|
-
# loader_for(Person, :name => 'Sam', :age => 29).to_parameterized_sql.should == [expected_sql, 'Sam', 29]
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should allow block-interception during load" do
|
130
|
-
result = false
|
131
|
-
Person.first(:intercept_load => lambda { result = true })
|
132
|
-
result.should == true
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'database-specific load should not fail' do
|
136
|
-
|
137
|
-
DataMapper::database do |db|
|
138
|
-
froggy = db.first(Animal, :conditions => ['name = ?', 'Frog'])
|
139
|
-
froggy.name.should == 'Frog'
|
140
|
-
end
|
141
|
-
|
142
|
-
end
|
143
|
-
|
144
|
-
it 'current-database load should not fail' do
|
145
|
-
froggy = DataMapper::database.first(Animal).name.should == 'Frog'
|
146
|
-
end
|
147
|
-
|
148
|
-
it 'load through ActiveRecord impersonation should not fail' do
|
149
|
-
Animal.find(:all).size.should == 16
|
150
|
-
end
|
151
|
-
|
152
|
-
it 'load through Og impersonation should not fail' do
|
153
|
-
Animal.all.size.should == 16
|
154
|
-
end
|
155
|
-
|
156
|
-
it ':conditions option should accept a hash' do
|
157
|
-
Animal.all(:conditions => { :name => 'Frog' }).size.should == 1
|
158
|
-
end
|
159
|
-
|
160
|
-
it 'non-standard options should be considered part of the conditions' do
|
161
|
-
database.logger.debug { 'non-standard options should be considered part of the conditions' }
|
162
|
-
zebra = Animal.first(:name => 'Zebra')
|
163
|
-
zebra.name.should == 'Zebra'
|
164
|
-
|
165
|
-
elephant = Animal.first(:name => 'Elephant')
|
166
|
-
elephant.name.should == 'Elephant'
|
167
|
-
|
168
|
-
aged = Person.all(:age => 29)
|
169
|
-
aged.size.should == 2
|
170
|
-
aged.first.name.should == 'Sam'
|
171
|
-
aged.last.name.should == 'Bob'
|
172
|
-
|
173
|
-
fixtures(:animals)
|
174
|
-
end
|
175
|
-
|
176
|
-
it 'should not find deleted objects' do
|
177
|
-
database do
|
178
|
-
wally = Animal.first(:name => 'Whale')
|
179
|
-
wally.new_record?.should == false
|
180
|
-
wally.destroy!.should == true
|
181
|
-
|
182
|
-
wallys_evil_twin = Animal.first(:name => 'Whale')
|
183
|
-
wallys_evil_twin.should == nil
|
184
|
-
|
185
|
-
wally.new_record?.should == true
|
186
|
-
wally.save
|
187
|
-
wally.new_record?.should == false
|
188
|
-
|
189
|
-
Animal.first(:name => 'Whale').should == wally
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
it 'lazy-loads should issue for whole sets' do
|
194
|
-
people = Person.all
|
195
|
-
|
196
|
-
people.each do |person|
|
197
|
-
person.notes
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
it "should only query once" do
|
202
|
-
database do
|
203
|
-
zoo = Zoo.first
|
204
|
-
same_zoo = Zoo[zoo.id]
|
205
|
-
|
206
|
-
zoo.should == same_zoo
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
it "should return a single object" do
|
211
|
-
Zoo.first.should be_a_kind_of(Zoo)
|
212
|
-
Zoo[1].should be_a_kind_of(Zoo)
|
213
|
-
Zoo.find(1).should be_a_kind_of(Zoo)
|
214
|
-
end
|
215
|
-
|
216
|
-
# TICKET: http://wm.lighthouseapp.com/projects/4819-datamapper/tickets/90
|
217
|
-
it "should return a CLEAN object" do
|
218
|
-
Animal[2].should_not be_dirty
|
219
|
-
Animal.first(:name => 'Cup').should_not be_dirty
|
220
|
-
end
|
221
|
-
|
222
|
-
it "should retrieve altered integer columns correctly" do
|
223
|
-
pending "see http://wm.lighthouseapp.com/projects/4819-datamapper/tickets/95"
|
224
|
-
sam = Person.first
|
225
|
-
sam.age = 6471561394
|
226
|
-
sam.save
|
227
|
-
sam.reload
|
228
|
-
sam.original_values[:age].should == 6471561394
|
229
|
-
sam.age.should == 6471561394
|
230
|
-
end
|
231
|
-
|
232
|
-
it "should be able to search on UTF-8 strings" do
|
233
|
-
Zoo.create(:name => 'Danish Vowels: Smoot!') # øø
|
234
|
-
Zoo.first(:name.like => '%Smoot%').should be_a_kind_of(Zoo)
|
235
|
-
end
|
236
|
-
|
237
|
-
it "should destructively reload the loaded attributes of an object" do
|
238
|
-
zoo = Zoo.first(:name => 'Dallas')
|
239
|
-
zoo.name.should eql('Dallas')
|
240
|
-
zoo.name = 'bob'
|
241
|
-
zoo.name.should eql('bob')
|
242
|
-
zoo.reload!
|
243
|
-
zoo.name.should eql('Dallas')
|
244
|
-
end
|
245
|
-
|
246
|
-
# See the comment in dataobjects_spec for why this is failing
|
247
|
-
unless ENV["ADAPTER"] == "mysql"
|
248
|
-
it "should return nil when finding by id, and the id is not present and/or invalid" do
|
249
|
-
Zoo.find(nil).should be_nil
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
# it "should return in order" do
|
254
|
-
# pending("This spec is silly, and nothing but trouble since it depends on the table's clustered index. :-p")
|
255
|
-
# fixtures(:posts)
|
256
|
-
#
|
257
|
-
# one = Post.first
|
258
|
-
# one.title.should eql('One')
|
259
|
-
# two = one.next
|
260
|
-
# two.title.should eql('Two')
|
261
|
-
# one.next.next.previous.previous.next.previous.next.next.title.should eql('Three')
|
262
|
-
# end
|
263
|
-
|
264
|
-
it "should allow both implicit :conditions and explicit in the same finder" do
|
265
|
-
cup = Animal.first(:name => 'Cup', :conditions => ['name <> ?', 'Frog'])
|
266
|
-
cup.should == Animal[cup.key]
|
267
|
-
end
|
268
|
-
|
269
|
-
it "should iterate in batches" do
|
270
|
-
|
271
|
-
total = Animal.count
|
272
|
-
count = 0
|
273
|
-
|
274
|
-
Animal.each(:name.not => nil) do |animal|
|
275
|
-
count += 1
|
276
|
-
end
|
277
|
-
|
278
|
-
count.should == total
|
279
|
-
|
280
|
-
count = 0
|
281
|
-
|
282
|
-
Animal.each(:order => "id asc", :conditions => ["id > ? AND id < ?", 0, 9985], :limit => 2) do |animal|
|
283
|
-
count += 1
|
284
|
-
end
|
285
|
-
|
286
|
-
count.should == total
|
287
|
-
end
|
288
|
-
|
289
|
-
it "should get the right object back" do
|
290
|
-
a = Animal.first(:name => 'Cup')
|
291
|
-
Animal.get(a.id).should == a
|
292
|
-
|
293
|
-
b = Person.first(:name => 'Amy')
|
294
|
-
Person.get(b.id).should == b
|
295
|
-
|
296
|
-
c = Person.first(:name => 'Bob')
|
297
|
-
Person.get(c.id).should == c
|
298
|
-
|
299
|
-
database.execute("UPDATE people SET type = ? WHERE name = ?", nil, "Bob")
|
300
|
-
|
301
|
-
d = Person.first(:name => 'Bob')
|
302
|
-
Person.get(d.id).should == d
|
303
|
-
end
|
304
|
-
|
305
|
-
end
|
306
|
-
|
307
|
-
=begin
|
308
|
-
context 'Sub-selection' do
|
309
|
-
|
310
|
-
specify 'should return a Cup' do
|
311
|
-
Animal[:id.select => { :name => 'cup' }].name.should == 'Cup'
|
312
|
-
end
|
313
|
-
|
314
|
-
specify 'should return all exhibits for Galveston zoo' do
|
315
|
-
Exhibit.all(:zoo_id.select(Zoo) => { :name => 'Galveston' }).size.should == 3
|
316
|
-
end
|
317
|
-
|
318
|
-
specify 'should allow a sub-select in the select-list' do
|
319
|
-
Animal[:select => [ :id.count ]]
|
320
|
-
end
|
321
|
-
end
|
322
|
-
=end
|