mirror of
https://github.com/thoughtbot/shoulda-matchers.git
synced 2022-11-09 12:01:38 -05:00
Adding comment on define_enum_for_matcher.rb
[ci skip]
This commit is contained in:
parent
359339a4cd
commit
c47e6db739
1 changed files with 32 additions and 5 deletions
|
@ -2,7 +2,7 @@ module Shoulda
|
||||||
module Matchers
|
module Matchers
|
||||||
module ActiveRecord
|
module ActiveRecord
|
||||||
# The `define_enum_for` matcher is used to test that the `enum` macro has
|
# The `define_enum_for` matcher is used to test that the `enum` macro has
|
||||||
# been used to decorate an attribute with enum methods.
|
# been used to decorate an attribute with enum capabilities.
|
||||||
#
|
#
|
||||||
# class Process < ActiveRecord::Base
|
# class Process < ActiveRecord::Base
|
||||||
# enum status: [:running, :stopped, :suspended]
|
# enum status: [:running, :stopped, :suspended]
|
||||||
|
@ -22,8 +22,8 @@ module Shoulda
|
||||||
#
|
#
|
||||||
# ##### with_values
|
# ##### with_values
|
||||||
#
|
#
|
||||||
# Use `with_values` to test that the attribute has been defined with a
|
# Use `with_values` to test that the attribute can only receive a certain
|
||||||
# certain set of possible values.
|
# set of possible values.
|
||||||
#
|
#
|
||||||
# class Process < ActiveRecord::Base
|
# class Process < ActiveRecord::Base
|
||||||
# enum status: [:running, :stopped, :suspended]
|
# enum status: [:running, :stopped, :suspended]
|
||||||
|
@ -43,10 +43,37 @@ module Shoulda
|
||||||
# with_values([:running, :stopped, :suspended])
|
# with_values([:running, :stopped, :suspended])
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
|
# If the values backing your enum attribute are arbitrary instead of a
|
||||||
|
# series of integers starting from 0, pass a hash to `with_values` instead
|
||||||
|
# of an array:
|
||||||
|
#
|
||||||
|
# class Process < ActiveRecord::Base
|
||||||
|
# enum status: {
|
||||||
|
# running: 0,
|
||||||
|
# stopped: 1,
|
||||||
|
# suspended: 3,
|
||||||
|
# other: 99
|
||||||
|
# }
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# # RSpec
|
||||||
|
# RSpec.describe Process, type: :model do
|
||||||
|
# it do
|
||||||
|
# should define_enum_for(:status).
|
||||||
|
# with_values(running: 0, stopped: 1, suspended: 3, other: 99)
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# # Minitest (Shoulda)
|
||||||
|
# class ProcessTest < ActiveSupport::TestCase
|
||||||
|
# should define_enum_for(:status).
|
||||||
|
# with_values(running: 0, stopped: 1, suspended: 3, other: 99)
|
||||||
|
# end
|
||||||
|
#
|
||||||
# ##### backed_by_column_of_type
|
# ##### backed_by_column_of_type
|
||||||
#
|
#
|
||||||
# Use `backed_by_column_of_type` to test that the attribute is of a
|
# Use `backed_by_column_of_type` when the column backing your column type
|
||||||
# certain column type. (The default is `:integer`.)
|
# is a string instead of an integer:
|
||||||
#
|
#
|
||||||
# class LoanApplication < ActiveRecord::Base
|
# class LoanApplication < ActiveRecord::Base
|
||||||
# enum status: {
|
# enum status: {
|
||||||
|
|
Loading…
Reference in a new issue