diff --git a/CHANGELOG b/CHANGELOG index 540fcb8..88355cc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ * Specs and bug fixes for the ActiveRecordPersistence, keeping persistence columns in sync Allowing for nil values in states for active record + Only set state to default state before_validation_on_create + New rake task to uninstall, build and reinstall the gem (useful for development) New non-(!) methods that allow for firing events without persisting [Jeff Dean] * Added aasm_states_for_select that will return a select friendly collection of states. diff --git a/Rakefile b/Rakefile index 9ea235b..e60794d 100644 --- a/Rakefile +++ b/Rakefile @@ -22,9 +22,9 @@ end $package_version = CURRENT_VERSION PKG_FILES = FileList['[A-Z]*', - 'lib/**/*.rb', - 'doc/**/*' - ] +'lib/**/*.rb', +'doc/**/*' +] desc 'Generate documentation for the acts as state machine plugin.' rd = Rake::RDocTask.new(:rdoc) do |rdoc| @@ -45,8 +45,8 @@ else s.version = $package_version s.summary = 'State machine mixin for Ruby objects' s.description = <<-EOF -AASM is a continuation of the acts as state machine rails plugin, built for plain Ruby objects. -EOF + AASM is a continuation of the acts as state machine rails plugin, built for plain Ruby objects. + EOF s.files = PKG_FILES.to_a s.require_path = 'lib' s.has_rdoc = true @@ -73,7 +73,7 @@ else t.rcov = true t.rcov_opts = ['--exclude', 'spec'] end - + desc "Run all examples" Spec::Rake::SpecTask.new('spec') do |t| t.spec_files = FileList['spec/**/*.rb'] @@ -82,4 +82,13 @@ else end end +if !defined?(Gem) + puts "Package target requires RubyGEMs" +else + desc "sudo gem uninstall aasm && rake gem && sudo gem install pkg/aasm-3.0.0.gem" + task :reinstall do + puts `sudo gem uninstall aasm && rake gem && sudo gem install pkg/aasm-3.0.0.gem` + end +end + task :default => [:spec] diff --git a/lib/persistence/active_record_persistence.rb b/lib/persistence/active_record_persistence.rb index 42b3c79..9488143 100644 --- a/lib/persistence/active_record_persistence.rb +++ b/lib/persistence/active_record_persistence.rb @@ -11,6 +11,10 @@ module AASM # * WriteState # * WriteStateWithoutPersistence # + # Adds + # + # before_validation_on_create :aasm_ensure_initial_state + # # As a result, it doesn't matter when you define your methods - the following 2 are equivalent # # class Foo < ActiveRecord::Base @@ -94,13 +98,20 @@ module AASM private - # Called from before_validation_on_create to ensure - # that if there is a nil value in the underlying aasm_state - # column, the initial state is used instead + # Ensures that if the aasm_state column is nil and the record is new + # that the initial state gets populated before validation on create # # foo = Foo.new - # foo.save - # foo.aasm_state # => the initial state + # foo.aasm_state # => nil + # foo.valid? + # foo.aasm_state # => "open" (where :open is the initial state) + # + # + # foo = Foo.find(:first) + # foo.aasm_state # => 1 + # foo.aasm_state = nil + # foo.valid? + # foo.aasm_state # => nil # def aasm_ensure_initial_state send("#{self.class.aasm_column}=", self.aasm_current_state.to_s)