Skip to content

Instantly share code, notes, and snippets.

@Edouard-chin
Created October 18, 2018 03:38
Show Gist options
  • Save Edouard-chin/6abff4cd230006a2c22cb341c198e34e to your computer and use it in GitHub Desktop.
Save Edouard-chin/6abff4cd230006a2c22cb341c198e34e to your computer and use it in GitHub Desktop.
State machine initial state broken after rails/rails@366e7e3
# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails", branch: "5-2-stable"
gem "sqlite3"
gem 'state_machines-activerecord'
end
require "active_record"
require "minitest/autorun"
require "logger"
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :posts, force: true do |t|
t.string :status
t.string :name
end
end
class Post < ActiveRecord::Base
state_machine :status, initial: :pending do
event :something do
transition :pending => :completed
end
end
end
class BugTest < Minitest::Test
def test_initial_state
post = Post.create_with(status: 'completed').find_or_create_by!(name: 'foo')
assert_equal "completed", post.status
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment