Skip to content

Instantly share code, notes, and snippets.

@ClayShentrup
Created November 16, 2013 20:25
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ClayShentrup/7504878 to your computer and use it in GitHub Desktop.
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
end
end
class Sweeper
def self.sweep
User.all.select do |user|
user.active? and user.paid_at < 1.month.ago
end.each do |user|
UserMailer.billing_problem(bob)
end
end
end
describe Sweeper do
context 'a subscription is expired' do
let(:bob) { double(active?: true, paid_at: 2.months.ago) }
it 'emails the user' do
expect(ExpiredUsers.for_users(users)).to eq [bob]
end
end
end
class ExpiredUsers
def self.for_users(user)
users.select do |user|
user.active? and user.paid_at < 1.month.ago
end
end
end
class Sweeper
def self.sweep
ExpiredUsers.for_users(User.all).each do |user|
UserMailer.billing_problem(user)
end
end
end
@skwp
Copy link

skwp commented Nov 17, 2013

My accounting stuff is too Reverb specific to post, but at some point in the future if I have a good example of this type of refactoring, I'll make a post on the Reverb Dev Blog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment