composite_primary_keys 14.0.9 → 14.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.rdoc +10 -0
- data/README.rdoc +182 -182
- data/Rakefile +37 -37
- data/lib/composite_primary_keys/associations/collection_association.rb +38 -38
- data/lib/composite_primary_keys/associations/preloader/association.rb +52 -52
- data/lib/composite_primary_keys/autosave_association.rb +60 -60
- data/lib/composite_primary_keys/composite_arrays.rb +88 -88
- data/lib/composite_primary_keys/composite_predicates.rb +121 -121
- data/lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb +36 -36
- data/lib/composite_primary_keys/core.rb +71 -48
- data/lib/composite_primary_keys/persistence.rb +96 -96
- data/lib/composite_primary_keys/reflection.rb +93 -91
- data/lib/composite_primary_keys/relation/calculations.rb +110 -110
- data/lib/composite_primary_keys/relation/query_methods.rb +40 -40
- data/lib/composite_primary_keys/relation.rb +199 -199
- data/lib/composite_primary_keys/validations/uniqueness.rb +40 -40
- data/lib/composite_primary_keys/version.rb +1 -1
- data/lib/composite_primary_keys.rb +117 -117
- data/scripts/console.rb +48 -48
- data/tasks/databases/trilogy.rake +23 -23
- data/test/abstract_unit.rb +124 -124
- data/test/connections/databases.ci.yml +32 -32
- data/test/fixtures/admin.rb +4 -4
- data/test/fixtures/db_definitions/db2-create-tables.sql +146 -146
- data/test/fixtures/db_definitions/db2-drop-tables.sql +23 -23
- data/test/fixtures/db_definitions/mysql.sql +203 -203
- data/test/fixtures/db_definitions/oracle.drop.sql +45 -45
- data/test/fixtures/db_definitions/oracle.sql +220 -220
- data/test/fixtures/db_definitions/postgresql.sql +205 -205
- data/test/fixtures/db_definitions/sqlite.sql +190 -190
- data/test/fixtures/db_definitions/sqlserver.sql +199 -199
- data/test/fixtures/department.rb +20 -20
- data/test/fixtures/moderator.rb +4 -4
- data/test/fixtures/room.rb +14 -14
- data/test/fixtures/room_assignment.rb +18 -18
- data/test/fixtures/staff_room.rb +6 -6
- data/test/fixtures/staff_room_key.rb +6 -6
- data/test/fixtures/user.rb +14 -14
- data/test/test_associations.rb +403 -403
- data/test/test_composite_arrays.rb +44 -44
- data/test/test_equal.rb +55 -26
- data/test/test_has_one_through.rb +30 -30
- data/test/test_hash.rb +73 -0
- data/test/test_nested_attributes.rb +90 -90
- metadata +7 -8
@@ -1,44 +1,44 @@
|
|
1
|
-
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
-
|
3
|
-
class CompositeArraysTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
def test_new_primary_keys
|
6
|
-
keys = CompositePrimaryKeys::CompositeKeys.new
|
7
|
-
assert_not_nil keys
|
8
|
-
assert_equal '', keys.to_s
|
9
|
-
assert_equal '', "#{keys}"
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_initialize_primary_keys
|
13
|
-
keys = CompositePrimaryKeys::CompositeKeys.new([1,2,3])
|
14
|
-
assert_not_nil keys
|
15
|
-
assert_equal '1,2,3', keys.to_s
|
16
|
-
assert_equal '1,2,3', "#{keys}"
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_to_composite_keys
|
20
|
-
keys = [1,2,3].to_composite_keys
|
21
|
-
assert_equal CompositePrimaryKeys::CompositeKeys, keys.class
|
22
|
-
assert_equal '1,2,3', keys.to_s
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_parse
|
26
|
-
assert_equal ['1', '2'], CompositePrimaryKeys::CompositeKeys.parse('1,2')
|
27
|
-
assert_equal ['The USA', '^Washington, D.C.'],
|
28
|
-
CompositePrimaryKeys::CompositeKeys.parse('The USA,^5EWashington^2C D.C.')
|
29
|
-
assert_equal ['The USA', '^Washington, D.C.'],
|
30
|
-
CompositePrimaryKeys::CompositeKeys.parse(['The USA', '^Washington, D.C.'])
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_to_s
|
34
|
-
assert_equal '1,2', CompositePrimaryKeys::CompositeKeys.new([1, 2]).to_s
|
35
|
-
assert_equal 'The USA,^5EWashington^2C D.C.',
|
36
|
-
CompositePrimaryKeys::CompositeKeys.new(['The USA', '^Washington, D.C.']).to_s
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_to_param
|
40
|
-
assert_equal '1,2', CompositePrimaryKeys::CompositeKeys.new([1, 2]).to_param
|
41
|
-
assert_equal 'The USA,^5EWashington^2C D.C.',
|
42
|
-
CompositePrimaryKeys::CompositeKeys.new(['The USA', '^Washington, D.C.']).to_param
|
43
|
-
end
|
44
|
-
end
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
+
|
3
|
+
class CompositeArraysTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def test_new_primary_keys
|
6
|
+
keys = CompositePrimaryKeys::CompositeKeys.new
|
7
|
+
assert_not_nil keys
|
8
|
+
assert_equal '', keys.to_s
|
9
|
+
assert_equal '', "#{keys}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_initialize_primary_keys
|
13
|
+
keys = CompositePrimaryKeys::CompositeKeys.new([1,2,3])
|
14
|
+
assert_not_nil keys
|
15
|
+
assert_equal '1,2,3', keys.to_s
|
16
|
+
assert_equal '1,2,3', "#{keys}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_to_composite_keys
|
20
|
+
keys = [1,2,3].to_composite_keys
|
21
|
+
assert_equal CompositePrimaryKeys::CompositeKeys, keys.class
|
22
|
+
assert_equal '1,2,3', keys.to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_parse
|
26
|
+
assert_equal ['1', '2'], CompositePrimaryKeys::CompositeKeys.parse('1,2')
|
27
|
+
assert_equal ['The USA', '^Washington, D.C.'],
|
28
|
+
CompositePrimaryKeys::CompositeKeys.parse('The USA,^5EWashington^2C D.C.')
|
29
|
+
assert_equal ['The USA', '^Washington, D.C.'],
|
30
|
+
CompositePrimaryKeys::CompositeKeys.parse(['The USA', '^Washington, D.C.'])
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_to_s
|
34
|
+
assert_equal '1,2', CompositePrimaryKeys::CompositeKeys.new([1, 2]).to_s
|
35
|
+
assert_equal 'The USA,^5EWashington^2C D.C.',
|
36
|
+
CompositePrimaryKeys::CompositeKeys.new(['The USA', '^Washington, D.C.']).to_s
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_to_param
|
40
|
+
assert_equal '1,2', CompositePrimaryKeys::CompositeKeys.new([1, 2]).to_param
|
41
|
+
assert_equal 'The USA,^5EWashington^2C D.C.',
|
42
|
+
CompositePrimaryKeys::CompositeKeys.new(['The USA', '^Washington, D.C.']).to_param
|
43
|
+
end
|
44
|
+
end
|
data/test/test_equal.rb
CHANGED
@@ -1,26 +1,55 @@
|
|
1
|
-
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
-
|
3
|
-
class TestEqual < ActiveSupport::TestCase
|
4
|
-
fixtures :
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
+
|
3
|
+
class TestEqual < ActiveSupport::TestCase
|
4
|
+
fixtures :restaurants, :products
|
5
|
+
|
6
|
+
############################################################
|
7
|
+
### Tests for Product model with single primary key (id) ###
|
8
|
+
############################################################
|
9
|
+
|
10
|
+
def test_single_same
|
11
|
+
first = Product.find(1)
|
12
|
+
second = Product.find(1)
|
13
|
+
assert_equal(first, second)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_different
|
17
|
+
first = Product.find(1)
|
18
|
+
second = Product.find(2)
|
19
|
+
assert_not_equal(first, second)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_two_new_objects_are_not_equal
|
23
|
+
assert_not_equal(Product.new, Product.new)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_same_new_object_is_equal_to_itself
|
27
|
+
it = Product.new
|
28
|
+
assert_equal(it, it)
|
29
|
+
end
|
30
|
+
|
31
|
+
#####################################################################################
|
32
|
+
### Tests for Restaurant model with composite primary key (franchise_id, store_id) ##
|
33
|
+
#####################################################################################
|
34
|
+
|
35
|
+
def test_composite_same
|
36
|
+
first = Restaurant.find([1, 1])
|
37
|
+
second = Restaurant.find([1, 1])
|
38
|
+
assert_equal(first, second)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_composite_different
|
42
|
+
first = Restaurant.find([1, 1])
|
43
|
+
second = Restaurant.find([2, 2])
|
44
|
+
assert_not_equal(first, second)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_composite_two_new_objects_are_not_equal
|
48
|
+
assert_not_equal(Restaurant.new, Restaurant.new)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_composite_same_new_object_is_equal_to_itself
|
52
|
+
it = Restaurant.new
|
53
|
+
assert_equal(it, it)
|
54
|
+
end
|
55
|
+
end
|
@@ -1,30 +1,30 @@
|
|
1
|
-
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
-
|
3
|
-
class TestHasOneThrough < ActiveSupport::TestCase
|
4
|
-
fixtures :users, :rooms
|
5
|
-
|
6
|
-
def test_no_cpk
|
7
|
-
# This test makes sure we don't break anything in standard rails by using CPK
|
8
|
-
user = User.find(1)
|
9
|
-
assert_nil user.moderator
|
10
|
-
assert_nil user.admin
|
11
|
-
|
12
|
-
admin = Admin.create!(user: user)
|
13
|
-
assert_equal admin, user.admin
|
14
|
-
assert_equal 1, user.moderator.id
|
15
|
-
assert_equal 1, admin.id
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_has_one_through
|
19
|
-
room = Room.find([1,1])
|
20
|
-
assert_nil room.staff_room
|
21
|
-
assert_nil room.staff_room_key
|
22
|
-
|
23
|
-
key = StaffRoomKey.create!(room: room, key_no: '1234')
|
24
|
-
assert_equal key, room.staff_room_key
|
25
|
-
assert_equal 1, room.staff_room.dorm_id
|
26
|
-
assert_equal 1, room.staff_room.room_id
|
27
|
-
assert_equal 1, key.dorm_id
|
28
|
-
assert_equal 1, key.room_id
|
29
|
-
end
|
30
|
-
end
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
+
|
3
|
+
class TestHasOneThrough < ActiveSupport::TestCase
|
4
|
+
fixtures :users, :rooms
|
5
|
+
|
6
|
+
def test_no_cpk
|
7
|
+
# This test makes sure we don't break anything in standard rails by using CPK
|
8
|
+
user = User.find(1)
|
9
|
+
assert_nil user.moderator
|
10
|
+
assert_nil user.admin
|
11
|
+
|
12
|
+
admin = Admin.create!(user: user)
|
13
|
+
assert_equal admin, user.admin
|
14
|
+
assert_equal 1, user.moderator.id
|
15
|
+
assert_equal 1, admin.id
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_has_one_through
|
19
|
+
room = Room.find([1,1])
|
20
|
+
assert_nil room.staff_room
|
21
|
+
assert_nil room.staff_room_key
|
22
|
+
|
23
|
+
key = StaffRoomKey.create!(room: room, key_no: '1234')
|
24
|
+
assert_equal key, room.staff_room_key
|
25
|
+
assert_equal 1, room.staff_room.dorm_id
|
26
|
+
assert_equal 1, room.staff_room.room_id
|
27
|
+
assert_equal 1, key.dorm_id
|
28
|
+
assert_equal 1, key.room_id
|
29
|
+
end
|
30
|
+
end
|
data/test/test_hash.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
+
|
3
|
+
class TestHash < ActiveSupport::TestCase
|
4
|
+
fixtures :restaurants, :products
|
5
|
+
|
6
|
+
############################################################
|
7
|
+
### Tests for Product model with single primary key (id) ###
|
8
|
+
############################################################
|
9
|
+
|
10
|
+
def test_single_same_object_has_the_same_hash
|
11
|
+
first = Product.find(1)
|
12
|
+
second = Product.find(1)
|
13
|
+
assert_equal(first.hash, second.hash)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_single_different_objects_have_different_hashes
|
17
|
+
first = Product.find(1)
|
18
|
+
second = Product.find(2)
|
19
|
+
assert_not_equal(first.hash, second.hash)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_single_persisted_object_hash_is_based_on_primary_key
|
23
|
+
first = Product.find(1)
|
24
|
+
second = Product.find(1)
|
25
|
+
|
26
|
+
assert_equal(first.hash, second.hash)
|
27
|
+
first.name = 'new name'
|
28
|
+
assert_equal(first.hash, second.hash)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_single_two_new_objects_have_different_hashes
|
32
|
+
assert_not_equal(Product.new.hash, Product.new.hash)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_single_same_new_object_has_the_same_hash
|
36
|
+
it = Product.new
|
37
|
+
assert_equal(it.hash, it.hash)
|
38
|
+
end
|
39
|
+
|
40
|
+
#####################################################################################
|
41
|
+
### Tests for Restaurant model with composite primary key (franchise_id, store_id) ##
|
42
|
+
#####################################################################################
|
43
|
+
|
44
|
+
def test_composite_same_object_has_the_same_hash
|
45
|
+
first = Restaurant.find([1, 1])
|
46
|
+
second = Restaurant.find([1, 1])
|
47
|
+
assert_equal(first.hash, second.hash)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_composite_different_objects_have_different_hashes
|
51
|
+
first = Restaurant.find([1, 1])
|
52
|
+
second = Restaurant.find([2, 2])
|
53
|
+
assert_not_equal(first.hash, second.hash)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_composite_persisted_object_hash_is_based_on_primary_key
|
57
|
+
first = Restaurant.find([1, 1])
|
58
|
+
second = Restaurant.find([1, 1])
|
59
|
+
|
60
|
+
assert_equal(first.hash, second.hash)
|
61
|
+
first.name = 'new name'
|
62
|
+
assert_equal(first.hash, second.hash)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_composite_two_new_objects_have_different_hashes
|
66
|
+
assert_not_equal(Restaurant.new.hash, Restaurant.new.hash)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_composite_same_new_object_has_the_same_hash
|
70
|
+
it = Restaurant.new
|
71
|
+
assert_equal(it.hash, it.hash)
|
72
|
+
end
|
73
|
+
end
|
@@ -1,90 +1,90 @@
|
|
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 :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 :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 :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(: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(: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
|
-
def test_nested_atttribute_update_4
|
69
|
-
code_id = 1003
|
70
|
-
|
71
|
-
reference_type = reference_types(:name_prefix)
|
72
|
-
reference_type.update :reference_codes_attributes => [{
|
73
|
-
:reference_code => code_id,
|
74
|
-
:code_label => 'XX',
|
75
|
-
:abbreviation => 'Xx'
|
76
|
-
}]
|
77
|
-
assert_not_nil ReferenceCode.find_by_reference_code(code_id)
|
78
|
-
reference_code = ReferenceCode.find_by_reference_code(code_id)
|
79
|
-
# directly pass :id as a array
|
80
|
-
reference_type.update :reference_codes_attributes => [{
|
81
|
-
:id => [reference_type.reference_type_id, code_id],
|
82
|
-
:code_label => 'AAA',
|
83
|
-
:abbreviation => 'Aaa'
|
84
|
-
}]
|
85
|
-
|
86
|
-
reference_code = ReferenceCode.find_by_reference_code(code_id)
|
87
|
-
assert_kind_of(ReferenceCode, reference_code)
|
88
|
-
assert_equal(reference_code.code_label, 'AAA')
|
89
|
-
end
|
90
|
-
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 :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 :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 :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(: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(: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
|
+
def test_nested_atttribute_update_4
|
69
|
+
code_id = 1003
|
70
|
+
|
71
|
+
reference_type = reference_types(:name_prefix)
|
72
|
+
reference_type.update :reference_codes_attributes => [{
|
73
|
+
:reference_code => code_id,
|
74
|
+
:code_label => 'XX',
|
75
|
+
:abbreviation => 'Xx'
|
76
|
+
}]
|
77
|
+
assert_not_nil ReferenceCode.find_by_reference_code(code_id)
|
78
|
+
reference_code = ReferenceCode.find_by_reference_code(code_id)
|
79
|
+
# directly pass :id as a array
|
80
|
+
reference_type.update :reference_codes_attributes => [{
|
81
|
+
:id => [reference_type.reference_type_id, code_id],
|
82
|
+
:code_label => 'AAA',
|
83
|
+
:abbreviation => 'Aaa'
|
84
|
+
}]
|
85
|
+
|
86
|
+
reference_code = ReferenceCode.find_by_reference_code(code_id)
|
87
|
+
assert_kind_of(ReferenceCode, reference_code)
|
88
|
+
assert_equal(reference_code.code_label, 'AAA')
|
89
|
+
end
|
90
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: composite_primary_keys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 14.0.
|
4
|
+
version: 14.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charlie Savage
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2024-12-19 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: activerecord
|
@@ -39,7 +38,6 @@ dependencies:
|
|
39
38
|
- !ruby/object:Gem::Version
|
40
39
|
version: '0'
|
41
40
|
description: Composite key support for ActiveRecord
|
42
|
-
email:
|
43
41
|
executables: []
|
44
42
|
extensions: []
|
45
43
|
extra_rdoc_files: []
|
@@ -189,6 +187,7 @@ files:
|
|
189
187
|
- test/test_find.rb
|
190
188
|
- test/test_habtm.rb
|
191
189
|
- test/test_has_one_through.rb
|
190
|
+
- test/test_hash.rb
|
192
191
|
- test/test_ids.rb
|
193
192
|
- test/test_miscellaneous.rb
|
194
193
|
- test/test_nested_attributes.rb
|
@@ -206,8 +205,8 @@ files:
|
|
206
205
|
homepage: https://github.com/composite-primary-keys/composite_primary_keys
|
207
206
|
licenses:
|
208
207
|
- MIT
|
209
|
-
metadata:
|
210
|
-
|
208
|
+
metadata:
|
209
|
+
changelog_uri: https://github.com/composite-primary-keys/composite_primary_keys/blob/master/History.rdoc
|
211
210
|
rdoc_options: []
|
212
211
|
require_paths:
|
213
212
|
- lib
|
@@ -222,8 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
221
|
- !ruby/object:Gem::Version
|
223
222
|
version: '0'
|
224
223
|
requirements: []
|
225
|
-
rubygems_version: 3.
|
226
|
-
signing_key:
|
224
|
+
rubygems_version: 3.6.1
|
227
225
|
specification_version: 4
|
228
226
|
summary: Composite key support for ActiveRecord
|
229
227
|
test_files:
|
@@ -245,6 +243,7 @@ test_files:
|
|
245
243
|
- test/test_find.rb
|
246
244
|
- test/test_habtm.rb
|
247
245
|
- test/test_has_one_through.rb
|
246
|
+
- test/test_hash.rb
|
248
247
|
- test/test_ids.rb
|
249
248
|
- test/test_miscellaneous.rb
|
250
249
|
- test/test_nested_attributes.rb
|