【发布时间】:2018-02-14 04:10:07
【问题描述】:
这是我的设计单元测试代码。有什么方法可以写出更好的测试代码吗?
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
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 rubygems