Skip to content

Instantly share code, notes, and snippets.

View joshuaclayton's full-sized avatar

Josh Clayton joshuaclayton

View GitHub Profile
$("form").each(function(idx, form) {
var onsubmit = $(form).attr("onsubmit");
if(typeof(onsubmit) !== undefined) {
$(form).removeAttr("onsubmit"); // this properly removes the attribute; nothing within this is triggered
$(form).submit(function() {
alert("submitted!"); // this doesn't get called
});
}
});
$("form").each(function(idx, form) {
console.log("looping through forms");
var submitFunction = $(form).attr("onsubmit");
if(typeof(submitFunction) !== undefined) {
delete(form.onsubmit);
var anonymousSubmit = new Function(submitFunction);
$(form).submit(anonymousSubmit);
}
gem "thoughtbot-clearance", :version => "0.6.3", :source => "http://gems.github.com", :lib => "clearance"
gem "aslakhellesoy-cucumber", :version => "0.3.0", :source => "http://gems.github.com", :lib => "cucumber"
gem "giraffesoft-resource_controller", :version => "0.6.1", :source => "http://gems.github.com", :lib => "resource_controller"
generate "cucumber"
generate "clearance"
generate "clearance_features"
source ~/.git-completion.sh
source ~/.bash_colors.sh
git_prompt_info() {
git_branch_prompt=$(__git_ps1 " | %s")
if [ -n "$git_branch_prompt" ]; then
if [ "changed" = $(git_status) ]; then
branch_prompt=$(__git_ps1 "${ESC}[${BRIGHT};${FG_RED}m %s")
elif [ "pending" = $(git_status) ]; then
branch_prompt=$(__git_ps1 "${ESC}[${BRIGHT};${FG_YELLOW}m %s")
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
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
# 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
class FilterableEnumerable
def initialize(original)
@original = original
end
def ==(value)
@original.select { |v| v == value }
end
def method_missing(sym, *args, &block)
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}'"
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}'"
}}