Fixing #property? support for boolean and TrueClass
This commit is contained in:
parent
81168bdd79
commit
3fa8c4b215
|
@ -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'
|
||||
|
|
|
@ -598,8 +598,21 @@ 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
|
||||
|
||||
describe "a casted model retrieved from the database" do
|
||||
|
|
1
spec/fixtures/more/course.rb
vendored
1
spec/fixtures/more/course.rb
vendored
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue