composite_primary_keys 13.0.7 → 14.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.rdoc +894 -910
- data/README.rdoc +182 -181
- data/lib/composite_primary_keys/associations/collection_association.rb +31 -31
- data/lib/composite_primary_keys/associations/{join_association.rb → join_dependency.rb} +137 -137
- data/lib/composite_primary_keys/associations/preloader/association.rb +68 -61
- data/lib/composite_primary_keys/associations/through_association.rb +25 -24
- data/lib/composite_primary_keys/autosave_association.rb +60 -60
- data/lib/composite_primary_keys/base.rb +141 -137
- data/lib/composite_primary_keys/composite_arrays.rb +86 -86
- data/lib/composite_primary_keys/composite_predicates.rb +71 -120
- data/lib/composite_primary_keys/persistence.rb +96 -83
- data/lib/composite_primary_keys/relation/calculations.rb +110 -104
- data/lib/composite_primary_keys/relation.rb +2 -2
- data/lib/composite_primary_keys/validations/uniqueness.rb +31 -31
- data/lib/composite_primary_keys/version.rb +8 -8
- data/lib/composite_primary_keys.rb +118 -118
- data/test/abstract_unit.rb +118 -114
- data/test/fixtures/department.rb +16 -16
- data/test/fixtures/membership.rb +8 -8
- data/test/fixtures/room_assignment.rb +13 -13
- data/test/test_associations.rb +372 -372
- data/test/test_composite_arrays.rb +38 -38
- data/test/test_create.rb +218 -219
- data/test/test_predicates.rb +60 -130
- metadata +7 -7
@@ -1,119 +1,119 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2006-2016 Nic Williams and Charlie Savage
|
3
|
-
#
|
4
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
-
# a copy of this software and associated documentation files (the
|
6
|
-
# "Software"), to deal in the Software without restriction, including
|
7
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
-
# the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be
|
13
|
-
# included in all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
-
#++
|
23
|
-
|
24
|
-
unless defined?(ActiveRecord)
|
25
|
-
require 'rubygems'
|
26
|
-
gem 'activerecord', '~>
|
27
|
-
require 'active_record'
|
28
|
-
end
|
29
|
-
|
30
|
-
# ActiveModel files we override
|
31
|
-
# _write_attribute
|
32
|
-
require 'active_model/attribute_assignment'
|
33
|
-
|
34
|
-
# ActiveRecord files we override
|
35
|
-
require 'active_record/attribute_methods'
|
36
|
-
require 'active_record/autosave_association'
|
37
|
-
require 'active_record/counter_cache'
|
38
|
-
require 'active_record/fixtures'
|
39
|
-
require 'active_record/model_schema'
|
40
|
-
require 'active_record/persistence'
|
41
|
-
require 'active_record/reflection'
|
42
|
-
require 'active_record/relation'
|
43
|
-
require 'active_record/sanitization'
|
44
|
-
require 'active_record/transactions'
|
45
|
-
|
46
|
-
require 'active_record/associations/association'
|
47
|
-
require 'active_record/associations/association_scope'
|
48
|
-
require 'active_record/associations/foreign_association'
|
49
|
-
require 'active_record/associations/has_many_association'
|
50
|
-
require 'active_record/associations/has_many_through_association'
|
51
|
-
require 'active_record/associations/join_dependency'
|
52
|
-
require 'active_record/associations/preloader/association'
|
53
|
-
require 'active_record/associations/singular_association'
|
54
|
-
require 'active_record/associations/collection_association'
|
55
|
-
require 'active_record/associations/through_association'
|
56
|
-
|
57
|
-
require 'active_record/attribute_methods/primary_key'
|
58
|
-
require 'active_record/attribute_methods/read'
|
59
|
-
require 'active_record/attribute_methods/write'
|
60
|
-
require 'active_record/nested_attributes'
|
61
|
-
|
62
|
-
require 'active_record/connection_adapters/abstract/database_statements'
|
63
|
-
require 'active_record/connection_adapters/abstract_adapter'
|
64
|
-
require 'active_record/connection_adapters/postgresql/database_statements'
|
65
|
-
|
66
|
-
require 'active_record/relation/where_clause'
|
67
|
-
require 'active_record/table_metadata'
|
68
|
-
|
69
|
-
# CPK overrides
|
70
|
-
require_relative 'composite_primary_keys/active_model/attribute_assignment'
|
71
|
-
require_relative 'composite_primary_keys/attribute_methods'
|
72
|
-
require_relative 'composite_primary_keys/autosave_association'
|
73
|
-
require_relative 'composite_primary_keys/persistence'
|
74
|
-
require_relative 'composite_primary_keys/base'
|
75
|
-
require_relative 'composite_primary_keys/core'
|
76
|
-
require_relative 'composite_primary_keys/composite_arrays'
|
77
|
-
require_relative 'composite_primary_keys/composite_predicates'
|
78
|
-
require_relative 'composite_primary_keys/counter_cache'
|
79
|
-
require_relative 'composite_primary_keys/fixtures'
|
80
|
-
require_relative 'composite_primary_keys/reflection'
|
81
|
-
require_relative 'composite_primary_keys/relation'
|
82
|
-
require_relative 'composite_primary_keys/sanitization'
|
83
|
-
require_relative 'composite_primary_keys/transactions'
|
84
|
-
require_relative 'composite_primary_keys/version'
|
85
|
-
|
86
|
-
require_relative 'composite_primary_keys/associations/association'
|
87
|
-
require_relative 'composite_primary_keys/associations/association_scope'
|
88
|
-
require_relative 'composite_primary_keys/associations/foreign_association'
|
89
|
-
require_relative 'composite_primary_keys/associations/has_many_association'
|
90
|
-
require_relative 'composite_primary_keys/associations/has_many_through_association'
|
91
|
-
require_relative 'composite_primary_keys/associations/
|
92
|
-
require_relative 'composite_primary_keys/associations/preloader/association'
|
93
|
-
require_relative 'composite_primary_keys/associations/collection_association'
|
94
|
-
require_relative 'composite_primary_keys/associations/through_association'
|
95
|
-
|
96
|
-
require_relative 'composite_primary_keys/attribute_methods/primary_key'
|
97
|
-
require_relative 'composite_primary_keys/attribute_methods/read'
|
98
|
-
require_relative 'composite_primary_keys/attribute_methods/write'
|
99
|
-
require_relative 'composite_primary_keys/nested_attributes'
|
100
|
-
|
101
|
-
require_relative 'composite_primary_keys/connection_adapters/abstract/database_statements'
|
102
|
-
require_relative 'composite_primary_keys/connection_adapters/abstract_adapter'
|
103
|
-
require_relative 'composite_primary_keys/connection_adapters/postgresql/database_statements'
|
104
|
-
require_relative 'composite_primary_keys/connection_adapters/sqlserver/database_statements'
|
105
|
-
|
106
|
-
require_relative 'composite_primary_keys/relation/batches'
|
107
|
-
require_relative 'composite_primary_keys/relation/where_clause'
|
108
|
-
require_relative 'composite_primary_keys/relation/calculations'
|
109
|
-
require_relative 'composite_primary_keys/relation/finder_methods'
|
110
|
-
require_relative 'composite_primary_keys/relation/predicate_builder/association_query_value'
|
111
|
-
require_relative 'composite_primary_keys/relation/query_methods'
|
112
|
-
|
113
|
-
require_relative 'composite_primary_keys/validations/uniqueness'
|
114
|
-
|
115
|
-
require_relative 'composite_primary_keys/composite_relation'
|
116
|
-
|
117
|
-
require_relative 'composite_primary_keys/arel/to_sql'
|
118
|
-
require_relative 'composite_primary_keys/arel/sqlserver'
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2006-2016 Nic Williams and Charlie Savage
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
unless defined?(ActiveRecord)
|
25
|
+
require 'rubygems'
|
26
|
+
gem 'activerecord', '~>7.0.0', '>= 7.0.1'
|
27
|
+
require 'active_record'
|
28
|
+
end
|
29
|
+
|
30
|
+
# ActiveModel files we override
|
31
|
+
# _write_attribute
|
32
|
+
require 'active_model/attribute_assignment'
|
33
|
+
|
34
|
+
# ActiveRecord files we override
|
35
|
+
require 'active_record/attribute_methods'
|
36
|
+
require 'active_record/autosave_association'
|
37
|
+
require 'active_record/counter_cache'
|
38
|
+
require 'active_record/fixtures'
|
39
|
+
require 'active_record/model_schema'
|
40
|
+
require 'active_record/persistence'
|
41
|
+
require 'active_record/reflection'
|
42
|
+
require 'active_record/relation'
|
43
|
+
require 'active_record/sanitization'
|
44
|
+
require 'active_record/transactions'
|
45
|
+
|
46
|
+
require 'active_record/associations/association'
|
47
|
+
require 'active_record/associations/association_scope'
|
48
|
+
require 'active_record/associations/foreign_association'
|
49
|
+
require 'active_record/associations/has_many_association'
|
50
|
+
require 'active_record/associations/has_many_through_association'
|
51
|
+
require 'active_record/associations/join_dependency'
|
52
|
+
require 'active_record/associations/preloader/association'
|
53
|
+
require 'active_record/associations/singular_association'
|
54
|
+
require 'active_record/associations/collection_association'
|
55
|
+
require 'active_record/associations/through_association'
|
56
|
+
|
57
|
+
require 'active_record/attribute_methods/primary_key'
|
58
|
+
require 'active_record/attribute_methods/read'
|
59
|
+
require 'active_record/attribute_methods/write'
|
60
|
+
require 'active_record/nested_attributes'
|
61
|
+
|
62
|
+
require 'active_record/connection_adapters/abstract/database_statements'
|
63
|
+
require 'active_record/connection_adapters/abstract_adapter'
|
64
|
+
require 'active_record/connection_adapters/postgresql/database_statements'
|
65
|
+
|
66
|
+
require 'active_record/relation/where_clause'
|
67
|
+
require 'active_record/table_metadata'
|
68
|
+
|
69
|
+
# CPK overrides
|
70
|
+
require_relative 'composite_primary_keys/active_model/attribute_assignment'
|
71
|
+
require_relative 'composite_primary_keys/attribute_methods'
|
72
|
+
require_relative 'composite_primary_keys/autosave_association'
|
73
|
+
require_relative 'composite_primary_keys/persistence'
|
74
|
+
require_relative 'composite_primary_keys/base'
|
75
|
+
require_relative 'composite_primary_keys/core'
|
76
|
+
require_relative 'composite_primary_keys/composite_arrays'
|
77
|
+
require_relative 'composite_primary_keys/composite_predicates'
|
78
|
+
require_relative 'composite_primary_keys/counter_cache'
|
79
|
+
require_relative 'composite_primary_keys/fixtures'
|
80
|
+
require_relative 'composite_primary_keys/reflection'
|
81
|
+
require_relative 'composite_primary_keys/relation'
|
82
|
+
require_relative 'composite_primary_keys/sanitization'
|
83
|
+
require_relative 'composite_primary_keys/transactions'
|
84
|
+
require_relative 'composite_primary_keys/version'
|
85
|
+
|
86
|
+
require_relative 'composite_primary_keys/associations/association'
|
87
|
+
require_relative 'composite_primary_keys/associations/association_scope'
|
88
|
+
require_relative 'composite_primary_keys/associations/foreign_association'
|
89
|
+
require_relative 'composite_primary_keys/associations/has_many_association'
|
90
|
+
require_relative 'composite_primary_keys/associations/has_many_through_association'
|
91
|
+
require_relative 'composite_primary_keys/associations/join_dependency'
|
92
|
+
require_relative 'composite_primary_keys/associations/preloader/association'
|
93
|
+
require_relative 'composite_primary_keys/associations/collection_association'
|
94
|
+
require_relative 'composite_primary_keys/associations/through_association'
|
95
|
+
|
96
|
+
require_relative 'composite_primary_keys/attribute_methods/primary_key'
|
97
|
+
require_relative 'composite_primary_keys/attribute_methods/read'
|
98
|
+
require_relative 'composite_primary_keys/attribute_methods/write'
|
99
|
+
require_relative 'composite_primary_keys/nested_attributes'
|
100
|
+
|
101
|
+
require_relative 'composite_primary_keys/connection_adapters/abstract/database_statements'
|
102
|
+
require_relative 'composite_primary_keys/connection_adapters/abstract_adapter'
|
103
|
+
require_relative 'composite_primary_keys/connection_adapters/postgresql/database_statements'
|
104
|
+
require_relative 'composite_primary_keys/connection_adapters/sqlserver/database_statements'
|
105
|
+
|
106
|
+
require_relative 'composite_primary_keys/relation/batches'
|
107
|
+
require_relative 'composite_primary_keys/relation/where_clause'
|
108
|
+
require_relative 'composite_primary_keys/relation/calculations'
|
109
|
+
require_relative 'composite_primary_keys/relation/finder_methods'
|
110
|
+
require_relative 'composite_primary_keys/relation/predicate_builder/association_query_value'
|
111
|
+
require_relative 'composite_primary_keys/relation/query_methods'
|
112
|
+
|
113
|
+
require_relative 'composite_primary_keys/validations/uniqueness'
|
114
|
+
|
115
|
+
require_relative 'composite_primary_keys/composite_relation'
|
116
|
+
|
117
|
+
require_relative 'composite_primary_keys/arel/to_sql'
|
118
|
+
require_relative 'composite_primary_keys/arel/sqlserver'
|
119
119
|
require_relative 'composite_primary_keys/table_metadata'
|
data/test/abstract_unit.rb
CHANGED
@@ -1,114 +1,118 @@
|
|
1
|
-
spec_name = ENV['ADAPTER'] || 'postgresql'
|
2
|
-
require 'bundler'
|
3
|
-
require 'minitest/autorun'
|
4
|
-
|
5
|
-
Bundler.setup(:default, spec_name.to_sym)
|
6
|
-
Bundler.require(:default, spec_name.to_sym)
|
7
|
-
require 'composite_primary_keys'
|
8
|
-
|
9
|
-
# Require the connection spec
|
10
|
-
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
11
|
-
require File.join(PROJECT_ROOT, 'test', 'connections', 'connection_spec')
|
12
|
-
|
13
|
-
spec = CompositePrimaryKeys::ConnectionSpec[spec_name]
|
14
|
-
puts "Loaded #{spec_name}"
|
15
|
-
|
16
|
-
# And now connect to the database
|
17
|
-
ActiveRecord::Base.establish_connection(spec)
|
18
|
-
|
19
|
-
# Tell active record about the configuration
|
20
|
-
ActiveRecord::Base.configurations = {test: spec}
|
21
|
-
|
22
|
-
# Tell ActiveRecord where to find models
|
23
|
-
ActiveSupport::Dependencies.autoload_paths << File.join(PROJECT_ROOT, 'test', 'fixtures')
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
assert_equal expected.
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
@
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
ActiveRecord::
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
1
|
+
spec_name = ENV['ADAPTER'] || 'postgresql'
|
2
|
+
require 'bundler'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
Bundler.setup(:default, spec_name.to_sym)
|
6
|
+
Bundler.require(:default, spec_name.to_sym)
|
7
|
+
require 'composite_primary_keys'
|
8
|
+
|
9
|
+
# Require the connection spec
|
10
|
+
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
11
|
+
require File.join(PROJECT_ROOT, 'test', 'connections', 'connection_spec')
|
12
|
+
|
13
|
+
spec = CompositePrimaryKeys::ConnectionSpec[spec_name]
|
14
|
+
puts "Loaded #{spec_name}"
|
15
|
+
|
16
|
+
# And now connect to the database
|
17
|
+
ActiveRecord::Base.establish_connection(spec)
|
18
|
+
|
19
|
+
# Tell active record about the configuration
|
20
|
+
ActiveRecord::Base.configurations = {test: spec}
|
21
|
+
|
22
|
+
# Tell ActiveRecord where to find models
|
23
|
+
ActiveSupport::Dependencies.autoload_paths << File.join(PROJECT_ROOT, 'test', 'fixtures')
|
24
|
+
Dir[File.join(PROJECT_ROOT, 'test', 'fixtures', '*.rb')].each do |file_path|
|
25
|
+
require_file = file_path.sub(PROJECT_ROOT, '..').sub('.rb', '')
|
26
|
+
require_relative require_file
|
27
|
+
end
|
28
|
+
|
29
|
+
I18n.config.enforce_available_locales = true
|
30
|
+
|
31
|
+
class ActiveSupport::TestCase
|
32
|
+
include ActiveRecord::TestFixtures
|
33
|
+
|
34
|
+
self.fixture_path = File.dirname(__FILE__) + '/fixtures/'
|
35
|
+
self.use_instantiated_fixtures = false
|
36
|
+
self.use_transactional_tests = true
|
37
|
+
self.test_order = :random
|
38
|
+
|
39
|
+
def assert_date_from_db(expected, actual, message = nil)
|
40
|
+
# SQL Server doesn't have a separate column type just for dates,
|
41
|
+
# so the time is in the string and incorrectly formatted
|
42
|
+
if current_adapter?(:SQLServerAdapter)
|
43
|
+
assert_equal expected.strftime('%Y/%m/%d 00:00:00'), actual.strftime('%Y/%m/%d 00:00:00')
|
44
|
+
elsif current_adapter?(:SybaseAdapter)
|
45
|
+
assert_equal expected.to_s, actual.to_date.to_s, message
|
46
|
+
else
|
47
|
+
assert_equal expected.to_s, actual.to_s, message
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def assert_queries(num = 1)
|
52
|
+
ActiveRecord::Base.connection.class.class_eval do
|
53
|
+
self.query_count = 0
|
54
|
+
alias_method :execute, :execute_with_query_counting
|
55
|
+
end
|
56
|
+
yield
|
57
|
+
ensure
|
58
|
+
ActiveRecord::Base.connection.class.class_eval do
|
59
|
+
alias_method :execute, :execute_without_query_counting
|
60
|
+
end
|
61
|
+
assert_equal num, ActiveRecord::Base.connection.query_count, '#{ActiveRecord::Base.connection.query_count} instead of #{num} queries were executed.'
|
62
|
+
end
|
63
|
+
|
64
|
+
def assert_no_queries(&block)
|
65
|
+
assert_queries(0, &block)
|
66
|
+
end
|
67
|
+
|
68
|
+
cattr_accessor :classes
|
69
|
+
|
70
|
+
protected
|
71
|
+
|
72
|
+
def testing_with(&block)
|
73
|
+
classes.keys.each do |key_test|
|
74
|
+
@key_test = key_test
|
75
|
+
@klass_info = classes[@key_test]
|
76
|
+
@klass, @primary_keys = @klass_info[:class], @klass_info[:primary_keys]
|
77
|
+
order = @klass.primary_key.is_a?(String) ? @klass.primary_key : @klass.primary_key.join(',')
|
78
|
+
@first = @klass.order(order).first
|
79
|
+
yield
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def first_id
|
84
|
+
ids = (1..@primary_keys.length).map {|num| 1}
|
85
|
+
composite? ? ids.to_composite_ids : ids.first
|
86
|
+
end
|
87
|
+
|
88
|
+
def composite?
|
89
|
+
@key_test != :single
|
90
|
+
end
|
91
|
+
|
92
|
+
# Oracle metadata is in all caps.
|
93
|
+
def with_quoted_identifiers(s)
|
94
|
+
s.gsub(/'(\w+)'/) { |m|
|
95
|
+
if ActiveRecord::Base.configurations[:test]['adapter'] =~ /oracle/i
|
96
|
+
m.upcase
|
97
|
+
else
|
98
|
+
m
|
99
|
+
end
|
100
|
+
}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def current_adapter?(type)
|
105
|
+
ActiveRecord::ConnectionAdapters.const_defined?(type) &&
|
106
|
+
ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters.const_get(type))
|
107
|
+
end
|
108
|
+
|
109
|
+
ActiveRecord::Base.connection.class.class_eval do
|
110
|
+
cattr_accessor :query_count
|
111
|
+
alias_method :execute_without_query_counting, :execute
|
112
|
+
def execute_with_query_counting(sql, name = nil)
|
113
|
+
self.query_count += 1
|
114
|
+
execute_without_query_counting(sql, name)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
ActiveRecord::Base.logger = Logger.new(ENV['CPK_LOGFILE'] || STDOUT)
|
data/test/fixtures/department.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
class Department < ActiveRecord::Base
|
2
|
-
self.primary_keys = :id, :location_id
|
3
|
-
|
4
|
-
has_many :employees,
|
5
|
-
# We intentionally redefine primary key for test purposes. #455
|
6
|
-
:primary_key => [:id, :location_id],
|
7
|
-
:foreign_key => [:department_id, :location_id]
|
8
|
-
|
9
|
-
has_many :comments, :through => :employees
|
10
|
-
|
11
|
-
has_one :head, :class_name => 'Employee', :autosave => true, :dependent => :delete,
|
12
|
-
# We intentionally redefine primary key for test purposes. #455
|
13
|
-
:primary_key => [:id, :location_id],
|
14
|
-
:foreign_key => [:department_id, :location_id]
|
15
|
-
|
16
|
-
end
|
1
|
+
class Department < ActiveRecord::Base
|
2
|
+
self.primary_keys = :id, :location_id
|
3
|
+
|
4
|
+
has_many :employees,
|
5
|
+
# We intentionally redefine primary key for test purposes. #455
|
6
|
+
:primary_key => [:id, :location_id],
|
7
|
+
:foreign_key => [:department_id, :location_id]
|
8
|
+
|
9
|
+
has_many :comments, :through => :employees
|
10
|
+
|
11
|
+
has_one :head, :class_name => 'Employee', :autosave => true, :dependent => :delete,
|
12
|
+
# We intentionally redefine primary key for test purposes. #455
|
13
|
+
:primary_key => [:id, :location_id],
|
14
|
+
:foreign_key => [:department_id, :location_id]
|
15
|
+
|
16
|
+
end
|
data/test/fixtures/membership.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
class Membership < ActiveRecord::Base
|
2
|
-
self.primary_keys = :user_id, :group_id
|
3
|
-
belongs_to :user
|
4
|
-
belongs_to :group
|
5
|
-
has_many :statuses, :class_name => 'MembershipStatus', :foreign_key => [:user_id, :group_id]
|
6
|
-
has_many :active_statuses, -> { where('membership_statuses.status = ?', 'Active') },
|
7
|
-
:class_name => 'MembershipStatus', :foreign_key => [:user_id, :group_id]
|
8
|
-
has_many :readings, :primary_key => :user_id, :foreign_key => :user_id
|
1
|
+
class Membership < ActiveRecord::Base
|
2
|
+
self.primary_keys = :user_id, :group_id
|
3
|
+
belongs_to :user
|
4
|
+
belongs_to :group
|
5
|
+
has_many :statuses, :class_name => 'MembershipStatus', :foreign_key => [:user_id, :group_id]
|
6
|
+
has_many :active_statuses, -> { where('membership_statuses.status = ?', 'Active') },
|
7
|
+
:class_name => 'MembershipStatus', :foreign_key => [:user_id, :group_id]
|
8
|
+
has_many :readings, :primary_key => :user_id, :foreign_key => :user_id
|
9
9
|
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
class RoomAssignment < ActiveRecord::Base
|
2
|
-
self.primary_keys = :student_id, :dorm_id, :room_id
|
3
|
-
belongs_to :student
|
4
|
-
belongs_to :room, :foreign_key => [:dorm_id, :room_id], :primary_key => [:dorm_id, :room_id]
|
5
|
-
validates_uniqueness_of :student_id
|
6
|
-
|
7
|
-
before_destroy do |record|
|
8
|
-
puts record
|
9
|
-
end
|
10
|
-
|
11
|
-
after_destroy do |record|
|
12
|
-
puts record
|
13
|
-
end
|
1
|
+
class RoomAssignment < ActiveRecord::Base
|
2
|
+
self.primary_keys = :student_id, :dorm_id, :room_id
|
3
|
+
belongs_to :student
|
4
|
+
belongs_to :room, :foreign_key => [:dorm_id, :room_id], :primary_key => [:dorm_id, :room_id]
|
5
|
+
validates_uniqueness_of :student_id
|
6
|
+
|
7
|
+
before_destroy do |record|
|
8
|
+
puts record
|
9
|
+
end
|
10
|
+
|
11
|
+
after_destroy do |record|
|
12
|
+
puts record
|
13
|
+
end
|
14
14
|
end
|