there are two models user and resident .. and both has one to one relationship (has_one) btw them. this is the test for the user(user-test.rb)
I m getting error in this test :
require 'test_helper'
class UserTest < ActiveSupport::TestCase
def setup
@resident = residents(:res1)
@user = @resident.build_user(roll_number: "101303110", email: "user@example.com",password: "foobar", password_confirmation: "foobar")
end
test "should be valid" do
assert @user.valid?
end
test "roll_number should be present" do
@user.roll_number = " "
assert_not @user.valid?
end
test "email should be present" do
@user.email = " "
assert_not @user.valid?
end
test "email should not be too long" do
@user.email = "a" * 244 + "@example.com"
assert_not @user.valid?
end
test "email validation should accept valid addresses" do
valid_addresses = %w[user@example.com USER@foo.COM A_US-ER@foo.bar.org
first.last@foo.jp alice+bob@baz.cn]
valid_addresses.each do |valid_address|
@user.email = valid_address
assert @user.valid?, "#{valid_address.inspect} should be valid"
end
end
test "email validation should reject invalid addresses" do
invalid_addresses = %w[user@example,com user_at_foo.org user.name@example.
foo@bar_baz.com foo@bar+baz.com]
invalid_addresses.each do |invalid_address|
@user.email = invalid_address
assert_not @user.valid?, "#{invalid_address.inspect} should be invalid"
end
end
test "email addresses should be unique" do
duplicate_user = @user.dup
duplicate_user.email = @user.email.upcase
@user.save
assert_not duplicate_user.valid?
end
test "password should be present (nonblank)" do
@user.password = @user.password_confirmation = " " * 6
assert_not @user.valid?
end
test "password should have a minimum length" do
@user.password = @user.password_confirmation = "a" * 5
assert_not @user.valid?
end
test "authenticated? should return false for a user with nil digest" do
assert_not @user.authenticated?(:remember, '')
end
end
After executing the test,error came is as follows :
1) Failure:
ResidentTest#test_should_be_valid [/Users/nischaynamdev/RubymineProjects/hostel_mess_pay/test/models/resident_test.rb:9]:
Failed assertion, no message given.
18 runs, 25 assertions, 1 failures, 0 errors, 0 skips
the link for user model is as follows : Pls help me passing this test,I m trying since 30 minutes !
Aucun commentaire:
Enregistrer un commentaire