How to add 'rake test' to project - ruby-on-rails-3

When I ran rake -T, I discovered rake test was missing. What do I need to do to get this task in there? Specifically, I want to run rake test:benchmark but that doesn't seem to be loaded. For example...
$rake test:benchmark
rake aborted!
Don't know how to build task 'test:benchmark'

My config/application.rb file was missing this line:
require 'rails/all'

You only need:
require "rails/test_unit/railtie"
in your config/application.rb

Related

Rails db:seed unknown attribute

Here is a question.
I have an Rails project. When I want to clear my database and fill it with some test data I run:
rake db:drop db:create db:migrate db:seed
and I have an error:
NoMethodError: undefined method login for #<User:0x007fecf46afe80>
When I run separately:
rake db:drop db:create db:migrate
rake db:seed
all goes fine.
Also all my actions in db/seeds.rb are wrapped in ActiveRecord::Base.transaction block.
I had to add User.reset_column_information in the top of my db/seeds.rb to make
rake db:drop db:create db:migrate db:seed
working.
I didn't have the same errors before without reset_column_information. Does somebody have any ideas why it's happen?
PS: after running rake db:drop db:create db:migrate there is "missing" column in db/schema.rb and I can see this column in DB directly
From the docs:
reset_column_information() public
Resets all the cached information
about columns, which will cause them to be reloaded on the next
request.
The most common usage pattern for this method is probably in a
migration, when just after creating a table you want to populate it
with some default values
You're db:migrate task changes the column information in the users table, but it looks like these changes are not properly written to the db/schema.rb file until the rake cammand finishes. Your db:seed task looks at db/schema.rb to see if the columns it needs exists, but this shows the schema as it was before the db:migrate unless you put it in a separate rake command or you run reset_column_information() before it.

How to check SQL commands executed using rake in Ruby on Rails

I want to count the votes a user has given to an article and save it somewhere.
I want to check all the SQL INSERT or CREATE lines executed when we do something like:
>$ bundle exec rake db:reset
>$ bundle exec rake db:seed
>$ bundle exec rake test:prepare
Is there a way I can check the SQL commands in Ruby on Rails?
You can add a custom Rake task and use it whenever you need to log the SQL output:
task log: :environment do
ActiveRecord::Base.logger = Logger.new(STDOUT)
end
Now you can run:
bundle exec rake log db:reset
bundle exec rake log db:seed
bundle exec rake log test:prepare
See "Is it possible to output the SQL change scripts that 'rake db:migrate' produces?"

I get a "database does not exist error" when running unit tests

Every time I run the command:
rake test test/models/post_test.rb test_the_truth
I get the following error:
`initialize': FATAL: database "knome_test" does not exist (PG::Error).
Can someone explain and help me to debug it?
It sounds like you have not created the database.
Try running the following to create, migrate, then prepare your test database.
rake db:create
rake db:migrate
rake db:test:prepare
You have create a new database in postgres and update database.yml "test" section with that db_name, username & password. The same way you have done in "development" section.

How to Send RubyMine Notifications to Growl/NotifyOSD?

I want just send command-line notifications (like "notify-send 'done' ") after some long rake tasks starting from Rubymine. Maybe I need some wrapper for rake? Thanks for help!
I don't know about RubyMine but this should do in Terminal:
rake db:setup && growlnotify -m 'Finished DB setup'
Add terminal-notifier gem to Gemfile
Add few lines to Project/bin/rake file: https://gist.github.com/skydan/f333cd1fc2900f4b4ed7

jruby pass jvm arguments to rake task

How do i pass jvm arguments like Xmx to a rake task in jruby?
Am using rvm and running the rake task "rake db:migrate".
Thanks!
Rather that put the entire path, if jruby is already the Ruby you're using (for example, with rvm) such that just typing rake would be using jruby, you can use a double dash to send the arguments to the jvm.
Examples:
bundle exec rake -- -J-Xmx1024m (if you're using bundler)
rake -- -J-Xmx1024m
Found it!
jruby -J-Xmx2048m -S /home/prats/.rvm/gems/jruby-1.6.1#myapp/bin/rake db:migrate