tenacity 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/.gitignore +3 -0
  2. data/EXTEND.rdoc +11 -1
  3. data/README.rdoc +4 -1
  4. data/Rakefile +20 -9
  5. data/history.txt +21 -0
  6. data/lib/tenacity.rb +12 -4
  7. data/lib/tenacity/associates_proxy.rb +67 -0
  8. data/lib/tenacity/association.rb +19 -6
  9. data/lib/tenacity/associations/has_many.rb +6 -0
  10. data/lib/tenacity/class_methods.rb +52 -1
  11. data/lib/tenacity/instance_methods.rb +7 -3
  12. data/lib/tenacity/orm_ext/activerecord.rb +30 -13
  13. data/lib/tenacity/orm_ext/couchrest.rb +140 -0
  14. data/lib/tenacity/orm_ext/datamapper.rb +139 -0
  15. data/lib/tenacity/orm_ext/mongo_mapper.rb +88 -80
  16. data/lib/tenacity/orm_ext/mongoid.rb +108 -0
  17. data/lib/tenacity/orm_ext/sequel.rb +134 -0
  18. data/lib/tenacity/version.rb +1 -1
  19. data/tenacity.gemspec +14 -3
  20. data/test/association_features/belongs_to_test.rb +42 -0
  21. data/test/association_features/has_many_test.rb +110 -0
  22. data/test/association_features/has_one_test.rb +41 -0
  23. data/test/associations/belongs_to_test.rb +36 -127
  24. data/test/associations/has_many_test.rb +77 -196
  25. data/test/associations/has_one_test.rb +22 -84
  26. data/test/core/classmethods_test.rb +24 -22
  27. data/test/fixtures/active_record_has_many_target.rb +10 -0
  28. data/test/fixtures/active_record_has_one_target.rb +10 -0
  29. data/test/fixtures/{active_record_nuts.rb → active_record_nut.rb} +0 -0
  30. data/test/fixtures/active_record_object.rb +17 -0
  31. data/test/fixtures/couch_rest_door.rb +0 -2
  32. data/test/fixtures/couch_rest_has_many_target.rb +12 -0
  33. data/test/fixtures/couch_rest_has_one_target.rb +12 -0
  34. data/test/fixtures/couch_rest_object.rb +19 -0
  35. data/test/fixtures/couch_rest_windshield.rb +0 -2
  36. data/test/fixtures/data_mapper_has_many_target.rb +19 -0
  37. data/test/fixtures/data_mapper_has_one_target.rb +19 -0
  38. data/test/fixtures/data_mapper_object.rb +20 -0
  39. data/test/fixtures/mongo_mapper_ash_tray.rb +0 -2
  40. data/test/fixtures/mongo_mapper_dashboard.rb +0 -2
  41. data/test/fixtures/mongo_mapper_has_many_target.rb +11 -0
  42. data/test/fixtures/mongo_mapper_has_one_target.rb +11 -0
  43. data/test/fixtures/mongo_mapper_object.rb +18 -0
  44. data/test/fixtures/mongo_mapper_vent.rb +0 -2
  45. data/test/fixtures/mongo_mapper_wheel.rb +0 -2
  46. data/test/fixtures/mongoid_has_many_target.rb +13 -0
  47. data/test/fixtures/mongoid_has_one_target.rb +13 -0
  48. data/test/fixtures/mongoid_object.rb +20 -0
  49. data/test/fixtures/sequel_has_many_target.rb +10 -0
  50. data/test/fixtures/sequel_has_one_target.rb +10 -0
  51. data/test/fixtures/sequel_object.rb +17 -0
  52. data/test/helpers/active_record_test_helper.rb +51 -0
  53. data/test/helpers/data_mapper_test_helper.rb +44 -0
  54. data/test/helpers/mongoid_test_helper.rb +21 -0
  55. data/test/helpers/sequel_test_helper.rb +60 -0
  56. data/test/orm_ext/activerecord_test.rb +55 -35
  57. data/test/orm_ext/couchrest_test.rb +66 -46
  58. data/test/orm_ext/datamapper_test.rb +112 -0
  59. data/test/orm_ext/mongo_mapper_test.rb +64 -44
  60. data/test/orm_ext/mongoid_test.rb +121 -0
  61. data/test/orm_ext/sequel_test.rb +113 -0
  62. data/test/test_helper.rb +87 -11
  63. metadata +159 -59
  64. data/lib/tenacity/orm_ext/couchrest/couchrest_extended_document.rb +0 -42
  65. data/lib/tenacity/orm_ext/couchrest/couchrest_model.rb +0 -44
  66. data/lib/tenacity/orm_ext/couchrest/tenacity_class_methods.rb +0 -43
  67. data/lib/tenacity/orm_ext/couchrest/tenacity_instance_methods.rb +0 -21
  68. data/test/fixtures/couch_rest_radio.rb +0 -10
  69. data/test/fixtures/mongo_mapper_button.rb +0 -6
