simply_stored 0.3.9 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +38 -0
- data/README.md +45 -24
- data/lib/simply_stored/couch/association_property.rb +27 -0
- data/lib/simply_stored/couch/belongs_to.rb +5 -7
- data/lib/simply_stored/couch/finders.rb +5 -1
- data/lib/simply_stored/couch/has_and_belongs_to_many.rb +202 -0
- data/lib/simply_stored/couch/has_many.rb +6 -51
- data/lib/simply_stored/couch/has_one.rb +4 -29
- data/lib/simply_stored/couch/properties.rb +11 -0
- data/lib/simply_stored/couch.rb +38 -2
- data/lib/simply_stored/instance_methods.rb +68 -29
- data/lib/simply_stored.rb +3 -1
- data/test/{couchdb/couch_active_model_compatibility_test.rb → active_model_compatibility_test.rb} +2 -2
- data/test/{couchdb/couch_belongs_to_test.rb → belongs_to_test.rb} +13 -3
- data/test/{couchdb/couch_conflict_handling_test.rb → conflict_handling_test.rb} +3 -3
- data/test/{couchdb/couch_finder_test.rb → finder_test.rb} +8 -3
- data/test/fixtures/couch.rb +55 -0
- data/test/has_and_belongs_to_many_test.rb +639 -0
- data/test/{couchdb/couch_has_many_test.rb → has_many_test.rb} +13 -3
- data/test/{couchdb/couch_has_one_test.rb → has_one_test.rb} +13 -3
- data/test/{couchdb/couch_instance_lifecycle_test.rb → instance_lifecycle_test.rb} +3 -3
- data/test/{couchdb/couch_mass_assignment_protection_test.rb → mass_assignment_protection_test.rb} +3 -3
- data/test/{couchdb/couch_s3_test.rb → s3_test.rb} +3 -3
- data/test/{couchdb/couch_soft_deletable_test.rb → soft_deletable_test.rb} +3 -3
- data/test/test_helper.rb +1 -5
- data/test/{couchdb/couch_validations_test.rb → validations_test.rb} +3 -3
- data/test/{couchdb/custom_views_test.rb → views_test.rb} +3 -3
- metadata +36 -234
- data/lib/simply_stored/simpledb/associations.rb +0 -215
- data/lib/simply_stored/simpledb/attributes.rb +0 -173
- data/lib/simply_stored/simpledb/storag.rb +0 -85
- data/lib/simply_stored/simpledb/validations.rb +0 -88
- data/lib/simply_stored/simpledb.rb +0 -216
- data/test/fixtures/simpledb/item.rb +0 -11
- data/test/fixtures/simpledb/item_daddy.rb +0 -8
- data/test/fixtures/simpledb/log_item.rb +0 -3
- data/test/fixtures/simpledb/namespace_bar.rb +0 -5
- data/test/fixtures/simpledb/namespace_foo.rb +0 -7
- data/test/fixtures/simpledb/protected_item.rb +0 -3
- data/test/simply_stored_simpledb_test.rb +0 -1376
- data/test/vendor/dhaka-2.2.1/lib/dhaka/dot/dot.rb +0 -29
- data/test/vendor/dhaka-2.2.1/lib/dhaka/evaluator/evaluator.rb +0 -133
- data/test/vendor/dhaka-2.2.1/lib/dhaka/grammar/closure_hash.rb +0 -15
- data/test/vendor/dhaka-2.2.1/lib/dhaka/grammar/grammar.rb +0 -240
- data/test/vendor/dhaka-2.2.1/lib/dhaka/grammar/grammar_symbol.rb +0 -27
- data/test/vendor/dhaka-2.2.1/lib/dhaka/grammar/precedence.rb +0 -19
- data/test/vendor/dhaka-2.2.1/lib/dhaka/grammar/production.rb +0 -36
- data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/accept_actions.rb +0 -36
- data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/alphabet.rb +0 -21
- data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/compiled_lexer.rb +0 -46
- data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/dfa.rb +0 -121
- data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/lexeme.rb +0 -32
- data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/lexer.rb +0 -70
- data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/lexer_run.rb +0 -78
- data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/regex_grammar.rb +0 -392
- data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/regex_parser.rb +0 -2010
- data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/regex_tokenizer.rb +0 -14
- data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/specification.rb +0 -96
- data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/state.rb +0 -68
- data/test/vendor/dhaka-2.2.1/lib/dhaka/lexer/state_machine.rb +0 -37
- data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/action.rb +0 -55
- data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/channel.rb +0 -58
- data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/compiled_parser.rb +0 -51
- data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/conflict.rb +0 -54
- data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/item.rb +0 -42
- data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/parse_result.rb +0 -50
- data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/parse_tree.rb +0 -66
- data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/parser.rb +0 -165
- data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/parser_methods.rb +0 -11
- data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/parser_run.rb +0 -39
- data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/parser_state.rb +0 -74
- data/test/vendor/dhaka-2.2.1/lib/dhaka/parser/token.rb +0 -22
- data/test/vendor/dhaka-2.2.1/lib/dhaka/runtime.rb +0 -51
- data/test/vendor/dhaka-2.2.1/lib/dhaka/tokenizer/tokenizer.rb +0 -190
- data/test/vendor/dhaka-2.2.1/lib/dhaka.rb +0 -62
- data/test/vendor/dhaka-2.2.1/test/all_tests.rb +0 -5
- data/test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_evaluator.rb +0 -64
- data/test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_evaluator_test.rb +0 -43
- data/test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_grammar.rb +0 -41
- data/test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_grammar_test.rb +0 -9
- data/test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_test_methods.rb +0 -9
- data/test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_tokenizer.rb +0 -39
- data/test/vendor/dhaka-2.2.1/test/arithmetic/arithmetic_tokenizer_test.rb +0 -38
- data/test/vendor/dhaka-2.2.1/test/arithmetic_precedence/arithmetic_precedence_evaluator.rb +0 -43
- data/test/vendor/dhaka-2.2.1/test/arithmetic_precedence/arithmetic_precedence_grammar.rb +0 -24
- data/test/vendor/dhaka-2.2.1/test/arithmetic_precedence/arithmetic_precedence_grammar_test.rb +0 -30
- data/test/vendor/dhaka-2.2.1/test/arithmetic_precedence/arithmetic_precedence_lexer_specification.rb +0 -23
- data/test/vendor/dhaka-2.2.1/test/arithmetic_precedence/arithmetic_precedence_parser_test.rb +0 -33
- data/test/vendor/dhaka-2.2.1/test/brackets/bracket_grammar.rb +0 -23
- data/test/vendor/dhaka-2.2.1/test/brackets/bracket_tokenizer.rb +0 -22
- data/test/vendor/dhaka-2.2.1/test/brackets/brackets_test.rb +0 -28
- data/test/vendor/dhaka-2.2.1/test/chittagong/chittagong_driver.rb +0 -46
- data/test/vendor/dhaka-2.2.1/test/chittagong/chittagong_driver_test.rb +0 -276
- data/test/vendor/dhaka-2.2.1/test/chittagong/chittagong_evaluator.rb +0 -284
- data/test/vendor/dhaka-2.2.1/test/chittagong/chittagong_evaluator_test.rb +0 -38
- data/test/vendor/dhaka-2.2.1/test/chittagong/chittagong_grammar.rb +0 -104
- data/test/vendor/dhaka-2.2.1/test/chittagong/chittagong_lexer.rb +0 -109
- data/test/vendor/dhaka-2.2.1/test/chittagong/chittagong_lexer_specification.rb +0 -37
- data/test/vendor/dhaka-2.2.1/test/chittagong/chittagong_lexer_test.rb +0 -58
- data/test/vendor/dhaka-2.2.1/test/chittagong/chittagong_parser.rb +0 -879
- data/test/vendor/dhaka-2.2.1/test/chittagong/chittagong_parser_test.rb +0 -55
- data/test/vendor/dhaka-2.2.1/test/chittagong/chittagong_test.rb +0 -170
- data/test/vendor/dhaka-2.2.1/test/core/another_lalr_but_not_slr_grammar.rb +0 -20
- data/test/vendor/dhaka-2.2.1/test/core/compiled_parser_test.rb +0 -44
- data/test/vendor/dhaka-2.2.1/test/core/dfa_test.rb +0 -170
- data/test/vendor/dhaka-2.2.1/test/core/evaluator_test.rb +0 -22
- data/test/vendor/dhaka-2.2.1/test/core/grammar_test.rb +0 -83
- data/test/vendor/dhaka-2.2.1/test/core/lalr_but_not_slr_grammar.rb +0 -19
- data/test/vendor/dhaka-2.2.1/test/core/lexer_test.rb +0 -139
- data/test/vendor/dhaka-2.2.1/test/core/malformed_grammar.rb +0 -7
- data/test/vendor/dhaka-2.2.1/test/core/malformed_grammar_test.rb +0 -8
- data/test/vendor/dhaka-2.2.1/test/core/nullable_grammar.rb +0 -21
- data/test/vendor/dhaka-2.2.1/test/core/parse_result_test.rb +0 -44
- data/test/vendor/dhaka-2.2.1/test/core/parser_state_test.rb +0 -24
- data/test/vendor/dhaka-2.2.1/test/core/parser_test.rb +0 -131
- data/test/vendor/dhaka-2.2.1/test/core/precedence_grammar.rb +0 -17
- data/test/vendor/dhaka-2.2.1/test/core/precedence_grammar_test.rb +0 -9
- data/test/vendor/dhaka-2.2.1/test/core/rr_conflict_grammar.rb +0 -21
- data/test/vendor/dhaka-2.2.1/test/core/simple_grammar.rb +0 -22
- data/test/vendor/dhaka-2.2.1/test/core/sr_conflict_grammar.rb +0 -16
- data/test/vendor/dhaka-2.2.1/test/dhaka_test_helper.rb +0 -17
- data/test/vendor/dhaka-2.2.1/test/fake_logger.rb +0 -17
- data/test/vendor/simplerdb-0.2/lib/simplerdb/client_exception.rb +0 -10
- data/test/vendor/simplerdb-0.2/lib/simplerdb/db.rb +0 -146
- data/test/vendor/simplerdb-0.2/lib/simplerdb/query_language.rb +0 -266
- data/test/vendor/simplerdb-0.2/lib/simplerdb/server.rb +0 -33
- data/test/vendor/simplerdb-0.2/lib/simplerdb/servlet.rb +0 -191
- data/test/vendor/simplerdb-0.2/lib/simplerdb.rb +0 -3
- data/test/vendor/simplerdb-0.2/test/functional_test.rb +0 -81
- data/test/vendor/simplerdb-0.2/test/query_evaluator_test.rb +0 -73
- data/test/vendor/simplerdb-0.2/test/query_parser_test.rb +0 -64
- data/test/vendor/simplerdb-0.2/test/simplerdb_test.rb +0 -80
data/lib/simply_stored/couch.rb
CHANGED
@@ -8,10 +8,13 @@ end
|
|
8
8
|
|
9
9
|
require File.expand_path(File.dirname(__FILE__) + '/../simply_stored')
|
10
10
|
require 'simply_stored/couch/validations'
|
11
|
+
require 'simply_stored/couch/association_property'
|
12
|
+
require 'simply_stored/couch/properties'
|
11
13
|
require 'simply_stored/couch/finders'
|
12
14
|
require 'simply_stored/couch/find_by'
|
13
15
|
require 'simply_stored/couch/belongs_to'
|
14
16
|
require 'simply_stored/couch/has_many'
|
17
|
+
require 'simply_stored/couch/has_and_belongs_to_many'
|
15
18
|
require 'simply_stored/couch/has_one'
|
16
19
|
require 'simply_stored/couch/ext/couch_potato'
|
17
20
|
require 'simply_stored/couch/views'
|
@@ -37,8 +40,10 @@ module SimplyStored
|
|
37
40
|
module ClassMethods
|
38
41
|
include SimplyStored::ClassMethods::Base
|
39
42
|
include SimplyStored::Couch::Validations
|
43
|
+
include SimplyStored::Couch::Properties
|
40
44
|
include SimplyStored::Couch::BelongsTo
|
41
45
|
include SimplyStored::Couch::HasMany
|
46
|
+
include SimplyStored::Couch::HasAndBelongsToMany
|
42
47
|
include SimplyStored::Couch::HasOne
|
43
48
|
include SimplyStored::Couch::Finders
|
44
49
|
include SimplyStored::Couch::FindBy
|
@@ -132,9 +137,40 @@ module SimplyStored
|
|
132
137
|
def _define_soft_delete_views
|
133
138
|
view :all_documents_without_deleted, :key => soft_delete_attribute
|
134
139
|
end
|
140
|
+
|
141
|
+
def _define_cache_accessors(name, options)
|
142
|
+
define_method "_get_cached_#{name}" do
|
143
|
+
instance_variable_get("@#{name}") || {}
|
144
|
+
end
|
145
|
+
|
146
|
+
define_method "_set_cached_#{name}" do |value, cache_key|
|
147
|
+
cached = send("_get_cached_#{name}")
|
148
|
+
cached[cache_key] = value
|
149
|
+
instance_variable_set("@#{name}", cached)
|
150
|
+
end
|
151
|
+
|
152
|
+
define_method "_cache_key_for" do |opt|
|
153
|
+
opt.blank? ? :all : opt.to_s
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def extract_association_options(local_options = nil)
|
159
|
+
forced_reload = false
|
160
|
+
with_deleted = false
|
161
|
+
limit = nil
|
162
|
+
descending = false
|
135
163
|
|
164
|
+
if local_options
|
165
|
+
local_options.assert_valid_keys(:force_reload, :with_deleted, :limit, :order)
|
166
|
+
forced_reload = local_options.delete(:force_reload)
|
167
|
+
with_deleted = local_options[:with_deleted]
|
168
|
+
limit = local_options[:limit]
|
169
|
+
descending = (local_options[:order] == :desc) ? true : false
|
170
|
+
end
|
171
|
+
return [forced_reload, with_deleted, limit, descending]
|
136
172
|
end
|
137
|
-
|
173
|
+
|
138
174
|
def self.delete_all_design_documents(database)
|
139
175
|
db = CouchRest.database(database)
|
140
176
|
db.info # ensure DB exists
|
@@ -148,4 +184,4 @@ module SimplyStored
|
|
148
184
|
end
|
149
185
|
|
150
186
|
end
|
151
|
-
end
|
187
|
+
end
|
@@ -144,21 +144,25 @@ module SimplyStored
|
|
144
144
|
def check_and_destroy_dependents
|
145
145
|
self.class.properties.each do |property|
|
146
146
|
if property.respond_to?(:association?) and property.association?
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
147
|
+
if property.is_a?(SimplyStored::Couch::HasAndBelongsToMany::Property)
|
148
|
+
has_and_belongs_to_many_clean_up_after_destroy(property)
|
149
|
+
else
|
150
|
+
next unless property.options[:dependent]
|
151
|
+
next if property.options[:through]
|
152
|
+
dependents = send(property.name, :force_reload => true)
|
153
|
+
dependents = [dependents] unless dependents.is_a?(Array)
|
154
|
+
dependents.reject{|d| d.nil?}.each do |dependent|
|
155
|
+
case property.options[:dependent]
|
156
|
+
when :destroy
|
157
|
+
dependent.destroy
|
158
|
+
when :ignore
|
159
|
+
# skip
|
160
|
+
else
|
161
|
+
# nullify
|
162
|
+
unless dependent.class.soft_deleting_enabled?
|
163
|
+
dependent.send("#{self.class.foreign_property}=", nil)
|
164
|
+
dependent.save(false)
|
165
|
+
end
|
162
166
|
end
|
163
167
|
end
|
164
168
|
end
|
@@ -166,6 +170,20 @@ module SimplyStored
|
|
166
170
|
end
|
167
171
|
end
|
168
172
|
|
173
|
+
def _default_view_options(options = {})
|
174
|
+
view_options = {:include_docs => true, :reduce => false}
|
175
|
+
view_options[:descending] = options[:descending] if options[:descending]
|
176
|
+
if view_options[:descending]
|
177
|
+
view_options[:startkey] = ["#{id}\u9999"]
|
178
|
+
view_options[:endkey] = [id]
|
179
|
+
else
|
180
|
+
view_options[:startkey] = [id]
|
181
|
+
view_options[:endkey] = ["#{id}\u9999"]
|
182
|
+
end
|
183
|
+
view_options[:limit] = options[:limit] if options[:limit]
|
184
|
+
view_options
|
185
|
+
end
|
186
|
+
|
169
187
|
def find_one_associated(from, to, options = {})
|
170
188
|
options = {
|
171
189
|
:limit => 1,
|
@@ -176,17 +194,8 @@ module SimplyStored
|
|
176
194
|
|
177
195
|
def find_associated(from, to, options = {})
|
178
196
|
foreign_key = (options.delete(:foreign_key) || self.class.name.singularize.underscore.foreign_key ).gsub(/_id$/, '')
|
179
|
-
view_options =
|
180
|
-
|
181
|
-
view_options[:descending] = options[:descending] if options[:descending]
|
182
|
-
if view_options[:descending]
|
183
|
-
view_options[:startkey] = ["#{id}\u9999"]
|
184
|
-
view_options[:endkey] = [id]
|
185
|
-
else
|
186
|
-
view_options[:startkey] = [id]
|
187
|
-
view_options[:endkey] = ["#{id}\u9999"]
|
188
|
-
end
|
189
|
-
view_options[:limit] = options[:limit] if options[:limit]
|
197
|
+
view_options = _default_view_options(options)
|
198
|
+
|
190
199
|
if options[:with_deleted]
|
191
200
|
CouchPotato.database.view(
|
192
201
|
self.class.get_class_from_name(from).send(
|
@@ -199,11 +208,10 @@ module SimplyStored
|
|
199
208
|
end
|
200
209
|
|
201
210
|
def count_associated(from, to, options = {})
|
202
|
-
view_options =
|
211
|
+
view_options = _default_view_options(options)
|
203
212
|
view_options[:reduce] = true
|
204
213
|
view_options[:include_docs] = false
|
205
|
-
|
206
|
-
view_options[:endkey] = ["#{id}\u9999"]
|
214
|
+
|
207
215
|
if options[:with_deleted]
|
208
216
|
CouchPotato.database.view(
|
209
217
|
self.class.get_class_from_name(from).send(
|
@@ -215,6 +223,37 @@ module SimplyStored
|
|
215
223
|
end
|
216
224
|
end
|
217
225
|
|
226
|
+
def find_associated_via_join_view(from, to, options = {})
|
227
|
+
foreign_key = options.delete(:foreign_key).gsub(/_ids$/, '').pluralize
|
228
|
+
view_options = _default_view_options(options)
|
229
|
+
|
230
|
+
if options[:with_deleted]
|
231
|
+
CouchPotato.database.view(
|
232
|
+
self.class.get_class_from_name(from).send(
|
233
|
+
"association_#{from.to_s.singularize.underscore}_has_and_belongs_to_many_#{to.to_s.pluralize.underscore}_with_deleted", view_options))
|
234
|
+
else
|
235
|
+
CouchPotato.database.view(
|
236
|
+
self.class.get_class_from_name(from).send(
|
237
|
+
"association_#{from.to_s.singularize.underscore}_has_and_belongs_to_many_#{to.to_s.pluralize.underscore}", view_options))
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
def count_associated_via_join_view(from, to, options = {})
|
242
|
+
view_options = _default_view_options(options)
|
243
|
+
view_options[:reduce] = true
|
244
|
+
view_options[:include_docs] = false
|
245
|
+
|
246
|
+
if options[:with_deleted]
|
247
|
+
CouchPotato.database.view(
|
248
|
+
self.class.get_class_from_name(from).send(
|
249
|
+
"association_#{from.to_s.singularize.underscore}_has_and_belongs_to_many_#{to.to_s.pluralize.underscore}_with_deleted", view_options))
|
250
|
+
else
|
251
|
+
CouchPotato.database.view(
|
252
|
+
self.class.get_class_from_name(from).send(
|
253
|
+
"association_#{from.to_s.singularize.underscore}_has_and_belongs_to_many_#{to.to_s.pluralize.underscore}", view_options))
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
218
257
|
def _mark_as_deleted
|
219
258
|
run_callbacks(:before_destroy)
|
220
259
|
send("#{self.class.soft_delete_attribute}=", Time.now)
|
data/lib/simply_stored.rb
CHANGED
@@ -4,7 +4,9 @@ require File.expand_path(File.dirname(__FILE__) + '/simply_stored/storage')
|
|
4
4
|
require File.expand_path(File.dirname(__FILE__) + '/simply_stored/class_methods_base')
|
5
5
|
|
6
6
|
module SimplyStored
|
7
|
-
VERSION = '0.
|
7
|
+
VERSION = '0.5.0'
|
8
8
|
class Error < RuntimeError; end
|
9
9
|
class RecordNotFound < RuntimeError; end
|
10
10
|
end
|
11
|
+
|
12
|
+
require File.expand_path(File.dirname(__FILE__) + '/simply_stored/couch')
|
data/test/{couchdb/couch_active_model_compatibility_test.rb → active_model_compatibility_test.rb}
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__) + '
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
2
|
|
3
3
|
begin
|
4
4
|
require 'active_model'
|
@@ -9,7 +9,7 @@ begin
|
|
9
9
|
validates_presence_of :name
|
10
10
|
end
|
11
11
|
|
12
|
-
class
|
12
|
+
class ActiveModelCompatibilityTest < Test::Unit::TestCase
|
13
13
|
def setup
|
14
14
|
@model = CouchModel.new
|
15
15
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require File.
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/fixtures/couch')
|
3
3
|
|
4
|
-
class
|
4
|
+
class BelongsToTest < Test::Unit::TestCase
|
5
5
|
context "with associations" do
|
6
6
|
setup do
|
7
7
|
CouchPotato::Config.database_name = 'simply_stored_test'
|
@@ -12,6 +12,16 @@ class CouchBelongsToTest < Test::Unit::TestCase
|
|
12
12
|
should "generate a view for the association" do
|
13
13
|
assert Post.respond_to?(:association_post_belongs_to_user)
|
14
14
|
end
|
15
|
+
|
16
|
+
should "raise an error if another property with the same name already exists" do
|
17
|
+
assert_raise(RuntimeError) do
|
18
|
+
class ::DoubleBelongsToUser
|
19
|
+
include SimplyStored::Couch
|
20
|
+
property :user
|
21
|
+
belongs_to :user
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
15
25
|
|
16
26
|
should "add the foreign key id to the referencing object" do
|
17
27
|
user = User.create(:title => "Mr.")
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require File.
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/fixtures/couch')
|
3
3
|
|
4
|
-
class
|
4
|
+
class ConflictHandlingTest < Test::Unit::TestCase
|
5
5
|
context "when handling conflicts" do
|
6
6
|
setup do
|
7
7
|
CouchPotato::Config.database_name = 'simply_stored_test'
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require File.
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/fixtures/couch')
|
3
3
|
|
4
|
-
class
|
4
|
+
class FinderTest < Test::Unit::TestCase
|
5
5
|
context "when finding instances" do
|
6
6
|
setup do
|
7
7
|
CouchPotato::Config.database_name = 'simply_stored_test'
|
@@ -52,6 +52,11 @@ class CouchFinderTest < Test::Unit::TestCase
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
+
should 'find the last as a reverse first' do
|
56
|
+
User.expects(:find).with(:first, :order => :desc)
|
57
|
+
User.last
|
58
|
+
end
|
59
|
+
|
55
60
|
should 'return nil when no user found' do
|
56
61
|
assert_nil User.first
|
57
62
|
end
|
data/test/fixtures/couch.rb
CHANGED
@@ -33,6 +33,7 @@ class Comment
|
|
33
33
|
include SimplyStored::Couch
|
34
34
|
|
35
35
|
belongs_to :user
|
36
|
+
belongs_to :network
|
36
37
|
end
|
37
38
|
|
38
39
|
class Category
|
@@ -229,3 +230,57 @@ class BigProblem < Problem
|
|
229
230
|
|
230
231
|
end
|
231
232
|
|
233
|
+
class Server
|
234
|
+
include SimplyStored::Couch
|
235
|
+
|
236
|
+
property :hostname
|
237
|
+
|
238
|
+
has_and_belongs_to_many :networks, :storing_keys => true
|
239
|
+
has_and_belongs_to_many :subnets, :storing_keys => true
|
240
|
+
has_and_belongs_to_many :ips, :storing_keys => false
|
241
|
+
end
|
242
|
+
|
243
|
+
class Network
|
244
|
+
include SimplyStored::Couch
|
245
|
+
|
246
|
+
property :klass
|
247
|
+
|
248
|
+
has_and_belongs_to_many :servers, :storing_keys => false
|
249
|
+
has_and_belongs_to_many :routers, :storing_keys => false
|
250
|
+
end
|
251
|
+
|
252
|
+
class Subnet < Network
|
253
|
+
has_and_belongs_to_many :servers, :storing_keys => false
|
254
|
+
end
|
255
|
+
|
256
|
+
class Ip
|
257
|
+
include SimplyStored::Couch
|
258
|
+
|
259
|
+
has_and_belongs_to_many :servers, :storing_keys => true
|
260
|
+
end
|
261
|
+
|
262
|
+
class Router
|
263
|
+
include SimplyStored::Couch
|
264
|
+
enable_soft_delete
|
265
|
+
|
266
|
+
property :hostname
|
267
|
+
|
268
|
+
has_and_belongs_to_many :networks, :storing_keys => true
|
269
|
+
end
|
270
|
+
|
271
|
+
class Book
|
272
|
+
include SimplyStored::Couch
|
273
|
+
|
274
|
+
property :title
|
275
|
+
|
276
|
+
has_and_belongs_to_many :authors, :storing_keys => true
|
277
|
+
end
|
278
|
+
|
279
|
+
class Author
|
280
|
+
include SimplyStored::Couch
|
281
|
+
enable_soft_delete
|
282
|
+
|
283
|
+
property :name
|
284
|
+
|
285
|
+
has_and_belongs_to_many :books, :storing_keys => false
|
286
|
+
end
|