Skip to content

Instantly share code, notes, and snippets.

View stuliston's full-sized avatar

Stuart Liston stuliston

View GitHub Profile
@stuliston
stuliston / test.md
Created May 26, 2014 04:07
Date Test

The Challenge

Create an application that can read in pairs of dates in the following format -

DD MM YYYY, DD MM YYYY

Validate the input data, and compute the difference between the two dates in days.

@stuliston
stuliston / face.rb
Last active December 27, 2015 20:39
IN YOUR ActiveRecord::Face
# DISCLAIMER: Beer was consumed
# Need to make assertions about ActiveRecord query messages applied to
# a model but don't want to include AR as a dependency? Feeling yolo?
# I had that situation lately with a gem that takes params and uses macros
# to build a scoped relation (github.com/hooroo/query_ar), so I cooked this up.
# Usage is as follows.
@stuliston
stuliston / a.rb
Last active December 27, 2015 03:28
A or B, with reasons
# A. Less nested contexts, clearer object collaboration at the cost of repetition
describe PlaceParameters do
describe '#sort_by' do
it 'concatenates the sort_by and sort_dir params' do
params = { sort_by: 'name', sort_dir: 'asc' }
sort_by = PlaceParameters.new(params).sort_by
expect(sort_by).to match /^name asc$/i
@stuliston
stuliston / artists_releases_spec.rb
Created September 10, 2011 04:44
Testing HABTM with rspec and factory girl
require 'spec_helper'
describe "Artists to releases relationship" do
before(:all) do
@kanye = FactoryGirl.create(:artist, :name => 'Kanye West')
@jz = FactoryGirl.create(:artist, :name => 'Jay Z')
@watch_the_throne = FactoryGirl.create(:release, :name => 'Watch the Throne')
@dropout = FactoryGirl.create(:release, :name => 'The College Dropout')
end