activerecord 1.0.0 → 1.1.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 +102 -1
- data/dev-utils/eval_debugger.rb +12 -7
- data/lib/active_record.rb +2 -0
- data/lib/active_record/aggregations.rb +1 -1
- data/lib/active_record/associations.rb +74 -53
- data/lib/active_record/associations.rb.orig +555 -0
- data/lib/active_record/associations/association_collection.rb +74 -15
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +86 -25
- data/lib/active_record/associations/has_many_association.rb +48 -50
- data/lib/active_record/base.rb +56 -24
- data/lib/active_record/connection_adapters/abstract_adapter.rb +46 -3
- data/lib/active_record/connection_adapters/mysql_adapter.rb +15 -15
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +128 -135
- data/lib/active_record/connection_adapters/sqlite_adapter.rb +76 -78
- data/lib/active_record/deprecated_associations.rb +1 -1
- data/lib/active_record/fixtures.rb +137 -54
- data/lib/active_record/observer.rb +1 -1
- data/lib/active_record/support/inflector.rb +8 -0
- data/lib/active_record/transactions.rb +31 -14
- data/rakefile +13 -5
- data/test/abstract_unit.rb +7 -1
- data/test/associations_test.rb +99 -27
- data/test/base_test.rb +15 -1
- data/test/connections/native_sqlite/connection.rb +24 -14
- data/test/deprecated_associations_test.rb +3 -4
- data/test/deprecated_associations_test.rb.orig +334 -0
- data/test/fixtures/bad_fixtures/attr_with_numeric_first_char +1 -0
- data/test/fixtures/bad_fixtures/attr_with_spaces +1 -0
- data/test/fixtures/bad_fixtures/blank_line +3 -0
- data/test/fixtures/bad_fixtures/duplicate_attributes +3 -0
- data/test/fixtures/bad_fixtures/missing_value +1 -0
- data/test/fixtures/company_in_module.rb +15 -1
- data/test/fixtures/db_definitions/mysql.sql +2 -1
- data/test/fixtures/db_definitions/postgresql.sql +2 -1
- data/test/fixtures/db_definitions/sqlite.sql +2 -1
- data/test/fixtures/developers_projects/david_action_controller +2 -1
- data/test/fixtures/developers_projects/david_active_record +2 -1
- data/test/fixtures/fixture_database.sqlite +0 -0
- data/test/fixtures/fixture_database_2.sqlite +0 -0
- data/test/fixtures/project.rb +2 -1
- data/test/fixtures/projects/action_controller +1 -1
- data/test/fixtures/topics/second +1 -1
- data/test/fixtures_test.rb +63 -4
- data/test/inflector_test.rb +17 -0
- data/test/modules_test.rb +8 -0
- data/test/transactions_test.rb +16 -4
- metadata +10 -2
@@ -0,0 +1 @@
|
|
1
|
+
1b => 1
|
@@ -0,0 +1 @@
|
|
1
|
+
a b => 1
|
@@ -0,0 +1 @@
|
|
1
|
+
a =>
|
@@ -3,7 +3,7 @@ module MyApplication
|
|
3
3
|
class Company < ActiveRecord::Base
|
4
4
|
attr_protected :rating
|
5
5
|
end
|
6
|
-
|
6
|
+
|
7
7
|
class Firm < Company
|
8
8
|
has_many :clients, :order => "id", :dependent => true
|
9
9
|
has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC"
|
@@ -18,6 +18,20 @@ module MyApplication
|
|
18
18
|
belongs_to :firm, :foreign_key => "client_of"
|
19
19
|
belongs_to :firm_with_other_name, :class_name => "Firm", :foreign_key => "client_of"
|
20
20
|
end
|
21
|
+
|
22
|
+
class Developer < ActiveRecord::Base
|
23
|
+
has_and_belongs_to_many :projects
|
24
|
+
|
25
|
+
protected
|
26
|
+
def validate
|
27
|
+
errors.add_on_boundry_breaking("name", 3..20)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Project < ActiveRecord::Base
|
32
|
+
has_and_belongs_to_many :developers
|
33
|
+
end
|
34
|
+
|
21
35
|
end
|
22
36
|
|
23
37
|
module Billing
|
Binary file
|
Binary file
|
data/test/fixtures/project.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
id => 2
|
2
|
-
name => Active
|
2
|
+
name => Active Controller
|
data/test/fixtures/topics/second
CHANGED
data/test/fixtures_test.rb
CHANGED
@@ -1,20 +1,79 @@
|
|
1
1
|
require 'abstract_unit'
|
2
|
+
require 'fixtures/topic'
|
3
|
+
require 'fixtures/developer'
|
2
4
|
|
3
5
|
class FixturesTest < Test::Unit::TestCase
|
6
|
+
fixtures :topics, :developers
|
7
|
+
|
8
|
+
FIXTURES = %w( accounts companies customers
|
9
|
+
developers developers_projects entrants
|
10
|
+
movies projects subscribers topics )
|
11
|
+
MATCH_ATTRIBUTE_NAME = /[a-zA-Z][-_\w]*/
|
12
|
+
|
4
13
|
def setup
|
5
|
-
|
14
|
+
# just to annoy
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_clean_fixtures
|
18
|
+
FIXTURES.each do |name|
|
19
|
+
fixtures = nil
|
20
|
+
assert_nothing_raised { fixtures = create_fixtures(name) }
|
21
|
+
assert_kind_of(Fixtures, fixtures)
|
22
|
+
fixtures.each { |name, fixture|
|
23
|
+
fixture.each { |key, value|
|
24
|
+
assert_match(MATCH_ATTRIBUTE_NAME, key)
|
25
|
+
}
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_multiple_clean_fixtures
|
31
|
+
fixtures_array = nil
|
32
|
+
assert_nothing_raised { fixtures_array = create_fixtures(*FIXTURES) }
|
33
|
+
assert_kind_of(Array, fixtures_array)
|
34
|
+
fixtures_array.each { |fixtures| assert_kind_of(Fixtures, fixtures) }
|
6
35
|
end
|
7
36
|
|
8
37
|
def test_attributes
|
9
|
-
|
10
|
-
|
38
|
+
topics = create_fixtures("topics")
|
39
|
+
assert_equal("The First Topic", topics["first"]["title"])
|
40
|
+
assert_nil(topics["second"]["author_email_address"])
|
11
41
|
end
|
12
42
|
|
13
43
|
def test_inserts
|
44
|
+
topics = create_fixtures("topics")
|
14
45
|
firstRow = ActiveRecord::Base.connection.select_one("SELECT * FROM topics WHERE author_name = 'David'")
|
15
46
|
assert_equal("The First Topic", firstRow["title"])
|
16
47
|
|
17
48
|
secondRow = ActiveRecord::Base.connection.select_one("SELECT * FROM topics WHERE author_name = 'Mary'")
|
18
49
|
assert_nil(secondRow["author_email_address"])
|
19
50
|
end
|
20
|
-
|
51
|
+
|
52
|
+
def test_bad_format
|
53
|
+
path = File.join(File.dirname(__FILE__), 'fixtures', 'bad_fixtures')
|
54
|
+
Dir.entries(path).each do |file|
|
55
|
+
next unless File.file?(file) and file !~ %r(^.|.yaml$)
|
56
|
+
assert_raise(Fixture::FormatError) {
|
57
|
+
Fixture.new(bad_fixtures_path, file)
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_logger_level_invariant
|
63
|
+
level = ActiveRecord::Base.logger.level
|
64
|
+
create_fixtures('topics')
|
65
|
+
assert_equal level, ActiveRecord::Base.logger.level
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_instantiation
|
69
|
+
topics = create_fixtures("topics")
|
70
|
+
assert_kind_of Topic, topics["first"].find
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_complete_instantiation
|
74
|
+
# instantiate_fixtures "topics", "developers"
|
75
|
+
assert_equal 2, @topics.size
|
76
|
+
assert_equal 2, @developers.size
|
77
|
+
assert_equal "The First Topic", @first.title
|
78
|
+
end
|
79
|
+
end
|
data/test/inflector_test.rb
CHANGED
@@ -58,6 +58,11 @@ class InflectorTest < Test::Unit::TestCase
|
|
58
58
|
"Person" => "personid",
|
59
59
|
"MyApplication::Billing::Account" => "accountid"
|
60
60
|
}
|
61
|
+
|
62
|
+
ClassNameToTableName = {
|
63
|
+
"PrimarySpokesman" => "primary_spokesmen",
|
64
|
+
"NodeChild" => "node_children"
|
65
|
+
}
|
61
66
|
|
62
67
|
def test_pluralize
|
63
68
|
SingularToPlural.each do |singular, plural|
|
@@ -101,4 +106,16 @@ class InflectorTest < Test::Unit::TestCase
|
|
101
106
|
assert_equal(foreign_key, Inflector.foreign_key(klass, false))
|
102
107
|
end
|
103
108
|
end
|
109
|
+
|
110
|
+
def test_tableize
|
111
|
+
ClassNameToTableName.each do |class_name, table_name|
|
112
|
+
assert_equal(table_name, Inflector.tableize(class_name))
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_classify
|
117
|
+
ClassNameToTableName.each do |class_name, table_name|
|
118
|
+
assert_equal(class_name, Inflector.classify(table_name))
|
119
|
+
end
|
120
|
+
end
|
104
121
|
end
|
data/test/modules_test.rb
CHANGED
@@ -6,6 +6,8 @@ class ModulesTest < Test::Unit::TestCase
|
|
6
6
|
def setup
|
7
7
|
create_fixtures "accounts"
|
8
8
|
create_fixtures "companies"
|
9
|
+
create_fixtures "projects"
|
10
|
+
create_fixtures "developers"
|
9
11
|
end
|
10
12
|
|
11
13
|
def test_module_spanning_associations
|
@@ -14,6 +16,12 @@ class ModulesTest < Test::Unit::TestCase
|
|
14
16
|
assert_nil firm.class.table_name.match('::'), "Firm shouldn't have the module appear in its table name"
|
15
17
|
assert_equal 2, firm.clients_count, "Firm should have two clients"
|
16
18
|
end
|
19
|
+
|
20
|
+
def test_module_spanning_has_and_belongs_to_many_associations
|
21
|
+
project = MyApplication::Business::Project.find_first
|
22
|
+
project.developers << MyApplication::Business::Developer.create("name" => "John")
|
23
|
+
assert "John", project.developers.last.name
|
24
|
+
end
|
17
25
|
|
18
26
|
def test_associations_spanning_cross_modules
|
19
27
|
assert MyApplication::Billing::Account.find(1).has_firm?, "37signals account should be able to backtrack"
|
data/test/transactions_test.rb
CHANGED
@@ -8,18 +8,30 @@ class TransactionTest < Test::Unit::TestCase
|
|
8
8
|
@first, @second = Topic.find(1, 2)
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
11
|
+
def test_successful
|
12
12
|
Topic.transaction do
|
13
13
|
@first.approved = 1
|
14
14
|
@second.approved = 0
|
15
15
|
@first.save
|
16
16
|
@second.save
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
assert Topic.find(1).approved?, "First should have been approved"
|
20
20
|
assert !Topic.find(2).approved?, "Second should have been unapproved"
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
|
+
def test_successful_with_instance_method
|
24
|
+
@first.transaction do
|
25
|
+
@first.approved = 1
|
26
|
+
@second.approved = 0
|
27
|
+
@first.save
|
28
|
+
@second.save
|
29
|
+
end
|
30
|
+
|
31
|
+
assert Topic.find(1).approved?, "First should have been approved"
|
32
|
+
assert !Topic.find(2).approved?, "Second should have been unapproved"
|
33
|
+
end
|
34
|
+
|
23
35
|
def test_failing_on_exception
|
24
36
|
begin
|
25
37
|
Topic.transaction do
|
@@ -80,4 +92,4 @@ class TransactionTest < Test::Unit::TestCase
|
|
80
92
|
def remove_exception_raising_after_save_callback_to_topic
|
81
93
|
Topic.class_eval { remove_method :after_save }
|
82
94
|
end
|
83
|
-
end
|
95
|
+
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.1
|
|
3
3
|
specification_version: 1
|
4
4
|
name: activerecord
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.
|
7
|
-
date: 2004-
|
6
|
+
version: 1.1.0
|
7
|
+
date: 2004-11-18
|
8
8
|
summary: Implements the ActiveRecord pattern for ORM.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- lib/active_record/aggregations.rb
|
37
37
|
- lib/active_record/associations
|
38
38
|
- lib/active_record/associations.rb
|
39
|
+
- lib/active_record/associations.rb.orig
|
39
40
|
- lib/active_record/base.rb
|
40
41
|
- lib/active_record/callbacks.rb
|
41
42
|
- lib/active_record/connection_adapters
|
@@ -71,6 +72,7 @@ files:
|
|
71
72
|
- test/class_inheritable_attributes_test.rb
|
72
73
|
- test/connections
|
73
74
|
- test/deprecated_associations_test.rb
|
75
|
+
- test/deprecated_associations_test.rb.orig
|
74
76
|
- test/finder_test.rb
|
75
77
|
- test/fixtures
|
76
78
|
- test/fixtures_test.rb
|
@@ -93,6 +95,7 @@ files:
|
|
93
95
|
- test/connections/native_sqlite/connection.rb
|
94
96
|
- test/fixtures/accounts
|
95
97
|
- test/fixtures/auto_id.rb
|
98
|
+
- test/fixtures/bad_fixtures
|
96
99
|
- test/fixtures/column_name.rb
|
97
100
|
- test/fixtures/companies
|
98
101
|
- test/fixtures/company.rb
|
@@ -121,6 +124,11 @@ files:
|
|
121
124
|
- test/fixtures/topics
|
122
125
|
- test/fixtures/accounts/signals37
|
123
126
|
- test/fixtures/accounts/unknown
|
127
|
+
- test/fixtures/bad_fixtures/attr_with_numeric_first_char
|
128
|
+
- test/fixtures/bad_fixtures/attr_with_spaces
|
129
|
+
- test/fixtures/bad_fixtures/blank_line
|
130
|
+
- test/fixtures/bad_fixtures/duplicate_attributes
|
131
|
+
- test/fixtures/bad_fixtures/missing_value
|
124
132
|
- test/fixtures/companies/first_client
|
125
133
|
- test/fixtures/companies/first_firm
|
126
134
|
- test/fixtures/companies/second_client
|