Skip to content

Commit

Permalink
Attachment now typecasts fields for stub values.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Sosinski committed Nov 16, 2010
1 parent 96adc0b commit 26f32be
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
v0.1.2. Attachment now typecasts fields for stub values.

v0.1.1. Fixing Manifest contents and adding Rails information to README.

v0.1.0. Adding rake tasks to sync and manage database functions and design documents. Also added support for list and show functions; as well as fulltext administration.
Expand Down
1 change: 0 additions & 1 deletion Manifest
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Manifest
README.markdown
Rakefile
TODO
couch-client.gemspec
lib/couch-client.rb
lib/couch-client/attachment.rb
lib/couch-client/attachment_list.rb
Expand Down
2 changes: 1 addition & 1 deletion couch-client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Robert Sosinski"]
s.date = %q{2010-11-11}
s.date = %q{2010-11-16}
s.description = %q{A Ruby interface for CouchDB}
s.email = %q{email@robertsosinski.com}
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.markdown", "TODO", "lib/couch-client.rb", "lib/couch-client/attachment.rb", "lib/couch-client/attachment_list.rb", "lib/couch-client/collection.rb", "lib/couch-client/connection.rb", "lib/couch-client/connection_handler.rb", "lib/couch-client/consistent_hash.rb", "lib/couch-client/database.rb", "lib/couch-client/design.rb", "lib/couch-client/document.rb", "lib/couch-client/hookup.rb", "lib/couch-client/rake_task.rb", "lib/couch-client/row.rb"]
Expand Down
2 changes: 1 addition & 1 deletion lib/couch-client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# The CouchClient module is the overall container of all CouchClient logic.
module CouchClient
VERSION = "0.1.0"
VERSION = "0.1.2"

class Error < Exception; end

Expand Down
10 changes: 9 additions & 1 deletion lib/couch-client/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ class Attachment < ConsistentHash
# Attachment is constructed with the id of the document it is attached to,
# the filename, file stub and connection object.
def initialize(id, name, stub, connection)
# Ensure that `revpos` and `length` fields are numbers, not strings, or couchdb will thow an error.
["revpos", "length"].each do |field|
stub[field] &&= stub[field].to_i
end

# Ensure that `stub` is a boolean, not a string, or couchdb will throw an error
stub["stub"] &&= true

self.merge!(stub)

@id = id
@name = name
@connection = connection
Expand Down
10 changes: 10 additions & 0 deletions spec/attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@
@couch.database.delete!
end

describe '#initialize' do
it 'should typecast fields to the currect type' do
attachment = CouchClient::Attachment.new("123abc", "text.txt", {"content_type" => "text/plain", "revpos" => "3", "length" => "123", "stub" => "true"}, true)
attachment["content_type"].should eql("text/plain")
attachment["revpos"].should eql(3)
attachment["length"].should eql(123)
attachment["stub"].should be_true
end
end

describe '#uri' do
it 'should yield the uri for the attachment' do
@attachment_plain.uri.should eql([@couch.hookup.handler.uri, @alice.id, "plain.txt"].join("/"))
Expand Down

0 comments on commit 26f32be

Please sign in to comment.