美好的一天,目前我正在努力解决这个错误。
失败/错误:FactoryGirl.create(:订阅) NoMethodError: “AdvtCategories”的未定义方法“attribute_list”:字符串
我无法找到此错误的正确解决方案。我发现的是一些建议,一些列与该类名称相同。没有帮助 我的考试
describe Subscription do
context "validations" do
#it { should validate_presence_of :category_id }
it do
FactoryGirl.create(:category)
FactoryGirl.create(:subscription)
should validate_uniqueness_of( :category_id).scoped_to(:user_id)
end
# TODO validator :category_should_exist
end
#it { should belong_to(:user) }
#it { should belong_to(:category) }
#specify { Subscription.per_page.should eq(20) }
end
工厂:
factory :subscription do
association :category, factory: :category, :class => 'AdvtCategory'
user
end
factory :category do
name "MyString"
alias_name "MyString"
number_of_items 1
type ""
end
更新1 这是一个factory_girl错误。解决它
更新2
创建时出现factory_girl错误(当然是构建过程,所以db错误) 更新的代码
答案 0 :(得分:0)
从一个班级改为另一个班级。
require 'spec_helper'
describe Subscription do
before do
FactoryGirl.create(:subscription)
end
context "validations" do
it { should validate_presence_of :category_id }
it do
should validate_uniqueness_of( :category_id).scoped_to(:user_id).with_message(/уже создана/)
end
end
it { should belong_to(:user) }
it { should belong_to(:category) }
specify { Subscription.per_page.should eq(20) }
end
factory :subscription do
association :category, factory: :advt_category
user
end
factory :advt_category do
name 'Category'
alias_name '1'
end