Pregunta

I have a simple model with sequence as a attribute as integer. When I am setting sequence as 1 it fail the simple test case ie:

  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

Factories:

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

Uncommenting sequence fails the test case with issue ie:

   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
¿Fue útil?

Solución

As Peter pointed out, sequence is a FactoryGirl method.

Try this for setting the sequence attribute:

FactoryGirl.define do
  factory :math_fact_attempt_data do
    add_attribute :sequence, 1
  end
end

Otros consejos

sequence is a FactoryGirl method which expects a symbol as it's first parameter. That's why you're getting the error you're getting.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top