@@ -2,51 +2,53 @@ require 'test_helper'
2
2
 
3
3
  class ClassmethodsTest < Test::Unit::TestCase
4
4
 
5
- context "A class with a belongs_to :active_record_car association" do
5
+ context "A class with a belongs_to :mongo_mapper_object association" do
6
6
  setup do
7
7
  setup_fixtures
8
- @wheel = MongoMapperWheel.new
8
+ @object = MongoMapperHasOneTarget.new
9
9
  end
10
10
 
11
- should("respond to active_record_car") { assert @wheel.respond_to?(:active_record_car) }
12
- should("respond to active_record_car=") { assert @wheel.respond_to?(:active_record_car=) }
13
- should("respond to active_record_car_id") { assert @wheel.respond_to?(:active_record_car_id) }
11
+ should("respond to mongo_mapper_object") { assert @object.respond_to?(:mongo_mapper_object) }
12
+ should("respond to mongo_mapper_object=") { assert @object.respond_to?(:mongo_mapper_object=) }
13
+ should("respond to mongo_mapper_object_id") { assert @object.respond_to?(:mongo_mapper_object_id) }
14
14
  end
15
15
 
16
- context "A class with a has_one :active_record_climate_control_unit association" do
16
+ context "A class with a has_one :mongo_mapper_has_one_target association" do
17
17
  setup do
18
18
  setup_fixtures
19
- @dashboard = MongoMapperDashboard.new
19
+ @object = MongoMapperObject.new
20
20
  end
21
21
 
22
- should("respond to active_record_climate_control_unit") { assert @dashboard.respond_to?(:active_record_climate_control_unit) }
23
- should("respond to active_record_climate_control_unit=") { assert @dashboard.respond_to?(:active_record_climate_control_unit=) }
22
+ should("respond to mongo_mapper_has_one_target") { assert @object.respond_to?(:mongo_mapper_has_one_target) }
23
+ should("respond to mongo_mapper_has_one_target=") { assert @object.respond_to?(:mongo_mapper_has_one_target=) }
24
24
  end
25
25
 
26
- context "A class with a has_many :active_record_nuts association" do
26
+ context "A class with a has_many :mongo_mapper_has_many_targets association" do
27
27
  setup do
28
28
  setup_fixtures
29
- @wheel = MongoMapperWheel.new
29
+ @object = MongoMapperObject.new
30
30
  end
31
31
 
32
- should("respond to active_record_nuts") { assert @wheel.respond_to?(:active_record_nuts) }
33
- should("respond to active_record_nuts=") { assert @wheel.respond_to?(:active_record_nuts=) }
34
- should("respond to active_record_nut_ids") { assert @wheel.respond_to?(:active_record_nut_ids) }
35
- should("respond to active_record_nut_ids=") { assert @wheel.respond_to?(:active_record_nut_ids=) }
32
+ should("respond to mongo_mapper_has_many_targets") { assert @object.respond_to?(:mongo_mapper_has_many_targets) }
33
+ should("respond to mongo_mapper_has_many_targets=") { assert @object.respond_to?(:mongo_mapper_has_many_targets=) }
34
+ should("respond to mongo_mapper_has_many_target_ids") { assert @object.respond_to?(:mongo_mapper_has_many_target_ids) }
35
+ should("respond to mongo_mapper_has_many_target_ids=") { assert @object.respond_to?(:mongo_mapper_has_many_target_ids=) }
36
36
  end
