aasm / aasm/aasm

Describe how to use it with factory_bot

Open
#523 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
5.2k
Forks
644
PR merge metrics
No merged PRs in 30d

Description

I use Factory_bot with rspec.

How can I create an object with different state other the initial?

class Job
  include AASM

  aasm do
    state :sleeping, :initial => true
    state :running, :cleaning

    event :run do
      transitions :from => :sleeping, :to => :running
    end

    event :clean do
      transitions :from => :running, :to => :cleaning
    end

    event :sleep do
      transitions :from => [:running, :cleaning], :to => :sleeping
    end
  end
end

How to define a factory to create objects with different states?

FactoryBot.define do
  factory :job do

    factory :job_running do
      # how can I create a job with the state runing?

    end
    factory :job_cleaning do
      # how can I create a job with the state cleaning?

    end

  end
end

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the linked FactoryBot getting-started guide and AASM's state and event usage. Document how factories can create Job objects in the running and cleaning states, using the example in the issue; done means the documentation answers both factory definitions without requiring follow-up clarification.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.