Sha256: 38390d65254e5c5bee9a814ab587410e39fd3684592ff49aa9d54e8715215531

Contents?: true

Size: 1.7 KB

Versions: 7

Compression:

Stored size: 1.7 KB

Contents

# multi_alias name, :create => :new, :insert_into => [:inject_into, :update], :read => :X_content
#                   :options => :after  
# 
# create_xxx becomes new_xxx
# insert_into_xxx becomes inject_into_xxx and update_xxx
# read_xxx becomes xxx_content (overriding default :after action to insert at the X)

require 'spec_helper'
require 'sugar-high/alias'

class Abc
  def hello_kristian
    'hello'
  end
  multi_alias :_after_ => :kristian, :hello => :howdy
end

class Xyz  
  def hello_kristian
    'hi'
  end

  multi_alias :kristian, :hello => :alloha
end

class Ged  
  def kristian_hello
    'hejsa'
  end
  
  multi_alias :_before_ => :kristian, :hejsa => :hello, :_direction_ => :reverse  
end  

class Wow
  REGISTRATION_LINKS = {
    :new_registration => :sign_up,
    :edit_registration => :edit_profile
  }

  # new_registration_link, edit_registration_link
  REGISTRATION_LINKS.keys.each do |name|
    puts "name: #{name}"
    class_eval %{
      def #{name}_link
      end
    }
  end
  multi_alias REGISTRATION_LINKS.merge(:_after_ => :link)  
end
     
describe "SugarHigh" do
  describe "Arguments" do    
    context 'should alias :hello_kristian with :howdy_kristian ' do
      it "should find alias" do
        Abc.new.respond_to?(:howdy_kristian).should be_true
      end
    end

    it "should find -alloha alias method for kristian" do
      Xyz.new.respond_to?(:alloha_kristian).should be_true
    end

    it "should find -hejsa alias method for kristian" do
      Ged.new.respond_to?(:kristian_hejsa).should be_true
    end

    it "should find alias methods!" do
      w = Wow.new
      w.respond_to?(:new_registration_link).should be_true
      w.respond_to?(:sign_up_link).should be_true
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sugar-high-0.2.1 spec/sugar-high/alias_spec.rb
sugar-high-0.2.0 spec/sugar-high/alias_spec.rb
sugar-high-0.1.8 spec/sugar-high/alias_spec.rb
sugar-high-0.1.7 spec/sugar-high/alias_spec.rb
sugar-high-0.1.6 spec/sugar-high/alias_spec.rb
sugar-high-0.1.5 spec/sugar-high/alias_spec.rb
sugar-high-0.1.4 spec/sugar-high/alias_spec.rb