Permalink
Browse files

Fixes saving & reloading models that assign with enum class

  • Loading branch information...
1 parent fc1a89b commit 859bd48b7bd2bd7d3692e968c477db78eb6b1426 @beerlington beerlington committed Jan 13, 2013
Showing with 13 additions and 2 deletions.
  1. +5 −0 CHANGELOG.md
  2. +1 −1 lib/classy_enum/active_record.rb
  3. +1 −1 lib/classy_enum/version.rb
  4. +6 −0 spec/classy_enum/active_record_spec.rb
View
@@ -1,5 +1,10 @@
# ClassyEnum Changelog
+## 3.1.3
+
+* Fixes saving and reloading ActiveRecord models that assign enum using
+ class
+
## 3.1.2
* Allow enum property to be assigned using enum class. Previously it
@@ -45,7 +45,7 @@ def classy_enum_attr(attribute, options={})
# Define setter method that accepts string, symbol, instance or class for member
define_method "#{attribute}=" do |value|
if value.class == Class && value < ClassyEnum::Base
- value = value.new
+ value = value.new.to_s
elsif value.present?
value = value.to_s
end
@@ -1,3 +1,3 @@
module ClassyEnum
- VERSION = "3.1.2"
+ VERSION = "3.1.3"
end
@@ -48,6 +48,12 @@ class OtherDog < ActiveRecord::Base
it { should be_valid }
its(:breed) { should be_a(Breed::GoldenRetriever) }
its('breed.allow_blank') { should be_false }
+
+ it 'stores the enum as a valid string representation' do
+ subject.save!
+ subject.reload
+ subject.breed.should be_a(Breed::GoldenRetriever)
+ end
end
end

0 comments on commit 859bd48

Please sign in to comment.