0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【RSpec】ActiveRecordを継承してないクラスでテストが通らないとき

Posted at

ActiveRecordを継承しているクラスで標準実装されている==メソッドが動き、newしたインスタンスが本当に一意でなくても同じものと判断されてテストが通る。
今回はActiveRecordを継承してないクラスのモデルで==メソッドをオーバーライドし、意図的にテストを通した。

class Book
  include ActiveModel::Model
...
  def ==(comparison_object)
    super || (comparison_object.instance_of?(self.class) && attendances == comparison_object.attendances)
  end
  alias :eql? :==
end

##参考
https://github.com/rails/rails/blob/c7dfe33f3958295a857d7bfb1070302e5b7429ff/activerecord/lib/active_record/core.rb#L411

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?