This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ENV["RAILS_ENV"] = "test" | |
require File.expand_path('../../config/environment', __FILE__) | |
require File.dirname(__FILE__) + '/blueprints' | |
require 'faker' | |
require 'rails/test_help' | |
require 'minitest/autorun' | |
require 'minitest/pride' | |
class MiniTest::Unit::TestCase | |
include MiniTest::ActiveRecordAssertions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MiniTest | |
module Assertions | |
module ActiveRecord | |
# assert_association User, :has_many, :editables, :polymorphic => true | |
# | |
def assert_association(clazz, association, associate, options={}) | |
reflected_assoc = clazz.reflect_on_association(associate) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def to_bool | |
return true if self == true || self =~ (/(true|t|yes|y|1)$/i) | |
return false if self == false || self.blank? || self =~ (/(false|f|no|n|0)$/i) | |
raise ArgumentError.new("invalid value for Boolean: \"#{self}\"") | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/application.rb | |
module MyApp | |
class Application < Rails::Application | |
... other configs | |
config.secondary_database_url = ENV['SECONDARY_DB_URL'] | |
end | |
end | |
We may want to override this in development / test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Place me in config/application.rb or in your development file | |
if Rails.env.development? | |
class Hook | |
def self.delivering_email(message) | |
message.to = "\"#{message.to.first}\" <[email protected]>" | |
message.cc = nil if !message.cc.nil? | |
message.bcc = nil if !message.bcc.nil? | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'will_paginate' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -u 'USER:PASS' https://api.github.com/user/repos -d '{"name":"REPO"}' | |
git remote add origin [email protected]:USER/REPO.git | |
git push origin master |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
First put an empty, placeholder div in the main response | |
<div id="pink-dancing-elephants"></div> | |
and then add a little jQuery to the page | |
$.ajax({ | |
url: "/elephants/dancing", | |
cache: false, | |
success: function(html){ | |
$("#pink-dancing-elephants").append(html); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Controller | |
include LazyLoad | |
def show | |
@model = Model.find(...) | |
respond_to do |format| | |
format.html do | |
@html_specific_data = Model.find(...) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :db do | |
desc "Handle orphans" | |
task :handle_orphans => :environment do | |
Dir[Rails.root + "app/models/**/*.rb"].each do |path| | |
require path | |
end | |
ActiveRecord::Base.send(:descendants).each do |model| | |
model.reflections.each do |association_name, reflection| | |
if reflection.macro == :belongs_to | |
model.all.each do |model_instance| |