From 273a174aae7d5907cc4fefbc35ee1067dbedc6e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tapaj=C3=B3s?= Date: Wed, 2 Sep 2009 23:52:43 -0300 Subject: [PATCH 1/6] Fixing spec description --- spec/couchrest/more/property_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/couchrest/more/property_spec.rb b/spec/couchrest/more/property_spec.rb index 146f0f8..95899aa 100644 --- a/spec/couchrest/more/property_spec.rb +++ b/spec/couchrest/more/property_spec.rb @@ -127,7 +127,7 @@ describe "ExtendedDocument properties" do @event = Event.get e['id'] end - it "should cast created_at to Time" do + it "should cast occurs_at to Time" do @event['occurs_at'].should be_an_instance_of(Time) end end From bc6df2f5ca0ce15b92012d03dd437ff4cba17d35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tapaj=C3=B3s?= Date: Wed, 2 Sep 2009 23:54:25 -0300 Subject: [PATCH 2/6] Adding support to :cast_as => 'Date'. --- lib/couchrest/mixins/properties.rb | 3 +++ spec/couchrest/more/property_spec.rb | 5 ++++- spec/fixtures/more/event.rb | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/couchrest/mixins/properties.rb b/lib/couchrest/mixins/properties.rb index b1dddd5..e627186 100644 --- a/lib/couchrest/mixins/properties.rb +++ b/lib/couchrest/mixins/properties.rb @@ -53,6 +53,9 @@ module CouchRest # Auto parse Time objects self[property.name] = if ((property.init_method == 'new') && target == 'Time') self[key].is_a?(String) ? Time.parse(self[key].dup) : self[key] + elsif + ((property.init_method == 'new') && target == 'Date') + self[key].is_a?(String) ? Date.parse(self[key].dup) : self[key] else # Let people use :send as a Time parse arg klass = ::CouchRest.constantize(target) diff --git a/spec/couchrest/more/property_spec.rb b/spec/couchrest/more/property_spec.rb index 95899aa..f8626f1 100644 --- a/spec/couchrest/more/property_spec.rb +++ b/spec/couchrest/more/property_spec.rb @@ -122,7 +122,7 @@ describe "ExtendedDocument properties" do describe "casting" do describe "cast keys to any type" do before(:all) do - event_doc = { :subject => "Some event", :occurs_at => Time.now } + event_doc = { :subject => "Some event", :occurs_at => Time.now, :end_date => Date.today } e = Event.database.save_doc event_doc @event = Event.get e['id'] @@ -130,6 +130,9 @@ describe "ExtendedDocument properties" do it "should cast occurs_at to Time" do @event['occurs_at'].should be_an_instance_of(Time) end + it "should cast end_date to Date" do + @event['end_date'].should be_an_instance_of(Date) + end end end diff --git a/spec/fixtures/more/event.rb b/spec/fixtures/more/event.rb index c36527a..b1ca6e3 100644 --- a/spec/fixtures/more/event.rb +++ b/spec/fixtures/more/event.rb @@ -3,4 +3,7 @@ class Event < CouchRest::ExtendedDocument property :subject property :occurs_at, :cast_as => 'Time', :send => 'parse' + property :end_date, :cast_as => 'Date' + + end \ No newline at end of file From 13c69d4487ce05f4f52ef2b7aa6b0ab343fdb56b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tapaj=C3=B3s?= Date: Thu, 3 Sep 2009 00:00:46 -0300 Subject: [PATCH 3/6] Adding more examples of availables options for property. --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 6c68ad9..82eee42 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,13 @@ you can define some casting rules. property :casted_attribute, :cast_as => 'WithCastedModelMixin' property :keywords, :cast_as => ["String"] + property :occurs_at, :cast_as => 'Time' + property :end_date, :cast_as => 'Date' + property :last_name, :alias => :family_name + property :read_only_value, :read_only => true + property :name, :length => 4...20 + property :price, :type => Integer + If you want to cast an array of instances from a specific Class, use the trick shown above ["ClassName"] From 5219f3c0d5032cf39d88724c7fc501d7b8ae8cc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tapaj=C3=B3s?= Date: Thu, 3 Sep 2009 00:09:16 -0300 Subject: [PATCH 4/6] Updating the version number --- THANKS.md | 1 + couchrest.gemspec | 4 ++-- lib/couchrest.rb | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/THANKS.md b/THANKS.md index 301f569..643cf5e 100644 --- a/THANKS.md +++ b/THANKS.md @@ -12,6 +12,7 @@ changes. A list of these people is included below. * [Jonathan S. Katz](http://github.com/jkatz) * [Matt Lyon](http://mattly.tumblr.com/) * Simon Rozet (simon /at/ rozet /dot/ name) + * [Marcos Tapajós](http://tapajos.me) Patches are welcome. The primary source for this software project is [on Github](http://github.com/jchris/couchrest/tree/master) diff --git a/couchrest.gemspec b/couchrest.gemspec index 41d86fc..6cf71e4 100644 --- a/couchrest.gemspec +++ b/couchrest.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |s| s.name = %q{couchrest} - s.version = "0.23" + s.version = "0.34" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["J. Chris Anderson", "Matt Aimonetti"] @@ -10,7 +10,7 @@ Gem::Specification.new do |s| s.description = %q{CouchRest provides a simple interface on top of CouchDB's RESTful HTTP API, as well as including some utility scripts for managing views and attachments.} s.email = %q{jchris@apache.org} s.extra_rdoc_files = ["README.md", "LICENSE", "THANKS.md"] - s.files = ["LICENSE", "README.md", "Rakefile", "THANKS.md", "examples/model", "examples/model/example.rb", "examples/word_count", "examples/word_count/markov", "examples/word_count/views", "examples/word_count/views/books", "examples/word_count/views/books/chunked-map.js", "examples/word_count/views/books/united-map.js", "examples/word_count/views/markov", "examples/word_count/views/markov/chain-map.js", "examples/word_count/views/markov/chain-reduce.js", "examples/word_count/views/word_count", "examples/word_count/views/word_count/count-map.js", "examples/word_count/views/word_count/count-reduce.js", "examples/word_count/word_count.rb", "examples/word_count/word_count_query.rb", "examples/word_count/word_count_views.rb", "lib/couchrest", "lib/couchrest/commands", "lib/couchrest/commands/generate.rb", "lib/couchrest/commands/push.rb", "lib/couchrest/core", "lib/couchrest/core/database.rb", "lib/couchrest/core/design.rb", "lib/couchrest/core/document.rb", "lib/couchrest/core/response.rb", "lib/couchrest/core/server.rb", "lib/couchrest/core/view.rb", "lib/couchrest/helper", "lib/couchrest/helper/pager.rb", "lib/couchrest/helper/streamer.rb", "lib/couchrest/helper/upgrade.rb", "lib/couchrest/mixins", "lib/couchrest/mixins/attachments.rb", "lib/couchrest/mixins/callbacks.rb", "lib/couchrest/mixins/class_proxy.rb", "lib/couchrest/mixins/design_doc.rb", "lib/couchrest/mixins/document_queries.rb", "lib/couchrest/mixins/extended_attachments.rb", "lib/couchrest/mixins/extended_document_mixins.rb", "lib/couchrest/mixins/properties.rb", "lib/couchrest/mixins/validation.rb", "lib/couchrest/mixins/views.rb", "lib/couchrest/mixins.rb", "lib/couchrest/monkeypatches.rb", "lib/couchrest/more", "lib/couchrest/more/casted_model.rb", "lib/couchrest/more/extended_document.rb", "lib/couchrest/more/property.rb", "lib/couchrest/support", "lib/couchrest/support/blank.rb", "lib/couchrest/support/class.rb", "lib/couchrest/validation", "lib/couchrest/validation/auto_validate.rb", "lib/couchrest/validation/contextual_validators.rb", "lib/couchrest/validation/validation_errors.rb", "lib/couchrest/validation/validators", "lib/couchrest/validation/validators/absent_field_validator.rb", "lib/couchrest/validation/validators/confirmation_validator.rb", "lib/couchrest/validation/validators/format_validator.rb", "lib/couchrest/validation/validators/formats", "lib/couchrest/validation/validators/formats/email.rb", "lib/couchrest/validation/validators/formats/url.rb", "lib/couchrest/validation/validators/generic_validator.rb", "lib/couchrest/validation/validators/length_validator.rb", "lib/couchrest/validation/validators/method_validator.rb", "lib/couchrest/validation/validators/numeric_validator.rb", "lib/couchrest/validation/validators/required_field_validator.rb", "lib/couchrest.rb", "spec/couchrest", "spec/couchrest/core", "spec/couchrest/core/couchrest_spec.rb", "spec/couchrest/core/database_spec.rb", "spec/couchrest/core/design_spec.rb", "spec/couchrest/core/document_spec.rb", "spec/couchrest/core/server_spec.rb", "spec/couchrest/helpers", "spec/couchrest/helpers/pager_spec.rb", "spec/couchrest/helpers/streamer_spec.rb", "spec/couchrest/more", "spec/couchrest/more/casted_extended_doc_spec.rb", "spec/couchrest/more/casted_model_spec.rb", "spec/couchrest/more/extended_doc_attachment_spec.rb", "spec/couchrest/more/extended_doc_spec.rb", "spec/couchrest/more/extended_doc_subclass_spec.rb", "spec/couchrest/more/extended_doc_view_spec.rb", "spec/couchrest/more/property_spec.rb", "spec/fixtures", "spec/fixtures/attachments", "spec/fixtures/attachments/couchdb.png", "spec/fixtures/attachments/README", "spec/fixtures/attachments/test.html", "spec/fixtures/more", "spec/fixtures/more/article.rb", "spec/fixtures/more/card.rb", "spec/fixtures/more/course.rb", "spec/fixtures/more/event.rb", "spec/fixtures/more/invoice.rb", "spec/fixtures/more/person.rb", "spec/fixtures/more/question.rb", "spec/fixtures/more/service.rb", "spec/fixtures/views", "spec/fixtures/views/lib.js", "spec/fixtures/views/test_view", "spec/fixtures/views/test_view/lib.js", "spec/fixtures/views/test_view/only-map.js", "spec/fixtures/views/test_view/test-map.js", "spec/fixtures/views/test_view/test-reduce.js", "spec/spec.opts", "spec/spec_helper.rb", "utils/remap.rb", "utils/subset.rb"] + s.files = ["LICENSE", "README.md", "Rakefile", "THANKS.md", "examples/model", "examples/model/example.rb", "examples/word_count", "examples/word_count/markov", "examples/word_count/views", "examples/word_count/views/books", "examples/word_count/views/books/chunked-map.js", "examples/word_count/views/books/united-map.js", "examples/word_count/views/markov", "examples/word_count/views/markov/chain-map.js", "examples/word_count/views/markov/chain-reduce.js", "examples/word_count/views/word_count", "examples/word_count/views/word_count/count-map.js", "examples/word_count/views/word_count/count-reduce.js", "examples/word_count/word_count.rb", "examples/word_count/word_count_query.rb", "examples/word_count/word_count_views.rb", "lib/couchrest", "lib/couchrest/commands", "lib/couchrest/commands/generate.rb", "lib/couchrest/commands/push.rb", "lib/couchrest/core", "lib/couchrest/core/database.rb", "lib/couchrest/core/design.rb", "lib/couchrest/core/document.rb", "lib/couchrest/core/response.rb", "lib/couchrest/core/server.rb", "lib/couchrest/core/view.rb", "lib/couchrest/helper", "lib/couchrest/helper/pager.rb", "lib/couchrest/helper/streamer.rb", "lib/couchrest/helper/upgrade.rb", "lib/couchrest/mixins", "lib/couchrest/mixins/attachments.rb", "lib/couchrest/mixins/callbacks.rb", "lib/couchrest/mixins/class_proxy.rb", "lib/couchrest/mixins/design_doc.rb", "lib/couchrest/mixins/document_queries.rb", "lib/couchrest/mixins/extended_attachments.rb", "lib/couchrest/mixins/extended_document_mixins.rb", "lib/couchrest/mixins/properties.rb", "lib/couchrest/mixins/validation.rb", "lib/couchrest/mixins/views.rb", "lib/couchrest/mixins.rb", "lib/couchrest/monkeypatches.rb", "lib/couchrest/more", "lib/couchrest/more/casted_model.rb", "lib/couchrest/more/extended_document.rb", "lib/couchrest/more/property.rb", "lib/couchrest/support", "lib/couchrest/support/blank.rb", "lib/couchrest/support/class.rb", "lib/couchrest/support/rails.rb", "lib/couchrest/validation", "lib/couchrest/validation/auto_validate.rb", "lib/couchrest/validation/contextual_validators.rb", "lib/couchrest/validation/validation_errors.rb", "lib/couchrest/validation/validators", "lib/couchrest/validation/validators/absent_field_validator.rb", "lib/couchrest/validation/validators/confirmation_validator.rb", "lib/couchrest/validation/validators/format_validator.rb", "lib/couchrest/validation/validators/formats", "lib/couchrest/validation/validators/formats/email.rb", "lib/couchrest/validation/validators/formats/url.rb", "lib/couchrest/validation/validators/generic_validator.rb", "lib/couchrest/validation/validators/length_validator.rb", "lib/couchrest/validation/validators/method_validator.rb", "lib/couchrest/validation/validators/numeric_validator.rb", "lib/couchrest/validation/validators/required_field_validator.rb", "lib/couchrest.rb", "spec/couchrest", "spec/couchrest/core", "spec/couchrest/core/couchrest_spec.rb", "spec/couchrest/core/database_spec.rb", "spec/couchrest/core/design_spec.rb", "spec/couchrest/core/document_spec.rb", "spec/couchrest/core/server_spec.rb", "spec/couchrest/helpers", "spec/couchrest/helpers/pager_spec.rb", "spec/couchrest/helpers/streamer_spec.rb", "spec/couchrest/more", "spec/couchrest/more/casted_extended_doc_spec.rb", "spec/couchrest/more/casted_model_spec.rb", "spec/couchrest/more/extended_doc_attachment_spec.rb", "spec/couchrest/more/extended_doc_spec.rb", "spec/couchrest/more/extended_doc_subclass_spec.rb", "spec/couchrest/more/extended_doc_view_spec.rb", "spec/couchrest/more/property_spec.rb", "spec/fixtures", "spec/fixtures/attachments", "spec/fixtures/attachments/couchdb.png", "spec/fixtures/attachments/README", "spec/fixtures/attachments/test.html", "spec/fixtures/more", "spec/fixtures/more/article.rb", "spec/fixtures/more/card.rb", "spec/fixtures/more/course.rb", "spec/fixtures/more/event.rb", "spec/fixtures/more/invoice.rb", "spec/fixtures/more/person.rb", "spec/fixtures/more/question.rb", "spec/fixtures/more/service.rb", "spec/fixtures/views", "spec/fixtures/views/lib.js", "spec/fixtures/views/test_view", "spec/fixtures/views/test_view/lib.js", "spec/fixtures/views/test_view/only-map.js", "spec/fixtures/views/test_view/test-map.js", "spec/fixtures/views/test_view/test-reduce.js", "spec/spec.opts", "spec/spec_helper.rb", "utils/remap.rb", "utils/subset.rb"] s.has_rdoc = true s.homepage = %q{http://github.com/jchris/couchrest} s.require_paths = ["lib"] diff --git a/lib/couchrest.rb b/lib/couchrest.rb index f72d35a..49d3d2b 100644 --- a/lib/couchrest.rb +++ b/lib/couchrest.rb @@ -28,7 +28,7 @@ require 'couchrest/monkeypatches' # = CouchDB, close to the metal module CouchRest - VERSION = '0.23' unless self.const_defined?("VERSION") + VERSION = '0.34' unless self.const_defined?("VERSION") autoload :Server, 'couchrest/core/server' autoload :Database, 'couchrest/core/database' From 37c6cb30c20c902a476600eebaef7875baa64e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tapaj=C3=B3s?= Date: Thu, 3 Sep 2009 00:12:16 -0300 Subject: [PATCH 5/6] Updating documentation --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 82eee42..9afd7f3 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,13 @@ CouchRest uses a mixin you can find in lib/mixins/callbacks which is extracted f Check the mixin or the ExtendedDocument class to see how to implement your own callbacks. +### Properties + + property :last_name, :alias => :family_name + property :read_only_value, :read_only => true + property :name, :length => 4...20 + property :price, :type => Integer + ### Casting Often, you will want to store multiple objects within a document, to be able to retrieve your objects when you load the document, @@ -92,11 +99,5 @@ you can define some casting rules. property :keywords, :cast_as => ["String"] property :occurs_at, :cast_as => 'Time' property :end_date, :cast_as => 'Date' - property :last_name, :alias => :family_name - property :read_only_value, :read_only => true - property :name, :length => 4...20 - property :price, :type => Integer - - -If you want to cast an array of instances from a specific Class, use the trick shown above ["ClassName"] +If you want to cast an array of instances from a specific Class, use the trick shown above ["ClassName"] \ No newline at end of file From 8db522a116ff3f6e7d7d041ca6d8a8527509a76a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tapaj=C3=B3s?= Date: Thu, 3 Sep 2009 00:27:04 -0300 Subject: [PATCH 6/6] Fix issue #1. --- lib/couchrest/more/extended_document.rb | 1 + spec/couchrest/more/extended_doc_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/couchrest/more/extended_document.rb b/lib/couchrest/more/extended_document.rb index c1590f1..eb1d68e 100644 --- a/lib/couchrest/more/extended_document.rb +++ b/lib/couchrest/more/extended_document.rb @@ -193,6 +193,7 @@ module CouchRest # if the document is not saved properly. def save! raise "#{self.inspect} failed to save" unless self.save + true end # Deletes the document from the database. Runs the :destroy callbacks. diff --git a/spec/couchrest/more/extended_doc_spec.rb b/spec/couchrest/more/extended_doc_spec.rb index 190baba..cbd1ca5 100644 --- a/spec/couchrest/more/extended_doc_spec.rb +++ b/spec/couchrest/more/extended_doc_spec.rb @@ -1,6 +1,7 @@ require File.dirname(__FILE__) + '/../../spec_helper' require File.join(FIXTURE_PATH, 'more', 'article') require File.join(FIXTURE_PATH, 'more', 'course') +require File.join(FIXTURE_PATH, 'more', 'card') describe "ExtendedDocument" do @@ -339,6 +340,25 @@ describe "ExtendedDocument" do it "should set the type" do @sobj['couchrest-type'].should == 'Basic' end + + describe "save!" do + + before(:each) do + @sobj = Card.new(:first_name => "Marcos", :last_name => "Tapajós") + end + + it "should return true if save the document" do + @sobj.save!.should == true + end + + it "should raise error if don't save the document" do + @sobj.first_name = nil + lambda { @sobj.save!.should == true }.should raise_error(RuntimeError) + end + + end + + end describe "saving a model with a unique_id configured" do