Skip to content

Commit

Permalink
Deprecate alternate syntaxes
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaclayton committed Apr 23, 2012
1 parent d67b798 commit c006dd1
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/factory_girl/syntax.rb
@@ -1,3 +1,4 @@
require "active_support/deprecation"
require "factory_girl/syntax/methods"
require "factory_girl/syntax/default"
require "factory_girl/syntax/vintage"
Expand Down
1 change: 1 addition & 0 deletions lib/factory_girl/syntax/blueprint.rb
Expand Up @@ -26,6 +26,7 @@ def self.included(base) # :nodoc:
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)
Expand Down
3 changes: 3 additions & 0 deletions lib/factory_girl/syntax/generate.rb
Expand Up @@ -42,19 +42,22 @@ def self.included(base) # :nodoc:
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?
instance
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
Expand Down
2 changes: 2 additions & 0 deletions lib/factory_girl/syntax/make.rb
Expand Up @@ -28,10 +28,12 @@ def self.included(base) # :nodoc:
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

Expand Down
1 change: 1 addition & 0 deletions lib/factory_girl/syntax/sham.rb
Expand Up @@ -26,6 +26,7 @@ module Sham
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
Expand Down
2 changes: 0 additions & 2 deletions lib/factory_girl/syntax/vintage.rb
@@ -1,5 +1,3 @@
require "active_support/deprecation"

module FactoryGirl
module Syntax
module Vintage
Expand Down
2 changes: 2 additions & 0 deletions spec/acceptance/syntax/blueprint_spec.rb
Expand Up @@ -4,6 +4,8 @@

describe "a blueprint" do
before do
ActiveSupport::Deprecation.silenced = true

define_model('User', first_name: :string, last_name: :string, email: :string)

FactoryGirl.define do
Expand Down
2 changes: 2 additions & 0 deletions spec/acceptance/syntax/generate_spec.rb
Expand Up @@ -4,6 +4,8 @@

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
Expand Down
2 changes: 2 additions & 0 deletions spec/acceptance/syntax/make_spec.rb
Expand Up @@ -4,6 +4,8 @@

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
Expand Down

0 comments on commit c006dd1

Please sign in to comment.