Resque hates kaminari dsl method paginates_per - ruby-on-rails-3

So I'm converting my Admin mailers to use Resque and execute in the background.
When I ran:
rake resque:work QUEUE='*' --trace
I get this:
$ rake resque:work QUEUE='*' --trace (in /my/directory)
** Invoke resque:work (first_time)
** Invoke resque:preload (first_time)
** Execute resque:preload rake aborted! undefined method `paginates_per' for #<Class:0x000000045ba1b8>
which traces back to my Micropost model that default to 10 micropost per page using kaminari's dsl method paginates_per:
class Micropost < ActiveRecord::Base
.
.
.
paginates_per 10
How do I get rake to stop puking without moving the DSL method?

Related

How to call a rake task in rspec

I am trying to invoke a rake task in in my rspec.
require "rake"
rake = Rake::Application.new
Rake.application = rake
rake.init
rake.load_rakefile
rake['rake my:task'].invoke
But i am getting error
Failure/Error: rake['rake db:migrate'].invoke
RuntimeError:
Don't know how to build task 'rake db:migrate'
Does anyone have a idea how we can invoke rake task in rspec code.
Any help would be highly appreciated.
Small namespacing issue, the task is db:migrate not rake db:migrate like the command line usage.
So changing it to this should help:
rake['db:migrate'].invoke
A simpler solution for Rails with Rspec :
In your spec_helper (or rails_helper for newer versions of rspec-rails) :
require "rake"
Rails.application.load_tasks
Then when you want to invoke your task you can do the following :
Rake::Task['my:task'].invoke
To pass in the arguments in square brackets to invoke:
rake sim:manual_review_referral_program[3,4]
becomes:
rake['sim:manual_review_referral_program'].invoke(3,4)
If your args are in an array, you can do the following:
args = [3,4]
rake['sim:manual_review_referral_program'].invoke(*args)
More info at this StackOverflow question: How to run Rake tasks from within Rake tasks?.

Cap deploy doesn't work all the sudden; something to do with FactoryGirl and assets

I've been cap deploying my app all throughout it development, and this last time I tried to deploy it, it didn't work. Here's what happened:
* executing `deploy:assets:precompile'
* executing "cd /var/www/oneteam/releases/20121006153136 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
servers: ["electricsasquatch.com"]
[electricsasquatch.com] executing command
** [out :: electricsasquatch.com] rake aborted!
** [out :: electricsasquatch.com] uninitialized constant OneTeam::Application::FactoryGirl
** [out :: electricsasquatch.com]
** [out :: electricsasquatch.com] (See full trace by running task with --trace)
It looks like it failed on the deploy:assets:precompile command. I don't get why that command would have tried to do anything with FactoryGirl, though. Any ideas?
It is not that something is wrong with deploy:assets:precompile task, but something is wrong with rake task that is using FactoryGirl. Even if you place a syntax error let us say in lib/tasks/first.rake and you execute task from lib/tasks/second.rake for instance rake second the rake will scream with rake aborted!. Even rake -T will not work. So there is rake task that is trying to use FactoryGirl but FactoryGirl is not included.
I had this in config/application.rb:
FactoryGirl.define do
sequence(:random_string) { |s| ('a'..'z').to_a.shuffle[0, 30].join }
end
I changed it to this:
if Rails.env != "production"
FactoryGirl.define do
sequence(:random_string) { |s| ('a'..'z').to_a.shuffle[0, 30].join }
end
end
The problem went away.

RoR: why doesn't rake db:migrate output anything?

I added add_column :microposts, :type, :string to one of my db migrations (not the most recent one if that matters). and also ran rake db:reset. So I have definitely made changes. But now if I run rake db:migrate or bundle exec rake db:migrate, it doesn't output anything. If I run trace...
alex#alex-ThinkPad-T410:~/rails_projects/final2$ rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:migrate
** Invoke db:_dump (first_time)
** Execute db:_dump
** Invoke db:schema:dump (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:schema:dump
You wrote:
I added add_column :microposts, :type, :string to one of my db
migrations (not the most recent one if that matters).
This suspiciously sounds, as if you just added the text into the migration file. That won't work. The migration state machine doesnt notice changes in the actual text files. Please check
rake db:migrate:status
You should instead create a new migration
rails g migration AddTypeToMicropost type:string
and then run rake again

CScript Error: Execution of the Windows Script Host failed - Rails rake assets:precompile

I am deploying rails project on heroku. When I use rake assets:precompile it gives following error -
rake aborted!
CScript Error: Execution of the Windows Script Host failed. (0x800A0007)
(in c:/Rails Projects/sheets_vip_rails/app/assets/javascripts/application.js)
Tasks: TOP => assets:precompile:primary
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [c:/Ruby193/bin/ruby.exe c:/Ruby193/bin/rak...]
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
Thanks for any help.

Migration silent error

When I run rake db:migrate, I don't get a response.
Doing a trace, I get the following but I am not sure how to interpret it:
$ rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
** Invoke db:schema:dump (first_time)
** Invoke environment
** Execute db:schema:dump
I am running rails 3.0.10.
As coreyword suggested, perhaps there are no new migrations to run.
The rake db:migrate command will exit silently when there's nothing (new) to do.