Skip to content

Instantly share code, notes, and snippets.

View martinhawkins's full-sized avatar

Martin Hawkins martinhawkins

View GitHub Profile
@martinhawkins
martinhawkins / select_option_disabled_step.rb
Created December 14, 2010 11:19
Cucumber step definition to detect whether a disabled select option exists
Then /^"([^"]*)" from "([^"]*)" within "([^"]*)" should be disabled$/ do |option_name, type_label, selector|
with_scope(selector) do
x=page.find(:xpath, '//body').all(:xpath, XPath.generate { |x| x.descendant(:select).descendant(:option)[x.attr(:disabled) == 'disabled'] })
x.collect(&:text).should include(option_text)
end
end
@martinhawkins
martinhawkins / date_convert.rb
Created December 9, 2010 12:57
Contains the date_of_next method
#date_convert.rb
require 'date'
require 'active_support/core_ext'
Date::DATE_FORMATS.merge!({british: "%d/%m/%Y"})
class DateConvert
# usage:
# date_of_next( day_name, date) where day_name is a string or symbol representation of a full weekday name, e.g. :saturday
# and date is either a valid Date object or a string representation of a date
@martinhawkins
martinhawkins / date_time_formats.rb
Created December 3, 2010 13:04
Adding formats to work with Date.to_s(:format)
Date::DATE_FORMATS[:british] = "%d/%m/%Y"
Date::DATE_FORMATS[:british_long] = "%d %B, %Y"
Date::DATE_FORMATS[:british_long_ordinal] = lambda { |date| date.strftime("#{ActiveSupport::Inflector.ordinalize(date.day)} %B, %Y") } # => "25th April, 2007"
polaris:~ martin$ rvm debug
ruby-1.8.7-p302:
rvm 1.0.14 by Wayne E. Seguin ([email protected]) [http://rvm.beginrescueend.com/]
ruby-1.8.7-p302:
describe "when authorised as admin" do
describe "POST 'create'" do
before(:each) do
login_as_admin
end
after(:each) do
logout
end
describe "with valid params" do
it "should set password and password_confirmation to the same 10 digit value" do
def initialize(user)
user ||= User.new # Guest user
if user.role? :admin
can [:index, :show, :new, :edit, :create, :update, :destroy], [User, CommonContents, Logo]
else
can [:show, :edit, :update], User
cannot [:index, :show, :new, :edit, :create, :update, :destroy], [CommonContents, Logo]
end
end