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.

Files changed (178) hide show
  1. data/CHANGELOG +5518 -76
  2. data/README.rdoc +222 -0
  3. data/examples/performance.rb +162 -0
  4. data/examples/simple.rb +14 -0
  5. data/lib/active_record/aggregations.rb +192 -80
  6. data/lib/active_record/association_preload.rb +403 -0
  7. data/lib/active_record/associations/association_collection.rb +545 -53
  8. data/lib/active_record/associations/association_proxy.rb +295 -0
  9. data/lib/active_record/associations/belongs_to_association.rb +91 -0
  10. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +78 -0
  11. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +127 -36
  12. data/lib/active_record/associations/has_many_association.rb +108 -84
  13. data/lib/active_record/associations/has_many_through_association.rb +116 -0
  14. data/lib/active_record/associations/has_one_association.rb +143 -0
  15. data/lib/active_record/associations/has_one_through_association.rb +40 -0
  16. data/lib/active_record/associations/through_association_scope.rb +154 -0
  17. data/lib/active_record/associations.rb +2086 -368
  18. data/lib/active_record/attribute_methods/before_type_cast.rb +33 -0
  19. data/lib/active_record/attribute_methods/dirty.rb +95 -0
  20. data/lib/active_record/attribute_methods/primary_key.rb +50 -0
  21. data/lib/active_record/attribute_methods/query.rb +39 -0
  22. data/lib/active_record/attribute_methods/read.rb +116 -0
  23. data/lib/active_record/attribute_methods/time_zone_conversion.rb +61 -0
  24. data/lib/active_record/attribute_methods/write.rb +37 -0
  25. data/lib/active_record/attribute_methods.rb +60 -0
  26. data/lib/active_record/autosave_association.rb +369 -0
  27. data/lib/active_record/base.rb +1603 -721
  28. data/lib/active_record/callbacks.rb +176 -225
  29. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +365 -0
  30. data/lib/active_record/connection_adapters/abstract/connection_specification.rb +113 -0
  31. data/lib/active_record/connection_adapters/abstract/database_limits.rb +57 -0
  32. data/lib/active_record/connection_adapters/abstract/database_statements.rb +329 -0
  33. data/lib/active_record/connection_adapters/abstract/query_cache.rb +81 -0
  34. data/lib/active_record/connection_adapters/abstract/quoting.rb +72 -0
  35. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +739 -0
  36. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +543 -0
  37. data/lib/active_record/connection_adapters/abstract_adapter.rb +165 -279
  38. data/lib/active_record/connection_adapters/mysql_adapter.rb +594 -82
  39. data/lib/active_record/connection_adapters/postgresql_adapter.rb +988 -135
  40. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +53 -0
  41. data/lib/active_record/connection_adapters/sqlite_adapter.rb +365 -71
  42. data/lib/active_record/counter_cache.rb +115 -0
  43. data/lib/active_record/dynamic_finder_match.rb +53 -0
  44. data/lib/active_record/dynamic_scope_match.rb +32 -0
  45. data/lib/active_record/errors.rb +172 -0
  46. data/lib/active_record/fixtures.rb +941 -105
  47. data/lib/active_record/locale/en.yml +40 -0
  48. data/lib/active_record/locking/optimistic.rb +172 -0
  49. data/lib/active_record/locking/pessimistic.rb +55 -0
  50. data/lib/active_record/log_subscriber.rb +48 -0
  51. data/lib/active_record/migration.rb +617 -0
  52. data/lib/active_record/named_scope.rb +138 -0
  53. data/lib/active_record/nested_attributes.rb +417 -0
  54. data/lib/active_record/observer.rb +105 -36
  55. data/lib/active_record/persistence.rb +291 -0
  56. data/lib/active_record/query_cache.rb +36 -0
  57. data/lib/active_record/railtie.rb +91 -0
  58. data/lib/active_record/railties/controller_runtime.rb +38 -0
  59. data/lib/active_record/railties/databases.rake +512 -0
  60. data/lib/active_record/reflection.rb +364 -87
  61. data/lib/active_record/relation/batches.rb +89 -0
  62. data/lib/active_record/relation/calculations.rb +286 -0
  63. data/lib/active_record/relation/finder_methods.rb +355 -0
  64. data/lib/active_record/relation/predicate_builder.rb +41 -0
  65. data/lib/active_record/relation/query_methods.rb +261 -0
  66. data/lib/active_record/relation/spawn_methods.rb +112 -0
  67. data/lib/active_record/relation.rb +393 -0
  68. data/lib/active_record/schema.rb +59 -0
  69. data/lib/active_record/schema_dumper.rb +195 -0
  70. data/lib/active_record/serialization.rb +60 -0
  71. data/lib/active_record/serializers/xml_serializer.rb +244 -0
  72. data/lib/active_record/session_store.rb +340 -0
  73. data/lib/active_record/test_case.rb +67 -0
  74. data/lib/active_record/timestamp.rb +88 -0
  75. data/lib/active_record/transactions.rb +329 -75
  76. data/lib/active_record/validations/associated.rb +48 -0
  77. data/lib/active_record/validations/uniqueness.rb +185 -0
  78. data/lib/active_record/validations.rb +58 -179
  79. data/lib/active_record/version.rb +9 -0
  80. data/lib/active_record.rb +100 -24
  81. data/lib/rails/generators/active_record/migration/migration_generator.rb +25 -0
  82. data/lib/rails/generators/active_record/migration/templates/migration.rb +17 -0
  83. data/lib/rails/generators/active_record/model/model_generator.rb +38 -0
  84. data/lib/rails/generators/active_record/model/templates/migration.rb +16 -0
  85. data/lib/rails/generators/active_record/model/templates/model.rb +5 -0
  86. data/lib/rails/generators/active_record/model/templates/module.rb +5 -0
  87. data/lib/rails/generators/active_record/observer/observer_generator.rb +15 -0
  88. data/lib/rails/generators/active_record/observer/templates/observer.rb +2 -0
  89. data/lib/rails/generators/active_record/session_migration/session_migration_generator.rb +24 -0
  90. data/lib/rails/generators/active_record/session_migration/templates/migration.rb +16 -0
  91. data/lib/rails/generators/active_record.rb +27 -0
  92. metadata +216 -158
  93. data/README +0 -361
  94. data/RUNNING_UNIT_TESTS +0 -36
  95. data/dev-utils/eval_debugger.rb +0 -9
  96. data/examples/associations.rb +0 -87
  97. data/examples/shared_setup.rb +0 -15
  98. data/examples/validation.rb +0 -88
  99. data/install.rb +0 -60
  100. data/lib/active_record/deprecated_associations.rb +0 -70
  101. data/lib/active_record/support/class_attribute_accessors.rb +0 -43
  102. data/lib/active_record/support/class_inheritable_attributes.rb +0 -37
  103. data/lib/active_record/support/clean_logger.rb +0 -10
  104. data/lib/active_record/support/inflector.rb +0 -70
  105. data/lib/active_record/vendor/mysql.rb +0 -1117
  106. data/lib/active_record/vendor/simple.rb +0 -702
  107. data/lib/active_record/wrappers/yaml_wrapper.rb +0 -15
  108. data/lib/active_record/wrappings.rb +0 -59
  109. data/rakefile +0 -122
  110. data/test/abstract_unit.rb +0 -16
  111. data/test/aggregations_test.rb +0 -34
  112. data/test/all.sh +0 -8
  113. data/test/associations_test.rb +0 -477
  114. data/test/base_test.rb +0 -513
  115. data/test/class_inheritable_attributes_test.rb +0 -33
  116. data/test/connections/native_mysql/connection.rb +0 -24
  117. data/test/connections/native_postgresql/connection.rb +0 -24
  118. data/test/connections/native_sqlite/connection.rb +0 -24
  119. data/test/deprecated_associations_test.rb +0 -336
  120. data/test/finder_test.rb +0 -67
  121. data/test/fixtures/accounts/signals37 +0 -3
  122. data/test/fixtures/accounts/unknown +0 -2
  123. data/test/fixtures/auto_id.rb +0 -4
  124. data/test/fixtures/column_name.rb +0 -3
  125. data/test/fixtures/companies/first_client +0 -6
  126. data/test/fixtures/companies/first_firm +0 -4
  127. data/test/fixtures/companies/second_client +0 -6
  128. data/test/fixtures/company.rb +0 -37
  129. data/test/fixtures/company_in_module.rb +0 -33
  130. data/test/fixtures/course.rb +0 -3
  131. data/test/fixtures/courses/java +0 -2
  132. data/test/fixtures/courses/ruby +0 -2
  133. data/test/fixtures/customer.rb +0 -30
  134. data/test/fixtures/customers/david +0 -6
  135. data/test/fixtures/db_definitions/mysql.sql +0 -96
  136. data/test/fixtures/db_definitions/mysql2.sql +0 -4
  137. data/test/fixtures/db_definitions/postgresql.sql +0 -113
  138. data/test/fixtures/db_definitions/postgresql2.sql +0 -4
  139. data/test/fixtures/db_definitions/sqlite.sql +0 -85
  140. data/test/fixtures/db_definitions/sqlite2.sql +0 -4
  141. data/test/fixtures/default.rb +0 -2
  142. data/test/fixtures/developer.rb +0 -8
  143. data/test/fixtures/developers/david +0 -2
  144. data/test/fixtures/developers/jamis +0 -2
  145. data/test/fixtures/developers_projects/david_action_controller +0 -2
  146. data/test/fixtures/developers_projects/david_active_record +0 -2
  147. data/test/fixtures/developers_projects/jamis_active_record +0 -2
  148. data/test/fixtures/entrant.rb +0 -3
  149. data/test/fixtures/entrants/first +0 -3
  150. data/test/fixtures/entrants/second +0 -3
  151. data/test/fixtures/entrants/third +0 -3
  152. data/test/fixtures/fixture_database.sqlite +0 -0
  153. data/test/fixtures/fixture_database_2.sqlite +0 -0
  154. data/test/fixtures/movie.rb +0 -5
  155. data/test/fixtures/movies/first +0 -2
  156. data/test/fixtures/movies/second +0 -2
  157. data/test/fixtures/project.rb +0 -3
  158. data/test/fixtures/projects/action_controller +0 -2
  159. data/test/fixtures/projects/active_record +0 -2
  160. data/test/fixtures/reply.rb +0 -21
  161. data/test/fixtures/subscriber.rb +0 -5
  162. data/test/fixtures/subscribers/first +0 -2
  163. data/test/fixtures/subscribers/second +0 -2
  164. data/test/fixtures/topic.rb +0 -20
  165. data/test/fixtures/topics/first +0 -9
  166. data/test/fixtures/topics/second +0 -8
  167. data/test/fixtures_test.rb +0 -20
  168. data/test/inflector_test.rb +0 -104
  169. data/test/inheritance_test.rb +0 -125
  170. data/test/lifecycle_test.rb +0 -110
  171. data/test/modules_test.rb +0 -21
  172. data/test/multiple_db_test.rb +0 -46
  173. data/test/pk_test.rb +0 -57
  174. data/test/reflection_test.rb +0 -78
  175. data/test/thread_safety_test.rb +0 -33
  176. data/test/transactions_test.rb +0 -83
  177. data/test/unconnected_test.rb +0 -24
  178. 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,4 +0,0 @@
