composite_primary_keys 6.0.8 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/History.rdoc +2 -8
  3. data/lib/composite_primary_keys.rb +9 -11
  4. data/lib/composite_primary_keys/active_model/dirty.rb +14 -0
  5. data/lib/composite_primary_keys/associations/association_scope.rb +30 -32
  6. data/lib/composite_primary_keys/associations/has_and_belongs_to_many_association.rb +1 -2
  7. data/lib/composite_primary_keys/associations/has_many_association.rb +13 -14
  8. data/lib/composite_primary_keys/associations/has_many_through_association.rb +88 -0
  9. data/lib/composite_primary_keys/associations/join_dependency.rb +23 -15
  10. data/lib/composite_primary_keys/associations/join_dependency/join_association.rb +3 -3
  11. data/lib/composite_primary_keys/associations/preloader/association.rb +37 -21
  12. data/lib/composite_primary_keys/associations/preloader/belongs_to.rb +9 -3
  13. data/lib/composite_primary_keys/base.rb +0 -1
  14. data/lib/composite_primary_keys/composite_predicates.rb +11 -34
  15. data/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb +6 -5
  16. data/lib/composite_primary_keys/core.rb +28 -16
  17. data/lib/composite_primary_keys/model_schema.rb +15 -0
  18. data/lib/composite_primary_keys/nested_attributes.rb +8 -10
  19. data/lib/composite_primary_keys/persistence.rb +28 -29
  20. data/lib/composite_primary_keys/relation.rb +86 -16
  21. data/lib/composite_primary_keys/relation/finder_methods.rb +113 -59
  22. data/lib/composite_primary_keys/version.rb +2 -2
  23. data/test/abstract_unit.rb +7 -8
  24. data/test/fixtures/db_definitions/db2-create-tables.sql +13 -20
  25. data/test/fixtures/db_definitions/db2-drop-tables.sql +13 -14
  26. data/test/fixtures/db_definitions/mysql.sql +0 -7
  27. data/test/fixtures/db_definitions/oracle.drop.sql +0 -1
  28. data/test/fixtures/db_definitions/oracle.sql +0 -6
  29. data/test/fixtures/db_definitions/postgresql.sql +0 -7
  30. data/test/fixtures/db_definitions/sqlite.sql +24 -30
  31. data/test/fixtures/db_definitions/sqlserver.drop.sql +1 -4
  32. data/test/fixtures/db_definitions/sqlserver.sql +7 -16
  33. data/test/fixtures/dorm.rb +2 -2
  34. data/test/fixtures/suburb.rb +2 -2
  35. data/test/test_associations.rb +1 -2
  36. data/test/test_attribute_methods.rb +3 -3
  37. data/test/test_delete.rb +3 -5
  38. data/test/test_equal.rb +5 -5
  39. data/test/test_find.rb +2 -14
  40. data/test/test_predicates.rb +2 -2
  41. data/test/test_santiago.rb +1 -1
  42. data/test/test_serialize.rb +1 -1
  43. data/test/test_suite.rb +0 -1
  44. data/test/test_tutorial_example.rb +3 -3
  45. metadata +9 -32
  46. data/lib/composite_primary_keys/attribute_methods/primary_key.rb +0 -17
  47. data/lib/composite_primary_keys/composite_relation.rb +0 -44
  48. data/lib/composite_primary_keys/locking/optimistic.rb +0 -51
  49. data/test/fixtures/model_with_callback.rb +0 -39
  50. data/test/fixtures/model_with_callbacks.yml +0 -3
  51. data/test/test_callbacks.rb +0 -36
  52. data/test/test_dumpable.rb +0 -15
  53. data/test/test_optimistic.rb +0 -18
@@ -1,51 +0,0 @@
1
- module CompositePrimaryKeys
2
- module ActiveRecord
3
- module Locking
4
- module Optimistic
5
- private
6
- def _update_record(attribute_names = @attributes.keys) #:nodoc:
7
- return super unless locking_enabled?
8
- return 0 if attribute_names.empty?
9
-
10
- lock_col = self.class.locking_column
11
- previous_lock_value = send(lock_col).to_i
12
- increment_lock
13
-
14
- attribute_names += [lock_col]
15
- attribute_names.uniq!
16
-
17
- begin
18
- relation = self.class.unscoped
19
-
20
- if self.composite?
21
- stmt = relation.where(
22
- relation.cpk_id_predicate(relation.table, self.class.primary_key, id_was).and(
23
- relation.table[lock_col].eq(self.class.quote_value(previous_lock_value, column_for_attribute(lock_col)))
24
- )
25
- ).arel.compile_update(arel_attributes_with_values_for_update(attribute_names))
26
- else
27
- stmt = relation.where(
28
- relation.table[self.class.primary_key].eq(id).and(
29
- relation.table[lock_col].eq(self.class.quote_value(previous_lock_value, column_for_attribute(lock_col)))
30
- )
31
- ).arel.compile_update(arel_attributes_with_values_for_update(attribute_names))
32
- end
33
-
34
- affected_rows = self.class.connection.update stmt
35
-
36
- unless affected_rows == 1
37
- raise ::ActiveRecord::StaleObjectError.new(self, "update")
38
- end
39
-
40
- affected_rows
41
-
42
- # If something went wrong, revert the version.
43
- rescue Exception
44
- send(lock_col + '=', previous_lock_value)
45
- raise
46
- end
47
- end
48
- end
49
- end
50
- end
51
- end
@@ -1,39 +0,0 @@
1
- class ModelWithCallback < ActiveRecord::Base
2
- after_save :after_save_method
3
- before_save :before_save_method
4
- around_save :around_save_method
5
-
6
- after_create :after_create_method
7
- before_create :before_create_method
8
- around_create :around_create_method
9
-
10
- after_update :after_update_method
11
- before_update :before_update_method
12
- around_update :around_update_method
13
-
14
- after_destroy :after_destroy_method
15
- before_destroy :before_destroy_method
16
- around_destroy :around_destroy_method
17
-
18
- private
19
-
20
- # Save callbacks
21
- def after_save_method ; end
22
- def before_save_method ; end
23
- def around_save_method ; yield ; end
24
-
25
- # Create callbacks
26
- def after_create_method ; end
27
- def before_create_method ; end
28
- def around_create_method ; yield ;end
29
-
30
- # Update callbacks
31
- def after_update_method ; end
32
- def before_update_method ; end
33
- def around_update_method ; yield ; end
34
-
35
- # Destroy callbacks
36
- def after_destroy_method ; end
37
- def before_destroy_method ; end
38
- def around_destroy_method ; yield ; end
39
- end
@@ -1,3 +0,0 @@
1
- random:
2
- reference_type_id: 1
3
- reference_code: 1
@@ -1,36 +0,0 @@
1
- require File.expand_path('../abstract_unit', __FILE__)
2
-
3
- def has_callbacks(obj, action, options = {})
4
- obj.expects(:"before_#{action}_method")
5
- obj.expects(:"after_#{action}_method")
6
- obj.expects(:"around_#{action}_method")
7
- end
8
-
9
- class TestCallbacks < ActiveSupport::TestCase
10
- fixtures :model_with_callbacks
11
-
12
- def test_save_callbacks
13
- obj = ModelWithCallback.first
14
- has_callbacks(obj, :save)
15
- obj.save
16
- end
17
-
18
- def test_create_callbacks
19
- obj = ModelWithCallback.new
20
- has_callbacks(obj, :create)
21
- obj.save!
22
- end
23
-
24
- def test_update_callbacks
25
- obj = ModelWithCallback.first
26
- has_callbacks(obj, :update)
27
- obj.reference_code = 4
28
- obj.save!
29
- end
30
-
31
- def test_destroy_callbacks
32
- obj = ModelWithCallback.first
33
- has_callbacks(obj, :destroy)
34
- obj.destroy
35
- end
36
- end
@@ -1,15 +0,0 @@
1
- require File.expand_path('../abstract_unit', __FILE__)
2
-
3
- class TestDumpable < ActiveSupport::TestCase
4
- fixtures :articles, :readings, :users
5
-
6
- def test_marshal_with_simple_preload
7
- articles = Article.preload(:readings).where(id: 1).to_a
8
- assert_equal(Marshal.load(Marshal.dump(articles)), articles)
9
- end
10
-
11
- def test_marshal_with_comples_preload
12
- articles = Article.preload({ readings: :user }).where(id: 1).to_a
13
- assert_equal(Marshal.load(Marshal.dump(articles)), articles)
14
- end
15
- end
@@ -1,18 +0,0 @@
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