activerecord 1.15.6 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- data/CHANGELOG +2454 -34
- data/README +1 -1
- data/RUNNING_UNIT_TESTS +3 -34
- data/Rakefile +98 -77
- data/install.rb +1 -1
- data/lib/active_record.rb +13 -22
- data/lib/active_record/aggregations.rb +38 -49
- data/lib/active_record/associations.rb +452 -333
- data/lib/active_record/associations/association_collection.rb +66 -20
- data/lib/active_record/associations/association_proxy.rb +9 -8
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +46 -51
- data/lib/active_record/associations/has_many_association.rb +21 -57
- data/lib/active_record/associations/has_many_through_association.rb +38 -18
- data/lib/active_record/associations/has_one_association.rb +30 -14
- data/lib/active_record/attribute_methods.rb +253 -0
- data/lib/active_record/base.rb +719 -494
- data/lib/active_record/calculations.rb +62 -63
- data/lib/active_record/callbacks.rb +57 -83
- data/lib/active_record/connection_adapters/abstract/connection_specification.rb +38 -9
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +56 -15
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +87 -0
- data/lib/active_record/connection_adapters/abstract/quoting.rb +23 -12
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +191 -62
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +37 -34
- data/lib/active_record/connection_adapters/abstract_adapter.rb +28 -17
- data/lib/active_record/connection_adapters/mysql_adapter.rb +119 -37
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +473 -210
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +34 -0
- data/lib/active_record/connection_adapters/sqlite_adapter.rb +91 -107
- data/lib/active_record/fixtures.rb +503 -113
- data/lib/active_record/locking/optimistic.rb +72 -34
- data/lib/active_record/migration.rb +80 -57
- data/lib/active_record/observer.rb +13 -10
- data/lib/active_record/query_cache.rb +16 -57
- data/lib/active_record/reflection.rb +35 -38
- data/lib/active_record/schema.rb +5 -5
- data/lib/active_record/schema_dumper.rb +35 -13
- data/lib/active_record/serialization.rb +98 -0
- data/lib/active_record/serializers/json_serializer.rb +71 -0
- data/lib/active_record/{xml_serialization.rb → serializers/xml_serializer.rb} +90 -83
- data/lib/active_record/timestamp.rb +20 -21
- data/lib/active_record/transactions.rb +39 -43
- data/lib/active_record/validations.rb +256 -107
- data/lib/active_record/version.rb +3 -3
- data/lib/activerecord.rb +1 -0
- data/test/aaa_create_tables_test.rb +15 -2
- data/test/abstract_unit.rb +24 -17
- data/test/active_schema_test_mysql.rb +20 -8
- data/test/adapter_test.rb +23 -5
- data/test/adapter_test_sqlserver.rb +15 -1
- data/test/aggregations_test.rb +16 -1
- data/test/all.sh +2 -2
- data/test/associations/ar_joins_test.rb +0 -0
- data/test/associations/callbacks_test.rb +51 -30
- data/test/associations/cascaded_eager_loading_test.rb +1 -29
- data/test/associations/eager_singularization_test.rb +145 -0
- data/test/associations/eager_test.rb +42 -6
- data/test/associations/extension_test.rb +6 -1
- data/test/associations/inner_join_association_test.rb +88 -0
- data/test/associations/join_model_test.rb +47 -16
- data/test/associations_test.rb +449 -226
- data/test/attribute_methods_test.rb +97 -0
- data/test/base_test.rb +251 -105
- data/test/binary_test.rb +22 -27
- data/test/calculations_test.rb +37 -5
- data/test/callbacks_test.rb +23 -0
- data/test/connection_test_firebird.rb +2 -2
- data/test/connection_test_mysql.rb +30 -0
- data/test/connections/native_mysql/connection.rb +3 -0
- data/test/connections/native_sqlite/connection.rb +5 -14
- data/test/connections/native_sqlite3/connection.rb +5 -14
- data/test/connections/native_sqlite3/in_memory_connection.rb +1 -1
- data/test/{copy_table_sqlite.rb → copy_table_test_sqlite.rb} +8 -3
- data/test/datatype_test_postgresql.rb +178 -27
- data/test/{empty_date_time_test.rb → date_time_test.rb} +13 -1
- data/test/defaults_test.rb +8 -1
- data/test/deprecated_finder_test.rb +7 -128
- data/test/finder_test.rb +192 -54
- data/test/fixtures/all/developers.yml +0 -0
- data/test/fixtures/all/people.csv +0 -0
- data/test/fixtures/all/tasks.yml +0 -0
- data/test/fixtures/author.rb +12 -5
- data/test/fixtures/binaries.yml +130 -435
- data/test/fixtures/category.rb +6 -0
- data/test/fixtures/company.rb +8 -1
- data/test/fixtures/computer.rb +1 -0
- data/test/fixtures/contact.rb +16 -0
- data/test/fixtures/customer.rb +2 -2
- data/test/fixtures/db_definitions/db2.drop.sql +1 -0
- data/test/fixtures/db_definitions/db2.sql +4 -0
- data/test/fixtures/db_definitions/firebird.drop.sql +3 -1
- data/test/fixtures/db_definitions/firebird.sql +6 -0
- data/test/fixtures/db_definitions/frontbase.drop.sql +1 -0
- data/test/fixtures/db_definitions/frontbase.sql +5 -0
- data/test/fixtures/db_definitions/openbase.sql +41 -25
- data/test/fixtures/db_definitions/oracle.drop.sql +2 -0
- data/test/fixtures/db_definitions/oracle.sql +5 -0
- data/test/fixtures/db_definitions/postgresql.drop.sql +7 -0
- data/test/fixtures/db_definitions/postgresql.sql +87 -58
- data/test/fixtures/db_definitions/postgresql2.sql +1 -2
- data/test/fixtures/db_definitions/schema.rb +280 -0
- data/test/fixtures/db_definitions/schema2.rb +11 -0
- data/test/fixtures/db_definitions/sqlite.drop.sql +1 -0
- data/test/fixtures/db_definitions/sqlite.sql +4 -0
- data/test/fixtures/db_definitions/sybase.drop.sql +1 -0
- data/test/fixtures/db_definitions/sybase.sql +4 -0
- data/test/fixtures/developer.rb +10 -0
- data/test/fixtures/example.log +1 -0
- data/test/fixtures/flowers.jpg +0 -0
- data/test/fixtures/item.rb +7 -0
- data/test/fixtures/items.yml +4 -0
- data/test/fixtures/joke.rb +0 -3
- data/test/fixtures/matey.rb +4 -0
- data/test/fixtures/mateys.yml +4 -0
- data/test/fixtures/minimalistic.rb +2 -0
- data/test/fixtures/minimalistics.yml +2 -0
- data/test/fixtures/mixins.yml +2 -100
- data/test/fixtures/parrot.rb +13 -0
- data/test/fixtures/parrots.yml +27 -0
- data/test/fixtures/parrots_pirates.yml +7 -0
- data/test/fixtures/pirate.rb +5 -0
- data/test/fixtures/pirates.yml +9 -0
- data/test/fixtures/post.rb +1 -0
- data/test/fixtures/project.rb +3 -2
- data/test/fixtures/reserved_words/distinct.yml +5 -0
- data/test/fixtures/reserved_words/distincts_selects.yml +11 -0
- data/test/fixtures/reserved_words/group.yml +14 -0
- data/test/fixtures/reserved_words/select.yml +8 -0
- data/test/fixtures/reserved_words/values.yml +7 -0
- data/test/fixtures/ship.rb +3 -0
- data/test/fixtures/ships.yml +5 -0
- data/test/fixtures/tagging.rb +4 -0
- data/test/fixtures/taggings.yml +8 -1
- data/test/fixtures/topic.rb +13 -1
- data/test/fixtures/treasure.rb +4 -0
- data/test/fixtures/treasures.yml +10 -0
- data/test/fixtures_test.rb +205 -24
- data/test/inheritance_test.rb +7 -1
- data/test/json_serialization_test.rb +180 -0
- data/test/lifecycle_test.rb +1 -1
- data/test/locking_test.rb +85 -2
- data/test/migration_test.rb +206 -40
- data/test/mixin_test.rb +13 -515
- data/test/pk_test.rb +3 -6
- data/test/query_cache_test.rb +104 -0
- data/test/reflection_test.rb +16 -0
- data/test/reserved_word_test_mysql.rb +177 -0
- data/test/schema_dumper_test.rb +38 -3
- data/test/serialization_test.rb +47 -0
- data/test/transactions_test.rb +74 -23
- data/test/unconnected_test.rb +1 -1
- data/test/validations_test.rb +322 -32
- data/test/xml_serialization_test.rb +121 -44
- metadata +48 -41
- data/examples/associations.rb +0 -87
- data/examples/shared_setup.rb +0 -15
- data/examples/validation.rb +0 -85
- data/lib/active_record/acts/list.rb +0 -256
- data/lib/active_record/acts/nested_set.rb +0 -211
- data/lib/active_record/acts/tree.rb +0 -96
- data/lib/active_record/connection_adapters/db2_adapter.rb +0 -228
- data/lib/active_record/connection_adapters/firebird_adapter.rb +0 -728
- data/lib/active_record/connection_adapters/frontbase_adapter.rb +0 -861
- data/lib/active_record/connection_adapters/openbase_adapter.rb +0 -350
- data/lib/active_record/connection_adapters/oracle_adapter.rb +0 -690
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +0 -591
- data/lib/active_record/connection_adapters/sybase_adapter.rb +0 -662
- data/lib/active_record/deprecated_associations.rb +0 -104
- data/lib/active_record/deprecated_finders.rb +0 -44
- data/lib/active_record/vendor/simple.rb +0 -693
- data/lib/active_record/wrappers/yaml_wrapper.rb +0 -15
- data/lib/active_record/wrappings.rb +0 -58
- data/test/connections/native_sqlserver/connection.rb +0 -23
- data/test/connections/native_sqlserver_odbc/connection.rb +0 -25
- data/test/deprecated_associations_test.rb +0 -396
- data/test/fixtures/db_definitions/mysql.drop.sql +0 -32
- data/test/fixtures/db_definitions/mysql.sql +0 -234
- data/test/fixtures/db_definitions/mysql2.drop.sql +0 -2
- data/test/fixtures/db_definitions/mysql2.sql +0 -5
- data/test/fixtures/db_definitions/sqlserver.drop.sql +0 -34
- data/test/fixtures/db_definitions/sqlserver.sql +0 -243
- data/test/fixtures/db_definitions/sqlserver2.drop.sql +0 -2
- data/test/fixtures/db_definitions/sqlserver2.sql +0 -5
- data/test/fixtures/mixin.rb +0 -63
- data/test/mixin_nested_set_test.rb +0 -196
@@ -0,0 +1,13 @@
|
|
1
|
+
class Parrot < ActiveRecord::Base
|
2
|
+
set_inheritance_column :parrot_sti_class
|
3
|
+
has_and_belongs_to_many :pirates
|
4
|
+
has_and_belongs_to_many :treasures
|
5
|
+
has_many :loots, :as => :looter
|
6
|
+
end
|
7
|
+
|
8
|
+
class LiveParrot < Parrot
|
9
|
+
end
|
10
|
+
|
11
|
+
class DeadParrot < Parrot
|
12
|
+
belongs_to :killer, :class_name => 'Pirate'
|
13
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
george:
|
2
|
+
name: "Curious George"
|
3
|
+
treasures: diamond, sapphire
|
4
|
+
parrot_sti_class: LiveParrot
|
5
|
+
|
6
|
+
louis:
|
7
|
+
name: "King Louis"
|
8
|
+
treasures: [diamond, sapphire]
|
9
|
+
parrot_sti_class: LiveParrot
|
10
|
+
|
11
|
+
frederick:
|
12
|
+
name: $LABEL
|
13
|
+
parrot_sti_class: LiveParrot
|
14
|
+
|
15
|
+
polly:
|
16
|
+
id: 4
|
17
|
+
name: $LABEL
|
18
|
+
killer: blackbeard
|
19
|
+
treasures: sapphire, ruby
|
20
|
+
parrot_sti_class: DeadParrot
|
21
|
+
|
22
|
+
DEFAULTS: &DEFAULTS
|
23
|
+
treasures: sapphire, ruby
|
24
|
+
parrot_sti_class: LiveParrot
|
25
|
+
|
26
|
+
davey:
|
27
|
+
<<: *DEFAULTS
|
data/test/fixtures/post.rb
CHANGED
@@ -16,6 +16,7 @@ class Post < ActiveRecord::Base
|
|
16
16
|
has_one :very_special_comment
|
17
17
|
has_one :very_special_comment_with_post, :class_name => "VerySpecialComment", :include => :post
|
18
18
|
has_many :special_comments
|
19
|
+
has_many :nonexistant_comments, :class_name => 'Comment', :conditions => 'comments.id < 0'
|
19
20
|
|
20
21
|
has_and_belongs_to_many :categories
|
21
22
|
has_and_belongs_to_many :special_categories, :join_table => "categories_posts", :association_foreign_key => 'category_id'
|
data/test/fixtures/project.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
class Project < ActiveRecord::Base
|
2
2
|
has_and_belongs_to_many :developers, :uniq => true, :order => 'developers.name desc, developers.id desc'
|
3
|
+
has_and_belongs_to_many :selected_developers, :class_name => "Developer", :select => "developers.*", :uniq => true
|
3
4
|
has_and_belongs_to_many :non_unique_developers, :order => 'developers.name desc, developers.id desc', :class_name => 'Developer'
|
4
5
|
has_and_belongs_to_many :limited_developers, :class_name => "Developer", :limit => 1
|
5
6
|
has_and_belongs_to_many :developers_named_david, :class_name => "Developer", :conditions => "name = 'David'", :uniq => true
|
@@ -7,8 +8,8 @@ class Project < ActiveRecord::Base
|
|
7
8
|
has_and_belongs_to_many :salaried_developers, :class_name => "Developer", :conditions => "salary > 0"
|
8
9
|
has_and_belongs_to_many :developers_with_finder_sql, :class_name => "Developer", :finder_sql => 'SELECT t.*, j.* FROM developers_projects j, developers t WHERE t.id = j.developer_id AND j.project_id = #{id}'
|
9
10
|
has_and_belongs_to_many :developers_by_sql, :class_name => "Developer", :delete_sql => "DELETE FROM developers_projects WHERE project_id = \#{id} AND developer_id = \#{record.id}"
|
10
|
-
has_and_belongs_to_many :developers_with_callbacks, :class_name => "Developer", :before_add => Proc.new {|o, r| o.developers_log << "before_adding#{r.id}"},
|
11
|
-
:after_add => Proc.new {|o, r| o.developers_log << "after_adding#{r.id}"},
|
11
|
+
has_and_belongs_to_many :developers_with_callbacks, :class_name => "Developer", :before_add => Proc.new {|o, r| o.developers_log << "before_adding#{r.id || '<new>'}"},
|
12
|
+
:after_add => Proc.new {|o, r| o.developers_log << "after_adding#{r.id || '<new>'}"},
|
12
13
|
:before_remove => Proc.new {|o, r| o.developers_log << "before_removing#{r.id}"},
|
13
14
|
:after_remove => Proc.new {|o, r| o.developers_log << "after_removing#{r.id}"}
|
14
15
|
|
data/test/fixtures/tagging.rb
CHANGED
data/test/fixtures/taggings.yml
CHANGED
data/test/fixtures/topic.rb
CHANGED
@@ -13,8 +13,14 @@ class Topic < ActiveRecord::Base
|
|
13
13
|
def topic_id
|
14
14
|
id
|
15
15
|
end
|
16
|
+
|
16
17
|
|
17
18
|
protected
|
19
|
+
def approved=(val)
|
20
|
+
@custom_approved = val
|
21
|
+
write_attribute(:approved, val)
|
22
|
+
end
|
23
|
+
|
18
24
|
def default_written_on
|
19
25
|
self.written_on = Time.now unless attribute_present?("written_on")
|
20
26
|
end
|
@@ -22,4 +28,10 @@ class Topic < ActiveRecord::Base
|
|
22
28
|
def destroy_children
|
23
29
|
self.class.delete_all "parent_id = #{id}"
|
24
30
|
end
|
25
|
-
|
31
|
+
|
32
|
+
def after_initialize
|
33
|
+
if self.new_record?
|
34
|
+
self.author_email_address = 'test@test.com'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/test/fixtures_test.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'abstract_unit'
|
2
|
+
require 'fixtures/post'
|
3
|
+
require 'fixtures/binary'
|
2
4
|
require 'fixtures/topic'
|
5
|
+
require 'fixtures/computer'
|
3
6
|
require 'fixtures/developer'
|
4
7
|
require 'fixtures/company'
|
5
8
|
require 'fixtures/task'
|
@@ -7,6 +10,11 @@ require 'fixtures/reply'
|
|
7
10
|
require 'fixtures/joke'
|
8
11
|
require 'fixtures/course'
|
9
12
|
require 'fixtures/category'
|
13
|
+
require 'fixtures/parrot'
|
14
|
+
require 'fixtures/pirate'
|
15
|
+
require 'fixtures/treasure'
|
16
|
+
require 'fixtures/matey'
|
17
|
+
require 'fixtures/ship'
|
10
18
|
|
11
19
|
class FixturesTest < Test::Unit::TestCase
|
12
20
|
self.use_instantiated_fixtures = true
|
@@ -49,15 +57,18 @@ class FixturesTest < Test::Unit::TestCase
|
|
49
57
|
|
50
58
|
def test_inserts
|
51
59
|
topics = create_fixtures("topics")
|
52
|
-
|
53
|
-
assert_equal("The First Topic",
|
60
|
+
first_row = ActiveRecord::Base.connection.select_one("SELECT * FROM topics WHERE author_name = 'David'")
|
61
|
+
assert_equal("The First Topic", first_row["title"])
|
54
62
|
|
55
|
-
|
56
|
-
assert_nil(
|
63
|
+
second_row = ActiveRecord::Base.connection.select_one("SELECT * FROM topics WHERE author_name = 'Mary'")
|
64
|
+
assert_nil(second_row["author_email_address"])
|
57
65
|
end
|
58
66
|
|
59
67
|
if ActiveRecord::Base.connection.supports_migrations?
|
60
68
|
def test_inserts_with_pre_and_suffix
|
69
|
+
# Reset cache to make finds on the new table work
|
70
|
+
Fixtures.reset_cache
|
71
|
+
|
61
72
|
ActiveRecord::Base.connection.create_table :prefix_topics_suffix do |t|
|
62
73
|
t.column :title, :string
|
63
74
|
t.column :author_name, :string
|
@@ -82,15 +93,15 @@ class FixturesTest < Test::Unit::TestCase
|
|
82
93
|
|
83
94
|
topics = create_fixtures("topics")
|
84
95
|
|
85
|
-
|
86
|
-
assert_equal("The First Topic",
|
96
|
+
first_row = ActiveRecord::Base.connection.select_one("SELECT * FROM prefix_topics_suffix WHERE author_name = 'David'")
|
97
|
+
assert_equal("The First Topic", first_row["title"])
|
87
98
|
|
88
|
-
|
89
|
-
assert_nil(
|
99
|
+
second_row = ActiveRecord::Base.connection.select_one("SELECT * FROM prefix_topics_suffix WHERE author_name = 'Mary'")
|
100
|
+
assert_nil(second_row["author_email_address"])
|
90
101
|
ensure
|
91
102
|
# Restore prefix/suffix to its previous values
|
92
|
-
ActiveRecord::Base.table_name_prefix = old_prefix
|
93
|
-
ActiveRecord::Base.table_name_suffix = old_suffix
|
103
|
+
ActiveRecord::Base.table_name_prefix = old_prefix
|
104
|
+
ActiveRecord::Base.table_name_suffix = old_suffix
|
94
105
|
|
95
106
|
ActiveRecord::Base.connection.drop_table :prefix_topics_suffix rescue nil
|
96
107
|
end
|
@@ -187,7 +198,7 @@ class FixturesTest < Test::Unit::TestCase
|
|
187
198
|
|
188
199
|
def test_binary_in_fixtures
|
189
200
|
assert_equal 1, @binaries.size
|
190
|
-
data = File.
|
201
|
+
data = File.open(BINARY_FIXTURE_PATH, "rb").read.freeze
|
191
202
|
assert_equal data, @flowers.data
|
192
203
|
end
|
193
204
|
end
|
@@ -199,6 +210,7 @@ if Account.connection.respond_to?(:reset_pk_sequence!)
|
|
199
210
|
|
200
211
|
def setup
|
201
212
|
@instances = [Account.new(:credit_limit => 50), Company.new(:name => 'RoR Consulting')]
|
213
|
+
Fixtures.reset_cache # make sure tables get reinitialized
|
202
214
|
end
|
203
215
|
|
204
216
|
def test_resets_to_min_pk_with_specified_pk_and_sequence
|
@@ -223,7 +235,7 @@ if Account.connection.respond_to?(:reset_pk_sequence!)
|
|
223
235
|
end
|
224
236
|
end
|
225
237
|
|
226
|
-
def
|
238
|
+
def test_create_fixtures_resets_sequences_when_not_cached
|
227
239
|
@instances.each do |instance|
|
228
240
|
max_id = create_fixtures(instance.class.table_name).inject(0) do |max_id, (name, fixture)|
|
229
241
|
fixture_id = fixture['id'].to_i
|
@@ -238,7 +250,6 @@ if Account.connection.respond_to?(:reset_pk_sequence!)
|
|
238
250
|
end
|
239
251
|
end
|
240
252
|
|
241
|
-
|
242
253
|
class FixturesWithoutInstantiationTest < Test::Unit::TestCase
|
243
254
|
self.use_instantiated_fixtures = false
|
244
255
|
fixtures :topics, :developers, :accounts
|
@@ -259,8 +270,20 @@ class FixturesWithoutInstantiationTest < Test::Unit::TestCase
|
|
259
270
|
assert_equal "Jamis", developers(:jamis).name
|
260
271
|
assert_equal 50, accounts(:signals37).credit_limit
|
261
272
|
end
|
262
|
-
end
|
263
273
|
|
274
|
+
def test_accessor_methods_with_multiple_args
|
275
|
+
assert_equal 2, topics(:first, :second).size
|
276
|
+
assert_raise(StandardError) { topics([:first, :second]) }
|
277
|
+
end
|
278
|
+
|
279
|
+
uses_mocha 'reloading_fixtures_through_accessor_methods' do
|
280
|
+
def test_reloading_fixtures_through_accessor_methods
|
281
|
+
assert_equal "The First Topic", topics(:first).title
|
282
|
+
@loaded_fixtures['topics']['first'].expects(:find).returns(stub(:title => "Fresh Topic!"))
|
283
|
+
assert_equal "Fresh Topic!", topics(:first, true).title
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
264
287
|
|
265
288
|
class FixturesWithoutInstanceInstantiationTest < Test::Unit::TestCase
|
266
289
|
self.use_instantiated_fixtures = true
|
@@ -276,7 +299,6 @@ class FixturesWithoutInstanceInstantiationTest < Test::Unit::TestCase
|
|
276
299
|
end
|
277
300
|
end
|
278
301
|
|
279
|
-
|
280
302
|
class TransactionalFixturesTest < Test::Unit::TestCase
|
281
303
|
self.use_instantiated_fixtures = true
|
282
304
|
self.use_transactional_fixtures = true
|
@@ -293,7 +315,6 @@ class TransactionalFixturesTest < Test::Unit::TestCase
|
|
293
315
|
end
|
294
316
|
end
|
295
317
|
|
296
|
-
|
297
318
|
class MultipleFixturesTest < Test::Unit::TestCase
|
298
319
|
fixtures :topics
|
299
320
|
fixtures :developers, :accounts
|
@@ -303,7 +324,6 @@ class MultipleFixturesTest < Test::Unit::TestCase
|
|
303
324
|
end
|
304
325
|
end
|
305
326
|
|
306
|
-
|
307
327
|
class OverlappingFixturesTest < Test::Unit::TestCase
|
308
328
|
fixtures :topics, :developers
|
309
329
|
fixtures :developers, :accounts
|
@@ -313,7 +333,6 @@ class OverlappingFixturesTest < Test::Unit::TestCase
|
|
313
333
|
end
|
314
334
|
end
|
315
335
|
|
316
|
-
|
317
336
|
class ForeignKeyFixturesTest < Test::Unit::TestCase
|
318
337
|
fixtures :fk_test_has_pk, :fk_test_has_fk
|
319
338
|
|
@@ -333,7 +352,7 @@ end
|
|
333
352
|
class SetTableNameFixturesTest < Test::Unit::TestCase
|
334
353
|
set_fixture_class :funny_jokes => 'Joke'
|
335
354
|
fixtures :funny_jokes
|
336
|
-
|
355
|
+
|
337
356
|
def test_table_method
|
338
357
|
assert_kind_of Joke, funny_jokes(:a_joke)
|
339
358
|
end
|
@@ -342,7 +361,7 @@ end
|
|
342
361
|
class CustomConnectionFixturesTest < Test::Unit::TestCase
|
343
362
|
set_fixture_class :courses => Course
|
344
363
|
fixtures :courses
|
345
|
-
|
364
|
+
|
346
365
|
def test_connection
|
347
366
|
assert_kind_of Course, courses(:ruby)
|
348
367
|
assert_equal Course.connection, courses(:ruby).connection
|
@@ -368,17 +387,15 @@ class CheckEscapedYamlFixturesTest < Test::Unit::TestCase
|
|
368
387
|
end
|
369
388
|
end
|
370
389
|
|
371
|
-
class DevelopersProject; end
|
372
|
-
|
390
|
+
class DevelopersProject; end
|
373
391
|
class ManyToManyFixturesWithClassDefined < Test::Unit::TestCase
|
374
392
|
fixtures :developers_projects
|
375
|
-
|
393
|
+
|
376
394
|
def test_this_should_run_cleanly
|
377
395
|
assert true
|
378
396
|
end
|
379
397
|
end
|
380
398
|
|
381
|
-
|
382
399
|
class FixturesBrokenRollbackTest < Test::Unit::TestCase
|
383
400
|
def blank_setup; end
|
384
401
|
alias_method :ar_setup_with_fixtures, :setup_with_fixtures
|
@@ -403,3 +420,167 @@ class FixturesBrokenRollbackTest < Test::Unit::TestCase
|
|
403
420
|
raise 'argh'
|
404
421
|
end
|
405
422
|
end
|
423
|
+
|
424
|
+
class LoadAllFixturesTest < Test::Unit::TestCase
|
425
|
+
self.fixture_path= File.join(File.dirname(__FILE__), '/fixtures/all')
|
426
|
+
fixtures :all
|
427
|
+
|
428
|
+
def test_all_there
|
429
|
+
assert_equal %w(developers people tasks), fixture_table_names.sort
|
430
|
+
end
|
431
|
+
end
|
432
|
+
|
433
|
+
class FasterFixturesTest < Test::Unit::TestCase
|
434
|
+
fixtures :categories, :authors
|
435
|
+
|
436
|
+
def load_extra_fixture(name)
|
437
|
+
fixture = create_fixtures(name)
|
438
|
+
assert fixture.is_a?(Fixtures)
|
439
|
+
@loaded_fixtures[fixture.table_name] = fixture
|
440
|
+
end
|
441
|
+
|
442
|
+
def test_cache
|
443
|
+
assert Fixtures.fixture_is_cached?(ActiveRecord::Base.connection, 'categories')
|
444
|
+
assert Fixtures.fixture_is_cached?(ActiveRecord::Base.connection, 'authors')
|
445
|
+
|
446
|
+
assert_no_queries do
|
447
|
+
create_fixtures('categories')
|
448
|
+
create_fixtures('authors')
|
449
|
+
end
|
450
|
+
|
451
|
+
load_extra_fixture('posts')
|
452
|
+
assert Fixtures.fixture_is_cached?(ActiveRecord::Base.connection, 'posts')
|
453
|
+
self.class.setup_fixture_accessors('posts')
|
454
|
+
assert_equal 'Welcome to the weblog', posts(:welcome).title
|
455
|
+
end
|
456
|
+
end
|
457
|
+
|
458
|
+
class FoxyFixturesTest < Test::Unit::TestCase
|
459
|
+
fixtures :parrots, :parrots_pirates, :pirates, :treasures, :mateys, :ships, :computers, :developers
|
460
|
+
|
461
|
+
def test_identifies_strings
|
462
|
+
assert_equal(Fixtures.identify("foo"), Fixtures.identify("foo"))
|
463
|
+
assert_not_equal(Fixtures.identify("foo"), Fixtures.identify("FOO"))
|
464
|
+
end
|
465
|
+
|
466
|
+
def test_identifies_symbols
|
467
|
+
assert_equal(Fixtures.identify(:foo), Fixtures.identify(:foo))
|
468
|
+
end
|
469
|
+
|
470
|
+
TIMESTAMP_COLUMNS = %w(created_at created_on updated_at updated_on)
|
471
|
+
|
472
|
+
def test_populates_timestamp_columns
|
473
|
+
TIMESTAMP_COLUMNS.each do |property|
|
474
|
+
assert_not_nil(parrots(:george).send(property), "should set #{property}")
|
475
|
+
end
|
476
|
+
end
|
477
|
+
|
478
|
+
def test_does_not_populate_timestamp_columns_if_model_has_set_record_timestamps_to_false
|
479
|
+
TIMESTAMP_COLUMNS.each do |property|
|
480
|
+
assert_nil(ships(:black_pearl).send(property), "should not set #{property}")
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
484
|
+
def test_populates_all_columns_with_the_same_time
|
485
|
+
last = nil
|
486
|
+
|
487
|
+
TIMESTAMP_COLUMNS.each do |property|
|
488
|
+
current = parrots(:george).send(property)
|
489
|
+
last ||= current
|
490
|
+
|
491
|
+
assert_equal(last, current)
|
492
|
+
last = current
|
493
|
+
end
|
494
|
+
end
|
495
|
+
|
496
|
+
def test_only_populates_columns_that_exist
|
497
|
+
assert_not_nil(pirates(:blackbeard).created_on)
|
498
|
+
assert_not_nil(pirates(:blackbeard).updated_on)
|
499
|
+
end
|
500
|
+
|
501
|
+
def test_preserves_existing_fixture_data
|
502
|
+
assert_equal(2.weeks.ago.to_date, pirates(:redbeard).created_on.to_date)
|
503
|
+
assert_equal(2.weeks.ago.to_date, pirates(:redbeard).updated_on.to_date)
|
504
|
+
end
|
505
|
+
|
506
|
+
def test_generates_unique_ids
|
507
|
+
assert_not_nil(parrots(:george).id)
|
508
|
+
assert_not_equal(parrots(:george).id, parrots(:louis).id)
|
509
|
+
end
|
510
|
+
|
511
|
+
def test_automatically_sets_primary_key
|
512
|
+
assert_not_nil(ships(:black_pearl))
|
513
|
+
end
|
514
|
+
|
515
|
+
def test_preserves_existing_primary_key
|
516
|
+
assert_equal(2, ships(:interceptor).id)
|
517
|
+
end
|
518
|
+
|
519
|
+
def test_resolves_belongs_to_symbols
|
520
|
+
assert_equal(parrots(:george), pirates(:blackbeard).parrot)
|
521
|
+
end
|
522
|
+
|
523
|
+
def test_ignores_belongs_to_symbols_if_association_and_foreign_key_are_named_the_same
|
524
|
+
assert_equal(developers(:david), computers(:workstation).developer)
|
525
|
+
end
|
526
|
+
|
527
|
+
def test_supports_join_tables
|
528
|
+
assert(pirates(:blackbeard).parrots.include?(parrots(:george)))
|
529
|
+
assert(pirates(:blackbeard).parrots.include?(parrots(:louis)))
|
530
|
+
assert(parrots(:george).pirates.include?(pirates(:blackbeard)))
|
531
|
+
end
|
532
|
+
|
533
|
+
def test_supports_inline_habtm
|
534
|
+
assert(parrots(:george).treasures.include?(treasures(:diamond)))
|
535
|
+
assert(parrots(:george).treasures.include?(treasures(:sapphire)))
|
536
|
+
assert(!parrots(:george).treasures.include?(treasures(:ruby)))
|
537
|
+
end
|
538
|
+
|
539
|
+
def test_supports_inline_habtm_with_specified_id
|
540
|
+
assert(parrots(:polly).treasures.include?(treasures(:ruby)))
|
541
|
+
assert(parrots(:polly).treasures.include?(treasures(:sapphire)))
|
542
|
+
assert(!parrots(:polly).treasures.include?(treasures(:diamond)))
|
543
|
+
end
|
544
|
+
|
545
|
+
def test_supports_yaml_arrays
|
546
|
+
assert(parrots(:louis).treasures.include?(treasures(:diamond)))
|
547
|
+
assert(parrots(:louis).treasures.include?(treasures(:sapphire)))
|
548
|
+
end
|
549
|
+
|
550
|
+
def test_strips_DEFAULTS_key
|
551
|
+
assert_raise(StandardError) { parrots(:DEFAULTS) }
|
552
|
+
|
553
|
+
# this lets us do YAML defaults and not have an extra fixture entry
|
554
|
+
%w(sapphire ruby).each { |t| assert(parrots(:davey).treasures.include?(treasures(t))) }
|
555
|
+
end
|
556
|
+
|
557
|
+
def test_supports_label_interpolation
|
558
|
+
assert_equal("frederick", parrots(:frederick).name)
|
559
|
+
end
|
560
|
+
|
561
|
+
def test_supports_polymorphic_belongs_to
|
562
|
+
assert_equal(pirates(:redbeard), treasures(:sapphire).looter)
|
563
|
+
assert_equal(parrots(:louis), treasures(:ruby).looter)
|
564
|
+
end
|
565
|
+
|
566
|
+
def test_only_generates_a_pk_if_necessary
|
567
|
+
m = Matey.find(:first)
|
568
|
+
m.pirate = pirates(:blackbeard)
|
569
|
+
m.target = pirates(:redbeard)
|
570
|
+
end
|
571
|
+
|
572
|
+
def test_supports_sti
|
573
|
+
assert_kind_of DeadParrot, parrots(:polly)
|
574
|
+
assert_equal pirates(:blackbeard), parrots(:polly).killer
|
575
|
+
end
|
576
|
+
end
|
577
|
+
|
578
|
+
class ActiveSupportSubclassWithFixturesTest < ActiveSupport::TestCase
|
579
|
+
fixtures :parrots
|
580
|
+
|
581
|
+
# This seemingly useless assertion catches a bug that caused the fixtures
|
582
|
+
# setup code call nil[]
|
583
|
+
def test_foo
|
584
|
+
assert_equal parrots(:louis), Parrot.find_by_name("King Louis")
|
585
|
+
end
|
586
|
+
end
|