-
-
Save RaVbaker/5d076449247e5e0fc453 to your computer and use it in GitHub Desktop.
Corrected version of initial repo by @Tuhaj
This file contains hidden or 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
unless File.exist?('Gemfile') | |
File.write('Gemfile', <<-GEMFILE) | |
source 'https://rubygems.org' | |
gem 'activerecord', '4.2.1' | |
gem 'state_machines' | |
gem 'state_machines-activerecord' | |
gem 'sqlite3' | |
gem 'minitest' | |
GEMFILE | |
system 'bundle' | |
end | |
require 'bundler' | |
Bundler.setup(:default) | |
# Activate the gem you are reporting the issue against. | |
require 'active_record' | |
require 'minitest/autorun' | |
require 'logger' | |
require 'state_machines' | |
require 'state_machines-activerecord' | |
# Ensure backward compatibility with Minitest 4 | |
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test) | |
# 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 :lights, force: true do |t| | |
t.string :state | |
end | |
end | |
class Light < ActiveRecord::Base | |
state_machine initial: :green do | |
state :green | |
state :yellow | |
state :red | |
end | |
end | |
class BugTest < Minitest::Test | |
def test_initial_state | |
light = Light.new | |
assert_equal 'green', light.state | |
light.save! | |
light = Light.find(light.id) | |
refute_equal nil, light.state | |
assert_equal 'green', light.state | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment