Created
March 10, 2009 21:58
-
-
Save jpemberthy/77170 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
require File.expand_path(File.dirname(__FILE__) + '/refactored_mocks') | |
describe TitlesController do | |
include ControllersSpecHelper | |
def mock_title(stubs={}) | |
@mock_title ||= mock_model(Title, stubs) | |
end | |
before do | |
@mock_portafolio = mock_model(Portafolio, :id => 1, :save => true) | |
authenticate_user | |
end | |
describe "responding to POST create" do | |
before do | |
@mock_title = mock_model(Title, :save => true, :portafolio_id => @mock_portafolio.id) | |
@params = {:title => {:quantity => 300, :initial_price => 14000.23}, :name => "ALMACENES EXITO", :portafolio_id => 1} | |
@mock_portafolio.stub!(:titles).and_return([mock_title]) | |
@mock_portafolio.titles.stub!(:build).and_return(@mock_title) | |
end | |
describe "with valid params from portafolio/:id" do | |
it "should expose a newly created title as @title" do | |
Portafolio.should_receive(:find).and_return(@mock_portafolio) | |
@mock_portafolio.titles.should_receive(:build).and_return(@mock_title) | |
post :create, :model => @params[:title], :portafolio_id => @params[:portafolio_id] | |
end | |
it "should redirect to the title's portafolio" do | |
Portafolio.stub!(:find).and_return(@mock_portafolio) | |
post :create, :model => @params[:title], :portafolio_id => @params[:portafolio_id] | |
response.should redirect_to(portafolio_path(@mock_portafolio)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment