Skip to content

Instantly share code, notes, and snippets.

View mgreenly's full-sized avatar

Michael Greenly mgreenly

View GitHub Profile
Given /^(?:|I )am on (.+)$/ do |page_name|
visit path_to(page_name)
selenium.wait_for_page_to_load(5)
end
When /^(?:|I )press "([^\"]*)"$/ do |button|
click_button(button)
selenium.wait_for_page_to_load(5)
end
Scenario: unsucessful login
Given "John Doe" is a registered user
And I am on the login page
When I fill in "email" with "John Doe's" user information
And I fill in "password" with "incorrect information"
And I press "Login"
Then I should be on the login page
And I should see "Login unsuccessful!"
@mgreenly
mgreenly / git-config.sh
Created August 29, 2010 15:33
git config
git config --global user.name "Your Name Comes Here"
git config --global user.email you@yourdomain.example.com
git config --global core.editor "vim"
git config --global core.excludesfile ~/.gitignore
git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto
git config --global color.interactive auto
@mgreenly
mgreenly / gist:873316
Created March 16, 2011 21:11
datatable.to_json
#------------------------------------------------------------------------------------------------------------------
# type name description
#------------------------------------------------------------------------------------------------------------------
# int iTotalRecords Total records, before filtering (i.e. the total number of records in
# the database)
#
# int iTotalDisplayRecords Total records, after filtering (i.e. the total number of records after
# filtering has been applied - not just the number of records being returned
# in this result set)
#
@mgreenly
mgreenly / gist:876350
Created March 18, 2011 16:15
recursively walk association.accessor chain and return the result
def render(object)
receiver = object
accessors = accessor.split(".")
while accessor = accessors.shift
if receiver.class.reflect_on_association(accessor.to_sym)
receiver = receiver.send(accessor)
else
return receiver.send(accessor)
end
end
@mgreenly
mgreenly / gist:971540
Created May 14, 2011 00:23
datatable with arel and reflection
# 1. data table subclass is initialized
# class methods are going to be called on the class instance, and the class will store table data
#
# 2. instantiate an instance of the data table subclass ( OrdersIndex.new)
#
# 3. query the instance w/ pagination and sorting params
# a query gets executed w/ params -> ARel
# results get stored -> AR
# results get passed back as json
class DataTable
@mgreenly
mgreenly / gist:971546
Created May 14, 2011 00:35
ruby class instance variables
class Foo
# create class instance variables
class << self;
attr_accessor :bar;
end
#initialize class instance variables
@bar = 42
# use class instance variables in class methods
@mgreenly
mgreenly / gist:971885
Created May 14, 2011 03:23
datatable spec
require 'spec_helper'
describe 'Data tables subclasses' do
# it 'should work' do
# Order.create!(:order_number => 32)
# data_table = OrdersIndex.new
# params = {}
# json = data_table.query(params).json
# json['aaRecords'][0][0].should == 32
@mgreenly
mgreenly / gist:977842
Created May 18, 2011 01:43
respond_to respond_with
# apps/data_tables/orders_index.rb
class OrdersIndex < DataTable
model Order
column :order_number, :width => 300
joins :customer
column :first_name
column :last_name
end
column :memo
order [:memo, :first_name]
# undefine the class if it's defined
Object.send(:remove_const, :OrderExample) rescue nil
# define the class
class OrderExample < DataTable
set_model Order
column :id
column :order_number
joins :customer do
column :first_name