- Notifications
You must be signed in to change notification settings - Fork38
Support STI and inheritance(with test)#34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
@raskhadafi@unasuke Nice, but what's gonna happen if we created multiple STI child classes, and then declared enums on each of these? e.g. classBug <ActiveRecord::Baseself.abstract_class=trueendclassNormalBug <Bugenumstatus:{unassigned:0,assigned:1,resolved:2,closed:3}do ...endendclassCriticalBug <Bugenumstatus:{unassigned:0,assigned:1,resolved:2,closed:3,released:4}do ...endend So, maybe we can fallback to Moreover, there can be enums with the same name on BOTH parent and children classes, and I'm not sure what's the desired behavior in such case. |
I confirmed the current behavior of stateful_enum and it seems good for me. How do you think@amatsuda ? Is it test cases lack some edge-case? and...@raskhadafi, do you think about this? classBug <ActiveRecord::Baseenumstatus:{unassigned:0,assigned:1,resolved:2,closed:3}doevent:assigndotransition:unassigned=>:assignedendendendclassNormalBug <Bugenumstatus:{unassigned:0,assigned:1,resolved:2,closed:3}doevent:assigndotransition:closed=>:assignedendevent:resolvedotransition[:unassigned,:assigned]=>:resolvedendendendclassCriticalBug <Bugenumstatus:{unassigned:0,assigned:1,resolved:2,closed:3,released:4}doevent:assigndotransition:closed=>:assignedendevent:releasedotransition:resolved=>:releasedendendendclassBugTest <Minitest::Testdeftest_bug_cannnot_resolvebug=Bug.create!(status::unassigned)assert_raises(NoMethodError)dobug.resolveendenddeftest_normal_bug_can_resolvenormal_bug=NormalBug.create!(status::unassigned)normal_bug.resolveassert_equal'resolved',normal_bug.statusenddeftest_unassigned_critical_big_cannot_assigncritical_bug=CriticalBug.create!(status::unassigned)critical_bug.assignassert_equal'unassigned',critical_bug.statusendend sample code(full)# frozen_string_literal: truebeginrequire"bundler/inline"rescueLoadError=>e $stderr.puts"Bundler version 1.10 or later is required. Please update your Bundler"raiseeendgemfile(true)dosource"https://rubygems.org"git_source(:github){ |repo|"https://github.com/#{repo}.git"}#gem "rails", github: "rails/rails"gem"rails",'5.2.0'gem"sqlite3"gem'stateful_enum',git:'https://github.com/unasuke/stateful_enum.git',ref:'6f6e18b1d'endrequire"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.definedocreate_table:bugs,force:truedo |t|t.integer:statust.string:typeendendclassBug <ActiveRecord::Baseenumstatus:{unassigned:0,assigned:1,resolved:2,closed:3}doevent:assigndotransition:unassigned=>:assignedendendendclassNormalBug <Bugenumstatus:{unassigned:0,assigned:1,resolved:2,closed:3}doevent:assigndotransition:closed=>:assignedendevent:resolvedotransition[:unassigned,:assigned]=>:resolvedendendendclassCriticalBug <Bugenumstatus:{unassigned:0,assigned:1,resolved:2,closed:3,released:4}doevent:assigndotransition:closed=>:assignedendevent:releasedotransition:resolved=>:releasedendendendclassBugTest <Minitest::Testdeftest_bug_cannnot_resolvebug=Bug.create!(status::unassigned)assert_raises(NoMethodError)dobug.resolveendenddeftest_normal_bug_can_resolvenormal_bug=NormalBug.create!(status::unassigned)normal_bug.resolveassert_equal'resolved',normal_bug.statusenddeftest_unassigned_critical_big_cannot_assigncritical_bug=CriticalBug.create!(status::unassigned)critical_bug.assignassert_equal'unassigned',critical_bug.statusendend |
dups#29 .But I wrote test.
Original pull request description is below.
If use stateful_enum on STI model, raise that error.