composite_primary_keys 8.1.6 → 9.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +5 -5
  2. data/History.rdoc +59 -7
  3. data/README.rdoc +62 -1
  4. data/Rakefile +4 -1
  5. data/lib/composite_primary_keys/arel/in.rb +6 -0
  6. data/lib/composite_primary_keys/arel/sqlserver.rb +36 -0
  7. data/lib/composite_primary_keys/arel/to_sql.rb +26 -0
  8. data/lib/composite_primary_keys/associations/association.rb +14 -12
  9. data/lib/composite_primary_keys/associations/association_scope.rb +22 -27
  10. data/lib/composite_primary_keys/associations/collection_association.rb +39 -8
  11. data/lib/composite_primary_keys/associations/has_many_association.rb +17 -40
  12. data/lib/composite_primary_keys/associations/has_many_through_association.rb +58 -58
  13. data/lib/composite_primary_keys/associations/join_dependency/join_association.rb +13 -11
  14. data/lib/composite_primary_keys/associations/join_dependency.rb +73 -56
  15. data/lib/composite_primary_keys/associations/preloader/association.rb +75 -73
  16. data/lib/composite_primary_keys/attribute_methods/primary_key.rb +13 -11
  17. data/lib/composite_primary_keys/attribute_methods/read.rb +18 -15
  18. data/lib/composite_primary_keys/attribute_methods/write.rb +21 -19
  19. data/lib/composite_primary_keys/attribute_methods.rb +6 -4
  20. data/lib/composite_primary_keys/autosave_association.rb +19 -54
  21. data/lib/composite_primary_keys/base.rb +18 -82
  22. data/lib/composite_primary_keys/composite_arrays.rb +9 -1
  23. data/lib/composite_primary_keys/composite_predicates.rb +1 -0
  24. data/lib/composite_primary_keys/connection_adapters/abstract_adapter.rb +10 -10
  25. data/lib/composite_primary_keys/connection_adapters/abstract_mysql_adapter.rb +5 -6
  26. data/lib/composite_primary_keys/connection_adapters/sqlite3_adapter.rb +23 -0
  27. data/lib/composite_primary_keys/core.rb +46 -45
  28. data/lib/composite_primary_keys/fixtures.rb +19 -17
  29. data/lib/composite_primary_keys/locking/optimistic.rb +53 -49
  30. data/lib/composite_primary_keys/nested_attributes.rb +60 -53
  31. data/lib/composite_primary_keys/persistence.rb +49 -41
  32. data/lib/composite_primary_keys/relation/batches.rb +35 -32
  33. data/lib/composite_primary_keys/relation/calculations.rb +3 -7
  34. data/lib/composite_primary_keys/relation/finder_methods.rb +122 -55
  35. data/lib/composite_primary_keys/relation/predicate_builder.rb +18 -29
  36. data/lib/composite_primary_keys/relation/query_methods.rb +25 -36
  37. data/lib/composite_primary_keys/relation/where_clause.rb +33 -0
  38. data/lib/composite_primary_keys/relation.rb +96 -43
  39. data/lib/composite_primary_keys/sanitization.rb +6 -15
  40. data/lib/composite_primary_keys/version.rb +3 -3
  41. data/lib/composite_primary_keys.rb +10 -19
  42. data/scripts/console.rb +48 -48
  43. data/scripts/txt2html +76 -76
  44. data/scripts/txt2js +65 -65
  45. data/tasks/databases/mysql.rake +17 -19
  46. data/tasks/databases/oracle.rake +29 -15
  47. data/tasks/databases/postgresql.rake +20 -29
  48. data/tasks/databases/sqlite.rake +25 -0
  49. data/tasks/databases/sqlserver.rake +32 -16
  50. data/tasks/website.rake +18 -18
  51. data/test/README_tests.rdoc +56 -56
  52. data/test/abstract_unit.rb +24 -18
  53. data/test/connections/connection_spec.rb +11 -2
  54. data/test/connections/databases.ci.yml +5 -4
  55. data/test/connections/databases.example.yml +19 -4
  56. data/test/connections/databases.yml +40 -30
  57. data/test/db_test.rb +52 -52
  58. data/test/fixtures/article.rb +1 -0
  59. data/test/fixtures/articles.yml +6 -6
  60. data/test/fixtures/capitol.rb +3 -3
  61. data/test/fixtures/capitols.yml +16 -16
  62. data/test/fixtures/comments.yml +15 -15
  63. data/test/fixtures/db_definitions/mysql.sql +16 -17
  64. data/test/fixtures/db_definitions/oracle.drop.sql +2 -0
  65. data/test/fixtures/db_definitions/oracle.sql +26 -17
  66. data/test/fixtures/db_definitions/postgresql.sql +2 -3
  67. data/test/fixtures/db_definitions/sqlite.sql +0 -1
  68. data/test/fixtures/db_definitions/sqlserver.sql +20 -35
  69. data/test/fixtures/department.rb +5 -5
  70. data/test/fixtures/departments.yml +15 -15
  71. data/test/fixtures/dorms.yml +4 -4
  72. data/test/fixtures/employee.rb +5 -7
  73. data/test/fixtures/employees.yml +1 -5
  74. data/test/fixtures/group.rb +2 -2
  75. data/test/fixtures/groups.yml +6 -6
  76. data/test/fixtures/hack.rb +4 -4
  77. data/test/fixtures/hacks.yml +2 -2
  78. data/test/fixtures/membership_status.rb +2 -2
  79. data/test/fixtures/product.rb +9 -9
  80. data/test/fixtures/product_tariff.rb +5 -5
  81. data/test/fixtures/products.yml +11 -11
  82. data/test/fixtures/reading.rb +4 -4
  83. data/test/fixtures/readings.yml +10 -10
  84. data/test/fixtures/reference_code_using_composite_key_alias.rb +8 -8
  85. data/test/fixtures/reference_code_using_simple_key_alias.rb +8 -8
  86. data/test/fixtures/reference_codes.yml +28 -28
  87. data/test/fixtures/reference_type.rb +1 -1
  88. data/test/fixtures/reference_types.yml +9 -9
  89. data/test/fixtures/restaurant.rb +9 -9
  90. data/test/fixtures/restaurants.yml +14 -14
  91. data/test/fixtures/restaurants_suburbs.yml +10 -10
  92. data/test/fixtures/room.rb +11 -11
  93. data/test/fixtures/room_assignment.rb +13 -13
  94. data/test/fixtures/room_assignments.yml +24 -24
  95. data/test/fixtures/room_attribute.rb +2 -2
  96. data/test/fixtures/room_attribute_assignment.rb +4 -4
  97. data/test/fixtures/room_attribute_assignments.yml +4 -4
  98. data/test/fixtures/room_attributes.yml +2 -2
  99. data/test/fixtures/rooms.yml +12 -12
  100. data/test/fixtures/seat.rb +5 -5
  101. data/test/fixtures/seats.yml +8 -8
  102. data/test/fixtures/street.rb +2 -2
  103. data/test/fixtures/streets.yml +16 -16
  104. data/test/fixtures/student.rb +3 -3
  105. data/test/fixtures/students.yml +15 -15
  106. data/test/fixtures/suburbs.yml +14 -14
  107. data/test/fixtures/tariff.rb +1 -1
  108. data/test/fixtures/tariffs.yml +14 -14
  109. data/test/fixtures/user.rb +0 -1
  110. data/test/plugins/pagination.rb +405 -405
  111. data/test/plugins/pagination_helper.rb +135 -135
  112. data/test/setup.rb +50 -50
  113. data/test/test_aliases.rb +18 -18
  114. data/test/test_associations.rb +18 -17
  115. data/test/test_composite_arrays.rb +24 -24
  116. data/test/test_counter_cache.rb +30 -30
  117. data/test/test_create.rb +14 -6
  118. data/test/test_delete.rb +36 -34
  119. data/test/test_dup.rb +37 -37
  120. data/test/test_exists.rb +39 -39
  121. data/test/test_find.rb +16 -4
  122. data/test/test_habtm.rb +27 -3
  123. data/test/test_miscellaneous.rb +32 -32
  124. data/test/test_nested_attributes.rb +6 -6
  125. data/test/test_pagination.rb +35 -35
  126. data/test/test_polymorphic.rb +0 -7
  127. data/test/test_predicates.rb +20 -20
  128. data/test/test_preload.rb +94 -0
  129. data/test/test_suite.rb +1 -1
  130. data/test/test_update.rb +10 -7
  131. data/test/test_validations.rb +13 -13
  132. metadata +30 -39
  133. data/README_DB2.rdoc +0 -33
  134. data/lib/composite_primary_keys/arel/visitors/to_sql.rb +0 -36
  135. data/lib/composite_primary_keys/associations/singular_association.rb +0 -18
  136. data/lib/composite_primary_keys/attribute_methods/dirty.rb +0 -29
  137. data/lib/composite_primary_keys/attribute_set/builder.rb +0 -20
  138. data/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb +0 -70
  139. data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +0 -19
  140. data/lib/composite_primary_keys/dirty.rb +0 -19
  141. data/lib/composite_primary_keys/validations/uniqueness.rb +0 -41
  142. data/tasks/databases/oracle_enhanced.rake +0 -27
  143. data/tasks/databases/sqlite3.rake +0 -27
  144. data/test/connections/native_ibm_db/connection.rb +0 -19
  145. data/test/connections/native_mysql/connection.rb +0 -17
  146. data/test/connections/native_oracle/connection.rb +0 -11
  147. data/test/connections/native_oracle_enhanced/connection.rb +0 -16
  148. data/test/connections/native_postgresql/connection.rb +0 -13
  149. data/test/connections/native_sqlite3/connection.rb +0 -9
  150. data/test/connections/native_sqlserver/connection.rb +0 -11
  151. data/test/fixtures/db_definitions/sqlserver.drop.sql +0 -92
  152. data/test/test_delete_all.rb +0 -35
  153. data/test/test_find_in_batches.rb +0 -30
data/test/test_delete.rb CHANGED
@@ -4,50 +4,41 @@ class TestDelete < ActiveSupport::TestCase
4
4
  fixtures :articles, :departments, :employees, :products, :tariffs, :product_tariffs,
5
5
  :reference_types, :reference_codes
6
6
 
7
- CLASSES = {
8
- :single => {
9
- :class => ReferenceType,
10
- :primary_keys => :reference_type_id,
11
- },
12
- :dual => {
13
- :class => ReferenceCode,
14
- :primary_keys => [:reference_type_id, :reference_code],
15
- },
16
- }
7
+ def test_delete_one
8
+ assert_equal(5, ReferenceCode.count)
9
+ ReferenceCode.first.delete
10
+ assert_equal(4, ReferenceCode.count)
11
+ end
17
12
 
18
- def setup
19
- self.class.classes = CLASSES
13
+ def test_delete_one_with_id
14
+ assert_equal(5, ReferenceCode.count)
15
+ ReferenceCode.delete(ReferenceCode.first.id)
16
+ assert_equal(4, ReferenceCode.count)
20
17
  end
21
18
 
22
19
  def test_destroy_one
23
- testing_with do
24
- assert @first.destroy
25
- end
20
+ assert_equal(5, ReferenceCode.count)
21
+ ReferenceCode.first.destroy
22
+ assert_equal(4, ReferenceCode.count)
26
23
  end
27
24
 
28
- def test_destroy_one_alone_via_class
29
- testing_with do
30
- assert @klass.destroy(@first.id)
31
- end
25
+ def test_delete_all
26
+ refute_empty(ReferenceCode.all)
27
+ ReferenceCode.delete_all
28
+ assert_empty(ReferenceCode.all)
32
29
  end
33
30
 
34
- def test_delete_one_alone
35
- testing_with do
36
- assert @klass.delete(@first.id)
37
- end
38
- end
31
+ def test_delete_all_with_join
32
+ department = departments(:accounting)
39
33
 
40
- def test_delete_many
41
- testing_with do
42
- to_delete = @klass.limit(2)
43
- assert_equal 2, to_delete.length
44
- end
45
- end
34
+ assert_equal(4, Department.count)
46
35
 
47
- def test_delete_all
48
- testing_with do
49
- @klass.delete_all
50
- end
36
+ Department.joins(:employees).
37
+ where('departments.department_id = ?', department.department_id).
38
+ where('departments.location_id = ?', department.location_id).
39
+ delete_all
40
+
41
+ assert_equal(3, Department.count)
51
42
  end
52
43
 
53
44
  def test_clear_association
@@ -71,6 +62,17 @@ class TestDelete < ActiveSupport::TestCase
71
62
  assert_equal 1, department.employees.size, "After delete and a reload from DB employee count should be 1."
