Permalink
Browse files

Version 1.3.1 -- Compatibility with Ruby 1.9.3: fixed YAML deserializ…

…ation issue.
  • Loading branch information...
1 parent 9c52d55 commit 366aa4128c33c56459298dd4218c788ee6083313 @ihoka ihoka committed Feb 3, 2012
Showing with 152 additions and 26 deletions.
  1. +1 −0 .rspec
  2. +2 −2 .rvmrc
  3. +12 −1 Gemfile
  4. +25 −8 Gemfile.lock
  5. +26 −14 hashie-model.gemspec
  6. +10 −0 lib/hashie_model/base.rb
  7. +24 −0 lib/hashie_model/spec/matchers.rb
  8. +1 −1 lib/hashie_model/version.rb
  9. +51 −0 spec/hashie_model/base_spec.rb
View
@@ -0,0 +1 @@
+--color
View
@@ -1,2 +1,2 @@
-rvm use 1.9.2@zencash --create
-rvm wrapper 1.9.2@zencash textmate
+rvm use 1.9.3@zencash --create
+rvm wrapper 1.9.3@zencash textmate
View
@@ -1,7 +1,18 @@
source 'http://rubygems.org'
group :development do
- gem 'rspec', '~> 2.3.0'
+ # Ruby 1.9.3 requires special dependencies
+ #
+ # Install Ruby 1.9.3 with:
+ # * rvm install 1.9.3
+ # * rvm use 1.9.3
+ # * bash < <(curl -L https://raw.github.com/gist/1422357)
+ gem 'linecache19', '~> 0.5.13'
+ gem 'ruby-debug-base19', '~> 0.11.26'
+
+ gem 'ruby-debug19', '>= 0', :require => 'ruby-debug'
+
+ gem 'rspec', '~> 2.8.0'
gem 'shoulda-matchers', '~> 1.0.0.beta3'
gem 'yard', '>= 0.7.0'
gem 'bundler', '~> 1.0.0'
View
@@ -7,7 +7,9 @@ GEM
i18n (~> 0.6)
activesupport (3.1.1)
multi_json (~> 1.0)
+ archive-tar-minitar (0.5.2)
builder (3.0.0)
+ columnize (0.3.6)
diff-lcs (1.1.3)
git (1.2.5)
growl (1.0.3)
@@ -26,20 +28,32 @@ GEM
bundler (~> 1.0)
git (>= 1.2.5)
rake
+ linecache19 (0.5.13)
+ ruby_core_source (>= 0.1.4)
money (3.7.1)
i18n (~> 0.4)
multi_json (1.0.3)
rake (0.9.2.2)
rb-fsevent (0.4.3.1)
rcov (0.9.11)
- rspec (2.3.0)
- rspec-core (~> 2.3.0)
- rspec-expectations (~> 2.3.0)
- rspec-mocks (~> 2.3.0)
- rspec-core (2.3.1)
- rspec-expectations (2.3.0)
+ rspec (2.8.0)
+ rspec-core (~> 2.8.0)
+ rspec-expectations (~> 2.8.0)
+ rspec-mocks (~> 2.8.0)
+ rspec-core (2.8.0)
+ rspec-expectations (2.8.0)
diff-lcs (~> 1.1.2)
- rspec-mocks (2.3.0)
+ rspec-mocks (2.8.0)
+ ruby-debug-base19 (0.11.26)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby_core_source (>= 0.1.4)
+ ruby-debug19 (0.11.6)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby-debug-base19 (>= 0.11.19)
+ ruby_core_source (0.1.5)
+ archive-tar-minitar (>= 0.5.2)
shoulda-matchers (1.0.0.beta3)
thor (0.14.6)
yajl-ruby (1.0.0)
@@ -58,10 +72,13 @@ DEPENDENCIES
guard-rspec
guard-yard
jeweler (~> 1.6.4)
+ linecache19 (~> 0.5.13)
money (>= 3.7.1)
rb-fsevent
rcov
- rspec (~> 2.3.0)
+ rspec (~> 2.8.0)
+ ruby-debug-base19 (~> 0.11.26)
+ ruby-debug19
shoulda-matchers (~> 1.0.0.beta3)
yajl-ruby (>= 0.8.0)
yard (>= 0.7.0)
View
@@ -4,14 +4,14 @@
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
- s.name = %q{hashie-model}
- s.version = "1.3.0"
+ s.name = "hashie-model"
+ s.version = "1.3.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = [%q{ZenCash.com}]
- s.date = %q{2012-01-24}
- s.description = %q{Hashie2 + ActiveModel 3, offering declared properties, validations, JSON serialization/deserialization}
- s.email = %q{istvan@zencash.com}
+ s.authors = ["ZenCash.com"]
+ s.date = "2012-02-03"
+ s.description = "Hashie2 + ActiveModel 3, offering declared properties, validations, JSON serialization/deserialization"
+ s.email = "istvan@zencash.com"
s.extra_rdoc_files = [
"LICENSE.txt",
"README.md"
@@ -43,11 +43,11 @@ Gem::Specification.new do |s|
"vendor/hashie2/lib/hashie2/trash.rb",
"vendor/hashie2/lib/hashie2/version.rb"
]
- s.homepage = %q{http://github.com/doublewide/hashie-model}
- s.licenses = [%q{MIT}]
- s.require_paths = [%q{lib}]
- s.rubygems_version = %q{1.8.6}
- s.summary = %q{Hashie2 + ActiveModel 3.x}
+ s.homepage = "http://github.com/doublewide/hashie-model"
+ s.licenses = ["MIT"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = "1.8.15"
+ s.summary = "Hashie2 + ActiveModel 3.x"
if s.respond_to? :specification_version then
s.specification_version = 3
@@ -57,7 +57,11 @@ Gem::Specification.new do |s|
s.add_runtime_dependency(%q<activesupport>, [">= 3.1.1"])
s.add_runtime_dependency(%q<activemodel>, [">= 3.1.1"])
s.add_runtime_dependency(%q<money>, [">= 3.7.1"])
- s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
+ s.add_runtime_dependency(%q<psych>, [">= 1.2.2"])
+ s.add_development_dependency(%q<linecache19>, ["~> 0.5.13"])
+ s.add_development_dependency(%q<ruby-debug-base19>, ["~> 0.11.26"])
+ s.add_development_dependency(%q<ruby-debug19>, [">= 0"])
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
s.add_development_dependency(%q<shoulda-matchers>, ["~> 1.0.0.beta3"])
s.add_development_dependency(%q<yard>, [">= 0.7.0"])
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -74,7 +78,11 @@ Gem::Specification.new do |s|
s.add_dependency(%q<activesupport>, [">= 3.1.1"])
s.add_dependency(%q<activemodel>, [">= 3.1.1"])
s.add_dependency(%q<money>, [">= 3.7.1"])
- s.add_dependency(%q<rspec>, ["~> 2.3.0"])
+ s.add_dependency(%q<psych>, [">= 1.2.2"])
+ s.add_dependency(%q<linecache19>, ["~> 0.5.13"])
+ s.add_dependency(%q<ruby-debug-base19>, ["~> 0.11.26"])
+ s.add_dependency(%q<ruby-debug19>, [">= 0"])
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
s.add_dependency(%q<shoulda-matchers>, ["~> 1.0.0.beta3"])
s.add_dependency(%q<yard>, [">= 0.7.0"])
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -92,7 +100,11 @@ Gem::Specification.new do |s|
s.add_dependency(%q<activesupport>, [">= 3.1.1"])
s.add_dependency(%q<activemodel>, [">= 3.1.1"])
s.add_dependency(%q<money>, [">= 3.7.1"])
- s.add_dependency(%q<rspec>, ["~> 2.3.0"])
+ s.add_dependency(%q<psych>, [">= 1.2.2"])
+ s.add_dependency(%q<linecache19>, ["~> 0.5.13"])
+ s.add_dependency(%q<ruby-debug-base19>, ["~> 0.11.26"])
+ s.add_dependency(%q<ruby-debug19>, [">= 0"])
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
s.add_dependency(%q<shoulda-matchers>, ["~> 1.0.0.beta3"])
s.add_dependency(%q<yard>, [">= 0.7.0"])
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -42,6 +42,16 @@ def validates_associated(*attr_names)
end
end
+ def init_with(coder)
+ coder.map.each do |k, v|
+ self.send(:"#{k}=", v)
+ end
+ end
+
+ def encode_with(coder)
+ coder.represent_map(coder.tag, self)
+ end
+
def attributes_before_type_cast
@attributes_before_type_cast ||= {}
end
@@ -63,6 +63,30 @@
end
end
+RSpec::Matchers.define :yaml_serialize_to do |yaml|
+ description { "serialize to YAML" }
+ expected = YAML.load(yaml)
+
+ match do |object|
+ actual = YAML.load(object.to_yaml)
+ actual == expected
+ end
+
+ failure_message_for_should do |object|
+ actual = YAML.load(object.to_yaml)
+ "expected that #{object} would serialize to #{expected.pretty_inspect}Diff:#{RSpec::Expectations.differ.diff_as_object(actual, expected)}"
+ end
+end
+
+RSpec::Matchers.define :yaml_deserialize_from do |yaml|
+ description { "deserialize from YAML" }
+
+ match do |object|
+ new_object = YAML.load(yaml)
+ new_object.is_a?(object.class) && new_object.eql?(object)
+ end
+end
+
RSpec::Matchers.define :act_as_array do |array_klass|
match do |object|
klass = object.class
@@ -2,7 +2,7 @@ module HashieModel
module Version
MAJOR = 1
MINOR = 3
- PATCH = 0
+ PATCH = 1
BUILD = nil
STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
@@ -127,4 +127,55 @@ class BarModel < HashieModel::Base
it { should serialize_to(json) }
it { should deserialize_from(json) }
end
+
+ describe "YAML serialization" do
+ let(:yaml) {
+ <<-YAML.gsub(/^\s{6}/m, '')
+ --- !ruby/object:BarModel
+ must_have: here
+ cash: !ruby/object:HashieModel::Money
+ cents: 4200
+ currency: !ruby/object:Money::Currency
+ id: :usd
+ priority: 1
+ iso_code: USD
+ name: United States Dollar
+ symbol: $
+ subunit: Cent
+ subunit_to_unit: 100
+ symbol_first: true
+ html_entity: $
+ decimal_mark: .
+ thousands_separator: ! ','
+ bank: &70263216595100 !ruby/object:Money::Bank::VariableExchange
+ rounding_method:
+ rates: {}
+ mutex: !ruby/object:Mutex {}
+ foos:
+ - !ruby/object:FooModel
+ x: x-value
+ y: !ruby/object:HashieModel::Money
+ cents: 7595
+ currency: !ruby/object:Money::Currency
+ id: :usd
+ priority: 1
+ iso_code: USD
+ name: United States Dollar
+ symbol: $
+ subunit: Cent
+ subunit_to_unit: 100
+ symbol_first: true
+ html_entity: $
+ decimal_mark: .
+ thousands_separator: ! ','
+ bank: *70263216595100
+ YAML
+ }
+
+ subject { bar }
+
+ it { should yaml_serialize_to(yaml) }
+ it { should yaml_deserialize_from(yaml) }
+
+ end
end

0 comments on commit 366aa41

Please sign in to comment.