2

シーケンスを属性として整数として持つ単純なモデルがあります。シーケンスを 1 に設定すると、単純なテスト ケースに失敗します。

  context 'MathFactAttemptData' do
    it 'should insert rows' do
      math_fact_attempt_data  = FactoryGirl.build :math_fact_attempt_data

      @params[:request_params]         = {
          user_data: {
              math_fact_attempt_data: [JSON.parse(math_fact_attempt_data.to_json)]
          }
      }

      initial_math_fact_attempt_data_count = MathFactAttemptData.unscoped.count

      post api_v3_user_data_path, @params
      response.should be_success

      response_body = JSON.parse response.body
      response_body['user_data'].should be_nil
      response_body['seed_data'].should be_nil

      MathFactAttemptData.unscoped.count.should == initial_math_fact_attempt_data_count + 1

    end
  end

工場:

factory :math_fact_attempt_data do
 association :user, factory: :student
 association :math_fact_attempt, factory: :math_fact_attempt
 association :problem_type, factory: :problem_type
 num1 1
 num2 1
 correct_answer 1
 response 1
 correct 1
 #sequence 1
 time_spent 1
 choice_type "MyString"
 selected_operator "MyString"
end

シーケンスのコメントを解除すると、次の問題でテスト ケースが失敗します。

   API v3 POST /user_data.json Entities MathFactAttemptData should insert rows
         Failure/Error: math_fact_attempt_data  = FactoryGirl.build :math_fact_attempt_data
         NoMethodError:
           undefined method `to_sym' for 1:Fixnum
         # ./spec/requests/api/v3/post_user_data_spec.rb:1116:in `block (5 levels) in <top (required)>'

    Finished in 3.7 seconds
    1 example, 1 failure

    Failed examples:

    rspec ./spec/requests/api/v3/post_user_data_spec.rb:1115 # API v3 POST /user_data.json Entities MathFactAttemptData should insert rows
4

2 に答える 2

8

Peter が指摘したようにsequence、FactoryGirl メソッドです。

シーケンス属性を設定するには、これを試してください:

FactoryGirl.define do
  factory :math_fact_attempt_data do
    add_attribute :sequence, 1
  end
end
于 2013-12-24T11:49:34.243 に答える