Merge remote branch 'tapajos/master'
Conflicts: README.md lib/couchrest/mixins/properties.rb spec/couchrest/core/database_spec.rb spec/couchrest/more/extended_doc_spec.rb
This commit is contained in:
commit
2f2c507582
10
README.md
10
README.md
|
@ -135,6 +135,13 @@ To halt the callback, simply return a :halt symbol in your callback method.
|
|||
|
||||
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,
|
||||
|
@ -142,6 +149,8 @@ you can define some casting rules.
|
|||
|
||||
property :casted_attribute, :cast_as => 'WithCastedModelMixin'
|
||||
property :keywords, :cast_as => ["String"]
|
||||
property :occurs_at, :cast_as => 'Time', :send => 'parse
|
||||
property :end_date, :cast_as => 'Date', :send => 'parse
|
||||
|
||||
If you want to cast an array of instances from a specific Class, use the trick shown above ["ClassName"]
|
||||
|
||||
|
@ -168,7 +177,6 @@ Low level usage:
|
|||
Article.paginate(:design_doc => 'Article', :view_name => 'by_date',
|
||||
:per_page => 3, :page => 2, :descending => true, :key => Date.today, :include_docs => true)
|
||||
|
||||
|
||||
## Ruby on Rails
|
||||
|
||||
CouchRest is compatible with rails and can even be used a Rails plugin.
|
||||
|
|
1
Rakefile
1
Rakefile
|
@ -53,6 +53,7 @@ end
|
|||
|
||||
desc "Run all specs"
|
||||
Spec::Rake::SpecTask.new('spec') do |t|
|
||||
t.spec_opts = ["--color"]
|
||||
t.spec_files = FileList['spec/**/*_spec.rb']
|
||||
end
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = %q{couchrest}
|
||||
s.version = "0.33"
|
||||
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"]
|
||||
|
@ -11,14 +11,15 @@ Gem::Specification.new do |s|
|
|||
s.email = %q{jchris@apache.org}
|
||||
s.extra_rdoc_files = ["README.md", "LICENSE", "THANKS.md"]
|
||||
s.files = ["LICENSE", "README.md", "Rakefile", "THANKS.md", "history.txt", "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/adapters", "lib/couchrest/core/adapters/restclient.rb", "lib/couchrest/core/database.rb", "lib/couchrest/core/design.rb", "lib/couchrest/core/document.rb", "lib/couchrest/core/http_abstraction.rb", "lib/couchrest/core/response.rb", "lib/couchrest/core/rest_api.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/middlewares", "lib/couchrest/middlewares/logger.rb", "lib/couchrest/mixins", "lib/couchrest/mixins/attachments.rb", "lib/couchrest/mixins/callbacks.rb", "lib/couchrest/mixins/class_proxy.rb", "lib/couchrest/mixins/collection.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/cat.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"]
|
||||
s.rubygems_version = %q{1.3.4}
|
||||
s.rubygems_version = %q{1.3.1}
|
||||
s.summary = %q{Lean and RESTful interface to CouchDB.}
|
||||
|
||||
if s.respond_to? :specification_version then
|
||||
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
||||
s.specification_version = 3
|
||||
s.specification_version = 2
|
||||
|
||||
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
||||
s.add_runtime_dependency(%q<rest-client>, [">= 0.5"])
|
||||
|
|
|
@ -28,7 +28,7 @@ require 'couchrest/monkeypatches'
|
|||
|
||||
# = CouchDB, close to the metal
|
||||
module CouchRest
|
||||
VERSION = '0.33' unless self.const_defined?("VERSION")
|
||||
VERSION = '0.34' unless self.const_defined?("VERSION")
|
||||
|
||||
autoload :Server, 'couchrest/core/server'
|
||||
autoload :Database, 'couchrest/core/database'
|
||||
|
|
|
@ -64,7 +64,7 @@ module CouchRest
|
|||
def set_attachment_attr(args)
|
||||
content_type = args[:content_type] ? args[:content_type] : get_mime_type(args[:file])
|
||||
self['_attachments'][args[:name]] = {
|
||||
'content-type' => content_type,
|
||||
'content_type' => content_type,
|
||||
'data' => encode_attachment(args[:file].read)
|
||||
}
|
||||
end
|
||||
|
|
|
@ -245,6 +245,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.
|
||||
|
|
|
@ -66,7 +66,7 @@ describe "ExtendedDocument attachments" do
|
|||
|
||||
it 'should set the content-type if passed' do
|
||||
@obj.create_attachment(:file => @file_ext, :name => @attachment_name, :content_type => @content_type)
|
||||
@obj['_attachments'][@attachment_name]['content-type'].should == @content_type
|
||||
@obj['_attachments'][@attachment_name]['content_type'].should == @content_type
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -100,7 +100,7 @@ describe "ExtendedDocument attachments" do
|
|||
file = File.open(FIXTURE_PATH + '/attachments/README')
|
||||
@file.should_not == file
|
||||
@obj.update_attachment(:file => file, :name => @attachment_name, :content_type => @content_type)
|
||||
@obj['_attachments'][@attachment_name]['content-type'].should == @content_type
|
||||
@obj['_attachments'][@attachment_name]['content_type'].should == @content_type
|
||||
end
|
||||
|
||||
it 'should delete an attachment that exists' do
|
||||
|
|
|
@ -3,7 +3,6 @@ require File.join(FIXTURE_PATH, 'more', 'article')
|
|||
require File.join(FIXTURE_PATH, 'more', 'course')
|
||||
require File.join(FIXTURE_PATH, 'more', 'cat')
|
||||
|
||||
|
||||
describe "ExtendedDocument" do
|
||||
|
||||
class WithDefaultValues < CouchRest::ExtendedDocument
|
||||
|
@ -463,6 +462,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
|
||||
|
|
|
@ -133,14 +133,17 @@ 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']
|
||||
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
|
||||
it "should cast end_date to Date" do
|
||||
@event['end_date'].should be_an_instance_of(Date)
|
||||
end
|
||||
end
|
||||
|
||||
describe "casting to Float object" do
|
||||
|
|
3
spec/fixtures/more/event.rb
vendored
3
spec/fixtures/more/event.rb
vendored
|
@ -3,4 +3,7 @@ class Event < CouchRest::ExtendedDocument
|
|||
|
||||
property :subject
|
||||
property :occurs_at, :cast_as => 'Time', :send => 'parse'
|
||||
property :end_date, :cast_as => 'Date', :send => 'parse'
|
||||
|
||||
|
||||
end
|
Loading…
Reference in a new issue