Skip to content

Commit

Permalink
Spec now use embed associations instead of has
Browse files Browse the repository at this point in the history
  • Loading branch information
leshill committed Mar 13, 2010
1 parent e720b29 commit 5093cbc
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions features/step_definitions/documents.rb
Expand Up @@ -12,7 +12,7 @@ class Place

attr_accessor :name
attr_accessor :type
has_one :address
embed :address
end

class Contact
Expand All @@ -22,7 +22,7 @@ class Contact
attr_accessor :type
attr_accessor :note
attr_accessor :interests
has_many :addresses
embed_many :addresses

scope :rubyists, any_in(:interests => ['ruby'])
scope :contract_work, any_in(:interests => ['contract work'])
Expand Down
2 changes: 1 addition & 1 deletion spec/associations/collection_proxy_spec.rb
Expand Up @@ -8,7 +8,7 @@ class CollectionProxyTest
end

let(:root) { stub('root', :register_save_observer => nil) }
let(:proxy) { MongoDoc::Associations::CollectionProxy.new(:assoc_name => 'has_many_name', :assoc_class => CollectionProxyTest, :root => root, :parent => root) }
let(:proxy) { MongoDoc::Associations::CollectionProxy.new(:assoc_name => 'embed_many_name', :assoc_class => CollectionProxyTest, :root => root, :parent => root) }
let(:item) { CollectionProxyTest.new }

context "#<<" do
Expand Down
2 changes: 1 addition & 1 deletion spec/associations/hash_proxy_spec.rb
Expand Up @@ -8,7 +8,7 @@ class HashProxyTest
end

let(:root) { stub('root', :register_save_observer => nil) }
let(:proxy) { MongoDoc::Associations::HashProxy.new(:assoc_name => 'has_many_name', :assoc_class => HashProxyTest, :root => root, :parent => root) }
let(:proxy) { MongoDoc::Associations::HashProxy.new(:assoc_name => 'embed_hash_name', :assoc_class => HashProxyTest, :root => root, :parent => root) }
let(:item) { HashProxyTest.new }
let(:other_item) {[1,2]}

Expand Down
2 changes: 1 addition & 1 deletion spec/associations_spec.rb
Expand Up @@ -208,7 +208,7 @@ class EmbedHashValidationChild
class EmbedHashValidationTest
include MongoDoc::Document

has_hash :subdocs, :class_name => 'EmbedHashValidationChild'
embed_hash :subdocs, :class_name => 'EmbedHashValidationChild'
end

let(:invalid_child) { EmbedHashValidationChild.new }
Expand Down
2 changes: 1 addition & 1 deletion spec/attributes_spec.rb
Expand Up @@ -135,7 +135,7 @@ class TestHasOneDoc
include MongoDoc::Document

attr_accessor :key
has_one :has_one
embed :embed
end

it "is _keys + _associations" do
Expand Down
2 changes: 1 addition & 1 deletion spec/contexts_spec.rb
Expand Up @@ -5,7 +5,7 @@
class ContextTest
include MongoDoc::Document

has_many :children
embed_many :children
end

context ".context_for" do
Expand Down
38 changes: 19 additions & 19 deletions spec/document_spec.rb
Expand Up @@ -62,7 +62,7 @@ class SimpleValidationTest
class SaveRoot
include MongoDoc::Document

has_many :save_children
embed_many :save_children
end

class SaveChild
Expand Down Expand Up @@ -261,7 +261,7 @@ class CreateTest
class UpdateAttributesRoot
include MongoDoc::Document

has_one :update_attributes_child
embed :update_attributes_child
end

class UpdateAttributesChild
Expand Down Expand Up @@ -530,67 +530,67 @@ class OtherObject
end

context "associations" do
context "has_one" do
class TestHasOneBsonDoc
context "embed" do
class TestEmbedBsonDoc
include MongoDoc::Document

has_one :subdoc
embed :subdoc
end

class SubHasOneBsonDoc
class SubEmbedBsonDoc
include MongoDoc::Document

attr_accessor :attr
end

it "#to_bson renders a bson representation of the document" do
doc = TestHasOneBsonDoc.new
subdoc = SubHasOneBsonDoc.new(:attr => "value")
doc = TestEmbedBsonDoc.new
subdoc = SubEmbedBsonDoc.new(:attr => "value")
bson = doc.to_bson
bson["subdoc"] = subdoc.to_bson
doc.subdoc = subdoc
doc.to_bson.should == bson
end

