Skip to content

Instantly share code, notes, and snippets.

View joshuaclayton's full-sized avatar

Josh Clayton joshuaclayton

View GitHub Profile
base.send :include, AASM
base.aasm_column :status
base.aasm_initial_state :drafted
base.aasm_state :drafted
base.aasm_state :submitted
base.aasm_state :booked
base.aasm_state :lost
base.aasm_state :cancelled
scope = LoggedException
scope = scope.search(params[:query]) unless params[:query].blank?
scope = scope.days_old(params[:date_ranges_filter]) unless params[:date_ranges_filter].blank?
scope = scope.by_exception_class(params[:exception_names_filter]) unless params[:exception_names_filter].blank?
scope = scope.by_controller_and_action(*params[:controller_actions_filter].split('/').collect(&:downcase)) unless params[:controller_actions_filter].blank?
scope = scope.sorted
require 'test/unit'
require 'test/unit/ui/console/testrunner'
# cute.
module Color
COLORS = { :clear => 0, :red => 31, :green => 32, :yellow => 33 }
def self.method_missing(color_name, *args)
color(color_name) + args.first + color(:clear)
end
def self.color(color)
(function($) {
var dirtyForm = {
settings: {
changedClassName: "changed",
checkableSelector: ":radio, :checkbox",
eventName: "change.dirty_form",
eventBubbling: {
preventDefault: function(){ return false; },
stopPropagation: function(){ return false; },
bubbles: true,
named_scope :on, lambda {|klass| {
:joins => "INNER JOIN #{Tagging.quoted_table_name} ON #{Tagging.quoted_table_name}.tag_id = #{Tag.quoted_table_name}.id " + \
"INNER JOIN #{klass.quoted_table_name} ON #{klass.quoted_table_name}.id = #{Tagging.quoted_table_name}.taggable_id " + \
"AND #{Tagging.quoted_table_name}.taggable_type = '#{klass.to_s}'"
}}
Tag.class_eval do
default_scope :joins => :taggings
named_scope :popular, lambda {{
:select => "#{Tag.quoted_table_name}.*, COUNT(*) AS popularity",
:group => "#{Tagging.quoted_table_name}.tag_id",
:order => "popularity DESC"
}}
named_scope :on, lambda {|klass| {
:joins => "INNER JOIN #{klass.quoted_table_name} ON #{klass.quoted_table_name}.id = #{Tagging.quoted_table_name}.taggable_id " + \
"AND #{Tagging.quoted_table_name}.taggable_type = '#{klass.to_s}'"
class FilterableEnumerable
def initialize(original)
@original = original
end
def ==(value)
@original.select { |v| v == value }
end
def method_missing(sym, *args, &block)
# Notes: You NEED to type 'y' and then press enter a few seconds into
# generating the clearance features (to overwrite the features/support/paths.rb).
# no prompt shows up by default.
#
# A few features fail initially; I'm only concerned with the one re: logging
# out (it's looking for a flash that doesn't, for some reason, persist). The
# checking for text with contains can be switched to check for a regex of the text.
# build session store
initializer "session_store.rb", <<-END
When /^I attach the file "([^\"]*)" to "([^\"]*)"$/ do |path, field|
path = File.join(RAILS_ROOT, path)
webrat.simulate do
attach_file(field, path)
end
webrat.automate do
# fake the upload
end
end
DULL=0
BRIGHT=1
FG_BLACK=30
FG_RED=31
FG_GREEN=32
FG_YELLOW=33
FG_BLUE=34
FG_VIOLET=35
FG_CYAN=36