mongo_mapper 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -11,12 +11,14 @@ begin
11
11
  gem.authors = ["John Nunemaker"]
12
12
  gem.rubyforge_project = "mongomapper"
13
13
 
14
- gem.add_dependency('activesupport')
14
+ gem.add_dependency('activesupport', '>= 2.3')
15
15
  gem.add_dependency('mongo', '0.15.1')
16
16
  gem.add_dependency('jnunemaker-validatable', '1.7.4')
17
17
 
18
- gem.add_development_dependency('mocha', '0.9.4')
19
18
  gem.add_development_dependency('jnunemaker-matchy', '0.4.0')
19
+ gem.add_development_dependency('shoulda', '2.10.2')
20
+ gem.add_development_dependency('timecop', '0.3.1')
21
+ gem.add_development_dependency('mocha', '0.9.4')
20
22
  end
21
23
 
22
24
  Jeweler::RubyforgeTasks.new do |rubyforge|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.4
1
+ 0.5.5
@@ -1,6 +1,6 @@
1
1
  require 'rubygems'
2
2
 
3
- gem 'activesupport'
3
+ gem 'activesupport', '>= 2.3'
4
4
  gem 'mongo', '0.15.1'
5
5
  gem 'jnunemaker-validatable', '1.7.4'
6
6
 
@@ -102,10 +102,9 @@ require 'mongo_mapper/dynamic_finder'
102
102
  require 'mongo_mapper/key'
103
103
  require 'mongo_mapper/observing'
104
104
  require 'mongo_mapper/pagination'
105
- require 'mongo_mapper/save_with_validation'
106
105
  require 'mongo_mapper/serialization'
107
106
  require 'mongo_mapper/validations'
108
107
  require 'mongo_mapper/rails_compatibility/document'
109
108
  require 'mongo_mapper/rails_compatibility/embedded_document'
110
109
  require 'mongo_mapper/embedded_document'
111
- require 'mongo_mapper/document'
110
+ require 'mongo_mapper/document'
@@ -48,16 +48,16 @@ module MongoMapper
48
48
  end
49
49
 
50
50
  def define_dependent_callback_for_many(association)
51
- return if association.embeddable?
52
-
53
51
  after_destroy do |doc|
54
- case association.options[:dependent]
55
- when :destroy
56
- doc.get_proxy(association).destroy_all
57
- when :delete_all
58
- doc.get_proxy(association).delete_all
59
- when :nullify
60
- doc.get_proxy(association).nullify
52
+ if !association.embeddable?
53
+ case association.options[:dependent]
54
+ when :destroy
55
+ doc.get_proxy(association).destroy_all
56
+ when :delete_all
57
+ doc.get_proxy(association).delete_all
58
+ when :nullify
59
+ doc.get_proxy(association).nullify
60
+ end
61
61
  end
62
62
  end
63
63
  end
@@ -1,87 +1,50 @@
1
1
  module MongoMapper
2
- module Callbacks
2
+ module Callbacks
3
3
  def self.included(model) #:nodoc:
4
4
  model.class_eval do
5
5
  extend Observable
6
6
  include ActiveSupport::Callbacks
