Problems with "rake test" - ruby-on-rails-3

I have one problem with the command "rake test" that I don't know how to resolve. When I execute this command show me:
DEPRECATION WARNING: primary_key_name is deprecated and will be removed from Rails 3.2 (use foreign_key instead). (called from foreign_key at /home/guilhermec/.rvm/gems/ruby-1.9.2-p290#iba-jornais/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/association_matcher.rb:194)
What can I do to resolve it ?

This warning stems from a deprecated method in a gem. If you want you can:
file a issue on the project page
fork the gem and replace the method
ignore it
edit: this seems to be fixed in shoulda-matchers since 9 months

Related

Rails 5 DEPRECATION WARNING: to_prepare is deprecated

When running rspec tests, I am getting the following deprecation warning
DEPRECATION WARNING: to_prepare is deprecated and will be removed from Rails 5.1 (use ActiveSupport::Reloader.to_prepare instead) (called from <top (required)> at /Users/Chris/Sites/golf_mentor/config/environment.rb:5)
Line 5 of my environment.rb is just
Rails.application.initialize!
How do I fix the code so this deprecation warning does not occur?
That message for sure is generated because a gem is using that deprecated method.
Maybe with rspec -b you could have more insight about what gem is and update that gem (in the best case that the warning was already solved).
If that doesn't work, another option could be to update your gems until find which one is causing the warning.
The last option is just ignore the warning because is not going to cause you problems until you update your app to rails 5.1 and when that time comes you will know which gem is because it will throw an exception.

Rails 3 in test env won't allow records to save, even with latest sqlite3

I saw this post:
Rails/ActiveRecord/SQLite3: Can't save records in test environment
And after upgrading my sqlite version to the very latest (3.7.17), I am still getting the following error:
ActiveRecord::StatementInvalid: SQLite3::SQLException: near "SAVEPOINT": syntax error: SAVEPOINT active_record_1
Any time I try to create anything at all. If all I do is load my fixtures, everything is fine.
I have confirmed that rails is using the updated sqlite3 version by running "rails db".
In my development environment, I can create objects all day long with no errors (I can even have an object create another object after create).
What is special about my test environment that this is happening? How can I fix it?
Edit:
If I delete my test database, and redo rake:db:create and rake:db:migrate, I still get the same issues.
Doing "rails console test" lets me use the test environment just fine, and I can create objects all day long and see existing fixtures. It's only when I type "rake test:units" that I get the errors... (originally I had errors, but one error was legitimate (I don't know why I wasn't getting it in the development environment, and the adapter error was because apparently you aren't supposed to do "rails console RAILS_ENV="test", so it was looking for an adapter for an envrionment called "RAILS_ENV=test")
Edit: When I type "gem uninstall sqlite3" it uninstalls. When I then type "bundle install" it has a problem reinstalling...working on it now.
/home/jenny/.rvm/rubies/ruby-1.9.3-p0/bin/ruby extconf.rb --with-sqlite3-dir=/usr/local/bin/sqlite3 checking for sqlite3.h... *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check
the mkmf.log file for more details. You may need configuration
options.
If I type "gem install sqlite3" separately, it works just fine, and then "bundle install" it works. However, "rake test:units" has the same errors.
Edit:
When I type "which sqlite3" it prints out "/usr/local/bin/sqlite3"
I wasn't even aware sqlite3 headers were a thing, so I doubt I installed them. I'll try to figure out how to confirm this and see if it helps.
Edit:
I don't see anywhere to download sqlite3 headers on the main site...just source and the precompiled linux binary. There doesn't seem to be a special header in the source, but even if there was, wouldn't it be included in the precompiled binary?
EDIT: link to bundler sqlite3 install error that don't happen when i manually install the gem
http://pastie.org/8063577
EDIT: Not a devise problem. I thought it was, but it turned out I was just creating another object in fixtures, not in the test code.
So, I can create devise User or any other type of object in fixtures all day long, but if I attempt to create one in the unit test, I get the save point error. Same thing for trying to save a fixture in a unit test.
Your problem is most likely related to the fact that you updated your local sqlite but after that you haven't reinstalled your sqlite3 gem.
I'd recommend you follow these steps:
Remove the corresponding line gem 'sqlite3' from your Gemfile
Run bundle install
Run gem uninstall sqlite3
Return the line gem 'sqlite3' to your Gemfile
Run bundle install one more time
If you simply gem uninstall and then bundle install, it will install the same version and dependencies that were recorded in Gemfile.lock. But since you're now using a different and more updated local version, it's safer to allow Bundler to install a new version if needed.

warning in installation in fedena

I got following warning while installing fedena , how do I fix it
rake/rdoctask is deprecated. Use rdoc/task instead (in RDoc 2.4.2+)
WARNING: Global access to Rake DSL methods is deprecated. Please include
... Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method Spec::Rake::SpecTask#task called at C:/Fedena/lib/tasks/rspe
c.rake:28:in `initialize'
I had recently installed Fedena. The command "bundle exec rake db:create" worked for me! Glad to provide more info if needed!
1. Go to rakefile
change require 'rake/rdoctask'
to require 'rdoc/task'
2. Go to Gemfile
add gem 'rdoc'
3. run Bundle

Ruby-on-rails gem failing for "where" condition of meta_where

I have a question about what is probably a gems problem, but may be meta-where. I used gems to install meta_where-1.0.4, and the response was that I succeeded and the uri for meta_where was provided, but when I tried a where-condition in the search method of a controller, similar to this example that meta-where provides:
Person.where(:skill_set.matches => 'Hello%'
an error was reported:
"undefined method 'matches' for :skill_set:Symbol"
It's as if the gem's methods aren't being accessed. I tried using "require" but that didn't help.
I'm using Windows XP, Firefox, Ruby 1.9.2.
What do I need to do?
Thanks, Barney
I assume you have run the migrations and there is a skill_set attribute in the person table: you don't need require. Just add 'gem meta_where' to your Gemfile and then run 'bundle install'.

Global access to Rake DSL methods is deprecated

I am working through the Ruby on Rails 3 tutorial book and typed the following on the command line:
rake db:migrate
which produced the following warning.
WARNING: Global access to Rake DSL methods is deprecated. Please Include
... Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method DemoApp::Application#task called at /Users/imac/.rvm/gems/ruby-1.9.2-p180#rails3tutorial/gems/railties-3.0.7/lib/rails/application.rb:215:in `initialize_tasks'
I am not sure what to do about it or how to work with it. I don't know any other command for Rake.
How can I fix this problem?
Adding include Rake::DSL to the Rakefile before the applications load_tasks were called also worked for me.
So in the above user's case before the DemoApp::Application.load_tasks in the Rakefile.
I found this in Stack Overflow question Ruby on Rails and Rake problems: uninitialized constant Rake::DSL. It refers to a #DHH tweet.
Put the following in your Gemfile
gem "rake", "0.8.7"
You may see something like
rake aborted!
You have already activated Rake 0.9.1 ...
I still had a copy of Rake 0.9.1 in my directory so I deleted it.
You can "delete" Rake 0.9.1 by running the following command:
gem uninstall rake -v=0.9.1
If you have multiple versions of the gem installed, you'll be prompted to pick a version.
After 0.9.1 was cleaned out, I ran
bundle update rake
and was finally able to create my database files. I was using rake db:create, but it should work for rake db:migrate as well.
I hope it helps.
I was having the same problem on Windows with the installer. Ruby 1.9.2 and Rails 3.0.9.
Here is what I did:
bundle update rake
bundle show rake
After doing that I was running rake 0.9.2.
Then I updated the Rakefile in application root folder as follows:
require File.expand_path('../config/application', __FILE__)
require 'rake'
# If you named your application something other than SampleApp, change that below
module ::SampleApp
class Application
include Rake::DSL
end
end
module ::RakeFileUtils
extend Rake::FileUtilsExt
end
SampleApp::Application.load_tasks
As noted in the comment, make sure the name of your app is correct in the two appropriate lines above.
If you are seeing this on later versions of Rails (like 3.+) you may also want to verify that your environment is clean by using RVM http://beginrescueend.com/ and creating a specific ruby & gemset for your projects.
Use an .rvmrc file on a per-project basis, this will guarantee you aren't getting older system gems into your projects. Which has bitten me before.
This prevents having to monkey around with generated Rakefiles & such.
bundle exec rake db:migrate will solve your ruby version issues