Deprecate alternate syntaxes

This commit is contained in:
Joshua Clayton 2012-04-23 16:46:42 -05:00
parent d67b798195
commit c006dd186f
9 changed files with 14 additions and 2 deletions

View File

@ -1,3 +1,4 @@
require "active_support/deprecation"
require "factory_girl/syntax/methods"
require "factory_girl/syntax/default"
require "factory_girl/syntax/vintage"

View File

@ -26,6 +26,7 @@ module FactoryGirl
module ClassMethods #:nodoc:
def blueprint(&block)
ActiveSupport::Deprecation.warn "Model.blueprint is deprecated; use the FactoryGirl.define syntax instead", caller
instance = Factory.new(name.underscore, class: self)
proxy = FactoryGirl::DefinitionProxy.new(instance)
proxy.instance_eval(&block)

View File

@ -42,6 +42,7 @@ module FactoryGirl
module ClassMethods #:nodoc:
def generate(overrides = {}, &block)
ActiveSupport::Deprecation.warn "Model.generate is deprecated; use the FactoryGirl.define syntax instead", caller
instance = FactoryRunner.new(name.underscore, Strategy::Build, [overrides]).run
instance.save
yield(instance) if block_given?
@ -49,12 +50,14 @@ module FactoryGirl
end
def generate!(overrides = {}, &block)
ActiveSupport::Deprecation.warn "Model.generate! is deprecated; use the FactoryGirl.define syntax instead", caller
instance = FactoryRunner.new(name.underscore, Strategy::Create, [overrides]).run
yield(instance) if block_given?
instance
end
def spawn(overrides = {}, &block)
ActiveSupport::Deprecation.warn "Model.spawn is deprecated; use the FactoryGirl.define syntax instead", caller
instance = FactoryRunner.new(name.underscore, Strategy::Build, [overrides]).run
yield(instance) if block_given?
instance

View File

@ -28,10 +28,12 @@ module FactoryGirl
module ClassMethods #:nodoc:
def make(overrides = {})
ActiveSupport::Deprecation.warn "Model.make is deprecated; use the FactoryGirl.define syntax instead", caller
FactoryRunner.new(name.underscore, Strategy::Build, [overrides]).run
end
def make!(overrides = {})
ActiveSupport::Deprecation.warn "Model.make! is deprecated; use the FactoryGirl.define syntax instead", caller
FactoryRunner.new(name.underscore, Strategy::Create, [overrides]).run
end

View File

@ -26,6 +26,7 @@ module FactoryGirl
module Sham #:nodoc:
def self.method_missing(name, *args, &block)
if block_given?
ActiveSupport::Deprecation.warn "Sham.sequence is deprecated; use the FactoryGirl.define syntax instead", caller
start_value = args.first
FactoryGirl.register_sequence(Sequence.new(name, start_value || 1, &block))
else

View File

@ -1,5 +1,3 @@
require "active_support/deprecation"
module FactoryGirl
module Syntax
module Vintage

View File

@ -4,6 +4,8 @@ require 'factory_girl/syntax/blueprint'
describe "a blueprint" do
before do
ActiveSupport::Deprecation.silenced = true
define_model('User', first_name: :string, last_name: :string, email: :string)
FactoryGirl.define do

View File

@ -4,6 +4,8 @@ require 'factory_girl/syntax/generate'
describe "a factory using generate syntax" do
before do
ActiveSupport::Deprecation.silenced = true
define_model('User', first_name: :string, last_name: :string, email: :string) do
validates_presence_of :first_name
end

View File

@ -4,6 +4,8 @@ require 'factory_girl/syntax/make'
describe "a factory using make syntax" do
before do
ActiveSupport::Deprecation.silenced = true
define_model('User', first_name: :string, last_name: :string)
FactoryGirl.define do