Sha256: ff0bc6751c0a80f1c6c9f20808e9ffd26e7bddcd35505cae5ff40ebb44d14340
Contents?: true
Size: 1.09 KB
Versions: 2
Compression:
Stored size: 1.09 KB
Contents
# frozen_string_literals: true module Jobshop class Thing < ApplicationRecord self.primary_keys = %i[ organization_id thing_id ] after_initialize { self.thing_id ||= SecureRandom.uuid if new_record? } belongs_to :organization, inverse_of: :things belongs_to :collection, inverse_of: :things, foreign_key: %i[ organization_id collection_id ] validates :name, presence: true, uniqueness: { scope: :organization_id, case_sensitive: false } validates :custom_fields, json: { message: -> (errors) { errors }, schema: -> { my_schema }, options: { errors_as_objects: true } } def my_schema # TODO: Because shoulda-matchers doesn't properly recreate the test # subject this has the return {} when collection is nil. Collection will # only ever be nil during this test. Once the proper fk constraint is # added to the db, the test in question will raise an exception and a new # solution will need to be found. collection && collection.schema || {} end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
jobshop-0.0.167 | app/models/jobshop/thing.rb |
jobshop-0.0.163 | app/models/jobshop/thing.rb |