From 0428ef5ccc87e1403de4017b6f854c310bfc8d82 Mon Sep 17 00:00:00 2001 From: Brandon Turner Date: Mon, 13 Feb 2012 15:02:44 -0600 Subject: [PATCH] Add embedded serialization without includes specs --- spec/functional/mongoid/serialization_spec.rb | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/spec/functional/mongoid/serialization_spec.rb b/spec/functional/mongoid/serialization_spec.rb index 32dd995dfa..e87ecf3b3c 100644 --- a/spec/functional/mongoid/serialization_spec.rb +++ b/spec/functional/mongoid/serialization_spec.rb @@ -99,6 +99,84 @@ end end + context "when a model has relations" do + let(:attributes) do + { "title" => "President", "security_code" => "1234" } + end + + before do + person.write_attributes(attributes, false) + end + + context "when the model is saved before the relation is added" do + + before do + person.save + end + + context "when a model has an embeds many" do + + let!(:address_one) do + person.addresses.build(:street => "Kudamm") + end + + before do + person.save + end + + it "includes the relation" do + person.serializable_hash.keys.should include('addresses') + end + end + + context "when a model has an embeds one" do + let!(:name) do + person.build_name(:first_name => "Leo", :last_name => "Marvin") + end + + before do + person.save + end + + it "includes the relation" do + person.serializable_hash.keys.should include('name') + end + end + end + + context "when the model is saved after the relation is added" do + + context "when a model has an embeds many" do + + let!(:address_one) do + person.addresses.build(:street => "Kudamm") + end + + before do + person.save + end + + it "includes the relation" do + person.serializable_hash.keys.should include('addresses') + end + end + + context "when a model has an embeds one" do + let!(:name) do + person.build_name(:first_name => "Leo", :last_name => "Marvin") + end + + before do + person.save + end + + it "includes the relation" do + person.serializable_hash.keys.should include('name') + end + end + end + end + context "when including methods" do it "includes the method result" do