Sha256: 58cb35dfe5506acecb5e054f7a6604d10b7a7e05bbd6354e9ec711a697968ad3

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

require "#{File.expand_path(File.dirname(__FILE__))}/helper"
require "crystal/support/callbacks"
require "crystal/support/filters"

describe "Filters" do
  module ARemote
    inherit Crystal::Filters
  end
  
  class FiltersBasic
    inherit ARemote
          
    before :set_user
    
    def action
      'result'
    end

    attr_reader :user
    def set_user
      @user = 'some user'
    end
  end
  
  class FilterInheritance < FiltersBasic
    before :set_model
    
    attr_reader :model
    def set_model
      @model = 'some model'
    end      
  end
  
  class FilterOverrideAction < FiltersBasic
    def action
      'overriden result'
    end
  end
  
  it 'basic' do
    r = FiltersBasic.new
    r.run_callbacks(:action){r.send :action}.should == 'result'
    r.user.should == 'some user'
  end
  
  it 'inheritance' do
    r = FilterInheritance.new
    r.run_callbacks(:action){r.send :action}.should == 'result'
    r.user.should == 'some user'
    r.model.should == 'some model'
  end
  
  it "overriding action" do
    r = FilterOverrideAction.new
    r.run_callbacks(:action){r.send :action}.should == 'overriden result'
    r.user.should == 'some user'
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
crystal_ext-0.0.11 spec/support/filters_spec.rb