37
37
 
38
38
  context "The object returned by a has_many association" do
39
39
  setup do
40
40
  setup_fixtures
41
- @wheel = MongoMapperWheel.new
42
- @nuts = @wheel.active_record_nuts
41
+ @object = MongoMapperObject.new
42
+ @targets = @object.mongo_mapper_has_many_targets
43
43
  end
44
44
 
45
- should("respond to <<") { assert @nuts.respond_to?(:<<) }
46
- should("respond to delete") { assert @nuts.respond_to?(:delete) }
47
- should("respond to clear") { assert @nuts.respond_to?(:clear) }
48
- should("respond to empty?") { assert @nuts.respond_to?(:empty?) }
49
- should("respond to size") { assert @nuts.respond_to?(:size) }
45
+ should("respond to <<") { assert @targets.respond_to?(:<<) }
46
+ should("respond to delete") { assert @targets.respond_to?(:delete) }
47
+ should("respond to clear") { assert @targets.respond_to?(:clear) }
48
+ should("respond to empty?") { assert @targets.respond_to?(:empty?) }
49
+ should("respond to size") { assert @targets.respond_to?(:size) }
50
+ should("respond to delete_all") { assert @targets.respond_to?(:delete_all) }
51
+ should("respond to destroy_all") { assert @targets.respond_to?(:destroy_all) }
50
52
  end
51
53
 
52
54
  end
@@ -0,0 +1,10 @@
1
+ class ActiveRecordHasManyTarget < ActiveRecord::Base
2
+ include Tenacity
3
+
4
+ t_belongs_to :active_record_object
5
+ t_belongs_to :couch_rest_object
6
+ t_belongs_to :data_mapper_object
7
+ t_belongs_to :mongo_mapper_object
8
+ require_mongoid { t_belongs_to :mongoid_object }
9
+ t_belongs_to :sequel_object
10
+ end
@@ -0,0 +1,10 @@
1
+ class ActiveRecordHasOneTarget < ActiveRecord::Base
2
+ include Tenacity
3
+
4
+ t_belongs_to :active_record_object
5
+ t_belongs_to :couch_rest_object
6
+ t_belongs_to :data_mapper_object
7
+ t_belongs_to :mongo_mapper_object
8
+ require_mongoid { t_belongs_to :mongoid_object }
9
+ t_belongs_to :sequel_object
10
+ end
@@ -0,0 +1,17 @@
1
+ class ActiveRecordObject < ActiveRecord::Base
2
+ include Tenacity
3
+
4
+ t_has_one :active_record_has_one_target
5
+ t_has_one :couch_rest_has_one_target
6
+ t_has_one :data_mapper_has_one_target
7
+ t_has_one :mongo_mapper_has_one_target
8
+ require_mongoid { t_has_one :mongoid_has_one_target }
9
+ t_has_one :sequel_has_one_target
10
+
11
+ t_has_many :active_record_has_many_targets
12
+ t_has_many :couch_rest_has_many_targets
13
+ t_has_many :data_mapper_has_many_targets
14
+ t_has_many :mongo_mapper_has_many_targets
15
+ require_mongoid { t_has_many :mongoid_has_many_targets }
16
+ t_has_many :sequel_has_many_targets
17
+ end
@@ -1,5 +1,3 @@
1
- require 'couchrest_model'
2
-
3
1
  class CouchRestDoor < CouchRest::Model::Base
4
2
  include Tenacity
5
3
  use_database COUCH_DB
