Authlogic:功能测试失败验证

时间:2015-06-08 09:21:51

标签: ruby-on-rails ruby testing functional-testing authlogic

我希望有人可以帮助我。我正在构建标准博客应用程序,作为学习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

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

据我所知,POST to CREATE是失败的行,因为当通过Authlogic的所有验证被删除或覆盖时,它都会通过。非常感谢任何帮助。

感谢。

1 个答案:

答案 0 :(得分:0)

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