mingusbabcock-composite_primary_keys 2.2.2 → 2.2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +156 -0
- data/Manifest.txt +122 -0
- data/README.txt +41 -0
- data/README_DB2.txt +33 -0
- data/Rakefile +65 -0
- data/init.rb +2 -0
- data/install.rb +30 -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/postgresql.rb +13 -0
- data/lib/adapter_helper/sqlite3.rb +13 -0
- data/lib/composite_primary_keys.rb +56 -0
- data/lib/composite_primary_keys/association_preload.rb +253 -0
- data/lib/composite_primary_keys/associations.rb +428 -0
- data/lib/composite_primary_keys/attribute_methods.rb +84 -0
- data/lib/composite_primary_keys/base.rb +341 -0
- data/lib/composite_primary_keys/calculations.rb +69 -0
- data/lib/composite_primary_keys/composite_arrays.rb +30 -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/postgresql_adapter.rb +53 -0
- data/lib/composite_primary_keys/connection_adapters/sqlite3_adapter.rb +15 -0
- data/lib/composite_primary_keys/fixtures.rb +8 -0
- data/lib/composite_primary_keys/migration.rb +20 -0
- data/lib/composite_primary_keys/reflection.rb +19 -0
- data/lib/composite_primary_keys/version.rb +8 -0
- data/loader.rb +24 -0
- data/local/database_connections.rb.sample +10 -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 +26 -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 +94 -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_postgresql/connection.rb +9 -0
- data/test/connections/native_sqlite/connection.rb +9 -0
- data/test/fixtures/article.rb +5 -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 +174 -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 +199 -0
- data/test/fixtures/db_definitions/sqlite.sql +160 -0
- data/test/fixtures/department.rb +5 -0
- data/test/fixtures/departments.yml +3 -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/membership.rb +7 -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/street.rb +3 -0
- data/test/fixtures/streets.yml +15 -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 +160 -0
- data/test/test_attribute_methods.rb +22 -0
- data/test/test_attributes.rb +84 -0
- data/test/test_clone.rb +34 -0
- data/test/test_composite_arrays.rb +51 -0
- data/test/test_create.rb +68 -0
- data/test/test_delete.rb +96 -0
- data/test/test_dummy.rb +28 -0
- data/test/test_exists.rb +29 -0
- data/test/test_find.rb +73 -0
- data/test/test_ids.rb +97 -0
- data/test/test_miscellaneous.rb +39 -0
- data/test/test_pagination.rb +38 -0
- data/test/test_polymorphic.rb +31 -0
- data/test/test_santiago.rb +27 -0
- data/test/test_tutorial_examle.rb +26 -0
- data/test/test_update.rb +40 -0
- data/website/index.html +199 -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 +180 -18
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 < Test::Unit::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,96 @@
|
|
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 < Test::Unit::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
|
+
assert true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_destroy_one_via_class
|
33
|
+
testing_with do
|
34
|
+
assert @klass.destroy(*@first.id)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_destroy_one_alone_via_class
|
39
|
+
testing_with do
|
40
|
+
assert @klass.destroy(@first.id)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_delete_one
|
45
|
+
testing_with do
|
46
|
+
assert @klass.delete(*@first.id) if composite?
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_delete_one_alone
|
51
|
+
testing_with do
|
52
|
+
assert @klass.delete(@first.id)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_delete_many
|
57
|
+
testing_with do
|
58
|
+
to_delete = @klass.find(:all)[0..1]
|
59
|
+
assert_equal 2, to_delete.length
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_delete_all
|
64
|
+
testing_with do
|
65
|
+
@klass.delete_all
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_clear_association
|
70
|
+
department = Department.find(1,1)
|
71
|
+
assert_equal 2, department.employees.size, "Before clear employee count should be 2."
|
72
|
+
department.employees.clear
|
73
|
+
assert_equal 0, department.employees.size, "After clear employee count should be 0."
|
74
|
+
department.reload
|
75
|
+
assert_equal 0, department.employees.size, "After clear and a reload from DB employee count should be 0."
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_delete_association
|
79
|
+
department = Department.find(1,1)
|
80
|
+
assert_equal 2, department.employees.size , "Before delete employee count should be 2."
|
81
|
+
first_employee = department.employees[0]
|
82
|
+
department.employees.delete(first_employee)
|
83
|
+
assert_equal 1, department.employees.size, "After delete employee count should be 1."
|
84
|
+
department.reload
|
85
|
+
assert_equal 1, department.employees.size, "After delete and a reload from DB employee count should be 1."
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_delete_records_for_has_many_association_with_composite_primary_key
|
89
|
+
reference_type = ReferenceType.find(1)
|
90
|
+
codes_to_delete = reference_type.reference_codes[0..1]
|
91
|
+
assert_equal 3, reference_type.reference_codes.size, "Before deleting records reference_code count should be 3."
|
92
|
+
reference_type.reference_codes.delete_records(codes_to_delete)
|
93
|
+
reference_type.reload
|
94
|
+
assert_equal 1, reference_type.reference_codes.size, "After deleting 2 records and a reload from DB reference_code count should be 1."
|
95
|
+
end
|
96
|
+
end
|
data/test/test_dummy.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
require 'fixtures/reference_type'
|
3
|
+
require 'fixtures/reference_code'
|
4
|
+
|
5
|
+
class TestDummy < Test::Unit::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
|
+
}
|
18
|
+
|
19
|
+
def setup
|
20
|
+
self.class.classes = classes
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_truth
|
24
|
+
testing_with do
|
25
|
+
assert true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/test/test_exists.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
require 'fixtures/article'
|
3
|
+
require 'fixtures/department'
|
4
|
+
|
5
|
+
class TestExists < Test::Unit::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_string
|
17
|
+
assert Department.exists?('1,1,')
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_composite_key_exists_giving_ids_as_array
|
21
|
+
assert Department.exists?([1,1])
|
22
|
+
assert_equal(false, Department.exists?([1111,1111]))
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_composite_key_exists_giving_ids_as_condition
|
26
|
+
assert Department.exists?(['department_id = ? and location_id = ?', 1, 1])
|
27
|
+
assert_equal(false, Department.exists?(['department_id = ? and location_id = ?', 11111, 11111]))
|
28
|
+
end
|
29
|
+
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 < Test::Unit::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,97 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
require 'fixtures/reference_type'
|
3
|
+
require 'fixtures/reference_code'
|
4
|
+
|
5
|
+
class TestIds < Test::Unit::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_composite_where_clause
|
50
|
+
testing_with do
|
51
|
+
where = 'reference_codes.reference_type_id=1 AND reference_codes.reference_code=2) OR (reference_codes.reference_type_id=2 AND reference_codes.reference_code=2'
|
52
|
+
assert_equal(where, @klass.composite_where_clause([[1, 2], [2, 2]])) if @key_test == :dual
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_set_ids_string
|
57
|
+
testing_with do
|
58
|
+
array = @primary_keys.collect {|key| 5}
|
59
|
+
expected = composite? ? array.to_composite_keys : array.first
|
60
|
+
@first.id = expected.to_s
|
61
|
+
assert_equal expected, @first.id
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_set_ids_array
|
66
|
+
testing_with do
|
67
|
+
array = @primary_keys.collect {|key| 5}
|
68
|
+
expected = composite? ? array.to_composite_keys : array.first
|
69
|
+
@first.id = expected
|
70
|
+
assert_equal expected, @first.id
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_set_ids_comp
|
75
|
+
testing_with do
|
76
|
+
array = @primary_keys.collect {|key| 5}
|
77
|
+
expected = composite? ? array.to_composite_keys : array.first
|
78
|
+
@first.id = expected
|
79
|
+
assert_equal expected, @first.id
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_primary_keys
|
84
|
+
testing_with do
|
85
|
+
if composite?
|
86
|
+
assert_not_nil @klass.primary_keys
|
87
|
+
assert_equal @primary_keys.map {|key| key.to_sym}, @klass.primary_keys
|
88
|
+
assert_equal @klass.primary_keys, @klass.primary_key
|
89
|
+
else
|
90
|
+
assert_not_nil @klass.primary_key
|
91
|
+
assert_equal @primary_keys, [@klass.primary_key.to_sym]
|
92
|
+
end
|
93
|
+
assert_equal @primary_keys.join(','), @klass.primary_key.to_s
|
94
|
+
# Need a :primary_keys should be Array with to_s overridden
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
require 'fixtures/reference_type'
|
3
|
+
require 'fixtures/reference_code'
|
4
|
+
|
5
|
+
class TestMiscellaneous < Test::Unit::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 < Test::Unit::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
|