Ruby on rails 用户测试不工作
这是我第一次在rails中运行测试,这是我遇到的错误 运行: E 错误:PostsControllerTest#test _应_显示_post: ActiveRecord::语句无效:找不到表“users” bin/rails测试/控制器/posts\u控制器\u测试。rb:26 E 错误:PostsControllerTest#test(测试)应(更新)post: ActiveRecord::语句无效:找不到表“users” 箱子/轨道测试/控制器/立柱控制器测试。rb:36 E 错误:PostsControllerTest#test(测试)应(创建)post: ActiveRecord::语句无效:找不到表“users” bin/rails测试/controllers/posts\u controller\u测试。rb:18 E 错误:PostsControllerTest#test(测试)应(销毁)post: ActiveRecord::语句无效:找不到表“users” bin/rails测试/控制器/posts\u控制器\u测试。rb:41 E 错误:PostsControllerTest#test(测试)应(获取)新的: ActiveRecord::语句无效:找不到表“users” bin/rails测试/controllers/posts\u controller\u测试。rb:13 E 错误:PostsControllerTest#test _应_获取_索引: ActiveRecord::语句无效:找不到表“users” bin/rails测试/controllers/posts\u controller\u测试。rb:8 E 错误:PostsControllerTest#test _应_获取_编辑: ActiveRecord::语句无效:找不到表“users” bin/rails测试/controllers/posts\u controller\u测试。rb:31 E 错误:UserTest#test(测试)用户(应)有效: ActiveRecord::语句无效:找不到表“users” bin/rails测试/模型/用户测试。rb:8 E 错误: HomeControllerTest测试应获取索引: ActiveRecord::语句无效:找不到表“users” bin/rails测试/controllers/home\u controller\u测试。rb:4 以0.316289s、28.4550次运行/秒、0.0000次断言/秒的速度完成。 9次运行,0次断言,0次失败,9次错误,0次跳过 这是说找不到用户表,为什么。这是我的密码Ruby on rails 用户测试不工作,ruby-on-rails,ruby,unit-testing,Ruby On Rails,Ruby,Unit Testing,这是我第一次在rails中运行测试,这是我遇到的错误 运行: E 错误:PostsControllerTest#test _应_显示_post: ActiveRecord::语句无效:找不到表“users” bin/rails测试/控制器/posts\u控制器\u测试。rb:26 E 错误:PostsControllerTest#test(测试)应(更新)post: ActiveRecord::语句无效:找不到表“users” 箱子/轨道测试/控制器/立柱控制器测试。rb:36 E 错误:Pos
require 'test_helper'
class UserTest < ActiveSupport::TestCase
def setup
@user=User.new(name:"minhaj")
end
test "user should be valid" do
assert @category.valid?
end
end
ActiveRecord::Schema.define(版本:20180413094453)do
祝贺你的测试。这总比调试好。在
assert@category.valid?
中尝试rake db:test:prepare
?为什么它不是@user
?你的权利我更改了它,但仍然得到相同的错误。我尝试过,但仍然得到相同的错误,在rails/bin控制台中
你可以运行user.new(名称:'foo')
,它可以工作,对吗?没有,但当我更改为user.new(电子邮件:“foo@hotmail.com")它在rails控制台上工作。因此,我在测试中做了更改,所以它显示的是email而不是名称,但我仍然收到相同的错误,有人建议bin/rails db:migrate
,但删除了它。尝试一下,即使你已经迁移了。然后尝试(在bash
)RAILS\u ENV=test bin/RAILS db:drop db:create
。我遵循了您所说的,但是仍然得到了与前面所述相同的错误。
def change
create_table :users do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
t.timestamps null: false
end
add_index :users, :email, unique: true
add_index :users, :reset_password_token, unique: true
# add_index :users, :confirmation_token, unique: true
# add_index :users, :unlock_token, unique: true
end
end
create_table "posts", force: :cascade do |t|
t.datetime "date"
t.string "name"
t.integer "user_id"
t.text "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.float "latitude"
t.float "longitude"
t.string "address"
end
create_table "rsvps", force: :cascade do |t|
t.integer "user_id"
t.integer "post_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["post_id"], name: "index_rsvps_on_post_id"
t.index ["user_id"], name: "index_rsvps_on_user_id"
end
# Could not dump table "users" because of following StandardError
# Unknown type 'false' for column 'admin_role'
end