@@ -0,0 +1,12 @@
1
+ class CouchRestHasManyTarget < CouchRest::Model::Base
2
+ include Tenacity
3
+ use_database COUCH_DB
4
+
5
+ t_belongs_to :active_record_object
6
+ t_belongs_to :couch_rest_object
7
+ t_belongs_to :data_mapper_object
8
+ t_belongs_to :mongo_mapper_object
9
+ require_mongoid { t_belongs_to :mongoid_object }
10
+ t_belongs_to :sequel_object
11
+ end
12
+
@@ -0,0 +1,12 @@
1
+ class CouchRestHasOneTarget < CouchRest::Model::Base
2
+ include Tenacity
3
+ use_database COUCH_DB
4
+
5
+ t_belongs_to :active_record_object
6
+ t_belongs_to :couch_rest_object
7
+ t_belongs_to :data_mapper_object
8
+ t_belongs_to :mongo_mapper_object
9
+ require_mongoid { t_belongs_to :mongoid_object }
10
+ t_belongs_to :sequel_object
11
+ end
12
+
@@ -0,0 +1,19 @@
1
+ class CouchRestObject < CouchRest::Model::Base
2
+ include Tenacity
3
+ use_database COUCH_DB
4
+
5
+ t_has_one :active_record_has_one_target
6
+ t_has_one :couch_rest_has_one_target
7
+ t_has_one :data_mapper_has_one_target
8
+ t_has_one :mongo_mapper_has_one_target
9
+ require_mongoid { t_has_one :mongoid_has_one_target }
10
+ t_has_one :sequel_has_one_target
11
+
12
+ t_has_many :active_record_has_many_targets
13
+ t_has_many :couch_rest_has_many_targets
14
+ t_has_many :data_mapper_has_many_targets
15
+ t_has_many :mongo_mapper_has_many_targets
16
+ require_mongoid { t_has_many :mongoid_has_many_targets }
17
+ t_has_many :sequel_has_many_targets
18
+ end
19
+
@@ -1,5 +1,3 @@
1
- require 'couchrest_model'
2
-
3
1
  class CouchRestWindshield < CouchRest::Model::Base
4
2
  include Tenacity
5
3
  use_database COUCH_DB
@@ -0,0 +1,19 @@
1
+ class DataMapperHasManyTarget
2
+ include DataMapper::Resource
3
+ include Tenacity
4
+
5
+ property :id, Serial
6
+ property :active_record_object_id, String
7
+ property :couch_rest_object_id, String
8
+ property :data_mapper_object_id, String
9
+ property :mongo_mapper_object_id, String
10
+ property :mongoid_object_id, String
11
+ property :sequel_object_id, String
12
+
13
+ t_belongs_to :active_record_object
14
+ t_belongs_to :couch_rest_object
15
+ t_belongs_to :data_mapper_object
16
+ t_belongs_to :mongo_mapper_object
17
+ require_mongoid { t_belongs_to :mongoid_object }
18
+ t_belongs_to :sequel_object
19
+ end
@@ -0,0 +1,19 @@
1
+ class DataMapperHasOneTarget
2
+ include DataMapper::Resource
3
+ include Tenacity
4
+
5
+ property :id, Serial
6
+ property :active_record_object_id, String
7
+ property :couch_rest_object_id, String
8
+ property :data_mapper_object_id, String
9
+ property :mongo_mapper_object_id, String
10
+ property :mongoid_object_id, String
11
+ property :sequel_object_id, String
12
+
13
+ t_belongs_to :active_record_object
14
+ t_belongs_to :couch_rest_object
15
+ t_belongs_to :data_mapper_object
16
+ t_belongs_to :mongo_mapper_object
17
+ require_mongoid { t_belongs_to :mongoid_object }
18
+ t_belongs_to :sequel_object
19
+ end
@@ -0,0 +1,20 @@
1
+ class DataMapperObject
2
+ include DataMapper::Resource
3
+ include Tenacity
4
+
5
+ property :id, Serial
6
+
7
+ t_has_one :active_record_has_one_target
8
+ t_has_one :couch_rest_has_one_target
9
+ t_has_one :data_mapper_has_one_target
10
+ t_has_one :mongo_mapper_has_one_target
11
+ require_mongoid { t_has_one :mongoid_has_one_target }
12
+ t_has_one :sequel_has_one_target
13
+
14
+ t_has_many :active_record_has_many_targets
15
+ t_has_many :couch_rest_has_many_targets
16
+ t_has_many :data_mapper_has_many_targets
17
+ t_has_many :mongo_mapper_has_many_targets
18
+ require_mongoid { t_has_many :mongoid_has_many_targets }
19
+ t_has_many :sequel_has_many_targets
20
+ end
@@ -1,5 +1,3 @@
1
- require 'mongo_mapper'
2
-
3
1
  class MongoMapperAshTray
