tenacity 0.1.0

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.
Files changed (40) hide show
  1. data/.gitignore +6 -0
  2. data/EXTEND.rdoc +79 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +70 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +103 -0
  7. data/Rakefile +96 -0
  8. data/lib/tenacity/associations/belongs_to.rb +28 -0
  9. data/lib/tenacity/associations/has_many.rb +86 -0
  10. data/lib/tenacity/associations/has_one.rb +40 -0
  11. data/lib/tenacity/class_methods.rb +226 -0
  12. data/lib/tenacity/instance_methods.rb +31 -0
  13. data/lib/tenacity/orm_ext/activerecord.rb +116 -0
  14. data/lib/tenacity/orm_ext/couchrest/couchrest_extended_document.rb +45 -0
  15. data/lib/tenacity/orm_ext/couchrest/couchrest_model.rb +46 -0
  16. data/lib/tenacity/orm_ext/couchrest/tenacity_class_methods.rb +52 -0
  17. data/lib/tenacity/orm_ext/couchrest/tenacity_instance_methods.rb +21 -0
  18. data/lib/tenacity/orm_ext/mongo_mapper.rb +107 -0
  19. data/lib/tenacity/version.rb +3 -0
  20. data/lib/tenacity.rb +27 -0
  21. data/tenacity.gemspec +34 -0
  22. data/test/associations/belongs_to_test.rb +119 -0
  23. data/test/associations/has_many_test.rb +184 -0
  24. data/test/associations/has_one_test.rb +77 -0
  25. data/test/core/classmethods_test.rb +53 -0
  26. data/test/fixtures/active_record_car.rb +6 -0
  27. data/test/fixtures/active_record_climate_control_unit.rb +5 -0
  28. data/test/fixtures/active_record_nuts.rb +5 -0
  29. data/test/fixtures/couch_rest_radio.rb +10 -0
  30. data/test/fixtures/mongo_mapper_button.rb +6 -0
  31. data/test/fixtures/mongo_mapper_dashboard.rb +10 -0
  32. data/test/fixtures/mongo_mapper_wheel.rb +9 -0
  33. data/test/helpers/active_record_test_helper.rb +7 -0
  34. data/test/helpers/couch_rest_test_helper.rb +8 -0
  35. data/test/helpers/mongo_mapper_test_helper.rb +3 -0
  36. data/test/orm_ext/activerecord_test.rb +85 -0
  37. data/test/orm_ext/couchrest_test.rb +95 -0
  38. data/test/orm_ext/mongo_mapper_test.rb +93 -0
  39. data/test/test_helper.rb +47 -0
  40. metadata +253 -0
