aboutsummaryrefslogtreecommitdiffstats
path: root/spec/active_relation/relations/alias_spec.rb
blob: a2deae2840cecc35b22012357efe08dcf85e543f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')

module ActiveRelation
  describe Alias do
    before do
      @relation = Table.new(:users)
      @alias_relation = Alias.new(@relation, :foo)
    end
    
    describe '#prefix_for' do
      it "delegates to the underlying relation" do
        @alias_relation.prefix_for(@relation[:id]).should == :users
      end
    end
    
    describe '#aliased_prefix_for' do
      it "returns the alias" do
        @alias_relation.aliased_prefix_for(@relation[:id]).should == :foo
        @alias_relation.aliased_prefix_for(:does_not_exist).should be_nil
      end
    end
  end
end