activerecord 1.0.0 → 3.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 +5518 -76
- data/README.rdoc +222 -0
- data/examples/performance.rb +162 -0
- data/examples/simple.rb +14 -0
- data/lib/active_record/aggregations.rb +192 -80
- data/lib/active_record/association_preload.rb +403 -0
- data/lib/active_record/associations/association_collection.rb +545 -53
- data/lib/active_record/associations/association_proxy.rb +295 -0
- data/lib/active_record/associations/belongs_to_association.rb +91 -0
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +78 -0
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +127 -36
- data/lib/active_record/associations/has_many_association.rb +108 -84
- data/lib/active_record/associations/has_many_through_association.rb +116 -0
- data/lib/active_record/associations/has_one_association.rb +143 -0
- data/lib/active_record/associations/has_one_through_association.rb +40 -0
- data/lib/active_record/associations/through_association_scope.rb +154 -0
- data/lib/active_record/associations.rb +2086 -368
- data/lib/active_record/attribute_methods/before_type_cast.rb +33 -0
- data/lib/active_record/attribute_methods/dirty.rb +95 -0
- data/lib/active_record/attribute_methods/primary_key.rb +50 -0
- data/lib/active_record/attribute_methods/query.rb +39 -0
- data/lib/active_record/attribute_methods/read.rb +116 -0
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +61 -0
- data/lib/active_record/attribute_methods/write.rb +37 -0
- data/lib/active_record/attribute_methods.rb +60 -0
- data/lib/active_record/autosave_association.rb +369 -0
- data/lib/active_record/base.rb +1603 -721
- data/lib/active_record/callbacks.rb +176 -225
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +365 -0
- data/lib/active_record/connection_adapters/abstract/connection_specification.rb +113 -0
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +57 -0
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +329 -0
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +81 -0
- data/lib/active_record/connection_adapters/abstract/quoting.rb +72 -0
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +739 -0
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +543 -0
- data/lib/active_record/connection_adapters/abstract_adapter.rb +165 -279
- data/lib/active_record/connection_adapters/mysql_adapter.rb +594 -82
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +988 -135
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +53 -0
- data/lib/active_record/connection_adapters/sqlite_adapter.rb +365 -71
- data/lib/active_record/counter_cache.rb +115 -0
- data/lib/active_record/dynamic_finder_match.rb +53 -0
- data/lib/active_record/dynamic_scope_match.rb +32 -0
- data/lib/active_record/errors.rb +172 -0
- data/lib/active_record/fixtures.rb +941 -105
- data/lib/active_record/locale/en.yml +40 -0
- data/lib/active_record/locking/optimistic.rb +172 -0
- data/lib/active_record/locking/pessimistic.rb +55 -0
- data/lib/active_record/log_subscriber.rb +48 -0
- data/lib/active_record/migration.rb +617 -0
- data/lib/active_record/named_scope.rb +138 -0
- data/lib/active_record/nested_attributes.rb +417 -0
- data/lib/active_record/observer.rb +105 -36
- data/lib/active_record/persistence.rb +291 -0
- data/lib/active_record/query_cache.rb +36 -0
- data/lib/active_record/railtie.rb +91 -0
- data/lib/active_record/railties/controller_runtime.rb +38 -0
- data/lib/active_record/railties/databases.rake +512 -0
- data/lib/active_record/reflection.rb +364 -87
- data/lib/active_record/relation/batches.rb +89 -0
- data/lib/active_record/relation/calculations.rb +286 -0
- data/lib/active_record/relation/finder_methods.rb +355 -0
- data/lib/active_record/relation/predicate_builder.rb +41 -0
- data/lib/active_record/relation/query_methods.rb +261 -0
- data/lib/active_record/relation/spawn_methods.rb +112 -0
- data/lib/active_record/relation.rb +393 -0
- data/lib/active_record/schema.rb +59 -0
- data/lib/active_record/schema_dumper.rb +195 -0
- data/lib/active_record/serialization.rb +60 -0
- data/lib/active_record/serializers/xml_serializer.rb +244 -0
- data/lib/active_record/session_store.rb +340 -0
- data/lib/active_record/test_case.rb +67 -0
- data/lib/active_record/timestamp.rb +88 -0
- data/lib/active_record/transactions.rb +329 -75
- data/lib/active_record/validations/associated.rb +48 -0
- data/lib/active_record/validations/uniqueness.rb +185 -0
- data/lib/active_record/validations.rb +58 -179
- data/lib/active_record/version.rb +9 -0
- data/lib/active_record.rb +100 -24
- data/lib/rails/generators/active_record/migration/migration_generator.rb +25 -0
- data/lib/rails/generators/active_record/migration/templates/migration.rb +17 -0
- data/lib/rails/generators/active_record/model/model_generator.rb +38 -0
- data/lib/rails/generators/active_record/model/templates/migration.rb +16 -0
- data/lib/rails/generators/active_record/model/templates/model.rb +5 -0
- data/lib/rails/generators/active_record/model/templates/module.rb +5 -0
- data/lib/rails/generators/active_record/observer/observer_generator.rb +15 -0
- data/lib/rails/generators/active_record/observer/templates/observer.rb +2 -0
- data/lib/rails/generators/active_record/session_migration/session_migration_generator.rb +24 -0
- data/lib/rails/generators/active_record/session_migration/templates/migration.rb +16 -0
- data/lib/rails/generators/active_record.rb +27 -0
- metadata +216 -158
- data/README +0 -361
- data/RUNNING_UNIT_TESTS +0 -36
- data/dev-utils/eval_debugger.rb +0 -9
- 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/deprecated_associations.rb +0 -70
- 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
@@ -1,113 +0,0 @@
|
|
1
|
-
SET search_path = public, pg_catalog;
|
2
|
-
|
3
|
-
CREATE TABLE accounts (
|
4
|
-
id serial,
|
5
|
-
firm_id integer,
|
6
|
-
credit_limit integer,
|
7
|
-
PRIMARY KEY (id)
|
8
|
-
);
|
9
|
-
SELECT setval('accounts_id_seq', 100);
|
10
|
-
|
11
|
-
CREATE TABLE companies (
|
12
|
-
id serial,
|
13
|
-
"type" character varying(50),
|
14
|
-
"ruby_type" character varying(50),
|
15
|
-
firm_id integer,
|
16
|
-
name character varying(50),
|
17
|
-
client_of integer,
|
18
|
-
rating integer default 1,
|
19
|
-
PRIMARY KEY (id)
|
20
|
-
);
|
21
|
-
SELECT setval('companies_id_seq', 100);
|
22
|
-
|
23
|
-
CREATE TABLE developers_projects (
|
24
|
-
developer_id integer NOT NULL,
|
25
|
-
project_id integer NOT NULL
|
26
|
-
);
|
27
|
-
|
28
|
-
CREATE TABLE developers (
|
29
|
-
id serial,
|
30
|
-
name character varying(100),
|
31
|
-
PRIMARY KEY (id)
|
32
|
-
);
|
33
|
-
SELECT setval('developers_id_seq', 100);
|
34
|
-
|
35
|
-
CREATE TABLE projects (
|
36
|
-
id serial,
|
37
|
-
name character varying(100),
|
38
|
-
PRIMARY KEY (id)
|
39
|
-
);
|
40
|
-
SELECT setval('projects_id_seq', 100);
|
41
|
-
|
42
|
-
CREATE TABLE topics (
|
43
|
-
id serial,
|
44
|
-
title character varying(255),
|
45
|
-
author_name character varying(255),
|
46
|
-
author_email_address character varying(255),
|
47
|
-
written_on timestamp without time zone,
|
48
|
-
last_read date,
|
49
|
-
content text,
|
50
|
-
replies_count integer default 0,
|
51
|
-
parent_id integer,
|
52
|
-
"type" character varying(50),
|
53
|
-
approved smallint DEFAULT 1,
|
54
|
-
PRIMARY KEY (id)
|
55
|
-
);
|
56
|
-
SELECT setval('topics_id_seq', 100);
|
57
|
-
|
58
|
-
CREATE TABLE customers (
|
59
|
-
id serial,
|
60
|
-
name character varying,
|
61
|
-
balance integer default 0,
|
62
|
-
address_street character varying,
|
63
|
-
address_city character varying,
|
64
|
-
address_country character varying,
|
65
|
-
PRIMARY KEY (id)
|
66
|
-
);
|
67
|
-
SELECT setval('customers_id_seq', 100);
|
68
|
-
|
69
|
-
CREATE TABLE movies (
|
70
|
-
movieid serial,
|
71
|
-
name text,
|
72
|
-
PRIMARY KEY (movieid)
|
73
|
-
);
|
74
|
-
|
75
|
-
CREATE TABLE subscribers (
|
76
|
-
nick text NOT NULL,
|
77
|
-
name text,
|
78
|
-
PRIMARY KEY (nick)
|
79
|
-
);
|
80
|
-
|
81
|
-
CREATE TABLE booleantests (
|
82
|
-
id serial,
|
83
|
-
value boolean,
|
84
|
-
PRIMARY KEY (id)
|
85
|
-
);
|
86
|
-
|
87
|
-
CREATE TABLE defaults (
|
88
|
-
id serial,
|
89
|
-
modified_date date default CURRENT_DATE,
|
90
|
-
fixed_date date default '2004-01-01',
|
91
|
-
modified_time timestamp default CURRENT_TIMESTAMP,
|
92
|
-
fixed_time timestamp default '2004-01-01 00:00:00.000000-00',
|
93
|
-
char1 char(1) default 'Y',
|
94
|
-
char2 character varying(50) default 'a varchar field',
|
95
|
-
char3 text default 'a text field'
|
96
|
-
);
|
97
|
-
|
98
|
-
CREATE TABLE auto_id_tests (
|
99
|
-
auto_id serial,
|
100
|
-
value integer,
|
101
|
-
PRIMARY KEY (auto_id)
|
102
|
-
);
|
103
|
-
|
104
|
-
CREATE TABLE entrants (
|
105
|
-
id serial,
|
106
|
-
name text,
|
107
|
-
course_id integer
|
108
|
-
);
|
109
|
-
|
110
|
-
CREATE TABLE colnametests (
|
111
|
-
id serial,
|
112
|
-
"references" integer NOT NULL
|
113
|
-
);
|
@@ -1,85 +0,0 @@
|
|
1
|
-
CREATE TABLE 'accounts' (
|
2
|
-
'id' INTEGER PRIMARY KEY NOT NULL,
|
3
|
-
'firm_id' INTEGER DEFAULT NULL,
|
4
|
-
'credit_limit' INTEGER DEFAULT NULL
|
5
|
-
);
|
6
|
-
|
7
|
-
CREATE TABLE 'companies' (
|
8
|
-
'id' INTEGER PRIMARY KEY NOT NULL,
|
9
|
-
'type' VARCHAR(255) DEFAULT NULL,
|
10
|
-
'ruby_type' VARCHAR(255) DEFAULT NULL,
|
11
|
-
'firm_id' INTEGER DEFAULT NULL,
|
12
|
-
'name' TEXT DEFAULT NULL,
|
13
|
-
'client_of' INTEGER DEFAULT NULL,
|
14
|
-
'rating' INTEGER DEFAULT 1
|
15
|
-
);
|
16
|
-
|
17
|
-
|
18
|
-
CREATE TABLE 'topics' (
|
19
|
-
'id' INTEGER PRIMARY KEY NOT NULL,
|
20
|
-
'title' VARCHAR(255) DEFAULT NULL,
|
21
|
-
'author_name' VARCHAR(255) DEFAULT NULL,
|
22
|
-
'author_email_address' VARCHAR(255) DEFAULT NULL,
|
23
|
-
'written_on' DATETIME DEFAULT NULL,
|
24
|
-
'last_read' DATE DEFAULT NULL,
|
25
|
-
'content' TEXT,
|
26
|
-
'approved' INTEGER DEFAULT 1,
|
27
|
-
'replies_count' INTEGER DEFAULT 0,
|
28
|
-
'parent_id' INTEGER DEFAULT NULL,
|
29
|
-
'type' VARCHAR(255) DEFAULT NULL
|
30
|
-
);
|
31
|
-
|
32
|
-
CREATE TABLE 'developers' (
|
33
|
-
'id' INTEGER PRIMARY KEY NOT NULL,
|
34
|
-
'name' TEXT DEFAULT NULL
|
35
|
-
);
|
36
|
-
|
37
|
-
CREATE TABLE 'projects' (
|
38
|
-
'id' INTEGER PRIMARY KEY NOT NULL,
|
39
|
-
'name' TEXT DEFAULT NULL
|
40
|
-
);
|
41
|
-
|
42
|
-
CREATE TABLE 'developers_projects' (
|
43
|
-
'developer_id' INTEGER NOT NULL,
|
44
|
-
'project_id' INTEGER NOT NULL
|
45
|
-
);
|
46
|
-
|
47
|
-
CREATE TABLE 'customers' (
|
48
|
-
'id' INTEGER PRIMARY KEY NOT NULL,
|
49
|
-
'name' VARCHAR(255) DEFAULT NULL,
|
50
|
-
'balance' INTEGER DEFAULT 0,
|
51
|
-
'address_street' TEXT DEFAULT NULL,
|
52
|
-
'address_city' TEXT DEFAULT NULL,
|
53
|
-
'address_country' TEXT DEFAULT NULL
|
54
|
-
);
|
55
|
-
|
56
|
-
CREATE TABLE 'movies' (
|
57
|
-
'movieid' INTEGER PRIMARY KEY NOT NULL,
|
58
|
-
'name' VARCHAR(255) DEFAULT NULL
|
59
|
-
);
|
60
|
-
|
61
|
-
CREATE TABLE subscribers (
|
62
|
-
'nick' VARCHAR(255) PRIMARY KEY NOT NULL,
|
63
|
-
'name' VARCHAR(255) DEFAULT NULL
|
64
|
-
);
|
65
|
-
|
66
|
-
CREATE TABLE 'booleantests' (
|
67
|
-
'id' INTEGER PRIMARY KEY NOT NULL,
|
68
|
-
'value' INTEGER DEFAULT NULL
|
69
|
-
);
|
70
|
-
|
71
|
-
CREATE TABLE 'auto_id_tests' (
|
72
|
-
'auto_id' INTEGER PRIMARY KEY NOT NULL,
|
73
|
-
'value' INTEGER DEFAULT NULL
|
74
|
-
);
|
75
|
-
|
76
|
-
CREATE TABLE 'entrants' (
|
77
|
-
'id' INTEGER NOT NULL PRIMARY KEY,
|
78
|
-
'name' VARCHAR(255) NOT NULL,
|
79
|
-
'course_id' INTEGER NOT NULL
|
80
|
-
);
|
81
|
-
|
82
|
-
CREATE TABLE 'colnametests' (
|
83
|
-
'id' INTEGER NOT NULL PRIMARY KEY,
|
84
|
-
'references' INTEGER NOT NULL
|
85
|
-
);
|
data/test/fixtures/default.rb
DELETED
data/test/fixtures/developer.rb
DELETED
data/test/fixtures/entrant.rb
DELETED
Binary file
|
Binary file
|
data/test/fixtures/movie.rb
DELETED
data/test/fixtures/movies/first
DELETED
data/test/fixtures/movies/second
DELETED
data/test/fixtures/project.rb
DELETED
data/test/fixtures/reply.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
class Reply < Topic
|
2
|
-
belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true
|
3
|
-
|
4
|
-
attr_accessible :title, :author_name, :author_email_address, :written_on, :content, :last_read
|
5
|
-
|
6
|
-
def validate
|
7
|
-
errors.add("title", "Empty") unless attribute_present? "title"
|
8
|
-
errors.add("content", "Empty") unless attribute_present? "content"
|
9
|
-
end
|
10
|
-
|
11
|
-
def validate_on_create
|
12
|
-
errors.add("title", "is Wrong Create") if attribute_present?("title") && title == "Wrong Create"
|
13
|
-
if attribute_present?("title") && attribute_present?("content") && content == "Mismatch"
|
14
|
-
errors.add("title", "is Content Mismatch")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def validate_on_update
|
19
|
-
errors.add("title", "is Wrong Update") if attribute_present?("title") && title == "Wrong Update"
|
20
|
-
end
|
21
|
-
end
|
data/test/fixtures/subscriber.rb
DELETED
data/test/fixtures/topic.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
class Topic < ActiveRecord::Base
|
2
|
-
has_many :replies, :foreign_key => "parent_id"
|
3
|
-
serialize :content
|
4
|
-
|
5
|
-
before_create :default_written_on
|
6
|
-
before_destroy :destroy_children #'self.class.delete_all "parent_id = #{id}"'
|
7
|
-
|
8
|
-
def parent
|
9
|
-
self.class.find(parent_id)
|
10
|
-
end
|
11
|
-
|
12
|
-
protected
|
13
|
-
def default_written_on
|
14
|
-
self.written_on = Time.now unless attribute_present?("written_on")
|
15
|
-
end
|
16
|
-
|
17
|
-
def destroy_children
|
18
|
-
self.class.delete_all "parent_id = #{id}"
|
19
|
-
end
|
20
|
-
end
|
data/test/fixtures/topics/first
DELETED
data/test/fixtures/topics/second
DELETED
data/test/fixtures_test.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'abstract_unit'
|
2
|
-
|
3
|
-
class FixturesTest < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@fixtures = create_fixtures("topics")
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_attributes
|
9
|
-
assert_equal("The First Topic", @fixtures["first"]["title"])
|
10
|
-
assert_nil(@fixtures["second"]["author_email_address"])
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_inserts
|
14
|
-
firstRow = ActiveRecord::Base.connection.select_one("SELECT * FROM topics WHERE author_name = 'David'")
|
15
|
-
assert_equal("The First Topic", firstRow["title"])
|
16
|
-
|
17
|
-
secondRow = ActiveRecord::Base.connection.select_one("SELECT * FROM topics WHERE author_name = 'Mary'")
|
18
|
-
assert_nil(secondRow["author_email_address"])
|
19
|
-
end
|
20
|
-
end
|
data/test/inflector_test.rb
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
require 'abstract_unit'
|
2
|
-
|
3
|
-
class InflectorTest < Test::Unit::TestCase
|
4
|
-
SingularToPlural = {
|
5
|
-
"search" => "searches",
|
6
|
-
"switch" => "switches",
|
7
|
-
"fix" => "fixes",
|
8
|
-
"box" => "boxes",
|
9
|
-
"process" => "processes",
|
10
|
-
"address" => "addresses",
|
11
|
-
"case" => "cases",
|
12
|
-
"stack" => "stacks",
|
13
|
-
|
14
|
-
"category" => "categories",
|
15
|
-
"query" => "queries",
|
16
|
-
"ability" => "abilities",
|
17
|
-
"agency" => "agencies",
|
18
|
-
|
19
|
-
"wife" => "wives",
|
20
|
-
"safe" => "saves",
|
21
|
-
"half" => "halves",
|
22
|
-
|
23
|
-
"salesperson" => "salespeople",
|
24
|
-
"person" => "people",
|
25
|
-
|
26
|
-
"spokesman" => "spokesmen",
|
27
|
-
"man" => "men",
|
28
|
-
"woman" => "women",
|
29
|
-
|
30
|
-
"basis" => "bases",
|
31
|
-
"diagnosis" => "diagnoses",
|
32
|
-
|
33
|
-
"datum" => "data",
|
34
|
-
"medium" => "media",
|
35
|
-
|
36
|
-
"node_child" => "node_children",
|
37
|
-
"child" => "children",
|
38
|
-
|
39
|
-
"experience" => "experiences",
|
40
|
-
"day" => "days",
|
41
|
-
|
42
|
-
"comment" => "comments",
|
43
|
-
"foobar" => "foobars"
|
44
|
-
}
|
45
|
-
|
46
|
-
CamelToUnderscore = {
|
47
|
-
"Product" => "product",
|
48
|
-
"SpecialGuest" => "special_guest",
|
49
|
-
"AbstractApplicationController" => "abstract_application_controller"
|
50
|
-
}
|
51
|
-
|
52
|
-
ClassNameToForeignKeyWithUnderscore = {
|
53
|
-
"Person" => "person_id",
|
54
|
-
"MyApplication::Billing::Account" => "account_id"
|
55
|
-
}
|
56
|
-
|
57
|
-
ClassNameToForeignKeyWithoutUnderscore = {
|
58
|
-
"Person" => "personid",
|
59
|
-
"MyApplication::Billing::Account" => "accountid"
|
60
|
-
}
|
61
|
-
|
62
|
-
def test_pluralize
|
63
|
-
SingularToPlural.each do |singular, plural|
|
64
|
-
assert_equal(plural, Inflector.pluralize(singular))
|
65
|
-
end
|
66
|
-
|
67
|
-
assert_equal("plurals", Inflector.pluralize("plurals"))
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_singularize
|
71
|
-
SingularToPlural.each do |singular, plural|
|
72
|
-
assert_equal(singular, Inflector.singularize(plural))
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_camelize
|
77
|
-
CamelToUnderscore.each do |camel, underscore|
|
78
|
-
assert_equal(camel, Inflector.camelize(underscore))
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_underscore
|
83
|
-
CamelToUnderscore.each do |camel, underscore|
|
84
|
-
assert_equal(underscore, Inflector.underscore(camel))
|
85
|
-
end
|
86
|
-
|
87
|
-
assert_equal "html_tidy", Inflector.underscore("HTMLTidy")
|
88
|
-
assert_equal "html_tidy_generator", Inflector.underscore("HTMLTidyGenerator")
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_demodulize
|
92
|
-
assert_equal "Account", Inflector.demodulize("MyApplication::Billing::Account")
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_foreign_key
|
96
|
-
ClassNameToForeignKeyWithUnderscore.each do |klass, foreign_key|
|
97
|
-
assert_equal(foreign_key, Inflector.foreign_key(klass))
|
98
|
-
end
|
99
|
-
|
100
|
-
ClassNameToForeignKeyWithoutUnderscore.each do |klass, foreign_key|
|
101
|
-
assert_equal(foreign_key, Inflector.foreign_key(klass, false))
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
data/test/inheritance_test.rb
DELETED
@@ -1,125 +0,0 @@
|
|
1
|
-
require 'abstract_unit'
|
2
|
-
require 'fixtures/company'
|
3
|
-
|
4
|
-
|
5
|
-
class InheritanceTest < Test::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
@company_fixtures = create_fixtures "companies"
|
8
|
-
end
|
9
|
-
|
10
|
-
def switch_to_alt_inheritance_column
|
11
|
-
# we don't want misleading test results, so get rid of the values in the type column
|
12
|
-
Company.find_all(nil, "id").each do |c|
|
13
|
-
c['type'] = nil
|
14
|
-
c.save
|
15
|
-
end
|
16
|
-
|
17
|
-
def Company.inheritance_column() "ruby_type" end
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_inheritance_find
|
21
|
-
assert Company.find(1).kind_of?(Firm), "37signals should be a firm"
|
22
|
-
assert Firm.find(1).kind_of?(Firm), "37signals should be a firm"
|
23
|
-
assert Company.find(2).kind_of?(Client), "Summit should be a client"
|
24
|
-
assert Client.find(2).kind_of?(Client), "Summit should be a client"
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_alt_inheritance_find
|
28
|
-
switch_to_alt_inheritance_column
|
29
|
-
test_inheritance_find
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_inheritance_find_all
|
33
|
-
companies = Company.find_all(nil, "id")
|
34
|
-
assert companies[0].kind_of?(Firm), "37signals should be a firm"
|
35
|
-
assert companies[1].kind_of?(Client), "Summit should be a client"
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_alt_inheritance_find_all
|
39
|
-
switch_to_alt_inheritance_column
|
40
|
-
test_inheritance_find_all
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_inheritance_save
|
44
|
-
firm = Firm.new
|
45
|
-
firm.name = "Next Angle"
|
46
|
-
firm.save
|
47
|
-
|
48
|
-
next_angle = Company.find(firm.id)
|
49
|
-
assert next_angle.kind_of?(Firm), "Next Angle should be a firm"
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_alt_inheritance_save
|
53
|
-
switch_to_alt_inheritance_column
|
54
|
-
test_inheritance_save
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_inheritance_condition
|
58
|
-
assert_equal 3, Company.find_all.length
|
59
|
-
assert_equal 1, Firm.find_all.length
|
60
|
-
assert_equal 2, Client.find_all.length
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_alt_inheritance_condition
|
64
|
-
switch_to_alt_inheritance_column
|
65
|
-
test_inheritance_condition
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_finding_incorrect_type_data
|
69
|
-
assert_raises(ActiveRecord::RecordNotFound) { Firm.find(2) }
|
70
|
-
assert_nothing_raised { Firm.find(1) }
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_alt_finding_incorrect_type_data
|
74
|
-
switch_to_alt_inheritance_column
|
75
|
-
test_finding_incorrect_type_data
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_update_all_within_inheritance
|
79
|
-
Client.update_all "name = 'I am a client'"
|
80
|
-
assert_equal "I am a client", Client.find_all.first.name
|
81
|
-
assert_equal "37signals", Firm.find_all.first.name
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_alt_update_all_within_inheritance
|
85
|
-
switch_to_alt_inheritance_column
|
86
|
-
test_update_all_within_inheritance
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_destroy_all_within_inheritance
|
90
|
-
Client.destroy_all
|
91
|
-
assert_equal 0, Client.find_all.length
|
92
|
-
assert_equal 1, Firm.find_all.length
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_alt_destroy_all_within_inheritance
|
96
|
-
switch_to_alt_inheritance_column
|
97
|
-
test_destroy_all_within_inheritance
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_find_first_within_inheritance
|
101
|
-
assert_kind_of Firm, Company.find_first("name = '37signals'")
|
102
|
-
assert_kind_of Firm, Firm.find_first("name = '37signals'")
|
103
|
-
assert_nil Client.find_first("name = '37signals'")
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_alt_find_first_within_inheritance
|
107
|
-
switch_to_alt_inheritance_column
|
108
|
-
test_find_first_within_inheritance
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_complex_inheritance
|
112
|
-
very_special_client = VerySpecialClient.create("name" => "veryspecial")
|
113
|
-
assert_equal very_special_client, VerySpecialClient.find_first("name = 'veryspecial'")
|
114
|
-
assert_equal very_special_client, SpecialClient.find_first("name = 'veryspecial'")
|
115
|
-
assert_equal very_special_client, Company.find_first("name = 'veryspecial'")
|
116
|
-
assert_equal very_special_client, Client.find_first("name = 'veryspecial'")
|
117
|
-
assert_equal 1, Client.find_all("name = 'Summit'").size
|
118
|
-
assert_equal very_special_client, Client.find(very_special_client.id)
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_alt_complex_inheritance
|
122
|
-
switch_to_alt_inheritance_column
|
123
|
-
test_complex_inheritance
|
124
|
-
end
|
125
|
-
end
|