This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use instances rather than class methods
Rather than sending Griddler.configuration.processor_method to Griddler.configuration.processor_class with a Griddler::Email as an argument (i.e., EmailProcessor.process(email)), instantiate Griddler.configuration.processor_class with a Griddler::Email and call Griddler.configuration.processor_method on that object (i.e., EmailProcessor.new(email).process). This encourages the behavior of separating logic into methods within an EmailProcessor, which is better than having a single class method with many responsibilities or passing state around between class methods.
- Loading branch information
1 parent
33187f5
commit 7e8f34e
Showing
4 changed files
with
22 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,21 +24,21 @@ | |
end | ||
|
||
it 'calls process on the custom processor class' do | ||
my_handler = double | ||
my_handler.should_receive(:process) | ||
my_handler = double(process: nil) | ||
my_handler.should_receive(:new).and_return(my_handler) | ||
Griddler.configuration.stub(processor_class: my_handler) | ||
|
||
post :create, email_params | ||
end | ||
|
||
it 'calls the custom processor method on the processor class' do | ||
Griddler.configuration.stub(processor_method: :perform) | ||
griddler_email = double | ||
Griddler::Email.should_receive(:new).and_return(griddler_email) | ||
fake_processor = double(perform: nil) | ||
|
||
EmailProcessor.should_receive(:perform).with(griddler_email) | ||
EmailProcessor.should_receive(:new).and_return(fake_processor) | ||
fake_processor.should_receive(:perform) | ||
|
||
post :create, to: '[email protected]' | ||
post :create, email_params | ||
end | ||
end | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
class EmailProcessor | ||
cattr_accessor :email | ||
def self.process(email) | ||
@@email = email | ||
def initialize(email) | ||
@email = email | ||
end | ||
|
||
def process; end | ||
end |