activerecord 1.0.0 → 4.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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +2102 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +213 -0
- data/examples/performance.rb +172 -0
- data/examples/simple.rb +14 -0
- data/lib/active_record/aggregations.rb +180 -84
- data/lib/active_record/associations/alias_tracker.rb +76 -0
- data/lib/active_record/associations/association.rb +248 -0
- data/lib/active_record/associations/association_scope.rb +135 -0
- data/lib/active_record/associations/belongs_to_association.rb +92 -0
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +35 -0
- data/lib/active_record/associations/builder/association.rb +108 -0
- data/lib/active_record/associations/builder/belongs_to.rb +98 -0
- data/lib/active_record/associations/builder/collection_association.rb +89 -0
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +39 -0
- data/lib/active_record/associations/builder/has_many.rb +15 -0
- data/lib/active_record/associations/builder/has_one.rb +25 -0
- data/lib/active_record/associations/builder/singular_association.rb +32 -0
- data/lib/active_record/associations/collection_association.rb +608 -0
- data/lib/active_record/associations/collection_proxy.rb +986 -0
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +58 -39
- data/lib/active_record/associations/has_many_association.rb +116 -85
- data/lib/active_record/associations/has_many_through_association.rb +197 -0
- data/lib/active_record/associations/has_one_association.rb +102 -0
- data/lib/active_record/associations/has_one_through_association.rb +36 -0
- data/lib/active_record/associations/join_dependency/join_association.rb +174 -0
- data/lib/active_record/associations/join_dependency/join_base.rb +24 -0
- data/lib/active_record/associations/join_dependency/join_part.rb +78 -0
- data/lib/active_record/associations/join_dependency.rb +235 -0
- data/lib/active_record/associations/join_helper.rb +45 -0
- data/lib/active_record/associations/preloader/association.rb +121 -0
- data/lib/active_record/associations/preloader/belongs_to.rb +17 -0
- data/lib/active_record/associations/preloader/collection_association.rb +24 -0
- data/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +60 -0
- data/lib/active_record/associations/preloader/has_many.rb +17 -0
- data/lib/active_record/associations/preloader/has_many_through.rb +19 -0
- data/lib/active_record/associations/preloader/has_one.rb +23 -0
- data/lib/active_record/associations/preloader/has_one_through.rb +9 -0
- data/lib/active_record/associations/preloader/singular_association.rb +21 -0
- data/lib/active_record/associations/preloader/through_association.rb +63 -0
- data/lib/active_record/associations/preloader.rb +178 -0
- data/lib/active_record/associations/singular_association.rb +64 -0
- data/lib/active_record/associations/through_association.rb +87 -0
- data/lib/active_record/associations.rb +1437 -431
- data/lib/active_record/attribute_assignment.rb +201 -0
- data/lib/active_record/attribute_methods/before_type_cast.rb +70 -0
- data/lib/active_record/attribute_methods/dirty.rb +118 -0
- data/lib/active_record/attribute_methods/primary_key.rb +122 -0
- data/lib/active_record/attribute_methods/query.rb +40 -0
- data/lib/active_record/attribute_methods/read.rb +107 -0
- data/lib/active_record/attribute_methods/serialization.rb +162 -0
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +59 -0
- data/lib/active_record/attribute_methods/write.rb +63 -0
- data/lib/active_record/attribute_methods.rb +393 -0
- data/lib/active_record/autosave_association.rb +426 -0
- data/lib/active_record/base.rb +268 -930
- data/lib/active_record/callbacks.rb +203 -230
- data/lib/active_record/coders/yaml_column.rb +38 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +638 -0
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +67 -0
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +390 -0
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +95 -0
- data/lib/active_record/connection_adapters/abstract/quoting.rb +129 -0
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +501 -0
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +70 -0
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +873 -0
- data/lib/active_record/connection_adapters/abstract/transaction.rb +203 -0
- data/lib/active_record/connection_adapters/abstract_adapter.rb +389 -275
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +782 -0
- data/lib/active_record/connection_adapters/column.rb +318 -0
- data/lib/active_record/connection_adapters/connection_specification.rb +96 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +273 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +517 -90
- data/lib/active_record/connection_adapters/postgresql/array_parser.rb +97 -0
- data/lib/active_record/connection_adapters/postgresql/cast.rb +152 -0
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +242 -0
- data/lib/active_record/connection_adapters/postgresql/oid.rb +366 -0
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +171 -0
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +30 -0
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +489 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +911 -138
- data/lib/active_record/connection_adapters/schema_cache.rb +129 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +624 -0
- data/lib/active_record/connection_adapters/statement_pool.rb +40 -0
- data/lib/active_record/connection_handling.rb +98 -0
- data/lib/active_record/core.rb +463 -0
- data/lib/active_record/counter_cache.rb +122 -0
- data/lib/active_record/dynamic_matchers.rb +131 -0
- data/lib/active_record/errors.rb +213 -0
- data/lib/active_record/explain.rb +38 -0
- data/lib/active_record/explain_registry.rb +30 -0
- data/lib/active_record/explain_subscriber.rb +29 -0
- data/lib/active_record/fixture_set/file.rb +55 -0
- data/lib/active_record/fixtures.rb +892 -138
- data/lib/active_record/inheritance.rb +200 -0
- data/lib/active_record/integration.rb +60 -0
- data/lib/active_record/locale/en.yml +47 -0
- data/lib/active_record/locking/optimistic.rb +181 -0
- data/lib/active_record/locking/pessimistic.rb +77 -0
- data/lib/active_record/log_subscriber.rb +82 -0
- data/lib/active_record/migration/command_recorder.rb +164 -0
- data/lib/active_record/migration/join_table.rb +15 -0
- data/lib/active_record/migration.rb +1015 -0
- data/lib/active_record/model_schema.rb +345 -0
- data/lib/active_record/nested_attributes.rb +546 -0
- data/lib/active_record/null_relation.rb +65 -0
- data/lib/active_record/persistence.rb +509 -0
- data/lib/active_record/query_cache.rb +56 -0
- data/lib/active_record/querying.rb +62 -0
- data/lib/active_record/railtie.rb +205 -0
- data/lib/active_record/railties/console_sandbox.rb +5 -0
- data/lib/active_record/railties/controller_runtime.rb +50 -0
- data/lib/active_record/railties/databases.rake +402 -0
- data/lib/active_record/railties/jdbcmysql_error.rb +16 -0
- data/lib/active_record/readonly_attributes.rb +30 -0
- data/lib/active_record/reflection.rb +544 -87
- data/lib/active_record/relation/batches.rb +93 -0
- data/lib/active_record/relation/calculations.rb +399 -0
- data/lib/active_record/relation/delegation.rb +125 -0
- data/lib/active_record/relation/finder_methods.rb +349 -0
- data/lib/active_record/relation/merger.rb +161 -0
- data/lib/active_record/relation/predicate_builder.rb +106 -0
- data/lib/active_record/relation/query_methods.rb +1044 -0
- data/lib/active_record/relation/spawn_methods.rb +73 -0
- data/lib/active_record/relation.rb +655 -0
- data/lib/active_record/result.rb +67 -0
- data/lib/active_record/runtime_registry.rb +17 -0
- data/lib/active_record/sanitization.rb +168 -0
- data/lib/active_record/schema.rb +65 -0
- data/lib/active_record/schema_dumper.rb +204 -0
- data/lib/active_record/schema_migration.rb +39 -0
- data/lib/active_record/scoping/default.rb +146 -0
- data/lib/active_record/scoping/named.rb +175 -0
- data/lib/active_record/scoping.rb +82 -0
- data/lib/active_record/serialization.rb +22 -0
- data/lib/active_record/serializers/xml_serializer.rb +197 -0
- data/lib/active_record/statement_cache.rb +26 -0
- data/lib/active_record/store.rb +156 -0
- data/lib/active_record/tasks/database_tasks.rb +203 -0
- data/lib/active_record/tasks/firebird_database_tasks.rb +56 -0
- data/lib/active_record/tasks/mysql_database_tasks.rb +143 -0
- data/lib/active_record/tasks/oracle_database_tasks.rb +45 -0
- data/lib/active_record/tasks/postgresql_database_tasks.rb +90 -0
- data/lib/active_record/tasks/sqlite_database_tasks.rb +51 -0
- data/lib/active_record/tasks/sqlserver_database_tasks.rb +48 -0
- data/lib/active_record/test_case.rb +96 -0
- data/lib/active_record/timestamp.rb +119 -0
- data/lib/active_record/transactions.rb +366 -69
- data/lib/active_record/translation.rb +22 -0
- data/lib/active_record/validations/associated.rb +49 -0
- data/lib/active_record/validations/presence.rb +65 -0
- data/lib/active_record/validations/uniqueness.rb +225 -0
- data/lib/active_record/validations.rb +64 -185
- data/lib/active_record/version.rb +11 -0
- data/lib/active_record.rb +149 -24
- data/lib/rails/generators/active_record/migration/migration_generator.rb +62 -0
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb +19 -0
- data/lib/rails/generators/active_record/migration/templates/migration.rb +39 -0
- data/lib/rails/generators/active_record/model/model_generator.rb +48 -0
- data/lib/rails/generators/active_record/model/templates/model.rb +10 -0
- data/lib/rails/generators/active_record/model/templates/module.rb +7 -0
- data/lib/rails/generators/active_record.rb +23 -0
- metadata +261 -161
- data/CHANGELOG +0 -581
- data/README +0 -361
- data/RUNNING_UNIT_TESTS +0 -36
- data/dev-utils/eval_debugger.rb +0 -9
- data/examples/associations.png +0 -0
- data/examples/associations.rb +0 -87
- data/examples/shared_setup.rb +0 -15
- data/examples/validation.rb +0 -88
- data/install.rb +0 -60
- data/lib/active_record/associations/association_collection.rb +0 -70
- data/lib/active_record/connection_adapters/sqlite_adapter.rb +0 -107
- data/lib/active_record/deprecated_associations.rb +0 -70
- data/lib/active_record/observer.rb +0 -71
- data/lib/active_record/support/class_attribute_accessors.rb +0 -43
- data/lib/active_record/support/class_inheritable_attributes.rb +0 -37
- data/lib/active_record/support/clean_logger.rb +0 -10
- data/lib/active_record/support/inflector.rb +0 -70
- data/lib/active_record/vendor/mysql.rb +0 -1117
- data/lib/active_record/vendor/simple.rb +0 -702
- data/lib/active_record/wrappers/yaml_wrapper.rb +0 -15
- data/lib/active_record/wrappings.rb +0 -59
- data/rakefile +0 -122
- data/test/abstract_unit.rb +0 -16
- data/test/aggregations_test.rb +0 -34
- data/test/all.sh +0 -8
- data/test/associations_test.rb +0 -477
- data/test/base_test.rb +0 -513
- data/test/class_inheritable_attributes_test.rb +0 -33
- data/test/connections/native_mysql/connection.rb +0 -24
- data/test/connections/native_postgresql/connection.rb +0 -24
- data/test/connections/native_sqlite/connection.rb +0 -24
- data/test/deprecated_associations_test.rb +0 -336
- data/test/finder_test.rb +0 -67
- data/test/fixtures/accounts/signals37 +0 -3
- data/test/fixtures/accounts/unknown +0 -2
- data/test/fixtures/auto_id.rb +0 -4
- data/test/fixtures/column_name.rb +0 -3
- data/test/fixtures/companies/first_client +0 -6
- data/test/fixtures/companies/first_firm +0 -4
- data/test/fixtures/companies/second_client +0 -6
- data/test/fixtures/company.rb +0 -37
- data/test/fixtures/company_in_module.rb +0 -33
- data/test/fixtures/course.rb +0 -3
- data/test/fixtures/courses/java +0 -2
- data/test/fixtures/courses/ruby +0 -2
- data/test/fixtures/customer.rb +0 -30
- data/test/fixtures/customers/david +0 -6
- data/test/fixtures/db_definitions/mysql.sql +0 -96
- data/test/fixtures/db_definitions/mysql2.sql +0 -4
- data/test/fixtures/db_definitions/postgresql.sql +0 -113
- data/test/fixtures/db_definitions/postgresql2.sql +0 -4
- data/test/fixtures/db_definitions/sqlite.sql +0 -85
- data/test/fixtures/db_definitions/sqlite2.sql +0 -4
- data/test/fixtures/default.rb +0 -2
- data/test/fixtures/developer.rb +0 -8
- data/test/fixtures/developers/david +0 -2
- data/test/fixtures/developers/jamis +0 -2
- data/test/fixtures/developers_projects/david_action_controller +0 -2
- data/test/fixtures/developers_projects/david_active_record +0 -2
- data/test/fixtures/developers_projects/jamis_active_record +0 -2
- data/test/fixtures/entrant.rb +0 -3
- data/test/fixtures/entrants/first +0 -3
- data/test/fixtures/entrants/second +0 -3
- data/test/fixtures/entrants/third +0 -3
- data/test/fixtures/fixture_database.sqlite +0 -0
- data/test/fixtures/fixture_database_2.sqlite +0 -0
- data/test/fixtures/movie.rb +0 -5
- data/test/fixtures/movies/first +0 -2
- data/test/fixtures/movies/second +0 -2
- data/test/fixtures/project.rb +0 -3
- data/test/fixtures/projects/action_controller +0 -2
- data/test/fixtures/projects/active_record +0 -2
- data/test/fixtures/reply.rb +0 -21
- data/test/fixtures/subscriber.rb +0 -5
- data/test/fixtures/subscribers/first +0 -2
- data/test/fixtures/subscribers/second +0 -2
- data/test/fixtures/topic.rb +0 -20
- data/test/fixtures/topics/first +0 -9
- data/test/fixtures/topics/second +0 -8
- data/test/fixtures_test.rb +0 -20
- data/test/inflector_test.rb +0 -104
- data/test/inheritance_test.rb +0 -125
- data/test/lifecycle_test.rb +0 -110
- data/test/modules_test.rb +0 -21
- data/test/multiple_db_test.rb +0 -46
- data/test/pk_test.rb +0 -57
- data/test/reflection_test.rb +0 -78
- data/test/thread_safety_test.rb +0 -33
- data/test/transactions_test.rb +0 -83
- data/test/unconnected_test.rb +0 -24
- data/test/validations_test.rb +0 -126
data/test/base_test.rb
DELETED
@@ -1,513 +0,0 @@
|
|
1
|
-
require 'abstract_unit'
|
2
|
-
require 'fixtures/topic'
|
3
|
-
require 'fixtures/reply'
|
4
|
-
require 'fixtures/company'
|
5
|
-
require 'fixtures/default'
|
6
|
-
require 'fixtures/auto_id'
|
7
|
-
require 'fixtures/column_name'
|
8
|
-
|
9
|
-
class Category < ActiveRecord::Base; end
|
10
|
-
class Smarts < ActiveRecord::Base; end
|
11
|
-
class CreditCard < ActiveRecord::Base; end
|
12
|
-
class MasterCreditCard < ActiveRecord::Base; end
|
13
|
-
|
14
|
-
class LoosePerson < ActiveRecord::Base
|
15
|
-
attr_protected :credit_rating, :administrator
|
16
|
-
end
|
17
|
-
|
18
|
-
class TightPerson < ActiveRecord::Base
|
19
|
-
attr_accessible :name, :address
|
20
|
-
end
|
21
|
-
|
22
|
-
class TightDescendent < TightPerson
|
23
|
-
attr_accessible :phone_number
|
24
|
-
end
|
25
|
-
|
26
|
-
class Booleantest < ActiveRecord::Base; end
|
27
|
-
|
28
|
-
class BasicsTest < Test::Unit::TestCase
|
29
|
-
def setup
|
30
|
-
@topic_fixtures, @companies = create_fixtures "topics", "companies"
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_set_attributes
|
34
|
-
topic = Topic.find(1)
|
35
|
-
topic.attributes = { "title" => "Budget", "author_name" => "Jason" }
|
36
|
-
topic.save
|
37
|
-
assert_equal("Budget", topic.title)
|
38
|
-
assert_equal("Jason", topic.author_name)
|
39
|
-
assert_equal(@topic_fixtures["first"]["author_email_address"], Topic.find(1).author_email_address)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_integers_as_nil
|
43
|
-
Topic.update(1, "approved" => "")
|
44
|
-
assert_nil Topic.find(1).approved
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_set_attributes_with_block
|
48
|
-
topic = Topic.new do |t|
|
49
|
-
t.title = "Budget"
|
50
|
-
t.author_name = "Jason"
|
51
|
-
end
|
52
|
-
|
53
|
-
assert_equal("Budget", topic.title)
|
54
|
-
assert_equal("Jason", topic.author_name)
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_respond_to?
|
58
|
-
topic = Topic.find(1)
|
59
|
-
assert topic.respond_to?("title")
|
60
|
-
assert topic.respond_to?("title?")
|
61
|
-
assert topic.respond_to?("title=")
|
62
|
-
assert topic.respond_to?("author_name")
|
63
|
-
assert topic.respond_to?("attribute_names")
|
64
|
-
assert !topic.respond_to?("nothingness")
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_array_content
|
68
|
-
topic = Topic.new
|
69
|
-
topic.content = %w( one two three )
|
70
|
-
topic.save
|
71
|
-
|
72
|
-
assert_equal(%w( one two three ), Topic.find(topic.id).content)
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_hash_content
|
76
|
-
topic = Topic.new
|
77
|
-
topic.content = { "one" => 1, "two" => 2 }
|
78
|
-
topic.save
|
79
|
-
|
80
|
-
assert_equal 2, Topic.find(topic.id).content["two"]
|
81
|
-
|
82
|
-
topic.content["three"] = 3
|
83
|
-
topic.save
|
84
|
-
|
85
|
-
assert_equal 3, Topic.find(topic.id).content["three"]
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_update_array_content
|
89
|
-
topic = Topic.new
|
90
|
-
topic.content = %w( one two three )
|
91
|
-
|
92
|
-
topic.content.push "four"
|
93
|
-
assert_equal(%w( one two three four ), topic.content)
|
94
|
-
|
95
|
-
topic.save
|
96
|
-
|
97
|
-
topic = Topic.find(topic.id)
|
98
|
-
topic.content << "five"
|
99
|
-
assert_equal(%w( one two three four five ), topic.content)
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_create
|
103
|
-
topic = Topic.new
|
104
|
-
topic.title = "New Topic"
|
105
|
-
topic.save
|
106
|
-
id = topic.id
|
107
|
-
topicReloaded = Topic.find(id)
|
108
|
-
assert_equal("New Topic", topicReloaded.title)
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_create_through_factory
|
112
|
-
topic = Topic.create("title" => "New Topic")
|
113
|
-
topicReloaded = Topic.find(topic.id)
|
114
|
-
assert_equal(topic, topicReloaded)
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_update
|
118
|
-
topic = Topic.new
|
119
|
-
topic.title = "Another New Topic"
|
120
|
-
topic.written_on = "2003-12-12 23:23"
|
121
|
-
topic.save
|
122
|
-
id = topic.id
|
123
|
-
assert_equal(id, topic.id)
|
124
|
-
|
125
|
-
topicReloaded = Topic.find(id)
|
126
|
-
assert_equal("Another New Topic", topicReloaded.title)
|
127
|
-
|
128
|
-
topicReloaded.title = "Updated topic"
|
129
|
-
topicReloaded.save
|
130
|
-
|
131
|
-
topicReloadedAgain = Topic.find(id)
|
132
|
-
|
133
|
-
assert_equal("Updated topic", topicReloadedAgain.title)
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_preserving_objects
|
137
|
-
assert_kind_of(
|
138
|
-
Time, Topic.find(1).written_on,
|
139
|
-
"The written_on attribute should be of the Time class"
|
140
|
-
)
|
141
|
-
|
142
|
-
assert_kind_of(
|
143
|
-
Date, Topic.find(1).last_read,
|
144
|
-
"The last_read attribute should be of the Date class"
|
145
|
-
)
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_destroy
|
149
|
-
topic = Topic.new
|
150
|
-
topic.title = "Yet Another New Topic"
|
151
|
-
topic.written_on = "2003-12-12 23:23"
|
152
|
-
topic.save
|
153
|
-
id = topic.id
|
154
|
-
topic.destroy
|
155
|
-
|
156
|
-
assert_raises(ActiveRecord::RecordNotFound) { topicReloaded = Topic.find(id) }
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_record_not_found_exception
|
160
|
-
assert_raises(ActiveRecord::RecordNotFound) { topicReloaded = Topic.find(id) }
|
161
|
-
end
|
162
|
-
|
163
|
-
def test_initialize_with_attributes
|
164
|
-
topic = Topic.new({
|
165
|
-
"title" => "initialized from attributes", "written_on" => "2003-12-12 23:23"
|
166
|
-
})
|
167
|
-
|
168
|
-
assert_equal("initialized from attributes", topic.title)
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_load
|
172
|
-
topics = Topic.find_all nil, "id"
|
173
|
-
assert_equal(2, topics.size)
|
174
|
-
assert_equal(@topic_fixtures["first"]["title"], topics.first.title)
|
175
|
-
end
|
176
|
-
|
177
|
-
def test_load_with_condition
|
178
|
-
topics = Topic.find_all "author_name = 'Mary'"
|
179
|
-
|
180
|
-
assert_equal(1, topics.size)
|
181
|
-
assert_equal(@topic_fixtures["second"]["title"], topics.first.title)
|
182
|
-
end
|
183
|
-
|
184
|
-
def test_table_name_guesses
|
185
|
-
assert_equal "topics", Topic.table_name
|
186
|
-
|
187
|
-
assert_equal "categories", Category.table_name
|
188
|
-
assert_equal "smarts", Smarts.table_name
|
189
|
-
assert_equal "credit_cards", CreditCard.table_name
|
190
|
-
assert_equal "master_credit_cards", MasterCreditCard.table_name
|
191
|
-
|
192
|
-
ActiveRecord::Base.pluralize_table_names = false
|
193
|
-
assert_equal "category", Category.table_name
|
194
|
-
assert_equal "smarts", Smarts.table_name
|
195
|
-
assert_equal "credit_card", CreditCard.table_name
|
196
|
-
assert_equal "master_credit_card", MasterCreditCard.table_name
|
197
|
-
ActiveRecord::Base.pluralize_table_names = true
|
198
|
-
|
199
|
-
ActiveRecord::Base.table_name_prefix = "test_"
|
200
|
-
assert_equal "test_categories", Category.table_name
|
201
|
-
ActiveRecord::Base.table_name_suffix = "_test"
|
202
|
-
assert_equal "test_categories_test", Category.table_name
|
203
|
-
ActiveRecord::Base.table_name_prefix = ""
|
204
|
-
assert_equal "categories_test", Category.table_name
|
205
|
-
ActiveRecord::Base.table_name_suffix = ""
|
206
|
-
assert_equal "categories", Category.table_name
|
207
|
-
|
208
|
-
ActiveRecord::Base.pluralize_table_names = false
|
209
|
-
ActiveRecord::Base.table_name_prefix = "test_"
|
210
|
-
assert_equal "test_category", Category.table_name
|
211
|
-
ActiveRecord::Base.table_name_suffix = "_test"
|
212
|
-
assert_equal "test_category_test", Category.table_name
|
213
|
-
ActiveRecord::Base.table_name_prefix = ""
|
214
|
-
assert_equal "category_test", Category.table_name
|
215
|
-
ActiveRecord::Base.table_name_suffix = ""
|
216
|
-
assert_equal "category", Category.table_name
|
217
|
-
ActiveRecord::Base.pluralize_table_names = true
|
218
|
-
end
|
219
|
-
|
220
|
-
def test_destroy_all
|
221
|
-
assert_equal(2, Topic.find_all.size)
|
222
|
-
|
223
|
-
Topic.destroy_all "author_name = 'Mary'"
|
224
|
-
assert_equal(1, Topic.find_all.size)
|
225
|
-
end
|
226
|
-
|
227
|
-
def test_boolean_attributes
|
228
|
-
assert ! Topic.find(1).approved?
|
229
|
-
assert Topic.find(2).approved?
|
230
|
-
end
|
231
|
-
|
232
|
-
def test_increment_counter
|
233
|
-
Topic.increment_counter("replies_count", 1)
|
234
|
-
assert_equal 1, Topic.find(1).replies_count
|
235
|
-
|
236
|
-
Topic.increment_counter("replies_count", 1)
|
237
|
-
assert_equal 2, Topic.find(1).replies_count
|
238
|
-
end
|
239
|
-
|
240
|
-
def test_decrement_counter
|
241
|
-
Topic.decrement_counter("replies_count", 2)
|
242
|
-
assert_equal 1, Topic.find(2).replies_count
|
243
|
-
|
244
|
-
Topic.decrement_counter("replies_count", 2)
|
245
|
-
assert_equal 0, Topic.find(1).replies_count
|
246
|
-
end
|
247
|
-
|
248
|
-
def test_update_all
|
249
|
-
Topic.update_all "content = 'bulk updated!'"
|
250
|
-
assert_equal "bulk updated!", Topic.find(1).content
|
251
|
-
assert_equal "bulk updated!", Topic.find(2).content
|
252
|
-
end
|
253
|
-
|
254
|
-
def test_update_by_condition
|
255
|
-
Topic.update_all "content = 'bulk updated!'", "approved = 1"
|
256
|
-
assert_equal "Have a nice day", Topic.find(1).content
|
257
|
-
assert_equal "bulk updated!", Topic.find(2).content
|
258
|
-
end
|
259
|
-
|
260
|
-
def test_attribute_present
|
261
|
-
t = Topic.new
|
262
|
-
t.title = "hello there!"
|
263
|
-
t.written_on = Time.now
|
264
|
-
assert t.attribute_present?("title")
|
265
|
-
assert t.attribute_present?("written_on")
|
266
|
-
assert !t.attribute_present?("content")
|
267
|
-
end
|
268
|
-
|
269
|
-
def test_attribute_keys_on_new_instance
|
270
|
-
t = Topic.new
|
271
|
-
assert_equal nil, t.title, "The topics table has a title column, so it should be nil"
|
272
|
-
assert_raises(NoMethodError) { t.title2 }
|
273
|
-
end
|
274
|
-
|
275
|
-
def test_class_name
|
276
|
-
assert_equal "Firm", ActiveRecord::Base.class_name("firms")
|
277
|
-
assert_equal "Category", ActiveRecord::Base.class_name("categories")
|
278
|
-
assert_equal "AccountHolder", ActiveRecord::Base.class_name("account_holder")
|
279
|
-
|
280
|
-
ActiveRecord::Base.pluralize_table_names = false
|
281
|
-
assert_equal "Firms", ActiveRecord::Base.class_name( "firms" )
|
282
|
-
ActiveRecord::Base.pluralize_table_names = true
|
283
|
-
|
284
|
-
ActiveRecord::Base.table_name_prefix = "test_"
|
285
|
-
assert_equal "Firm", ActiveRecord::Base.class_name( "test_firms" )
|
286
|
-
ActiveRecord::Base.table_name_suffix = "_tests"
|
287
|
-
assert_equal "Firm", ActiveRecord::Base.class_name( "test_firms_tests" )
|
288
|
-
ActiveRecord::Base.table_name_prefix = ""
|
289
|
-
assert_equal "Firm", ActiveRecord::Base.class_name( "firms_tests" )
|
290
|
-
ActiveRecord::Base.table_name_suffix = ""
|
291
|
-
assert_equal "Firm", ActiveRecord::Base.class_name( "firms" )
|
292
|
-
end
|
293
|
-
|
294
|
-
def test_null_fields
|
295
|
-
assert_nil Topic.find(1).parent_id
|
296
|
-
assert_nil Topic.create("title" => "Hey you").parent_id
|
297
|
-
end
|
298
|
-
|
299
|
-
def test_default_values
|
300
|
-
topic = Topic.new
|
301
|
-
assert_equal 1, topic.approved
|
302
|
-
assert_nil topic.written_on
|
303
|
-
assert_nil topic.last_read
|
304
|
-
|
305
|
-
topic.save
|
306
|
-
|
307
|
-
topic = Topic.find(topic.id)
|
308
|
-
assert_equal 1, topic.approved
|
309
|
-
assert_nil topic.last_read
|
310
|
-
end
|
311
|
-
|
312
|
-
def test_default_values_on_empty_strings
|
313
|
-
topic = Topic.new
|
314
|
-
topic.approved = nil
|
315
|
-
topic.last_read = nil
|
316
|
-
|
317
|
-
topic.save
|
318
|
-
|
319
|
-
topic = Topic.find(topic.id)
|
320
|
-
assert_nil topic.last_read
|
321
|
-
assert_nil topic.approved
|
322
|
-
end
|
323
|
-
|
324
|
-
def test_equality
|
325
|
-
assert_equal Topic.find(1), Topic.find(2).parent
|
326
|
-
end
|
327
|
-
|
328
|
-
def test_destroy_new_record
|
329
|
-
client = Client.new
|
330
|
-
client.destroy
|
331
|
-
assert client.frozen?
|
332
|
-
end
|
333
|
-
|
334
|
-
def test_update_attribute
|
335
|
-
assert !Topic.find(1).approved?
|
336
|
-
Topic.find(1).update_attribute("approved", true)
|
337
|
-
assert Topic.find(1).approved?
|
338
|
-
end
|
339
|
-
|
340
|
-
def test_mass_assignment_protection
|
341
|
-
firm = Firm.new
|
342
|
-
firm.attributes = { "name" => "Next Angle", "rating" => 5 }
|
343
|
-
assert_equal 1, firm.rating
|
344
|
-
end
|
345
|
-
|
346
|
-
def test_mass_assignment_accessible
|
347
|
-
reply = Reply.new("title" => "hello", "content" => "world", "approved" => 0)
|
348
|
-
reply.save
|
349
|
-
|
350
|
-
assert_equal 1, reply.approved
|
351
|
-
|
352
|
-
reply.approved = 0
|
353
|
-
reply.save
|
354
|
-
|
355
|
-
assert_equal 0, reply.approved
|
356
|
-
end
|
357
|
-
|
358
|
-
def test_mass_assignment_protection_inheritance
|
359
|
-
assert_equal [ :credit_rating, :administrator ], LoosePerson.protected_attributes
|
360
|
-
assert_nil TightPerson.protected_attributes
|
361
|
-
end
|
362
|
-
|
363
|
-
def test_multiparameter_attributes_on_date
|
364
|
-
attributes = { "last_read(1i)" => "2004", "last_read(2i)" => "6", "last_read(3i)" => "24" }
|
365
|
-
topic = Topic.find(1)
|
366
|
-
topic.attributes = attributes
|
367
|
-
assert_equal Date.new(2004, 6, 24).to_s, topic.last_read.to_s
|
368
|
-
end
|
369
|
-
|
370
|
-
def test_multiparameter_attributes_on_date_with_empty_date
|
371
|
-
attributes = { "last_read(1i)" => "2004", "last_read(2i)" => "6", "last_read(3i)" => "" }
|
372
|
-
topic = Topic.find(1)
|
373
|
-
topic.attributes = attributes
|
374
|
-
assert_equal Date.new(2004, 6, 1).to_s, topic.last_read.to_s
|
375
|
-
end
|
376
|
-
|
377
|
-
def test_multiparameter_attributes_on_date_with_all_empty
|
378
|
-
attributes = { "last_read(1i)" => "", "last_read(2i)" => "", "last_read(3i)" => "" }
|
379
|
-
topic = Topic.find(1)
|
380
|
-
topic.attributes = attributes
|
381
|
-
assert_nil topic.last_read
|
382
|
-
end
|
383
|
-
|
384
|
-
def test_multiparameter_attributes_on_time
|
385
|
-
attributes = {
|
386
|
-
"written_on(1i)" => "2004", "written_on(2i)" => "6", "written_on(3i)" => "24",
|
387
|
-
"written_on(4i)" => "16", "written_on(5i)" => "24", "written_on(6i)" => "00"
|
388
|
-
}
|
389
|
-
topic = Topic.find(1)
|
390
|
-
topic.attributes = attributes
|
391
|
-
assert_equal Time.local(2004, 6, 24, 16, 24, 0), topic.written_on
|
392
|
-
end
|
393
|
-
|
394
|
-
def test_multiparameter_attributes_on_time_with_empty_seconds
|
395
|
-
attributes = {
|
396
|
-
"written_on(1i)" => "2004", "written_on(2i)" => "6", "written_on(3i)" => "24",
|
397
|
-
"written_on(4i)" => "16", "written_on(5i)" => "24", "written_on(6i)" => ""
|
398
|
-
}
|
399
|
-
topic = Topic.find(1)
|
400
|
-
topic.attributes = attributes
|
401
|
-
assert_equal Time.local(2004, 6, 24, 16, 24, 0), topic.written_on
|
402
|
-
end
|
403
|
-
|
404
|
-
def test_boolean
|
405
|
-
b_false = Booleantest.create({ "value" => false })
|
406
|
-
false_id = b_false.id
|
407
|
-
b_true = Booleantest.create({ "value" => true })
|
408
|
-
true_id = b_true.id
|
409
|
-
|
410
|
-
b_false = Booleantest.find(false_id)
|
411
|
-
assert !b_false.value?
|
412
|
-
b_true = Booleantest.find(true_id)
|
413
|
-
assert b_true.value?
|
414
|
-
end
|
415
|
-
|
416
|
-
def test_clone
|
417
|
-
topic = Topic.find(1)
|
418
|
-
cloned_topic = topic.clone
|
419
|
-
assert_equal topic.title, cloned_topic.title
|
420
|
-
assert cloned_topic.new_record?
|
421
|
-
|
422
|
-
# test if the attributes have been cloned
|
423
|
-
topic.title = "a"
|
424
|
-
cloned_topic.title = "b"
|
425
|
-
assert_equal "a", topic.title
|
426
|
-
assert_equal "b", cloned_topic.title
|
427
|
-
|
428
|
-
# test if the attribute values have been cloned
|
429
|
-
topic.title = {"a" => "b"}
|
430
|
-
cloned_topic = topic.clone
|
431
|
-
cloned_topic.title["a"] = "c"
|
432
|
-
assert_equal "b", topic.title["a"]
|
433
|
-
end
|
434
|
-
|
435
|
-
def test_bignum
|
436
|
-
company = Company.find(1)
|
437
|
-
company.rating = 2147483647
|
438
|
-
company.save
|
439
|
-
company = Company.find(1)
|
440
|
-
assert_equal 2147483647, company.rating
|
441
|
-
end
|
442
|
-
|
443
|
-
def test_default
|
444
|
-
if Default.connection.class.name == 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter'
|
445
|
-
default = Default.new
|
446
|
-
|
447
|
-
# dates / timestampts
|
448
|
-
time_format = "%m/%d/%Y %H:%M"
|
449
|
-
assert_equal Time.now.strftime(time_format), default.modified_time.strftime(time_format)
|
450
|
-
assert_equal Date.today, default.modified_date
|
451
|
-
|
452
|
-
# fixed dates / times
|
453
|
-
assert_equal Date.new(2004, 1, 1), default.fixed_date
|
454
|
-
assert_equal Time.local(2004, 1,1,0,0,0,0), default.fixed_time
|
455
|
-
|
456
|
-
# char types
|
457
|
-
assert_equal 'Y', default.char1
|
458
|
-
assert_equal 'a varchar field', default.char2
|
459
|
-
assert_equal 'a text field', default.char3
|
460
|
-
end
|
461
|
-
end
|
462
|
-
|
463
|
-
def test_auto_id
|
464
|
-
auto = AutoId.new
|
465
|
-
auto.save
|
466
|
-
assert (auto.id > 0)
|
467
|
-
end
|
468
|
-
|
469
|
-
def quote_column_name(name)
|
470
|
-
"<#{name}>"
|
471
|
-
end
|
472
|
-
|
473
|
-
def test_quote_keys
|
474
|
-
ar = AutoId.new
|
475
|
-
source = {"foo" => "bar", "baz" => "quux"}
|
476
|
-
actual = ar.send(:quote_columns, self, source)
|
477
|
-
inverted = actual.invert
|
478
|
-
assert_equal("<foo>", inverted["bar"])
|
479
|
-
assert_equal("<baz>", inverted["quux"])
|
480
|
-
end
|
481
|
-
|
482
|
-
def test_column_name_properly_quoted
|
483
|
-
col_record = ColumnName.new
|
484
|
-
col_record.references = 40
|
485
|
-
col_record.save
|
486
|
-
col_record.references = 41
|
487
|
-
col_record.save
|
488
|
-
c2 = ColumnName.find(col_record.id)
|
489
|
-
assert_equal(41, c2.references)
|
490
|
-
end
|
491
|
-
|
492
|
-
MyObject = Struct.new :attribute1, :attribute2
|
493
|
-
|
494
|
-
def test_serialized_attribute
|
495
|
-
myobj = MyObject.new('value1', 'value2')
|
496
|
-
topic = Topic.create("content" => myobj)
|
497
|
-
Topic.serialize("content", MyObject)
|
498
|
-
assert_equal(myobj, topic.content)
|
499
|
-
end
|
500
|
-
|
501
|
-
def test_serialized_attribute_with_class_constraint
|
502
|
-
myobj = MyObject.new('value1', 'value2')
|
503
|
-
topic = Topic.create("content" => myobj)
|
504
|
-
Topic.serialize(:content, Hash)
|
505
|
-
|
506
|
-
assert_raises(ActiveRecord::SerializationTypeMismatch) { Topic.find(topic.id).content }
|
507
|
-
|
508
|
-
settings = { "color" => "blue" }
|
509
|
-
Topic.find(topic.id).update_attribute("content", settings)
|
510
|
-
assert_equal(settings, Topic.find(topic.id).content)
|
511
|
-
Topic.serialize(:content)
|
512
|
-
end
|
513
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'active_record/support/class_inheritable_attributes'
|
5
|
-
|
6
|
-
class A
|
7
|
-
include ClassInheritableAttributes
|
8
|
-
end
|
9
|
-
|
10
|
-
class B < A
|
11
|
-
write_inheritable_array "first", [ :one, :two ]
|
12
|
-
end
|
13
|
-
|
14
|
-
class C < A
|
15
|
-
write_inheritable_array "first", [ :three ]
|
16
|
-
end
|
17
|
-
|
18
|
-
class D < B
|
19
|
-
write_inheritable_array "first", [ :four ]
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
class ClassInheritableAttributesTest < Test::Unit::TestCase
|
24
|
-
def test_first_level
|
25
|
-
assert_equal [ :one, :two ], B.read_inheritable_attribute("first")
|
26
|
-
assert_equal [ :three ], C.read_inheritable_attribute("first")
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_second_level
|
30
|
-
assert_equal [ :one, :two, :four ], D.read_inheritable_attribute("first")
|
31
|
-
assert_equal [ :one, :two ], B.read_inheritable_attribute("first")
|
32
|
-
end
|
33
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
print "Using native MySQL\n"
|
2
|
-
require 'fixtures/course'
|
3
|
-
require 'logger'
|
4
|
-
|
5
|
-
ActiveRecord::Base.logger = Logger.new("debug.log")
|
6
|
-
|
7
|
-
db1 = 'activerecord_unittest'
|
8
|
-
db2 = 'activerecord_unittest2'
|
9
|
-
|
10
|
-
ActiveRecord::Base.establish_connection(
|
11
|
-
:adapter => "mysql",
|
12
|
-
:host => "localhost",
|
13
|
-
:username => "root",
|
14
|
-
:password => "",
|
15
|
-
:database => db1
|
16
|
-
)
|
17
|
-
|
18
|
-
Course.establish_connection(
|
19
|
-
:adapter => "mysql",
|
20
|
-
:host => "localhost",
|
21
|
-
:username => "root",
|
22
|
-
:password => "",
|
23
|
-
:database => db2
|
24
|
-
)
|
@@ -1,24 +0,0 @@
|
|
1
|
-
print "Using native PostgreSQL\n"
|
2
|
-
require 'fixtures/course'
|
3
|
-
require 'logger'
|
4
|
-
|
5
|
-
ActiveRecord::Base.logger = Logger.new("debug.log")
|
6
|
-
|
7
|
-
db1 = 'activerecord_unittest'
|
8
|
-
db2 = 'activerecord_unittest2'
|
9
|
-
|
10
|
-
ActiveRecord::Base.establish_connection(
|
11
|
-
:adapter => "postgresql",
|
12
|
-
:host => nil,
|
13
|
-
:username => "postgres",
|
14
|
-
:password => "postgres",
|
15
|
-
:database => db1
|
16
|
-
)
|
17
|
-
|
18
|
-
Course.establish_connection(
|
19
|
-
:adapter => "postgresql",
|
20
|
-
:host => nil,
|
21
|
-
:username => "postgres",
|
22
|
-
:password => "postgres",
|
23
|
-
:database => db2
|
24
|
-
)
|
@@ -1,24 +0,0 @@
|
|
1
|
-
print "Using native SQlite\n"
|
2
|
-
require 'fixtures/course'
|
3
|
-
require 'logger'
|
4
|
-
ActiveRecord::Base.logger = Logger.new("debug.log")
|
5
|
-
|
6
|
-
base = "#{File.dirname(__FILE__)}/../../fixtures"
|
7
|
-
sqlite_test_db = "#{base}/fixture_database.sqlite"
|
8
|
-
sqlite_test_db2 = "#{base}/fixture_database_2.sqlite"
|
9
|
-
|
10
|
-
[sqlite_test_db, sqlite_test_db2].each do |db|
|
11
|
-
unless File.exist?(db) and File.size(db) > 0
|
12
|
-
puts "*** You must create the SQLite test database in: #{db} ***"
|
13
|
-
exit!
|
14
|
-
else
|
15
|
-
puts "OK: #{db}"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
ActiveRecord::Base.establish_connection(
|
20
|
-
:adapter => "sqlite",
|
21
|
-
:dbfile => sqlite_test_db)
|
22
|
-
Course.establish_connection(
|
23
|
-
:adapter => "sqlite",
|
24
|
-
:dbfile => sqlite_test_db2)
|