72
63
  end
73
64
 
65
+ def test_has_many_replace
66
+ tariff = tariffs(:flat)
67
+ assert_equal(1, tariff.product_tariffs.length)
68
+
69
+ tariff.product_tariffs = [product_tariffs(:first_free), product_tariffs(:second_free)]
70
+ tariff.reload
71
+
72
+ assert_equal(2, tariff.product_tariffs.length)
73
+ refute(tariff.product_tariffs.include?(tariff))
74
+ end
75
+
74
76
  def test_destroy_has_one
75
77
  # In this case the association is a has_one with
76
78
  # dependent set to :destroy
data/test/test_dup.rb CHANGED
@@ -1,38 +1,38 @@
1
- require File.expand_path('../abstract_unit', __FILE__)
2
-
3
- class TestClone < ActiveSupport::TestCase
4
- fixtures :reference_types, :reference_codes
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_dup
22
- testing_with do
23
- clone = @first.dup
24
-
25
- remove_keys = Array(@klass.primary_key).map(&:to_s)
26
- remove_keys << Array(@klass.primary_key) # Rails 4 adds the PK to the attributes, so we want to remove it as well
27
- assert_equal(@first.attributes.except(*remove_keys), clone.attributes.except(*remove_keys))
28
-
29
- if composite?
30
- @klass.primary_key.each do |key|
31
- assert_nil(clone[key], "Primary key '#{key}' should be nil")
32
- end
33
- else
34
- assert_nil(clone[@klass.primary_key], "Sole primary key should be nil")
35
- end
36
- end
37
- end
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
+
3
+ class TestClone < ActiveSupport::TestCase
4
+ fixtures :reference_types, :reference_codes
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_dup
22
+ testing_with do
23
+ clone = @first.dup
24
+
25
+ remove_keys = Array(@klass.primary_key).map(&:to_s)
26
+ remove_keys << Array(@klass.primary_key) # Rails 4 adds the PK to the attributes, so we want to remove it as well
27
+ assert_equal(@first.attributes.except(*remove_keys), clone.attributes.except(*remove_keys))
28
+
29
+ if composite?
30
+ @klass.primary_key.each do |key|
31
+ assert_nil(clone[key], "Primary key '#{key}' should be nil")
32
+ end
33
+ else
34
+ assert_nil(clone[@klass.primary_key], "Sole primary key should be nil")
35
+ end
36
+ end
37
+ end
38
38
  end
data/test/test_exists.rb CHANGED
@@ -1,40 +1,40 @@
1
- require File.expand_path('../abstract_unit', __FILE__)
2
-
3
- class TestExists < ActiveSupport::TestCase
4
- fixtures :articles, :departments, :capitols
5
-
6
- def test_id
7
- assert(Article.exists?(1))
8
- assert(!Article.exists?(-1))
9
- end
10
-
11
- def test_array
12
- assert(Article.exists?(['name = ?', 'Article One']))
13
- assert(!Article.exists?(['name = ?', 'Article -1']))
14
- end
15
-
16
- def test_hash
17
- assert(Article.exists?('name' => 'Article One'))
18
- assert(!Article.exists?('name' => 'Article -1'))
19
- end
20
-
21
- def test_cpk_id
22
- assert(Department.exists?(CompositePrimaryKeys::CompositeKeys.new([1,1])))
23
- assert(!Department.exists?(CompositePrimaryKeys::CompositeKeys.new([1,-1])))
24
- end
25
-
26
- def test_cpk_array_id
27
- assert(Department.exists?([1,1]))
28
- assert(!Department.exists?([1,-1]))
29
- end
30
-
31
- def test_cpk_array_condition
32
- assert(Department.exists?(['department_id = ? and location_id = ?', 1, 1]))
33
- assert(!Department.exists?(['department_id = ? and location_id = ?', 1, -1]))
34
- end
35
-
36
- def test_cpk_array_string_id
37
- assert(Capitol.exists?(['The Netherlands', 'Amsterdam']))
38
- assert(!Capitol.exists?(['The Netherlands', 'Paris']))
39
- end
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
+
3
+ class TestExists < ActiveSupport::TestCase
4
+ fixtures :articles, :departments, :capitols
5
+
6
+ def test_id
7
+ assert(Article.exists?(1))
8
+ assert(!Article.exists?(-1))
9
+ end
10
+
11
+ def test_array
12
+ assert(Article.exists?(['name = ?', 'Article One']))
13
+ assert(!Article.exists?(['name = ?', 'Article -1']))
14
+ end
15
+
16
+ def test_hash
17
+ assert(Article.exists?('name' => 'Article One'))
18
+ assert(!Article.exists?('name' => 'Article -1'))
19
+ end
20
+
21
+ def test_cpk_id
22
+ assert(Department.exists?(CompositePrimaryKeys::CompositeKeys.new([1,1])))
23
+ assert(!Department.exists?(CompositePrimaryKeys::CompositeKeys.new([1,-1])))
24
+ end
25
+
26
+ def test_cpk_array_id
27
+ assert(Department.exists?([1,1]))
28
+ assert(!Department.exists?([1,-1]))
29
+ end
30
+
31
+ def test_cpk_array_condition
32
+ assert(Department.exists?(['department_id = ? and location_id = ?', 1, 1]))
33
+ assert(!Department.exists?(['department_id = ? and location_id = ?', 1, -1]))
34
+ end
35
+
36
+ def test_cpk_array_string_id
37
+ assert(Capitol.exists?(['The Netherlands', 'Amsterdam']))
38
+ assert(!Capitol.exists?(['The Netherlands', 'Paris']))
39
+ end
40
40
  end
data/test/test_find.rb CHANGED
@@ -62,10 +62,6 @@ class TestFind < ActiveSupport::TestCase
62
62
  ReferenceCode.find(['999', '999'])
63
63
  end
64
64
 
65
- connection = ActiveRecord::Base.connection
66
- ref_type_quoted = "#{connection.quote_table_name('reference_codes')}.#{connection.quote_column_name('reference_type_id')}"
67
- ref_code_quoted = "#{connection.quote_table_name('reference_codes')}.#{connection.quote_column_name('reference_code')}"
68
-
69
65
  expected = "Couldn't find all ReferenceCodes with 'reference_type_id,reference_code': (999, 999) (found 0 results, but was looking for 1)"
70
66
  assert_equal(with_quoted_identifiers(expected), error.message)
71
67
  end
@@ -87,12 +83,28 @@ class TestFind < ActiveSupport::TestCase
87
83
  end
88
84
  end
89
85
 
86
+ def test_in_batches_of_1
87
+ num_found = 0
88
+ Department.in_batches(of: 1) do |batch|
89
+ batch.each do |dept|
90
+ num_found += 1
91
+ end
92
+ end
93
+ assert_equal(Department.count, num_found)
94
+ end
95
+
90
96
  def test_expand
91
97
  department = departments(:engineering)
92
98
  employees = Employee.where(:department => department)
93
99
  assert_equal(2, employees.count)
94
100
  end
95
101
 
102
+ def test_expand_with_multiple
103
+ departments = Department.all
104
+ employees = Employee.where(:department => departments)
105
+ assert_equal(4, employees.count)
106
+ end
107
+
96
108
  def test_find_one_with_params_id
97
109
  params_id = ReferenceCode.find([1,3]).to_param
98
110
  assert_equal params_id, "1,3"
data/test/test_habtm.rb CHANGED
@@ -1,7 +1,31 @@
1
1
  require File.expand_path('../abstract_unit', __FILE__)
2
2
 
3
3
  class TestHabtm < ActiveSupport::TestCase
4
- fixtures :suburbs, :restaurants, :restaurants_suburbs, :products
4
+ fixtures :suburbs, :restaurants, :restaurants_suburbs, :products, :groups, :employees
5
+
6
+ def test_no_cpk
7
+ # This test makes sure we don't break anything in standard rails by using CPK
8
+ groups = Group.all
9
+
10
+ # First test records
11
+ employee = Employee.first
12
+ assert_equal(0, employee.groups.length)
13
+ employee.groups = groups
14
+ employee.reload
15
+ assert_equal(groups, employee.groups)
16
+ end
17
+
18
+ def test_no_cpk_ids
19
+ # This test makes sure we don't break anything in standard rails by using CPK
20
+ groups = Group.all
21
+
22
+ employee = Employee.last
23
+ assert_equal(0, employee.groups.length)
24
+ employee.group_ids = groups.map {|group| group.id}
25
+ employee.group_ids = [groups.first.id]
26
+ employee.reload
27
+ assert_equal([groups.first], employee.groups)
28
+ end
5
29
 
6
30
  def test_has_and_belongs_to_many
7
31
  @restaurant = Restaurant.find([1,1])
@@ -42,7 +66,7 @@ class TestHabtm < ActiveSupport::TestCase
42
66
  product = products(:first_product)
43
67
  subway = restaurants(:subway_one)
44
68
  product.restaurants << subway
45
-
69
+
46
70
  # reload
47
71
  # test positive
48
72
  product = products(:first_product)
@@ -106,7 +130,7 @@ class TestHabtm < ActiveSupport::TestCase
106
130
  # an array it will be evaluated as 3[0], which is 1, which would
107
131
  # delete product_one's associations rather than product_three's
108
132
  product_three.restaurants.clear
109
-
133
+
110
134
  # reload to force reload of associations
111
135
  product_one = Product.find(1)
112
136
  assert_equal 2, product_one.restaurants.size
@@ -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
@@ -8,7 +8,7 @@ class TestNestedAttributes < ActiveSupport::TestCase
8
8
  code_id = 1001
9
9
 
10
10
  reference_type = reference_types(:name_prefix)
