0

良い一日、現在私はこのエラーに苦しんでいます。

失敗/エラー:FactoryGirl.create(:subscription)NoMethodError:「AdvtCategories」の未定義のメソッド `attribute_list':String

このエラーの正しい解決策が見つかりません。私が見つけたのは、いくつかの列がクラスと同じ名前であるという提案でした。私のテストを助けませんでした

 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

UPDATE1 これは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 に答える