【发布时间】:2016-01-25 11:33:23
【问题描述】:
我的 Rails 应用程序运行良好,但是当我尝试应用一些模型测试时,RSpec 会抛出错误:
/home/luka/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql_adapter.rb:655:in `initialize': FATAL: password authentication failed for user "luka" (PG::ConnectionBad)
FATAL: password authentication failed for user "luka"
这是我的 database.yml 文件:
default: &default
adapter: postgresql
encoding: unicode
host: localhost
username: luka
password: 4129235
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5
test:
<<: *default
database: postdb_test
这是我运行的测试:
require 'spec_helper'
require 'rails_helper'
describe Student do
it "creates valid entry"
end
宝石文件:
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.4'
# Use postgresql as the database for Active Record
gem 'pg'
...
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'devise'
gem 'rails_12factor', group: :production
gem 'cancancan'
gem 'rspec-rails'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
我安装了一个 pg,用正确的密码创建了用户,并用正确的所有者创建了“postdb”。我已经在配置中从对等更改为 md5。没啥事儿。
UPD:看起来问题出在“postgres”用户中。命令“createdb”和 CREATE DATABASE 什么也没做,CREATE USER 和 ALTER USER 也是如此
【问题讨论】:
-
我想你忘了创建测试数据库吧?
-
@SergeiStralenia 肯定地创建了“postdb”和“postdb_test”
-
您确定您使用的密码正确吗?试试
psql --username luka --password -
@max 我发现了一些woodoo魔法,这个问题出在postgre用户身上(也许)。发送命令后,我一直一无所获。 psql -l 没有显示我的任何数据库。
-
你不会碰巧在 Mac 上运行 Postgres.app 吗?
标签: ruby-on-rails ruby postgresql rspec