Skip to content

Commit

Permalink
MONGOID-4921 add test for calling discriminator_key on instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Neilshweky committed Jul 14, 2020
1 parent 7da5e7f commit db017b5
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions spec/mongoid/traversable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
describe "#discriminator_key" do

context "when the discriminator key is not changed" do

it "equals _type" do
expect(Instrument.discriminator_key).to eq("_type")
end
Expand All @@ -270,6 +271,7 @@
end

context "when the discriminator key is changed at the global level" do

before do
Mongoid.discriminator_key = "hello"
end
Expand All @@ -285,11 +287,12 @@
it "all discriminator keys change" do
expect(Instrument.discriminator_key).to eq("hello")
expect(Piano.discriminator_key).to eq("hello")
expect(Guitar.discrdiminator_key).to eq("hello")
expect(Guitar.discriminator_key).to eq("hello")
end
end

context "when the discriminator key is changed in the parent" do

before do
Instrument.discriminator_key = "hello2"
end
Expand All @@ -309,7 +312,7 @@
end

context "when the discriminator key is changed in the child" do

it "raises an error" do
expect do
Guitar.discriminator_key = "hello3"
Expand All @@ -332,5 +335,24 @@
expect(Instrument.discriminator_key).to eq("_type")
end
end

context "when discriminator key is called on an instance" do

let(:guitar) do
Guitar.new
end

it "raises an error on setter" do
expect do
guitar.discriminator_key = "hello3"
end.to raise_error(NoMethodError)
end

it "raises an error on getter" do
expect do
guitar.discriminator_key
end.to raise_error(NoMethodError)
end
end
end
end

0 comments on commit db017b5

Please sign in to comment.