Reputation: 1835
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
Reputation: 115531
Replace
@show = FactoryGirl.build(:show)
with:
@show = FactoryGirl.attributes_for(:show)
Upvotes: 1