Sha256: 86c3b4f2b24424a847778a8a177655ed806a68ef292e91f36fdccb40e2eaf957

Contents?: true

Size: 1.15 KB

Versions: 5

Compression:

Stored size: 1.15 KB

Contents

require 'spec_helper'

module Arel
  describe "Header" do
    before :all do
      @relation = Model.build do |r|
        r.attribute :id,   Attributes::Integer
        r.attribute :name, Attributes::String
        r.attribute :age,  Attributes::Integer
      end

      @other = Model.build do |r|
        r.attribute :foo, Attributes::String
      end

      @subset = Model.build do |r|
        r.attribute :id, Attributes::Integer
      end
    end

    describe "attribute lookup" do
      it "finds attributes by name" do
        @relation.attributes[:name].should == Attributes::String.new(@relation, :name)
      end

      it "returns nil if no attribute is found" do
        @relation.attributes[:does_not_exist].should be_nil
        @relation[:does_not_exist].should be_nil
      end
    end

    describe "#union" do
      it "keeps all attributes from disjoint headers" do
        (@relation.attributes.union @other.attributes).to_ary.should have(4).items
      end

      it "keeps all attributes from both relations even if they seem like subsets" do
        (@relation.attributes.union @subset.attributes).to_ary.should have(4).items
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
arel-1.0.1 spec/attributes/header_spec.rb
arel-1.0.0 spec/attributes/header_spec.rb
arel-1.0.0.rc1 spec/attributes/header_spec.rb
arel-compat-0.4.0 spec/attributes/header_spec.rb
arel-0.4.0 spec/attributes/header_spec.rb