rake

Generate only tests from existing model / controllers

血红的双手。 提交于 2019-12-20 17:35:21
问题 I have a Rails3 app that is based on someone else's work. For some reason they decided not to supply the tests with the app, which I am finding frustrating. What I want to be able to do is scaffold the tests for all the existing controllers and models so I can get a head start on creating the tests myself in test::unit. I don't want to recreate the models or controllers, just create the tests. I am new to Rails, and have hunted about for the rake command that might do this, but all with no

Alias of task name in Rake

喜夏-厌秋 提交于 2019-12-20 17:24:55
问题 When I need to alias some task's name, how should I do it? For example, how do I turn the task name: rake db:table rake db:create rake db:schema rake db:migration to: rake db:t rake db:c rake db:s rake db:m Editing after getting the answer: def alias_task(tasks) tasks.each do |new_name, old_name| task new_name, [*Rake.application[old_name].arg_names] => [old_name] end end alias_task [ [:ds, :db_schema], [:dc, :db_create], [:dr, :db_remove] ] 回答1: Why do you need an alias? You may introduce a

Why are there no Makefiles for automation in Python projects?

孤街醉人 提交于 2019-12-20 16:17:08
问题 As a long time Python programmer, I wonder, if a central aspect of Python culture eluded me a long time: What do we do instead of Makefiles? Most ruby-projects I've seen (not just rails) use Rake , shortly after node.js became popular, there was cake . In many other (compiled and non-compiled) languages there are classic Make files. But in Python, no one seems to need such infrastructure. I randomly picked Python projects on GitHub, and they had no automation, besides the installation,

rake db:create fails, authentication problem with postgresql 8.4

浪尽此生 提交于 2019-12-20 14:22:42
问题 first things first, please excuse my utter noobness. I really tried to find a solution out there, but now i'm stuck and completely clueless. i'm trying to deploy a rails 3 app on a distant server ; when developping on my local VM, no problem showed. But now, when i try to run rake db:create it fails, with error (here translated, since i'm french): FATAL : password authentication failed for user <<mylogin>> here's my database.yml : login: &login adapter: postgresql username: mylogin password:

Update db/migrate after manually updating models?

一笑奈何 提交于 2019-12-20 10:47:09
问题 For example i have this model: class Product < ActiveRecord::Base attr_accessible :name, :order end Then when i did rake db:migrate it created this db/migrate/20120825132038_create_products.rb : class CreateProducts < ActiveRecord::Migration def change create_table :products do |t| t.integer :order t.string :name t.timestamps end end end But it all happend cuz i used rails generate Product order:integer name:string Now after i go to Product model and changes it manually to: class Product <

How to call Rake tasks that are defined in the standard Rakefile from an other Ruby script?

感情迁移 提交于 2019-12-20 10:45:11
问题 Is it possible to call a task which is defined in a Rakefile - not in somefile.rake - from an other Ruby script? I was hoping that creating a new Rake::Application would automatically load the Rakefile from the same directory, but it seems that this is not the case. Here is what I came up with so far: $LOAD_PATH.unshift File.dirname(__FILE__) require 'rake' require 'pp' rake = Rake::Application.new rake[:hello].invoke Executing this code results in the following: /opt/ruby/1.9.2-p180/lib/ruby

How do I use helpers in rake?

让人想犯罪 __ 提交于 2019-12-20 10:16:50
问题 Can I use helper methods in rake? 回答1: Yes, you can. You simply need to require the helper file and then include that helper inside your rake file (which actually a helper is a mixin that we can include). For example, here I have an application_helper file inside app/helpers directory that contains this: module ApplicationHelper def hi "hi" end end so here is my rake file's content: require "#{Rails.root}/app/helpers/application_helper" include ApplicationHelper namespace :help do task :hi do

How do I pass arguments from the parent task to the child task in Rake?

懵懂的女人 提交于 2019-12-20 09:59:49
问题 I am writing a Rake script which consists of tasks with arguments. I figured out how to pass arguments and how to make a task dependent on other tasks. task :parent, [:parent_argument1, :parent_argument2, :parent_argument3] => [:child1, :child2] do # Perform Parent Task Functionalities end task :child1, [:child1_argument1, :child1_argument2] do |t, args| # Perform Child1 Task Functionalities end task :child2, [:child2_argument1, :child2_argument2] do |t, args| # Perform Child2 Task

How do I make a Rake Task run after all other tasks? (i.e. a Rake AfterBuild task)

眉间皱痕 提交于 2019-12-20 09:54:29
问题 I'm new to Rake and using it to build .net projects. What I'm interested in is having a Summary task that prints out a summary of what has been done. I want this task to always be called, no matter what tasks rake was invoked with. Is there an easy way to accomplish this? Thanks Update on the question, responding to Patrick's answer what I want is the after task to run once after all other tasks, so the output I want is: task :test1 do puts 'test1' end task :test2 do puts 'test2' end Rake:

def block in rake task

别说谁变了你拦得住时间么 提交于 2019-12-20 09:32:46
问题 I got undefined local variable or method 'address_geo' for main:Object with the following rake task. What's the problem with it? include Geokit::Geocoders namespace :geocode do desc "Geocode to get latitude, longitude and address" task :all => :environment do @spot = Spot.find(:first) if @spot.latitude.blank? && !@spot.address.blank? puts address_geo end def address_geo arr = [] arr << address if @spot.address arr << city if @spot.city arr << country if @spot.country arr.reject{|y|y==""}.join