Skip to content

Instantly share code, notes, and snippets.

@joho
Created February 27, 2013 01:42
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 joho/5044188 to your computer and use it in GitHub Desktop.
Save joho/5044188 to your computer and use it in GitHub Desktop.
my way of half assing DI with rails
class FakeModel < ActiveRecord::Base
def save_and_do_those_other_things
save &&
that_other_model_class.create(:some_attr => self.my_attr_todo_with_something) &&
some_api_class.new.do_that_thing
end
def that_other_model_class
ThatOtherModel
end
def some_api_class
SomeApiGem::Client
end
end
require 'fast_model_spec_helper'
require 'fake_model'
describe FakeModel do
before do
subject.stub(:that_other_model_class => mock)
subject.stub(:some_api_class => mock.as_null_object)
end
it "should to that thing with its collaborators" do
subject.my_attr_todo_with_something = "testinglol"
subject.should_receive(:create).with(subject.my_attr_todo_with_something)
subject.should_receive(:new).should_receive(:do_that_thing)
subject.save
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment