datamapper 0.3.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. data/History.txt +0 -0
  2. data/Manifest.txt +5 -0
  3. data/README.txt +11 -0
  4. data/Rakefile +70 -0
  5. data/lib/datamapper.rb +8 -0
  6. metadata +152 -319
  7. data/CHANGELOG +0 -145
  8. data/FAQ +0 -96
  9. data/MIT-LICENSE +0 -22
  10. data/QUICKLINKS +0 -12
  11. data/README +0 -105
  12. data/environment.rb +0 -62
  13. data/example.rb +0 -156
  14. data/lib/data_mapper.rb +0 -88
  15. data/lib/data_mapper/adapters/abstract_adapter.rb +0 -43
  16. data/lib/data_mapper/adapters/data_object_adapter.rb +0 -480
  17. data/lib/data_mapper/adapters/mysql_adapter.rb +0 -72
  18. data/lib/data_mapper/adapters/postgresql_adapter.rb +0 -258
  19. data/lib/data_mapper/adapters/sql/coersion.rb +0 -134
  20. data/lib/data_mapper/adapters/sql/commands/load_command.rb +0 -545
  21. data/lib/data_mapper/adapters/sql/mappings/associations_set.rb +0 -34
  22. data/lib/data_mapper/adapters/sql/mappings/column.rb +0 -279
  23. data/lib/data_mapper/adapters/sql/mappings/conditions.rb +0 -172
  24. data/lib/data_mapper/adapters/sql/mappings/schema.rb +0 -60
  25. data/lib/data_mapper/adapters/sql/mappings/table.rb +0 -459
  26. data/lib/data_mapper/adapters/sql/quoting.rb +0 -24
  27. data/lib/data_mapper/adapters/sqlite3_adapter.rb +0 -159
  28. data/lib/data_mapper/associations.rb +0 -106
  29. data/lib/data_mapper/associations/belongs_to_association.rb +0 -160
  30. data/lib/data_mapper/associations/has_and_belongs_to_many_association.rb +0 -437
  31. data/lib/data_mapper/associations/has_many_association.rb +0 -283
  32. data/lib/data_mapper/associations/has_n_association.rb +0 -143
  33. data/lib/data_mapper/associations/reference.rb +0 -47
  34. data/lib/data_mapper/attributes.rb +0 -73
  35. data/lib/data_mapper/auto_migrations.rb +0 -36
  36. data/lib/data_mapper/base.rb +0 -17
  37. data/lib/data_mapper/callbacks.rb +0 -107
  38. data/lib/data_mapper/context.rb +0 -112
  39. data/lib/data_mapper/database.rb +0 -234
  40. data/lib/data_mapper/dependency_queue.rb +0 -28
  41. data/lib/data_mapper/embedded_value.rb +0 -145
  42. data/lib/data_mapper/identity_map.rb +0 -47
  43. data/lib/data_mapper/is/tree.rb +0 -121
  44. data/lib/data_mapper/migration.rb +0 -155
  45. data/lib/data_mapper/persistence.rb +0 -852
  46. data/lib/data_mapper/property.rb +0 -310
  47. data/lib/data_mapper/query.rb +0 -164
  48. data/lib/data_mapper/support/blank.rb +0 -35
  49. data/lib/data_mapper/support/connection_pool.rb +0 -117
  50. data/lib/data_mapper/support/enumerable.rb +0 -35
  51. data/lib/data_mapper/support/errors.rb +0 -16
  52. data/lib/data_mapper/support/inflector.rb +0 -265
  53. data/lib/data_mapper/support/object.rb +0 -54
  54. data/lib/data_mapper/support/serialization.rb +0 -96
  55. data/lib/data_mapper/support/silence.rb +0 -10
  56. data/lib/data_mapper/support/string.rb +0 -72
  57. data/lib/data_mapper/support/struct.rb +0 -7
  58. data/lib/data_mapper/support/symbol.rb +0 -82
  59. data/lib/data_mapper/support/typed_set.rb +0 -65
  60. data/lib/data_mapper/types/base.rb +0 -44
  61. data/lib/data_mapper/types/string.rb +0 -34
  62. data/lib/data_mapper/validatable_extensions/errors.rb +0 -12
  63. data/lib/data_mapper/validatable_extensions/macros.rb +0 -7
  64. data/lib/data_mapper/validatable_extensions/validatable_instance_methods.rb +0 -62
  65. data/lib/data_mapper/validatable_extensions/validation_base.rb +0 -18
  66. data/lib/data_mapper/validatable_extensions/validations/formats/email.rb +0 -43
  67. data/lib/data_mapper/validatable_extensions/validations/validates_acceptance_of.rb +0 -7
  68. data/lib/data_mapper/validatable_extensions/validations/validates_confirmation_of.rb +0 -7
  69. data/lib/data_mapper/validatable_extensions/validations/validates_each.rb +0 -7
  70. data/lib/data_mapper/validatable_extensions/validations/validates_format_of.rb +0 -28
  71. data/lib/data_mapper/validatable_extensions/validations/validates_length_of.rb +0 -15
  72. data/lib/data_mapper/validatable_extensions/validations/validates_numericality_of.rb +0 -7
  73. data/lib/data_mapper/validatable_extensions/validations/validates_presence_of.rb +0 -7
  74. data/lib/data_mapper/validatable_extensions/validations/validates_true_for.rb +0 -7
  75. data/lib/data_mapper/validatable_extensions/validations/validates_uniqueness_of.rb +0 -40
  76. data/lib/data_mapper/validations.rb +0 -20
  77. data/lib/data_mapper/validations/number_validator.rb +0 -40
  78. data/lib/data_mapper/validations/string_validator.rb +0 -20
  79. data/lib/data_mapper/validations/validator.rb +0 -13
  80. data/performance.rb +0 -307
  81. data/plugins/can_has_sphinx/LICENSE +0 -23
  82. data/plugins/can_has_sphinx/README +0 -4
  83. data/plugins/can_has_sphinx/REVISION +0 -1
  84. data/plugins/can_has_sphinx/Rakefile +0 -22
  85. data/plugins/can_has_sphinx/init.rb +0 -1
  86. data/plugins/can_has_sphinx/install.rb +0 -1
  87. data/plugins/can_has_sphinx/lib/acts_as_sphinx.rb +0 -123
  88. data/plugins/can_has_sphinx/lib/sphinx.rb +0 -460
  89. data/plugins/can_has_sphinx/scripts/sphinx.sh +0 -47
  90. data/plugins/can_has_sphinx/tasks/acts_as_sphinx_tasks.rake +0 -41
  91. data/profile_data_mapper.rb +0 -40
  92. data/rakefile.rb +0 -159
  93. data/spec/acts_as_tree_spec.rb +0 -67
  94. data/spec/adapters/data_object_adapter_spec.rb +0 -31
  95. data/spec/associations/belongs_to_association_spec.rb +0 -98
  96. data/spec/associations/has_and_belongs_to_many_association_spec.rb +0 -377
  97. data/spec/associations/has_many_association_spec.rb +0 -337
  98. data/spec/attributes_spec.rb +0 -52
  99. data/spec/auto_migrations_spec.rb +0 -101
  100. data/spec/callbacks_spec.rb +0 -186
  101. data/spec/can_has_sphinx.rb +0 -5
  102. data/spec/coersion_spec.rb +0 -41
  103. data/spec/column_spec.rb +0 -114
  104. data/spec/count_command_spec.rb +0 -45
  105. data/spec/database_spec.rb +0 -18
  106. data/spec/dataobjects_spec.rb +0 -27
  107. data/spec/delete_command_spec.rb +0 -11
  108. data/spec/dependency_spec.rb +0 -29
  109. data/spec/embedded_value_spec.rb +0 -161
  110. data/spec/fixtures/animals.yaml +0 -33
  111. data/spec/fixtures/animals_exhibits.yaml +0 -2
  112. data/spec/fixtures/careers.yaml +0 -5
  113. data/spec/fixtures/comments.yaml +0 -1
  114. data/spec/fixtures/exhibits.yaml +0 -90
  115. data/spec/fixtures/fruit.yaml +0 -6
  116. data/spec/fixtures/people.yaml +0 -37
  117. data/spec/fixtures/posts.yaml +0 -3
  118. data/spec/fixtures/projects.yaml +0 -13
  119. data/spec/fixtures/sections.yaml +0 -5
  120. data/spec/fixtures/serializers.yaml +0 -6
  121. data/spec/fixtures/tasks.yaml +0 -6
  122. data/spec/fixtures/tasks_tasks.yaml +0 -2
  123. data/spec/fixtures/tomatoes.yaml +0 -1
  124. data/spec/fixtures/users.yaml +0 -1
  125. data/spec/fixtures/zoos.yaml +0 -24
  126. data/spec/is_a_tree_spec.rb +0 -149
  127. data/spec/legacy_spec.rb +0 -16
  128. data/spec/load_command_spec.rb +0 -322
  129. data/spec/magic_columns_spec.rb +0 -26
  130. data/spec/migration_spec.rb +0 -267
  131. data/spec/mock_adapter.rb +0 -20
  132. data/spec/models/animal.rb +0 -12
  133. data/spec/models/candidate.rb +0 -8
  134. data/spec/models/career.rb +0 -7
  135. data/spec/models/chain.rb +0 -8
  136. data/spec/models/comment.rb +0 -6
  137. data/spec/models/exhibit.rb +0 -14
  138. data/spec/models/fence.rb +0 -7
  139. data/spec/models/fruit.rb +0 -8
  140. data/spec/models/job.rb +0 -8
  141. data/spec/models/person.rb +0 -30
  142. data/spec/models/post.rb +0 -14
  143. data/spec/models/project.rb +0 -41
  144. data/spec/models/sales_person.rb +0 -5
  145. data/spec/models/section.rb +0 -8
  146. data/spec/models/serializer.rb +0 -5
  147. data/spec/models/task.rb +0 -9
  148. data/spec/models/tomato.rb +0 -27
  149. data/spec/models/user.rb +0 -12
  150. data/spec/models/zoo.rb +0 -13
  151. data/spec/natural_key_spec.rb +0 -36
  152. data/spec/paranoia_spec.rb +0 -38
  153. data/spec/persistence_spec.rb +0 -479
  154. data/spec/postgres_spec.rb +0 -96
  155. data/spec/property_spec.rb +0 -151
  156. data/spec/query_spec.rb +0 -77
  157. data/spec/save_command_spec.rb +0 -94
  158. data/spec/schema_spec.rb +0 -8
  159. data/spec/serialize_spec.rb +0 -19
  160. data/spec/single_table_inheritance_spec.rb +0 -43
  161. data/spec/spec_helper.rb +0 -45
  162. data/spec/support/blank_spec.rb +0 -8
  163. data/spec/support/inflector_spec.rb +0 -41
  164. data/spec/support/object_spec.rb +0 -9
  165. data/spec/support/serialization_spec.rb +0 -61
  166. data/spec/support/silence_spec.rb +0 -15
  167. data/spec/support/string_spec.rb +0 -7
  168. data/spec/support/struct_spec.rb +0 -12
  169. data/spec/support/typed_set_spec.rb +0 -66
  170. data/spec/symbolic_operators_spec.rb +0 -27
  171. data/spec/table_spec.rb +0 -79
  172. data/spec/types/string.rb +0 -81
  173. data/spec/validates_confirmation_of_spec.rb +0 -55
  174. data/spec/validates_format_of_spec.rb +0 -78
  175. data/spec/validates_length_of_spec.rb +0 -117
  176. data/spec/validates_uniqueness_of_spec.rb +0 -92
  177. data/spec/validations/number_validator.rb +0 -59
  178. data/spec/validations/string_validator.rb +0 -14
  179. data/spec/validations_spec.rb +0 -141
  180. data/tasks/fixtures.rb +0 -53
@@ -1,3 +0,0 @@
1
- - title: One
2
- - title: Two
3
- - title: Three
@@ -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"
@@ -1,5 +0,0 @@
1
- ---
2
- - id: 1
3
- title: Main
4
- created_at: 2007-12-08T11:31:08-06:00
5
- project_id: 1
@@ -1,6 +0,0 @@
1
- ---
2
- - id: 1
3
- content:
4
- :second: dos
5
- :first: 1
6
- :third: 3.0
@@ -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
@@ -1,2 +0,0 @@
1
- - task_id: 1
2
- related_task_id: 2
@@ -1 +0,0 @@
1
- --- []
@@ -1 +0,0 @@
1
- --- []
@@ -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
@@ -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
@@ -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
@@ -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