aasm / aasm/aasm

Bang methods don't transition new_records when skip_validation_on_save is true

Open
#242 3 comments 0 reactions 1 assignee View on GitHub

@alto is already working on this.

Since Jul 21, 2015.

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

Description

It will set the value back to old_value as the update_all won't match any records where(self.class.primary_key => self.id) as self.id doesn't exist

See https://github.com/aasm/aasm/blob/master/lib/aasm/persistence/active_record_persistence.rb#L87-L89

Makes some transitions harder from other state machine gems

Example:

class Order < ActiveRecord::Base
  aasm(skip_validation_on_save: true) do
    state :new, initial: true
    state :shipped

    event :process do
      transitions(from: :new, to: :shipped)
    end
  end
end

spec

let(:order) { Order.new }

it "should change the status when a bang method is called" do
  expect { order.process! }.to change(order, :status).from('new').to('shipped')
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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.