norr-couchrest 0.30.4 → 0.33.01

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/README.md +58 -10
  2. data/history.txt +45 -1
  3. data/lib/couchrest.rb +9 -49
  4. data/lib/couchrest/core/adapters/restclient.rb +35 -0
  5. data/lib/couchrest/core/database.rb +18 -10
  6. data/lib/couchrest/core/document.rb +0 -4
  7. data/lib/couchrest/core/http_abstraction.rb +48 -0
  8. data/lib/couchrest/core/rest_api.rb +49 -0
  9. data/lib/couchrest/middlewares/logger.rb +263 -0
  10. data/lib/couchrest/mixins/attachments.rb +2 -2
  11. data/lib/couchrest/mixins/class_proxy.rb +5 -1
  12. data/lib/couchrest/mixins/collection.rb +23 -6
  13. data/lib/couchrest/mixins/design_doc.rb +5 -0
  14. data/lib/couchrest/mixins/document_queries.rb +33 -4
  15. data/lib/couchrest/mixins/properties.rb +30 -4
  16. data/lib/couchrest/mixins/views.rb +5 -13
  17. data/lib/couchrest/monkeypatches.rb +59 -59
  18. data/lib/couchrest/more/casted_model.rb +3 -2
  19. data/lib/couchrest/more/extended_document.rb +18 -1
  20. data/lib/couchrest/validation/validation_errors.rb +7 -0
  21. data/spec/couchrest/core/couchrest_spec.rb +2 -2
  22. data/spec/couchrest/core/database_spec.rb +19 -5
  23. data/spec/couchrest/core/design_spec.rb +1 -1
  24. data/spec/couchrest/core/document_spec.rb +1 -1
  25. data/spec/couchrest/core/server_spec.rb +1 -1
  26. data/spec/couchrest/helpers/pager_spec.rb +1 -1
  27. data/spec/couchrest/helpers/streamer_spec.rb +1 -1
  28. data/spec/couchrest/more/casted_extended_doc_spec.rb +1 -1
  29. data/spec/couchrest/more/casted_model_spec.rb +1 -1
  30. data/spec/couchrest/more/extended_doc_attachment_spec.rb +1 -1
  31. data/spec/couchrest/more/extended_doc_spec.rb +27 -2
  32. data/spec/couchrest/more/extended_doc_subclass_spec.rb +1 -1
  33. data/spec/couchrest/more/extended_doc_view_spec.rb +21 -9
  34. data/spec/couchrest/more/property_spec.rb +50 -1
  35. data/spec/spec_helper.rb +1 -1
  36. metadata +9 -2
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
2
  require File.join(FIXTURE_PATH, 'more', 'person')
3
3
  require File.join(FIXTURE_PATH, 'more', 'card')
4
4
  require File.join(FIXTURE_PATH, 'more', 'invoice')
@@ -141,6 +141,55 @@ describe "ExtendedDocument properties" do
141
141
  @event['occurs_at'].should be_an_instance_of(Time)
142
142
  end
143
143
  end
144
+
145
+ describe "casting to Float object" do
146
+ class RootBeerFloat < CouchRest::ExtendedDocument
147
+ use_database DB
148
+ property :price, :cast_as => 'Float'
149
+ end
150
+
151
+ it "should convert a string into a float if casted as so" do
152
+ RootBeerFloat.new(:price => '12.50').price.should == 12.50
153
+ RootBeerFloat.new(:price => '9').price.should == 9.0
154
+ RootBeerFloat.new(:price => '-9').price.should == -9.0
155
+ end
156
+
157
+ it "should not convert a string if it's not a string that can be cast as a float" do
158
+ RootBeerFloat.new(:price => 'test').price.should == 'test'
159
+ end
160
+
161
+ it "should work fine when a float is being passed" do
162
+ RootBeerFloat.new(:price => 9.99).price.should == 9.99
163
+ end
164
+ end
165
+
166
+ describe "casting to a boolean value" do
167
+ class RootBeerFloat < CouchRest::ExtendedDocument
168
+ use_database DB
169
+ property :tasty, :cast_as => :boolean
170
+ end
171
+
172
+ it "should add an accessor with a '?' for boolean attributes that returns true or false" do
173
+ RootBeerFloat.new(:tasty => true).tasty?.should == true
174
+ RootBeerFloat.new(:tasty => 'you bet').tasty?.should == true
175
+ RootBeerFloat.new(:tasty => 123).tasty?.should == true
176
+
177
+ RootBeerFloat.new(:tasty => false).tasty?.should == false
178
+ RootBeerFloat.new(:tasty => 'false').tasty?.should == false
179
+ RootBeerFloat.new(:tasty => 'FaLsE').tasty?.should == false
180
+ RootBeerFloat.new(:tasty => nil).tasty?.should == false
181
+ end
182
+
183
+ it "should return the real value when the default accessor is used" do
184
+ RootBeerFloat.new(:tasty => true).tasty.should == true
185
+ RootBeerFloat.new(:tasty => 'you bet').tasty.should == 'you bet'
186
+ RootBeerFloat.new(:tasty => 123).tasty.should == 123
187
+ RootBeerFloat.new(:tasty => 'false').tasty.should == 'false'
188
+ RootBeerFloat.new(:tasty => false).tasty.should == false
189
+ RootBeerFloat.new(:tasty => nil).tasty.should == nil
190
+ end
191
+ end
192
+
144
193
  end
145
194
 
146
195
  end
@@ -20,7 +20,7 @@ class Basic < CouchRest::ExtendedDocument
20
20
  end
21
21
 
22
22
  def reset_test_db!
23
- DB.recreate! rescue nil
23
+ DB.recreate! rescue nil
24
24
  DB
25
25
  end
26
26
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: norr-couchrest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.30.4
4
+ version: 0.33.01
5
5
  platform: ruby
6
6
  authors:
7
7
  - J. Chris Anderson
@@ -71,16 +71,22 @@ files:
71
71
  - lib/couchrest/commands/generate.rb
72
72
  - lib/couchrest/commands/push.rb
73
73
  - lib/couchrest/core
74
+ - lib/couchrest/core/adapters
75
+ - lib/couchrest/core/adapters/restclient.rb
74
76
  - lib/couchrest/core/database.rb
75
77
  - lib/couchrest/core/design.rb
76
78
  - lib/couchrest/core/document.rb
79
+ - lib/couchrest/core/http_abstraction.rb
77
80
  - lib/couchrest/core/response.rb
81
+ - lib/couchrest/core/rest_api.rb
78
82
  - lib/couchrest/core/server.rb
79
83
  - lib/couchrest/core/view.rb
80
84
  - lib/couchrest/helper
81
85
  - lib/couchrest/helper/pager.rb
82
86
  - lib/couchrest/helper/streamer.rb
83
87
  - lib/couchrest/helper/upgrade.rb
88
+ - lib/couchrest/middlewares
89
+ - lib/couchrest/middlewares/logger.rb
84
90
  - lib/couchrest/mixins
85
91
  - lib/couchrest/mixins/attachments.rb
86
92
  - lib/couchrest/mixins/callbacks.rb
@@ -166,6 +172,7 @@ files:
166
172
  - utils/subset.rb
167
173
  has_rdoc: false
168
174
  homepage: http://github.com/jchris/couchrest
175
+ licenses:
169
176
  post_install_message:
170
177
  rdoc_options: []
171
178
 
@@ -186,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
193
  requirements: []
187
194
 
188
195
  rubyforge_project:
189
- rubygems_version: 1.2.0
196
+ rubygems_version: 1.3.5
190
197
  signing_key:
191
198
  specification_version: 3
192
199
  summary: Lean and RESTful interface to CouchDB.