Sha256: 9e991cdcee1021f369cfd43d1a64c6c13cb73d4a59ebe24fb015a6851639a087

Contents?: true

Size: 1.42 KB

Versions: 5

Compression:

Stored size: 1.42 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'

describe "finders", :type => :controller do 
  setup = lambda {
    class PiratesController < ActionController::Base
      expose_many(:pirates)
      private
        def find_pirate
          Pirate.find_by_title(params[:id])
        end
    end
    
    ActionController::Routing::Routes.draw do |map| 
      map.resources :pirates
    end
  }
  
  setup.call
  controller_name :pirates
  Object.remove_class(PiratesController)

  before(:each) do
    setup.call
    @controller = PiratesController.new
    @request    = ActionController::TestRequest.new
    @response   = ActionController::TestResponse.new
    
    @pirate = Factory.stub(:pirate)
    Pirate.stub(:find_by_title => @pirate)
  end
  
  after(:each) do
    Object.remove_class(PiratesController)
  end
  
  it "finds with a method name as symbol" do
    PiratesController.find :pirate, :with => Proc.new { Pirate.find_by_title(params[:id]) }
    get(:show, {:id => 'Captain'})
    
    should assign_to(:pirate).with(@pirate)
  end
  
  it "finds with a proc" do
    PiratesController.find :pirate, :with => :find_pirate
    get(:show, {:id => 'Captain'})
    
    should assign_to(:pirate).with(@pirate)    
  end
  
  it "finds with a block" do
    PiratesController.find :pirate do
      Pirate.find_by_title(params[:id])
    end
    
    get(:show, {:id => 'Captain'})
    
    should assign_to(:pirate).with(@pirate)    
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
exposure-0.1.3 spec/finders/finder_spec.rb
exposure-0.1.2 spec/finders/finder_spec.rb
exposure-0.1.1 spec/finders/finder_spec.rb
exposure-0.1.0 spec/finders/finder_spec.rb
exposure-0.0.7 spec/finders/finder_spec.rb