Home How to test my devise code using rspec?
Reply: 0

How to test my devise code using rspec?

user1166
1#
user1166 Published in May 23, 2018, 8:19 pm

Here is my unit testing code for devise. Are there any ways to write better test code?

user_spec.rb:

require 'rails_helper'

    RSpec.describe User, type: :model do

      it { should have_many(:companies) }
      it { should have_many(:jobs) }
      it do
               should validate_length_of(:encrypted_password).
                   is_at_least(6).
                   on(:create)
               end

      it { is_expected.to validate_presence_of(:email) }
      it { is_expected.to validate_presence_of(:encrypted_password) }
      it { should have_db_column(:id) }
      it { should have_db_column(:email) }
      it { should have_db_column(:encrypted_password) }
      it { should have_db_column(:confirmation_token) }
      it { should have_db_column(:confirmed_at) }
      it { should have_db_column(:confirmation_sent_at) }

      it 'is databse authenticable' do
        user = User.create(
           email: 'test@example.com', 
          password: 'password123',
          password_confirmation: 'password123'
        )
        expect(user.valid_password?('password123')).to be_truthy
      end
end
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.378274 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO