Skip to content

Instantly share code, notes, and snippets.

View patricksrobertson's full-sized avatar

Patrick Robertson patricksrobertson

View GitHub Profile
@patricksrobertson
patricksrobertson / template.rb
Last active October 12, 2015 03:38
Temporary Rails template
# ZOMG RAILS TEMPLATE
def replace_line(path, options = {})
lines = File.open(path).readlines
lines.map! do |line|
if line.match(options[:match])
line = "#{options[:with].rstrip}\n"
end
line
end
@patricksrobertson
patricksrobertson / save_appointment_spec.js.coffee
Created July 22, 2012 11:43
fuller Backbone.js jasmine spec
describe '#_saveAppointment', ->
beforeEach ->
@view = new Iora.Views.Appointments.WalkInForm
@appointment = new Iora.Models.Appointment
patient_id: 5
doctor_id: 2
php_id: 3
at: '2012-04-07T00:00:00-04:00'
@saveSpy = sinon.collection.stub(@appointment, 'save')
@patricksrobertson
patricksrobertson / bb_fetch_spec.js.coffee
Created July 22, 2012 11:27
stubbing Backbone.fetch
collection = new Backbone.Collection
model = new Backbone.Model {title: 'fun times'}
fetchStub = sinon.collection.stub(collection, 'fetch').yieldsTo 'success', model
#rails c production
Patient.all.each do |patient|
Rails.cache.delete("#{Rails.env}-patient-#{patient.id}")
end
@patricksrobertson
patricksrobertson / domPresenter.js
Created March 1, 2012 15:15
dom interaction presenter pattern?
Iora.Presenters.Patients.Edit = function() {
this.initialize.apply(this, arguments);
};
_.extend(Iora.Presenters.Patients.Edit.prototype, function() {
checkSomeBox: function() {
//dom manipulation here
}
});
@patricksrobertson
patricksrobertson / something.rb
Created March 1, 2012 12:34
Testing Rails internals
class User < ActiveRecord::Base
validates :name, presence: true
end
#spec
require 'spec_helper'
Describe User do
it { should validate_presence_of :name } #AMG RAILS IS WORKING!!!!!!!!
it { should_not validate_presence_of :nickname }
class User < ActiveRecord::Base
has_many :cars
end
class Color < ActiveRecord::Base
belongs_to :car
delegate :name, :to => :car, :prefix => true
end
class Car < ActiveRecord::Base
require 'uri'
class IoraBot::Hangout < IoraBot::Observer
def matcher
/^(hangout|standup)(.*)$/mi
end
def handle(message, match_data)
person = message[:user][:name].split(' ')[0]
command = match_data[1]
if command == 'standup'
reply = "All: time for standup: #{link('iora_standup')}"
describe "GET /users" do
it "lists users if you are logged in" do
user1 = Factory(:user, name: "Elliot Stabler")
user2 = Factory(:user, name: "Olivia Benson")
login_user(user1)
login_user(user2)
visit users_path
page.should_have content(user1.name)
Background:
Given the following user:
| first name | last name | email |
| Fred | Friend | [email protected] |
Scenario: I follow a User from their profile
Given I am logged in
When I go to the profile page for "[email protected]"
And I press "Follow"
Then I should be following "Fred Friend"