samlown-couchrest_extended_document 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ module CouchRest
8
8
  # Same as CouchRest::Document but with properties and validations
9
9
  class ExtendedDocument < Document
10
10
 
11
- VERSION = "1.0.3"
11
+ VERSION = "1.0.4"
12
12
 
13
13
  include CouchRest::Mixins::Callbacks
14
14
  include CouchRest::Mixins::DocumentQueries
@@ -119,10 +119,10 @@ module CouchRest
119
119
  end
120
120
  EOS
121
121
 
122
- if property.type == 'boolean'
122
+ if ['boolean', TrueClass.to_s.downcase].include?(property.type.to_s.downcase)
123
123
  class_eval <<-EOS, __FILE__, __LINE__
124
124
  def #{property.name}?
125
- if self['#{property.name}'].nil? || self['#{property.name}'] == false || self['#{property.name}'].to_s.downcase == 'false'
125
+ if self['#{property.name}'].nil? || self['#{property.name}'] == false
126
126
  false
127
127
  else
128
128
  true
@@ -130,7 +130,7 @@ module CouchRest
130
130
  begin
131
131
  design_doc.view_on(db, view_name, opts, &block)
132
132
  # the design doc may not have been saved yet on this database
133
- rescue HttpAbstraction::ResourceNotFound => e
133
+ rescue RestClient::ResourceNotFound => e
134
134
  if retryable
135
135
  save_design_doc(db)
136
136
  retryable = false
@@ -578,6 +578,11 @@ describe "ExtendedDocument properties" do
578
578
  end
579
579
 
580
580
  describe 'when type primitive is a Boolean' do
581
+ class RootBeerFloat < CouchRest::ExtendedDocument
582
+ use_database DB
583
+ property :tasty, TrueClass
584
+ end
585
+
581
586
  [ true, 'true', 'TRUE', '1', 1, 't', 'T' ].each do |value|
582
587
  it "returns true when value is #{value.inspect}" do
583
588
  @course.active = value
@@ -598,7 +603,32 @@ describe "ExtendedDocument properties" do
598
603
  @course['active'].should equal(value)
599
604
  end
600
605
  end
606
+
607
+ it "should respond to requests with ? modifier" do
608
+ @course.active = 'false'
609
+ @course.active?.should be_false
610
+ end
611
+
612
+ it "should add an accessor with a '?' for boolean attributes that returns true or false" do
613
+ RootBeerFloat.new(:tasty => true).tasty?.should == true
614
+ RootBeerFloat.new(:tasty => 'you bet').tasty?.should == true
615
+ RootBeerFloat.new(:tasty => 123).tasty?.should == true
616
+
617
+ RootBeerFloat.new(:tasty => false).tasty?.should == false
618
+ RootBeerFloat.new(:tasty => 'false').tasty?.should == false
619
+ RootBeerFloat.new(:tasty => 'FaLsE').tasty?.should == false
620
+ RootBeerFloat.new(:tasty => nil).tasty?.should == false
621
+ end
622
+
623
+ end
624
+
625
+ describe 'when type primitive is a TrueClass' do
626
+ it "should respond to requests with ? modifier" do
627
+ @course.very_active = 'true'
628
+ @course.very_active?.should be_true
629
+ end
601
630
  end
631
+
602
632
  end
603
633
  end
604
634
 
@@ -15,6 +15,7 @@ class Course < CouchRest::ExtendedDocument
15
15
  property :started_on, :type => 'Date'
16
16
  property :updated_at, :type => 'DateTime'
17
17
  property :active, :type => 'Boolean'
18
+ property :very_active, :type => TrueClass
18
19
  property :klass, :type => 'Class'
19
20
 
20
21
  view_by :title
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 3
9
- version: 1.0.3
8
+ - 4
9
+ version: 1.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - J. Chris Anderson
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-05-13 00:00:00 +02:00
20
+ date: 2010-05-22 00:00:00 +02:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -174,23 +174,23 @@ specification_version: 3
174
174
  summary: Extend CouchRest Document class with useful features.
175
175
  test_files:
176
176
  - spec/spec_helper.rb
177
- - spec/couchrest/extended_doc_inherited_spec.rb
177
+ - spec/couchrest/property_spec.rb
178
+ - spec/couchrest/extended_doc_view_spec.rb
178
179
  - spec/couchrest/extended_doc_attachment_spec.rb
180
+ - spec/couchrest/extended_doc_inherited_spec.rb
181
+ - spec/couchrest/casted_model_spec.rb
179
182
  - spec/couchrest/attribute_protection_spec.rb
183
+ - spec/couchrest/casted_extended_doc_spec.rb
180
184
  - spec/couchrest/extended_doc_subclass_spec.rb
181
185
  - spec/couchrest/extended_doc_spec.rb
182
- - spec/couchrest/property_spec.rb
183
- - spec/couchrest/casted_model_spec.rb
184
- - spec/couchrest/extended_doc_view_spec.rb
185
- - spec/couchrest/casted_extended_doc_spec.rb
186
- - spec/fixtures/more/invoice.rb
187
- - spec/fixtures/more/service.rb
188
- - spec/fixtures/more/course.rb
189
- - spec/fixtures/more/article.rb
186
+ - spec/fixtures/more/card.rb
187
+ - spec/fixtures/more/event.rb
190
188
  - spec/fixtures/more/user.rb
189
+ - spec/fixtures/more/article.rb
190
+ - spec/fixtures/more/service.rb
191
+ - spec/fixtures/more/invoice.rb
191
192
  - spec/fixtures/more/person.rb
192
- - spec/fixtures/more/cat.rb
193
- - spec/fixtures/more/event.rb
194
193
  - spec/fixtures/more/question.rb
195
- - spec/fixtures/more/card.rb
194
+ - spec/fixtures/more/cat.rb
195
+ - spec/fixtures/more/course.rb
196
196
  - examples/model/example.rb