composite_primary_keys 2.3.5.1 → 3.0.0.b2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. data/History.txt +26 -0
  2. data/README.txt +1 -1
  3. data/Rakefile +41 -51
  4. data/lib/composite_primary_keys.rb +19 -7
  5. data/lib/composite_primary_keys/association_preload.rb +75 -170
  6. data/lib/composite_primary_keys/associations.rb +98 -400
  7. data/lib/composite_primary_keys/associations/association_proxy.rb +32 -0
  8. data/lib/composite_primary_keys/associations/has_and_belongs_to_many_association.rb +30 -0
  9. data/lib/composite_primary_keys/associations/has_many_association.rb +72 -0
  10. data/lib/composite_primary_keys/associations/has_one_association.rb +19 -0
  11. data/lib/composite_primary_keys/associations/through_association_scope.rb +103 -0
  12. data/lib/composite_primary_keys/base.rb +148 -305
  13. data/lib/composite_primary_keys/calculations.rb +22 -64
  14. data/lib/composite_primary_keys/composite_arrays.rb +3 -10
  15. data/lib/composite_primary_keys/connection_adapters/abstract_adapter.rb +9 -0
  16. data/lib/composite_primary_keys/connection_adapters/oracle_enhanced_adapter.rb +17 -0
  17. data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +1 -1
  18. data/lib/composite_primary_keys/finder_methods.rb +71 -0
  19. data/lib/composite_primary_keys/fixtures.rb +1 -1
  20. data/lib/composite_primary_keys/read.rb +25 -0
  21. data/lib/composite_primary_keys/reflection.rb +30 -10
  22. data/lib/composite_primary_keys/relation.rb +31 -0
  23. data/lib/composite_primary_keys/validations/uniqueness.rb +106 -66
  24. data/lib/composite_primary_keys/version.rb +4 -4
  25. data/scripts/console.rb +1 -1
  26. data/tasks/Rakefile.rb +13 -0
  27. data/tasks/databases/mysql.rake +11 -15
  28. data/tasks/databases/oracle.rake +10 -11
  29. data/tasks/databases/postgresql.rake +10 -13
  30. data/tasks/databases/sqlite3.rake +9 -9
  31. data/test/README_tests.txt +1 -45
  32. data/test/abstract_unit.rb +17 -14
  33. data/test/connections/connection_spec.rb +19 -0
  34. data/test/connections/databases.example.yml +11 -0
  35. data/test/connections/databases.yml +13 -0
  36. data/test/connections/native_mysql/connection.rb +10 -2
  37. data/test/connections/native_oracle/connection.rb +7 -4
  38. data/test/connections/native_oracle_enhanced/connection.rb +23 -0
  39. data/test/connections/native_postgresql/connection.rb +13 -5
  40. data/test/connections/native_sqlite/connection.rb +7 -3
  41. data/test/fixtures/article_group.rb +4 -0
  42. data/test/fixtures/article_groups.yml +7 -0
  43. data/test/fixtures/db_definitions/postgresql.sql +2 -1
  44. data/test/fixtures/debug.log +133 -0
  45. data/test/fixtures/dorm.rb +3 -0
  46. data/test/fixtures/dorms.yml +2 -0
  47. data/test/fixtures/kitchen_sink.rb +3 -0
  48. data/test/fixtures/kitchen_sinks.yml +5 -0
  49. data/test/fixtures/reference_codes.yml +2 -0
  50. data/test/fixtures/reference_type.rb +1 -1
  51. data/test/fixtures/restaurant.rb +6 -0
  52. data/test/fixtures/restaurants.yml +5 -0
  53. data/test/fixtures/restaurants_suburbs.yml +11 -0
  54. data/test/fixtures/room.rb +10 -0
  55. data/test/fixtures/room_assignment.rb +4 -0
  56. data/test/fixtures/room_assignments.yml +4 -0
  57. data/test/fixtures/room_attribute.rb +3 -0
  58. data/test/fixtures/room_attribute_assignment.rb +5 -0
  59. data/test/fixtures/room_attribute_assignments.yml +4 -0
  60. data/test/fixtures/room_attributes.yml +3 -0
  61. data/test/fixtures/rooms.yml +3 -0
  62. data/test/fixtures/seat.rb +5 -0
  63. data/test/fixtures/seats.yml +4 -0
  64. data/test/fixtures/student.rb +4 -0
  65. data/test/fixtures/students.yml +2 -0
  66. data/test/test_associations.rb +27 -50
  67. data/test/test_attributes.rb +15 -19
  68. data/test/test_composite_arrays.rb +2 -21
  69. data/test/test_create.rb +3 -3
  70. data/test/test_delete.rb +7 -20
  71. data/test/test_exists.rb +3 -7
  72. data/test/test_find.rb +0 -8
  73. data/test/test_ids.rb +3 -17
  74. data/test/test_polymorphic.rb +5 -4
  75. data/test/test_suite.rb +19 -0
  76. data/test/{test_tutorial_examle.rb → test_tutorial_example.rb} +0 -0
  77. metadata +110 -72
  78. data/Manifest.txt +0 -123
  79. data/lib/adapter_helper/base.rb +0 -63
  80. data/lib/adapter_helper/mysql.rb +0 -13
  81. data/lib/adapter_helper/oracle.rb +0 -12
  82. data/lib/adapter_helper/postgresql.rb +0 -13
  83. data/lib/adapter_helper/sqlite3.rb +0 -13
  84. data/lib/composite_primary_keys/migration.rb +0 -20
  85. data/local/database_connections.rb.sample +0 -12
  86. data/local/paths.rb.sample +0 -2
  87. data/local/tasks.rb.sample +0 -2
  88. data/tasks/activerecord_selection.rake +0 -43
  89. data/tasks/databases.rake +0 -12
  90. data/tasks/deployment.rake +0 -22
  91. data/tasks/local_setup.rake +0 -13
  92. data/test/test_dummy.rb +0 -28
  93. data/tmp/test.db +0 -0
  94. data/website/index.html +0 -195
  95. data/website/index.txt +0 -159
  96. data/website/javascripts/rounded_corners_lite.inc.js +0 -285
  97. data/website/stylesheets/screen.css +0 -126
  98. data/website/template.js +0 -3
  99. data/website/template.rhtml +0 -53
  100. data/website/version-raw.js +0 -3
  101. data/website/version-raw.txt +0 -2
  102. data/website/version.js +0 -4
  103. 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
