我刚刚在我的开发mac上将rails从3.0.1升级到3.0.7。已尝试运行rspec (2.6.0) (使用factory_girl_rails 1.0.1),但在模型使用classy_enum (0.9.1) gem进行状态实现的所有测试中都出现错误。Rails本身运行没有问题,但rspec测试失败。不知道是什么导致了错误。
这里的确切错误是:
1) Billboard should create a new instance given valid attributes
Failure/Error: @etype = Factory(:etype)
TypeError:
Cannot visit EtypeGroupActivity
# ./spec/models/billboard_spec.rb:6:in `block (2 levels) in <top (required)>'Etype模型代码:
class Etype < ActiveRecord::Base
attr_accessible :code, :group, :order, :logo
classy_enum_attr :group, :enum => :etype_group
delegate :group_name, :to => :groupEtype_group枚举代码:
class EtypeGroup < ClassyEnum::Base
enum_classes :event, :event_session, :activity, :venue, :venue_space
def group_name
""
end
end
class EtypeGroupEvent < EtypeGroup
def group_name
I18n.t('etypes.groups.event')
end
end更新:
billboard_spec代码为:
require 'spec_helper'
describe Billboard do
before(:each) do
@user = Factory(:user)
@etype = Factory(:etype)
@attr = { :title => "First Keynote",
:etype_id => @etype,
:summary => "This keynote will open our event" }
end
it "should create a new instance given valid attributes" do
@user.billboards.create!(@attr)
end
end在factories.db中,我有:
Factory.define :etype do |etype|
etype.code "keynote"
etype.group "activity"
etype.order 10
end发布于 2011-06-29 11:00:32
问题已从ClassyEnum version 1.0.0开始解决
https://stackoverflow.com/questions/6464221
复制相似问题