Skip to content

Instantly share code, notes, and snippets.

@emyl
emyl / spec_helper.rb
Created November 21, 2012 10:26
Rspec matcher for equality without considering newlines
RSpec::Matchers.define :eq_in_one_line do |target|
match do |source|
source.gsub(/\n/, '').should eq target.gsub(/\n/, '')
end
end
@emyl
emyl / enumerable.rb
Created April 6, 2012 15:21
Iterate and returns the couple [previous || nil, current]
module Enumerable
def each_with_previous
self.inject(nil) { |pre, cur| yield pre, cur; cur }
self
end
end
@emyl
emyl / i18n.rake
Created March 13, 2012 21:37
Copy translations from simple backend (YAML) to Active Record
namespace :i18n do
desc "Copy translations from simple backend (YAML) to Active Record"
task :copy2ar => :environment do
unless I18n.backend.instance_of?(I18n::Backend::Simple)
I18n.backend = I18n::Backend::Simple.new
I18n.backend.load_translations
end
Translation.delete_all
I18n.available_locales.each do |loc|
@emyl
emyl / assets_helper.rb
Created March 6, 2012 17:03
Determine if asset pipeline is enabled, exiting gracefully if on Rails < 3.1
def assets?
begin
Rails.application.config.assets.enabled || false
rescue NoMethodError
false
end
end