Not able to access test db from rake tests - ruby-on-rails

I'm unable to execute bundle exec rake because for some reason I can't connect to my database, the error is more than obvious :
rake aborted!
Java::JavaSql::SQLException: ORA-01017: invalid username/password; logon denied
You're seeing Java etc. because I'm using jRuby. So my next move was to start a rails console in test mode which I did with rails console test. Worked just fine, I tried to create a new object just in case and I was able to do it with no issues.
So why is my bundle exec rake failing to connect to the db? And what can I do to fix this? The test db configuration is fine because I can use the test rails console right?
Have no idea what to try next, any hints/tips will be appreciated.

Related

Error when running bin/rails test in Vagrant

I'm running the rails-dev-box on Vagrant, with a folder shared between the box and my Windows computer. Rails version 5.0.5. I have a very basic app using a sqlite3 database, and a basic generated scaffold for a model. When I ran bin/rails test I received this error:
ActiveRecord::Tasks::DatabaseAlreadyExists
A link in this GitHub thread pointed to this SO question, and I followed this answer - I edited database.yml to change the location of the databases to a location outside of the shared folder. I then re-migrated the databases with bin/rails db:migrate. This seemed to help a bit, because the next time I ran bin/rails test I received a different error:
Migrations are pending. To resolve this issue, run:
bin/rails db:migrate RAILS_ENV=test
But even after running bin/rails db:migrate RAILS_ENV=test I still receive this error each time I try to run the test.
I think all you need is bin/rails db:test:prepare before bin/rails test

Heroku deployment error RoR

When running my RoR app in Heroku shows this error:
We're sorry, but something went wrong.
If you are the application owner check the logs for more information.
Checking the heroku logs, this shows http://pastebin.com/yTWtRMVD
My main page is https://salty-stream-26420.herokuapp.com/ and my callback URL is https://salty-stream-26420.herokuapp.com/auth/twitter/callback in OmniAuth.
It runs in Cloud9 perfectly but not in Heroku. What is wrong?
Thank you, Alex.
This:
2016-05-03T13:47:23.544506+00:00 app[web.1]: PG::UndefinedTable: ERROR: relation "submissions" does not exist
suggests to me that you have to simply migrate your database on the remote server.
Try running heroku run rake db:migrate
You will have to create environment variables in the config/database.yml file for the username, password and database name
Those same environment variables need to be defined under
Heroku login >> application >> settings >> reveal config vars
By default you will get a DATABSE_URL something as
postgres://wwwbirawxqwmws:7bef28c02299c9c6054a646b5ce19276bbab52feca6692dac8305b32dbd7d36c#ec2-81-XX-XXX-X26.compute-1.amazonaws.com:5432/d6n59y5r09ko99
where wwwbirawxqwmws is USER
and 7bef28c02299c9c6054a646b5ce19276bbab52feca6692dac8305b32dbd7d36c is PASSWORD
and d6n59y5r09ko99 is the DATABASE
These three variables needs to be assigned in the heroku config, then you will be able to run
heroku run rake db:create
heroku run rake db:migrate

FATAL: database «sampleapp_production» does not exits

First time here, I hope do it right.
I'm following the railstutorial 3.2 and I'm in section 5.4, in the paragraph above to listing 5.32.
(In fact, you can just type rake by itself; the default behavior of rake is to
run the test suite.)
I used rake by itselft but I have a error since then. When I run:
"$ bundle exec rake spec" I get this error.
http://pastebin.com/F0wrEkT1
My database.yml is:
http://pastebin.com/tWAgeFTV
My problem is that I don't know why it is asking for production database when I didn't use it yet. And whe I look for the issue I don't find topics about (almost I didn't find it).
Do you have some clues to star looking or to know what is happening?
Thanks a lot.
I'm not sure why it is looking for the production DB but you may want to skip ahead. Just read a little further:
(In fact, you can just type rake by itself; the default behavior of rake is to run the test suite.) The only caveat is that using rake to run the tests for the current sample application will raise an error since it requires the test database to be prepared properly, a step we’ll defer to Section 6.2.1.
It recommends running:
bundle exec rake db:test:prepare

running rake task on 'production' and specifying environment?

I have a host at Linode and am trying to run a Rake task on it, but I get a mySQL error saying it can't connect. It looks like it thinks it is on dev. I did some Googling and saw that I can do something like this:
bundle exec rails c
It loads the dev environment and I can't run User.all giving me an access denied error.
If I run bundle exec rails c RAILS_ENV=production I get the error:
Rails.env=production database is not configured (ActiveRecord::AdapterNotSpecified)
However, if I access it via the web, everything is OK. I was able to run rake db:seed before so I know that there's some way around this.
Accessing mySQL with the production credentials works fine.
Any ideas?
Try this:
rails c production
or, at the beginning:
RAILS_ENV=production rails c
It thinks you're passing RAILS_ENV=production as an argument when you put it at the end.
If you want to run your console in the context of the current bundle in your Gemfile and ensure you're using your Gemset use:
bundle exec rails c production
This works for me. It depends on how your server and all its dependencies are set up:
RAILS_ENV=production bundle exec rails console

Rake error fixed by bundle exec, but deployment not working

I pushed an update to my Rails app production server, and in the update there was a new database migration. I ran rake db:migrate and got the common error seen here. I ran the rake again in bundle exec bash and it was successful. But after restarting my apache server, I'm now getting the 500 Error page. This update worked fine on my localhost, and was mostly this update to the db with supporting changes in the according view and controller/routing.
I don't even know why this error appeared this time, as I have pushed db updates successfully before using only rake. Nonetheless, the rake was successful. The 500 error page only shows on pages that require that specific new ActiveRecord. Any ideas on how to debug?
EDIT: My problem was an extremely simple one. I merely forgot to include the environment with the rake:
bundle exec rake db:migrate RAILS_ENV=production
Unfortunately, it took quite a while to narrow that down, as I couldn't use IRB to check the db entries until I followed these steps.
Did you run rake db:migrate on your server? Also be sure to set the RAILS_ENV flag so your production database is updated:
rake db:migrate RAILS_ENV=production

Resources