Skip to content

Instantly share code, notes, and snippets.

@aeden
Created May 7, 2011 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aeden/960637 to your computer and use it in GitHub Desktop.
Save aeden/960637 to your computer and use it in GitHub Desktop.
Extraction Blog Post
class Contact < ActiveRecord::Base
belongs_to :user
def name
"#{first_name} #{last_name}"
end
end
require 'lib/logic/contact'
class FakeContact
include Logic::Contact
attr_accessor :first_name, :last_name
end
describe Logic::Contact do
subject do
contact = FakeContact.new
contact.first_name = "Anthony"
contact.last_name = "Eden"
contact
end
it "has a name" do
subject.name.should eq("#{subject.first_name} #{subject.last_name}")
end
end
class Domain < ActiveRecord::Base
# ...lots of code...
def auto_renew?
registry_domain.auto_renew?
rescue => e
logger.error e
false
end
# ... more code ...
end
class Contact < ActiveRecord::Base
include Logic::Contact
belongs_to :user
end
module Logic
module Contact
def name
"#{first_name} #{last_name}"
end
end
end
class Domain < ActiveRecord::Base
include Logic::Domain::Renewable
end
module Logic
module Domain
module Renewable
def auto_renew?
registry_domain.auto_renew?
rescue => e
logger.error e
false
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment