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: "u...@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: "u...@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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to