Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This changes Strategy from a class to a module and removes inheritance. It introduces an Evaluation facade to make building strategies easier
- Loading branch information
1 parent
dcae837
commit 89d5e94
Showing
21 changed files
with
122 additions
and
167 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module FactoryGirl | ||
class CallbackRunner | ||
def initialize(callbacks, evaluator) | ||
@callbacks = callbacks | ||
@evaluator = evaluator | ||
end | ||
|
||
def update(name, result_instance) | ||
callbacks_by_name(name).each do |callback| | ||
callback.run(result_instance, @evaluator) | ||
end | ||
end | ||
|
||
private | ||
|
||
def callbacks_by_name(name) | ||
@callbacks.select {|callback| callback.name == name } | ||
end | ||
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require "observer" | ||
|
||
module FactoryGirl | ||
class Evaluation | ||
include Observable | ||
|
||
def initialize(attribute_assigner, to_create) | ||
@attribute_assigner = attribute_assigner | ||
@to_create = to_create | ||
end | ||
|
||
def create(result_instance) | ||
@to_create[result_instance] | ||
end | ||
|
||
delegate :object, :hash, to: :@attribute_assigner | ||
|
||
def notify(name, result_instance) | ||
changed | ||
notify_observers(name, result_instance) | ||
end | ||
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
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 was deleted.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,18 +1,18 @@ | ||
require 'spec_helper' | ||
|
||
describe FactoryGirl::Strategy::AttributesFor do | ||
let(:result) { { name: "John Doe", gender: "Male", admin: false } } | ||
let(:attribute_assigner) { stub("attribute assigner", hash: result) } | ||
let(:result) { { name: "John Doe", gender: "Male", admin: false } } | ||
let(:evaluation) { stub("evaluation", hash: result) } | ||
|
||
it_should_behave_like "strategy without association support" | ||
|
||
it "returns the hash from the attribute assigner" do | ||
subject.result(attribute_assigner, lambda {|item| item }).should == result | ||
it "returns the hash from the evaluation" do | ||
subject.result(evaluation).should == result | ||
end | ||
|
||
it "does not run the to_create block" do | ||
expect do | ||
subject.result(attribute_assigner, lambda {|item| raise "failed" }) | ||
subject.result(evaluation) | ||
end.to_not raise_error | ||
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
Oops, something went wrong.