7
-
8
- define_callbacks *%w(
9
- before_save after_save before_create after_create before_update after_update before_validation
10
- after_validation before_validation_on_create after_validation_on_create before_validation_on_update
11
- after_validation_on_update before_destroy after_destroy
7
+
8
+ callbacks = %w(
9
+ before_save
10
+ after_save
11
+ before_create
12
+ after_create
13
+ before_update
14
+ after_update
15
+ before_validation
16
+ after_validation
17
+ before_validation_on_create
18
+ after_validation_on_create
19
+ before_validation_on_update
20
+ after_validation_on_update
21
+ before_destroy
22
+ after_destroy
12
23
  )
13
-
14
- [:create_or_update, :valid?, :create, :update, :destroy].each do |method|
15
- alias_method_chain method, :callbacks
16
- end
17
- end
18
- end
19
24
 
20
- def before_save() end
25
+ define_callbacks(*callbacks)
21
26
 
22
- def after_save() end
23
- def create_or_update_with_callbacks #:nodoc:
24
- return false if callback(:before_save) == false
25
- if result = create_or_update_without_callbacks
26
- callback(:after_save)
27
+ callbacks.each do |callback|
28
+ define_method(callback.to_sym) {}
29
+ end
27
30
  end
28
- result
29
31
  end
30
- private :create_or_update_with_callbacks
31
-
32
- def before_create() end
33
-
34
- def after_create() end
35
- def create_with_callbacks #:nodoc:
36
- return false if callback(:before_create) == false
37
- result = create_without_callbacks
38
- callback(:after_create)
39
- result
40
- end
41
- private :create_with_callbacks
42
-
43
- def before_update() end
44
-
45
- def after_update() end
46
-
47
- def update_with_callbacks(*args) #:nodoc:
48
- return false if callback(:before_update) == false
49
- result = update_without_callbacks(*args)
50
- callback(:after_update)
51
- result
52
- end
53
- private :update_with_callbacks
54
-
55
- def before_validation() end
56
-
57
- def after_validation() end
58
32
 
59
- def before_validation_on_create() end
60
-
61
- def after_validation_on_create() end
62
-
63
- def before_validation_on_update() end
64
-
65
- def after_validation_on_update() end
66
-
67
- def valid_with_callbacks? #:nodoc:
33
+ def valid? #:nodoc:
68
34
  return false if callback(:before_validation) == false
69
35
  result = new? ? callback(:before_validation_on_create) : callback(:before_validation_on_update)
70
36
  return false if false == result
71
-
72
- result = valid_without_callbacks?
37
+
38
+ result = super
73
39
  callback(:after_validation)
74
-
40
+
75
41
  new? ? callback(:after_validation_on_create) : callback(:after_validation_on_update)
76
42
  return result
77
43
  end
78
44
 
79
- def before_destroy() end
80
-
81
- def after_destroy() end
82
- def destroy_with_callbacks #:nodoc:
45
+ def destroy #:nodoc:
83
46
  return false if callback(:before_destroy) == false
84
- result = destroy_without_callbacks
47
+ result = super
85
48
  callback(:after_destroy)
86
49
  result
87
50
  end
@@ -89,18 +52,40 @@ module MongoMapper
89
52
  private
90
53
  def callback(method)
91
54
  result = run_callbacks(method) { |result, object| false == result }
92
-
55
+
93
56
  if result != false && respond_to?(method)
94
57
  result = send(method)
95
58
  end
96
-
59
+
97
60
  notify(method)
98
61
  return result
99
62
  end
100
-
63
+
101
64
  def notify(method) #:nodoc:
102
65
  self.class.changed
103
66
  self.class.notify_observers(method, self)
104
67
  end
68
+
69
+ def create_or_update #:nodoc:
70
+ return false if callback(:before_save) == false
71
+ if result = super
72
+ callback(:after_save)
73
+ end
74
+ result
75
+ end
76
+
77
+ def create #:nodoc:
78
+ return false if callback(:before_create) == false
79
+ result = super
80
+ callback(:after_create)
81
+ result
82
+ end
83
+
84
+ def update(*args) #:nodoc:
85
+ return false if callback(:before_update) == false
86
+ result = super
87
+ callback(:after_update)
88
+ result
89
+ end
105
90
  end
106
91
  end
@@ -2,13 +2,6 @@ module MongoMapper
2
2
  module Dirty
3
3
  DIRTY_SUFFIXES = ['_changed?', '_change', '_will_change!', '_was']
4
4
 
5
- def self.included(base)
6
- base.alias_method_chain :initialize, :dirty
7
- base.alias_method_chain :write_attribute, :dirty
8
- base.alias_method_chain :save, :dirty
9
- base.alias_method_chain :save!, :dirty
10
- end
11
-
12
5
  def method_missing(method, *args, &block)
13
6
  if method.to_s =~ /(_changed\?|_change|_will_change!|_was)$/
14
7
  method_suffix = $1
@@ -53,26 +46,26 @@ module MongoMapper
53
46
  changed.inject({}) { |h, attribute| h[attribute] = key_change(attribute); h }
54
47
  end
55
48
 
56
- def initialize_with_dirty(attrs={})
57
- initialize_without_dirty(attrs)
49
+ def initialize(attrs={})
50
+ super(attrs)
58
51
  changed_keys.clear unless new?
59
52
  end
60
-
53
+
61
54
  # Attempts to +save+ the record and clears changed keys if successful.
62
- def save_with_dirty(*args) #:nodoc:
63
- if status = save_without_dirty(*args)
55
+ def save(*args)
56
+ if status = super
64
57
  changed_keys.clear
65
58
  end
66
59
  status
67
60
  end
68
61
 
69
62
  # Attempts to <tt>save!</tt> the record and clears changed keys if successful.
70
- def save_with_dirty!(*args) #:nodoc:
71
- status = save_without_dirty!(*args)
63
+ def save!(*args)
64
+ status = super
72
65
  changed_keys.clear
73
66
  status
74
67
  end
75
-
68
+
76
69
  # <tt>reload</tt> the record and clears changed keys.
77
70
  # def reload_with_dirty(*args) #:nodoc:
78
71
  # record = reload_without_dirty(*args)
@@ -114,7 +107,7 @@ module MongoMapper
114
107
  end
115
108
 
116
109
  # Wrap write_attribute to remember original key value.
117
- def write_attribute_with_dirty(attribute, value)
110
+ def write_attribute(attribute, value)
118
111
  attribute = attribute.to_s
119
112
 
120
113
  # The key already has an unsaved change.
@@ -127,7 +120,7 @@ module MongoMapper
127
120
  end
128
121
 
129
122
  # Carry on.
130
- write_attribute_without_dirty(attribute, value)
123
+ super(attribute, value)
131
124
  end
132
125
 
133
126
  def value_changed?(key_name, old, value)
@@ -140,4 +133,4 @@ module MongoMapper
140
133
  old != value
141
134
  end
142
135
  end
143
- end
136
+ end
@@ -8,7 +8,6 @@ module MongoMapper
8
8
  include InstanceMethods
9
9
  include Observing
10
10
  include Callbacks
11
- include SaveWithValidation
12
11
  include Dirty
13
12
  include RailsCompatibility::Document
14
13
  extend Validations::Macros
@@ -111,13 +110,11 @@ module MongoMapper
111
110
  end
112
111
 
113
112
  def create(*docs)
114
- instances = []
115
- docs = [{}] if docs.blank?
116
- docs.flatten.each do |attrs|
117
- doc = new(attrs); doc.save
118
- instances << doc
119
- end
120
- instances.size == 1 ? instances[0] : instances
113
+ initialize_each(*docs) { |doc| doc.save }
114
+ end
115
+
116
+ def create!(*docs)
117
+ initialize_each(*docs) { |doc| doc.save! }
121
118
  end
122
119
 
123
120
  # For updating single document
@@ -207,6 +204,18 @@ module MongoMapper
207
204
  end
208
205
 
209
206
  private
207
+ # Initializes each document and yields each initialized document
208
+ def initialize_each(*docs)
209
+ instances = []
210
+ docs = [{}] if docs.blank?
211
+ docs.flatten.each do |attrs|
212
+ doc = new(attrs)
213
+ yield(doc)
214
+ instances << doc
215
+ end
216
+ instances.size == 1 ? instances[0] : instances
217
+ end
218
+
210
219
  def create_indexes_for(key)
211
220
  ensure_index key.name if key.options[:index]
212
221
  end
@@ -285,11 +294,11 @@ module MongoMapper
285
294
  end
286
295
 
287
296
  def save
288
- create_or_update
297
+ valid? ? create_or_update : false
289
298
  end
290
299
 
291
300
  def save!
292
- create_or_update || raise(DocumentNotValid.new(self))
301
+ valid? ? create_or_update : raise(DocumentNotValid.new(self))
293
302
  end
294
303
 
295
304
  def destroy
@@ -198,6 +198,10 @@ module MongoMapper
198
198
  def new?
199
199
  !!@new_document
200
200
  end
201
+
202
+ def to_param
203
+ id
204
+ end
201
205
 
202
206
  def attributes=(attrs)
203
207
  return if attrs.blank?
@@ -308,7 +312,7 @@ module MongoMapper
308
312
 
309
313
  private
310
314
  def _keys
311
- self.class.keys
315
+ self.metaclass.keys
312
316
  end
313
317
 
314
318
  def key_names
@@ -324,7 +328,7 @@ module MongoMapper
324
328
  end
325
329
 
326
330
  def ensure_key_exists(name)
327
- self.class.key(name) unless respond_to?("#{name}=")
331
+ self.metaclass.key(name) unless respond_to?("#{name}=")
328
332
  end
329
333
 
330
334
  def read_attribute(name)
@@ -6,10 +6,6 @@ module MongoMapper
6
6
  alias_method :new_record?, :new?
7
7
  end
8
8
  end
9
-
10
- def to_param
11
- id
12
- end
13
9
  end
14
10
  end
15
11
  end
@@ -18,10 +18,6 @@ module MongoMapper
18
18
  keys.keys
19
19
  end
20
20
  end
21
-
22
- def to_param
23
- raise "Missing to_param method in #{self.class}. You should implement it to return the unique identifier of this embedded document within a document."
24
- end
25
21
  end
26
22
  end
27
23
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongo_mapper}
8
- s.version = "0.5.4"
8
+ s.version = "0.5.5"
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-10-11}
12
+ s.date = %q{2009-10-16}
13
13
  s.default_executable = %q{mmconsole}
