I'm using Test::Unit to do functional testing on one of my controllers.

The action I want to test is create, from SessionsController. I have
simplified it to the extreme:

def create
@user = User.find_by_email(params[:email])
if @user
flash.now[:notice] = "ok, it exists"
else
flash.now[:notice] = "it does not exist"
end
render :new
end


This is my functional test:

require 'test_helper'

class SessionsControllerTest < ActionController::TestCase
test "object creation" do
user = User.create!(email: "user@example.com", password: "secret")

assert user.valid? # make sure User.new is correct
assert user.persisted? # make sure it's persisted

post :create, post: { email: "user@example.com" }

assert_equal "ok, it exists", flash.now[:notice]
end
end


And this is the execution flow:

$ bundle exec rake db:test:prepare
$ ruby -Itest test/functional/sessions_controller_test.rb -n
test_object_creation
Run options: -n test_object_creation

# Running tests:

F

Finished tests in 0.235903s, 4.2390 tests/s, 12.7171 assertions/s.

1) Failure:
test_object_creation(SessionsControllerTest)
[test/functional/sessions_controller_test.rb:13]:
<"ok, it exists"> expected but was
<"it does not exist">.

1 tests, 1 assertions, 1 failures, 0 errors, 0 skips



It seems that User.new is not persisting to the database. But why? I have
asserted the persistion and it passes.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/SvJmSUO2048J.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedMar 14, '12 at 10:38p
activeMar 14, '12 at 10:38p
posts1
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

David M: 1 post

People

Translate

site design / logo © 2021 Grokbase