spec/mongoid/serializable_spec.rb in mongoid-8.0.8 vs spec/mongoid/serializable_spec.rb in mongoid-8.1.0

- old
+ new

@@ -12,23 +12,23 @@ it "does not duplicate fields" do expect(guitar.send(:field_names, {})).to eq(guitar.fields.except("_type").keys.sort) end - context "when using a custom discriminator_key" do - before do + context "when using a custom discriminator_key" do + before do Instrument.discriminator_key = "dkey" end - after do + after do Instrument.discriminator_key = nil end let(:guitar) do Guitar.new end - + it "includes _type but does not include the new discriminator key" do expect(guitar.send(:field_names, {})).to eq(guitar.fields.except("dkey").keys.sort) end end end @@ -39,20 +39,16 @@ before do reload_model(:Minim) end after do - Mongoid.include_root_in_json = false reload_model(:Minim) end context "when global config is set to true" do + config_override :include_root_in_json, true - before do - Mongoid.include_root_in_json = true - end - it "returns true" do expect(Minim.public_send(meth)).to be true end context 'when value is overridden to false in the model class' do @@ -65,15 +61,12 @@ end end end context "when global config set to false" do + config_override :include_root_in_json, false - before do - Mongoid.include_root_in_json = false - end - it "returns false" do expect(Minim.public_send(meth)).to be false end context 'when value is overridden to true in the model class' do @@ -87,17 +80,17 @@ end end end describe "#include_root_in_json" do + config_override :include_root_in_json, false before do reload_model(:Minim) end after do - Mongoid.include_root_in_json = false reload_model(:Minim) end let(:minim) do Minim.new @@ -125,14 +118,10 @@ end end context "when global config set to false" do - before do - Mongoid.include_root_in_json = false - end - it "returns false" do expect(minim.public_send(meth)).to be false end context 'when value is overridden to true in the model class' do @@ -295,19 +284,12 @@ expect(options[:except]).to be_nil end end context "when include_type_for_serialization is true" do + config_override :include_type_for_serialization, true - before do - Mongoid.include_type_for_serialization = true - end - - after do - Mongoid.include_type_for_serialization = false - end - it "includes _type field" do expect(person.serializable_hash.keys).to include '_type' end end @@ -879,17 +861,14 @@ let(:account) do Account.new end context "when including root in json via Mongoid" do + config_override :include_root_in_json, false before do account.include_root_in_json.should be false Mongoid.include_root_in_json = true - end - - after do - Mongoid.include_root_in_json = false end it "uses the mongoid configuration" do expect(JSON.parse(account.to_json)).to have_key("account") end