require 'spec_helper'

describe Relation::Mapper, '.from' do
  subject { described_class.from(other, name) }

  let(:model) {
    mock_model(:TestModel)
  }

  let(:other) {
    model_class = model
    address_model = mock_model('Address')

    Class.new(described_class) {
      model model_class
      map :id, Integer
      has 1, :address, address_model
    }
  }

  context "with another mapper" do
    context "without a name" do
      let(:name) { nil }

      its(:model) { should be(model) }
      its(:name)  { should eql("TestModelMapper") }
    end

    context "with a name" do
      let(:name) { 'AnotherTestModelMapper' }

      its(:model) { should be(model) }
      its(:name)  { should eql(name) }

      it "copies relationships" do
        subject.relationships[:address].should eql(other.relationships[:address])
      end
    end
  end
end

require 'spec_helper'

describe Relation::Mapper, '.from' do
  subject { described_class.from(other, name) }

  let(:model)        { mock_model(:TestModel) }
  let(:target_model) { mock_model(:Address) }

  let(:other)        { mock_mapper(model, [ attribute ], [ relationship ]) }
  let(:attribute)    { mock_attribute(:id, Integer) }
  let(:relationship) { mock_relationship(:address, :source_model => model, :target_model => target_model) }

  context "with another mapper" do
    context "without a name" do
      let(:name) { nil }

      its(:model) { should be(model) }
      its(:name)  { should eql("TestModelMapper") }
    end

    context "with a name" do
      let(:name) { 'AnotherTestModelMapper' }

      its(:model) { should be(model) }
      its(:name)  { should eql(name) }

      it "copies relationships" do
        subject.relationships[:address].should eql(other.relationships[:address])
      end
    end
  end
end

Fix Relation::Mapper.from spec under 1.8 rubies
Fix Relation::Mapper.from spec under 1.8 rubies