- # Adapter config setup in locals/database_connections.rb
8
- connection_options = AdapterHelper::Sqlite3.load_connection_from_env
9
- ActiveRecord::Base.establish_connection(connection_options)
8
+ def connection_string
9
+ connection_SPEC['dbfile']
10
+ end
11
+
12
+ SPEC = CompositePrimaryKeys::ConnectionSpec[:sqlite3]
13
+ ActiveRecord::Base.establish_connection(SPEC)
@@ -0,0 +1,4 @@
1
+ class ArticleGroup < ActiveRecord::Base
2
+ belongs_to :article
3
+ belongs_to :group
4
+ end
@@ -0,0 +1,7 @@
1
+ cpk:
2
+ article_id: 1
3
+ group_id: 1
4
+
5
+ transformers:
6
+ article_id: 1
7
+ group_id: 2
@@ -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
+ SQL (0.0ms) SHOW client_min_messages
11
+ SQL (0.0ms) SET client_min_messages TO 'panic'
12
+ SQL (0.0ms) SET standard_conforming_strings = on
13
+ SQL (0.0ms) SET client_min_messages TO 'notice'
14
+ SQL (0.0ms) SHOW TIME ZONE
15
+ SQL (3.0ms) SELECT tablename
16
+ FROM pg_tables
17
+ WHERE schemaname = ANY (current_schemas(false))
18
+
19
+ ReferenceCode Load (1.0ms) SELECT "reference_codes".* FROM "reference_codes" ORDER BY reference_type_id,reference_code LIMIT 1
20
+ SQL (4.0ms) 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
+ ReferenceCode Load (1.0ms) SELECT "reference_codes".* FROM "reference_codes" WHERE ("reference_codes"."reference_type_id" = 1) AND ("reference_codes"."reference_code" = 1)
28
+ ReferenceCode Load (2.0ms) SELECT "reference_codes".* FROM "reference_codes" ORDER BY reference_type_id,reference_code LIMIT 1
29
+ ReferenceCode Load (1.0ms) SELECT "reference_codes".* FROM "reference_codes" WHERE ("reference_codes"."reference_type_id" = 1) AND ("reference_codes"."reference_code" = 1)
30
+ ReferenceCode Load (7.0ms) SELECT "reference_codes".* FROM "reference_codes" ORDER BY reference_type_id,reference_code LIMIT 1
31
+ ReferenceCode Load (1.0ms) SELECT "reference_codes".* FROM "reference_codes" LIMIT 1
32
+ ReferenceCode Load (1.0ms) SELECT "reference_codes".* FROM "reference_codes"
33
+ ReferenceCode Load (1.0ms) SELECT "reference_codes".* FROM "reference_codes" ORDER BY reference_type_id,reference_code LIMIT 1
34
+ SQL (0.0ms) SHOW client_min_messages
35
+ SQL (0.0ms) SET client_min_messages TO 'panic'
36
+ SQL (0.0ms) SET standard_conforming_strings = on
37
+ SQL (0.0ms) SET client_min_messages TO 'notice'
38
+ SQL (0.0ms) SHOW TIME ZONE
39
+ SQL (0.0ms) SHOW client_min_messages
40
+ SQL (0.0ms) SET client_min_messages TO 'panic'
41
+ SQL (0.0ms) SET standard_conforming_strings = on
42
+ SQL (1.0ms) SET client_min_messages TO 'notice'
43
+ SQL (0.0ms) SHOW TIME ZONE
44
+ SQL (1.0ms) SHOW client_min_messages
45
+ SQL (0.0ms) SET client_min_messages TO 'panic'
46
+ SQL (0.0ms) SET standard_conforming_strings = on
47
+ SQL (0.0ms) SET client_min_messages TO 'notice'
48
+ SQL (0.0ms) SHOW TIME ZONE
49
+ SQL (1.0ms) SHOW client_min_messages
50
+ SQL (0.0ms) SET client_min_messages TO 'panic'
51
+ SQL (0.0ms) SET standard_conforming_strings = on
52
+ SQL (0.0ms) SET client_min_messages TO 'notice'
53
+ SQL (0.0ms) SHOW TIME ZONE
54
+ SQL (0.0ms) SHOW client_min_messages
55
+ SQL (0.0ms) SET client_min_messages TO 'panic'
56
+ SQL (0.0ms) SET standard_conforming_strings = on
57
+ SQL (0.0ms) SET client_min_messages TO 'notice'
58
+ SQL (0.0ms) SHOW TIME ZONE
59
+ SQL (0.0ms) SHOW client_min_messages
60
+ SQL (0.0ms) SET client_min_messages TO 'panic'
61
+ SQL (0.0ms) SET standard_conforming_strings = on
62
+ SQL (1.0ms) SET client_min_messages TO 'notice'
63
+ SQL (0.0ms) SHOW TIME ZONE
64
+ SQL (1.0ms) SHOW client_min_messages
65
+ SQL (1.0ms) SET client_min_messages TO 'panic'
66
+ SQL (0.0ms) SET standard_conforming_strings = on
67
+ SQL (0.0ms) SET client_min_messages TO 'notice'
68
+ SQL (0.0ms) SHOW TIME ZONE
69
+ SQL (0.0ms) SHOW client_min_messages
70
+ SQL (0.0ms) SET client_min_messages TO 'panic'
71
+ SQL (0.0ms) SET standard_conforming_strings = on
72
+ SQL (0.0ms) SET client_min_messages TO 'notice'
73
+ SQL (0.0ms) SHOW TIME ZONE
74
+ SQL (0.0ms) SHOW client_min_messages
75
+ SQL (0.0ms) SET client_min_messages TO 'panic'
76
+ SQL (0.0ms) SET standard_conforming_strings = on
77
+ SQL (0.0ms) SET client_min_messages TO 'notice'
78
+ SQL (1.0ms) SHOW TIME ZONE
79
+ SQL (1.0ms) SHOW client_min_messages
80
+ SQL (0.0ms) SET client_min_messages TO 'panic'
81
+ SQL (1.0ms) SET standard_conforming_strings = on
82
+ SQL (0.0ms) SET client_min_messages TO 'notice'
83
+ SQL (0.0ms) SHOW TIME ZONE
84
+ SQL (1.0ms) SHOW client_min_messages
85
+ SQL (0.0ms) SET client_min_messages TO 'panic'
86
+ SQL (0.0ms) SET standard_conforming_strings = on
87
+ SQL (0.0ms) SET client_min_messages TO 'notice'
88
+ SQL (1.0ms) SHOW TIME ZONE
89
+ SQL (0.0ms) SHOW client_min_messages
90
+ SQL (0.0ms) SET client_min_messages TO 'panic'
91
+ SQL (1.0ms) SET standard_conforming_strings = on
92
+ SQL (0.0ms) SET client_min_messages TO 'notice'
93
+ SQL (1.0ms) SHOW TIME ZONE
94
+ SQL (1.0ms) SHOW client_min_messages
95
+ SQL (1.0ms) SET client_min_messages TO 'panic'
96
+ SQL (0.0ms) SET standard_conforming_strings = on
97
+ SQL (0.0ms) SET client_min_messages TO 'notice'
98
+ SQL (1.0ms) SHOW TIME ZONE
99
+ SQL (0.0ms) SHOW client_min_messages
100
+ SQL (0.0ms) SET client_min_messages TO 'panic'
101
+ SQL (0.0ms) SET standard_conforming_strings = on
102
+ SQL (0.0ms) SET client_min_messages TO 'notice'
103
+ SQL (0.0ms) SHOW TIME ZONE
104
+ SQL (0.0ms) SHOW client_min_messages
105
+ SQL (0.0ms) SET client_min_messages TO 'panic'
106
+ SQL (0.0ms) SET standard_conforming_strings = on
107
+ SQL (0.0ms) SET client_min_messages TO 'notice'
108
+ SQL (1.0ms) SHOW TIME ZONE
109
+ SQL (0.0ms) SHOW client_min_messages
110
+ SQL (0.0ms) SET client_min_messages TO 'panic'
111
+ SQL (0.0ms) SET standard_conforming_strings = on
112
+ SQL (0.0ms) SET client_min_messages TO 'notice'
113
+ SQL (0.0ms) SHOW TIME ZONE
114
+ SQL (1.0ms) SHOW client_min_messages
115
+ SQL (0.0ms) SET client_min_messages TO 'panic'
116
+ SQL (0.0ms) SET standard_conforming_strings = on
117
+ SQL (0.0ms) SET client_min_messages TO 'notice'
118
+ SQL (0.0ms) SHOW TIME ZONE
119
+ SQL (0.0ms) SHOW client_min_messages
120
+ SQL (0.0ms) SET client_min_messages TO 'panic'
121
+ SQL (0.0ms) SET standard_conforming_strings = on
122
+ SQL (0.0ms) SET client_min_messages TO 'notice'
123
+ SQL (0.0ms) SHOW TIME ZONE
124
+ SQL (0.0ms) SHOW client_min_messages
125
+ SQL (0.0ms) SET client_min_messages TO 'panic'
126
+ SQL (0.0ms) SET standard_conforming_strings = on
127
+ SQL (0.0ms) SET client_min_messages TO 'notice'
128
+ SQL (0.0ms) SHOW TIME ZONE
129
+ SQL (1.0ms) SHOW client_min_messages
130
+ SQL (0.0ms) SET client_min_messages TO 'panic'
131
+ SQL (0.0ms) SET standard_conforming_strings = on
132
+ SQL (0.0ms) SET client_min_messages TO 'notice'
133
+ SQL (0.0ms) SHOW TIME ZONE
@@ -0,0 +1,3 @@
1
+ class Dorm < ActiveRecord::Base
2
+ has_many :rooms, :include => :room_attributes
3
+ end
@@ -0,0 +1,2 @@
1
+ jacksons_dorm:
2
+ id: 1
@@ -0,0 +1,3 @@
1
+ class KitchenSink < ActiveRecord::Base
2
+ set_primary_keys :id_1, :id_2
3
+ end
@@ -0,0 +1,5 @@
1
+ first:
2
+ id_1: 1
3
+ id_2: 2
4
+ a_date: <%= Date.today.to_s(:db) %>
5
+ a_string: 'string'
@@ -3,11 +3,13 @@ name_prefix_mr:
3
3
  reference_code: 1
