私の問題は、テスト環境で古いエイリアスメソッドを呼び出すことです。おそらく唯一のRuby、Railsとエイリアシング - スタックが深すぎる問題
module Authentication
module ByPassword
# Stuff directives into including module
def self.included(recipient)
recipient.class_eval do
include ModelInstanceMethods
attr_accessor :password
validates_presence_of :password, :if => :password_required?
end
end # #included directives
module ModelInstanceMethods
def password_required?
crypted_password.blank? || !password.blank?
end
end # instance methods
end
end
仕様/モデル/ user_spec.rb
by_password.rbファクトリー・ガールアプリ/モデル/ user.rb
class User < ActiveRecord::Base
...
include Authentication
include Authentication::ByPassword
...
attr_accessor :skip_password_validations
alias old_password_required? password_required?
# alias_method :old_password_required?, :password_required?
def password_required?
return false if !!skip_password_validations
old_password_required?
end
# def password_required_with_skip_validations?
# return false if !!skip_password_validations
# password_required_without_skip_validations?
# end
# alias_method_chain :password_required?, :skip_validations
end
ベンダー/プラグイン/../と
describe User do
it 'test' do
@user = Factory(:user)
@user.should be_valid
end
end
spec/factories/user_factories.rb
FactoryGirl.define do
factory :user do |u|
u.sequence(:email) { |n| "login#{n}@example.com" }
u.password 'qwertz123'
u.password_confirmation 'qwertz123'
end
end
結果が
1) User test
Failure/Error: Unable to find matching line from backtrace
SystemStackError:
stack level too deep
# /Users/schovi/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/database_statements.rb:197
私は、デバッガの宝石でそれをデバッグするとき、私はuser.rb
に新しい方法password_required?
にその方法old_password_required?
ポイントを発見し、vendor/plugins/../by_password.rb
にalias, alias_method or alias_method_chain
アイデア?
素晴らしいアイデア。私はおそらくそれを使用します。しかし、私はまだ興味があります、なぜ私はそのエラーを取得しています。 – Schovi