14
14
  s.email = %q{nunemaker@gmail.com}
15
15
  s.executables = ["mmconsole"]
@@ -47,7 +47,6 @@ Gem::Specification.new do |s|
47
47
  "lib/mongo_mapper/pagination.rb",
48
48
  "lib/mongo_mapper/rails_compatibility/document.rb",
49
49
  "lib/mongo_mapper/rails_compatibility/embedded_document.rb",
50
- "lib/mongo_mapper/save_with_validation.rb",
51
50
  "lib/mongo_mapper/serialization.rb",
52
51
  "lib/mongo_mapper/serializers/json_serializer.rb",
53
52
  "lib/mongo_mapper/support.rb",
@@ -55,7 +54,6 @@ Gem::Specification.new do |s|
55
54
  "mongo_mapper.gemspec",
56
55
  "specs.watchr",
57
56
  "test/NOTE_ON_TESTING",
58
- "test/custom_matchers.rb",
59
57
  "test/functional/associations/test_belongs_to_polymorphic_proxy.rb",
60
58
  "test/functional/associations/test_belongs_to_proxy.rb",
61
59
  "test/functional/associations/test_many_documents_as_proxy.rb",
@@ -74,6 +72,8 @@ Gem::Specification.new do |s|
74
72
  "test/functional/test_rails_compatibility.rb",