11
- reference_type.update_attribute :reference_codes_attributes, [{
11
+ reference_type.update_attributes :reference_codes_attributes => [{
12
12
  :reference_code => code_id,
13
13
  :code_label => 'XX',
14
14
  :abbreviation => 'Xx'
@@ -20,7 +20,7 @@ class TestNestedAttributes < ActiveSupport::TestCase
20
20
  code_id = 1002
21
21
 
22
22
  reference_type = reference_types(:name_prefix)
23
- reference_type.update_attribute :reference_codes_attributes, [{
23
+ reference_type.update_attributes :reference_codes_attributes => [{
24
24
  :reference_code => code_id,
25
25
  :code_label => 'XX',
26
26
  :abbreviation => 'Xx'
@@ -28,7 +28,7 @@ class TestNestedAttributes < ActiveSupport::TestCase
28
28
 
29
29
  reference_code = ReferenceCode.find_by_reference_code(code_id)
30
30
  cpk = CompositePrimaryKeys::CompositeKeys[reference_type.reference_type_id, code_id]
31
- reference_type.update_attribute :reference_codes_attributes, [{
31
+ reference_type.update_attributes :reference_codes_attributes => [{
32
32
  :id => cpk,
33
33
  :code_label => 'AAA',
34
34
  :abbreviation => 'Aaa'
@@ -71,7 +71,7 @@ class TestNestedAttributes < ActiveSupport::TestCase
71
71
  platform = 'instagram'
72
72
 
73
73
  topic = topics(:music)
74
- topic.update_attribute :topic_sources_attributes, [{
74
+ topic.update_attributes :topic_sources_attributes => [{
75
75
  :platform => platform,
76
76
  :keywords => 'funk'
77
77
  }]
@@ -82,7 +82,7 @@ class TestNestedAttributes < ActiveSupport::TestCase
82
82
  platform = 'instagram'
83
83
 
84
84
  topic = topics(:music)
85
- topic.update_attribute :topic_sources_attributes, [{
85
+ topic.update_attributes :topic_sources_attributes => [{
86
86
  :platform => platform,
87
87
  :keywords => 'funk'
88
88
  }]
@@ -90,7 +90,7 @@ class TestNestedAttributes < ActiveSupport::TestCase
90
90
 
91
91
  topic_source = TopicSource.find_by_platform(platform)
92
92
  cpk = CompositePrimaryKeys::CompositeKeys[topic.id, platform]
93
- topic.update_attribute :topic_sources_attributes, [{
93
+ topic.update_attributes :topic_sources_attributes => [{
94
94
  :id => cpk,
95
95
  :keywords => 'jazz'
96
96
  }]
@@ -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
@@ -24,11 +24,4 @@ class TestPolymorphic < ActiveSupport::TestCase
24
24
  user = users(:santiago)
25
25
  assert_equal(['andrew'], user.hacks.collect { |a| a.name }.sort)
26
26
  end
27
-
28
- def test_has_many_through_with_polymorphic_source
29
- user = users(:santiago)
30
- user_to_associate = users(:drnic)
31
- user.update_attributes :persons => [user_to_associate]
32
- assert_equal user.persons, [user_to_associate]
33
- end
34
27
  end
@@ -1,12 +1,12 @@
1
1
  require File.expand_path('../abstract_unit', __FILE__)
2
2
 
3
- class TestEqual < ActiveSupport::TestCase
3
+ class TestPredicates < ActiveSupport::TestCase
4
4
  fixtures :departments
5
5
 
6
6
  include CompositePrimaryKeys::Predicates
7
7
 
8
8
  def test_or
9
- dep = Arel::Table.new(:departments)
9
+ dep = Department.arel_table
10
10
 
11
11
  predicates = Array.new
12
12
 
@@ -27,7 +27,7 @@ class TestEqual < ActiveSupport::TestCase
27
27
 
28
28
  predicates = Array.new
29
29
 
30
- number_of_predicates = 30000 # This should really be big
30
+ number_of_predicates = 3000 # This should really be big
31
31
  number_of_predicates.times do |i|
32
32
  predicates << dep[:id].eq(i)
33
33
  end
@@ -41,20 +41,20 @@ class TestEqual < ActiveSupport::TestCase
41
41
  assert_equal(with_quoted_identifiers(expected), pred.to_sql)
42
42
  end
43
43
 
44
- # def test_and
45
- # dep = Arel::Table.new(:departments)
46
- #
47
- # predicates = Array.new
48
- #
49
- # 3.times do |i|
50
- # predicates << dep[:id].eq(i)
51
- # end
52
- #
53
- # connection = ActiveRecord::Base.connection
54
- # quoted = "#{connection.quote_table_name('departments')}.#{connection.quote_column_name('id')}"
55
- # expected = "#{quoted} = 0 AND #{quoted} = 1 AND #{quoted} = 2"
56
- #
57
- # pred = cpk_and_predicate(predicates)
58
- # assert_equal(with_quoted_identifiers(expected), pred.to_sql)
59
- # end
60
- end
44
+ def test_and
45
+ dep = Department.arel_table
46
+
47
+ predicates = Array.new
48
+
49
+ 3.times do |i|
50
+ predicates << dep[:id].eq(i)
51
+ end
52
+
53
+ connection = ActiveRecord::Base.connection
54
+ quoted = "#{connection.quote_table_name('departments')}.#{connection.quote_column_name('id')}"
55
+ expected = "#{quoted} = 0 AND #{quoted} = 1 AND #{quoted} = 2"
56
+
57
+ pred = cpk_and_predicate(predicates)
58
+ assert_equal(with_quoted_identifiers(expected), pred.to_sql)
59
+ end
60
+ end