mongo_mapper-unstable 2009.10.11

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 (73) hide show
  1. data/.gitignore +8 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +50 -0
  4. data/Rakefile +87 -0
  5. data/VERSION +1 -0
  6. data/bin/mmconsole +55 -0
  7. data/lib/mongo_mapper/associations/base.rb +83 -0
  8. data/lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb +34 -0
  9. data/lib/mongo_mapper/associations/belongs_to_proxy.rb +22 -0
  10. data/lib/mongo_mapper/associations/many_documents_as_proxy.rb +27 -0
  11. data/lib/mongo_mapper/associations/many_documents_proxy.rb +116 -0
  12. data/lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb +33 -0
  13. data/lib/mongo_mapper/associations/many_embedded_proxy.rb +67 -0
  14. data/lib/mongo_mapper/associations/many_polymorphic_proxy.rb +11 -0
  15. data/lib/mongo_mapper/associations/many_proxy.rb +6 -0
  16. data/lib/mongo_mapper/associations/proxy.rb +74 -0
  17. data/lib/mongo_mapper/associations.rb +86 -0
  18. data/lib/mongo_mapper/callbacks.rb +106 -0
  19. data/lib/mongo_mapper/dirty.rb +137 -0
  20. data/lib/mongo_mapper/document.rb +340 -0
  21. data/lib/mongo_mapper/dynamic_finder.rb +35 -0
  22. data/lib/mongo_mapper/embedded_document.rb +355 -0
  23. data/lib/mongo_mapper/finder_options.rb +98 -0
  24. data/lib/mongo_mapper/key.rb +36 -0
  25. data/lib/mongo_mapper/observing.rb +50 -0
  26. data/lib/mongo_mapper/pagination.rb +51 -0
  27. data/lib/mongo_mapper/rails_compatibility/document.rb +15 -0
  28. data/lib/mongo_mapper/rails_compatibility/embedded_document.rb +27 -0
  29. data/lib/mongo_mapper/save_with_validation.rb +19 -0
  30. data/lib/mongo_mapper/serialization.rb +55 -0
  31. data/lib/mongo_mapper/serializers/json_serializer.rb +92 -0
  32. data/lib/mongo_mapper/support.rb +161 -0
  33. data/lib/mongo_mapper/validations.rb +69 -0
  34. data/lib/mongo_mapper.rb +111 -0
  35. data/mongo_mapper.gemspec +162 -0
  36. data/specs.watchr +32 -0
  37. data/test/NOTE_ON_TESTING +1 -0
  38. data/test/custom_matchers.rb +55 -0
  39. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +55 -0
  40. data/test/functional/associations/test_belongs_to_proxy.rb +49 -0
  41. data/test/functional/associations/test_many_documents_as_proxy.rb +244 -0
  42. data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +132 -0
  43. data/test/functional/associations/test_many_embedded_proxy.rb +174 -0
  44. data/test/functional/associations/test_many_polymorphic_proxy.rb +297 -0
  45. data/test/functional/associations/test_many_proxy.rb +331 -0
  46. data/test/functional/test_associations.rb +44 -0
  47. data/test/functional/test_binary.rb +18 -0
  48. data/test/functional/test_callbacks.rb +85 -0
  49. data/test/functional/test_dirty.rb +138 -0
  50. data/test/functional/test_document.rb +1051 -0
  51. data/test/functional/test_embedded_document.rb +97 -0
  52. data/test/functional/test_logger.rb +20 -0
  53. data/test/functional/test_pagination.rb +87 -0
  54. data/test/functional/test_rails_compatibility.rb +30 -0
  55. data/test/functional/test_validations.rb +279 -0
  56. data/test/models.rb +195 -0
  57. data/test/test_helper.rb +30 -0
  58. data/test/unit/serializers/test_json_serializer.rb +189 -0
  59. data/test/unit/test_association_base.rb +144 -0
  60. data/test/unit/test_document.rb +184 -0
  61. data/test/unit/test_dynamic_finder.rb +125 -0
  62. data/test/unit/test_embedded_document.rb +656 -0
  63. data/test/unit/test_finder_options.rb +261 -0
  64. data/test/unit/test_key.rb +172 -0
  65. data/test/unit/test_mongomapper.rb +28 -0
  66. data/test/unit/test_observing.rb +101 -0
  67. data/test/unit/test_pagination.rb +109 -0
  68. data/test/unit/test_rails_compatibility.rb +39 -0
  69. data/test/unit/test_serializations.rb +52 -0
  70. data/test/unit/test_support.rb +291 -0
  71. data/test/unit/test_time_zones.rb +40 -0
  72. data/test/unit/test_validations.rb +503 -0
  73. metadata +210 -0
