[英]Issues with Rails 6 test
I am using ruby 2.7 and Rails version 6.0.2.1 When I try to test my model I get this message我使用的是 ruby 2.7 和 Rails 版本 6.0.2.1 当我尝试测试我的模型时,我收到此消息
Error:
OfferTest#test_valid_offer:
DRb::DRbRemoteError: PG::UndefinedTable: ERROR: relation "views" does not exist
LINE 8: WHERE a.attrelid = '"views"'::regclass
^
(ActiveRecord::StatementInvalid)
rails test test/models/offer_test.rb:4
This is my schema file:这是我的架构文件:
ActiveRecord::Schema.define(version: 2020_01_20_105655) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "offers", force: :cascade do |t|
t.string "city"
t.string "area"
t.string "address"
t.string "contact_person"
t.string "contact_person_phone"
t.string "denomination"
t.string "category"
t.string "typology"
t.integer "guests"
t.integer "rooms"
t.boolean "lift"
t.decimal "expense"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "requests", force: :cascade do |t|
t.string "name"
t.string "last_name"
t.string "address"
t.decimal "budget"
t.date "date_of_request"
t.string "document_id"
t.string "phone"
t.string "residential_address"
t.date "date_of_birth"
t.string "notes"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "users", force: :cascade do |t|
t.string "name", null: false
t.string "last_name", null: false
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
end
Ad of now I have 3 tables.现在我有 3 张桌子。 I am testing the Offer model but I get this strange behaviour.
我正在测试 Offer 模型,但我得到了这种奇怪的行为。 This is my test model code
这是我的测试模型代码
require 'test_helper'
class OfferTest < ActiveSupport::TestCase
test "valid offer" do
offer = Offer.new(city: "Rome", area: "Zona Sud", address: "Via Roma")
end
end
I've already run rails db:test:prepare but I cannot fix this issue.我已经运行了 rails db:test:prepare 但我无法解决这个问题。
My initial thought is that some gem is injecting behaviour into your models.我最初的想法是某些 gem 正在向您的模型中注入行为。
Something is expecting a table "views".有些东西在期待一个表“意见”。 The name
views
hints at either a gem using database views
to virtualize tables, or some gem that works in the domain with views
: for example a gem for statistics (An order has been viewed 21 times: has 21 views).这个名字
views
在任使用数据库宝石提示views
虚拟化表,或一些宝石,在同领域作品views
,例如用于统计宝石(订单已被浏览21次:有21个意见)。
I'd suggest removing all gems from your gemfile and re-including them one by one.我建议从您的 gemfile 中删除所有 gem,然后一一重新包含它们。 This will tell you what gem is injecting this behaviour: knowing what your dependencies do is an important part of building an app, IMO.
这将告诉您什么 gem 正在注入这种行为:了解您的依赖项的作用是构建应用程序 IMO 的重要部分。
If it is a gem, that gem most probably has some migrations that you need to install and run:如果它是一个 gem,那么这个 gem 很可能有一些你需要安装和运行的迁移:
bundle exec rake railties:install:migrations
bundle exec rake db:migrate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.