开发者

how to test ruby scripts, in rails app

开发者 https://www.devze.com 2023-02-16 21:21 出处:网络
I got some cron jobs that i wanna test, where should i out them, how can i run them with rails com开发者_JAVA百科mands and if the got some dependencies like files and stuff how can i load their fixtur

I got some cron jobs that i wanna test, where should i out them, how can i run them with rails com开发者_JAVA百科mands and if the got some dependencies like files and stuff how can i load their fixture?

to be more concrete lets say i got a rb file thats reads a file from a the app folder, do some parsing, and writes stuff to db.

where to put the test and how to connect it with rails?


My method is to create a folder called app/jobs, then name the classes in the folder accordingly. The jobs are then called using script/rails runner. The runner interface loads rails and you have access to all of your models.

class SomeOddJob
  def run
    #do something
  end
end

from your cron job you'd run the job like this (in production mode):

0 5 * * * /path/to/script/rails runner -e production "SomeOddJob.run"

0

精彩评论

暂无评论...
验证码 换一张
取 消