Ruby on rails Authlogic:验证失败的功能测试

Ruby on rails Authlogic:验证失败的功能测试,ruby-on-rails,ruby,testing,functional-testing,authlogic,Ruby On Rails,Ruby,Testing,Functional Testing,Authlogic,我希望有人能帮我。作为learning Rails的一部分,我正在构建标准博客应用程序,并选择将Authlogic包含在其中进行身份验证/授权 出于某种原因——我一生都搞不清楚——以下功能测试现在失败了,原因我认为是验证原因: user.rb class User < ActiveRecord::Base acts_as_authentic do |c| c.validates_length_of_password_field_options minimum: 6 end

我希望有人能帮我。作为learning Rails的一部分,我正在构建标准博客应用程序,并选择将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
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
据我所知,要创建的POST是失败的一行,因为当通过Authlogic的所有验证都被删除或覆盖时,它就通过了。如蒙协助,将不胜感激


谢谢。

瑞克-你真是个天才。我在控制器中缺少
:username
作为
用户参数的一部分。感谢您的提示。

显示您的
用户\u控制器
代码
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