This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Instructify | |
# Mark an ActiveRecord model as having a state machine. Requires a | |
# string attribute called `state`. To set the default state for a | |
# class, set a default column value for `state` in the database. | |
# | |
# Use Symbols for all keys and values in state definitions. | |
module Stateful | |
ANY = Object.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
has_one :intro_progress, inverse_of: :skill_progress, autosave: true, required: false, dependent: :destroy | |
has_one :video_challenge_progress, inverse_of: :skill_progress, autosave: true, required: false, dependent: :destroy | |
has_many :step_progresses, -> { includes(:step).order(:order) }, inverse_of: :skill_progress, autosave: true, | |
dependent: :destroy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with assessment_block_index as ( | |
select | |
entity_key as assessment_block_key, | |
parent_key as step_key | |
from entity_indices | |
where entity_type = 'AssessmentBlock' | |
), | |
step_index as ( | |
select | |
entity_key as step_key, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mark an ActiveRecord model as having a state machine. | |
# The state of the model defaults to being stored on an attribute | |
# called `state` or can be specified via the `column` arg to | |
# the `stateful` call. To set the default state for a | |
# class, set a default column value for `state` in the database | |
# or use `initial: true` when defining the initial state. | |
# | |
# Use Symbols for all keys and values in state definitions. | |
module Stateful |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
RSpec.describe Stateful do | |
let(:model_class) do | |
Struct.new(:status, :saved, :scopes, :running_at, :finished_at, :finished_count, :privileged) do | |
include Stateful | |
def self.scope(*args) | |
define_singleton_method(args.first) {} | |
end |
OlderNewer