1
- CREATE TABLE courses (
2
- id serial,
3
- name text
4
- );
@@ -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
- );
@@ -1,4 +0,0 @@
1
- CREATE TABLE 'courses' (
2
- 'id' INTEGER NOT NULL PRIMARY KEY,
3
- 'name' VARCHAR(255) NOT NULL
4
- );
@@ -1,2 +0,0 @@
1
- class Default < ActiveRecord::Base
2
- end
@@ -1,8 +0,0 @@
1
- class Developer < ActiveRecord::Base
2
- has_and_belongs_to_many :projects
3
-
4
- protected
5
- def validate
6
- errors.add_on_boundry_breaking("name", 3..20)
7
- end
8
- end
@@ -1,2 +0,0 @@
1
- id => 1
2
- name => David
@@ -1,2 +0,0 @@
1
- id => 2
2
- name => Jamis
@@ -1,2 +0,0 @@
1
- developer_id => 1
2
- project_id => 2
@@ -1,2 +0,0 @@
1
- developer_id => 1
2
- project_id => 1
@@ -1,2 +0,0 @@
1
- developer_id => 2
2
- project_id => 1
@@ -1,3 +0,0 @@
1
- class Entrant < ActiveRecord::Base
2
- belongs_to :course
3
- end
@@ -1,3 +0,0 @@
1
- id => 1
2
- course_id => 1
3
- name => Ruby Developer
@@ -1,3 +0,0 @@
1
- id => 2
2
- course_id => 1
3
- name => Ruby Guru
@@ -1,3 +0,0 @@
1
- id => 3
2
- course_id => 2
3
- name => Java Lover
Binary file
@@ -1,5 +0,0 @@
1
- class Movie < ActiveRecord::Base
2
- def self.primary_key
3
- "movieid"
4
- end
5
- end
@@ -1,2 +0,0 @@
1
- movieid => 1
2
- name => Terminator
@@ -1,2 +0,0 @@
1
- movieid => 2
2
- name => Gladiator
@@ -1,3 +0,0 @@
1
- class Project < ActiveRecord::Base
2
- has_and_belongs_to_many :developers
3
- end
@@ -1,2 +0,0 @@
1
- id => 2
2
- name => Active Record
@@ -1,2 +0,0 @@
1
- id => 1
2
- name => Active Record
@@ -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
@@ -1,5 +0,0 @@
1
- class Subscriber < ActiveRecord::Base
2
- def self.primary_key
3
- "nick"
4
- end
5
- end
@@ -1,2 +0,0 @@
1
- nick => alterself
2
- name => Luke Holden
@@ -1,2 +0,0 @@
1
- nick => webster132
2
- name => David Heinemeier Hansson
@@ -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
@@ -1,9 +0,0 @@
1
- id => 1
2
- title => The First Topic
3
- author_name => David
4
- author_email_address => david@loudthinking.com
5
- written_on => 2003-07-16 15:28
6
- last_read => 2004-04-15
7
- content => Have a nice day
8
- approved => 0
9
- replies_count => 0
@@ -1,8 +0,0 @@
1
- id => 2
2
- title => The Second Topic
3
- author_name => Mary
4
- written_on => 2003-07-15 15:28
5
- content => Have a great day!
6
- approved => 1
7
- replies_count => 2
8
- parent_id => 1
@@ -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
@@ -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
@@ -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