繁体   English   中英

规范在 Rails 3.0.4 中通过,在 3.1.0.rc4 中失败

[英]Spec passes in Rails 3.0.4, fails in 3.1.0.rc4

请帮我为 Rails 3.1 调试这个。 它在 3.0 中通过。 谢谢你。

$ rspec 规格/型号

更新:托管 model

require 'transitions'

class Escrow < ActiveRecord::Base
  include ActiveRecord::Transitions
  include Amendable
  include ActsAsAsset
  include Searchable

  acts_as_taggable_on :tags

  has_many :addresses, :as => :addressable
  has_many :events, :as => :entity
  has_many :phone_numbers, :as => :phoneable
  belongs_to :property

  validates :property, :presence => true

  state_machine do
    state :open
    state :cancel
    state :close

    event :cancel do
      transitions :to => :cancel, :from => [:open]
    end

    event :close do
      transitions :to => :close, :from => [:open]
    end
  end

  def self.open
    where :state => 'open'
  end

  def all_participants
    (self.users + property.users).flatten.compact.uniq.sort +
      (self.groups + property.groups).flatten.compact.uniq.sort
  end
end

model

require 'transitions'

class Property < ActiveRecord::Base
  include ActiveRecord::Transitions
  include ActsAsAsset
  include Amendable
  include Searchable

  acts_as_taggable_on :tags

  has_many :addresses, :as => :addressable
  has_many :escrows
  has_many :events, :as => :entity
  has_many :phone_numbers, :as => :phoneable

  state_machine do
    state :pending
    state :active,  :enter => :cancel_escrow
    state :cancel,  :enter => :cancel_escrow
    state :close,   :enter => :close_escrow
    state :expire
    state :escrow,  :enter => :open_escrow

    event :active do
      transitions :to => :active, :from => [:escrow, :expire, :pending, :cancel]
    end

    event :cancel do
      transitions :to => :cancel, :from => [:active, :escrow, :pending]
    end

    event :close do
      transitions :to => :close, :from => [:escrow]
    end

    event :expire do
      transitions :to => :expire, :from => [:active]
    end

    event :escrow do
      transitions :to => :escrow, :from => [:active], :guard => :no_open_escrows
    end
  end

  def current_escrow
    self.escrows.open.first
  end

  private

    def cancel_escrow
      self.current_escrow.try(:cancel!)
    end

    def close_escrow
      self.current_escrow.try(:close!)
    end

    def no_open_escrows
      self.escrows.open.empty?
    end

    def open_escrow
      self.escrows.create!
    end
end

规格

require 'spec_helper'

