edited: followed suggestions. See at end of question.
I have a controller with two functions:
def new
if login_required
@discussion = Discussion.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @discussion }
end
end
end
def create
if login_required
@discussion = Discussion.new(params[:discussion])
@discussion.update_attribute("user_id",session[:userid])
respond_to do |format|
if @discussion.save
flash[:notice] = 'Discussion was successfully created.'
format.html { redirect_to(@discussion) }
format.xml { render :xml => @discussion, :status => :created, :location => @Discussion }
else
format.html { render :action => "new" }
format.xml { render :xml => @discussion.errors, :status => :unprocessable_entity }
end
end
end
end
Now, in my integration test file I have:
test "test 1" do
post "/users/login",:user=> { :name => "bob", :password => "test_pass" }
post "/discussions/create", :discussion => { :title => "title 1", :body => "discussion body", :id => "101"} #Create 1
assert_response :success #Assert 1
get "/discussions/101"
assert_response :success #Assert 2
end
However, I get a 302
on Assert 1.
If I change "Create 1" to be: post "/discussions/new", :discussion => { :title => "title 1", :body => "discussion body", :id => "101"}
I get a 404 error.
1) What is going on?
2) what tools/options are available to me so that I figure this out myself?
Thanks
update
Followed suggestion (from Ryan Bigg):
- post :create, { :discussion => { } }, { :user_id => users(:bob).id }
Result:
- Rack::Lint::LintError: env variable HTTP_USER_ID has non-string value 1976283457
Still unresolved.