From 3fa8c4b215c34ab92f45c1e8e545cc29598d53ea Mon Sep 17 00:00:00 2001 From: Sam Lown Date: Fri, 21 May 2010 23:00:19 +0200 Subject: [PATCH] Fixing #property? support for boolean and TrueClass --- lib/couchrest/mixins/properties.rb | 2 +- spec/couchrest/property_spec.rb | 13 +++++++++++++ spec/fixtures/more/course.rb | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/couchrest/mixins/properties.rb b/lib/couchrest/mixins/properties.rb index 744cf95..a8a5b0f 100644 --- a/lib/couchrest/mixins/properties.rb +++ b/lib/couchrest/mixins/properties.rb @@ -119,7 +119,7 @@ module CouchRest end EOS - if property.type == 'boolean' + if ['boolean', TrueClass.to_s.downcase].include?(property.type.to_s.downcase) class_eval <<-EOS, __FILE__, __LINE__ def #{property.name}? if self['#{property.name}'].nil? || self['#{property.name}'] == false || self['#{property.name}'].to_s.downcase == 'false' diff --git a/spec/couchrest/property_spec.rb b/spec/couchrest/property_spec.rb index 7582197..16b14e3 100644 --- a/spec/couchrest/property_spec.rb +++ b/spec/couchrest/property_spec.rb @@ -598,7 +598,20 @@ describe "ExtendedDocument properties" do @course['active'].should equal(value) end end + + it "should respond to requests with ? modifier" do + @course.active = 'false' + @course.active?.should be_false + end end + + describe 'when type primitive is a TrueClass' do + it "should respond to requests with ? modifier" do + @course.very_active = 'true' + @course.very_active?.should be_true + end + end + end end diff --git a/spec/fixtures/more/course.rb b/spec/fixtures/more/course.rb index f340469..72b295e 100644 --- a/spec/fixtures/more/course.rb +++ b/spec/fixtures/more/course.rb @@ -15,6 +15,7 @@ class Course < CouchRest::ExtendedDocument property :started_on, :type => 'Date' property :updated_at, :type => 'DateTime' property :active, :type => 'Boolean' + property :very_active, :type => TrueClass property :klass, :type => 'Class' view_by :title