It is a minimal base class that acts like an ActiveRecord without a matching database table. It has basic methods to support polymorphic association. Nothing special here :)
Add this line to your application's Gemfile:
gem 'mock_record'
And then execute:
$ bundle
Or install it yourself as:
$ gem install mock_record
Inherit the MockRecord::Base
class
class Square < MockRecord::Base
end
Assuming you have a polymorhic association
class Poly < ApplicationRecord
belongs_to :subject, polymorphic: true
end
then you can now use our Square
as a the subject of Poly
Poly.create(subject: Square.new)
This will create a Poly with subject_id
of 0
and subject_type
of Square
It is the same as
Poly.create(subject_id: 0, subject_type: "Square")
Bug reports and pull requests are welcome on GitHub at https://github.com/neume/mock_record. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.