globe-composite_primary_keys 3.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.
- data/History.txt +203 -0
- data/Manifest.txt +121 -0
- data/README.txt +41 -0
- data/README_DB2.txt +33 -0
- data/Rakefile +30 -0
- data/composite_primary_keys.gemspec +17 -0
- data/lib/adapter_helper/base.rb +63 -0
- data/lib/adapter_helper/mysql.rb +13 -0
- data/lib/adapter_helper/oracle.rb +12 -0
- data/lib/adapter_helper/oracle_enhanced.rb +12 -0
- data/lib/adapter_helper/postgresql.rb +13 -0
- data/lib/adapter_helper/sqlite3.rb +13 -0
- data/lib/composite_primary_keys.rb +63 -0
- data/lib/composite_primary_keys/association_preload.rb +162 -0
- data/lib/composite_primary_keys/associations.rb +159 -0
- data/lib/composite_primary_keys/attribute_methods.rb +84 -0
- data/lib/composite_primary_keys/base.rb +200 -0
- data/lib/composite_primary_keys/composite_arrays.rb +29 -0
- data/lib/composite_primary_keys/connection_adapters/abstract_adapter.rb +9 -0
- data/lib/composite_primary_keys/connection_adapters/ibm_db_adapter.rb +21 -0
- data/lib/composite_primary_keys/connection_adapters/oracle_adapter.rb +15 -0
- data/lib/composite_primary_keys/connection_adapters/oracle_enhanced_adapter.rb +17 -0
- data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +53 -0
- data/lib/composite_primary_keys/connection_adapters/sqlite3_adapter.rb +15 -0
- data/lib/composite_primary_keys/finder_methods.rb +68 -0
- data/lib/composite_primary_keys/fixtures.rb +8 -0
- data/lib/composite_primary_keys/read.rb +25 -0
- data/lib/composite_primary_keys/reflection.rb +39 -0
- data/lib/composite_primary_keys/relation.rb +31 -0
- data/lib/composite_primary_keys/through_association_scope.rb +212 -0
- data/lib/composite_primary_keys/validations/uniqueness.rb +118 -0
- data/lib/composite_primary_keys/version.rb +9 -0
- data/loader.rb +24 -0
- data/local/database_connections.rb.sample +12 -0
- data/local/paths.rb.sample +2 -0
- data/local/tasks.rb.sample +2 -0
- data/scripts/console.rb +48 -0
- data/scripts/txt2html +67 -0
- data/scripts/txt2js +59 -0
- data/tasks/activerecord_selection.rake +43 -0
- data/tasks/databases.rake +12 -0
- data/tasks/databases/mysql.rake +30 -0
- data/tasks/databases/oracle.rake +25 -0
- data/tasks/databases/postgresql.rake +25 -0
- data/tasks/databases/sqlite3.rake +28 -0
- data/tasks/deployment.rake +22 -0
- data/tasks/local_setup.rake +13 -0
- data/tasks/website.rake +18 -0
- data/test/README_tests.txt +67 -0
- data/test/abstract_unit.rb +103 -0
- data/test/connections/native_ibm_db/connection.rb +23 -0
- data/test/connections/native_mysql/connection.rb +13 -0
- data/test/connections/native_oracle/connection.rb +14 -0
- data/test/connections/native_oracle_enhanced/connection.rb +20 -0
- data/test/connections/native_postgresql/connection.rb +8 -0
- data/test/connections/native_sqlite/connection.rb +9 -0
- data/test/fixtures/article.rb +5 -0
- data/test/fixtures/article_group.rb +4 -0
- data/test/fixtures/article_groups.yml +7 -0
- data/test/fixtures/articles.yml +6 -0
- data/test/fixtures/comment.rb +6 -0
- data/test/fixtures/comments.yml +16 -0
- data/test/fixtures/db_definitions/db2-create-tables.sql +113 -0
- data/test/fixtures/db_definitions/db2-drop-tables.sql +16 -0
- data/test/fixtures/db_definitions/mysql.sql +181 -0
- data/test/fixtures/db_definitions/oracle.drop.sql +39 -0
- data/test/fixtures/db_definitions/oracle.sql +188 -0
- data/test/fixtures/db_definitions/postgresql.sql +206 -0
- data/test/fixtures/db_definitions/sqlite.sql +166 -0
- data/test/fixtures/department.rb +5 -0
- data/test/fixtures/departments.yml +3 -0
- data/test/fixtures/dorm.rb +3 -0
- data/test/fixtures/dorms.yml +2 -0
- data/test/fixtures/employee.rb +4 -0
- data/test/fixtures/employees.yml +9 -0
- data/test/fixtures/group.rb +3 -0
- data/test/fixtures/groups.yml +3 -0
- data/test/fixtures/hack.rb +6 -0
- data/test/fixtures/hacks.yml +2 -0
- data/test/fixtures/kitchen_sink.rb +3 -0
- data/test/fixtures/kitchen_sinks.yml +5 -0
- data/test/fixtures/membership.rb +10 -0
- data/test/fixtures/membership_status.rb +3 -0
- data/test/fixtures/membership_statuses.yml +10 -0
- data/test/fixtures/memberships.yml +6 -0
- data/test/fixtures/product.rb +7 -0
- data/test/fixtures/product_tariff.rb +5 -0
- data/test/fixtures/product_tariffs.yml +12 -0
- data/test/fixtures/products.yml +6 -0
- data/test/fixtures/reading.rb +4 -0
- data/test/fixtures/readings.yml +10 -0
- data/test/fixtures/reference_code.rb +7 -0
- data/test/fixtures/reference_codes.yml +28 -0
- data/test/fixtures/reference_type.rb +7 -0
- data/test/fixtures/reference_types.yml +9 -0
- data/test/fixtures/restaurant.rb +6 -0
- data/test/fixtures/restaurants.yml +5 -0
- data/test/fixtures/restaurants_suburbs.yml +11 -0
- data/test/fixtures/room.rb +10 -0
- data/test/fixtures/room_assignment.rb +4 -0
- data/test/fixtures/room_assignments.yml +4 -0
- data/test/fixtures/room_attribute.rb +3 -0
- data/test/fixtures/room_attribute_assignment.rb +5 -0
- data/test/fixtures/room_attribute_assignments.yml +4 -0
- data/test/fixtures/room_attributes.yml +3 -0
- data/test/fixtures/rooms.yml +3 -0
- data/test/fixtures/seat.rb +5 -0
- data/test/fixtures/seats.yml +4 -0
- data/test/fixtures/street.rb +3 -0
- data/test/fixtures/streets.yml +15 -0
- data/test/fixtures/student.rb +4 -0
- data/test/fixtures/students.yml +2 -0
- data/test/fixtures/suburb.rb +6 -0
- data/test/fixtures/suburbs.yml +9 -0
- data/test/fixtures/tariff.rb +6 -0
- data/test/fixtures/tariffs.yml +13 -0
- data/test/fixtures/user.rb +10 -0
- data/test/fixtures/users.yml +6 -0
- data/test/hash_tricks.rb +34 -0
- data/test/plugins/pagination.rb +405 -0
- data/test/plugins/pagination_helper.rb +135 -0
- data/test/test_associations.rb +178 -0
- data/test/test_attribute_methods.rb +22 -0
- data/test/test_attributes.rb +80 -0
- data/test/test_clone.rb +34 -0
- data/test/test_composite_arrays.rb +32 -0
- data/test/test_create.rb +68 -0
- data/test/test_delete.rb +83 -0
- data/test/test_exists.rb +25 -0
- data/test/test_find.rb +73 -0
- data/test/test_ids.rb +90 -0
- data/test/test_miscellaneous.rb +39 -0
- data/test/test_pagination.rb +38 -0
- data/test/test_polymorphic.rb +32 -0
- data/test/test_santiago.rb +27 -0
- data/test/test_suite.rb +19 -0
- data/test/test_tutorial_example.rb +26 -0
- data/test/test_update.rb +40 -0
- data/test/test_validations.rb +11 -0
- data/website/index.html +195 -0
- data/website/index.txt +159 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +126 -0
- data/website/template.js +3 -0
- data/website/template.rhtml +53 -0
- data/website/version-raw.js +3 -0
- data/website/version-raw.txt +2 -0
- data/website/version.js +4 -0
- data/website/version.txt +3 -0
- metadata +339 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
require 'fixtures/reference_type'
|
|
3
|
+
require 'fixtures/reference_code'
|
|
4
|
+
|
|
5
|
+
class CompositeArraysTest < ActiveSupport::TestCase
|
|
6
|
+
|
|
7
|
+
def test_new_primary_keys
|
|
8
|
+
keys = CompositePrimaryKeys::CompositeKeys.new
|
|
9
|
+
assert_not_nil keys
|
|
10
|
+
assert_equal '', keys.to_s
|
|
11
|
+
assert_equal '', "#{keys}"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_initialize_primary_keys
|
|
15
|
+
keys = CompositePrimaryKeys::CompositeKeys.new([1,2,3])
|
|
16
|
+
assert_not_nil keys
|
|
17
|
+
assert_equal '1,2,3', keys.to_s
|
|
18
|
+
assert_equal '1,2,3', "#{keys}"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_to_composite_keys
|
|
22
|
+
keys = [1,2,3].to_composite_keys
|
|
23
|
+
assert_equal CompositePrimaryKeys::CompositeKeys, keys.class
|
|
24
|
+
assert_equal '1,2,3', keys.to_s
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_to_composite_ids
|
|
28
|
+
keys = [1,2,3].to_composite_ids
|
|
29
|
+
assert_equal CompositePrimaryKeys::CompositeIds, keys.class
|
|
30
|
+
assert_equal "1,2,3", keys.to_s
|
|
31
|
+
end
|
|
32
|
+
end
|
data/test/test_create.rb
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
require 'fixtures/reference_type'
|
|
3
|
+
require 'fixtures/reference_code'
|
|
4
|
+
require 'fixtures/street'
|
|
5
|
+
require 'fixtures/suburb'
|
|
6
|
+
|
|
7
|
+
class TestCreate < ActiveSupport::TestCase
|
|
8
|
+
fixtures :reference_types, :reference_codes, :streets, :suburbs
|
|
9
|
+
|
|
10
|
+
CLASSES = {
|
|
11
|
+
:single => {
|
|
12
|
+
:class => ReferenceType,
|
|
13
|
+
:primary_keys => :reference_type_id,
|
|
14
|
+
:create => {:reference_type_id => 10, :type_label => 'NEW_TYPE', :abbreviation => 'New Type'}
|
|
15
|
+
},
|
|
16
|
+
:dual => {
|
|
17
|
+
:class => ReferenceCode,
|
|
18
|
+
:primary_keys => [:reference_type_id, :reference_code],
|
|
19
|
+
:create => {:reference_type_id => 1, :reference_code => 20, :code_label => 'NEW_CODE', :abbreviation => 'New Code'}
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
def setup
|
|
24
|
+
self.class.classes = CLASSES
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_setup
|
|
28
|
+
testing_with do
|
|
29
|
+
assert_not_nil @klass_info[:create]
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_create
|
|
34
|
+
testing_with do
|
|
35
|
+
assert new_obj = @klass.create(@klass_info[:create])
|
|
36
|
+
assert !new_obj.new_record?
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_create_no_id
|
|
41
|
+
testing_with do
|
|
42
|
+
begin
|
|
43
|
+
@obj = @klass.create(@klass_info[:create].block(@klass.primary_key))
|
|
44
|
+
@successful = !composite?
|
|
45
|
+
rescue CompositePrimaryKeys::ActiveRecord::CompositeKeyError
|
|
46
|
+
@successful = false
|
|
47
|
+
rescue
|
|
48
|
+
flunk "Incorrect exception raised: #{$!}, #{$!.class}"
|
|
49
|
+
end
|
|
50
|
+
assert_equal composite?, !@successful, "Create should have failed for composites; #{@obj.inspect}"
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_create_on_association
|
|
55
|
+
suburb = Suburb.find(:first)
|
|
56
|
+
suburb.streets.create(:name => "my street")
|
|
57
|
+
street = Street.find_by_name('my street')
|
|
58
|
+
assert_equal(suburb.city_id, street.city_id)
|
|
59
|
+
assert_equal(suburb.suburb_id, street.suburb_id)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_create_on_association_when_belongs_to_is_single_key
|
|
63
|
+
rt = ReferenceType.find(:first)
|
|
64
|
+
rt.reference_codes.create(:reference_code => 4321, :code_label => 'foo', :abbreviation => 'bar')
|
|
65
|
+
rc = ReferenceCode.find_by_reference_code(4321)
|
|
66
|
+
assert_equal(rc.reference_type_id, rt.reference_type_id)
|
|
67
|
+
end
|
|
68
|
+
end
|
data/test/test_delete.rb
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
require 'fixtures/reference_type'
|
|
3
|
+
require 'fixtures/reference_code'
|
|
4
|
+
require 'fixtures/department'
|
|
5
|
+
require 'fixtures/employee'
|
|
6
|
+
|
|
7
|
+
class TestDelete < ActiveSupport::TestCase
|
|
8
|
+
fixtures :reference_types, :reference_codes, :departments, :employees
|
|
9
|
+
|
|
10
|
+
CLASSES = {
|
|
11
|
+
:single => {
|
|
12
|
+
:class => ReferenceType,
|
|
13
|
+
:primary_keys => :reference_type_id,
|
|
14
|
+
},
|
|
15
|
+
:dual => {
|
|
16
|
+
:class => ReferenceCode,
|
|
17
|
+
:primary_keys => [:reference_type_id, :reference_code],
|
|
18
|
+
},
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
def setup
|
|
22
|
+
self.class.classes = CLASSES
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_destroy_one
|
|
26
|
+
testing_with do
|
|
27
|
+
assert @first.destroy
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_destroy_one_alone_via_class
|
|
32
|
+
testing_with do
|
|
33
|
+
assert @klass.destroy(@first.id)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_delete_one_alone
|
|
38
|
+
testing_with do
|
|
39
|
+
assert @klass.delete(@first.id)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_delete_many
|
|
44
|
+
testing_with do
|
|
45
|
+
to_delete = @klass.find(:all)[0..1]
|
|
46
|
+
assert_equal 2, to_delete.length
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_delete_all
|
|
51
|
+
testing_with do
|
|
52
|
+
@klass.delete_all
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_clear_association
|
|
57
|
+
department = Department.find(1,1)
|
|
58
|
+
assert_equal 2, department.employees.size, "Before clear employee count should be 2."
|
|
59
|
+
department.employees.clear
|
|
60
|
+
assert_equal 0, department.employees.size, "After clear employee count should be 0."
|
|
61
|
+
department.reload
|
|
62
|
+
assert_equal 0, department.employees.size, "After clear and a reload from DB employee count should be 0."
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def test_delete_association
|
|
66
|
+
department = Department.find(1,1)
|
|
67
|
+
assert_equal 2, department.employees.size , "Before delete employee count should be 2."
|
|
68
|
+
first_employee = department.employees[0]
|
|
69
|
+
department.employees.delete(first_employee)
|
|
70
|
+
assert_equal 1, department.employees.size, "After delete employee count should be 1."
|
|
71
|
+
department.reload
|
|
72
|
+
assert_equal 1, department.employees.size, "After delete and a reload from DB employee count should be 1."
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def test_delete_records_for_has_many_association_with_composite_primary_key
|
|
76
|
+
reference_type = ReferenceType.find(1)
|
|
77
|
+
codes_to_delete = reference_type.reference_codes[0..1]
|
|
78
|
+
assert_equal 3, reference_type.reference_codes.size, "Before deleting records reference_code count should be 3."
|
|
79
|
+
reference_type.reference_codes.delete_records(codes_to_delete)
|
|
80
|
+
reference_type.reload
|
|
81
|
+
assert_equal 1, reference_type.reference_codes.size, "After deleting 2 records and a reload from DB reference_code count should be 1."
|
|
82
|
+
end
|
|
83
|
+
end
|
data/test/test_exists.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
require 'fixtures/article'
|
|
3
|
+
require 'fixtures/department'
|
|
4
|
+
|
|
5
|
+
class TestExists < ActiveSupport::TestCase
|
|
6
|
+
fixtures :articles, :departments
|
|
7
|
+
|
|
8
|
+
def test_single_key_exists_giving_id
|
|
9
|
+
assert Article.exists?(1)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_single_key_exists_giving_condition
|
|
13
|
+
assert Article.exists?(['name = ?', 'Article One'])
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_composite_key_exists_giving_ids_as_array
|
|
17
|
+
assert Department.exists?([1,1])
|
|
18
|
+
assert_equal(false, Department.exists?([1111,1111]))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_composite_key_exists_giving_ids_as_condition
|
|
22
|
+
assert Department.exists?(['department_id = ? and location_id = ?', 1, 1])
|
|
23
|
+
assert_equal(false, Department.exists?(['department_id = ? and location_id = ?', 11111, 11111]))
|
|
24
|
+
end
|
|
25
|
+
end
|
data/test/test_find.rb
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
require 'fixtures/reference_type'
|
|
3
|
+
require 'fixtures/reference_code'
|
|
4
|
+
|
|
5
|
+
# Testing the find action on composite ActiveRecords with two primary keys
|
|
6
|
+
class TestFind < 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_find_first
|
|
29
|
+
testing_with do
|
|
30
|
+
obj = @klass.find(:first)
|
|
31
|
+
assert obj
|
|
32
|
+
assert_equal @klass, obj.class
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_find
|
|
37
|
+
testing_with do
|
|
38
|
+
found = @klass.find(*first_id) # e.g. find(1,1) or find 1,1
|
|
39
|
+
assert found
|
|
40
|
+
assert_equal @klass, found.class
|
|
41
|
+
assert_equal found, @klass.find(found.id)
|
|
42
|
+
assert_equal found, @klass.find(found.to_param)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_find_composite_ids
|
|
47
|
+
testing_with do
|
|
48
|
+
found = @klass.find(first_id) # e.g. find([1,1].to_composite_ids)
|
|
49
|
+
assert found
|
|
50
|
+
assert_equal @klass, found.class
|
|
51
|
+
assert_equal found, @klass.find(found.id)
|
|
52
|
+
assert_equal found, @klass.find(found.to_param)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_to_param
|
|
57
|
+
testing_with do
|
|
58
|
+
assert_equal first_id_str, @first.to_param.to_s
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def things_to_look_at
|
|
63
|
+
testing_with do
|
|
64
|
+
assert_equal found, @klass.find(found.id.to_s) # fails for 2+ keys
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def test_not_found
|
|
69
|
+
assert_raise(::ActiveRecord::RecordNotFound) do
|
|
70
|
+
ReferenceCode.send :find, '999,999'
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
data/test/test_ids.rb
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
require 'fixtures/reference_type'
|
|
3
|
+
require 'fixtures/reference_code'
|
|
4
|
+
|
|
5
|
+
class TestIds < ActiveSupport::TestCase
|
|
6
|
+
fixtures :reference_types, :reference_codes
|
|
7
|
+
|
|
8
|
+
CLASSES = {
|
|
9
|
+
:single => {
|
|
10
|
+
:class => ReferenceType,
|
|
11
|
+
:primary_keys => [:reference_type_id],
|
|
12
|
+
},
|
|
13
|
+
:dual => {
|
|
14
|
+
:class => ReferenceCode,
|
|
15
|
+
:primary_keys => [:reference_type_id, :reference_code],
|
|
16
|
+
},
|
|
17
|
+
:dual_strs => {
|
|
18
|
+
:class => ReferenceCode,
|
|
19
|
+
:primary_keys => ['reference_type_id', 'reference_code'],
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
def setup
|
|
24
|
+
self.class.classes = CLASSES
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_id
|
|
28
|
+
testing_with do
|
|
29
|
+
assert_equal @first.id, @first.ids if composite?
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_id_to_s
|
|
34
|
+
testing_with do
|
|
35
|
+
assert_equal first_id_str, @first.id.to_s
|
|
36
|
+
assert_equal first_id_str, "#{@first.id}"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_ids_to_s
|
|
41
|
+
testing_with do
|
|
42
|
+
order = @klass.primary_key.is_a?(String) ? @klass.primary_key : @klass.primary_key.join(',')
|
|
43
|
+
to_test = @klass.find(:all, :order => order)[0..1].map(&:id)
|
|
44
|
+
assert_equal '(1,1),(1,2)', @klass.ids_to_s(to_test) if @key_test == :dual
|
|
45
|
+
assert_equal '1,1;1,2', @klass.ids_to_s(to_test, ',', ';', '', '') if @key_test == :dual
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_set_ids_string
|
|
50
|
+
testing_with do
|
|
51
|
+
array = @primary_keys.collect {|key| 5}
|
|
52
|
+
expected = composite? ? array.to_composite_keys : array.first
|
|
53
|
+
@first.id = expected.to_s
|
|
54
|
+
assert_equal expected, @first.id
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_set_ids_array
|
|
59
|
+
testing_with do
|
|
60
|
+
array = @primary_keys.collect {|key| 5}
|
|
61
|
+
expected = composite? ? array.to_composite_keys : array.first
|
|
62
|
+
@first.id = expected
|
|
63
|
+
assert_equal expected, @first.id
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_set_ids_comp
|
|
68
|
+
testing_with do
|
|
69
|
+
array = @primary_keys.collect {|key| 5}
|
|
70
|
+
expected = composite? ? array.to_composite_keys : array.first
|
|
71
|
+
@first.id = expected
|
|
72
|
+
assert_equal expected, @first.id
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def test_primary_keys
|
|
77
|
+
testing_with do
|
|
78
|
+
if composite?
|
|
79
|
+
assert_not_nil @klass.primary_keys
|
|
80
|
+
assert_equal @primary_keys.map {|key| key.to_sym}, @klass.primary_keys
|
|
81
|
+
assert_equal @klass.primary_keys, @klass.primary_key
|
|
82
|
+
assert_equal @primary_keys.map {|key| key.to_sym}.to_s, @klass.primary_key.to_s
|
|
83
|
+
else
|
|
84
|
+
assert_not_nil @klass.primary_key
|
|
85
|
+
assert_equal @primary_keys.first, @klass.primary_key.to_sym
|
|
86
|
+
assert_equal @primary_keys.first.to_s, @klass.primary_key.to_s
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
require 'fixtures/reference_type'
|
|
3
|
+
require 'fixtures/reference_code'
|
|
4
|
+
|
|
5
|
+
class TestMiscellaneous < ActiveSupport::TestCase
|
|
6
|
+
fixtures :reference_types, :reference_codes, :products
|
|
7
|
+
|
|
8
|
+
CLASSES = {
|
|
9
|
+
:single => {
|
|
10
|
+
:class => ReferenceType,
|
|
11
|
+
:primary_keys => :reference_type_id,
|
|
12
|
+
},
|
|
13
|
+
:dual => {
|
|
14
|
+
:class => ReferenceCode,
|
|
15
|
+
:primary_keys => [:reference_type_id, :reference_code],
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
def setup
|
|
20
|
+
self.class.classes = CLASSES
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_composite_class
|
|
24
|
+
testing_with do
|
|
25
|
+
assert_equal composite?, @klass.composite?
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_composite_instance
|
|
30
|
+
testing_with do
|
|
31
|
+
assert_equal composite?, @first.composite?
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_count
|
|
36
|
+
assert_equal 2, Product.count
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
require 'fixtures/reference_type'
|
|
3
|
+
require 'fixtures/reference_code'
|
|
4
|
+
require 'plugins/pagination'
|
|
5
|
+
|
|
6
|
+
class TestPagination < ActiveSupport::TestCase
|
|
7
|
+
fixtures :reference_types, :reference_codes
|
|
8
|
+
|
|
9
|
+
include ActionController::Pagination
|
|
10
|
+
DEFAULT_PAGE_SIZE = 2
|
|
11
|
+
|
|
12
|
+
attr_accessor :params
|
|
13
|
+
|
|
14
|
+
CLASSES = {
|
|
15
|
+
:single => {
|
|
16
|
+
:class => ReferenceType,
|
|
17
|
+
:primary_keys => :reference_type_id,
|
|
18
|
+
:table => :reference_types,
|
|
19
|
+
},
|
|
20
|
+
:dual => {
|
|
21
|
+
:class => ReferenceCode,
|
|
22
|
+
:primary_keys => [:reference_type_id, :reference_code],
|
|
23
|
+
:table => :reference_codes,
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
def setup
|
|
28
|
+
self.class.classes = CLASSES
|
|
29
|
+
@params = {}
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_paginate_all
|
|
33
|
+
testing_with do
|
|
34
|
+
@object_pages, @objects = paginate @klass_info[:table], :per_page => DEFAULT_PAGE_SIZE
|
|
35
|
+
assert_equal 2, @objects.length, "Each page should have #{DEFAULT_PAGE_SIZE} items"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|