Skip to content

Instantly share code, notes, and snippets.

View mattheworiordan's full-sized avatar
💭
V. busy with Ably, building a great team 🚀

Matthew O'Riordan mattheworiordan

💭
V. busy with Ably, building a great team 🚀
View GitHub Profile
@mattheworiordan
mattheworiordan / example_integration_test.rb
Last active August 29, 2015 13:57
Proposed DLS and structure for our tests using Page objects
require 'integration/spec_helper'
feature 'New user sign up', :js => true do
pages :home_page, :registration_page, :registration_complete_page
let(:user_email) { 'matt@econsultancy.com' }
scenario %{
User arrives on the home page, follows the sign up promotion,
fills in the form incorrectly, then corrects their mistakes,
@mattheworiordan
mattheworiordan / application.rb
Last active October 24, 2017 06:41
Cloudflare Middleware for Rails
# insert within your Application
config.middleware.insert_before(0, Rack::CloudFlareFixup)
@mattheworiordan
mattheworiordan / assign_locals_helper.rb
Last active June 30, 2017 16:55
Allow testing of locals when rendering Controllers
def assigns_local(key)
controller.instance_variable_get('@patched_locals')[key]
end
def patch_controller_render_to_support_locals(controller)
def controller.render(options = nil, extra_options = {}, &block)
[options, extra_options].select { |o| o.kind_of?(Hash) }.each do |option_hash|
if option_hash.include?(:locals)
@patched_locals = option_hash[:locals]
end
@mattheworiordan
mattheworiordan / view_spec.rb
Created January 22, 2014 16:41
JSON view test example with shared _item.json partial
describe 'JSON view test' do
let(:partial) { 'admin/case_studies/_item.json' }
let(:case_study) { build_stubbed(:case_study) }
it 'should render item partial' do
JSON.parse(render_item_partial).should == {
id: case_study.id,
title: case_study.title,
whatever: case_study.title
}
@mattheworiordan
mattheworiordan / gist:7374708
Created November 8, 2013 17:40
Econsultancy service objects following our discussion
AccountService.sign_up
AccountService.sign_up_for_existing_membership
AccountService.leave_membership
AccountService.move_to_new_membership
sign_up = AccountService.sign_up
if sign_up.success
...
else
errors = sign_up.errors
@mattheworiordan
mattheworiordan / rerun_rspec.rb
Created September 4, 2013 17:34
Rerun RSpec tests after parallel_tests failure
results = File.expand_path('../tmp/failing_specs.log', __FILE__)
if File.exists?(test_file)
tests = File.open(test_file).read.scan(/rspec .\/([^:]+:\d+)/)
if tests.present?
Dir.chdir(Rails.root) do
command = "bundle exec rspec #{tests.join(' ')}"
end
end
end
<div>Ably Quickstart example</div>
<ul id="output">
</ul>
Message: <input id="message" type="text" value="Hello"><br>
<input type="submit" id="publish" value="Publish the message">
</html>
body {
font-family: Helvetica, Verdana
}
p {
padding: 7px 10px;
}
#demo {
border: 1px solid #999;
}
<div>Ably Quickstart example</div>
<ul id="output">
</ul>
Message: <input id="message" type="text" value="Hello"><br>
<input type="submit" id="publish" value="Publish the message">
</html>