composite_primary_keys 2.3.5.1 → 3.0.0.b2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +26 -0
- data/README.txt +1 -1
- data/Rakefile +41 -51
- data/lib/composite_primary_keys.rb +19 -7
- data/lib/composite_primary_keys/association_preload.rb +75 -170
- data/lib/composite_primary_keys/associations.rb +98 -400
- data/lib/composite_primary_keys/associations/association_proxy.rb +32 -0
- data/lib/composite_primary_keys/associations/has_and_belongs_to_many_association.rb +30 -0
- data/lib/composite_primary_keys/associations/has_many_association.rb +72 -0
- data/lib/composite_primary_keys/associations/has_one_association.rb +19 -0
- data/lib/composite_primary_keys/associations/through_association_scope.rb +103 -0
- data/lib/composite_primary_keys/base.rb +148 -305
- data/lib/composite_primary_keys/calculations.rb +22 -64
- data/lib/composite_primary_keys/composite_arrays.rb +3 -10
- data/lib/composite_primary_keys/connection_adapters/abstract_adapter.rb +9 -0
- data/lib/composite_primary_keys/connection_adapters/oracle_enhanced_adapter.rb +17 -0
- data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +1 -1
- data/lib/composite_primary_keys/finder_methods.rb +71 -0
- data/lib/composite_primary_keys/fixtures.rb +1 -1
- data/lib/composite_primary_keys/read.rb +25 -0
- data/lib/composite_primary_keys/reflection.rb +30 -10
- data/lib/composite_primary_keys/relation.rb +31 -0
- data/lib/composite_primary_keys/validations/uniqueness.rb +106 -66
- data/lib/composite_primary_keys/version.rb +4 -4
- data/scripts/console.rb +1 -1
- data/tasks/Rakefile.rb +13 -0
- data/tasks/databases/mysql.rake +11 -15
- data/tasks/databases/oracle.rake +10 -11
- data/tasks/databases/postgresql.rake +10 -13
- data/tasks/databases/sqlite3.rake +9 -9
- data/test/README_tests.txt +1 -45
- data/test/abstract_unit.rb +17 -14
- data/test/connections/connection_spec.rb +19 -0
- data/test/connections/databases.example.yml +11 -0
- data/test/connections/databases.yml +13 -0
- data/test/connections/native_mysql/connection.rb +10 -2
- data/test/connections/native_oracle/connection.rb +7 -4
- data/test/connections/native_oracle_enhanced/connection.rb +23 -0
- data/test/connections/native_postgresql/connection.rb +13 -5
- data/test/connections/native_sqlite/connection.rb +7 -3
- data/test/fixtures/article_group.rb +4 -0
- data/test/fixtures/article_groups.yml +7 -0
- data/test/fixtures/db_definitions/postgresql.sql +2 -1
- data/test/fixtures/debug.log +133 -0
- data/test/fixtures/dorm.rb +3 -0
- data/test/fixtures/dorms.yml +2 -0
- data/test/fixtures/kitchen_sink.rb +3 -0
- data/test/fixtures/kitchen_sinks.yml +5 -0
- data/test/fixtures/reference_codes.yml +2 -0
- data/test/fixtures/reference_type.rb +1 -1
- data/test/fixtures/restaurant.rb +6 -0
- data/test/fixtures/restaurants.yml +5 -0
- data/test/fixtures/restaurants_suburbs.yml +11 -0
- data/test/fixtures/room.rb +10 -0
- data/test/fixtures/room_assignment.rb +4 -0
- data/test/fixtures/room_assignments.yml +4 -0
- data/test/fixtures/room_attribute.rb +3 -0
- data/test/fixtures/room_attribute_assignment.rb +5 -0
- data/test/fixtures/room_attribute_assignments.yml +4 -0
- data/test/fixtures/room_attributes.yml +3 -0
- data/test/fixtures/rooms.yml +3 -0
- data/test/fixtures/seat.rb +5 -0
- data/test/fixtures/seats.yml +4 -0
- data/test/fixtures/student.rb +4 -0
- data/test/fixtures/students.yml +2 -0
- data/test/test_associations.rb +27 -50
- data/test/test_attributes.rb +15 -19
- data/test/test_composite_arrays.rb +2 -21
- data/test/test_create.rb +3 -3
- data/test/test_delete.rb +7 -20
- data/test/test_exists.rb +3 -7
- data/test/test_find.rb +0 -8
- data/test/test_ids.rb +3 -17
- data/test/test_polymorphic.rb +5 -4
- data/test/test_suite.rb +19 -0
- data/test/{test_tutorial_examle.rb → test_tutorial_example.rb} +0 -0
- metadata +110 -72
- data/Manifest.txt +0 -123
- data/lib/adapter_helper/base.rb +0 -63
- data/lib/adapter_helper/mysql.rb +0 -13
- data/lib/adapter_helper/oracle.rb +0 -12
- data/lib/adapter_helper/postgresql.rb +0 -13
- data/lib/adapter_helper/sqlite3.rb +0 -13
- data/lib/composite_primary_keys/migration.rb +0 -20
- data/local/database_connections.rb.sample +0 -12
- data/local/paths.rb.sample +0 -2
- data/local/tasks.rb.sample +0 -2
- data/tasks/activerecord_selection.rake +0 -43
- data/tasks/databases.rake +0 -12
- data/tasks/deployment.rake +0 -22
- data/tasks/local_setup.rake +0 -13
- data/test/test_dummy.rb +0 -28
- data/tmp/test.db +0 -0
- data/website/index.html +0 -195
- data/website/index.txt +0 -159
- data/website/javascripts/rounded_corners_lite.inc.js +0 -285
- data/website/stylesheets/screen.css +0 -126
- data/website/template.js +0 -3
- data/website/template.rhtml +0 -53
- data/website/version-raw.js +0 -3
- data/website/version-raw.txt +0 -2
- data/website/version.js +0 -4
- data/website/version.txt +0 -3
@@ -1,9 +1,13 @@
|
|
1
1
|
print "Using native Sqlite3\n"
|
2
2
|
require 'logger'
|
3
3
|
require 'adapter_helper/sqlite3'
|
4
|
+
require 'active_record'
|
4
5
|
|
5
6
|
ActiveRecord::Base.logger = Logger.new("debug.log")
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def connection_string
|
9
|
+
connection_SPEC['dbfile']
|
10
|
+
end
|
11
|
+
|
12
|
+
SPEC = CompositePrimaryKeys::ConnectionSpec[:sqlite3]
|
13
|
+
ActiveRecord::Base.establish_connection(SPEC)
|
@@ -13,7 +13,8 @@ create table reference_codes (
|
|
13
13
|
reference_code int not null,
|
14
14
|
code_label varchar(50) default null,
|
15
15
|
abbreviation varchar(50) default null,
|
16
|
-
description varchar(50) default null
|
16
|
+
description varchar(50) default null,
|
17
|
+
primary key (reference_type_id, reference_code)
|
17
18
|
);
|
18
19
|
|
19
20
|
create sequence public.products_seq start 1000;
|
@@ -0,0 +1,133 @@
|
|
1
|
+
# Logfile created on 2010-05-01 19:19:57 -0600 by logger.rb/25413
|
2
|
+
PGError: ERROR: column employees.department_id,location_id does not exist
|
3
|
+
LINE 1: ...s" SET "department_id,location_id" = NULL WHERE ("employees...
|
4
|
+
^
|
5
|
+
: UPDATE "employees" SET "department_id,location_id" = NULL WHERE ("employees"."department_id,location_id" = (1, 1) AND "employees"."id" IN (1, 2))
|
6
|
+
PGError: ERROR: column employees.department_id,location_id does not exist
|
7
|
+
LINE 1: ...s" SET "department_id,location_id" = NULL WHERE ("employees...
|
8
|
+
^
|
9
|
+
: UPDATE "employees" SET "department_id,location_id" = NULL WHERE ("employees"."department_id,location_id" = (1, 1) AND "employees"."id" IN (1))
|
10
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW client_min_messages[0m
|
11
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'panic'
|
12
|
+
[1m[36mSQL (0.0ms)[0m [1mSET standard_conforming_strings = on[0m
|
13
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'notice'
|
14
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW TIME ZONE[0m
|
15
|
+
[1m[35mSQL (3.0ms)[0m SELECT tablename
|
16
|
+
FROM pg_tables
|
17
|
+
WHERE schemaname = ANY (current_schemas(false))
|
18
|
+
|
19
|
+
[1m[36mReferenceCode Load (1.0ms)[0m [1mSELECT "reference_codes".* FROM "reference_codes" ORDER BY reference_type_id,reference_code LIMIT 1[0m
|
20
|
+
[1m[35mSQL (4.0ms)[0m SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
|
21
|
+
FROM pg_attribute a LEFT JOIN pg_attrdef d
|
22
|
+
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
|
23
|
+
WHERE a.attrelid = '"reference_codes"'::regclass
|
24
|
+
AND a.attnum > 0 AND NOT a.attisdropped
|
25
|
+
ORDER BY a.attnum
|
26
|
+
|
27
|
+
[1m[36mReferenceCode Load (1.0ms)[0m [1mSELECT "reference_codes".* FROM "reference_codes" WHERE ("reference_codes"."reference_type_id" = 1) AND ("reference_codes"."reference_code" = 1)[0m
|
28
|
+
[1m[35mReferenceCode Load (2.0ms)[0m SELECT "reference_codes".* FROM "reference_codes" ORDER BY reference_type_id,reference_code LIMIT 1
|
29
|
+
[1m[36mReferenceCode Load (1.0ms)[0m [1mSELECT "reference_codes".* FROM "reference_codes" WHERE ("reference_codes"."reference_type_id" = 1) AND ("reference_codes"."reference_code" = 1)[0m
|
30
|
+
[1m[35mReferenceCode Load (7.0ms)[0m SELECT "reference_codes".* FROM "reference_codes" ORDER BY reference_type_id,reference_code LIMIT 1
|
31
|
+
[1m[36mReferenceCode Load (1.0ms)[0m [1mSELECT "reference_codes".* FROM "reference_codes" LIMIT 1[0m
|
32
|
+
[1m[35mReferenceCode Load (1.0ms)[0m SELECT "reference_codes".* FROM "reference_codes"
|
33
|
+
[1m[36mReferenceCode Load (1.0ms)[0m [1mSELECT "reference_codes".* FROM "reference_codes" ORDER BY reference_type_id,reference_code LIMIT 1[0m
|
34
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW client_min_messages[0m
|
35
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'panic'
|
36
|
+
[1m[36mSQL (0.0ms)[0m [1mSET standard_conforming_strings = on[0m
|
37
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'notice'
|
38
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW TIME ZONE[0m
|
39
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW client_min_messages[0m
|
40
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'panic'
|
41
|
+
[1m[36mSQL (0.0ms)[0m [1mSET standard_conforming_strings = on[0m
|
42
|
+
[1m[35mSQL (1.0ms)[0m SET client_min_messages TO 'notice'
|
43
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW TIME ZONE[0m
|
44
|
+
[1m[36mSQL (1.0ms)[0m [1mSHOW client_min_messages[0m
|
45
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'panic'
|
46
|
+
[1m[36mSQL (0.0ms)[0m [1mSET standard_conforming_strings = on[0m
|
47
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'notice'
|
48
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW TIME ZONE[0m
|
49
|
+
[1m[36mSQL (1.0ms)[0m [1mSHOW client_min_messages[0m
|
50
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'panic'
|
51
|
+
[1m[36mSQL (0.0ms)[0m [1mSET standard_conforming_strings = on[0m
|
52
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'notice'
|
53
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW TIME ZONE[0m
|
54
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW client_min_messages[0m
|
55
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'panic'
|
56
|
+
[1m[36mSQL (0.0ms)[0m [1mSET standard_conforming_strings = on[0m
|
57
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'notice'
|
58
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW TIME ZONE[0m
|
59
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW client_min_messages[0m
|
60
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'panic'
|
61
|
+
[1m[36mSQL (0.0ms)[0m [1mSET standard_conforming_strings = on[0m
|
62
|
+
[1m[35mSQL (1.0ms)[0m SET client_min_messages TO 'notice'
|
63
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW TIME ZONE[0m
|
64
|
+
[1m[36mSQL (1.0ms)[0m [1mSHOW client_min_messages[0m
|
65
|
+
[1m[35mSQL (1.0ms)[0m SET client_min_messages TO 'panic'
|
66
|
+
[1m[36mSQL (0.0ms)[0m [1mSET standard_conforming_strings = on[0m
|
67
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'notice'
|
68
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW TIME ZONE[0m
|
69
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW client_min_messages[0m
|
70
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'panic'
|
71
|
+
[1m[36mSQL (0.0ms)[0m [1mSET standard_conforming_strings = on[0m
|
72
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'notice'
|
73
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW TIME ZONE[0m
|
74
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW client_min_messages[0m
|
75
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'panic'
|
76
|
+
[1m[36mSQL (0.0ms)[0m [1mSET standard_conforming_strings = on[0m
|
77
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'notice'
|
78
|
+
[1m[36mSQL (1.0ms)[0m [1mSHOW TIME ZONE[0m
|
79
|
+
[1m[36mSQL (1.0ms)[0m [1mSHOW client_min_messages[0m
|
80
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'panic'
|
81
|
+
[1m[36mSQL (1.0ms)[0m [1mSET standard_conforming_strings = on[0m
|
82
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'notice'
|
83
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW TIME ZONE[0m
|
84
|
+
[1m[36mSQL (1.0ms)[0m [1mSHOW client_min_messages[0m
|
85
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'panic'
|
86
|
+
[1m[36mSQL (0.0ms)[0m [1mSET standard_conforming_strings = on[0m
|
87
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'notice'
|
88
|
+
[1m[36mSQL (1.0ms)[0m [1mSHOW TIME ZONE[0m
|
89
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW client_min_messages[0m
|
90
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'panic'
|
91
|
+
[1m[36mSQL (1.0ms)[0m [1mSET standard_conforming_strings = on[0m
|
92
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'notice'
|
93
|
+
[1m[36mSQL (1.0ms)[0m [1mSHOW TIME ZONE[0m
|
94
|
+
[1m[36mSQL (1.0ms)[0m [1mSHOW client_min_messages[0m
|
95
|
+
[1m[35mSQL (1.0ms)[0m SET client_min_messages TO 'panic'
|
96
|
+
[1m[36mSQL (0.0ms)[0m [1mSET standard_conforming_strings = on[0m
|
97
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'notice'
|
98
|
+
[1m[36mSQL (1.0ms)[0m [1mSHOW TIME ZONE[0m
|
99
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW client_min_messages[0m
|
100
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'panic'
|
101
|
+
[1m[36mSQL (0.0ms)[0m [1mSET standard_conforming_strings = on[0m
|
102
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'notice'
|
103
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW TIME ZONE[0m
|
104
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW client_min_messages[0m
|
105
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'panic'
|
106
|
+
[1m[36mSQL (0.0ms)[0m [1mSET standard_conforming_strings = on[0m
|
107
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'notice'
|
108
|
+
[1m[36mSQL (1.0ms)[0m [1mSHOW TIME ZONE[0m
|
109
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW client_min_messages[0m
|
110
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'panic'
|
111
|
+
[1m[36mSQL (0.0ms)[0m [1mSET standard_conforming_strings = on[0m
|
112
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'notice'
|
113
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW TIME ZONE[0m
|
114
|
+
[1m[36mSQL (1.0ms)[0m [1mSHOW client_min_messages[0m
|
115
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'panic'
|
116
|
+
[1m[36mSQL (0.0ms)[0m [1mSET standard_conforming_strings = on[0m
|
117
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'notice'
|
118
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW TIME ZONE[0m
|
119
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW client_min_messages[0m
|
120
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'panic'
|
121
|
+
[1m[36mSQL (0.0ms)[0m [1mSET standard_conforming_strings = on[0m
|
122
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'notice'
|
123
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW TIME ZONE[0m
|
124
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW client_min_messages[0m
|
125
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'panic'
|
126
|
+
[1m[36mSQL (0.0ms)[0m [1mSET standard_conforming_strings = on[0m
|
127
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'notice'
|
128
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW TIME ZONE[0m
|
129
|
+
[1m[36mSQL (1.0ms)[0m [1mSHOW client_min_messages[0m
|
130
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'panic'
|
131
|
+
[1m[36mSQL (0.0ms)[0m [1mSET standard_conforming_strings = on[0m
|
132
|
+
[1m[35mSQL (0.0ms)[0m SET client_min_messages TO 'notice'
|
133
|
+
[1m[36mSQL (0.0ms)[0m [1mSHOW TIME ZONE[0m
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class ReferenceType < ActiveRecord::Base
|
2
2
|
set_primary_key :reference_type_id
|
3
|
-
has_many :reference_codes, :foreign_key => "reference_type_id"
|
3
|
+
has_many :reference_codes, :foreign_key => "reference_type_id", :dependent => :destroy
|
4
4
|
|
5
5
|
validates_presence_of :type_label, :abbreviation
|
6
6
|
validates_uniqueness_of :type_label
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class Room < ActiveRecord::Base
|
2
|
+
set_primary_keys :dorm_id, :room_id
|
3
|
+
belongs_to :dorm
|
4
|
+
has_many :room_attribute_assignments, :foreign_key => [:dorm_id, :room_id]
|
5
|
+
has_many :room_attributes, :through => :room_attribute_assignments
|
6
|
+
|
7
|
+
def find_custom_room_attributes
|
8
|
+
room_attributes.find(:all, :conditions => ["room_attributes.name != ?", "keg"])
|
9
|
+
end
|
10
|
+
end
|
data/test/test_associations.rb
CHANGED
@@ -1,19 +1,4 @@
|
|
1
1
|
require 'abstract_unit'
|
2
|
-
require 'fixtures/article'
|
3
|
-
require 'fixtures/product'
|
4
|
-
require 'fixtures/tariff'
|
5
|
-
require 'fixtures/product_tariff'
|
6
|
-
require 'fixtures/suburb'
|
7
|
-
require 'fixtures/street'
|
8
|
-
require 'fixtures/restaurant'
|
9
|
-
require 'fixtures/dorm'
|
10
|
-
require 'fixtures/room'
|
11
|
-
require 'fixtures/room_attribute'
|
12
|
-
require 'fixtures/room_attribute_assignment'
|
13
|
-
require 'fixtures/student'
|
14
|
-
require 'fixtures/room_assignment'
|
15
|
-
require 'fixtures/user'
|
16
|
-
require 'fixtures/reading'
|
17
2
|
|
18
3
|
class TestAssociations < ActiveSupport::TestCase
|
19
4
|
fixtures :articles, :products, :tariffs, :product_tariffs, :suburbs, :streets, :restaurants, :restaurants_suburbs,
|
@@ -39,13 +24,13 @@ class TestAssociations < ActiveSupport::TestCase
|
|
39
24
|
room = Room.find(:first)
|
40
25
|
assert_equal 0, room.find_custom_room_attributes.size
|
41
26
|
end
|
42
|
-
|
27
|
+
|
43
28
|
def test_count
|
44
29
|
assert_equal 2, Product.count(:include => :product_tariffs)
|
45
30
|
assert_equal 3, Tariff.count(:include => :product_tariffs)
|
46
31
|
assert_equal 2, Tariff.count(:group => :start_date).size
|
47
32
|
end
|
48
|
-
|
33
|
+
|
49
34
|
def test_products
|
50
35
|
assert_not_nil products(:first_product).product_tariffs
|
51
36
|
assert_equal 2, products(:first_product).product_tariffs.length
|
@@ -53,14 +38,14 @@ class TestAssociations < ActiveSupport::TestCase
|
|
53
38
|
assert_equal 2, products(:first_product).tariffs.length
|
54
39
|
assert_not_nil products(:first_product).product_tariff
|
55
40
|
end
|
56
|
-
|
41
|
+
|
57
42
|
def test_product_tariffs
|
58
43
|
assert_not_nil product_tariffs(:first_flat).product
|
59
44
|
assert_not_nil product_tariffs(:first_flat).tariff
|
60
45
|
assert_equal Product, product_tariffs(:first_flat).product.class
|
61
46
|
assert_equal Tariff, product_tariffs(:first_flat).tariff.class
|
62
47
|
end
|
63
|
-
|
48
|
+
|
64
49
|
def test_tariffs
|
65
50
|
assert_not_nil tariffs(:flat).product_tariffs
|
66
51
|
assert_equal 1, tariffs(:flat).product_tariffs.length
|
@@ -68,60 +53,52 @@ class TestAssociations < ActiveSupport::TestCase
|
|
68
53
|
assert_equal 1, tariffs(:flat).products.length
|
69
54
|
assert_not_nil tariffs(:flat).product_tariff
|
70
55
|
end
|
71
|
-
|
56
|
+
|
72
57
|
# Its not generating the instances of associated classes from the rows
|
73
58
|
def test_find_includes_products
|
74
59
|
assert @products = Product.find(:all, :include => :product_tariffs)
|
75
60
|
assert_equal 2, @products.length
|
76
61
|
assert_not_nil @products.first.instance_variable_get('@product_tariffs'), '@product_tariffs not set; should be array'
|
77
|
-
assert_equal 3, @products.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
|
62
|
+
assert_equal 3, @products.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
|
78
63
|
"Incorrect number of product_tariffs returned"
|
79
64
|
end
|
80
|
-
|
65
|
+
|
81
66
|
def test_find_includes_tariffs
|
82
67
|
assert @tariffs = Tariff.find(:all, :include => :product_tariffs)
|
83
68
|
assert_equal 3, @tariffs.length
|
84
69
|
assert_not_nil @tariffs.first.instance_variable_get('@product_tariffs'), '@product_tariffs not set; should be array'
|
85
|
-
assert_equal 3, @tariffs.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
|
70
|
+
assert_equal 3, @tariffs.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
|
86
71
|
"Incorrect number of product_tariffs returnedturned"
|
87
72
|
end
|
88
|
-
|
73
|
+
|
89
74
|
def test_find_includes_product
|
90
75
|
assert @product_tariffs = ProductTariff.find(:all, :include => :product)
|
91
76
|
assert_equal 3, @product_tariffs.length
|
92
77
|
assert_not_nil @product_tariffs.first.instance_variable_get('@product'), '@product not set'
|
93
78
|
end
|
94
|
-
|
79
|
+
|
95
80
|
def test_find_includes_comp_belongs_to_tariff
|
96
81
|
assert @product_tariffs = ProductTariff.find(:all, :include => :tariff)
|
97
82
|
assert_equal 3, @product_tariffs.length
|
98
83
|
assert_not_nil @product_tariffs.first.instance_variable_get('@tariff'), '@tariff not set'
|
99
84
|
end
|
100
|
-
|
85
|
+
|
101
86
|
def test_find_includes_extended
|
102
87
|
assert @products = Product.find(:all, :include => {:product_tariffs => :tariff})
|
103
88
|
assert_equal 3, @products.inject(0) {|sum, product| sum + product.instance_variable_get('@product_tariffs').length},
|
104
89
|
"Incorrect number of product_tariffs returned"
|
105
|
-
|
90
|
+
|
106
91
|
assert @tariffs = Tariff.find(:all, :include => {:product_tariffs => :product})
|
107
|
-
assert_equal 3, @tariffs.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
|
92
|
+
assert_equal 3, @tariffs.inject(0) {|sum, tariff| sum + tariff.instance_variable_get('@product_tariffs').length},
|
108
93
|
"Incorrect number of product_tariffs returned"
|
109
94
|
end
|
110
|
-
|
111
|
-
def test_join_where_clause
|
112
|
-
@product = Product.find(:first, :include => :product_tariffs)
|
113
|
-
where_clause = @product.product_tariffs.composite_where_clause(
|
114
|
-
['foo','bar'], [1,2]
|
115
|
-
)
|
116
|
-
assert_equal('(foo=1 AND bar=2)', where_clause)
|
117
|
-
end
|
118
|
-
|
95
|
+
|
119
96
|
def test_has_many_through
|
120
97
|
@products = Product.find(:all, :include => :tariffs)
|
121
98
|
assert_equal 3, @products.inject(0) {|sum, product| sum + product.instance_variable_get('@tariffs').length},
|
122
99
|
"Incorrect number of tariffs returned"
|
123
100
|
end
|
124
|
-
|
101
|
+
|
125
102
|
def test_has_many_through_when_not_pre_loaded
|
126
103
|
student = Student.find(:first)
|
127
104
|
rooms = student.rooms
|
@@ -129,7 +106,7 @@ class TestAssociations < ActiveSupport::TestCase
|
|
129
106
|
assert_equal 1, rooms.first.dorm_id
|
130
107
|
assert_equal 1, rooms.first.room_id
|
131
108
|
end
|
132
|
-
|
109
|
+
|
133
110
|
def test_has_many_through_when_through_association_is_composite
|
134
111
|
dorm = Dorm.find(:first)
|
135
112
|
assert_equal 1, dorm.rooms.length
|
@@ -150,36 +127,36 @@ class TestAssociations < ActiveSupport::TestCase
|
|
150
127
|
@suburb = Suburb.find([2, 1], :include => :first_streets)
|
151
128
|
assert_equal 1, @suburb.first_streets.size
|
152
129
|
end
|
153
|
-
|
130
|
+
|
154
131
|
def test_has_and_belongs_to_many
|
155
|
-
|
156
|
-
assert_equal 2, @restaurant.suburbs.size
|
157
|
-
|
132
|
+
#@restaurant = Restaurant.find([1,1])
|
133
|
+
#assert_equal 2, @restaurant.suburbs.size
|
134
|
+
|
158
135
|
@restaurant = Restaurant.find([1,1], :include => :suburbs)
|
159
|
-
assert_equal 2, @restaurant.suburbs.size
|
136
|
+
assert_equal 2, @restaurant.suburbs.size
|
160
137
|
end
|
161
|
-
|
138
|
+
|
162
139
|
def test_has_many_with_primary_key
|
163
140
|
@membership = Membership.find([1, 1])
|
164
|
-
|
141
|
+
|
165
142
|
assert_equal 2, @membership.readings.size
|
166
143
|
end
|
167
144
|
|
168
145
|
def test_has_one_with_primary_key
|
169
146
|
@membership = Membership.find([1, 1])
|
170
|
-
|
147
|
+
|
171
148
|
assert_equal 2, @membership.reading.id
|
172
149
|
end
|
173
150
|
|
174
151
|
def test_joins_has_many_with_primary_key
|
175
152
|
@membership = Membership.find(:first, :joins => :readings, :conditions => { :readings => { :id => 1 } })
|
176
|
-
|
153
|
+
|
177
154
|
assert_equal [1, 1], @membership.id
|
178
155
|
end
|
179
156
|
|
180
157
|
def test_joins_has_one_with_primary_key
|
181
158
|
@membership = Membership.find(:first, :joins => :reading, :conditions => { :readings => { :id => 2 } })
|
182
|
-
|
159
|
+
|
183
160
|
assert_equal [1, 1], @membership.id
|
184
161
|
end
|
185
|
-
end
|
162
|
+
end
|