This file contains 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
# In application.rb | |
config.autoload_paths += %W(#{config.root}/lib/oauth_providers) | |
# In lib I have a directory (oauth_providers) with a file named oauth_provider.rb: | |
# lib/oauth_providers/oauth_provider.rb | |
module OauthProviders | |
class OauthProvider | |
def self.instantiate(name) | |
klass = "OauthProviders::#{name}".constantize | |
klass.new |
This file contains 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
# Given a controller that looks like this | |
class ModelsController < ApplicationController | |
load_and_authorize_resource #CanCan | |
def show | |
if stale? @model | |
respond_to do |format| | |
format.json do | |
@model | |
end |
This file contains 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
context "template name is substring of actual rendered template" do | |
it "will pass" do | |
get :hello_world | |
# The following line will pass, even though the template rendered is actually "accounts/hello_world" | |
response.should render_template "accounts/hello" | |
end | |
end |
This file contains 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
# In an initializer under config/initializers | |
[OtherPerson, OtherGroup].each do |model| | |
model.establish_connection(other_database[Rails.env].symbolize_keys!) | |
end | |
# Model definitions | |
class OtherGroup < ActiveRecord::Base | |
self.table_name = 'groups' | |
has_many :other_persons, :class_name => "OtherPerson", :foreign_key => 'group_id' | |
end |
This file contains 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
quietly do | |
SomeModuleOrClass.send(:remove_const, :SOME_CONSTANT) | |
SomeModuleOrClass.send(:const_set, :SOME_CONSTANT, "new constant value") | |
end |
This file contains 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
# Calling #to_hash on the Savon response in earlier version of Savon (0.8.6) return namespace keys formatted | |
# as such: :type, :ns14, :xsi. But in Savon 1.0.0, #to_hash returns namespace keys like :"@xsi:type", | |
# :"@xmlns:ns14", and :"@xmlns:xsi". This broke some parsing logic we had set up for the hashed Savon response. | |
# To change the format of these tags (or any tag, for that matter) in the hashed response, | |
# you can configure Nori like so: | |
Nori.configure do |config| | |
config.convert_tags_to do |tag| | |
converted_tag = tag[0] == "@" ? (tag.split(":")[1] || tag[1..-1]) : tag |