describe Property do
  disconnect_sunspot

  describe 'Associations' do
    it { should have_one :pivot }
    it { should have_many :addresses }
    it { should have_many :escrows }
    it { should have_many(:events) }
    it { should have_many(:groups).through(:pivot) }
    it { should have_many :phone_numbers }
    it { should have_many(:users).through(:pivot) }
  end

  describe 'Database Columns' do
    it { should have_db_column(:state).of_type(:string) }
  end

  describe 'Factory' do
    it { Factory.build(:property).valid?.should == true }
  end

  describe 'Methods' do
    describe '#current_escrow' do
      it 'returns open escrow or none' do
        p = Factory :property, :state => 'active'
        p.escrow!
        e = p.escrows.first
        2.times { p.escrows.create :state => 'canceled' }
        p.current_escrow.should == e
      end
    end
  end

  describe 'Modules' do
    it { Property.included_modules.include?(ActsAsAsset).should == true }
    it { Property.included_modules.include?(Amendable).should == true }
  end

  describe 'State Transitions' do
    describe 'active!' do
      %w(cancel escrow expire pending).each do |state|
        it "transitions to active from #{state}" do
          p = Factory :property, :state => state
          lambda { p.active! }.should_not raise_error
        end
      end

      %w(close).each do |state|
        it "cannot transition to active from #{state}" do
          p = Factory :property, :state => state
          lambda { p.active! }.should raise_error
        end
      end

      it 'marks escrow reconciled and canceled if escrow -> active' do
        p = Factory :property, :state => 'active'
        p.escrow!
        p.active!
        p.reload
        p.send(:no_open_escrows).should == true
        p.escrows.first.state.should == 'cancel'
      end
    end

    describe 'cancel!' do
      %w(active escrow pending).each do |state|
        it "transitions to cancel from #{state}" do
          p = Factory :property, :state => state
          lambda { p.cancel! }.should_not raise_error
        end
      end

      %w(close).each do |state|
        it "cannot transition to cancel from #{state}" do
          p = Factory :property, :state => state
          lambda { p.active! }.should raise_error
        end
      end
    end

    describe 'close!' do
      %w(escrow).each do |state|
        it "transitions to close from #{state}" do
          p = Factory :property, :state => state
          lambda { p.close! }.should_not raise_error
        end
      end

      %w(expire cancel pending).each do |state|
        it "cannot transition to close from #{state}" do
          p = Factory :property, :state => state
          lambda { p.close! }.should raise_error
        end
      end
    end

    describe 'escrow!' do
      %w(active).each do |state|
        it "transitions to escrow from #{state}" do
          p = Factory :property, :state => state
          lambda { p.escrow! }.should_not raise_error
        end
      end

      %w(escrow close cancel expire pending).each do |state|
        it "cannot transition to escrow from #{state}" do
          p = Factory :property, :state => state
          lambda { p.escrow! }.should raise_error
        end
      end

      it 'creates a new escrow object on escrow!' do
        p = Factory :property, :state => 'active'
        p.escrows.empty?.should == true
        p.escrow!
        p.reload
        p.escrows.size.should == 1
      end

      it 'cannot go to escrow if another escrow is open' do
        p = Factory :property, :state => 'active'
        p.escrow!
        lambda { p.escrow! }.should raise_error
      end

      it 'can go to escrow if previous escrows are canceled' do
        p = Factory :property, :state => 'active'
        p.escrows.create
        p.reload
        p.escrows.first.update_attribute :state, 'canceled'
        lambda { p.escrow! }.should_not raise_error
      end
    end

    describe 'expire!' do
      %w(active).each do |state|
        it "transitions to expire from #{state}" do
          p = Factory :property, :state => state
          lambda { p.expire! }.should_not raise_error
        end
      end

      %w(escrow close cancel pending).each do |state|
        it "cannot transition to expire from #{state}" do
          p = Factory :property, :state => state
          lambda { p.expire! }.should raise_error
        end
      end
    end

    describe 'pending' do
      it 'has initial state pending' do
        Factory(:property).state.should == 'pending'
      end

      %w(active close escrow expire cancel).each do |state|
        it "cannot transition to pending from #{state}" do
          p = Factory :property, :state => state
          lambda { p.pending! }.should raise_error
        end
      end
    end
  end

  describe 'Tags' do
    it { Factory(:property).tags.should == [] }
  end

  describe 'Validations' do
  end
end

失败

