Permalink
Browse files

Merge branch 'master' into rails3

* 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...
2 parents 6211577 + 5aca9ff commit b3ab248dd9071a7b45578a5415aab37f5f40e656 @bkeepers bkeepers committed Feb 1, 2011
View
@@ -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)
@@ -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
@@ -74,4 +77,5 @@ DEPENDENCIES
ruby-debug19
shoulda (~> 2.11)
timecop (~> 0.3.1)
+ turn (~> 0.8.1)
tzinfo
@@ -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
@@ -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}>"
@@ -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
@@ -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
@@ -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
View
@@ -12,6 +12,7 @@
require 'shoulda'
require 'timecop'
require 'mocha'
+require 'turn'
require 'ruby-debug'
class Test::Unit::TestCase
@@ -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
@@ -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
@@ -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.