@@ -0,0 +1,95 @@
1
+ require 'test_helper'
2
+
3
+ class CouchRestTest < Test::Unit::TestCase
4
+
5
+ context "The CouchRest extension" do
6
+ setup do
7
+ setup_couchdb_fixtures
8
+ end
9
+
10
+ should "be able to find the object in the database" do
11
+ radio = CouchRestRadio.create({})
12
+ assert_equal radio, CouchRestRadio._t_find(radio.id)
13
+ end
14
+
15
+ should "return nil if the specified id could not be found in the database" do
16
+ assert_nil CouchRestRadio._t_find("abc123")
17
+ end
18
+
19
+ should "be able to find multiple objects in the database" do
20
+ radio_1 = CouchRestRadio.create({})
21
+ radio_2 = CouchRestRadio.create({})
22
+ assert_set_equal [radio_1, radio_2], CouchRestRadio._t_find_bulk([radio_1.id, radio_2.id, "abc123"])
23
+ end
24
+
25
+ should "return an empty array if unable to find the specified objects in the database" do
26
+ assert_equal [], CouchRestRadio._t_find_bulk(["abc123", "abc456", "abc789"])
27
+ end
28
+
29
+ should "be able to find the first associate of an object" do
30
+ dashboard = MongoMapperDashboard.create
31
+ radio = CouchRestRadio.create(:mongo_mapper_dashboard_id => dashboard.id)
32
+ assert_equal radio, CouchRestRadio._t_find_first_by_associate(:mongo_mapper_dashboard_id, dashboard.id)
33
+ end
34
+
35
+ should "return nil if the first associate of an object could not be found" do
36
+ assert_nil CouchRestRadio._t_find_first_by_associate(:mongo_mapper_dashboard_id, 12345)
37
+ end
38
+
39
+ should "be able to find all associates of an object" do
40
+ dashboard = MongoMapperDashboard.create
41
+ radio_1 = CouchRestRadio.create(:mongo_mapper_dashboard_id => dashboard.id)
42
+ radio_2 = CouchRestRadio.create(:mongo_mapper_dashboard_id => dashboard.id)
43
+ radio_3 = CouchRestRadio.create(:mongo_mapper_dashboard_id => 'abc123')
44
+ assert_set_equal [radio_1, radio_2], CouchRestRadio._t_find_all_by_associate(:mongo_mapper_dashboard_id, dashboard.id)
45
+ end
46
+
47
+ should "return an empty array if unable to find the associates of an object" do
48
+ assert_equal [], CouchRestRadio._t_find_all_by_associate(:mongo_mapper_dashboard_id, 'abc123')
49
+ end
50
+
51
+ should "be able to reload an object from the database" do
52
+ radio = CouchRestRadio.create({"abc" => "123"})
53
+ assert_equal "123", radio["abc"]
54
+ radio["abc"] = "456"
55
+ assert_equal "456", radio["abc"]
56
+ radio._t_reload
57
+ assert_equal "123", radio["abc"]
58
+ end
59
+
60
+ should "be able to associate many objects with the given object" do
61
+ button_1 = MongoMapperButton.create
62
+ button_2 = MongoMapperButton.create
63
+ button_3 = MongoMapperButton.create
64
+ radio = CouchRestRadio.create({})
65
+ radio._t_associate_many(:mongo_mapper_buttons, [button_1.id, button_2.id, button_3.id])
66
+ assert_set_equal [button_1.id.to_s, button_2.id.to_s, button_3.id.to_s], radio.t_mongo_mapper_button_ids
67
+ end
68
+
69
+ should "be able to get the ids of the objects associated with the given object" do
70
+ button_1 = MongoMapperButton.create
71
+ button_2 = MongoMapperButton.create
72
+ button_3 = MongoMapperButton.create
73
+ radio = CouchRestRadio.create({})
74
+ radio._t_associate_many(:mongo_mapper_buttons, [button_1.id, button_2.id, button_3.id])
75
+ assert_set_equal [button_1.id.to_s, button_2.id.to_s, button_3.id.to_s], radio._t_get_associate_ids(:mongo_mapper_buttons)
76
+ end
77
+
78
+ should "return an empty array when trying to fetch associate ids for an object with no associates" do
79
+ radio = CouchRestRadio.create({})
80
+ assert_equal [], radio._t_get_associate_ids(:mongo_mapper_buttons)
81
+ end
82
+
83
+ should "be able to clear the associates of an object" do
84
+ button_1 = MongoMapperButton.create
85
+ button_2 = MongoMapperButton.create
86
+ button_3 = MongoMapperButton.create
87
+ radio = CouchRestRadio.create({})
88
+ radio._t_associate_many(:mongo_mapper_buttons, [button_1.id, button_2.id, button_3.id])
89
+ assert_set_equal [button_1.id.to_s, button_2.id.to_s, button_3.id.to_s], radio._t_get_associate_ids(:mongo_mapper_buttons)
90
+ radio._t_clear_associates(:mongo_mapper_buttons)
91
+ assert_equal [], radio._t_get_associate_ids(:mongo_mapper_buttons)
92
+ end
93
+
94
+ end
95
+ end
@@ -0,0 +1,93 @@
1
+ require 'test_helper'
2
+
3
+ class MongoMapperTest < Test::Unit::TestCase
4
+
5
+ context "The MongoMapper extension" do
6
+ setup do
7
+ setup_fixtures
8
+ end
9
+
10
+ should "be able to find the object in the database" do
11
+ wheel = MongoMapperWheel.create
12
+ assert_equal wheel, MongoMapperWheel._t_find(wheel.id)
13
+ end
14
+
15
+ should "return nil if the specified id could not be found in the database" do
16
+ assert_nil MongoMapperWheel._t_find('4d0e1224b28cdbfb72000042')
17
+ end
18
+
19
+ should "be able to find multiple objects in the database" do
20
+ wheel_1 = MongoMapperWheel.create
21
+ wheel_2 = MongoMapperWheel.create
22
+ assert_set_equal [wheel_1, wheel_2], MongoMapperWheel._t_find_bulk([wheel_1.id, wheel_2.id, '4d0e1224b28cdbfb72000042'])
23
+ end
24
+
25
+ should "return an empty array if none of the specified object ids could be found in the database" do
26
+ assert_equal [], MongoMapperWheel._t_find_bulk(['4d0e1224b28cdbfb72000042', '4d0e1224b28cdbfb72000043', '4d0e1224b28cdbfb72000044'])
27
+ end
28
+
29
+ should "be able to find the first associate of an object" do
30
+ car = ActiveRecordCar.create
31
+ wheel = MongoMapperWheel.create(:active_record_car_id => car.id.to_s)
32
+ assert_equal wheel, MongoMapperWheel._t_find_first_by_associate(:active_record_car_id, car.id)
33
+ end
34
+
35
+ should "return nil if the first associate of an object could not be found" do
36
+ assert_nil MongoMapperWheel._t_find_first_by_associate(:active_record_car_id, 12345)
37
+ end
38
+
39
+ should "be able to find the associates of an object" do
40
+ wheel_1 = MongoMapperWheel.create(:active_record_car_id => '101')
41
+ wheel_2 = MongoMapperWheel.create(:active_record_car_id => '101')
42
+ wheel_3 = MongoMapperWheel.create(:active_record_car_id => '102')
43
+ assert_set_equal [wheel_1, wheel_2], MongoMapperWheel._t_find_all_by_associate(:active_record_car_id, '101')
44
+ end
45
+
46
+ should "return an empty array if the object has no associates" do
47
+ assert_equal [], MongoMapperWheel._t_find_all_by_associate(:active_record_car_id, 1234)
48
+ end
49
+
50
+ should "be able to reload an object from the database" do
51
+ wheel = MongoMapperWheel.create
52
+ wheel.active_record_car_id = 101
53
+ assert_equal 101, wheel.active_record_car_id.to_i
54
+ wheel.reload
55
+ assert_equal '', wheel.active_record_car_id
56
+ end
57
+
58
+ should "be able to associate many objects with the given object" do
59
+ nut_1 = ActiveRecordNut.create
60
+ nut_2 = ActiveRecordNut.create
61
+ nut_3 = ActiveRecordNut.create
62
+ wheel = MongoMapperWheel.create
63
+ wheel._t_associate_many(:active_record_nuts, [nut_1.id, nut_2.id, nut_3.id])
64
+ assert_set_equal [nut_1.id.to_s, nut_2.id.to_s, nut_3.id.to_s], wheel.t_active_record_nut_ids
65
+ end
66
+
67
+ should "be able to get the ids of the objects associated with the given object" do
68
+ nut_1 = ActiveRecordNut.create
69
+ nut_2 = ActiveRecordNut.create
70
+ nut_3 = ActiveRecordNut.create
71
+ wheel = MongoMapperWheel.create
72
+ wheel._t_associate_many(:active_record_nuts, [nut_1.id, nut_2.id, nut_3.id])
73
+ assert_set_equal [nut_1.id.to_s, nut_2.id.to_s, nut_3.id.to_s], wheel._t_get_associate_ids(:active_record_nuts)
74
+ end
75
+
76
+ should "return an empty array when trying to fetch associate ids for an object with no associates" do
77
+ wheel = MongoMapperWheel.create
78
+ assert_equal [], wheel._t_get_associate_ids(:active_record_nuts)
79
+ end
80
+
81
+ should "be able to clear the associates of an object" do
82
+ nut_1 = ActiveRecordNut.create
83
+ nut_2 = ActiveRecordNut.create
84
+ nut_3 = ActiveRecordNut.create
85
+ wheel = MongoMapperWheel.create
86
+ wheel._t_associate_many(:active_record_nuts, [nut_1.id, nut_2.id, nut_3.id])
87
+ assert_set_equal [nut_1.id.to_s, nut_2.id.to_s, nut_3.id.to_s], wheel._t_get_associate_ids(:active_record_nuts)
88
+ wheel._t_clear_associates(:active_record_nuts)
89
+ assert_equal [], wheel._t_get_associate_ids(:active_record_nuts)
90
+ end
91
+ end
92
+
93
+ end
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+
11
+ require 'test/unit'
12
+ require 'shoulda'
13
+
14
+ require File.join(File.dirname(__FILE__), 'helpers', 'active_record_test_helper')
15
+ require File.join(File.dirname(__FILE__), 'helpers', 'mongo_mapper_test_helper')
16
+ require File.join(File.dirname(__FILE__), 'helpers', 'couch_rest_test_helper')
17
+
18
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
19
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
20
+ require 'tenacity'
21
+
22
+ Dir[File.join(File.dirname(__FILE__), 'fixtures/*.rb')].each { |file| require file }
23
+
24
+ def setup_fixtures
25
+ ActiveRecordCar.delete_all
26
+ ActiveRecordClimateControlUnit.delete_all
27
+ ActiveRecordNut.delete_all
28
+ MongoMapperDashboard.delete_all
29
+ MongoMapperWheel.delete_all
30
+
31
+ ActiveRecordCar.connection.execute("delete from active_record_cars_mongo_mapper_wheels")
32
+ ActiveRecordCar.connection.execute("delete from active_record_nuts_mongo_mapper_wheels")
33
+ end
34
+
35
+ def setup_couchdb_fixtures
36
+ COUCH_DB.recreate! rescue nil
37
+ end
38
+
39
+ def setup_all_fixtures
40
+ setup_fixtures
41
+ setup_couchdb_fixtures
42
+ end
43
+
44
+ def assert_set_equal(expecteds, actuals, message = nil)
45
+ assert_equal expecteds && Set.new(expecteds), actuals && Set.new(actuals), message
46
+ end
47
+
metadata ADDED
@@ -0,0 +1,253 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tenacity
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - John Wood
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-25 00:00:00 -06:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ requirement: &id001 !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ segments:
26
+ - 2
27
+ - 3
28
+ version: "2.3"
29
+ prerelease: false
30
+ name: activesupport
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: &id002 !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ segments:
39
+ - 1
40
+ - 0
41
+ - 0
42
+ version: 1.0.0
43
+ prerelease: false
44
+ name: bundler
45
+ type: :development
46
+ version_requirements: *id002
47
+ - !ruby/object:Gem::Dependency
48
+ requirement: &id003 !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ~>
51
+ - !ruby/object:Gem::Version
52
+ segments:
53
+ - 0
54
+ - 8
55
+ - 7
56
+ version: 0.8.7
57
+ prerelease: false
58
+ name: rake
59
+ type: :development
60
+ version_requirements: *id003
61
+ - !ruby/object:Gem::Dependency
62
+ requirement: &id004 !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
68
+ - 9
69
+ - 9
70
+ version: 0.9.9
71
+ prerelease: false
72
+ name: rcov
73
+ type: :development
74
+ version_requirements: *id004
75
+ - !ruby/object:Gem::Dependency
76
+ requirement: &id005 !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ~>
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 2
82
+ - 11
83
+ - 3
84
+ version: 2.11.3
85
+ prerelease: false
86
+ name: shoulda
87
+ type: :development
88
+ version_requirements: *id005
89
+ - !ruby/object:Gem::Dependency
90
+ requirement: &id006 !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ segments:
95
+ - 0
96
+ - 8
97
+ - 6
98
+ version: 0.8.6
99
+ prerelease: false
100
+ name: mongo_mapper
101
+ type: :development
102
+ version_requirements: *id006
103
+ - !ruby/object:Gem::Dependency
104
+ requirement: &id007 !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ~>
107
+ - !ruby/object:Gem::Version
108
+ segments:
109
+ - 1
110
+ - 1
111
+ - 3
112
+ version: 1.1.3
113
+ prerelease: false
114
+ name: bson_ext
115
+ type: :development
116
+ version_requirements: *id007
117
+ - !ruby/object:Gem::Dependency
118
+ requirement: &id008 !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ~>
121
+ - !ruby/object:Gem::Version
122
+ segments:
123
+ - 3
124
+ - 0
125
+ - 0
126
+ version: 3.0.0
127
+ prerelease: false
128
+ name: activerecord
129
+ type: :development
130
+ version_requirements: *id008
131
+ - !ruby/object:Gem::Dependency
132
+ requirement: &id009 !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ~>
135
+ - !ruby/object:Gem::Version
136
+ segments:
137
+ - 2
138
+ - 8
139
+ - 1
140
+ version: 2.8.1
141
+ prerelease: false
142
+ name: mysql
143
+ type: :development
144
+ version_requirements: *id009
145
+ - !ruby/object:Gem::Dependency
146
+ requirement: &id010 !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ~>
149
+ - !ruby/object:Gem::Version
150
+ segments:
151
+ - 1
152
+ - 0
153
+ - 0
154
+ version: 1.0.0
155
+ prerelease: false
156
+ name: couchrest
157
+ type: :development
158
+ version_requirements: *id010
159
+ - !ruby/object:Gem::Dependency
160
+ requirement: &id011 !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ segments:
165
+ - 0
166
+ version: "0"
167
+ prerelease: false
168
+ name: couchrest_model
169
+ type: :development
170
+ version_requirements: *id011
171
+ description: Tenacity provides an ORM independent way of specifying simple relationships between models backed by different databases.
172
+ email:
173
+ - john@johnpwood.net
174
+ executables: []
175
+
176
+ extensions: []
177
+
178
+ extra_rdoc_files: []
179
+
180
+ files:
181
+ - .gitignore
182
+ - EXTEND.rdoc
183
+ - Gemfile
184
+ - Gemfile.lock
185
+ - LICENSE.txt
186
+ - README.rdoc
187
+ - Rakefile
188
+ - lib/tenacity.rb
189
+ - lib/tenacity/associations/belongs_to.rb
190
+ - lib/tenacity/associations/has_many.rb
191
+ - lib/tenacity/associations/has_one.rb
192
+ - lib/tenacity/class_methods.rb
193
+ - lib/tenacity/instance_methods.rb
194
+ - lib/tenacity/orm_ext/activerecord.rb
195
+ - lib/tenacity/orm_ext/couchrest/couchrest_extended_document.rb
196
+ - lib/tenacity/orm_ext/couchrest/couchrest_model.rb
197
+ - lib/tenacity/orm_ext/couchrest/tenacity_class_methods.rb
198
+ - lib/tenacity/orm_ext/couchrest/tenacity_instance_methods.rb
199
+ - lib/tenacity/orm_ext/mongo_mapper.rb
200
+ - lib/tenacity/version.rb
201
+ - tenacity.gemspec
202
+ - test/associations/belongs_to_test.rb
203
+ - test/associations/has_many_test.rb
204
+ - test/associations/has_one_test.rb
205
+ - test/core/classmethods_test.rb
206
+ - test/fixtures/active_record_car.rb
207
+ - test/fixtures/active_record_climate_control_unit.rb
208
+ - test/fixtures/active_record_nuts.rb
209
+ - test/fixtures/couch_rest_radio.rb
210
+ - test/fixtures/mongo_mapper_button.rb
211
+ - test/fixtures/mongo_mapper_dashboard.rb
212
+ - test/fixtures/mongo_mapper_wheel.rb
213
+ - test/helpers/active_record_test_helper.rb
214
+ - test/helpers/couch_rest_test_helper.rb
215
+ - test/helpers/mongo_mapper_test_helper.rb
216
+ - test/orm_ext/activerecord_test.rb
217
+ - test/orm_ext/couchrest_test.rb
218
+ - test/orm_ext/mongo_mapper_test.rb
219
+ - test/test_helper.rb
220
+ has_rdoc: true
221
+ homepage: http://github.com/jwood/tenacity
222
+ licenses:
223
+ - MIT
224
+ post_install_message:
225
+ rdoc_options: []
226
+
227
+ require_paths:
228
+ - lib
229
+ required_ruby_version: !ruby/object:Gem::Requirement
230
+ requirements:
231
+ - - ">="
232
+ - !ruby/object:Gem::Version
233
+ segments:
234
+ - 0
235
+ version: "0"
236
+ required_rubygems_version: !ruby/object:Gem::Requirement
237
+ requirements:
238
+ - - ">="
239
+ - !ruby/object:Gem::Version
240
+ segments:
241
+ - 1
242
+ - 3
243
+ - 6
244
+ version: 1.3.6
245
+ requirements: []
246
+
247
+ rubyforge_project:
248
+ rubygems_version: 1.3.6
249
+ signing_key:
250
+ specification_version: 3
251
+ summary: A ORM independent way of specifying simple relationships between models backed by different databases.
252
+ test_files: []
253
+