Failures:

  1) Property Methods#current_escrow returns open escrow or none
     Failure/Error: p.escrow!
     ArgumentError:
       wrong number of arguments (0 for 1)
     # ./app/models/property.rb:60:in `no_open_escrows'
     # ./spec/models/property_spec.rb:28:in `block (4 levels) in <top (required)>'

  2) Property State Transitions active! transitions to active from cancel
     Failure/Error: lambda { p.active! }.should_not raise_error
       expected no Exception, got #<ArgumentError: wrong number of arguments (0 for 1)>
     # ./spec/models/property_spec.rb:46:in `block (5 levels) in <top (required)>'

  3) Property State Transitions active! transitions to active from escrow
     Failure/Error: lambda { p.active! }.should_not raise_error
       expected no Exception, got #<ArgumentError: wrong number of arguments (0 for 1)>
     # ./spec/models/property_spec.rb:46:in `block (5 levels) in <top (required)>'

  4) Property State Transitions active! transitions to active from expire
     Failure/Error: lambda { p.active! }.should_not raise_error
       expected no Exception, got #<ArgumentError: wrong number of arguments (0 for 1)>
     # ./spec/models/property_spec.rb:46:in `block (5 levels) in <top (required)>'

  5) Property State Transitions active! transitions to active from pending
     Failure/Error: lambda { p.active! }.should_not raise_error
       expected no Exception, got #<ArgumentError: wrong number of arguments (0 for 1)>
     # ./spec/models/property_spec.rb:46:in `block (5 levels) in <top (required)>'

  6) Property State Transitions active! marks escrow reconciled and canceled if escrow -> active
     Failure/Error: p.escrow!
     ArgumentError:
       wrong number of arguments (0 for 1)
     # ./app/models/property.rb:60:in `no_open_escrows'
     # ./spec/models/property_spec.rb:59:in `block (4 levels) in <top (required)>'

  7) Property State Transitions cancel! transitions to cancel from active
     Failure/Error: lambda { p.cancel! }.should_not raise_error
       expected no Exception, got #<ArgumentError: wrong number of arguments (0 for 1)>
     # ./spec/models/property_spec.rb:71:in `block (5 levels) in <top (required)>'

  8) Property State Transitions cancel! transitions to cancel from escrow
     Failure/Error: lambda { p.cancel! }.should_not raise_error
       expected no Exception, got #<ArgumentError: wrong number of arguments (0 for 1)>
     # ./spec/models/property_spec.rb:71:in `block (5 levels) in <top (required)>'

  9) Property State Transitions cancel! transitions to cancel from pending
     Failure/Error: lambda { p.cancel! }.should_not raise_error
       expected no Exception, got #<ArgumentError: wrong number of arguments (0 for 1)>
     # ./spec/models/property_spec.rb:71:in `block (5 levels) in <top (required)>'

  10) Property State Transitions close! transitions to close from escrow
     Failure/Error: lambda { p.close! }.should_not raise_error
       expected no Exception, got #<ArgumentError: wrong number of arguments (0 for 1)>
     # ./spec/models/property_spec.rb:87:in `block (5 levels) in <top (required)>'

  11) Property State Transitions escrow! transitions to escrow from active
     Failure/Error: lambda { p.escrow! }.should_not raise_error
       expected no Exception, got #<ArgumentError: wrong number of arguments (0 for 1)>
     # ./spec/models/property_spec.rb:103:in `block (5 levels) in <top (required)>'

  12) Property State Transitions escrow! creates a new escrow object on escrow!
     Failure/Error: p.escrow!
     ArgumentError:
       wrong number of arguments (0 for 1)
     # ./app/models/property.rb:60:in `no_open_escrows'
     # ./spec/models/property_spec.rb:117:in `block (4 levels) in <top (required)>'

  13) Property State Transitions escrow! cannot go to escrow if another escrow is open
     Failure/Error: p.escrow!
     ArgumentError:
       wrong number of arguments (0 for 1)
     # ./app/models/property.rb:60:in `no_open_escrows'
     # ./spec/models/property_spec.rb:124:in `block (4 levels) in <top (required)>'

  14) Property State Transitions escrow! can go to escrow if previous escrows are canceled
     Failure/Error: lambda { p.escrow! }.should_not raise_error
       expected no Exception, got #<ArgumentError: wrong number of arguments (0 for 1)>
     # ./spec/models/property_spec.rb:133:in `block (4 levels) in <top (required)>'

Finished in 35.44 seconds
297 examples, 14 failures, 1 pending

Failed examples:

rspec ./spec/models/property_spec.rb:26 # Property Methods#current_escrow returns open escrow or none
rspec ./spec/models/property_spec.rb:44 # Property State Transitions active! transitions to active from cancel
rspec ./spec/models/property_spec.rb:44 # Property State Transitions active! transitions to active from escrow
rspec ./spec/models/property_spec.rb:44 # Property State Transitions active! transitions to active from expire
rspec ./spec/models/property_spec.rb:44 # Property State Transitions active! transitions to active from pending
rspec ./spec/models/property_spec.rb:57 # Property State Transitions active! marks escrow reconciled and canceled if escrow -> active
rspec ./spec/models/property_spec.rb:69 # Property State Transitions cancel! transitions to cancel from active
rspec ./spec/models/property_spec.rb:69 # Property State Transitions cancel! transitions to cancel from escrow
rspec ./spec/models/property_spec.rb:69 # Property State Transitions cancel! transitions to cancel from pending
rspec ./spec/models/property_spec.rb:85 # Property State Transitions close! transitions to close from escrow
rspec ./spec/models/property_spec.rb:101 # Property State Transitions escrow! transitions to escrow from active
rspec ./spec/models/property_spec.rb:114 # Property State Transitions escrow! creates a new escrow object on escrow!
rspec ./spec/models/property_spec.rb:122 # Property State Transitions escrow! cannot go to escrow if another escrow is open
rspec ./spec/models/property_spec.rb:128 # Property State Transitions escrow! can go to escrow if previous escrows are canceled

错误出现在这个 function 中,在self.escrows.open.empty中:

  def no_open_escrows
    self.escrows.open.empty?
  end

错误说: wrong number of arguments (0 for 1)

所以我猜你在托管上定义了一个 scope 叫open 从错误看来,scope 现在需要一个您不提供的参数。 或者其他,因为open是一个非常通用的名称,它与新版本的 rails 中的其他内容冲突?

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM