# Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com # All files in this distribution are subject to the terms of the MIT license. require File.expand_path('../../../../spec/helper', __FILE__) class SpecViewAlias < Ramaze::Controller map '/' def greet(type, message = "Message") @greet = "#{type} : #{message}" end def list @obj = Ramaze::Current.action.method end alias_method :index, :list alias_view :index, :list alias_view :non_existant_method, :list end class SpecViewAlias2 < SpecViewAlias map '/other' def greet__mom(message = "Moms are cool!") greet('Mom', message) end alias_view :greet__mom, :greet, SpecViewAlias def greet__other @greet = "Other" end alias_view :greet__other, :blah def greet__another @greet = "Another" end alias_view :greet__another, :greet__other def greet__last @greet = 'Last' end alias_view :greet__last, 'greet__other' end describe "Template aliasing" do behaves_like :rack_test it 'serves normal template' do get('/greet/asdf').body.should == 'asdf : Message' end it 'references template from another controller' do get('/other/greet/mom').body.should == 'Mom : Moms are cool!' end it 'only uses aliased template if one can be found' do get('/other/greet/other').body.should == 'Other: Other' end it 'accepts aliases given as symbols' do get('/other/greet/another').body.should == 'Other: Another' end it 'accepts aliases given as strings' do get('/other/greet/last').body.should == 'Other: Last' end it 'aliases template for index action' do get('/list').body.should == 'list' get('/index').body.should == 'index' end it 'uses aliases even for non-existant actions' do get('/non_existant_method').body.should == '' end end