Skip to content

Instantly share code, notes, and snippets.

Avatar

James Bebbington jamesbebbington

View GitHub Profile
View logged_in_as.rb
# Doesn't work when user arg is a reference to variable in an outer context
class Test::Unit::TestCase
def self.logged_in_as(user, &block)
context "logged in as #{user}" do
setup do
UserSession.create(user)
end
merge_block(&block) if block_given?
View should_accept_nested_attributes_for.rb
class Test::Unit::TestCase
# Assert that the model accepts nested attributes for the given +associations+
#
# Example:
# should_accept_nested_attributes_for :orders
#
def self.should_accept_nested_attributes_for(*associations)
associations.each do |association|
should "accept nested attributes for #{association}" do
View link_to.rb
View authlogic-2.1.3 test failure.txt
$ rake
(in /<snip>/authlogic-2.1.3)
All dependencies seem to be installed.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I"lib:test" "/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/acts_as_authentic_test/base_test.rb" "test/acts_as_authentic_test/email_test.rb" "test/acts_as_authentic_test/logged_in_status_test.rb" "test/acts_as_authentic_test/login_test.rb" "test/acts_as_authentic_test/magic_columns_test.rb" "test/acts_as_authentic_test/password_test.rb" "test/acts_as_authentic_test/perishable_token_test.rb" "test/acts_as_authentic_test/persistence_token_test.rb" "test/acts_as_authentic_test/restful_authentication_test.rb" "test/acts_as_authentic_test/session_maintenance_test.rb" "test/acts_as_authentic_test/single_access_test.rb" "test/authenticates_many_test.rb" "test/crypto_provider_test/aes256_test.rb" "test/crypto_provider_test/bcrypt_test.rb" "test/crypto_provider_test/sha1_test.rb" "test/crypto_provider_test/sha256_test.rb" "test/crypto_provider_test/
View authlogic-2.1.1 -> authlogic-2.1.3 test failures.rb
require 'test_helper'
class UserSessionTest < ActiveSupport::TestCase
setup :activate_authlogic
context "A Participant" do
setup do
@participant = Factory(:participant)
assert @participant.password.present?
end
View hoptoad gem generator failure.txt
$ script/generate hoptoad --api-key 9<snip>4
/<snip>/vendor/gems/thoughtbot-paperclip-2.3.1/lib/paperclip.rb:47: warning: already initialized constant VERSION
** Erubis 2.6.5
exists lib/tasks
create lib/tasks/hoptoad_notifier_tasks.rake
insert
Dir[File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'hoptoad_notifier-*')].each do |vendored_notifier|
$: << File.join(vendored_notifier, 'lib')
end
View i18n_controller.rb
class I18nController < ApplicationController
caches_page :show
# Renders HTTP cacheable JSON encoded dictionary of translation strings for requested locale and currently selected locale
def show
@locale = params[:locale].to_sym
raise ActiveRecord::RecordNotFound unless I18n.selectable_locales.include?(@locale)
respond_to do |format|
format.js do
@strings = I18n.t('javascript', :locale => @locale)
@jamesbebbington
jamesbebbington / application_controller.rb
Created Apr 13, 2010
Rendering custom dynamic http error pages in a Rails app
View application_controller.rb
class ApplicationController < ActionController::Base
# alias_method :rescue_action_locally, :rescue_action_in_public # Uncomment to test in development environment.
def render_optional_error_file(status_code)
request.format = 'html' # Force html format so that requests to the likes of /foo/bar.png result in an HTML error page.
render :template => 'errors/http_error', :status => status_code, :locals => {:status_code => status_code}
end
end
View active_record_extensions.rb
module ActiveRecordExtensions
module ClassExtensions
# Returns +Array+ of all +ActiveRecord+ model classes
def models
Dir.glob(Rails.root.join('app', 'models', '**', '*rb')).each do |model|
ActiveSupport::Dependencies::Loadable.require_or_load model
end
Object.subclasses_of ActiveRecord::Base
View identify_mimetypes_middleware.rb
# Adobe Flash fails to pass the correct mime-type when POSTing files.
# This piece of middleware is used to correctify the matter
#
# N.B. Requires `file` command so will probably only work on POSIX systems
#
# To use add this to an initializer:
# ActionController::Dispatcher.middleware.insert_after(ActionController::ParamsParser, IdentifyMimetypesMiddleware, /^(Adobe|Shockwave) Flash/)
require 'rack/utils'