Skip to content

Instantly share code, notes, and snippets.

View skwp's full-sized avatar

Yan Pritzker skwp

View GitHub Profile
@ClayShentrup
ClayShentrup / original.rb
Created November 16, 2013 20:25
Trying to understand the point of Gary Bernhardt's "Boundaries" talk
describe Sweeper do
context 'a subscription is expired' do
let(:bob) { double(active?: true, paid_at: 2.months.ago) }
let(:users) { [bob] }
before { allow(User).to receive(:all).and_return(users) }
it 'emails the user' do
expect(UserMailer).to receive(:billing_problem).with(bob)
described_class.sweep
end
# Instructions for this test:
# 1. Please clone this gist as a git repo locally
# 2. Create your own github repo called 'rubytest' (or a name of your choice) and add this repo as a new remote to the cloned repo
# 3. Edit this file to answer the questions, and push this file with answers back out to your own 'rubytest' repo.
# Problem 1. Explain briefly what this code does. Create a RSpec unit test for
# it, fix any bugs, then clean up the syntax to be more idiomatic Ruby and make
# sure your tests still pass.
#
# Your spec should have at least 3 contexts/conditional tests (what are they?)
@skwp
skwp / watch_listing.rb
Last active December 15, 2015 18:09
Hexagonal extraction of a controller action from reverb.com, showing reuse between controller and Grape/Roar based API. This is sample code stripped down to the essentials and is not guaranteed to work as-is :)
class Reverb::Actions::WatchListing
def self.watch(user, product, listener)
if product.owner?(user)
listener.failure(I18n.t('flash.watchlist.error_own'))
else
Reverb::Analytics.track(user, :watch_product) # FIXME, this doesn't belong here
user.user_watch_products.create(:product_id => product.id)
listener.success
end
end
@dhh
dhh / gist:2643144
Created May 9, 2012 08:57
Coding stats from the new Basecamp
bcx david$ rake stats
+----------------------+-------+-------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers | 3704 | 2942 | 72 | 479 | 6 | 4 |
| Helpers | 1901 | 1529 | 13 | 261 | 20 | 3 |
| Models | 5310 | 4116 | 50 | 653 | 13 | 4 |
| Libraries | 2167 | 1593 | 51 | 200 | 3 | 5 |
| Integration tests | 297 | 217 | 6 | 1 | 0 | 215 |
| Functional tests | 3897 | 3065 | 61 | 11 | 0 | 276 |
@skwp
skwp / logcaller.js
Created November 21, 2011 22:17
log the caller of the log function
function logCall() {
console.log(logCall.caller.name + '(' +
Array.prototype.slice.call(logCall.caller.arguments)
.map(JSON.stringify).join(', ') +
')');
}