Skip to content

Instantly share code, notes, and snippets.

View kyamaguchi's full-sized avatar

kyamaguchi kyamaguchi

View GitHub Profile
# Show progress on rake task
def progress(char = '.')
STDOUT.write char
STDOUT.flush
end
ActiveRecord::Migration.say_with_time "Something" do
# 10MB毎に10ファイルをローテートする。
config.logger = Logger.new(config.log_path, 10, 10.megabytes)
@kyamaguchi
kyamaguchi / bundler_for_rails2.diff
Created October 31, 2011 17:16
Bundler for Rails 2.3.X
diff --git a/config/boot.rb b/config/boot.rb
index dd5e3b6..9ee835a 100644
--- a/config/boot.rb
+++ b/config/boot.rb
@@ -106,5 +106,19 @@ module Rails
end
end
+class Rails::Boot
+ def run
@kyamaguchi
kyamaguchi / confirmation_in_test
Created November 30, 2011 07:56
Confirmation in integration test
# selenium-webdriver (2.12.2) (with rails3)
def assert_confirmation(message, choice = 'ok')
if selenium?
assert_equal message, page.driver.browser.switch_to.alert.text
if choice == 'ok'
page.driver.browser.switch_to.alert.accept
elsif choice == 'cancel'
page.driver.browser.switch_to.alert.dismiss
end
@kyamaguchi
kyamaguchi / bindaddress.rb
Created May 22, 2012 02:38
Rspec webrick
# spec/support/bindaddress.rb
# Equivalent to $ rails server -b 127.0.0.1
require 'webrick'
module Rack
module Handler
class WEBrick
def self.run(app, options={})
options[:BindAddress] = '127.0.0.1'
@kyamaguchi
kyamaguchi / selenium_chromedriver.rb
Created May 22, 2012 02:40
RSpec Selenium Chrome
# spec/support/selenium_chromedriver.rb
Capybara.register_driver :selenium do |app|
# http://code.google.com/p/chromedriver/downloads/list
# sudo mv ~/Downloads/chromedriver /usr/bin/
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
@kyamaguchi
kyamaguchi / detect_translation_missing.rb
Created May 22, 2012 02:41
RSpec TranslationMissingDetector
# spec/support/detect_translation_missing.rb
module TranslationMissingDetector
module Capybara::Node::Finders
alias_method :find_original, :find
def find(*args)
begin
m = session.body.match(/translation[_ ]missing[^<]+/)
puts ["="*80, m[0], '', caller].join("\n")+"\n\n" if m
# Could be placed in spec_helper.rb
# Requiring foo.rake in this example.
def run_foo_bar(arg)
require 'rake'
@rake = Rake::Application.new
Rake.application = @rake
Rake.application.rake_require "lib/tasks/foo"
Rake::Task.define_task(:environment)
silence do
@kyamaguchi
kyamaguchi / hash_deep_values.rb
Created May 22, 2012 04:58
Collect values from deep hash
# http://www.ruby-doc.org/core-1.9.3/Hash.html#method-i-values
# http://rxr.whitequark.org/rubinius/source/kernel/common/hash18.rb
class Hash
def deep_values
ary = []
each_value do |value|
if value.is_a? Hash
ary += value.deep_values
elsif value.is_a? Array