Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
use AS deprecation warn, silence deprecations in specs
  • Loading branch information
nashby authored and joshuaclayton committed Mar 27, 2012
1 parent 08d01c1 commit bca13f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/factory_girl/syntax/vintage.rb
@@ -1,3 +1,5 @@
require "active_support/deprecation"

module FactoryGirl
module Syntax
module Vintage
Expand All @@ -21,7 +23,7 @@ module ::Factory
# Yields: +Factory+
# The newly created factory.
def self.define(name, options = {})
$stderr.puts "DEPRECATION WARNING: Factory.define is deprecated; use the FactoryGirl.define block syntax to declare your factory."
ActiveSupport::Deprecation.warn "DEPRECATION WARNING: Factory.define is deprecated; use the FactoryGirl.define block syntax to declare your factory.", caller
factory = FactoryGirl::Factory.new(name, options)
proxy = FactoryGirl::DefinitionProxy.new(factory)
yield(proxy)
Expand All @@ -44,7 +46,7 @@ def self.define(name, options = {})
#
# Factory.sequence(:email) {|n| "somebody_#{n}@example.com" }
def self.sequence(name, start_value = 1, &block)
$stderr.puts "DEPRECATION WARNING: Factory.sequence is deprecated; use the FactoryGirl.define block syntax to declare your sequence."
ActiveSupport::Deprecation.warn "DEPRECATION WARNING: Factory.sequence is deprecated; use the FactoryGirl.define block syntax to declare your sequence.", caller
FactoryGirl.register_sequence(Sequence.new(name, start_value, &block))
end

Expand All @@ -57,7 +59,7 @@ def self.sequence(name, start_value = 1, &block)
# Returns:
# The next value in the sequence. (Object)
def self.next(name)
$stderr.puts "DEPRECATION WARNING: Factory.next is deprecated; use FactoryGirl.generate instead."
ActiveSupport::Deprecation.warn "DEPRECATION WARNING: Factory.next is deprecated; use FactoryGirl.generate instead.", caller
FactoryGirl.generate(name)
end

Expand Down Expand Up @@ -86,31 +88,31 @@ def self.next(name)
# # will be used instead.
# Factory(:post, user_id: 1)
def self.alias(pattern, replace)
$stderr.puts "DEPRECATION WARNING: Factory.alias is deprecated; use FactoryGirl.aliases << [pattern, replace] instead."
ActiveSupport::Deprecation.warn "DEPRECATION WARNING: Factory.alias is deprecated; use FactoryGirl.aliases << [pattern, replace] instead.", caller
FactoryGirl.aliases << [pattern, replace]
end

# Alias for FactoryGirl.attributes_for
def self.attributes_for(name, overrides = {})
$stderr.puts "DEPRECATION WARNING: Factory.attributes_for is deprecated; use FactoryGirl.attributes_for instead."
ActiveSupport::Deprecation.warn "DEPRECATION WARNING: Factory.attributes_for is deprecated; use FactoryGirl.attributes_for instead.", caller
FactoryGirl.attributes_for(name, overrides)
end

# Alias for FactoryGirl.build
def self.build(name, overrides = {})
$stderr.puts "DEPRECATION WARNING: Factory.build is deprecated; use FactoryGirl.build instead."
ActiveSupport::Deprecation.warn "DEPRECATION WARNING: Factory.build is deprecated; use FactoryGirl.build instead.", caller
FactoryGirl.build(name, overrides)
end

# Alias for FactoryGirl.create
def self.create(name, overrides = {})
$stderr.puts "DEPRECATION WARNING: Factory.create is deprecated; use FactoryGirl.create instead."
ActiveSupport::Deprecation.warn "DEPRECATION WARNING: Factory.create is deprecated; use FactoryGirl.create instead.", caller
FactoryGirl.create(name, overrides)
end

# Alias for FactoryGirl.build_stubbed.
def self.stub(name, overrides = {})
$stderr.puts "DEPRECATION WARNING: Factory.stub is deprecated; use FactoryGirl.build_stubbed instead."
ActiveSupport::Deprecation.warn "DEPRECATION WARNING: Factory.stub is deprecated; use FactoryGirl.build_stubbed instead.", caller
FactoryGirl.build_stubbed(name, overrides)
end
end
Expand All @@ -120,7 +122,7 @@ def self.stub(name, overrides = {})
# Example:
# Factory(:user, name: 'Joe')
def Factory(name, attrs = {})
$stderr.puts "DEPRECATION WARNING: Factory(:name) is deprecated; use FactoryGirl.create(:name) instead."
ActiveSupport::Deprecation.warn "DEPRECATION WARNING: Factory(:name) is deprecated; use FactoryGirl.create(:name) instead.", caller
FactoryGirl.create(name, attrs)
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/acceptance/syntax/vintage_spec.rb
Expand Up @@ -2,6 +2,8 @@

describe "vintage syntax" do
before do
ActiveSupport::Deprecation.silenced = true

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

0 comments on commit bca13f1

Please sign in to comment.