我正在尝试从入门指南中实施新的FactoryGirl自定义构建策略。FactoryGirl我想使用他们必须能够将我的工厂输出为JSON文件的代码。
他们提供此代码以输出JSON:
class JsonStrategy
def initialize
@strategy = FactoryGirl.strategy_by_name(:create).new
end
delegate :association, to: :@strategy
def result(evaluation)
@strategy.result(evaluation).to_json
end
end
我应该在哪个目录保存此代码以便在其中使用它FactoryGirl?
这是我获取代码的链接以及对其功能的进一步解释:
http://robots.thoughtbot.com/post/21719164760/factorygirl-3-2-so-awesome-it-needs-to-be-released
在页面下方的标题"REGISTER CUSTOM BUILD STRATEGIES" 下2/3查看。