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,52 +0,0 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
2
-
3
- describe "DataMapper::Attributes" do
4
-
5
- it 'should allow mass-assignment of attributes' do
6
- zoo = Zoo.new(:name => 'MassAssignment', :notes => 'This is a test.')
7
-
8
- zoo.name.should eql('MassAssignment')
9
- zoo.notes.should eql('This is a test.')
10
-
11
- zoo.attributes = { :name => 'ThroughAttributesEqual', :notes => 'This is another test.' }
12
-
13
- zoo.name.should eql('ThroughAttributesEqual')
14
- zoo.notes.should eql('This is another test.')
15
- end
16
-
17
- it "should allow custom setters" do
18
- zoo = Zoo.new
19
-
20
- zoo.name = 'Colorado Springs'
21
- zoo.name.should eql("Cheyenne Mountain")
22
- end
23
-
24
- it "should call custom setters on mass-assignment" do
25
- zoo = Zoo.new(:name => 'Colorado Springs')
26
-
27
- zoo.name.should eql("Cheyenne Mountain")
28
- end
29
-
30
- it "should provide an ATTRIBUTES constant" do
31
- Tomato::ATTRIBUTES.should == Set.new([:id, :name, :bruised])
32
- end
33
-
34
- it "should get attributes declared in ATTRIBUTES constant" do
35
- Tomato.new.attributes.should == { :id => nil, :name => 'Ugly', :bruised => true }
36
- end
37
-
38
- it "should get proper values for mass-created attributes with array" do
39
- person = Person.new(:name => 'Steve Jobs', :occupation => 'Apple CEO')
40
-
41
- person.name.should eql('Steve Jobs')
42
- person.occupation.should eql('Apple CEO')
43
- end
44
-
45
- it "should get proper values for mass-created attributes without array" do
46
- job = Job.new(:name => 'Banker')
47
- job.save! and job.reload
48
-
49
- job.hours.should eql(0)
50
- job.days.should eql(0)
51
- end
52
- end
@@ -1,101 +0,0 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
2
-
3
- describe DataMapper::AutoMigrations do
4
- before(:all) do
5
- DataMapper::Persistence.drop_all_tables!
6
- DataMapper::Persistence.subclasses.clear
7
- end
8
-
9
- # before(:each) do
10
- # DataMapper::Persistence.drop_all_tables!
11
- # end
12
- #
13
- # after(:all) do
14
- # DataMapper::Persistence.drop_all_tables!
15
- # DataMapper::Persistence.auto_migrate!
16
- # end
17
-
18
- # describe DataMapper::Base do
19
- # it "should auto migrate all" do
20
- # DataMapper::Base.auto_migrate!
21
- #
22
- # database.adapter.schema.database_tables.size.should == Dir[File.dirname(__FILE__) + '/fixtures/*'].size
23
- # end
24
- #
25
- # describe "when migrating a descendant" do
26
- # before do
27
- # class Descendant < DataMapper::Base
28
- # property :one, :string
29
- # property :two, :string
30
- # property :three, :string
31
- # end
32
- # end
33
- #
34
- # it "should work" do
35
- # Descendant.auto_migrate!
36
- #
37
- # database.table_exists?(Descendant).should be_true
38
- # database.column_exists_for_table?(Descendant, :one).should be_true
39
- # database.column_exists_for_table?(Descendant, :two).should be_true
40
- # database.column_exists_for_table?(Descendant, :three).should be_true
41
- # database.adapter.schema.database_tables.size.should == 1
42
- # end
43
- #
44
- # after do
45
- # database.schema[Descendant].drop!
46
- # end
47
- # end
48
- # end
49
-
50
- it "should find all new models" do
51
- Zoo.auto_migrate!
52
-
53
- database.table_exists?(Zoo).should be_true
54
- database.column_exists_for_table?(Zoo, :id).should be_true
55
- database.column_exists_for_table?(Zoo, :name).should be_true
56
- database.column_exists_for_table?(Zoo, :notes).should be_true
57
- database.column_exists_for_table?(Zoo, :updated_at).should be_true
58
- database.adapter.schema.database_tables.size.should == 1
59
- end
60
-
61
- it "should find all changed models"
62
- it "should find all unmapped tables"
63
-
64
- describe Zoo, "with auto-migrations" do
65
- it "should allow auto migration" do
66
- Zoo.should respond_to("auto_migrate!")
67
- end
68
- end
69
-
70
- describe "when migrating a new model" do
71
- it "should allow creation of new tables for new models"
72
- it "should allow renaming of unmapped tables for new models"
73
- it "should create columns for the model's properties"
74
- end
75
-
76
- describe "when migrating a changed model" do
77
- it "should find all new properties"
78
- it "should allow creation of new columns for new properties"
79
- it "should allow an unmapped column to be renamed for a new property"
80
- it "should find all unmapped columns"
81
- it "should allow removal of any or all unmapped columns"
82
- end
83
-
84
- describe "when migrating an unmapped table" do
85
- it "should allow the table to be dropped"
86
- end
87
-
88
- describe "after migrating" do
89
- it "should store migration decisions to allow the migration to be replicated"
90
- end
91
-
92
- after(:all) do
93
- DataMapper::Persistence.subclasses.clear
94
- DataMapper::Persistence.subclasses.concat INITIAL_CLASSES
95
-
96
- # Use DataMapper::Base to boost spec coverage since it delegates to Persistence anyways.
97
- DataMapper::Base.auto_migrate!
98
-
99
- load_database
100
- end
101
- end
@@ -1,186 +0,0 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
2
-
3
- describe DataMapper::Callbacks do
4
-
5
- it "should allow for a callback to be set, then called" do
6
-
7
- example = Class.new do
8
- include DataMapper::CallbacksHelper
9
-
10
- attr_accessor :name
11
-
12
- def initialize(name)
13
- @name = name
14
- end
15
-
16
- before_save 'name = "bob"'
17
- before_validation { |instance| instance.name = 'Barry White Returns!' }
18
-
19
- end.new('Barry White')
20
-
21
- example.class::callbacks.execute(:before_save, example)
22
- example.name.should == 'Barry White'
23
-
24
- example.class::callbacks.execute(:before_validation, example)
25
- example.name.should == 'Barry White Returns!'
26
- end
27
-
28
- it "should allow method delegation by passing symbols to the callback definitions" do
29
-
30
- example = Class.new do
31
- include DataMapper::CallbacksHelper
32
-
33
- attr_accessor :name
34
-
35
- before_save :test
36
-
37
- def test
38
- @name = 'Walter'
39
- end
40
- end.new
41
-
42
- example.class::callbacks.execute(:before_save, example)
43
- example.name.should == 'Walter'
44
-
45
- end
46
-
47
- it "should execute before_save regardless of dirty state" do
48
-
49
- Post.before_save do |post|
50
- post.instance_variable_set("@one", 'moo')
51
- end
52
-
53
- Post.before_save do |post|
54
- post.instance_variable_set("@two", 'cow')
55
- end
56
-
57
- Post.before_save :red_cow
58
-
59
- class Post
60
- def red_cow
61
- @three = "blue_cow"
62
- end
63
- end
64
-
65
- post = Post.new(:title => 'bob')
66
- post.save
67
-
68
- post = Post.first(:title => 'bob')
69
- post.instance_variable_get("@one").should be_nil
70
- post.instance_variable_get("@two").should be_nil
71
- post.instance_variable_get("@three").should be_nil
72
-
73
- post.save
74
- post.instance_variable_get("@one").should eql('moo')
75
- post.instance_variable_get("@two").should eql('cow')
76
- post.instance_variable_get("@three").should eql('blue_cow')
77
- end
78
-
79
- it "should execute materialization callbacks" do
80
-
81
- $before_materialize = 0
82
- $after_materialize = 0
83
-
84
- Zoo.before_materialize do
85
- $before_materialize += 1
86
- end
87
-
88
- Zoo.after_materialize do
89
- $after_materialize += 1
90
- end
91
-
92
- class Zoo
93
-
94
- # This syntax doesn't work in DM.
95
- # Which I don't think is necessarily a bad thing...
96
- # Just FYI -Sam
97
- def before_materialize
98
- $before_materialize += 1
99
- end
100
-
101
- def call_before_materialize
102
- $before_materialize += 1
103
- end
104
-
105
- # Example of invalid syntax
106
- def after_materialize
107
- $after_materialize += 1
108
- end
109
-
110
- def call_after_materialize
111
- $after_materialize += 1
112
- end
113
-
114
- end
115
-
116
- Zoo.before_materialize :call_before_materialize
117
- Zoo.after_materialize :call_after_materialize
118
-
119
- Zoo.before_materialize "$before_materialize += 1"
120
- Zoo.after_materialize "$after_materialize += 1"
121
-
122
- Zoo.first
123
-
124
- $before_materialize.should == 3
125
- $after_materialize.should == 3
126
-
127
- Zoo[1]
128
-
129
- $before_materialize.should == 6
130
- $after_materialize.should == 6
131
-
132
- end
133
-
134
- it "should execute creation callbacks" do
135
-
136
- $before_create = 0
137
- $after_create = 0
138
-
139
- Zoo.before_create do
140
- $before_create += 1
141
- end
142
-
143
- Zoo.after_create do
144
- $after_create += 1
145
- end
146
-
147
- class Zoo
148
-
149
- # Example of invalid syntax
150
- def before_create
151
- $before_create += 1
152
- end
153
-
154
- def call_before_create
155
- $before_create += 1
156
- end
157
-
158
- # Example of invalid syntax
159
- def after_create
160
- $after_create += 1
161
- end
162
-
163
- def call_after_create
164
- $after_create += 1
165
- end
166
-
167
- end
168
-
169
- Zoo.before_create :call_before_create
170
- Zoo.after_create :call_after_create
171
-
172
- Zoo.before_create "$before_create += 1"
173
- Zoo.after_create "$after_create += 1"
174
-
175
- Zoo.create(:name => 'bob')
176
-
177
- $before_create.should == 3
178
- $after_create.should == 3
179
-
180
- Zoo.new(:name => 'bob2').save
181
-
182
- $before_create.should == 6
183
- $after_create.should == 6
184
- end
185
-
186
- end
@@ -1,5 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe DataMapper::Plugins::CanHasSphinx do
4
-
5
- end
@@ -1,41 +0,0 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
2
-
3
- describe DataMapper::Adapters::Sql::Coersion do
4
-
5
- before(:all) do
6
- @coersive = Class.new do
7
- include DataMapper::Adapters::Sql::Coersion
8
- end.new
9
- end
10
-
11
- it 'should cast to a BigDecimal' do
12
- target = BigDecimal.new('7.2')
13
- @coersive.type_cast_decimal('7.2').should == target
14
- @coersive.type_cast_decimal(7.2).should == target
15
- end
16
-
17
- it 'should store and load a date' do
18
- dob = Date::today
19
- bob = Person.create(:name => 'DateCoersionTest', :date_of_birth => dob)
20
-
21
- bob2 = Person.first(:name => 'DateCoersionTest')
22
-
23
- bob.date_of_birth.should eql(dob)
24
- bob2.date_of_birth.should eql(dob)
25
- end
26
-
27
- it 'should cast to a Date' do
28
- target = Date.civil(2001, 1, 1)
29
-
30
- @coersive.type_cast_date('2001-1-1').should eql(target)
31
- @coersive.type_cast_date(target.dup).should eql(target)
32
- @coersive.type_cast_date(DateTime::parse('2001-1-1')).should eql(target)
33
- @coersive.type_cast_date(Time::parse('2001-1-1')).should eql(target)
34
- end
35
-
36
- it 'should cast to a String' do
37
- target = "\n\ttest\n\n\ntest\n\n"
38
-
39
- @coersive.type_cast_text(target).should == target
40
- end
41
- end
@@ -1,114 +0,0 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
2
-
3
- describe DataMapper::Adapters::Sql::Mappings::Column do
4
-
5
- before(:all) do
6
- @mappings = DataMapper::Adapters::Sql::Mappings
7
- fixtures(:zoos)
8
- end
9
-
10
- def table
11
- @table ||= @mappings::Table.new(database(:mock).adapter, "Cow")
12
- end
13
-
14
- it "should only lazy loading text columns by default" do
15
- table = database.table(Zoo)
16
- table.columns.each do |column|
17
- if column.type == :text
18
- column.should be_lazy
19
- else
20
- column.should_not be_lazy
21
- end
22
- end
23
- end
24
-
25
- it "should be unique within a set" do
26
- columns = SortedSet.new
27
-
28
- columns << @mappings::Column.new(database(:mock).adapter, table, :one, :string, 1)
29
- columns << @mappings::Column.new(database(:mock).adapter, table, :two, :string, 2)
30
- columns << @mappings::Column.new(database(:mock).adapter, table, :three, :string, 3)
31
- columns.should have(3).entries
32
-
33
- columns << @mappings::Column.new(database(:mock).adapter, table, :two, :integer, 3)
34
- columns.should have(3).entries
35
-
36
- columns << @mappings::Column.new(database(:mock).adapter, table, :id, :integer, -1)
37
- columns.should have(4).entries
38
- end
39
-
40
- it "should get its meta data from the database"
41
-
42
- it "should be able to rename" do
43
- table = database.table(Zoo)
44
- name_column = table[:name]
45
-
46
- lambda { database.query("SELECT name FROM zoos") }.should_not raise_error
47
- lambda { database.query("SELECT moo FROM zoos") }.should raise_error
48
-
49
- name_column = name_column.rename!(:moo)
50
- name_column.name.should eql(:moo)
51
-
52
- lambda { database.query("SELECT name FROM zoos") }.should raise_error
53
- lambda { database.query("SELECT moo FROM zoos") }.should_not raise_error
54
-
55
- name_column = name_column.rename!(:name)
56
- name_column.name.should eql(:name)
57
-
58
- lambda { database.query("SELECT name FROM zoos") }.should_not raise_error
59
- lambda { database.query("SELECT moo FROM zoos") }.should raise_error
60
- end
61
-
62
- it "should create, alter and drop a column" do
63
- lambda { database.query("SELECT moo FROM zoos") }.should raise_error
64
-
65
- database.logger.debug { 'MOO' * 10 }
66
-
67
- table = database.table(Zoo)
68
- Zoo.property(:moo, :string)
69
- moo = table[:moo]
70
- moo.create!
71
-
72
- lambda { database.query("SELECT moo FROM zoos") }.should_not raise_error
73
-
74
- zoo = Zoo.create(:name => 'columns', :moo => 'AAA')
75
- zoo.moo.should eql('AAA')
76
-
77
- zoo.moo = 4
78
- zoo.save
79
- zoo.reload!
80
- zoo.moo.should eql('4')
81
-
82
- moo.type = :integer
83
- moo.alter!
84
- zoo.reload!
85
- zoo.moo.should eql(4)
86
-
87
- moo.drop!
88
-
89
- Zoo.send(:undef_method, :moo)
90
- Zoo.send(:undef_method, :moo=)
91
- Zoo.properties.delete_if { |x| x.name == :moo }
92
-
93
- lambda { database.query("SELECT moo FROM zoos") }.should raise_error
94
- end
95
-
96
- it "should default the size of an integer column to 11" do
97
- integer = @mappings::Column.new(database(:mock).adapter, table, :age, :integer, 1)
98
- integer.size.should == 11
99
- end
100
-
101
- it "should be able to create a column with unique index" do
102
- column = table.add_column("name", :string, :index => :unique)
103
- column.unique?.should be_true
104
- column.index?.should be_nil
105
- table.to_create_index_sql.should == []
106
- table.to_create_sql.should match(/UNIQUE/)
107
- end
108
-
109
- it "should be able to create an indexed column" do
110
- column = table.add_column("age", :integer, :index => true)
111
- column.index?.should be_true
112
- table.to_create_index_sql[0].should match(/CREATE INDEX cow_age_index/)
113
- end
114
- end