composite_primary_keys 4.1.1 → 4.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ == 4.1.2 2012-01-12
2
+ * Helper to allow the same tests to be used for both Oracle and other DBs
3
+ by replacing quoted identifiers with all-caps equivalents on Oracle (Rhett Sutphin)
4
+ * Update Oracle tests (Rhett Sutphin)
5
+
1
6
  == 4.1.1 2011-08-31
2
7
  * Support for AR 3.1.1
3
8
  * Make polymorphic belongs_to work in rails 3.1.1 (Tom Hughes)
@@ -36,13 +36,19 @@ module ActiveRecord
36
36
  foreign_key = reflection.active_record_primary_key
37
37
  end
38
38
 
39
+ conditions = self.conditions[i]
40
+
39
41
  if reflection == chain.last
40
42
  # CPK
41
43
  # scope = scope.where(table[key].eq(owner[foreign_key]))
42
44
  predicate = cpk_join_predicate(table, key, owner, foreign_key)
43
45
  scope = scope.where(predicate)
44
46
 
45
- conditions[i].each do |condition|
47
+ if reflection.type
48
+ scope = scope.where(table[reflection.type].eq(owner.class.base_class.name))
49
+ end
50
+
51
+ conditions.each do |condition|
46
52
  if options[:through] && condition.is_a?(Hash)
47
53
  condition = { table.name => condition }
48
54
  end
@@ -53,14 +59,16 @@ module ActiveRecord
53
59
  # CPK
54
60
  # constraint = table[key].eq(foreign_table[foreign_key])
55
61
  constraint = cpk_join_predicate(table, key, foreign_table, foreign_key)
56
- scope = scope.where(predicate)
57
62
 
58
- join = join(foreign_table, constraint)
63
+ if reflection.type
64
+ type = chain[i + 1].klass.base_class.name
65
+ constraint = constraint.and(table[reflection.type].eq(type))
66
+ end
59
67
 
60
- scope = scope.joins(join)
68
+ scope = scope.joins(join(foreign_table, constraint))
61
69
 
62
- unless conditions[i].empty?
63
- scope = scope.where(sanitize(conditions[i], table))
70
+ unless conditions.empty?
71
+ scope = scope.where(sanitize(conditions, table))
64
72
  end
65
73
  end
66
74
  end
@@ -2,7 +2,7 @@ module CompositePrimaryKeys
2
2
  module VERSION
3
3
  MAJOR = 4
4
4
  MINOR = 1
5
- TINY = 1
5
+ TINY = 2
6
6
  STRING = [MAJOR, MINOR, TINY].join('.')
7
7
  end
8
8
  end
@@ -81,6 +81,17 @@ class ActiveSupport::TestCase
81
81
  def composite?
82
82
  @key_test != :single
83
83
  end
84
+
85
+ # Oracle metadata is in all caps.
86
+ def with_quoted_identifiers(s)
87
+ s.gsub(/"(\w+)"/) { |m|
88
+ if ActiveRecord::Base.configurations[:test]['adapter'] =~ /oracle/i
89
+ m.upcase
90
+ else
91
+ m
92
+ end
93
+ }
94
+ end
84
95
  end
85
96
 
86
97
  def current_adapter?(type)
@@ -37,4 +37,6 @@ drop table room_attribute_assignments;
37
37
  drop table room_assignments;
38
38
  drop table students;
39
39
  drop sequence students_seq;
40
+ drop table seats;
41
+ drop table capitols;
40
42
  drop table products_restaurants;
@@ -181,6 +181,19 @@ create table room_assignments (
181
181
  room_id number(11) not null
182
182
  );
183
183
 
184
+ create table seats (
185
+ flight_number int not null,
186
+ seat int not null,
187
+ customer int,
188
+ primary key (flight_number, seat)
189
+ );
190
+
191
+ create table capitols (
192
+ country varchar2(2000) not null,
193
+ city varchar2(2000) not null,
194
+ primary key (country, city)
195
+ );
196
+
184
197
  create table products_restaurants (
185
198
  product_id number(11) not null,
186
199
  franchise_id number(11) not null,
@@ -19,6 +19,12 @@ class TestAssociations < ActiveSupport::TestCase
19
19
  product = products(:first_product)
20
20
  assert_equal(2, product.product_tariffs.count(:distinct => true))
21
21
  end
22
+
23
+ def test_count_includes
24
+ count = Dorm.count(:include => :rooms,
25
+ :conditions => ["rooms.room_id = ?", 2])
26
+ assert_equal(1, count)
27
+ end
22
28
 
23
29
  def test_products
24
30
  assert_not_nil products(:first_product).product_tariffs
@@ -50,7 +50,7 @@ class TestFind < ActiveSupport::TestCase
50
50
  error = assert_raise(::ActiveRecord::RecordNotFound) do
51
51
  ReferenceCode.find(['999', '999'])
52
52
  end
53
- assert_equal("Couldn't find ReferenceCode with ID=999,999 WHERE \"reference_codes\".\"reference_type_id\" = 999 AND \"reference_codes\".\"reference_code\" = 999",
53
+ assert_equal(with_quoted_identifiers("Couldn't find ReferenceCode with ID=999,999 WHERE \"reference_codes\".\"reference_type_id\" = 999 AND \"reference_codes\".\"reference_code\" = 999"),
54
54
  error.message)
55
55
  end
56
56
 
@@ -15,7 +15,7 @@ class TestEqual < ActiveSupport::TestCase
15
15
  end
16
16
 
17
17
  pred = cpk_or_predicate(predicates)
18
- assert_equal('(("departments"."id" = 0) OR ("departments"."id" = 1) OR ("departments"."id" = 2))',
18
+ assert_equal(with_quoted_identifiers('(("departments"."id" = 0) OR ("departments"."id" = 1) OR ("departments"."id" = 2))'),
19
19
  pred)
20
20
  end
21
21
 
@@ -29,7 +29,7 @@ class TestEqual < ActiveSupport::TestCase
29
29
  end
30
30
 
31
31
  pred = cpk_and_predicate(predicates)
32
- assert_equal('"departments"."id" = 0 AND "departments"."id" = 1 AND "departments"."id" = 2',
32
+ assert_equal(with_quoted_identifiers('"departments"."id" = 0 AND "departments"."id" = 1 AND "departments"."id" = 2'),
33
33
  pred.to_sql)
34
34
  end
35
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: composite_primary_keys
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.1
4
+ version: 4.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-11-03 00:00:00.000000000 Z
13
+ date: 2012-01-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
17
- requirement: &25587648 !ruby/object:Gem::Requirement
17
+ requirement: &22966128 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: '3.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *25587648
25
+ version_requirements: *22966128
26
26
  description: Composite key support for ActiveRecord 3
27
27
  email:
28
28
  - drnicwilliams@gmail.com