Authlogic: Functional Test Failing Validation

90 views Asked by At

I'm hoping someone can help me out. I'm in the process of building the standard blog application as part of learning Rails and have elected to include Authlogic for authentication/authorisation.

For some reason - and I can't for the life of me figure it out - the following functional test is now failing for what I assume are validation reasons:

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: "[email protected]", password: "foobar", password_confirmation: "foobar", dob: "2000-01-01", gender: "Female" }
    end
    assert User.find_by(email: "[email protected]").commenter?, "User is not a Commenter."
    assert_redirected_to root_url
  end

Output

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

From what I can tell, the POST to CREATE is the failing line as when all validations through Authlogic are removed or overridden, it passes. Any assistance would be greatly appreciated.

Thanks.

1

There are 1 answers

0
discrsadm On BEST ANSWER

Rick - you're a genius. I was missing :username as part of user_params in the controller. Thanks for the prompt.