Eytan
Eytan

Reputation: 1835

Rspec POST controller create test fails but web based submission works

I have the following rspec test for create method in my

describe "with valid information" do
  it "should respond with success" do
    post 'create', :show_secretary_id => @show_secretary.id, :show => @show
    response.should be_success
  end

  it "should incremenet the show count" do
    expect do 
      post 'create', :show_secretary_id => @show_secretary.id, :show => @show
    end.to change(Show,'count').by(1)
  end
end

The test fails. However, when I try the create method in the browser, it works. Any ideas on what I am missing?

EDIT: My Controller Code

  def create
    @show_secretary = ShowSecretary.find_by_id(params[:show_secretary_id])
    @show = @show_secretary.shows.build(params[:show])
    if @show.save
      flash[:notice] = "Successfully created show"
      redirect_to show_path @show 
    else
      render 'new'
    end
  end

EDIT: @show_secretary, @show

These two objects are ActiveRecords created and built by FactoryGirl respectively.

@show_secretary = FactoryGirl.create(:show_secretary_user).verifiable
@show = FactoryGirl.build(:show)

Upvotes: 0

Views: 215

Answers (1)

apneadiving
apneadiving

Reputation: 115531

Replace

@show = FactoryGirl.build(:show)

with:

@show = FactoryGirl.attributes_for(:show)

Upvotes: 1

Related Questions