Created
November 16, 2013 20:25
-
-
Save ClayShentrup/7504878 to your computer and use it in GitHub Desktop.
Trying to understand the point of Gary Bernhardt's "Boundaries" talk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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