Authlogic:功能测试验证失败

Authlogic: Functional Test Failing Validation

我希望有人能帮助我。作为学习 Rails 的一部分,我正在构建标准博客应用程序,并选择为 authentication/authorisation.

添加 Authlogic

出于某种原因——我一辈子也想不通——以下功能测试现在失败了,我认为是验证原因:

user.rb

class User < ActiveRecord::Base

  acts_as_authentic do |c|
    c.validates_length_of_password_field_options minimum: 6
  end

  has_many :articles, dependent: :destroy
  has_many :comments, through: :articles

  enum role: [:commenter, :contributer, :admin] 

end

users_controller_test.rb

class UsersControllerTest < ActionController::TestCase

  def setup
    @user = users(:ben)
    activate_authlogic
  end

  test "should create user with default commenter role" do
    assert_difference 'User.count', 1 do
        post :create, user: { username: "Elenor Smalls", email: "test@test.com", password: "foobar", password_confirmation: "foobar", dob: "2000-01-01", gender: "Female" }
    end
    assert User.find_by(email: "test@test.com").commenter?, "User is not a Commenter."
    assert_redirected_to root_url
  end

输出

Run options: --seed 48600

# Running:

......F...................

Finished in 1.172103s, 22.1824 runs/s, 33.2735 assertions/s.

  1) Failure:
  UsersControllerTest#test_should_create_user_with_default_commenter_role  
  [/Users/Donovan/developer/webdevelopment/workspace/articles/test/controllers/users_controller_test.rb:11]:
  "User.count" didn't change by 1.
  Expected: 4
    Actual: 3

  26 runs, 39 assertions, 1 failures, 0 errors, 0 skips

据我所知,CREATE 的 POST 是失败的行,因为当所有通过 Authlogic 的验证被删除或覆盖时,它通过了。如有任何帮助,我们将不胜感激。

谢谢。

瑞克 - 你是个天才。我在控制器中缺少 :username 作为 user_params 的一部分。谢谢提示。