Skip to content

Instantly share code, notes, and snippets.

From:
Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
field_labeled(label).should be_checked
end
Then /^the "([^\"]*)" checkbox should not be checked$/ do |label|
field_labeled(label).should_not be_checked
end
Before:
<ul class="actions">
<li><%= link_to content_tag(:span, 'Edit group'), edit_group_path(@group), :class => 'btn' if current_user.group_admin?(@group) %></li>
<li><%= link_to content_tag(:span, 'Start a new discussion'), new_group_discussion_path(@group), :class => 'btn' if @group.public? || @group.members.include?(current_user) %></li>
<li><%= link_to content_tag(:span, 'Start a shared document'), new_group_shared_document_path(@group), :class => 'btn' %></li>
<li><%= link_to content_tag(:span, 'Invite users to join this group'), new_group_invitation_path(@group), :class => 'btn' if current_user.andand.group_admin?(@group) %></li>
</ul>
After:
attachments: parent_id, asset_id
domain_names: organisation_id
event_memberships: user_id, event_id
events: editor_id
group_actions: user_id, group_id
groups: user_id
icons: parent_id
invitations: sender_id
legacy_actions: item_upon_id
news_items: author_id
#compdef gem
# My first zsh completion function, for the gem command. It lets you type 'gem <tab>' to complete gem commands
# (including installed ones) and for some commands (currently just open and update) allows you to complete gem
# names as well. The implementation isn't ideal, so I'd appreciate advice on how I can improve it, particularly
# the 'caching' of the gem_commands and installed_gems.
_gem_commands () {
if [[ -z $gem_commands ]] ; then
gem_commands=$(gem help commands | grep '^ [a-z]' | cut -d " " -f 5)
# 9 out of 10 microbenchmarks agree: implicit return smokes explicit return
require 'benchmark'
def explicit
return 1
end
def implicit
1
end
class Account < ActiveRecord::Base
end
# Is this crazy?
class AccountRole < ActiveRecord::Base
belongs_to :account
belongs_to :target, :polymorphic => true
validates_presence_of :role
end
class Project < ActiveRecord::Base
remove_constant(:JavaScriptHelper)
Kernel.expects(:require).with('action_view/helpers/javascript_helper')
JavaScriptHelper
module ColumnReader
def column_reader(column_name, options = {})
name = options.delete(:as) || column_name.to_s.pluralize
behaviour_module = column_reader_module(column_name)
column = columns_hash[column_name.to_s]
behaviour_module.module_eval %{
def #{name}(options = {})
connection.select_all(construct_finder_sql(options.merge(:select => '#{column_name}'))).collect do |value|
v = value.values.first
# I hear that aliasing lambda is bad, but this is
# much more readable...
alias :this_block :lambda
this_block{ @this.destroy }.should change(Thing, :count).by(-1)
# (tomafro) I've done this for ages, only using doing rather than this_block:
alias :doing, :lambda