samlown-couchrest_extended_document 1.0.4 → 1.0.5

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.
@@ -4,6 +4,11 @@
4
4
 
5
5
  * Minor enhancements
6
6
 
7
+ == 1.0.5
8
+
9
+ * Minor enhancements
10
+ * Added 'find' alias for 'get' for easier rails transition
11
+
7
12
  == 1.0.3
8
13
 
9
14
  * Minor enhancements
@@ -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.4"
11
+ VERSION = "1.0.5"
12
12
 
13
13
  include CouchRest::Mixins::Callbacks
14
14
  include CouchRest::Mixins::DocumentQueries
@@ -56,6 +56,7 @@ module CouchRest
56
56
  nil
57
57
  end
58
58
  end
59
+ alias :find :get
59
60
 
60
61
  # Load a document from the database by id
61
62
  # An exception will be raised if the document isn't found
@@ -72,6 +73,7 @@ module CouchRest
72
73
  doc = db.get id
73
74
  create_from_database(doc)
74
75
  end
76
+ alias :find! :get!
75
77
 
76
78
  end
77
79
 
@@ -54,6 +54,7 @@ module CouchRest
54
54
  private
55
55
 
56
56
  def get_mime_type(path)
57
+ return nil if path.nil?
57
58
  type = ::MIME::Types.type_for(path)
58
59
  type.empty? ? nil : type.first.content_type
59
60
  end
@@ -328,15 +328,20 @@ describe "ExtendedDocument" do
328
328
  foundart = Article.get @art.id
329
329
  foundart.title.should == "All About Getting"
330
330
  end
331
-
331
+ it "should load and instantiate with find" do
332
+ foundart = Article.find @art.id
333
+ foundart.title.should == "All About Getting"
334
+ end
332
335
  it "should return nil if `get` is used and the document doesn't exist" do
333
336
  foundart = Article.get 'matt aimonetti'
334
337
  foundart.should be_nil
335
338
  end
336
-
337
339
  it "should raise an error if `get!` is used and the document doesn't exist" do
338
340
  lambda{foundart = Article.get!('matt aimonetti')}.should raise_error
339
341
  end
342
+ it "should raise an error if `find!` is used and the document doesn't exist" do
343
+ lambda{foundart = Article.find!('matt aimonetti')}.should raise_error
344
+ end
340
345
  end
341
346
 
342
347
  describe "getting a model with a subobjects array" do
@@ -578,11 +578,7 @@ 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
582
  [ true, 'true', 'TRUE', '1', 1, 't', 'T' ].each do |value|
587
583
  it "returns true when value is #{value.inspect}" do
588
584
  @course.active = value
@@ -605,26 +601,20 @@ describe "ExtendedDocument properties" do
605
601
  end
606
602
 
607
603
  it "should respond to requests with ? modifier" do
608
- @course.active = 'false'
604
+ @course.active = nil
609
605
  @course.active?.should be_false
606
+ @course.active = false
607
+ @course.active?.should be_false
608
+ @course.active = true
609
+ @course.active?.should be_true
610
610
  end
611
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'
612
+ it "should respond to requests with ? modifier on TrueClass" do
613
+ @course.very_active = nil
614
+ @course.very_active?.should be_false
615
+ @course.very_active = false
616
+ @course.very_active?.should be_false
617
+ @course.very_active = true
628
618
  @course.very_active?.should be_true
629
619
  end
630
620
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 4
9
- version: 1.0.4
8
+ - 5
9
+ version: 1.0.5
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-22 00:00:00 +02:00
20
+ date: 2010-06-08 00:00:00 +02:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency