mongo_mapper 0.6.8 → 0.6.9

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 (44) hide show
  1. data/README.rdoc +2 -17
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/lib/mongo_mapper/associations/base.rb +19 -10
  5. data/lib/mongo_mapper/associations/in_array_proxy.rb +137 -0
  6. data/lib/mongo_mapper/associations/one_proxy.rb +61 -0
  7. data/lib/mongo_mapper/associations/proxy.rb +0 -2
  8. data/lib/mongo_mapper/associations.rb +5 -3
  9. data/lib/mongo_mapper/callbacks.rb +30 -78
  10. data/lib/mongo_mapper/dirty.rb +5 -24
  11. data/lib/mongo_mapper/document.rb +117 -144
  12. data/lib/mongo_mapper/embedded_document.rb +7 -11
  13. data/lib/mongo_mapper/finder_options.rb +42 -30
  14. data/lib/mongo_mapper/mongo_mapper.rb +125 -0
  15. data/lib/mongo_mapper/pagination.rb +12 -1
  16. data/lib/mongo_mapper/rails_compatibility/embedded_document.rb +1 -0
  17. data/lib/mongo_mapper/serialization.rb +2 -2
  18. data/lib/mongo_mapper/serializers/json_serializer.rb +2 -46
  19. data/lib/mongo_mapper/support.rb +5 -2
  20. data/lib/mongo_mapper/validations.rb +1 -3
  21. data/lib/mongo_mapper.rb +8 -2
  22. data/mongo_mapper.gemspec +14 -8
  23. data/specs.watchr +3 -5
  24. data/test/functional/associations/test_belongs_to_proxy.rb +43 -0
  25. data/test/functional/associations/test_in_array_proxy.rb +309 -0
  26. data/test/functional/associations/test_many_documents_proxy.rb +103 -53
  27. data/test/functional/associations/test_many_polymorphic_proxy.rb +4 -3
  28. data/test/functional/associations/test_one_proxy.rb +131 -0
  29. data/test/functional/test_binary.rb +15 -0
  30. data/test/functional/test_document.rb +581 -631
  31. data/test/functional/test_modifiers.rb +242 -0
  32. data/test/functional/test_validations.rb +0 -17
  33. data/test/models.rb +1 -1
  34. data/test/support/timing.rb +1 -1
  35. data/test/unit/associations/test_base.rb +54 -13
  36. data/test/unit/test_document.rb +32 -0
  37. data/test/unit/test_embedded_document.rb +0 -9
  38. data/test/unit/test_finder_options.rb +36 -7
  39. data/test/unit/test_pagination.rb +6 -0
  40. data/test/unit/test_rails_compatibility.rb +4 -1
  41. data/test/unit/test_support.rb +4 -0
  42. metadata +12 -6
  43. data/lib/mongo_mapper/observing.rb +0 -50
  44. data/test/unit/test_observing.rb +0 -101
@@ -0,0 +1,125 @@
1
+ # if Gem is defined i'll assume you are using rubygems and lock specific versions
2
+ # call me crazy but a plain old require will just get the latest version you have installed
3
+ # so i want to make sure that if you are using gems you do in fact have the correct versions
4
+ # if there is a better way to do this, please enlighten me!
5
+ if self.class.const_defined?(:Gem)
6
+ gem 'activesupport', '>= 2.3'
7
+ gem 'mongo', '0.18.2'
8
+ gem 'jnunemaker-validatable', '1.8.1'
9
+ end
10
+
11
+ require 'active_support'
12
+ require 'mongo'
13
+ require 'validatable'
14
+
15
+ module MongoMapper
16
+ # generic MM error
17
+ class MongoMapperError < StandardError; end
18
+
19
+ # raised when key expected to exist but not found
20
+ class KeyNotFound < MongoMapperError; end
21
+
22
+ # raised when document expected but not found
23
+ class DocumentNotFound < MongoMapperError; end
24
+
25
+ # raised when document not valid and using !
26
+ class DocumentNotValid < MongoMapperError
27
+ def initialize(document)
28
+ super("Validation failed: #{document.errors.full_messages.join(", ")}")
29
+ end
30
+ end
31
+
32
+ # @api public
33
+ def self.connection
34
+ @@connection ||= Mongo::Connection.new
35
+ end
36
+
37
+ # @api public
38
+ def self.connection=(new_connection)
39
+ @@connection = new_connection
40
+ end
41
+
42
+ # @api public
43
+ def self.logger
44
+ connection.logger
45
+ end
46
+
47
+ # @api public
48
+ def self.database=(name)
49
+ @@database = nil
50
+ @@database_name = name
51
+ end
52
+
53
+ # @api public
54
+ def self.database
55
+ if @@database_name.blank?
56
+ raise 'You forgot to set the default database name: MongoMapper.database = "foobar"'
57
+ end
58
+
59
+ @@database ||= MongoMapper.connection.db(@@database_name)
60
+ end
61
+
62
+ # @api private
63
+ def self.ensured_indexes
64
+ @@ensured_indexes ||= []
65
+ end
66
+
67
+ # @api private
68
+ def self.ensured_indexes=(value)
69
+ @@ensured_indexes = value
70
+ end
71
+
72
+ # @api private
73
+ def self.ensure_index(klass, keys, options={})
74
+ ensured_indexes << {:klass => klass, :keys => keys, :options => options}
75
+ end
76
+
77
+ # @api public
78
+ def self.ensure_indexes!
79
+ ensured_indexes.each do |index|
80
+ unique = index[:options].delete(:unique)
81
+ index[:klass].collection.create_index(index[:keys], unique)
82
+ end
83
+ end
84
+
85
+ # @api private
86
+ def self.use_time_zone?
87
+ Time.respond_to?(:zone) && Time.zone ? true : false
88
+ end
89
+
90
+ # @api private
91
+ def self.time_class
92
+ use_time_zone? ? Time.zone : Time
93
+ end
94
+
95
+ # @api private
96
+ def self.normalize_object_id(value)
97
+ value.is_a?(String) ? Mongo::ObjectID.from_string(value) : value
98
+ end
99
+ end
100
+
101
+ require 'mongo_mapper/support'
102
+ require 'mongo_mapper/callbacks'
103
+ require 'mongo_mapper/finder_options'
104
+ require 'mongo_mapper/dirty'
105
+ require 'mongo_mapper/dynamic_finder'
106
+ require 'mongo_mapper/key'
107
+ require 'mongo_mapper/pagination'
108
+ require 'mongo_mapper/serialization'
109
+ require 'mongo_mapper/validations'
110
+ require 'mongo_mapper/rails_compatibility/document'
111
+ require 'mongo_mapper/rails_compatibility/embedded_document'
112
+ require 'mongo_mapper/embedded_document'
113
+ require 'mongo_mapper/document'
114
+ require 'mongo_mapper/associations'
115
+ require 'mongo_mapper/associations/base'
116
+ require 'mongo_mapper/associations/proxy'
117
+ require 'mongo_mapper/associations/collection'
118
+ require 'mongo_mapper/associations/many_documents_proxy'
119
+ require 'mongo_mapper/associations/belongs_to_proxy'
120
+ require 'mongo_mapper/associations/belongs_to_polymorphic_proxy'
121
+ require 'mongo_mapper/associations/many_polymorphic_proxy'
122
+ require 'mongo_mapper/associations/many_embedded_proxy'
123
+ require 'mongo_mapper/associations/many_embedded_polymorphic_proxy'
124
+ require 'mongo_mapper/associations/many_documents_as_proxy'
125
+ require 'mongo_mapper/associations/one_proxy'
@@ -1,7 +1,7 @@
1
1
  module MongoMapper
2
2
  module Pagination
3
3
  class PaginationProxy
4
- instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil\?$|proxy_|^object_id$)/ }
4
+ instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil\?$|^send$|proxy_|^object_id$)/ }
5
5
 
6
6
  attr_accessor :subject
7
7
  attr_reader :total_entries, :per_page, :current_page
@@ -33,7 +33,18 @@ module MongoMapper
33
33
  (current_page - 1) * per_page
34
34
  end
35
35
  alias offset skip # for will paginate support
36
+
37
+ def send(method, *args, &block)
38
+ if respond_to?(method)
39
+ super
40
+ else
41
+ subject.send(method, *args, &block)
42
+ end
43
+ end
36
44
 
45
+ def ===(other)
46
+ other === subject
47
+ end
37
48
 
38
49
  def method_missing(name, *args, &block)
39
50
  @subject.send(name, *args, &block)
@@ -10,6 +10,7 @@ module MongoMapper
10
10
 
11
11
  class << model
12
12
  alias has_many many
13
+ alias has_one one
13
14
  end
14
15
  end
15
16
 
@@ -1,8 +1,8 @@
1
1
  require 'active_support/json'
2
2
 
3
- module MongoMapper #:nodoc:
3
+ module MongoMapper
4
4
  module Serialization
5
- class Serializer #:nodoc:
5
+ class Serializer
6
6
  attr_reader :options
7
7
 
8
8
  def initialize(record, options={})
@@ -1,54 +1,10 @@
1
- module MongoMapper #:nodoc:
1
+ module MongoMapper
2
2
  module Serialization
3
3
  def self.included(base)
4
4
  base.cattr_accessor :include_root_in_json, :instance_writer => false
5
5
  base.extend ClassMethods
6
6
  end
7
7
 
8
- # Returns a JSON string representing the model. Some configuration is
9
- # available through +options+.
10
- #
11
- # The option <tt>include_root_in_json</tt> controls the top-level behavior of
12
- # to_json. When it is <tt>true</tt>, to_json will emit a single root node named
13
- # after the object's type. For example:
14
- #
15
- # konata = User.find(1)
16
- # User.include_root_in_json = true
17
- # konata.to_json
18
- # # => { "user": {"id": 1, "name": "Konata Izumi", "age": 16,
19
- # "created_at": "2006/08/01", "awesome": true} }
20
- #
21
- # User.include_root_in_json = false
22
- # konata.to_json
23
- # # => {"id": 1, "name": "Konata Izumi", "age": 16,
24
- # "created_at": "2006/08/01", "awesome": true}
25
- #
26
- # The remainder of the examples in this section assume include_root_in_json is set to
27
- # <tt>false</tt>.
28
- #
29
- # Without any +options+, the returned JSON string will include all
30
- # the model's attributes. For example:
31
- #
32
- # konata = User.find(1)
33
- # konata.to_json
34
- # # => {"id": 1, "name": "Konata Izumi", "age": 16,
35
- # "created_at": "2006/08/01", "awesome": true}
36
- #
37
- # The <tt>:only</tt> and <tt>:except</tt> options can be used to limit the attributes
38
- # included, and work similar to the +attributes+ method. For example:
39
- #
40
- # konata.to_json(:only => [ :id, :name ])
41
- # # => {"id": 1, "name": "Konata Izumi"}
42
- #
43
- # konata.to_json(:except => [ :id, :created_at, :age ])
44
- # # => {"name": "Konata Izumi", "awesome": true}
45
- #
46
- # To include any methods on the model, use <tt>:methods</tt>.
47
- #
48
- # konata.to_json(:methods => :permalink)
49
- # # => {"id": 1, "name": "Konata Izumi", "age": 16,
50
- # "created_at": "2006/08/01", "awesome": true,
51
- # "permalink": "1-konata-izumi"}
52
8
  def to_json(options={})
53
9
  apply_to_json_defaults(options)
54
10
 
@@ -64,7 +20,7 @@ module MongoMapper #:nodoc:
64
20
  self
65
21
  end
66
22
 
67
- class JsonSerializer < MongoMapper::Serialization::Serializer #:nodoc:
23
+ class JsonSerializer < MongoMapper::Serialization::Serializer
68
24
  def serialize
69
25
  serializable_record.to_json
70
26
  end
@@ -120,7 +120,7 @@ end
120
120
 
121
121
  class ObjectId
122
122
  def self.to_mongo(value)
123
- if value.nil?
123
+ if value.blank?
124
124
  nil
125
125
  elsif value.is_a?(Mongo::ObjectID)
126
126
  value
@@ -160,9 +160,12 @@ class Symbol
160
160
  MongoMapper::FinderOperator.new(self, "$#{operator}")
161
161
  end
162
162
  end
163
+
164
+ def asc; MongoMapper::OrderOperator.new(self, 'asc') end
165
+ def desc; MongoMapper::OrderOperator.new(self, 'desc') end
163
166
  end
164
167
 
165
- class Time
168
+ class Time
166
169
  def self.to_mongo(value)
167
170
  if value.nil? || value == ''
168
171
  nil
@@ -31,9 +31,7 @@ module MongoMapper
31
31
 
32
32
  def where_conditions(instance)
33
33
  conditions = {}
34
- unless case_sensitive
35
- conditions.merge!({'$where' => "this.#{attribute}.toLowerCase() == '#{instance[attribute].to_s.downcase}'"})
36
- end
34
+ conditions[attribute] = /#{instance[attribute].to_s}/i unless case_sensitive
37
35
  conditions
38
36
  end
39
37
  end
data/lib/mongo_mapper.rb CHANGED
@@ -4,7 +4,7 @@
4
4
  # if there is a better way to do this, please enlighten me!
5
5
  if self.class.const_defined?(:Gem)
6
6
  gem 'activesupport', '>= 2.3'
7
- gem 'mongo', '0.18.1'
7
+ gem 'mongo', '0.18.2'
8
8
  gem 'jnunemaker-validatable', '1.8.1'
9
9
  end
10
10
 
@@ -64,6 +64,11 @@ module MongoMapper
64
64
  @@ensured_indexes ||= []
65
65
  end
66
66
 
67
+ # @api private
68
+ def self.ensured_indexes=(value)
69
+ @@ensured_indexes = value
70
+ end
71
+
67
72
  # @api private
68
73
  def self.ensure_index(klass, keys, options={})
69
74
  ensured_indexes << {:klass => klass, :keys => keys, :options => options}
@@ -99,7 +104,6 @@ require 'mongo_mapper/finder_options'
99
104
  require 'mongo_mapper/dirty'
100
105
  require 'mongo_mapper/dynamic_finder'
101
106
  require 'mongo_mapper/key'
102
- require 'mongo_mapper/observing'
103
107
  require 'mongo_mapper/pagination'
104
108
  require 'mongo_mapper/serialization'
105
109
  require 'mongo_mapper/validations'
@@ -118,3 +122,5 @@ require 'mongo_mapper/associations/many_polymorphic_proxy'
118
122
  require 'mongo_mapper/associations/many_embedded_proxy'
119
123
  require 'mongo_mapper/associations/many_embedded_polymorphic_proxy'
120
124
  require 'mongo_mapper/associations/many_documents_as_proxy'
125
+ require 'mongo_mapper/associations/one_proxy'
126
+ require 'mongo_mapper/associations/in_array_proxy'
data/mongo_mapper.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongo_mapper}
8
- s.version = "0.6.8"
8
+ s.version = "0.6.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Nunemaker"]
12
- s.date = %q{2009-12-15}
12
+ s.date = %q{2010-01-01}
13
13
  s.default_executable = %q{mmconsole}
14
14
  s.email = %q{nunemaker@gmail.com}
15
15
  s.executables = ["mmconsole"]
@@ -30,11 +30,13 @@ Gem::Specification.new do |s|
30
30
  "lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb",
31
31
  "lib/mongo_mapper/associations/belongs_to_proxy.rb",
32
32
  "lib/mongo_mapper/associations/collection.rb",
33
+ "lib/mongo_mapper/associations/in_array_proxy.rb",
33
34
  "lib/mongo_mapper/associations/many_documents_as_proxy.rb",
34
35
  "lib/mongo_mapper/associations/many_documents_proxy.rb",
35
36
  "lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb",
36
37
  "lib/mongo_mapper/associations/many_embedded_proxy.rb",
37
38
  "lib/mongo_mapper/associations/many_polymorphic_proxy.rb",
39
+ "lib/mongo_mapper/associations/one_proxy.rb",
38
40
  "lib/mongo_mapper/associations/proxy.rb",
39
41
  "lib/mongo_mapper/callbacks.rb",
40
42
  "lib/mongo_mapper/dirty.rb",
@@ -43,7 +45,7 @@ Gem::Specification.new do |s|
43
45
  "lib/mongo_mapper/embedded_document.rb",
44
46
  "lib/mongo_mapper/finder_options.rb",
45
47
  "lib/mongo_mapper/key.rb",
46
- "lib/mongo_mapper/observing.rb",
48
+ "lib/mongo_mapper/mongo_mapper.rb",
47
49
  "lib/mongo_mapper/pagination.rb",
48
50
  "lib/mongo_mapper/rails_compatibility/document.rb",
49
51
  "lib/mongo_mapper/rails_compatibility/embedded_document.rb",
@@ -56,11 +58,13 @@ Gem::Specification.new do |s|
56
58
  "test/NOTE_ON_TESTING",
57
59
  "test/functional/associations/test_belongs_to_polymorphic_proxy.rb",
58
60
  "test/functional/associations/test_belongs_to_proxy.rb",
61
+ "test/functional/associations/test_in_array_proxy.rb",
59
62
  "test/functional/associations/test_many_documents_as_proxy.rb",
60
63
  "test/functional/associations/test_many_documents_proxy.rb",
61
64
  "test/functional/associations/test_many_embedded_polymorphic_proxy.rb",
62
65
  "test/functional/associations/test_many_embedded_proxy.rb",
63
66
  "test/functional/associations/test_many_polymorphic_proxy.rb",
67
+ "test/functional/associations/test_one_proxy.rb",
64
68
  "test/functional/test_associations.rb",
65
69
  "test/functional/test_binary.rb",
66
70
  "test/functional/test_callbacks.rb",
@@ -68,6 +72,7 @@ Gem::Specification.new do |s|
68
72
  "test/functional/test_document.rb",
69
73
  "test/functional/test_embedded_document.rb",
70
74
  "test/functional/test_logger.rb",
75
+ "test/functional/test_modifiers.rb",
71
76
  "test/functional/test_pagination.rb",
72
77
  "test/functional/test_rails_compatibility.rb",
73
78
  "test/functional/test_string_id_compatibility.rb",
@@ -85,7 +90,6 @@ Gem::Specification.new do |s|
85
90
  "test/unit/test_finder_options.rb",
86
91
  "test/unit/test_key.rb",
87
92
  "test/unit/test_mongo_mapper.rb",
88
- "test/unit/test_observing.rb",
89
93
  "test/unit/test_pagination.rb",
90
94
  "test/unit/test_rails_compatibility.rb",
91
95
  "test/unit/test_serializations.rb",
@@ -101,11 +105,13 @@ Gem::Specification.new do |s|
101
105
  s.test_files = [
102
106
  "test/functional/associations/test_belongs_to_polymorphic_proxy.rb",
103
107
  "test/functional/associations/test_belongs_to_proxy.rb",
108
+ "test/functional/associations/test_in_array_proxy.rb",
104
109
  "test/functional/associations/test_many_documents_as_proxy.rb",
105
110
  "test/functional/associations/test_many_documents_proxy.rb",
106
111
  "test/functional/associations/test_many_embedded_polymorphic_proxy.rb",
107
112
  "test/functional/associations/test_many_embedded_proxy.rb",
108
113
  "test/functional/associations/test_many_polymorphic_proxy.rb",
114
+ "test/functional/associations/test_one_proxy.rb",
109
115
  "test/functional/test_associations.rb",
110
116
  "test/functional/test_binary.rb",
111
117
  "test/functional/test_callbacks.rb",
@@ -113,6 +119,7 @@ Gem::Specification.new do |s|
113
119
  "test/functional/test_document.rb",
114
120
  "test/functional/test_embedded_document.rb",
115
121
  "test/functional/test_logger.rb",
122
+ "test/functional/test_modifiers.rb",
116
123
  "test/functional/test_pagination.rb",
117
124
  "test/functional/test_rails_compatibility.rb",
118
125
  "test/functional/test_string_id_compatibility.rb",
@@ -130,7 +137,6 @@ Gem::Specification.new do |s|
130
137
  "test/unit/test_finder_options.rb",
131
138
  "test/unit/test_key.rb",
132
139
  "test/unit/test_mongo_mapper.rb",
133
- "test/unit/test_observing.rb",
134
140
  "test/unit/test_pagination.rb",
135
141
  "test/unit/test_rails_compatibility.rb",
136
142
  "test/unit/test_serializations.rb",
@@ -145,7 +151,7 @@ Gem::Specification.new do |s|
145
151
 
146
152
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
147
153
  s.add_runtime_dependency(%q<activesupport>, [">= 2.3"])
148
- s.add_runtime_dependency(%q<mongo>, ["= 0.18.1"])
154
+ s.add_runtime_dependency(%q<mongo>, ["= 0.18.2"])
149
155
  s.add_runtime_dependency(%q<jnunemaker-validatable>, ["= 1.8.1"])
150
156
  s.add_development_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
151
157
  s.add_development_dependency(%q<shoulda>, ["= 2.10.2"])
@@ -153,7 +159,7 @@ Gem::Specification.new do |s|
153
159
  s.add_development_dependency(%q<mocha>, ["= 0.9.8"])
154
160
  else
155
161
  s.add_dependency(%q<activesupport>, [">= 2.3"])
156
- s.add_dependency(%q<mongo>, ["= 0.18.1"])
162
+ s.add_dependency(%q<mongo>, ["= 0.18.2"])
157
163
  s.add_dependency(%q<jnunemaker-validatable>, ["= 1.8.1"])
158
164
  s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
159
165
  s.add_dependency(%q<shoulda>, ["= 2.10.2"])
@@ -162,7 +168,7 @@ Gem::Specification.new do |s|
162
168
  end
163
169
  else
164
170
  s.add_dependency(%q<activesupport>, [">= 2.3"])
165
- s.add_dependency(%q<mongo>, ["= 0.18.1"])
171
+ s.add_dependency(%q<mongo>, ["= 0.18.2"])
166
172
  s.add_dependency(%q<jnunemaker-validatable>, ["= 1.8.1"])
167
173
  s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
168
174
  s.add_dependency(%q<shoulda>, ["= 2.10.2"])
data/specs.watchr CHANGED
@@ -15,11 +15,9 @@ def related_test_files(path)
15
15
  Dir['test/**/*.rb'].select { |file| file =~ /test_#{File.basename(path)}/ }
16
16
  end
17
17
 
18
- watch('test/test_helper\.rb') { run_all_tests }
19
- watch('test/.*/test_.*\.rb') { |m| run_test_file(m[0]) }
20
- watch('lib/.*') do |m|
21
- related_test_files(m[0]).each { |file| run_test_file(file) }
22
- end
18
+ watch('test/test_helper\.rb') { system('clear'); run_all_tests }
19
+ watch('test/.*/test_.*\.rb') { |m| system('clear'); run_test_file(m[0]) }
20
+ watch('lib/.*') { |m| related_test_files(m[0]).each { |file| system('clear'); run_test_file(file) } }
23
21
 
24
22
  # Ctrl-\
25
23
  Signal.trap('QUIT') do
@@ -45,4 +45,47 @@ class BelongsToProxyTest < Test::Unit::TestCase
45
45
  id = Mongo::ObjectID.new
46
46
  @comment_class.new(:name => 'Foo', :post_id => id).post.nil?.should be_true
47
47
  end
48
+
49
+ context ":dependent" do
50
+ setup do
51
+ # FIXME: make use of already defined models
52
+ class ::Property
53
+ include MongoMapper::Document
54
+ end
55
+ Property.collection.remove
56
+
57
+ class ::Thing
58
+ include MongoMapper::Document
59
+ key :name, String
60
+ end
61
+ Thing.collection.remove
62
+ end
63
+
64
+ teardown do
65
+ Object.send :remove_const, 'Property' if defined?(::Property)
66
+ Object.send :remove_const, 'Thing' if defined?(::Thing)
67
+ end
68
+
69
+ context "=> destroy" do
70
+ setup do
71
+ Property.key :thing_id, ObjectId
72
+ Property.belongs_to :thing, :dependent => :destroy
73
+ Thing.has_many :properties
74
+
75
+ @thing = Thing.create(:name => "Tree")
76
+ @property1 = Property.create
77
+ @property2 = Property.create
78
+ @property3 = Property.create
79
+ @thing.properties << @property1
80
+ @thing.properties << @property2
81
+ @thing.properties << @property3
82
+ end
83
+
84
+ should "not execute on a belongs_to association" do
85
+ Thing.count.should == 1
86
+ @property1.destroy
87
+ Thing.count.should == 1
88
+ end
89
+ end
90
+ end
48
91
  end