Позвольте мне начать с того, что я довольно плохо знаком с тестированием в Rails.Я получаю некоторые ошибки в своих тестах, и я не совсем понимаю, почему.
rails test:models
Run options: --seed 21021
# Running:
F
Failure:
UserTest#test_user_should_be_valid [/home/ubuntu/workspace/test/models/user_test.rb:9]:
Expected false to be truthy.
bin/rails test test/models/user_test.rb:8
E
Error:
PostTest#test_post_should_be_valid:
ArgumentError: When assigning attributes, you must pass a hash as an argument.
test/models/post_test.rb:5:in `setup'
bin/rails test test/models/post_test.rb:8
Finished in 0.237740s, 8.4126 runs/s, 4.2063 assertions/s.
2 runs, 1 assertions, 1 failures, 1 errors, 0 skips
Вот код
user_test
require 'test_helper'
class UserTest < ActiveSupport::TestCase
def setup
@user=User.new(email:"fo0@hotmail.com")
end
test "user should be valid" do
assert @user.valid?
end
end
post_test
require 'test_helper'
class PostTest < ActiveSupport::TestCase
def setup
@post=Post.new(:ruby_meetup)
end
test "post should be valid" do
assert @post.valid?
end
end
user.rb
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :posts
has_many :rsvps
has_many :posts, through: :rsvps
validates :email, presence: true
end
post.rb
class Post < ApplicationRecord
belongs_to :user
geocoded_by :address
after_validation :geocode, if: ->(obj){ obj.address.present? and obj.address_changed? }
reverse_geocoded_by :latitude, :longitude
after_validation :reverse_geocode
has_many :rsvps
has_many :users, through: :rsvps
validates :name, presence: true
end