Skip to content

Commit

Permalink
Merge branch 'master' into rails3
Browse files Browse the repository at this point in the history
* master:
  Call #save! instead of #save on the parent when calling #save! on an embedded doc
  Added turn test output formatter.
  No longer needed as I added tests for inspect in previous commit.
  Attributes are now alpha sorted in #inspect.
  Minor: errant inspect statement in test.

Conflicts:
	lib/mongo_mapper/plugins/embedded_document.rb
  • Loading branch information
bkeepers committed Feb 1, 2011
2 parents 6211577 + 5aca9ff commit b3ab248
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 13 deletions.
4 changes: 4 additions & 0 deletions Gemfile.lock
Expand Up @@ -14,6 +14,7 @@ GEM
builder (~> 2.1.2)
i18n (~> 0.4.1)
activesupport (3.0.0)
ansi (1.2.2)
archive-tar-minitar (0.5.2)
bson (1.1)
bson_ext (1.1)
Expand Down Expand Up @@ -53,6 +54,8 @@ GEM
archive-tar-minitar (>= 0.5.2)
shoulda (2.11.3)
timecop (0.3.5)
turn (0.8.1)
ansi (>= 1.2.2)
tzinfo (0.3.23)

PLATFORMS
Expand All @@ -74,4 +77,5 @@ DEPENDENCIES
ruby-debug19
shoulda (~> 2.11)
timecop (~> 0.3.1)
turn (~> 0.8.1)
tzinfo
2 changes: 1 addition & 1 deletion lib/mongo_mapper/plugins/embedded_document.rb
Expand Up @@ -34,7 +34,7 @@ def save(options={})
end

def save!(options={})
_root_document.try(:save, options).tap do |result|
_root_document.try(:save!, options).tap do |result|
persist(options) if result
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mongo_mapper/plugins/inspect.rb
Expand Up @@ -4,7 +4,7 @@ module Plugins
module Inspect
module InstanceMethods
def inspect
attributes_as_nice_string = key_names.collect do |name|
attributes_as_nice_string = key_names.sort.collect do |name|
"#{name}: #{self[name].inspect}"
end.join(", ")
"#<#{self.class} #{attributes_as_nice_string}>"
Expand Down
1 change: 1 addition & 0 deletions mongo_mapper.gemspec
Expand Up @@ -26,5 +26,6 @@ Gem::Specification.new do |s|
s.add_development_dependency 'shoulda', '~> 2.11'
s.add_development_dependency 'timecop', '~> 0.3.1'
s.add_development_dependency 'mocha', '~> 0.9.8'
s.add_development_dependency 'turn', '~> 0.8.1'
s.add_development_dependency 'rack-test'
end
11 changes: 11 additions & 0 deletions test/functional/test_embedded_document.rb
Expand Up @@ -219,6 +219,17 @@ def setup
person.pets.first.should == pet
end

should "be able to save!" do
person = @klass.create

pet = @pet_klass.new(:name => 'sparky')
person.pets << pet
pet.should be_new

person.expects(:save!)
pet.save!
end

should "be able to dynamically add new keys and save" do
person = @klass.create

Expand Down
1 change: 0 additions & 1 deletion test/functional/test_identity_map.rb
Expand Up @@ -410,7 +410,6 @@ class ::BlogPost < ::Item
assert_in_map(root)

blog = Blog.create(:title => 'Jill', :parent => root)
blog.parent.inspect
assert_in_map(blog)
root.should equal(blog.parent.target)
end
Expand Down
1 change: 1 addition & 0 deletions test/test_helper.rb
Expand Up @@ -12,6 +12,7 @@
require 'shoulda'
require 'timecop'
require 'mocha'
require 'turn'
require 'ruby-debug'

class Test::Unit::TestCase
Expand Down
5 changes: 0 additions & 5 deletions test/unit/test_document.rb
Expand Up @@ -158,11 +158,6 @@ class Post
end
end

should "call inspect on the document's attributes instead of to_s when inspecting the document" do
doc = @document.new(:animals => %w(dog cat))
doc.inspect.should include(%(animals: ["dog", "cat"]))
end

context "equality" do
setup do
@oid = BSON::ObjectId.new
Expand Down
5 changes: 0 additions & 5 deletions test/unit/test_embedded_document.rb
Expand Up @@ -550,11 +550,6 @@ def name_and_age=(new_value)
end
end

should "call inspect on the document's attributes instead of to_s when inspecting the document" do
doc = @document.new(:animals => %w(dog cat))
doc.inspect.should include(%(animals: ["dog", "cat"]))
end

context "equality" do
setup do
@oid = BSON::ObjectId.new
Expand Down
22 changes: 22 additions & 0 deletions test/unit/test_inspect.rb
@@ -0,0 +1,22 @@
require 'test_helper'

class InspectTest < Test::Unit::TestCase
context "#inspect" do
setup do
@document = Doc('User') do
key :name, String
key :age, Integer
end

@doc = @document.new(:name => 'John', :age => 29)
end

should "print out attributes in alpha sorted order" do
@doc.inspect.should =~ /_id:.*, age: 29, name: "John"/
end

should "include class name" do
@doc.inspect.should =~ /^#<User/
end
end
end

0 comments on commit b3ab248

Please sign in to comment.