gpt4 book ai didi

ruby-on-rails - 未定义的方法 `to_sym' 为 1 :Fixnum

转载 作者:行者123 更新时间:2023-12-03 11:12:40 25 4
gpt4 key购买 nike

我有一个简单的模型,其中序列作为整数属性。当我将序列设置为 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

最佳答案

正如 Peter 所指出的,sequence 是一个 FactoryGirl 方法。

试试这个来设置序列属性:

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

关于ruby-on-rails - 未定义的方法 `to_sym' 为 1 :Fixnum,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20758307/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com