75
73
  "test/functional/test_validations.rb",
76
74
  "test/models.rb",
75
+ "test/support/custom_matchers.rb",
76
+ "test/support/test_timing.rb",
77
77
  "test/test_helper.rb",
78
78
  "test/unit/serializers/test_json_serializer.rb",
79
79
  "test/unit/test_association_base.rb",
@@ -98,8 +98,7 @@ Gem::Specification.new do |s|
98
98
  s.rubygems_version = %q{1.3.5}
99
99
  s.summary = %q{Awesome gem for modeling your domain and storing it in mongo}
100
100
  s.test_files = [
101
- "test/custom_matchers.rb",
102
- "test/functional/associations/test_belongs_to_polymorphic_proxy.rb",
101
+ "test/functional/associations/test_belongs_to_polymorphic_proxy.rb",
103
102
  "test/functional/associations/test_belongs_to_proxy.rb",
104
103
  "test/functional/associations/test_many_documents_as_proxy.rb",
105
104
  "test/functional/associations/test_many_embedded_polymorphic_proxy.rb",
@@ -117,6 +116,8 @@ Gem::Specification.new do |s|
117
116
  "test/functional/test_rails_compatibility.rb",
118
117
  "test/functional/test_validations.rb",
119
118
  "test/models.rb",
119
+ "test/support/custom_matchers.rb",
120
+ "test/support/test_timing.rb",
120
121
  "test/test_helper.rb",
121
122
  "test/unit/serializers/test_json_serializer.rb",
122
123
  "test/unit/test_association_base.rb",
@@ -140,23 +141,29 @@ Gem::Specification.new do |s|
140
141
  s.specification_version = 3
141
142
 
142
143
  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<activesupport>, [">= 2.3"])
144
145
  s.add_runtime_dependency(%q<mongo>, ["= 0.15.1"])
145
146
  s.add_runtime_dependency(%q<jnunemaker-validatable>, ["= 1.7.4"])
146
- s.add_development_dependency(%q<mocha>, ["= 0.9.4"])
147
147
  s.add_development_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
148
+ s.add_development_dependency(%q<shoulda>, ["= 2.10.2"])
149
+ s.add_development_dependency(%q<timecop>, ["= 0.3.1"])
150
+ s.add_development_dependency(%q<mocha>, ["= 0.9.4"])
148
151
  else