4
2
  include MongoMapper::Document
5
3
  include Tenacity
@@ -1,5 +1,3 @@
1
- require 'mongo_mapper'
2
-
3
1
  class MongoMapperDashboard
4
2
  include MongoMapper::Document
5
3
  include Tenacity
@@ -0,0 +1,11 @@
1
+ class MongoMapperHasManyTarget
2
+ include MongoMapper::Document
3
+ include Tenacity
4
+
5
+ t_belongs_to :active_record_object
6
+ t_belongs_to :couch_rest_object
7
+ t_belongs_to :data_mapper_object
8
+ t_belongs_to :mongo_mapper_object
9
+ require_mongoid { t_belongs_to :mongoid_object }
10
+ t_belongs_to :sequel_object
11
+ end
@@ -0,0 +1,11 @@
1
+ class MongoMapperHasOneTarget
2
+ include MongoMapper::Document
3
+ include Tenacity
4
+
5
+ t_belongs_to :active_record_object
6
+ t_belongs_to :couch_rest_object
7
+ t_belongs_to :data_mapper_object
8
+ t_belongs_to :mongo_mapper_object
9
+ require_mongoid { t_belongs_to :mongoid_object }
10
+ t_belongs_to :sequel_object
11
+ end
@@ -0,0 +1,18 @@
1
+ class MongoMapperObject
2
+ include MongoMapper::Document
3
+ include Tenacity
4
+
5
+ t_has_one :active_record_has_one_target
6
+ t_has_one :couch_rest_has_one_target
7
+ t_has_one :data_mapper_has_one_target
8
+ t_has_one :mongo_mapper_has_one_target
9
+ require_mongoid { t_has_one :mongoid_has_one_target }
10
+ t_has_one :sequel_has_one_target
11
+
12
+ t_has_many :active_record_has_many_targets
13
+ t_has_many :couch_rest_has_many_targets
14
+ t_has_many :data_mapper_has_many_targets
15
+ t_has_many :mongo_mapper_has_many_targets
16
+ require_mongoid { t_has_many :mongoid_has_many_targets }
17
+ t_has_many :sequel_has_many_targets
18
+ end
@@ -1,5 +1,3 @@
1
- require 'mongo_mapper'
2
-
3
1
  class MongoMapperVent
4
2
  include MongoMapper::Document
5
3
  include Tenacity
@@ -1,5 +1,3 @@
1
- require 'mongo_mapper'
2
-
3
1
  class MongoMapperWheel
4
2
  include MongoMapper::Document
5
3
  include Tenacity
@@ -0,0 +1,13 @@
1
+ require_mongoid do
2
+ class MongoidHasManyTarget
3
+ include Mongoid::Document
4
+ include Tenacity
5
+
6
+ t_belongs_to :active_record_object
7
+ t_belongs_to :couch_rest_object
8
+ t_belongs_to :data_mapper_object
9
+ t_belongs_to :mongo_mapper_object
10
+ t_belongs_to :mongoid_object
11
+ t_belongs_to :sequel_object
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require_mongoid do
2
+ class MongoidHasOneTarget
3
+ include Mongoid::Document
4
+ include Tenacity
5
+
6
+ t_belongs_to :active_record_object
7
+ t_belongs_to :couch_rest_object
8
+ t_belongs_to :data_mapper_object
9
+ t_belongs_to :mongo_mapper_object
10
+ t_belongs_to :mongoid_object
11
+ t_belongs_to :sequel_object
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ require_mongoid do
2
+ class MongoidObject
3
+ include Mongoid::Document
4
+ include Tenacity
5
+
6
+ t_has_one :active_record_has_one_target
7
+ t_has_one :couch_rest_has_one_target
8
+ t_has_one :data_mapper_has_one_target
9
+ t_has_one :mongo_mapper_has_one_target
10
+ t_has_one :mongoid_has_one_target
11
+ t_has_one :sequel_has_one_target
12
+
13
+ t_has_many :active_record_has_many_targets
14
+ t_has_many :couch_rest_has_many_targets
15
+ t_has_many :data_mapper_has_many_targets
16
+ t_has_many :mongo_mapper_has_many_targets
17
+ t_has_many :mongoid_has_many_targets
18
+ t_has_many :sequel_has_many_targets
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ class SequelHasManyTarget < Sequel::Model
2
+ include Tenacity
3
+
4
+ t_belongs_to :active_record_object
5
+ t_belongs_to :couch_rest_object
6
+ t_belongs_to :data_mapper_object
7
+ t_belongs_to :mongo_mapper_object
8
+ require_mongoid { t_belongs_to :mongoid_object }
9
+ t_belongs_to :sequel_object
10
+ end
@@ -0,0 +1,10 @@
1
+ class SequelHasOneTarget < Sequel::Model
2
+ include Tenacity
3
+
4
+ t_belongs_to :active_record_object
5
+ t_belongs_to :couch_rest_object
6
+ t_belongs_to :data_mapper_object
7
+ t_belongs_to :mongo_mapper_object
8
+ require_mongoid { t_belongs_to :mongoid_object }
9
+ t_belongs_to :sequel_object
10
+ end
@@ -0,0 +1,17 @@
1
+ class SequelObject < Sequel::Model
2
+ include Tenacity
3
+
4
+ t_has_one :active_record_has_one_target
5
+ t_has_one :couch_rest_has_one_target
6
+ t_has_one :data_mapper_has_one_target
7
+ t_has_one :mongo_mapper_has_one_target
8
+ require_mongoid { t_has_one :mongoid_has_one_target }
9
+ t_has_one :sequel_has_one_target
10
+
11
+ t_has_many :active_record_has_many_targets
12
+ t_has_many :couch_rest_has_many_targets
13
+ t_has_many :data_mapper_has_many_targets
14
+ t_has_many :mongo_mapper_has_many_targets
15
+ require_mongoid { t_has_many :mongoid_has_many_targets }
16
+ t_has_many :sequel_has_many_targets
17
+ end
@@ -34,4 +34,55 @@ ActiveRecord::Schema.define :version => 0 do
34
34
  t.integer :nut_id
35
35
  t.string :mongo_mapper_wheel_id
36
36
  end
37
+
38
+ create_table :active_record_objects, :force => true do |t|
39
+ end
40
+
41
+ create_table :active_record_has_one_targets, :force => true do |t|
42
+ t.string :active_record_object_id
43
+ t.string :couch_rest_object_id
44
+ t.string :data_mapper_object_id
45
+ t.string :mongo_mapper_object_id
46
+ t.string :mongoid_object_id
47
+ t.string :sequel_object_id
48
+ end
49
+
50
+ create_table :active_record_has_many_targets, :force => true do |t|
51
+ t.integer :active_record_object_id
52
+ t.string :couch_rest_object_id
53
+ t.string :data_mapper_object_id
54
+ t.string :mongo_mapper_object_id
55
+ t.string :mongoid_object_id
56
+ t.string :sequel_object_id
57
+ end
58
+
59
+ create_table :active_record_has_many_targets_active_record_objects, :force => true do |t|
60
+ t.integer :active_record_object_id
61
+ t.string :active_record_has_many_target_id
62
+ end
63
+
64
+ create_table :active_record_objects_mongo_mapper_has_many_targets, :force => true do |t|
65
+ t.integer :active_record_object_id
66
+ t.string :mongo_mapper_has_many_target_id
67
+ end
68
+
69
+ create_table :active_record_objects_couch_rest_has_many_targets, :force => true do |t|
70
+ t.integer :active_record_object_id
71
+ t.string :couch_rest_has_many_target_id
72
+ end
73
+
74
+ create_table :active_record_objects_data_mapper_has_many_targets, :force => true do |t|
75
+ t.integer :active_record_object_id
76
+ t.string :data_mapper_has_many_target_id
77
+ end
78
+
79
+ create_table :active_record_objects_mongoid_has_many_targets, :force => true do |t|
80
+ t.integer :active_record_object_id
81
+ t.string :mongoid_has_many_target_id
82
+ end
83
+
84
+ create_table :active_record_objects_sequel_has_many_targets, :force => true do |t|
85
+ t.integer :active_record_object_id
86
+ t.string :sequel_has_many_target_id
87
+ end
37
88
  end