Skip to content

Instantly share code, notes, and snippets.

View Bill's full-sized avatar

Bill Burcham Bill

View GitHub Profile
describe 'authenticated principal' do
before(:each) do
mock_valid_authentication
end
it 'should start with a new User object' do
get 'new'
assigns[:user].nil?.should == false
end
class FooController < ApplicationController
before_filter :include_scripts
protected
def include_scripts
include_tags = render_to_string( :partial => 'editor/head_elements' )
# um, see e.g. layout.rb line 254 in Rails 2.1.0. content_for variables have the form @content_for_<name>
@template.instance_variable_set("@content_for_head", include_tags )
# by Bill Burcham http://thoughtpropulsion.com
# do what you want with this
# Add :host variable extraction to Dan Webb's request_routing plugin
module Propel
module MultiDomainRouting
# include this module in RouteSet after request_routing plugin is loaded
module ExtractHostParameter
def self.included( other)
other.alias_method_chain :extract_request_environment, :host
@Bill
Bill / routes.rb
Created September 19, 2008 22:52
ActionController::Routing::Routes.draw do |map|
map.with_options :conditions => { :host => /^blog\.foo.com$/} do | blog |
blog.connect '', :controller => 'blog', :action => 'index', :conditions => {:method => :get}
blog.connect '/post/:id', :controller=>'post', :action=>'show', :conditions => {:method => :get}
... more blog stuff
end
map.with_options :conditions => { :host => /^foo.com$/} do | foo |
foo.connect '', :controller => 'foo_home', :action => 'index', :conditions => {:method => :get}
# This is an attempt at an improved version of params_for or rspec rails. It is meant to
# support recognition of paths when the Rails environment has been extended via patches like these:
# http://weblog.jamisbuck.org/2006/10/26/monkey-patching-rails-extending-routes-2
# http://svn.danwebb.net/external/rails/plugins/request_routing/trunk/README
# So instead of route :conditions having only :method, they may now have other data such as :domain
def recognize_path( path, options)
if options[:host].kind_of?( Array )
result = options[:host].collect{ | h | route( path, options.merge( :host => h) ) }
else
begin
<dl id='comments-block'>
<dt class='comment-author openid-comment-icon' id='c5069974981380830367'>
<a name='c5069974981380830367'></a>
<a href='http://meme-rocket.com/' rel='nofollow'>Bill</a>
said...
</dt>
<dd class='comment-body'>
<p>testing an OpenID comment</p>
</dd>
===================================================================
--- vendor/plugins/seed-fu/lib/seed-fu.rb (revision 3419)
+++ vendor/plugins/seed-fu/lib/seed-fu.rb (working copy)
@@ -20,7 +20,7 @@
raise "You must set at least one constraint." if constraints.empty?
@constraints = []
constraints.each do |constraint|
- raise "Your constraint `#{constraint}` is not a column in #{@model_class}. Valid columns are `#{@model_class.column_names.join("`, `")}`." unless @model_class.column_names.include?(constraint.to_s)
+ raise "Your constraint `#{constraint}` is not a column in #{@model_class}. Valid columns are `#{@model_class.column_names.join("`, `")}`." unless @model_class.column_names.include?(constraint.to_s) || association = @model_class.reflect_on_association(constraint)
@constraints << constraint.to_sym
# BAD:
foo.bar = 25
foo.biz = 'Hello World'
foo.bazzle = 42
# GOOD:
foo.bar = 25
foo.biz = 'Hello World'
foo.bazzle = 42
module Spec
module Rails
class ControllerContext < Rails::Context
module ContextEvalInstanceMethods
def setup_extra
(class << @controller; self; end).class_eval do
include ControllerInstanceMethods
end
@controller.integrate_views! if @integrate_views
@controller.session = session
# the approved way to add methods to example groups in rspec
# from David Chelimsky's comment here http://www.benmabey.com/2008/06/08/writing-macros-in-rspec/
Spec::Runner.configure do |config|
config.include(AssignMacro, :type => :controllers)
end