composite_primary_keys 12.0.9 → 14.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.rdoc +894 -877
- data/README.rdoc +182 -180
- data/Rakefile +37 -37
- data/lib/composite_primary_keys/active_model/attribute_assignment.rb +19 -19
- data/lib/composite_primary_keys/arel/sqlserver.rb +37 -37
- data/lib/composite_primary_keys/arel/to_sql.rb +18 -18
- data/lib/composite_primary_keys/associations/association.rb +23 -23
- data/lib/composite_primary_keys/associations/association_scope.rb +66 -68
- data/lib/composite_primary_keys/associations/collection_association.rb +31 -31
- data/lib/composite_primary_keys/associations/foreign_association.rb +15 -15
- data/lib/composite_primary_keys/associations/has_many_association.rb +35 -35
- data/lib/composite_primary_keys/associations/join_dependency.rb +137 -103
- data/lib/composite_primary_keys/associations/preloader/association.rb +68 -53
- data/lib/composite_primary_keys/associations/through_association.rb +25 -25
- data/lib/composite_primary_keys/attribute_methods/primary_key.rb +0 -2
- data/lib/composite_primary_keys/attribute_methods/read.rb +30 -30
- data/lib/composite_primary_keys/attribute_methods/write.rb +35 -35
- data/lib/composite_primary_keys/attribute_methods.rb +21 -9
- data/lib/composite_primary_keys/autosave_association.rb +60 -60
- data/lib/composite_primary_keys/base.rb +141 -141
- data/lib/composite_primary_keys/composite_arrays.rb +86 -86
- data/lib/composite_primary_keys/composite_predicates.rb +71 -69
- data/lib/composite_primary_keys/composite_relation.rb +29 -29
- data/lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb +37 -37
- data/lib/composite_primary_keys/connection_adapters/abstract_adapter.rb +10 -10
- data/lib/composite_primary_keys/connection_adapters/postgresql/database_statements.rb +26 -26
- data/lib/composite_primary_keys/connection_adapters/sqlserver/database_statements.rb +44 -44
- data/lib/composite_primary_keys/core.rb +48 -48
- data/lib/composite_primary_keys/counter_cache.rb +15 -15
- data/lib/composite_primary_keys/fixtures.rb +21 -21
- data/lib/composite_primary_keys/nested_attributes.rb +1 -1
- data/lib/composite_primary_keys/persistence.rb +96 -81
- data/lib/composite_primary_keys/reflection.rb +91 -29
- data/lib/composite_primary_keys/relation/batches.rb +15 -7
- data/lib/composite_primary_keys/relation/calculations.rb +110 -81
- data/lib/composite_primary_keys/relation/finder_methods.rb +235 -235
- data/lib/composite_primary_keys/relation/predicate_builder/association_query_value.rb +39 -20
- data/lib/composite_primary_keys/relation/query_methods.rb +42 -42
- data/lib/composite_primary_keys/relation/where_clause.rb +18 -23
- data/lib/composite_primary_keys/relation.rb +197 -193
- data/lib/composite_primary_keys/sanitization.rb +42 -42
- data/lib/composite_primary_keys/table_metadata.rb +11 -0
- data/lib/composite_primary_keys/transactions.rb +34 -34
- 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 +119 -117
- data/scripts/console.rb +48 -48
- data/scripts/txt2html +76 -76
- data/scripts/txt2js +65 -65
- data/tasks/databases/mysql.rake +40 -40
- data/tasks/databases/oracle.rake +41 -41
- data/tasks/databases/postgresql.rake +38 -38
- data/tasks/databases/sqlite.rake +25 -25
- data/tasks/databases/sqlserver.rake +43 -43
- data/tasks/website.rake +18 -18
- data/test/README_tests.rdoc +56 -56
- data/test/abstract_unit.rb +118 -114
- data/test/connections/connection_spec.rb +27 -27
- data/test/connections/databases.ci.yml +22 -22
- data/test/connections/databases.example.yml +40 -40
- data/test/connections/databases.yml +40 -39
- data/test/fixtures/article.rb +10 -10
- data/test/fixtures/articles.yml +7 -7
- data/test/fixtures/capitol.rb +3 -3
- data/test/fixtures/capitols.yml +16 -16
- data/test/fixtures/comment.rb +5 -5
- data/test/fixtures/comments.yml +17 -17
- data/test/fixtures/db_definitions/db2-create-tables.sql +112 -112
- data/test/fixtures/db_definitions/db2-drop-tables.sql +16 -16
- data/test/fixtures/db_definitions/mysql.sql +180 -180
- data/test/fixtures/db_definitions/oracle.drop.sql +41 -41
- data/test/fixtures/db_definitions/oracle.sql +199 -199
- data/test/fixtures/db_definitions/postgresql.sql +182 -182
- data/test/fixtures/db_definitions/sqlite.sql +169 -169
- data/test/fixtures/db_definitions/sqlserver.sql +176 -176
- data/test/fixtures/department.rb +16 -16
- data/test/fixtures/departments.yml +19 -15
- data/test/fixtures/dorm.rb +2 -2
- data/test/fixtures/dorms.yml +4 -4
- data/test/fixtures/employee.rb +5 -5
- data/test/fixtures/employees.yml +33 -28
- data/test/fixtures/group.rb +2 -2
- data/test/fixtures/groups.yml +6 -6
- data/test/fixtures/membership.rb +8 -6
- data/test/fixtures/membership_status.rb +2 -2
- data/test/fixtures/membership_statuses.yml +16 -16
- data/test/fixtures/memberships.yml +10 -10
- data/test/fixtures/product.rb +9 -9
- data/test/fixtures/product_tariff.rb +5 -5
- data/test/fixtures/product_tariffs.yml +14 -14
- data/test/fixtures/products.yml +11 -11
- data/test/fixtures/reading.rb +4 -4
- data/test/fixtures/readings.yml +10 -10
- data/test/fixtures/reference_code.rb +7 -7
- data/test/fixtures/reference_codes.yml +28 -28
- data/test/fixtures/reference_type.rb +12 -12
- data/test/fixtures/reference_types.yml +9 -9
- data/test/fixtures/restaurant.rb +9 -9
- data/test/fixtures/restaurants.yml +14 -14
- data/test/fixtures/restaurants_suburb.rb +2 -2
- data/test/fixtures/restaurants_suburbs.yml +10 -10
- data/test/fixtures/room.rb +11 -11
- data/test/fixtures/room_assignment.rb +13 -13
- data/test/fixtures/room_assignments.yml +24 -24
- data/test/fixtures/room_attribute.rb +2 -2
- data/test/fixtures/room_attribute_assignment.rb +4 -4
- data/test/fixtures/room_attribute_assignments.yml +4 -4
- data/test/fixtures/room_attributes.yml +2 -2
- data/test/fixtures/rooms.yml +12 -12
- data/test/fixtures/street.rb +2 -2
- data/test/fixtures/streets.yml +16 -16
- data/test/fixtures/student.rb +3 -3
- data/test/fixtures/students.yml +15 -15
- data/test/fixtures/suburb.rb +5 -5
- data/test/fixtures/suburbs.yml +14 -14
- data/test/fixtures/tariff.rb +5 -5
- data/test/fixtures/tariffs.yml +14 -14
- data/test/fixtures/topic_sources.yml +3 -3
- data/test/fixtures/topics.yml +8 -8
- data/test/fixtures/user.rb +11 -11
- data/test/fixtures/users.yml +10 -10
- data/test/plugins/pagination.rb +405 -405
- data/test/plugins/pagination_helper.rb +135 -135
- data/test/test_associations.rb +372 -358
- data/test/test_attribute_methods.rb +63 -63
- data/test/test_attributes.rb +75 -60
- data/test/test_calculations.rb +49 -42
- data/test/test_callbacks.rb +99 -99
- data/test/test_composite_arrays.rb +38 -38
- data/test/test_counter_cache.rb +30 -30
- data/test/test_create.rb +218 -206
- data/test/test_delete.rb +188 -179
- data/test/test_dumpable.rb +15 -15
- data/test/test_dup.rb +37 -37
- data/test/test_equal.rb +26 -26
- data/test/test_exists.rb +39 -39
- data/test/test_find.rb +170 -164
- data/test/test_habtm.rb +141 -141
- data/test/test_ids.rb +112 -112
- data/test/test_miscellaneous.rb +32 -32
- data/test/test_nested_attributes.rb +67 -67
- data/test/test_optimistic.rb +18 -18
- data/test/test_pagination.rb +35 -35
- data/test/test_polymorphic.rb +43 -43
- data/test/test_predicates.rb +59 -59
- data/test/test_preload.rb +102 -102
- data/test/test_santiago.rb +23 -23
- data/test/test_touch.rb +23 -23
- data/test/test_tutorial_example.rb +25 -25
- data/test/test_update.rb +102 -96
- data/test/test_validations.rb +13 -13
- metadata +7 -6
data/test/test_ids.rb
CHANGED
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
require File.expand_path('../abstract_unit', __FILE__)
|
|
2
|
-
|
|
3
|
-
class ChildCpkTest < ReferenceCode
|
|
4
|
-
end
|
|
5
|
-
|
|
6
|
-
class TestIds < ActiveSupport::TestCase
|
|
7
|
-
fixtures :reference_types, :reference_codes
|
|
8
|
-
|
|
9
|
-
CLASSES = {
|
|
10
|
-
:single => {
|
|
11
|
-
:class => ReferenceType,
|
|
12
|
-
:primary_keys => [:reference_type_id],
|
|
13
|
-
},
|
|
14
|
-
:dual => {
|
|
15
|
-
:class => ReferenceCode,
|
|
16
|
-
:primary_keys => [:reference_type_id, :reference_code],
|
|
17
|
-
},
|
|
18
|
-
:dual_strs => {
|
|
19
|
-
:class => ReferenceCode,
|
|
20
|
-
:primary_keys => ['reference_type_id', 'reference_code'],
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
def setup
|
|
25
|
-
self.class.classes = CLASSES
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def test_id
|
|
29
|
-
testing_with do
|
|
30
|
-
assert_equal @first.id, @first.ids if composite?
|
|
31
|
-
assert_kind_of(CompositePrimaryKeys::CompositeKeys, @first.id) if composite?
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def test_to_param
|
|
36
|
-
testing_with do
|
|
37
|
-
assert_equal '1,1', @first.to_param if composite?
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
capitol = Capitol.create!(country: 'The USA', city: 'Washington, D.C.')
|
|
41
|
-
assert_equal 'The USA,Washington^2C D.C.', capitol.to_param
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def test_ids_to_s
|
|
45
|
-
testing_with do
|
|
46
|
-
order = @klass.primary_key.is_a?(String) ? @klass.primary_key : @klass.primary_key.join(',')
|
|
47
|
-
to_test = @klass.order(order)[0..1].map(&:id)
|
|
48
|
-
assert_equal '(1,1),(1,2)', @klass.ids_to_s(to_test) if @key_test == :dual
|
|
49
|
-
assert_equal '1,1;1,2', @klass.ids_to_s(to_test, ',', ';', '', '') if @key_test == :dual
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def test_set_ids_string
|
|
54
|
-
testing_with do
|
|
55
|
-
array = @primary_keys.collect {|key| 5}
|
|
56
|
-
expected = composite? ? array.to_composite_keys : array.first
|
|
57
|
-
@first.id = expected.to_s
|
|
58
|
-
assert_equal expected, @first.id
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def test_set_ids_array
|
|
63
|
-
testing_with do
|
|
64
|
-
array = @primary_keys.collect {|key| 5}
|
|
65
|
-
expected = composite? ? array.to_composite_keys : array.first
|
|
66
|
-
@first.id = expected
|
|
67
|
-
assert_equal expected, @first.id
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def test_set_ids_comp
|
|
72
|
-
testing_with do
|
|
73
|
-
array = @primary_keys.collect {|key| 5}
|
|
74
|
-
expected = composite? ? array.to_composite_keys : array.first
|
|
75
|
-
@first.id = expected
|
|
76
|
-
assert_equal expected, @first.id
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def test_primary_keys
|
|
81
|
-
testing_with do
|
|
82
|
-
if composite?
|
|
83
|
-
assert_not_nil @klass.primary_keys
|
|
84
|
-
assert_equal @primary_keys.map {|key| key.to_s}, @klass.primary_keys
|
|
85
|
-
assert_equal @klass.primary_keys, @klass.primary_key
|
|
86
|
-
assert_kind_of(CompositePrimaryKeys::CompositeKeys, @klass.primary_keys)
|
|
87
|
-
assert_equal @primary_keys.map {|key| key.to_sym}.join(','), @klass.primary_key.to_s
|
|
88
|
-
else
|
|
89
|
-
assert_not_nil @klass.primary_key
|
|
90
|
-
assert_equal @primary_keys.first, @klass.primary_key.to_sym
|
|
91
|
-
assert_equal @primary_keys.first.to_s, @klass.primary_key.to_s
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def test_inherited_primary_keys
|
|
97
|
-
assert_equal(["reference_type_id", "reference_code"], ChildCpkTest.primary_keys)
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
def test_inherited_ids
|
|
101
|
-
cpk_test = ChildCpkTest.new
|
|
102
|
-
assert_equal([nil, nil], cpk_test.id)
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def test_assign_ids
|
|
106
|
-
ref_code = ReferenceCode.new
|
|
107
|
-
assert_equal([nil, nil], ref_code.id)
|
|
108
|
-
|
|
109
|
-
ref_code.id = [2,1]
|
|
110
|
-
assert_equal([2,1], ref_code.id)
|
|
111
|
-
end
|
|
112
|
-
end
|
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
|
2
|
+
|
|
3
|
+
class ChildCpkTest < ReferenceCode
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
class TestIds < ActiveSupport::TestCase
|
|
7
|
+
fixtures :reference_types, :reference_codes
|
|
8
|
+
|
|
9
|
+
CLASSES = {
|
|
10
|
+
:single => {
|
|
11
|
+
:class => ReferenceType,
|
|
12
|
+
:primary_keys => [:reference_type_id],
|
|
13
|
+
},
|
|
14
|
+
:dual => {
|
|
15
|
+
:class => ReferenceCode,
|
|
16
|
+
:primary_keys => [:reference_type_id, :reference_code],
|
|
17
|
+
},
|
|
18
|
+
:dual_strs => {
|
|
19
|
+
:class => ReferenceCode,
|
|
20
|
+
:primary_keys => ['reference_type_id', 'reference_code'],
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
def setup
|
|
25
|
+
self.class.classes = CLASSES
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_id
|
|
29
|
+
testing_with do
|
|
30
|
+
assert_equal @first.id, @first.ids if composite?
|
|
31
|
+
assert_kind_of(CompositePrimaryKeys::CompositeKeys, @first.id) if composite?
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_to_param
|
|
36
|
+
testing_with do
|
|
37
|
+
assert_equal '1,1', @first.to_param if composite?
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
capitol = Capitol.create!(country: 'The USA', city: 'Washington, D.C.')
|
|
41
|
+
assert_equal 'The USA,Washington^2C D.C.', capitol.to_param
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_ids_to_s
|
|
45
|
+
testing_with do
|
|
46
|
+
order = @klass.primary_key.is_a?(String) ? @klass.primary_key : @klass.primary_key.join(',')
|
|
47
|
+
to_test = @klass.order(order)[0..1].map(&:id)
|
|
48
|
+
assert_equal '(1,1),(1,2)', @klass.ids_to_s(to_test) if @key_test == :dual
|
|
49
|
+
assert_equal '1,1;1,2', @klass.ids_to_s(to_test, ',', ';', '', '') if @key_test == :dual
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_set_ids_string
|
|
54
|
+
testing_with do
|
|
55
|
+
array = @primary_keys.collect {|key| 5}
|
|
56
|
+
expected = composite? ? array.to_composite_keys : array.first
|
|
57
|
+
@first.id = expected.to_s
|
|
58
|
+
assert_equal expected, @first.id
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_set_ids_array
|
|
63
|
+
testing_with do
|
|
64
|
+
array = @primary_keys.collect {|key| 5}
|
|
65
|
+
expected = composite? ? array.to_composite_keys : array.first
|
|
66
|
+
@first.id = expected
|
|
67
|
+
assert_equal expected, @first.id
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_set_ids_comp
|
|
72
|
+
testing_with do
|
|
73
|
+
array = @primary_keys.collect {|key| 5}
|
|
74
|
+
expected = composite? ? array.to_composite_keys : array.first
|
|
75
|
+
@first.id = expected
|
|
76
|
+
assert_equal expected, @first.id
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def test_primary_keys
|
|
81
|
+
testing_with do
|
|
82
|
+
if composite?
|
|
83
|
+
assert_not_nil @klass.primary_keys
|
|
84
|
+
assert_equal @primary_keys.map {|key| key.to_s}, @klass.primary_keys
|
|
85
|
+
assert_equal @klass.primary_keys, @klass.primary_key
|
|
86
|
+
assert_kind_of(CompositePrimaryKeys::CompositeKeys, @klass.primary_keys)
|
|
87
|
+
assert_equal @primary_keys.map {|key| key.to_sym}.join(','), @klass.primary_key.to_s
|
|
88
|
+
else
|
|
89
|
+
assert_not_nil @klass.primary_key
|
|
90
|
+
assert_equal @primary_keys.first, @klass.primary_key.to_sym
|
|
91
|
+
assert_equal @primary_keys.first.to_s, @klass.primary_key.to_s
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def test_inherited_primary_keys
|
|
97
|
+
assert_equal(["reference_type_id", "reference_code"], ChildCpkTest.primary_keys)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def test_inherited_ids
|
|
101
|
+
cpk_test = ChildCpkTest.new
|
|
102
|
+
assert_equal([nil, nil], cpk_test.id)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def test_assign_ids
|
|
106
|
+
ref_code = ReferenceCode.new
|
|
107
|
+
assert_equal([nil, nil], ref_code.id)
|
|
108
|
+
|
|
109
|
+
ref_code.id = [2,1]
|
|
110
|
+
assert_equal([2,1], ref_code.id)
|
|
111
|
+
end
|
|
112
|
+
end
|
data/test/test_miscellaneous.rb
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
require File.expand_path('../abstract_unit', __FILE__)
|
|
2
|
-
|
|
3
|
-
class TestMiscellaneous < ActiveSupport::TestCase
|
|
4
|
-
fixtures :reference_types, :reference_codes, :products
|
|
5
|
-
|
|
6
|
-
CLASSES = {
|
|
7
|
-
:single => {
|
|
8
|
-
:class => ReferenceType,
|
|
9
|
-
:primary_keys => :reference_type_id,
|
|
10
|
-
},
|
|
11
|
-
:dual => {
|
|
12
|
-
:class => ReferenceCode,
|
|
13
|
-
:primary_keys => [:reference_type_id, :reference_code],
|
|
14
|
-
},
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
def setup
|
|
18
|
-
self.class.classes = CLASSES
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def test_composite_class
|
|
22
|
-
testing_with do
|
|
23
|
-
assert_equal composite?, @klass.composite?
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def test_composite_instance
|
|
28
|
-
testing_with do
|
|
29
|
-
assert_equal composite?, @first.composite?
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
|
2
|
+
|
|
3
|
+
class TestMiscellaneous < ActiveSupport::TestCase
|
|
4
|
+
fixtures :reference_types, :reference_codes, :products
|
|
5
|
+
|
|
6
|
+
CLASSES = {
|
|
7
|
+
:single => {
|
|
8
|
+
:class => ReferenceType,
|
|
9
|
+
:primary_keys => :reference_type_id,
|
|
10
|
+
},
|
|
11
|
+
:dual => {
|
|
12
|
+
:class => ReferenceCode,
|
|
13
|
+
:primary_keys => [:reference_type_id, :reference_code],
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
def setup
|
|
18
|
+
self.class.classes = CLASSES
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_composite_class
|
|
22
|
+
testing_with do
|
|
23
|
+
assert_equal composite?, @klass.composite?
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_composite_instance
|
|
28
|
+
testing_with do
|
|
29
|
+
assert_equal composite?, @first.composite?
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -1,67 +1,67 @@
|
|
|
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
|
-
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
|
+
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_pagination.rb
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
#require File.expand_path('../abstract_unit', __FILE__)
|
|
2
|
-
#require 'plugins/pagination'
|
|
3
|
-
#
|
|
4
|
-
#class TestPagination < ActiveSupport::TestCase
|
|
5
|
-
# fixtures :reference_types, :reference_codes
|
|
6
|
-
#
|
|
7
|
-
# include ActionController::Pagination
|
|
8
|
-
# DEFAULT_PAGE_SIZE = 2
|
|
9
|
-
#
|
|
10
|
-
# attr_accessor :params
|
|
11
|
-
#
|
|
12
|
-
# CLASSES = {
|
|
13
|
-
# :single => {
|
|
14
|
-
# :class => ReferenceType,
|
|
15
|
-
# :primary_keys => :reference_type_id,
|
|
16
|
-
# :table => :reference_types,
|
|
17
|
-
# },
|
|
18
|
-
# :dual => {
|
|
19
|
-
# :class => ReferenceCode,
|
|
20
|
-
# :primary_keys => [:reference_type_id, :reference_code],
|
|
21
|
-
# :table => :reference_codes,
|
|
22
|
-
# },
|
|
23
|
-
# }
|
|
24
|
-
#
|
|
25
|
-
# def setup
|
|
26
|
-
# self.class.classes = CLASSES
|
|
27
|
-
# @params = {}
|
|
28
|
-
# end
|
|
29
|
-
#
|
|
30
|
-
# def test_paginate_all
|
|
31
|
-
# testing_with do
|
|
32
|
-
# @object_pages, @objects = paginate @klass_info[:table], :per_page => DEFAULT_PAGE_SIZE
|
|
33
|
-
# assert_equal 2, @objects.length, "Each page should have #{DEFAULT_PAGE_SIZE} items"
|
|
34
|
-
# end
|
|
35
|
-
# end
|
|
1
|
+
#require File.expand_path('../abstract_unit', __FILE__)
|
|
2
|
+
#require 'plugins/pagination'
|
|
3
|
+
#
|
|
4
|
+
#class TestPagination < ActiveSupport::TestCase
|
|
5
|
+
# fixtures :reference_types, :reference_codes
|
|
6
|
+
#
|
|
7
|
+
# include ActionController::Pagination
|
|
8
|
+
# DEFAULT_PAGE_SIZE = 2
|
|
9
|
+
#
|
|
10
|
+
# attr_accessor :params
|
|
11
|
+
#
|
|
12
|
+
# CLASSES = {
|
|
13
|
+
# :single => {
|
|
14
|
+
# :class => ReferenceType,
|
|
15
|
+
# :primary_keys => :reference_type_id,
|
|
16
|
+
# :table => :reference_types,
|
|
17
|
+
# },
|
|
18
|
+
# :dual => {
|
|
19
|
+
# :class => ReferenceCode,
|
|
20
|
+
# :primary_keys => [:reference_type_id, :reference_code],
|
|
21
|
+
# :table => :reference_codes,
|
|
22
|
+
# },
|
|
23
|
+
# }
|
|
24
|
+
#
|
|
25
|
+
# def setup
|
|
26
|
+
# self.class.classes = CLASSES
|
|
27
|
+
# @params = {}
|
|
28
|
+
# end
|
|
29
|
+
#
|
|
30
|
+
# def test_paginate_all
|
|
31
|
+
# testing_with do
|
|
32
|
+
# @object_pages, @objects = paginate @klass_info[:table], :per_page => DEFAULT_PAGE_SIZE
|
|
33
|
+
# assert_equal 2, @objects.length, "Each page should have #{DEFAULT_PAGE_SIZE} items"
|
|
34
|
+
# end
|
|
35
|
+
# end
|
|
36
36
|
#end
|
data/test/test_polymorphic.rb
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
require File.expand_path('../abstract_unit', __FILE__)
|
|
2
|
-
|
|
3
|
-
class TestPolymorphic < ActiveSupport::TestCase
|
|
4
|
-
fixtures :articles, :departments, :employees, :users, :comments
|
|
5
|
-
|
|
6
|
-
def test_has_many
|
|
7
|
-
user = users(:santiago)
|
|
8
|
-
comments = user.comments
|
|
9
|
-
assert_equal(user.id, comments[0].person_id)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def test_has_one
|
|
13
|
-
user = users(:santiago)
|
|
14
|
-
first_comment = user.first_comment
|
|
15
|
-
assert_equal(user.id, first_comment.person_id)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def test_has_many_through
|
|
19
|
-
department = departments(:accounting)
|
|
20
|
-
comment = comments(:employee_comment)
|
|
21
|
-
|
|
22
|
-
assert_equal(1, department.comments.size)
|
|
23
|
-
assert_equal(comment, department.comments[0])
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def test_has_many_through_2
|
|
27
|
-
article = articles(:second)
|
|
28
|
-
|
|
29
|
-
user = users(:santiago)
|
|
30
|
-
assert_equal(user, article.user_commentators[0])
|
|
31
|
-
|
|
32
|
-
user = users(:drnic)
|
|
33
|
-
assert_equal(user, article.user_commentators[1])
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def test_clear_has_many_through
|
|
37
|
-
article = articles(:second)
|
|
38
|
-
|
|
39
|
-
assert_equal(2, article.comments.size)
|
|
40
|
-
article.user_commentators = []
|
|
41
|
-
assert_equal(0, article.comments.size)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
|
2
|
+
|
|
3
|
+
class TestPolymorphic < ActiveSupport::TestCase
|
|
4
|
+
fixtures :articles, :departments, :employees, :users, :comments
|
|
5
|
+
|
|
6
|
+
def test_has_many
|
|
7
|
+
user = users(:santiago)
|
|
8
|
+
comments = user.comments
|
|
9
|
+
assert_equal(user.id, comments[0].person_id)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_has_one
|
|
13
|
+
user = users(:santiago)
|
|
14
|
+
first_comment = user.first_comment
|
|
15
|
+
assert_equal(user.id, first_comment.person_id)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_has_many_through
|
|
19
|
+
department = departments(:accounting)
|
|
20
|
+
comment = comments(:employee_comment)
|
|
21
|
+
|
|
22
|
+
assert_equal(1, department.comments.size)
|
|
23
|
+
assert_equal(comment, department.comments[0])
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_has_many_through_2
|
|
27
|
+
article = articles(:second)
|
|
28
|
+
|
|
29
|
+
user = users(:santiago)
|
|
30
|
+
assert_equal(user, article.user_commentators[0])
|
|
31
|
+
|
|
32
|
+
user = users(:drnic)
|
|
33
|
+
assert_equal(user, article.user_commentators[1])
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_clear_has_many_through
|
|
37
|
+
article = articles(:second)
|
|
38
|
+
|
|
39
|
+
assert_equal(2, article.comments.size)
|
|
40
|
+
article.user_commentators = []
|
|
41
|
+
assert_equal(0, article.comments.size)
|
|
42
|
+
end
|
|
43
|
+
end
|