149
- s.add_dependency(%q<activesupport>, [">= 0"])
152
+ s.add_dependency(%q<activesupport>, [">= 2.3"])
150
153
  s.add_dependency(%q<mongo>, ["= 0.15.1"])
151
154
  s.add_dependency(%q<jnunemaker-validatable>, ["= 1.7.4"])
152
- s.add_dependency(%q<mocha>, ["= 0.9.4"])
153
155
  s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
156
+ s.add_dependency(%q<shoulda>, ["= 2.10.2"])
157
+ s.add_dependency(%q<timecop>, ["= 0.3.1"])
158
+ s.add_dependency(%q<mocha>, ["= 0.9.4"])
154
159
  end
155
160
  else
156
- s.add_dependency(%q<activesupport>, [">= 0"])
161
+ s.add_dependency(%q<activesupport>, [">= 2.3"])
157
162
  s.add_dependency(%q<mongo>, ["= 0.15.1"])
158
163
  s.add_dependency(%q<jnunemaker-validatable>, ["= 1.7.4"])
159
- s.add_dependency(%q<mocha>, ["= 0.9.4"])
160
164
  s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
165
+ s.add_dependency(%q<shoulda>, ["= 2.10.2"])
166
+ s.add_dependency(%q<timecop>, ["= 0.3.1"])
167
+ s.add_dependency(%q<mocha>, ["= 0.9.4"])
161
168
  end
162
169
  end
@@ -149,7 +149,8 @@ class ManyDocumentsAsProxyTest < Test::Unit::TestCase
149
149
 
150
150
  context "with #all" do
151
151
  should "work" do
152
- @post.comments.all.should == [@comment1, @comment2]
152
+ @post.comments.all.should include(@comment1)
153
+ @post.comments.all.should include(@comment2)
153
154
  end
154
155
 
155
156
  should "work with conditions" do
@@ -1007,8 +1007,11 @@ class DocumentTest < Test::Unit::TestCase
1007
1007
  old_created_at = doc.created_at
1008
1008
  old_updated_at = doc.updated_at
1009
1009
  doc.first_name = 'Johnny'
1010
- sleep 1 # this annoys me
1011
- doc.save
1010
+
1011
+ Timecop.freeze(Time.now + 5.seconds) do
1012
+ doc.save
1013
+ end
1014
+
1012
1015
  doc.created_at.should == old_created_at
1013
1016
  doc.updated_at.should_not == old_updated_at
1014
1017
  end
@@ -1017,12 +1020,14 @@ class DocumentTest < Test::Unit::TestCase
1017
1020
  doc = @document.create(:first_name => 'John', :age => 27)
1018
1021
  old_created_at = doc.created_at
1019
1022
  old_updated_at = doc.updated_at
1020
- sleep 1 # this annoys me
1021
- @document.update(doc._id, { :first_name => 'Johnny' })
1023
+
1024
+ Timecop.freeze(Time.now + 5.seconds) do
1025
+ @document.update(doc._id, { :first_name => 'Johnny' })
1026
+ end
1022
1027
 
1023
1028
  from_db = @document.find(doc.id)
1024
- from_db.created_at.to_i.should == old_created_at.to_i
1025
- from_db.updated_at.to_i.should_not == old_updated_at.to_i
1029
+ from_db.created_at.should == old_created_at
1030
+ from_db.updated_at.should_not == old_updated_at
1026
1031
  end
1027
1032
  end
1028
1033
 
@@ -74,6 +74,14 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
74
74
  doc = RealPerson.find(person.id)
75
75
  doc.pets.first.should == pet
76
76
  end
77
+
78
+ should "save new keys" do
79
+ person = RealPerson.new
80
+ person[:new_attribute] = 'foobar'
81
+ person.save
82
+ from_db = RealPerson.find(person.id)
83
+ person.new_attribute.should == 'foobar'
84
+ end
77
85
  end
78
86
 
79
87
  context "update_attributes" do
@@ -94,4 +102,4 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
94
102
  embedded.name.should == 'koda'
95
103
  end
96
104
  end
97
- end
105
+ end
@@ -16,11 +16,6 @@ class TestRailsCompatibility < Test::Unit::TestCase
16
16
  setup do
17
17
  Order.collection.clear
18
18
  end
19
-
20
- should "have to_param that returns id" do
21
- instance = Order.create('_id' => 1234)
22
- instance.to_param.should == '1234'
23
- end
24
19
 
