rspec undefined方法`序列'为1:Fixnum

时间:2015-10-28 18:14:32

标签: ruby-on-rails rspec factory-bot

我正在使用rspec在rails中编写规范测试。我正在测试的其中一个模型上有sequence的属性,它与rspec(从我发现的内容)相冲突,但我无法找到解决方法。

这是我的代码

lessons.rb(工厂)

FactoryGirl.define do 
 factory :lesson do 
    version_id 1
    add_attribute :sequence, 1 # this is the field
    name "Lesson Name"
    description "An Example Lesson Description"
    group_id 1
    content "here is some example context"
    passing_quiz_difficulty 2
    survey_id 1
    status 1
    staff_content "example staff content"
    lesson_type_id 1
  end   
end

方法我正在测试

def second_response?(lesson)
  self.lessons.where('sequence < ?', lesson.sequence).first
end

控制器

def show
  ...
  @part_two = true if @reveal_step.second_response?(@lesson)
  ...
end

rspec堆栈跟踪

Failure/Error: expect(@reveal_step.second_response?(lesson_1.id)).to eql true
NoMethodError: undefined method `sequence' for 1:Fixnum

这个方法在应用程序中工作正常,但我需要为它编写一个测试,我找不到sequence属性的解决方法,我不能把它留下来因为这整个方法和流程应用程序的这一部分取决于sequence attr。有没有人知道要使用的解决方法?或者我可以采用另一种方法吗?任何帮助,将不胜感激。

1 个答案:

答案 0 :(得分:0)

您的期望是将一个数字lesson_1.id传递给需要上课的方法。这个ID没有sequence方法,而课程也是如此。

相关问题