0

美好的一天,目前我正在努力解决这个错误。

失败/错误:FactoryGirl.create(:subscription) 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 错误)更新了代码

4

1 回答 1

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
于 2012-10-11T19:02:50.843 回答