composite_primary_keys 8.1.1 → 8.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.rdoc +4 -1
- data/lib/composite_primary_keys.rb +5 -1
- data/lib/composite_primary_keys/arel/visitors/to_sql.rb +24 -0
- data/lib/composite_primary_keys/associations/association_scope.rb +32 -58
- data/lib/composite_primary_keys/associations/join_dependency/join_association.rb +22 -22
- data/lib/composite_primary_keys/associations/preloader/association.rb +12 -6
- data/lib/composite_primary_keys/associations/preloader/belongs_to.rb +19 -19
- data/lib/composite_primary_keys/attribute_methods/primary_key.rb +1 -2
- data/lib/composite_primary_keys/attribute_methods/read.rb +2 -2
- data/lib/composite_primary_keys/attribute_methods/write.rb +1 -1
- data/lib/composite_primary_keys/composite_predicates.rb +55 -50
- data/lib/composite_primary_keys/composite_relation.rb +48 -48
- data/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb +2 -2
- data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +19 -46
- data/lib/composite_primary_keys/connection_adapters/sqlserver_adapter.rb +8 -4
- data/lib/composite_primary_keys/fixtures.rb +26 -22
- data/lib/composite_primary_keys/locking/optimistic.rb +54 -55
- data/lib/composite_primary_keys/relation.rb +15 -8
- data/lib/composite_primary_keys/relation/batches.rb +23 -19
- data/lib/composite_primary_keys/relation/calculations.rb +4 -2
- data/lib/composite_primary_keys/relation/finder_methods.rb +33 -27
- data/lib/composite_primary_keys/relation/predicate_builder.rb +18 -3
- data/lib/composite_primary_keys/relation/query_methods.rb +41 -41
- data/lib/composite_primary_keys/sanitization.rb +7 -5
- data/lib/composite_primary_keys/validations/uniqueness.rb +20 -16
- data/lib/composite_primary_keys/version.rb +1 -1
- data/tasks/databases/oracle.rake +27 -25
- data/tasks/databases/oracle_enhanced.rake +27 -0
- data/test/connections/databases.ci.yml +15 -15
- data/test/connections/native_oracle/connection.rb +11 -11
- data/test/connections/native_oracle_enhanced/connection.rb +16 -16
- data/test/fixtures/comment.rb +7 -7
- data/test/fixtures/db_definitions/db2-create-tables.sql +126 -126
- data/test/fixtures/db_definitions/db2-drop-tables.sql +18 -18
- data/test/fixtures/db_definitions/oracle.drop.sql +48 -45
- data/test/fixtures/db_definitions/oracle.sql +236 -223
- data/test/fixtures/dorm.rb +2 -2
- data/test/fixtures/membership.rb +6 -6
- data/test/fixtures/membership_statuses.yml +16 -16
- data/test/fixtures/memberships.yml +10 -10
- data/test/fixtures/product_tariffs.yml +14 -14
- data/test/fixtures/reference_code.rb +7 -7
- data/test/fixtures/restaurants_suburb.rb +2 -2
- data/test/fixtures/suburb.rb +5 -5
- data/test/fixtures/topic.rb +5 -5
- data/test/fixtures/topic_source.rb +6 -6
- data/test/fixtures/topic_sources.yml +3 -3
- data/test/fixtures/topics.yml +8 -8
- data/test/fixtures/users.yml +10 -10
- data/test/test_attribute_methods.rb +63 -63
- data/test/test_calculations.rb +42 -37
- data/test/test_callbacks.rb +99 -99
- data/test/test_delete.rb +28 -21
- data/test/test_delete_all.rb +5 -4
- data/test/test_dumpable.rb +15 -15
- data/test/test_nested_attributes.rb +124 -124
- data/test/test_optimistic.rb +18 -18
- data/test/test_polymorphic.rb +1 -1
- data/test/test_predicates.rb +40 -40
- data/test/test_santiago.rb +23 -23
- data/test/test_suite.rb +34 -34
- data/test/test_touch.rb +23 -23
- data/test/test_update.rb +71 -71
- metadata +9 -8
- data/lib/composite_primary_keys/model_schema.rb +0 -15
data/test/test_delete.rb
CHANGED
@@ -3,25 +3,25 @@ require File.expand_path('../abstract_unit', __FILE__)
|
|
3
3
|
class TestDelete < ActiveSupport::TestCase
|
4
4
|
fixtures :articles, :departments, :employees, :products, :tariffs, :product_tariffs,
|
5
5
|
:reference_types, :reference_codes
|
6
|
-
|
6
|
+
|
7
7
|
CLASSES = {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
:single => {
|
9
|
+
:class => ReferenceType,
|
10
|
+
:primary_keys => :reference_type_id,
|
11
|
+
},
|
12
|
+
:dual => {
|
13
|
+
:class => ReferenceCode,
|
14
|
+
:primary_keys => [:reference_type_id, :reference_code],
|
15
|
+
},
|
16
16
|
}
|
17
|
-
|
17
|
+
|
18
18
|
def setup
|
19
19
|
self.class.classes = CLASSES
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def test_destroy_one
|
23
23
|
testing_with do
|
24
|
-
|
24
|
+
assert @first.destroy
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -91,22 +91,29 @@ class TestDelete < ActiveSupport::TestCase
|
|
91
91
|
|
92
92
|
def test_destroy_has_and_belongs_to_many_on_non_cpk
|
93
93
|
steve = employees(:steve)
|
94
|
-
records_before = ActiveRecord::Base.connection.execute(
|
94
|
+
records_before = ActiveRecord::Base.connection.execute('select * from employees_groups')
|
95
95
|
steve.destroy
|
96
|
-
records_after = ActiveRecord::Base.connection.execute(
|
97
|
-
|
96
|
+
records_after = ActiveRecord::Base.connection.execute('select * from employees_groups')
|
97
|
+
if records_before.respond_to?(:count)
|
98
|
+
assert_equal records_after.count, records_before.count - steve.groups.count
|
99
|
+
elsif records_before.respond_to?(:row_count) # OCI8:Cursor for oracle adapter
|
100
|
+
assert_equal records_after.row_count, records_before.row_count - steve.groups.count
|
101
|
+
end
|
98
102
|
end
|
99
103
|
|
100
|
-
def
|
101
|
-
records_before = ActiveRecord::Base.connection.execute(
|
104
|
+
def test_create_destroy_has_and_belongs_to_many_on_non_cpk
|
105
|
+
records_before = ActiveRecord::Base.connection.execute('select * from employees_groups')
|
102
106
|
employee = Employee.create
|
103
107
|
employee.groups << Group.create(name: 'test')
|
104
|
-
employees_groups_count = employee.groups.count
|
105
108
|
employee.destroy!
|
106
|
-
records_after = ActiveRecord::Base.connection.execute(
|
107
|
-
|
109
|
+
records_after = ActiveRecord::Base.connection.execute('select * from employees_groups')
|
110
|
+
if records_before.respond_to?(:count)
|
111
|
+
assert_equal records_before.count, records_after.count
|
112
|
+
elsif records_before.respond_to?(:row_count) # OCI8:Cursor for oracle adapter
|
113
|
+
assert_equal records_before.row_count, records_after.row_count
|
114
|
+
end
|
108
115
|
end
|
109
|
-
|
116
|
+
|
110
117
|
def test_delete_not_destroy_on_cpk
|
111
118
|
tariff = Tariff.where(tariff_id: 2).first
|
112
119
|
tariff.delete
|
data/test/test_delete_all.rb
CHANGED
@@ -20,14 +20,15 @@ class TestValidations < ActiveSupport::TestCase
|
|
20
20
|
mysql_match = /Unknown column 'employees_groups.' in 'where clause/ =~ exception.message
|
21
21
|
sqlite3_match = /no such column: employees_groups./ =~ exception.message
|
22
22
|
postgresql_match = /PG::SyntaxError: ERROR: zero-length delimited identifier/ =~ exception.message
|
23
|
+
oracle_match = /OCIError: ORA-01741: illegal zero-length identifier/ =~ exception.message
|
23
24
|
|
24
|
-
assert(postgresql_match || mysql_match || sqlite3_match)
|
25
|
+
assert(postgresql_match || mysql_match || sqlite3_match || oracle_match)
|
25
26
|
|
26
27
|
assert(EmployeesGroup.all.size == 3)
|
27
28
|
end
|
28
29
|
|
29
30
|
# This test fails, requires fixin arel
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
def test_delete_all_with_joins
|
32
|
+
ReferenceCode.joins(:reference_type).where(:reference_type_id => 1).delete_all
|
33
|
+
end
|
33
34
|
end
|
data/test/test_dumpable.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
-
|
3
|
-
class TestDumpable < ActiveSupport::TestCase
|
4
|
-
fixtures :articles, :readings, :users
|
5
|
-
|
6
|
-
def test_marshal_with_simple_preload
|
7
|
-
articles = Article.preload(:readings).where(id: 1).to_a
|
8
|
-
assert_equal(Marshal.load(Marshal.dump(articles)), articles)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_marshal_with_comples_preload
|
12
|
-
articles = Article.preload({ readings: :user }).where(id: 1).to_a
|
13
|
-
assert_equal(Marshal.load(Marshal.dump(articles)), articles)
|
14
|
-
end
|
15
|
-
end
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
+
|
3
|
+
class TestDumpable < ActiveSupport::TestCase
|
4
|
+
fixtures :articles, :readings, :users
|
5
|
+
|
6
|
+
def test_marshal_with_simple_preload
|
7
|
+
articles = Article.preload(:readings).where(id: 1).to_a
|
8
|
+
assert_equal(Marshal.load(Marshal.dump(articles)), articles)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_marshal_with_comples_preload
|
12
|
+
articles = Article.preload({ readings: :user }).where(id: 1).to_a
|
13
|
+
assert_equal(Marshal.load(Marshal.dump(articles)), articles)
|
14
|
+
end
|
15
|
+
end
|
@@ -1,124 +1,124 @@
|
|
1
|
-
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
-
|
3
|
-
# Testing the find action on composite ActiveRecords with two primary keys
|
4
|
-
class TestNestedAttributes < ActiveSupport::TestCase
|
5
|
-
fixtures :reference_types, :reference_codes
|
6
|
-
|
7
|
-
def test_nested_atttribute_create
|
8
|
-
code_id = 1001
|
9
|
-
|
10
|
-
reference_type = reference_types(:name_prefix)
|
11
|
-
reference_type.update_attribute :reference_codes_attributes, [{
|
12
|
-
:reference_code => code_id,
|
13
|
-
:code_label => 'XX',
|
14
|
-
:abbreviation => 'Xx'
|
15
|
-
}]
|
16
|
-
assert_not_nil ReferenceCode.find_by_reference_code(code_id)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_nested_atttribute_update
|
20
|
-
code_id = 1002
|
21
|
-
|
22
|
-
reference_type = reference_types(:name_prefix)
|
23
|
-
reference_type.update_attribute :reference_codes_attributes, [{
|
24
|
-
:reference_code => code_id,
|
25
|
-
:code_label => 'XX',
|
26
|
-
:abbreviation => 'Xx'
|
27
|
-
}]
|
28
|
-
|
29
|
-
reference_code = ReferenceCode.find_by_reference_code(code_id)
|
30
|
-
cpk = CompositePrimaryKeys::CompositeKeys[reference_type.reference_type_id, code_id]
|
31
|
-
reference_type.update_attribute :reference_codes_attributes, [{
|
32
|
-
:id => cpk,
|
33
|
-
:code_label => 'AAA',
|
34
|
-
:abbreviation => 'Aaa'
|
35
|
-
}]
|
36
|
-
|
37
|
-
reference_code = ReferenceCode.find_by_reference_code(code_id)
|
38
|
-
assert_kind_of(ReferenceCode, reference_code)
|
39
|
-
assert_equal(reference_code.code_label, 'AAA')
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_nested_atttribute_update_2
|
43
|
-
reference_type = reference_types(:gender)
|
44
|
-
reference_code = reference_codes(:gender_male)
|
45
|
-
|
46
|
-
reference_type.update_attributes(:reference_codes_attributes => [{:id => reference_code.id,
|
47
|
-
:code_label => 'XX',
|
48
|
-
:abbreviation => 'Xx'}])
|
49
|
-
|
50
|
-
reference_code.reload
|
51
|
-
assert_equal(reference_code.code_label, 'XX')
|
52
|
-
assert_equal(reference_code.abbreviation, 'Xx')
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_nested_atttribute_update_3
|
56
|
-
reference_type = reference_types(:gender)
|
57
|
-
reference_code = reference_codes(:gender_male)
|
58
|
-
|
59
|
-
reference_type.update_attributes(:reference_codes_attributes => [{:id => reference_code.id.to_s,
|
60
|
-
:code_label => 'XX',
|
61
|
-
:abbreviation => 'Xx'}])
|
62
|
-
|
63
|
-
reference_code.reload
|
64
|
-
assert_equal(reference_code.code_label, 'XX')
|
65
|
-
assert_equal(reference_code.abbreviation, 'Xx')
|
66
|
-
end
|
67
|
-
|
68
|
-
fixtures :topics, :topic_sources
|
69
|
-
|
70
|
-
def test_nested_attributes_create_with_string_in_primary_key
|
71
|
-
platform = 'instagram'
|
72
|
-
|
73
|
-
topic = topics(:music)
|
74
|
-
topic.update_attribute :topic_sources_attributes, [{
|
75
|
-
:platform => platform,
|
76
|
-
:keywords => 'funk'
|
77
|
-
}]
|
78
|
-
assert_not_nil TopicSource.find_by_platform(platform)
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_nested_attributes_update_with_string_in_primary_key
|
82
|
-
platform = 'instagram'
|
83
|
-
|
84
|
-
topic = topics(:music)
|
85
|
-
topic.update_attribute :topic_sources_attributes, [{
|
86
|
-
:platform => platform,
|
87
|
-
:keywords => 'funk'
|
88
|
-
}]
|
89
|
-
assert_not_nil TopicSource.find_by_platform(platform)
|
90
|
-
|
91
|
-
topic_source = TopicSource.find_by_platform(platform)
|
92
|
-
cpk = CompositePrimaryKeys::CompositeKeys[topic.id, platform]
|
93
|
-
topic.update_attribute :topic_sources_attributes, [{
|
94
|
-
:id => cpk,
|
95
|
-
:keywords => 'jazz'
|
96
|
-
}]
|
97
|
-
|
98
|
-
topic_source = TopicSource.find_by_platform(platform)
|
99
|
-
assert_kind_of(TopicSource, topic_source)
|
100
|
-
assert_equal(topic_source.keywords, 'jazz')
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_nested_attributes_update_with_string_in_primary_key_2
|
104
|
-
topic = topics(:music)
|
105
|
-
topic_source = topic_sources(:music_source)
|
106
|
-
|
107
|
-
topic.update_attributes(:topic_sources_attributes => [{:id => topic_source.id,
|
108
|
-
:keywords => 'classical, jazz'}])
|
109
|
-
|
110
|
-
topic_source.reload
|
111
|
-
assert_equal(topic_source.keywords, 'classical, jazz')
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_nested_attributes_update_with_string_in_primary_key_3
|
115
|
-
topic = topics(:music)
|
116
|
-
topic_source = topic_sources(:music_source)
|
117
|
-
|
118
|
-
topic.update_attributes(:topic_sources_attributes => [{:id => topic_source.id.to_s,
|
119
|
-
:keywords => 'classical, jazz'}])
|
120
|
-
|
121
|
-
topic_source.reload
|
122
|
-
assert_equal(topic_source.keywords, 'classical, jazz')
|
123
|
-
end
|
124
|
-
end
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
+
|
3
|
+
# Testing the find action on composite ActiveRecords with two primary keys
|
4
|
+
class TestNestedAttributes < ActiveSupport::TestCase
|
5
|
+
fixtures :reference_types, :reference_codes
|
6
|
+
|
7
|
+
def test_nested_atttribute_create
|
8
|
+
code_id = 1001
|
9
|
+
|
10
|
+
reference_type = reference_types(:name_prefix)
|
11
|
+
reference_type.update_attribute :reference_codes_attributes, [{
|
12
|
+
:reference_code => code_id,
|
13
|
+
:code_label => 'XX',
|
14
|
+
:abbreviation => 'Xx'
|
15
|
+
}]
|
16
|
+
assert_not_nil ReferenceCode.find_by_reference_code(code_id)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_nested_atttribute_update
|
20
|
+
code_id = 1002
|
21
|
+
|
22
|
+
reference_type = reference_types(:name_prefix)
|
23
|
+
reference_type.update_attribute :reference_codes_attributes, [{
|
24
|
+
:reference_code => code_id,
|
25
|
+
:code_label => 'XX',
|
26
|
+
:abbreviation => 'Xx'
|
27
|
+
}]
|
28
|
+
|
29
|
+
reference_code = ReferenceCode.find_by_reference_code(code_id)
|
30
|
+
cpk = CompositePrimaryKeys::CompositeKeys[reference_type.reference_type_id, code_id]
|
31
|
+
reference_type.update_attribute :reference_codes_attributes, [{
|
32
|
+
:id => cpk,
|
33
|
+
:code_label => 'AAA',
|
34
|
+
:abbreviation => 'Aaa'
|
35
|
+
}]
|
36
|
+
|
37
|
+
reference_code = ReferenceCode.find_by_reference_code(code_id)
|
38
|
+
assert_kind_of(ReferenceCode, reference_code)
|
39
|
+
assert_equal(reference_code.code_label, 'AAA')
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_nested_atttribute_update_2
|
43
|
+
reference_type = reference_types(:gender)
|
44
|
+
reference_code = reference_codes(:gender_male)
|
45
|
+
|
46
|
+
reference_type.update_attributes(:reference_codes_attributes => [{:id => reference_code.id,
|
47
|
+
:code_label => 'XX',
|
48
|
+
:abbreviation => 'Xx'}])
|
49
|
+
|
50
|
+
reference_code.reload
|
51
|
+
assert_equal(reference_code.code_label, 'XX')
|
52
|
+
assert_equal(reference_code.abbreviation, 'Xx')
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_nested_atttribute_update_3
|
56
|
+
reference_type = reference_types(:gender)
|
57
|
+
reference_code = reference_codes(:gender_male)
|
58
|
+
|
59
|
+
reference_type.update_attributes(:reference_codes_attributes => [{:id => reference_code.id.to_s,
|
60
|
+
:code_label => 'XX',
|
61
|
+
:abbreviation => 'Xx'}])
|
62
|
+
|
63
|
+
reference_code.reload
|
64
|
+
assert_equal(reference_code.code_label, 'XX')
|
65
|
+
assert_equal(reference_code.abbreviation, 'Xx')
|
66
|
+
end
|
67
|
+
|
68
|
+
fixtures :topics, :topic_sources
|
69
|
+
|
70
|
+
def test_nested_attributes_create_with_string_in_primary_key
|
71
|
+
platform = 'instagram'
|
72
|
+
|
73
|
+
topic = topics(:music)
|
74
|
+
topic.update_attribute :topic_sources_attributes, [{
|
75
|
+
:platform => platform,
|
76
|
+
:keywords => 'funk'
|
77
|
+
}]
|
78
|
+
assert_not_nil TopicSource.find_by_platform(platform)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_nested_attributes_update_with_string_in_primary_key
|
82
|
+
platform = 'instagram'
|
83
|
+
|
84
|
+
topic = topics(:music)
|
85
|
+
topic.update_attribute :topic_sources_attributes, [{
|
86
|
+
:platform => platform,
|
87
|
+
:keywords => 'funk'
|
88
|
+
}]
|
89
|
+
assert_not_nil TopicSource.find_by_platform(platform)
|
90
|
+
|
91
|
+
topic_source = TopicSource.find_by_platform(platform)
|
92
|
+
cpk = CompositePrimaryKeys::CompositeKeys[topic.id, platform]
|
93
|
+
topic.update_attribute :topic_sources_attributes, [{
|
94
|
+
:id => cpk,
|
95
|
+
:keywords => 'jazz'
|
96
|
+
}]
|
97
|
+
|
98
|
+
topic_source = TopicSource.find_by_platform(platform)
|
99
|
+
assert_kind_of(TopicSource, topic_source)
|
100
|
+
assert_equal(topic_source.keywords, 'jazz')
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_nested_attributes_update_with_string_in_primary_key_2
|
104
|
+
topic = topics(:music)
|
105
|
+
topic_source = topic_sources(:music_source)
|
106
|
+
|
107
|
+
topic.update_attributes(:topic_sources_attributes => [{:id => topic_source.id,
|
108
|
+
:keywords => 'classical, jazz'}])
|
109
|
+
|
110
|
+
topic_source.reload
|
111
|
+
assert_equal(topic_source.keywords, 'classical, jazz')
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_nested_attributes_update_with_string_in_primary_key_3
|
115
|
+
topic = topics(:music)
|
116
|
+
topic_source = topic_sources(:music_source)
|
117
|
+
|
118
|
+
topic.update_attributes(:topic_sources_attributes => [{:id => topic_source.id.to_s,
|
119
|
+
:keywords => 'classical, jazz'}])
|
120
|
+
|
121
|
+
topic_source.reload
|
122
|
+
assert_equal(topic_source.keywords, 'classical, jazz')
|
123
|
+
end
|
124
|
+
end
|
data/test/test_optimistic.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
-
|
3
|
-
class TestOptimisitic < ActiveSupport::TestCase
|
4
|
-
fixtures :restaurants
|
5
|
-
|
6
|
-
def test_update_with_stale_error
|
7
|
-
restaurant_1 = Restaurant.find([1, 1])
|
8
|
-
restaurant_1['name'] = "McDonalds renamed"
|
9
|
-
|
10
|
-
restaurant_2 = Restaurant.find([1, 1])
|
11
|
-
restaurant_2['name'] = "McDonalds renamed 2"
|
12
|
-
|
13
|
-
assert(restaurant_1.save)
|
14
|
-
assert_raise ActiveRecord::StaleObjectError do
|
15
|
-
restaurant_2.save
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
+
|
3
|
+
class TestOptimisitic < ActiveSupport::TestCase
|
4
|
+
fixtures :restaurants
|
5
|
+
|
6
|
+
def test_update_with_stale_error
|
7
|
+
restaurant_1 = Restaurant.find([1, 1])
|
8
|
+
restaurant_1['name'] = "McDonalds renamed"
|
9
|
+
|
10
|
+
restaurant_2 = Restaurant.find([1, 1])
|
11
|
+
restaurant_2['name'] = "McDonalds renamed 2"
|
12
|
+
|
13
|
+
assert(restaurant_1.save)
|
14
|
+
assert_raise ActiveRecord::StaleObjectError do
|
15
|
+
restaurant_2.save
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/test/test_polymorphic.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path('../abstract_unit', __FILE__)
|
2
2
|
|
3
3
|
class TestPolymorphic < ActiveSupport::TestCase
|
4
|
-
fixtures :users, :employees, :comments, :hacks, :articles
|
4
|
+
fixtures :users, :employees, :comments, :hacks, :articles, :readings
|
5
5
|
|
6
6
|
def test_polymorphic_has_many
|
7
7
|
comments = Hack.find(7).comments
|
data/test/test_predicates.rb
CHANGED
@@ -1,41 +1,41 @@
|
|
1
|
-
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
-
|
3
|
-
class TestEqual < ActiveSupport::TestCase
|
4
|
-
fixtures :departments
|
5
|
-
|
6
|
-
include CompositePrimaryKeys::Predicates
|
7
|
-
|
8
|
-
def test_or
|
9
|
-
dep = Arel::Table.new(:departments)
|
10
|
-
|
11
|
-
predicates = Array.new
|
12
|
-
|
13
|
-
3.times do |i|
|
14
|
-
predicates << dep[:id].eq(i)
|
15
|
-
end
|
16
|
-
|
17
|
-
connection = ActiveRecord::Base.connection
|
18
|
-
quoted = "#{connection.quote_table_name('departments')}.#{connection.quote_column_name('id')}"
|
19
|
-
expected = "(
|
20
|
-
|
21
|
-
pred = cpk_or_predicate(predicates)
|
22
|
-
assert_equal(with_quoted_identifiers(expected), pred.to_sql)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_and
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
+
|
3
|
+
class TestEqual < ActiveSupport::TestCase
|
4
|
+
fixtures :departments
|
5
|
+
|
6
|
+
include CompositePrimaryKeys::Predicates
|
7
|
+
|
8
|
+
def test_or
|
9
|
+
dep = Arel::Table.new(:departments)
|
10
|
+
|
11
|
+
predicates = Array.new
|
12
|
+
|
13
|
+
3.times do |i|
|
14
|
+
predicates << dep[:id].eq(i)
|
15
|
+
end
|
16
|
+
|
17
|
+
connection = ActiveRecord::Base.connection
|
18
|
+
quoted = "#{connection.quote_table_name('departments')}.#{connection.quote_column_name('id')}"
|
19
|
+
expected = "(#{quoted} = 0 OR #{quoted} = 1 OR #{quoted} = 2)"
|
20
|
+
|
21
|
+
pred = cpk_or_predicate(predicates)
|
22
|
+
assert_equal(with_quoted_identifiers(expected), pred.to_sql)
|
23
|
+
end
|
24
|
+
|
25
|
+
# def test_and
|
26
|
+
# dep = Arel::Table.new(:departments)
|
27
|
+
#
|
28
|
+
# predicates = Array.new
|
29
|
+
#
|
30
|
+
# 3.times do |i|
|
31
|
+
# predicates << dep[:id].eq(i)
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# connection = ActiveRecord::Base.connection
|
35
|
+
# quoted = "#{connection.quote_table_name('departments')}.#{connection.quote_column_name('id')}"
|
36
|
+
# expected = "#{quoted} = 0 AND #{quoted} = 1 AND #{quoted} = 2"
|
37
|
+
#
|
38
|
+
# pred = cpk_and_predicate(predicates)
|
39
|
+
# assert_equal(with_quoted_identifiers(expected), pred.to_sql)
|
40
|
+
# end
|
41
41
|
end
|