it "roundtrips" do
doc = TestHasOneBsonDoc.new
subdoc = SubHasOneBsonDoc.new(:attr => "value")
doc = TestEmbedBsonDoc.new
subdoc = SubEmbedBsonDoc.new(:attr => "value")
doc.subdoc = subdoc
MongoDoc::BSON.decode(doc.to_bson).should == doc
end
end

context "has_many" do
context "embed_many" do

class SubHasManyBsonDoc
class SubEmbedManyBsonDoc
include MongoDoc::Document

attr_accessor :attr
end

class TestHasManyBsonDoc
class TestEmbedManyBsonDoc
include MongoDoc::Document
has_many :subdoc, :class_name => 'SubHasManyBsonDoc'
embed_many :subdoc, :class_name => 'SubEmbedManyBsonDoc'
end

it "#to_bson renders a bson representation of the document" do
doc = TestHasManyBsonDoc.new
subdoc = SubHasManyBsonDoc.new(:attr => "value")
doc = TestEmbedManyBsonDoc.new
subdoc = SubEmbedManyBsonDoc.new(:attr => "value")
bson = doc.to_bson
bson["subdoc"] = [subdoc].to_bson
doc.subdoc = subdoc
doc.to_bson.should == bson
end

it "roundtrips" do
doc = TestHasManyBsonDoc.new
subdoc = SubHasManyBsonDoc.new(:attr => "value")
doc = TestEmbedManyBsonDoc.new
subdoc = SubEmbedManyBsonDoc.new(:attr => "value")
doc.subdoc = subdoc
MongoDoc::BSON.decode(doc.to_bson).should == doc
end

it "roundtrips the proxy" do
doc = TestHasManyBsonDoc.new(:subdoc => SubHasManyBsonDoc.new(:attr => "value"))
doc = TestEmbedManyBsonDoc.new(:subdoc => SubEmbedManyBsonDoc.new(:attr => "value"))
MongoDoc::Associations::CollectionProxy.should === MongoDoc::BSON.decode(doc.to_bson).subdoc
end
end
Expand Down
12 changes: 6 additions & 6 deletions spec/embedded_save_spec.rb
Expand Up @@ -4,13 +4,13 @@
class NestedDocsRoot
include MongoDoc::Document

has_many :nested_children
embed_many :nested_children
end

class NestedChild
include MongoDoc::Document

has_one :leaf
embed :leaf
end

class LeafDoc
Expand Down Expand Up @@ -42,7 +42,7 @@ class LeafDoc
end

context "update_attributes naive" do
context "with no has_many, update_attributes" do
context "with no embed_many, update_attributes" do
let(:root) { NestedChild.new(:leaf => leaf) }

it "calls the root document's _naive_update_attributes with a full attribute path and not safe" do
Expand All @@ -56,7 +56,7 @@ class LeafDoc
end
end

context "with has_many, update_attributes" do
context "with embed_many, update_attributes" do
let(:root) { NestedDocsRoot.new(:nested_children => [NestedChild.new(:leaf => leaf)]) }

it "calls the root document's _naive_update_attributes with a full attribute path and not safe" do
Expand All @@ -78,7 +78,7 @@ class LeafDoc
leaf.stub(:_id).and_return(leaf_id)
end

context "with no has_many, update_attributes" do
context "with no embed_many, update_attributes" do
let(:root) { NestedChild.new(:leaf => leaf) }

it "calls the root document's _strict_update_attributes with a full attribute path and not safe" do
Expand All @@ -92,7 +92,7 @@ class LeafDoc
end
end

context "with has_many, update_attributes" do
context "with embed_many, update_attributes" do
let(:root) { NestedDocsRoot.new(:nested_children => [NestedChild.new(:leaf => leaf)]) }

it "calls the root document's _naive_update_attributes with a full attribute path and not safe" do
Expand Down
8 changes: 4 additions & 4 deletions spec/new_record_spec.rb
Expand Up @@ -8,8 +8,8 @@ class Child
class Parent
include MongoDoc::Document

has_one :child
has_many :children
embed :child
embed_many :children

attr_accessor :data

Expand All @@ -20,7 +20,7 @@ class Parent
let(:collection) { stub('collection', :save => id) }
let(:child) { Child.new }

context "as a has_one child" do
context "as a embed child" do
it "when added to the parent is a new record" do
Parent.new(:data => 'data', :child => child)
child.should be_new_record
Expand Down Expand Up @@ -70,7 +70,7 @@ class Parent
end
end

context "as a has_many child" do
context "as a embed_many child" do
it "when added to the parent is a new record" do
parent = Parent.new(:data => 'data')
parent.children << child
Expand Down

0 comments on commit 5093cbc

Please sign in to comment.