Graham Ashton gma

View capybara_assertions.rb
1 2 3 4 5 6 7 8 9 10
module CapybaraAssertions
def css_assertion_builder(outcome, selector, text, message)
if text
options = { :text => text }
message ||= "#{outcome} have found '#{selector}' containing '#{text}'"
else
options = {}
message ||= "#{outcome} have found '#{selector}'"
end
is_present = page.has_css?(selector, options)
View gist:3634662
1 2 3 4 5
def redirect_to_app_when_logged_in
if request.path == '/' && request.referer.blank? && current_user
redirect_to iteration_path('current')
end
end
View soc-to-the-max.rb
1 2 3 4 5 6 7 8 9
class TasksController < ApplicationController
def complete
# add responder as listener, or could subscribe etc...
# task could be the actual task, or pass through the ID
task.add_subscriber(TaskCompletedResponse.new(self))
task.add_subscriber(TaskEmail.new)
task.add_subscriber(TaskIndex)
task.complete_by(person)
end
View card_creator.rb
1 2 3 4 5 6 7 8 9 10
class CardCreator
include Publisher
def create(iteration, attributes)
card = iteration.cards.build(attributes)
card.save!
rescue ActiveRecord::RecordInvalid
notify_subscribers(:create_failed, card)
else
notify_subscribers(:created, card)
View card_creator.rb
1 2 3 4 5 6 7 8 9 10
class CardCreator < Struct.new(:listener)
def create(iteration, attributes)
card = iteration.cards.build(attributes)
if card.save
listener.created(card)
else
listener.create_failed(card)
end
end
end
View card_creator.rb
1 2 3 4 5 6 7 8 9 10
class CardCreator < Struct.new(:listener)
class Failed < RuntimeError
attr_accessor :model
def initialize(model)
@model = model
end
end
def self.create(iteration, attributes)
View gist:1876872
1 2 3 4 5 6 7 8 9
# The best approach depends on how you define a blog entry. If you think
# of a blog article the same way I do, that means "all pages with a date".
#
# In Ruby you can re-open a class and redefine its methods. Normally, this
# would be a horrific thing to do (as others could be very confused by
# your code) but in the context of a typical Nesta site I don't think it's
# particularly bad news, and its very convenient.
#
# So, in app.rb, add this (which is very similar to the default):
View gist:1876095
1 2 3 4 5 6 7
11:53:07 web.1 | /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/sass-3.1.15/lib/sass/plugin/compiler.rb:29:in `<class:Compiler>'
11:53:07 web.1 | /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/sass-3.1.15/lib/sass/plugin/compiler.rb:28:in `<module:Plugin>'
11:53:07 web.1 | /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/sass-3.1.15/lib/sass/plugin/compiler.rb:9:in `<top (required)>'
11:53:07 web.1 | /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/sass-3.1.15/lib/sass/plugin.rb:4:in `<top (required)>'
11:53:07 web.1 | /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/haml-3.1.4/lib/sass/rails3_shim.rb:15:in `block in <top (required)>'
11:53:07 web.1 | /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
11:53:07 web.1 | /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.2.
View gist:1847073
1 2 3 4 5 6 7 8 9 10
class Card extends Serenade.Model
@localStorage = true
@property 'title', serialize: true
 
class CardSet extends Serenade.Model
@localStorage = true
@hasMany 'cards', as: (-> Card), constructor: Card, serializeIds: true
 
# Create one card, and one card set, and save them to the database.
the_set = new CardSet(id: 1)
View gist:1770728
1 2 3 4 5 6 7 8 9 10
 
I said "I'll send you a link..." at least three times last night.
Thought I may as well send 'em to the list...
 
Daniel Tenner's example videos for validating product ideas without
writing any code are linked from this post:
http://swombat.com/2012/1/27/create-your-own-video
 
He's also got loads of other ideas on validating things that you can
find with this search: http://swombat.com/search?q=validat
Something went wrong with that request. Please try again.