Sha256: b559f6f38da0ee20f3bd8d70df23ac4278caf4c107c4b5cd82f41f2089663514
Contents?: true
Size: 1.96 KB
Versions: 17
Compression:
Stored size: 1.96 KB
Contents
require "spec_helper" describe Mongoid::Relations::Reflections do class TestClass include Mongoid::Document end let(:klass) do TestClass end before do klass.relations.clear end describe ".reflect_on_association" do before do klass.embeds_many(:addresses) end context "when the name exists" do let(:relation) do klass.reflect_on_association(:addresses) end it "returns the association metadata" do expect(relation.macro).to eq(:embeds_many) end end context "when the name does not exist" do let(:relation) do klass.reflect_on_association(:nonexistant) end it "returns nil" do expect(relation).to be_nil end end end describe ".reflect_on_all_associations" do context "when relations exist for the macros" do before do klass.embeds_one(:name) klass.embeds_many(:addresses) klass.has_one(:user) end context "when passing multiple arguments" do let(:relations) do klass.reflect_on_all_associations(:embeds_one, :has_one) end it "returns an array of the relations" do expect(relations.size).to eq(2) end end context "when passing a single argument" do let(:relations) do klass.reflect_on_all_associations(:embeds_one) end it "returns an array of the relations" do expect(relations.size).to eq(1) end end end context "when no relations exist for the macros" do let(:relations) do klass.reflect_on_all_associations(:embeds_one) end it "returns an empty array" do expect(relations).to be_empty end end context "when no argument supplied" do let(:relations) do klass.reflect_on_all_associations end it "returns an empty array" do expect(relations).to be_empty end end end end
Version data entries
17 entries across 17 versions & 5 rubygems