4
4
  code_label: MR
5
5
  abbreviation: Mr
6
+
6
7
  name_prefix_mrs:
7
8
  reference_type_id: 1
8
9
  reference_code: 2
9
10
  code_label: MRS
10
11
  abbreviation: Mrs
12
+
11
13
  name_prefix_ms:
12
14
  reference_type_id: 1
13
15
  reference_code: 3
@@ -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,6 @@
1
+ class Restaurant < ActiveRecord::Base
2
+ set_primary_keys :franchise_id, :store_id
3
+ has_and_belongs_to_many :suburbs,
4
+ :foreign_key => [:franchise_id, :store_id],
5
+ :association_foreign_key => [:city_id, :suburb_id]
6
+ end
@@ -0,0 +1,5 @@
1
+ mcdonalds:
2
+ franchise_id: 1
3
+ store_id: 1
4
+ name: McDonalds
5
+
@@ -0,0 +1,11 @@
1
+ a:
2
+ franchise_id: 1
3
+ store_id: 1
4
+ city_id: 1
5
+ suburb_id: 1
6
+
7
+ b:
8
+ franchise_id: 1
9
+ store_id: 1
10
+ city_id: 2
11
+ suburb_id: 1
@@ -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
@@ -0,0 +1,4 @@
1
+ class RoomAssignment < ActiveRecord::Base
2
+ belongs_to :student
3
+ belongs_to :room, :foreign_key => [:dorm_id, :room_id]
4
+ end
@@ -0,0 +1,4 @@
1
+ jacksons_room:
2
+ student_id: 1
3
+ dorm_id: 1
4
+ room_id: 1
@@ -0,0 +1,3 @@
1
+ class RoomAttribute < ActiveRecord::Base
2
+ has_many :rooms, :through => :room_attribute_assignments, :foreign_key => [:dorm_id, :room_id]
3
+ end
@@ -0,0 +1,5 @@
1
+ class RoomAttributeAssignment < ActiveRecord::Base
2
+ set_primary_keys :dorm_id, :room_id, :room_attribute_id
3
+ belongs_to :room, :foreign_key => [:dorm_id, :room_id]
4
+ belongs_to :room_attribute
5
+ end
@@ -0,0 +1,4 @@
1
+ assignment:
2
+ dorm_id: 1
3
+ room_id: 1
4
+ room_attribute_id: 1
@@ -0,0 +1,3 @@
1
+ attribute_1:
2
+ id: 1
3
+ name: 'keg'
@@ -0,0 +1,3 @@
1
+ jacksons_room:
2
+ dorm_id: 1
3
+ room_id: 1
@@ -0,0 +1,5 @@
1
+ class Seat < ActiveRecord::Base
2
+ set_primary_keys [:flight_number, :seat]
3
+
4
+ validates_uniqueness_of :customer
5
+ end
@@ -0,0 +1,4 @@
1
+ seat1:
2
+ flight_number: 1
3
+ seat: 1
4
+ customer: 1
@@ -0,0 +1,4 @@
1
+ class Student < ActiveRecord::Base
2
+ has_many :room_assignments
3
+ has_many :rooms, :through => :room_assignments, :foreign_key => [:building_code, :room_number]
4
+ end
@@ -0,0 +1,2 @@
1
+ jackson:
2
+ id: 1
@@ -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
- @restaurant = Restaurant.find([1,1])
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