25
20
  should "alias new to new_record?" do
26
21
  instance = Order.new
@@ -40,6 +40,26 @@ class ValidationsTest < Test::Unit::TestCase
40
40
  lambda { doc.save! }.should raise_error(MongoMapper::DocumentNotValid)
41
41
  end
42
42
  end
43
+
44
+ context "Creating a document that is invalid (destructive)" do
45
+ setup do
46
+ @document = Class.new do
47
+ include MongoMapper::Document
48
+ set_collection_name 'test'
49
+ key :name, String, :required => true
50
+ end
51
+ @document.collection.clear
52
+ end
53
+
54
+ should "raise error" do
55
+ lambda { @document.create! }.should raise_error(MongoMapper::DocumentNotValid)
56
+ end
57
+
58
+ should "create a new document" do
59
+ instance = @document.create!(:name => "James")
60
+ instance.new_record?.should be_false
61
+ end
62
+ end
43
63
 
44
64
  context "Saving an existing document that is invalid" do
45
65
  setup do
@@ -0,0 +1,16 @@
1
+ class Test::Unit::TestCase
2
+ def run_with_test_timing(*args, &block)
3
+ begin_time = Time.now
4
+ run_without_test_timing(*args, &block)
5
+ end_time = Time.now
6
+
7
+ duration = end_time - begin_time
8
+ threshold = 0.3
9
+
10
+ if duration > threshold
11
+ puts "\nSLOW TEST: #{duration} - #{self.name}"
12
+ end
13
+ end
14
+
15
+ alias_method_chain :run, :test_timing unless method_defined?(:run_without_test_timing)
16
+ end
@@ -1,18 +1,18 @@
1
- require 'pathname'
2
- require 'pp'
3
- require 'rubygems'
4
- require 'shoulda'
1
+ require File.join(File.expand_path(File.dirname(__FILE__) + '/../lib/mongo_mapper'))
5
2
 
6
- gem 'mocha', '0.9.4'
7
3
  gem 'jnunemaker-matchy', '0.4.0'
4
+ gem 'shoulda', '2.10.2'
5
+ gem 'timecop', '0.3.1'
6
+ gem 'mocha', '0.9.4'
8
7
 
9
8
  require 'matchy'
9
+ require 'shoulda'
10
+ require 'timecop'
10
11
  require 'mocha'
11
- require 'custom_matchers'
12
+ require 'pp'
12
13
 
13
- $LOAD_PATH.unshift(File.dirname(__FILE__))
14
- dir = (Pathname(__FILE__).dirname + '..' + 'lib').expand_path
15
- require dir + 'mongo_mapper'
14
+ require 'support/custom_matchers'
15
+ require 'support/test_timing'
16
16
 
17
17
  class Test::Unit::TestCase
18
18
  include CustomMatchers
@@ -289,6 +289,11 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
289
289
  end
290
290
  end
291
291
 
292
+ should "have to_param that is id" do
293
+ doc = @document.new
294
+ doc.to_param.should == doc.id
295
+ end
296
+
292
297
  should "have access to class logger" do
293
298
  doc = @document.new
294
299
  doc.logger.should == @document.logger
@@ -477,9 +482,15 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
477
482
  should "create key and write value for missing key" do
478
483
  doc = @document.new
479
484
  doc[:foo] = 'string'
480
- @document.keys.keys.include?('foo').should be_true
485
+ doc.metaclass.keys.include?('foo').should be_true
481
486
  doc[:foo].should == 'string'
482
487
  end
488
+
489
+ should "not share the new key" do
490
+ doc = @document.new
491
+ doc[:foo] = 'string'
492
+ @document.keys.should_not include('foo')
493
+ end
483
494
  end
484
495
  end
485
496
 
@@ -15,11 +15,7 @@ class TestRailsCompatibility < Test::Unit::TestCase
15
15
  key :second_only, String
16
16
  end
17
17
 
18
- context "EmbeddedDocument" do
19
- should "raise error for to_param as embedded do not have id's" do
20
- lambda { Item.new.to_param }.should raise_error
21
- end
22
-
18
+ context "EmbeddedDocument" do
23
19
  should "alias many to has_many" do
24
20
  FirstItem.should respond_to(:has_many)
25
21
  FirstItem.method(:has_many).should == FirstItem.method(:many)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-11 00:00:00 -04:00
12
+ date: 2009-10-16 00:00:00 -04:00
13
13
  default_executable: mmconsole
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: "0"
23
+ version: "2.3"
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mongo
@@ -43,24 +43,44 @@ dependencies:
43
43
  version: 1.7.4
44
44
  version:
45
45
  - !ruby/object:Gem::Dependency
46
- name: mocha
46
+ name: jnunemaker-matchy
47
47
  type: :development
48
48
  version_requirement:
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "="
52
52
  - !ruby/object:Gem::Version
53
- version: 0.9.4
53
+ version: 0.4.0
54
54
  version:
55
55
  - !ruby/object:Gem::Dependency
56
- name: jnunemaker-matchy
56
+ name: shoulda
57
57
  type: :development
58
58
  version_requirement:
59
59
  version_requirements: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - "="
62
62
  - !ruby/object:Gem::Version
63
- version: 0.4.0
63
+ version: 2.10.2
64
+ version:
65
+ - !ruby/object:Gem::Dependency
66
+ name: timecop
67
+ type: :development
68
+ version_requirement:
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "="
72
+ - !ruby/object:Gem::Version
73
+ version: 0.3.1
74
+ version:
75
+ - !ruby/object:Gem::Dependency
76
+ name: mocha
77
+ type: :development
78
+ version_requirement:
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "="
82
+ - !ruby/object:Gem::Version
83
+ version: 0.9.4
64
84
  version:
65
85
  description:
66
86
  email: nunemaker@gmail.com
@@ -101,7 +121,6 @@ files:
101
121
  - lib/mongo_mapper/pagination.rb
102
122
  - lib/mongo_mapper/rails_compatibility/document.rb
103
123
  - lib/mongo_mapper/rails_compatibility/embedded_document.rb
104
- - lib/mongo_mapper/save_with_validation.rb
105
124
  - lib/mongo_mapper/serialization.rb
106
125
  - lib/mongo_mapper/serializers/json_serializer.rb
107
126
  - lib/mongo_mapper/support.rb
@@ -109,7 +128,6 @@ files:
109
128
  - mongo_mapper.gemspec
110
129
  - specs.watchr
111
130
  - test/NOTE_ON_TESTING
112
- - test/custom_matchers.rb
113
131
  - test/functional/associations/test_belongs_to_polymorphic_proxy.rb
114
132
  - test/functional/associations/test_belongs_to_proxy.rb
115
133
  - test/functional/associations/test_many_documents_as_proxy.rb
@@ -128,6 +146,8 @@ files:
128
146
  - test/functional/test_rails_compatibility.rb
129
147
  - test/functional/test_validations.rb
130
148
  - test/models.rb
149
+ - test/support/custom_matchers.rb
150
+ - test/support/test_timing.rb
131
151
  - test/test_helper.rb
132
152
  - test/unit/serializers/test_json_serializer.rb
133
153
  - test/unit/test_association_base.rb
@@ -173,7 +193,6 @@ signing_key:
173
193
  specification_version: 3
174
194
  summary: Awesome gem for modeling your domain and storing it in mongo
175
195
  test_files:
176
- - test/custom_matchers.rb
177
196
  - test/functional/associations/test_belongs_to_polymorphic_proxy.rb
178
197
  - test/functional/associations/test_belongs_to_proxy.rb
179
198
  - test/functional/associations/test_many_documents_as_proxy.rb
@@ -192,6 +211,8 @@ test_files:
192
211
  - test/functional/test_rails_compatibility.rb
193
212
  - test/functional/test_validations.rb
194
213
  - test/models.rb
214
+ - test/support/custom_matchers.rb
215
+ - test/support/test_timing.rb
195
216
  - test/test_helper.rb
196
217
  - test/unit/serializers/test_json_serializer.rb
197
218
  - test/unit/test_association_base.rb
@@ -1,19 +0,0 @@
1
- module MongoMapper
2
- module SaveWithValidation
3
- def self.included(base)
4
- base.class_eval do
5
- alias_method_chain :save, :validation
6
- alias_method_chain :save!, :validation
7
- end
8
- end
9
-
10
- private
11
- def save_with_validation
12
- valid? ? save_without_validation : false
13
- end
14
-
15
- def save_with_validation!
16
- valid? ? save_without_validation! : raise(DocumentNotValid.new(self))
17
- end
18
- end
19
- end