Skip to content

Instantly share code, notes, and snippets.

View mattwynne's full-sized avatar

Matt Wynne mattwynne

View GitHub Profile
# Responsible for mapping a hash of parameters that will typically be POSTed to a controller into a hash that can be sent to find(:all)
# containing SQL clauses in :conditions / :order.
# This helps us decouple the view / controller layers from any database specific stuff.
class Venue::QueryAdapter < Hash
def initialize(params)
parse params
self.merge!(get_find_params)
@mattwynne
mattwynne / gist:11764
Created September 20, 2008 15:46
undefined
# put this in your features/steps/env.rb to clean up any AR objects created during a scenario before the next one runs
module CleanUp
class << self
attr_accessor :log
end
def self.record(obj)
@objects ||= {}
@objects[obj.class] ||= []
require 'rubygems'
require 'spec'
class Team
def initialize(game)
@game = game
end
def do_substitution
def within_list(css_class)
css_selector = css_class.gsub(/ /, '.') #stack the css classes for selection
list = current_dom.at("ol.#{css_selector}") || current_dom.at("ul.#{css_selector}") # Could add an opt param to the method to make this explicit - for now we don't care
assert_not_nil(list, "Expected to find a ul or li tag matching the css class '#{css_class}'")
yield list
end
Then /^I should see the text "(.*)" in the "(.*)" list$/ do |text, css_class| #"
within_list(css_class) do |list|
matching_list_items = list.search("li").select{ |li| strip_html_tags_from(li.inner_html) =~ escape_text_for_regexp(text) }
#
# Here is a (simplistic) example of a class with, arguably, too many responsibilites.
# Methods are clustered together in the file to maintain a semblance of cohesion, but there is no enapsulation of these
# behaviours. A class like this will grow ugly and over-complex.
#
# Forcing yourself to order the methods alphabetically would be one way to alert you to these multiple responsibilities,
# because you would feel uncomfortable breaking up the cohesive clusters of methods in order to sort them by this
# arbitrary rule.
#
class BloatedUser
it 'should do something' do
on_failure warn_that "@foo shouldn't be nil" do
@foo.should_not be_nil
end
end
Feature: Upload media
In order to collect vivid content about the site
A user with an account
Should be able to upload images, videos and posters about concerts
Scenario: Upload an image for an artist and create a concert in the process
Given I am logged in to my account
And there is one Artist named "Pixies"
And there is one Venue
When I visit the page for the Artist
require 'rubygems'
require File.dirname(__FILE__) + '/../rosetta_queue/lib/rosetta_queue'
RosettaQueue::Destinations.define do |queue|
queue.map :monitoring_acts, "/queue/bowie/monitoring_acts"
end
RosettaQueue::Adapter.define do |a|
a.user = ""
a.password = ""
namespace :db do
namespace :features do
def checking_for_config
if ActiveRecord::Base.configurations["features"]
yield
else
puts "Unable to prepare features database - it's not defined in your configuration. Skipping. Preparing test database instead."
Rake::Task['db:test:prepare'].invoke
end
desc 'Continuous build target. Runs specs and features.'
task :cruise => [] do
# needs grant all on *.* to builder@localhost IDENTIFIED BY 'password' to work
begin
ENV["RAILS_FEATURES_ENV"] = "features"
Dir.chdir(RAILS_ROOT) do
`rm -rf tmp/webrat*.html`
end