TrueClass Rails的未定义方法ID

时间:2011-09-09 04:01:50

标签: ruby-on-rails-3 rspec

  def can_save(board,role)
    if ar_user = already_registered?(email) || user = self.save
      Participant.make(ar_user||user, board, role)
    end
    user
  end

我在上面做了这个rspec测试:

it "should return the user if the user is not already registered" do
     lambda do
      user = @new_user.can_save(@board, "Manager")
    end.should change(User,:count).by(1)
   end

我收到此错误:

  undefined method `id' for true:TrueClass

为什么?

1 个答案:

答案 0 :(得分:8)

save方法返回true或false,而不是保存的对象实例。