@@ -0,0 +1,111 @@
1
+ require 'rubygems'
2
+
3
+ gem 'activesupport'
4
+ gem 'mongo', '0.15.1'
5
+ gem 'jnunemaker-validatable', '1.7.4'
6
+
7
+ require 'activesupport'
8
+ require 'mongo'
9
+ require 'validatable'
10
+
11
+ module MongoMapper
12
+ DocumentNotFound = Class.new(StandardError)
13
+ DocumentNotValid = Class.new(StandardError) do
14
+ def initialize(document)
15
+ @document = document
16
+ super("Validation failed: #{@document.errors.full_messages.join(", ")}")
17
+ end
18
+ end
19
+
20
+ def self.connection
21
+ @@connection ||= Mongo::Connection.new
22
+ end
23
+
24
+ def self.connection=(new_connection)
25
+ @@connection = new_connection
26
+ end
27
+
28
+ def self.logger
29
+ connection.logger
30
+ end
31
+
32
+ def self.database=(name)
33
+ @@database = nil
34
+ @@database_name = name
35
+ end
36
+
37
+ def self.database
38
+ if @@database_name.blank?
39
+ raise 'You forgot to set the default database name: MongoMapper.database = "foobar"'
40
+ end
41
+
42
+ @@database ||= MongoMapper.connection.db(@@database_name)
43
+ end
44
+
45
+ def self.ensured_indexes
46
+ @@ensured_indexes ||= []
47
+ end
48
+
49
+ def self.ensure_index(klass, keys, options={})
50
+ ensured_indexes << {:klass => klass, :keys => keys, :options => options}
51
+ end
52
+
53
+ def self.ensure_indexes!
54
+ ensured_indexes.each do |index|
55
+ unique = index[:options].delete(:unique)
56
+ index[:klass].collection.create_index(index[:keys], unique)
57
+ end
58
+ end
59
+
60
+ module Finders
61
+ def dynamic_find(finder, args)
62
+ attributes = {}
63
+ find_options = args.extract_options!.deep_merge(:conditions => attributes)
64
+
65
+ finder.attributes.each_with_index do |attr, index|
66
+ attributes[attr] = args[index]
67
+ end
68
+
69
+ result = find(finder.finder, find_options)
70
+
71
+ if result.nil?
72
+ if finder.bang
73
+ raise DocumentNotFound, "Couldn't find Document with #{attributes.inspect} in collection named #{collection.name}"
74
+ end
75
+
76
+ if finder.instantiator
77
+ self.send(finder.instantiator, attributes)
78
+ end
79
+ else
80
+ result
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ require 'mongo_mapper/support'
87
+ require 'mongo_mapper/associations'
88
+ require 'mongo_mapper/associations/base'
89
+ require 'mongo_mapper/associations/proxy'
90
+ require 'mongo_mapper/associations/many_documents_proxy'
91
+ require 'mongo_mapper/associations/belongs_to_proxy'
92
+ require 'mongo_mapper/associations/belongs_to_polymorphic_proxy'
93
+ require 'mongo_mapper/associations/many_proxy'
94
+ require 'mongo_mapper/associations/many_polymorphic_proxy'
95
+ require 'mongo_mapper/associations/many_embedded_proxy'
96
+ require 'mongo_mapper/associations/many_embedded_polymorphic_proxy'
97
+ require 'mongo_mapper/associations/many_documents_as_proxy'
98
+ require 'mongo_mapper/callbacks'
99
+ require 'mongo_mapper/finder_options'
100
+ require 'mongo_mapper/dirty'
101
+ require 'mongo_mapper/dynamic_finder'
102
+ require 'mongo_mapper/key'
103
+ require 'mongo_mapper/observing'
104
+ require 'mongo_mapper/pagination'
105
+ require 'mongo_mapper/save_with_validation'
106
+ require 'mongo_mapper/serialization'
107
+ require 'mongo_mapper/validations'
108
+ require 'mongo_mapper/rails_compatibility/document'
109
+ require 'mongo_mapper/rails_compatibility/embedded_document'
110
+ require 'mongo_mapper/embedded_document'
111
+ require 'mongo_mapper/document'
@@ -0,0 +1,162 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{mongo_mapper}
8
+ s.version = "0.5.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["John Nunemaker"]
12
+ s.date = %q{2009-10-11}
13
+ s.default_executable = %q{mmconsole}
14
+ s.email = %q{nunemaker@gmail.com}
15
+ s.executables = ["mmconsole"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "bin/mmconsole",
27
+ "lib/mongo_mapper.rb",
28
+ "lib/mongo_mapper/associations.rb",
29
+ "lib/mongo_mapper/associations/base.rb",
30
+ "lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb",
31
+ "lib/mongo_mapper/associations/belongs_to_proxy.rb",
32
+ "lib/mongo_mapper/associations/many_documents_as_proxy.rb",
33
+ "lib/mongo_mapper/associations/many_documents_proxy.rb",
34
+ "lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb",
35
+ "lib/mongo_mapper/associations/many_embedded_proxy.rb",
36
+ "lib/mongo_mapper/associations/many_polymorphic_proxy.rb",
37
+ "lib/mongo_mapper/associations/many_proxy.rb",
38
+ "lib/mongo_mapper/associations/proxy.rb",
39
+ "lib/mongo_mapper/callbacks.rb",
40
+ "lib/mongo_mapper/dirty.rb",
41
+ "lib/mongo_mapper/document.rb",
42
+ "lib/mongo_mapper/dynamic_finder.rb",
43
+ "lib/mongo_mapper/embedded_document.rb",
44
+ "lib/mongo_mapper/finder_options.rb",
45
+ "lib/mongo_mapper/key.rb",
46
+ "lib/mongo_mapper/observing.rb",
47
+ "lib/mongo_mapper/pagination.rb",
48
+ "lib/mongo_mapper/rails_compatibility/document.rb",
49
+ "lib/mongo_mapper/rails_compatibility/embedded_document.rb",
50
+ "lib/mongo_mapper/save_with_validation.rb",
51
+ "lib/mongo_mapper/serialization.rb",
52
+ "lib/mongo_mapper/serializers/json_serializer.rb",
53
+ "lib/mongo_mapper/support.rb",
54
+ "lib/mongo_mapper/validations.rb",
55
+ "mongo_mapper.gemspec",
56
+ "specs.watchr",
57
+ "test/NOTE_ON_TESTING",
58
+ "test/custom_matchers.rb",
59
+ "test/functional/associations/test_belongs_to_polymorphic_proxy.rb",
60
+ "test/functional/associations/test_belongs_to_proxy.rb",
61
+ "test/functional/associations/test_many_documents_as_proxy.rb",
62
+ "test/functional/associations/test_many_embedded_polymorphic_proxy.rb",
63
+ "test/functional/associations/test_many_embedded_proxy.rb",
64
+ "test/functional/associations/test_many_polymorphic_proxy.rb",
65
+ "test/functional/associations/test_many_proxy.rb",
66
+ "test/functional/test_associations.rb",
67
+ "test/functional/test_binary.rb",
68
+ "test/functional/test_callbacks.rb",
69
+ "test/functional/test_dirty.rb",
70
+ "test/functional/test_document.rb",
71
+ "test/functional/test_embedded_document.rb",
72
+ "test/functional/test_logger.rb",
73
+ "test/functional/test_pagination.rb",
74
+ "test/functional/test_rails_compatibility.rb",
75
+ "test/functional/test_validations.rb",
76
+ "test/models.rb",
77
+ "test/test_helper.rb",
78
+ "test/unit/serializers/test_json_serializer.rb",
79
+ "test/unit/test_association_base.rb",
80
+ "test/unit/test_document.rb",
81
+ "test/unit/test_dynamic_finder.rb",
82
+ "test/unit/test_embedded_document.rb",
83
+ "test/unit/test_finder_options.rb",
84
+ "test/unit/test_key.rb",
85
+ "test/unit/test_mongomapper.rb",
86
+ "test/unit/test_observing.rb",
87
+ "test/unit/test_pagination.rb",
88
+ "test/unit/test_rails_compatibility.rb",
89
+ "test/unit/test_serializations.rb",
90
+ "test/unit/test_support.rb",
91
+ "test/unit/test_time_zones.rb",
92
+ "test/unit/test_validations.rb"
93
+ ]
94
+ s.homepage = %q{http://github.com/jnunemaker/mongomapper}
95
+ s.rdoc_options = ["--charset=UTF-8"]
96
+ s.require_paths = ["lib"]
97
+ s.rubyforge_project = %q{mongomapper}
98
+ s.rubygems_version = %q{1.3.5}
99
+ s.summary = %q{Awesome gem for modeling your domain and storing it in mongo}
100
+ s.test_files = [
101
+ "test/custom_matchers.rb",
102
+ "test/functional/associations/test_belongs_to_polymorphic_proxy.rb",
103
+ "test/functional/associations/test_belongs_to_proxy.rb",
104
+ "test/functional/associations/test_many_documents_as_proxy.rb",
105
+ "test/functional/associations/test_many_embedded_polymorphic_proxy.rb",
106
+ "test/functional/associations/test_many_embedded_proxy.rb",
107
+ "test/functional/associations/test_many_polymorphic_proxy.rb",
108
+ "test/functional/associations/test_many_proxy.rb",
109
+ "test/functional/test_associations.rb",
110
+ "test/functional/test_binary.rb",
111
+ "test/functional/test_callbacks.rb",
112
+ "test/functional/test_dirty.rb",
113
+ "test/functional/test_document.rb",
114
+ "test/functional/test_embedded_document.rb",
115
+ "test/functional/test_logger.rb",
116
+ "test/functional/test_pagination.rb",
117
+ "test/functional/test_rails_compatibility.rb",
118
+ "test/functional/test_validations.rb",
119
+ "test/models.rb",
120
+ "test/test_helper.rb",
121
+ "test/unit/serializers/test_json_serializer.rb",
122
+ "test/unit/test_association_base.rb",
123
+ "test/unit/test_document.rb",
124
+ "test/unit/test_dynamic_finder.rb",
125
+ "test/unit/test_embedded_document.rb",
126
+ "test/unit/test_finder_options.rb",
127
+ "test/unit/test_key.rb",
128
+ "test/unit/test_mongomapper.rb",
129
+ "test/unit/test_observing.rb",
130
+ "test/unit/test_pagination.rb",
131
+ "test/unit/test_rails_compatibility.rb",
132
+ "test/unit/test_serializations.rb",
133
+ "test/unit/test_support.rb",
134
+ "test/unit/test_time_zones.rb",
135
+ "test/unit/test_validations.rb"
136
+ ]
137
+
138
+ if s.respond_to? :specification_version then
139
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
140
+ s.specification_version = 3
141
+
142
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
143
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
144
+ s.add_runtime_dependency(%q<mongo>, ["= 0.15.1"])
145
+ s.add_runtime_dependency(%q<jnunemaker-validatable>, ["= 1.7.4"])
146
+ s.add_development_dependency(%q<mocha>, ["= 0.9.4"])
147
+ s.add_development_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
148
+ else
149
+ s.add_dependency(%q<activesupport>, [">= 0"])
150
+ s.add_dependency(%q<mongo>, ["= 0.15.1"])
151
+ s.add_dependency(%q<jnunemaker-validatable>, ["= 1.7.4"])
152
+ s.add_dependency(%q<mocha>, ["= 0.9.4"])
153
+ s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
154
+ end
155
+ else
156
+ s.add_dependency(%q<activesupport>, [">= 0"])
157
+ s.add_dependency(%q<mongo>, ["= 0.15.1"])
158
+ s.add_dependency(%q<jnunemaker-validatable>, ["= 1.7.4"])
159
+ s.add_dependency(%q<mocha>, ["= 0.9.4"])
160
+ s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
161
+ end
162
+ end
data/specs.watchr ADDED
@@ -0,0 +1,32 @@
1
+ def run(cmd)
2
+ puts(cmd)
3
+ system(cmd)
4
+ end
5
+
6
+ def run_test_file(file)
7
+ run "ruby -Itest #{file}"
8
+ end
9
+
10
+ def run_all_tests
11
+ run "rake test"
12
+ end
13
+
14
+ def related_test_files(path)
15
+ Dir['test/**/*.rb'].select { |file| file =~ /#{File.basename(path)}/ }
16
+ end
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
23
+
24
+ # Ctrl-\
25
+ Signal.trap('QUIT') do
26
+ puts " --- Running all tests ---\n\n"
27
+ run_all_tests
28
+ end
29
+
30
+ # Ctrl-C
31
+ Signal.trap('INT') { abort("\n") }
32
+
@@ -0,0 +1 @@
1
+ I am doing my best to keep unit and functional tests separate. As I see them, functional tests hit the database and should never care about internals. Unit tests do not hit the database.
@@ -0,0 +1,55 @@
1
+ module CustomMatchers
2
+ custom_matcher :be_nil do |receiver, matcher, args|
3
+ matcher.positive_failure_message = "Expected #{receiver} to be nil but it wasn't"
4
+ matcher.negative_failure_message = "Expected #{receiver} not to be nil but it was"
5
+ receiver.nil?
6
+ end
7
+
8
+ custom_matcher :be_blank do |receiver, matcher, args|
9
+ matcher.positive_failure_message = "Expected #{receiver} to be blank but it wasn't"
10
+ matcher.negative_failure_message = "Expected #{receiver} not to be blank but it was"
11
+ receiver.blank?
12
+ end
13
+
14
+ custom_matcher :be_true do |receiver, matcher, args|
15
+ matcher.positive_failure_message = "Expected #{receiver} to be true but it wasn't"
16
+ matcher.negative_failure_message = "Expected #{receiver} not to be true but it was"
17
+ receiver.eql?(true)
18
+ end
19
+
20
+ custom_matcher :be_false do |receiver, matcher, args|
21
+ matcher.positive_failure_message = "Expected #{receiver} to be false but it wasn't"
22
+ matcher.negative_failure_message = "Expected #{receiver} not to be false but it was"
23
+ receiver.eql?(false)
24
+ end
25
+
26
+ custom_matcher :be_valid do |receiver, matcher, args|
27
+ matcher.positive_failure_message = "Expected to be valid but it was invalid #{receiver.errors.inspect}"
28
+ matcher.negative_failure_message = "Expected to be invalid but it was valid #{receiver.errors.inspect}"
29
+ receiver.valid?
30
+ end
31
+
32
+ custom_matcher :have_error_on do |receiver, matcher, args|
33
+ receiver.valid?
34
+ attribute = args[0]
35
+ expected_message = args[1]
36
+
37
+ if expected_message.nil?
38
+ matcher.positive_failure_message = "#{receiver} had no errors on #{attribute}"
39
+ matcher.negative_failure_message = "#{receiver} had errors on #{attribute} #{receiver.errors.inspect}"
40
+ !receiver.errors.on(attribute).blank?
41
+ else
42
+ actual = receiver.errors.on(attribute)
43
+ matcher.positive_failure_message = %Q(Expected error on #{attribute} to be "#{expected_message}" but was "#{actual}")
44
+ matcher.negative_failure_message = %Q(Expected error on #{attribute} not to be "#{expected_message}" but was "#{actual}")
45
+ actual == expected_message
46
+ end
47
+ end
48
+
49
+ custom_matcher :have_index do |receiver, matcher, args|
50
+ index_name = args[0]
51
+ matcher.positive_failure_message = "#{receiver} does not have index named #{index_name}, but should"
52
+ matcher.negative_failure_message = "#{receiver} does have index named #{index_name}, but should not"
53
+ !receiver.collection.index_information.detect { |index| index[0] == index_name }.nil?
54
+ end
55
+ end
@@ -0,0 +1,55 @@
1
+ require 'test_helper'
2
+ require 'models'
3
+
4
+ class BelongsToPolymorphicProxyTest < Test::Unit::TestCase
5
+ def setup
6
+ Status.collection.clear
7
+ Project.collection.clear
8
+ end
9
+
10
+ should "default to nil" do
11
+ status = Status.new
12
+ status.target.nil?.should be_true
13
+ status.target.inspect.should == "nil"
14
+ end
15
+
16
+ should "be able to replace the association" do
17
+ status = Status.new
18
+ project = Project.new(:name => "mongomapper")
19
+ status.target = project
20
+ status.save.should be_true
21
+
22
+ from_db = Status.find(status.id)
23
+ from_db.target.nil?.should be_false
24
+ from_db.target_id.should == project.id
25
+ from_db.target_type.should == "Project"
26
+ from_db.target.name.should == "mongomapper"
27
+ end
28
+
29
+ should "unset the association" do
30
+ status = Status.new
31
+ project = Project.new(:name => "mongomapper")
32
+ status.target = project
33
+ status.save.should be_true
34
+
35
+ from_db = Status.find(status.id)
36
+ from_db.target = nil
37
+ from_db.target_type.nil?.should be_true
38
+ from_db.target_id.nil?.should be_true
39
+ from_db.target.nil?.should be_true
40
+ end
41
+
42
+ context "association id set but document not found" do
43
+ setup do
44
+ @status = Status.new
45
+ project = Project.new(:name => "mongomapper")
46
+ @status.target = project
47
+ @status.save.should be_true
48
+ project.destroy
49
+ end
50
+
51
+ should "return nil instead of raising error" do
52
+ @status.target.nil?.should be_true
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+ require 'models'
3
+
4
+ class BelongsToProxyTest < Test::Unit::TestCase
5
+ def setup
6
+ Status.collection.clear
7
+ Project.collection.clear
8
+ end
9
+
10
+ should "default to nil" do
11
+ status = Status.new
12
+ status.project.nil?.should == true
13
+ status.project.inspect.should == 'nil'
14
+ end
15
+
16
+ should "be able to replace the association" do
17
+ status = Status.new
18
+ project = Project.new(:name => "mongomapper")
19
+ status.project = project
20
+ status.save.should be_true
21
+
22
+ from_db = Status.find(status.id)
23
+ from_db.project.nil?.should be_false
24
+ from_db.project.name.should == "mongomapper"
25
+ end
26
+
27
+ should "unset the association" do
28
+ status = Status.new
29
+ project = Project.new(:name => "mongomapper")
30
+ status.project = project
31
+ status.save.should be_true
32
+
33
+ from_db = Status.find(status.id)
34
+ from_db.project = nil
35
+ from_db.project.nil?.should be_true
36
+ from_db.project.inspect.should == 'nil'
37
+ end
38
+
39
+ context "association id set but document not found" do
40
+ setup do
41
+ @status = Status.new(:name => 'Foo', :project_id => '1234')
42
+ end
43
+
44
+ should "return nil instead of raising error" do
45
+ @status.project.nil?.should be_true
46
+ @status.project.inspect.should == 'nil'
47
+ end
48
+ end
49
+ end