user9601213
user9601213

Reputation:

user test not working

So this is my first time running test in rails and this is the error I'm getting.

Running:

E

Error: PostsControllerTest#test_should_show_post: ActiveRecord::StatementInvalid: Could not find table 'users'

bin/rails test test/controllers/posts_controller_test.rb:26

E

Error: PostsControllerTest#test_should_update_post: ActiveRecord::StatementInvalid: Could not find table 'users'

bin/rails test test/controllers/posts_controller_test.rb:36

E

Error: PostsControllerTest#test_should_create_post: ActiveRecord::StatementInvalid: Could not find table 'users'

bin/rails test test/controllers/posts_controller_test.rb:18

E

Error: PostsControllerTest#test_should_destroy_post: ActiveRecord::StatementInvalid: Could not find table 'users'

bin/rails test test/controllers/posts_controller_test.rb:41

E

Error: PostsControllerTest#test_should_get_new: ActiveRecord::StatementInvalid: Could not find table 'users'

bin/rails test test/controllers/posts_controller_test.rb:13

E

Error: PostsControllerTest#test_should_get_index: ActiveRecord::StatementInvalid: Could not find table 'users'

bin/rails test test/controllers/posts_controller_test.rb:8

E

Error: PostsControllerTest#test_should_get_edit: ActiveRecord::StatementInvalid: Could not find table 'users'

bin/rails test test/controllers/posts_controller_test.rb:31

E

Error: UserTest#test_user_should_be_valid: ActiveRecord::StatementInvalid: Could not find table 'users'

bin/rails test test/models/user_test.rb:8

E

Error:

HomeControllerTest#test_should_get_index: ActiveRecord::StatementInvalid: Could not find table 'users'

bin/rails test test/controllers/home_controller_test.rb:4

Finished in 0.316289s, 28.4550 runs/s, 0.0000 assertions/s. 9 runs, 0 assertions, 0 failures, 9 errors, 0 skips

It is saying that the user table could not be found, why is that. heres my code.

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

class DeviseCreateUsers < ActiveRecord::Migration[5.1]

 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

ActiveRecord::Schema.define(version: 20180413094453) do

  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

Upvotes: 0

Views: 161

Answers (1)

Phlip
Phlip

Reputation: 5343

Congratulations on testing. It's always better than debugging. Try rake db:test:prepare.

Upvotes: 0

Related Questions