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,96 +0,0 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
2
-
3
- # Only run these specs when the ADAPTER env-variable is set to 'postgresql'
4
- # You will probably need to set the DATABASE and USERNAME vars as well.
5
- if ENV['ADAPTER'] == 'postgresql'
6
-
7
- describe DataMapper::Adapters::PostgresqlAdapter::Mappings::Column do
8
- before(:all) do
9
- @mappings = DataMapper::Adapters::PostgresqlAdapter::Mappings
10
- @table = @mappings::Table.new(database(:mock).adapter, "Zebu")
11
- end
12
-
13
- it "should be able to set check-constraints on columns" do
14
- column = @mappings::Column.new(database(:mock).adapter, @table, :age,
15
- :integer, 1, { :check => "age > 18"})
16
- column.to_long_form.should match(/CHECK \(age > 18\)/)
17
- end
18
-
19
- it "should not set varchar length if none is specified" do
20
- column = @mappings::Column.new(database(:mock).adapter, @table,
21
- :varchar_len_test, :string, 1, { })
22
- column.size.should == nil
23
- column.to_long_form.should match(/.varchar_len_test. varchar/)
24
- end
25
-
26
- it "should set varchar length when it is specified" do
27
- column = @mappings::Column.new(database(:mock).adapter, @table,
28
- :varchar_len_test, :string, 1, { :length => 100 })
29
- column.size.should == 100
30
- column.to_long_form.should match(/.varchar_len_test. varchar\(100\)/)
31
- end
32
-
33
- it "should accept :size as alternative to :length" do
34
- column = @mappings::Column.new(database(:mock).adapter, @table,
35
- :varchar_len_test, :string, 1, { :size => 100 })
36
- column.size.should == 100
37
- column.to_long_form.should match(/.varchar_len_test. varchar\(100\)/)
38
- end
39
-
40
- it "should have size of nil when length of integer is specified" do
41
- column = @mappings::Column.new(database(:mock).adapter, @table,
42
- :integer_len_test, :integer, 1, { :length => 1 })
43
- column.size.should == nil
44
- column.to_long_form.should match(/.integer_len_test./)
45
- end
46
-
47
- it "should have size of nil when length of integer is not specified, overriding the default" do
48
- column = @mappings::Column.new(database(:mock).adapter, @table,
49
- :integer_len_test, :integer, 1)
50
- column.size.should == nil
51
- column.to_long_form.should match(/.integer_len_test./)
52
- end
53
- end
54
-
55
- describe DataMapper::Adapters::PostgresqlAdapter::Mappings::Table do
56
-
57
- before(:all) do
58
- class Cage #< DataMapper::Base # please do not remove this
59
- include DataMapper::Base
60
-
61
- set_table_name "cages"
62
- property :name, :string
63
- end
64
-
65
- class CageInSchema #< DataMapper::Base # please do not remove this
66
- include DataMapper::Base
67
-
68
- set_table_name "my_schema.cages"
69
- property :name, :string
70
- end
71
- end
72
-
73
- it "should return a quoted table name for a simple table" do
74
- table_sql = database.adapter.table(Cage).to_sql
75
- table_sql.should == "\"cages\""
76
- end
77
-
78
- it "should return a quoted schema and table name for a table which specifies a schema" do
79
- table_sql = database.adapter.table(CageInSchema).to_sql
80
- table_sql.should == "\"my_schema\".\"cages\""
81
- end
82
-
83
- it "should search only the specified schema if qualified" do
84
- database.save(Cage)
85
- database.adapter.table(CageInSchema).exists?.should == false
86
- database.save(CageInSchema)
87
- database.adapter.table(CageInSchema).exists?.should == true
88
- end
89
-
90
- after do
91
- database.adapter.execute("DROP SCHEMA my_schema CASCADE") rescue nil
92
- end
93
-
94
- end
95
-
96
- end
@@ -1,151 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe DataMapper::Property do
4
-
5
- before(:all) do
6
- @property = Zoo.properties.find { |property| property.name == :notes }
7
- end
8
-
9
- it "should map a column" do
10
- @property.column.should eql(database.table(Zoo)[:notes])
11
- end
12
-
13
- it "should determine lazyness" do
14
- @property.should be_lazy
15
- end
16
-
17
- it "should determine protection level" do
18
- @property.reader_visibility.should == :public
19
- @property.writer_visibility.should == :public
20
- end
21
-
22
- it "should return instance variable name" do
23
- @property.instance_variable_name.should == database.table(Zoo)[:notes].instance_variable_name
24
- end
25
-
26
- it "should add a validates_presence_of for not-null properties" do
27
- class NullableZoo #< DataMapper::Base # please do not remove this
28
- include DataMapper::Persistence
29
-
30
- property :name, :string, :nullable => false, :default => "Zoo"
31
- end
32
- zoo = NullableZoo.new
33
- zoo.valid?.should == false
34
- zoo.name = "Content"
35
- zoo.valid?.should == true
36
- end
37
-
38
- it "should add a validates_length_of for maximum size" do
39
- class SizableZoo #< DataMapper::Base # please do not remove this
40
- include DataMapper::Persistence
41
- property :name, :string, :length => 50
42
- end
43
- zoo = SizableZoo.new(:name => "San Diego" * 100)
44
- zoo.valid?.should == false
45
- zoo.name = "San Diego"
46
- zoo.valid?.should == true
47
- end
48
-
49
- it "should add a validates_length_of for a range" do
50
- class RangableZoo #< DataMapper::Base # please do not remove this
51
- include DataMapper::Persistence
52
- property :name, :string, :length => 2..255
53
- end
54
- zoo = RangableZoo.new(:name => "A")
55
- zoo.valid?.should == false
56
- zoo.name = "Zoo"
57
- zoo.valid?.should == true
58
- end
59
-
60
- it "should add a validates_format_of if you pass a format option" do
61
- class FormatableUser
62
- include DataMapper::Persistence
63
- property :email, :string, :format => :email_address
64
- end
65
- user = FormatableUser.new(:email => "incomplete_email")
66
- user.valid?.should == false
67
- user.email = "complete_email@anonymous.com"
68
- user.valid?.should == true
69
- end
70
-
71
- it "should not add a validates_presence_of for not-null properties if auto valdations are disabled" do
72
- class NullableZoo #< DataMapper::Base # please do not remove this
73
- include DataMapper::Persistence
74
- property :name, :string, :nullable => false, :default => "Zoo", :auto_validation => false
75
- end
76
- zoo = NullableZoo.new
77
- zoo.errors.empty?.should == true
78
- end
79
-
80
- it "should not add a validates_length_of if auto validations are disabled" do
81
- class SizableZoo #< DataMapper::Base # please do not remove this
82
- include DataMapper::Persistence
83
- property :name, :string, :length => 50, :auto_validation => false
84
- end
85
- zoo = SizableZoo.new(:name => "San Diego" * 100)
86
- zoo.errors.empty?.should == true
87
- end
88
-
89
- it "should not add a validates_format_of if you pass a format option if auto validations are disabled" do
90
- class FormatableUser
91
- include DataMapper::Persistence
92
- property :email, :string, :format => :email_address, :auto_validation => false
93
- end
94
- user = FormatableUser.new(:email => "incomplete_email")
95
- user.errors.empty?.should == true
96
- end
97
-
98
- it "should raise ArgumentError for unsupported types" do
99
- lambda {
100
- class PersistentFailure #< DataMapper::Base # please do not remove this
101
- include DataMapper::Persistence
102
- property :created_at, :timestamp
103
- end
104
- }.should raise_error(ArgumentError)
105
- end
106
- end
107
-
108
- describe DataMapper::Adapters::Sql::Mappings do
109
-
110
- it "should return the same Table instance for two objects mapped to the same database table" do
111
- # Refers to the same Table instance
112
- database.table(Person) == database.table(SalesPerson)
113
- end
114
-
115
- it "should have one super-set of total mapped columns" do
116
- # Refers to the mapped columns
117
- database.table(Person).columns == database.table(SalesPerson).columns
118
- end
119
-
120
- it "should have one set of columns that represents the actual database" do
121
- # Refers to the actual columns in the database, which may/are-likely-to-be different
122
- # than the mapped columns, sometimes just because your models are dealing with
123
- # a legacy database where not every column is mapped to the new model, so this
124
- # is expected.
125
- database.table(Person).send(:database_columns) == database.table(SalesPerson).send(:database_columns)
126
- end
127
-
128
- it "should have two different sets of mapped properties that point to subsets of the Table columns" do
129
- # pending("This one still needs some love to pass.")
130
- table = database.table(Person)
131
-
132
- # Every property's column should be represented in the Table's column mappings.
133
- Person.properties.each do |property|
134
- table.columns.should include(property.column)
135
- end
136
-
137
- # For both models in the STI setup...
138
- SalesPerson.properties.each do |property|
139
- database.table(SalesPerson).columns.should include(property.column)
140
- end
141
-
142
- # Even though Person's properties are fewer than a SalesPerson's
143
- Person.properties.size.should_not eql(SalesPerson.properties.size)
144
-
145
- # And Person's properties should be a subset of a SalesPerson's
146
- Person.properties.each do |property|
147
- SalesPerson.properties.map(&:column).should include(property.column)
148
- end
149
- end
150
-
151
- end
@@ -1,77 +0,0 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
2
-
3
- # * you have some crazy finder options... ie: Zoo, :name => 'bob', :include => :exhibits
4
- #
5
- # * you want to turn this into SQL.
6
- #
7
- # * you want to execute this SQL...
8
- #
9
- # * you want to load objects from the results, which means you have to know what columns in the results map to what objects
10
- #
11
- # * some values in the results will have no corresponding objects, theyll be indicators of other behaviour that should take place
12
- # ie: the values for a m:n join table will tell you how to bind the associated objects together, or...
13
- # the :type column will tell you what type to instantiate
14
- #
15
- #
16
- # So... the Query class should basically take the options from step 1, give you the SQL in step 2,
17
- # allow you to handle step 3, and expose types/result-set mappings to load objects by for step 4.
18
- # step 5 should be handled in the DataObjectAdapter
19
- describe DataMapper::Query do
20
-
21
- it "should generate the correct queries for the given options" do
22
- query = DataMapper::Query.new(database(:mock).adapter, Zoo, :name => 'bob')
23
- query.to_sql.should == "SELECT `id`, `name`, `updated_at` FROM `zoos` WHERE (`name` = ?)"
24
- query.parameters.should == ['bob']
25
-
26
- query = DataMapper::Query.new(database(:mock).adapter, Animal, :name => 'bob')
27
- query.to_sql.should == "SELECT `id`, `name`, `nice` FROM `animals` WHERE (`name` = ?)"
28
- query.parameters.should == ['bob']
29
-
30
- query = DataMapper::Query.new(database(:mock).adapter, Project)
31
- query.to_sql.should == "SELECT `id`, `title`, `description`, `deleted_at` FROM `projects` WHERE (`deleted_at` IS NULL OR `deleted_at` > NOW())"
32
- query.parameters.should be_empty
33
- end
34
-
35
- it "should use the include option for lazily-loaded columns" do
36
- query = DataMapper::Query.new(database(:mock).adapter, Zoo, :include => :notes)
37
- query.to_sql.should == "SELECT `id`, `name`, `notes`, `updated_at` FROM `zoos`"
38
- query.parameters.should be_empty
39
- end
40
-
41
- it "should generate the correct join query" do
42
- query = DataMapper::Query.new(database(:mock).adapter, Zoo, :include => [:exhibits])
43
- query.to_sql.should == <<-EOS.compress_lines
44
- SELECT `zoos`.`id`, `zoos`.`name`, `zoos`.`updated_at`, `exhibits`.`id`, `exhibits`.`name`, `exhibits`.`zoo_id`
45
- FROM `zoos`
46
- JOIN `exhibits` ON `exhibits`.`zoo_id` = `zoos`.`id`
47
- EOS
48
-
49
- query = DataMapper::Query.new(database(:mock).adapter, Zoo, :include => [:exhibits], :name => ['bob', 'sam'])
50
- query.to_sql.should == <<-EOS.compress_lines
51
- SELECT `zoos`.`id`, `zoos`.`name`, `zoos`.`updated_at`, `exhibits`.`id`, `exhibits`.`name`, `exhibits`.`zoo_id`
52
- FROM `zoos`
53
- JOIN `exhibits` ON `exhibits`.`zoo_id` = `zoos`.`id`
54
- WHERE (`zoos`.`name` IN ?)
55
- EOS
56
- query.parameters.should == [['bob', 'sam']]
57
- end
58
-
59
- it "should be forgiving with options that require Arrays" do
60
-
61
- query = DataMapper::Query.new(database(:mock).adapter, Zoo, :conditions => ["`name` = ?", 'bob'])
62
- query.to_sql.should == "SELECT `id`, `name`, `updated_at` FROM `zoos` WHERE (`name` = ?)"
63
- query.parameters.should == ['bob']
64
-
65
- query = DataMapper::Query.new(database(:mock).adapter, Zoo, :conditions => "`name` = 'bob'")
66
- query.to_sql.should == "SELECT `id`, `name`, `updated_at` FROM `zoos` WHERE (`name` = 'bob')"
67
- query.parameters.should be_empty
68
-
69
- query = DataMapper::Query.new(database(:mock).adapter, Zoo, :include => :exhibits)
70
- query.to_sql.should == <<-EOS.compress_lines
71
- SELECT `zoos`.`id`, `zoos`.`name`, `zoos`.`updated_at`, `exhibits`.`id`, `exhibits`.`name`, `exhibits`.`zoo_id`
72
- FROM `zoos`
73
- JOIN `exhibits` ON `exhibits`.`zoo_id` = `zoos`.`id`
74
- EOS
75
- end
76
-
77
- end
@@ -1,94 +0,0 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
2
-
3
- describe "Save Commands" do
4
-
5
- before(:all) do
6
- fixtures(:zoos)
7
- end
8
-
9
- it "should create a new row" do
10
- total = Zoo.all.length
11
- Zoo.create({ :name => 'bob' })
12
- zoo = Zoo.first(:name => 'bob')
13
- zoo.name.should == 'bob'
14
- Zoo.all.length.should == total+1
15
- end
16
-
17
- it "should update an existing row" do
18
- dallas = Zoo.first(:name => 'Dallas')
19
- dallas.name = 'bob'
20
- dallas.save
21
- dallas.name = 'Dallas'
22
- dallas.save
23
- end
24
-
25
- it "should be able to read other attributes after a record is created" do
26
- zoo = Zoo.create({ :name => 'bob' })
27
- zoo.notes.should == nil
28
- end
29
-
30
- it "should stamp association on save" do
31
- database do
32
- dallas = Zoo.first(:name => 'Dallas')
33
- dallas.exhibits << Exhibit.new(:name => 'Flying Monkeys')
34
- dallas.save
35
- Exhibit.first(:name => 'Flying Monkeys').zoo.should == dallas
36
- end
37
- end
38
-
39
- it "should return success of save call, not status of query execution" do
40
- # pending "http://wm.lighthouseapp.com/projects/4819/tickets/54-save-should-return-success"
41
- Exhibit.first.save.should be_true
42
- end
43
-
44
- it "should be invalid if invalid associations are loaded" do
45
- miami = Zoo.first(:name => 'Miami')
46
- fish_fancy = Exhibit.new
47
- miami.exhibits << fish_fancy
48
- miami.should_not be_valid
49
- fish_fancy.name = 'Fish Fancy'
50
- fish_fancy.should be_valid
51
- miami.should be_valid
52
- end
53
-
54
- it "should retrieve it's id on creation if the key is auto-incrementing so it can be successively updated" do
55
- database do # Use the same Session so the reference-equality checks will pass.
56
- mary = Animal::create(:name => 'Mary')
57
- mary.name = 'Jane'
58
- # Without retrieving the id during creation, the following #save call would fail,
59
- # because we wouldn't know what id to update.
60
- mary.save.should == true
61
- jane = Animal.first(:name => 'Jane')
62
- mary.should == jane
63
- end
64
- end
65
-
66
- it "should not be dirty if there are no attributes to update" do
67
- bob = Animal.new
68
- bob.should_not be_dirty
69
- bob.name = 'bob'
70
- bob.dirty_attributes.should == { :name => 'bob' }
71
- bob.should be_dirty
72
- end
73
-
74
- it "should not persist invalid objects" do
75
- zoo = Zoo.create(:notes => "I'm invalid!")
76
- zoo.should_not be_valid
77
- zoo.should be_new_record
78
- end
79
-
80
- it "should create a Project with a \"Main\" Section" do
81
- database do
82
- project = Project::create(:title => 'Test')
83
- project.sections.first.should == Section.first
84
- project.sections.first.should be_a_kind_of(Section)
85
- end
86
- end
87
-
88
- it "save! should raise an error if validation failed" do
89
- # pending "http://wm.lighthouseapp.com/projects/4819/tickets/29-dm-context-write"
90
- empty = Zoo.new
91
- lambda { empty.save! }.should raise_error(DataMapper::ValidationError)
92
- end
93
-
94
- end
@@ -1,8 +0,0 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
2
-
3
- describe DataMapper::Adapters::Sql::Mappings::Schema do
4
- it "should return all tables from the database schema" do
5
- database.adapter.schema.database_tables.size.should == Dir[File.dirname(__FILE__) + '/fixtures/*'].size
6
- database.adapter.schema.database_tables.each { |table| table.should be_a_kind_of( DataMapper::Adapters::Sql::Mappings::Table ) }
7
- end
8
- end
@@ -1,19 +0,0 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
2
-
3
- describe('An AR serialize implementation') do
4
-
5
- it 'should instatiate, save, (clear and load) the original objects' do
6
- test_data = { :first => 1, :second => "dos", :third => 3.0 }
7
-
8
- srlzr1 = Serializer.new(:content => test_data)
9
- srlzr1.content.should == test_data
10
-
11
- srlzr1.save
12
- srlzr1.content.should == test_data
13
-
14
- srlzr1 = nil
15
- srlzr2 = Serializer.first
16
- srlzr2.content.should == test_data
17
- end
18
-
19
- end