ruby on rails - Testing User Model (Devise Authentication) with MiniTest -


i'm trying test user model, i've devise authentication.

the problem i'm facing is, 1. having 'password'/'password_confirmation' fields in fixtures giving me invalid column 'password'/'password_confirmation' error.

  1. if remove these columns fixture , add in user_test.rb

    require 'test_helper'  class usertest < activesupport::testcase         def setup         @user = user.new(name: "example user",                          email: "example@example.com",                          password: "test123",                          work_number: '1234567890',                          cell_number: '1234567890')       end        test "should valid"         assert @user.valid?       end        test "name should present"         @user.name = "example name "         assert @user.valid?       end      end 

the error i'm getting is:

  test_0001_should valid                                       fail (0.74s) minitest::assertion:         failed assertion, no message given.         test/models/user_test.rb:49:in `block in <class:usertest>'    test_0002_name should present                                fail (0.01s) minitest::assertion:         failed assertion, no message given.         test/models/user_test.rb:54:in `block in <class:usertest>'   fabulous run in 0.75901s 2 tests, 2 assertions, 2 failures, 0 errors, 0 skips 

i'm wondering why user object not valid?

thanks

i got work around after investigation below: add helper method fixture:

module fixturefilehelpers   def encrypted_password(password = 'password123')     user.new.send(:password_digest, password)   end end  activerecord::fixtureset.context_class.send :include, fixturefilehelpers 

and make fixture this:

default:   email: 'default@example.com'   name: "user name"   encrypted_password: <%= encrypted_password %>   work_number: '(911) 235-9871'   cell_number: '(911) 235-9871' 

and use fixture user object in user test.

def setup     @user = users(:default) end 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -