请帮我调试Rails 3.1。它通过3.0。谢谢。
$ rspec spec / models
更新:托管模式
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
模型
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
答案 0 :(得分:0)
错误在此函数中,在self.escrows.open.empty
:
def no_open_escrows
self.escrows.open.empty?
end
错误说明:wrong number of arguments (0 for 1)
所以我猜你已经在名为open
的托管上定义了一个范围?从错误中看,该范围现在需要一个您不提供的参数。或者,因为open
是一个非常通用的名称,它与新版本中的rails中的其他东西冲突?
希望这有帮助。