Skip to content

Instantly share code, notes, and snippets.

View bjensen's full-sized avatar

Brian Jensen bjensen

View GitHub Profile
context "failure due to record invalid" do
before(:each) do
e = mock("errors", :null_object => true)
e.stub!(:full_messages).and_return([])
@obj.stub!(:errors).and_return(e)
@obj.stub!('update_attributes!').and_raise(ActiveRecord::RecordInvalid.new(@obj))
put :update, { :id => @obj.id, at_name => @invalid_update }
end
module OnlineUsers
def count_online_users
User.count(:conditions => ["last_request_at > ?", 30.minutes.ago])
end
end
@bjensen
bjensen / boot.rb
Created February 1, 2010 23:15 — forked from eladmeidar/boot.rb
Bundler and rails 2.3.5
# The original post by Yehuda says that code should go under config/preinitializer.rb, which can work if you are not running under Passenger
# that doesn't really gives a shit yet about preinitializer.rb, so you need to put this code at the bottom of your config/boot.rb not that the # Rails.boot! line should already be in your boot.rb file, it's just here for a position reference.
require "#{File.dirname(__FILE__)}/../vendor/bundler_gems/environment"
class Rails::Boot
def run
load_initializer
extend_environment
class Ability
include CanCan::Ability
# alias_action :index, :show, :to => :read
# alias_action :new, :to => :create
# alias_action :edit, :to => :update
def initialize(user)
if user.role? :admin
can :manage, :all
def ticket_filter_links(status_name, user_id=nil)
if user_id.nil?
if status_name.downcase == 'closed'
content_tag(:li, link_to("All Closed Tickets", tickets_path + "?search[status_id_equals]=#{@closed_status.id}"))
else
content_tag(:li, link_to("All Active Tickets", tickets_path))
end
else
if status_name.downcase == 'closed'
content_tag(:li, link_to("My Closed Tickets", tickets_path + "?search[status_id_equals]=#{@closed_status.id}&search[owned_by_equals]=#{user_id}"))
# If your workers are inactive for a long period of time, they'll lose
# their MySQL connection.
#
# This hack ensures we re-connect whenever a connection is
# lost. Because, really. why not?
#
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar)
#
# From:
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/
#Keeps a list of registered names associated with classes at a "base" class
#Example:
#
# class Base
# extend Registerable
# end
#
# class Foo < Base
# register :foo
# end
$ git clone github:lenary/guides.git
Cloning into guides...
remote: Counting objects: 255, done.
remote: Compressing objects: 100% (216/216), done.
remote: Total 255 (delta 111), reused 163 (delta 35)
Receiving objects: 100% (255/255), 1.49 MiB | 564 KiB/s, done.
Resolving deltas: 100% (111/111), done.
$ cd guides
$ git remote -v
@bjensen
bjensen / hack.sh
Created March 31, 2012 11:09 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@bjensen
bjensen / bootstrap_breadcrumbs_builder.rb
Created April 16, 2012 17:51
How to make breadcrumbs_on_rails render a Bootstrap compatible breadcrumb navigation
# The BootstrapBreadcrumbsBuilder is a Bootstrap compatible breadcrumb builder.
# It provides basic functionalities to render a breadcrumb navigation according to Bootstrap's conventions.
#
# BootstrapBreadcrumbsBuilder accepts a limited set of options:
# * separator: what should be displayed as a separator between elements
#
# You can use it with the :builder option on render_breadcrumbs:
# <%= render_breadcrumbs :builder => ::BootstrapBreadcrumbsBuilder, :separator => "&raquo;" %>
#
# Note: You may need to adjust the autoload_paths in your config/application.rb file for rails to load this class: