couchrest 2.0.0.beta2 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56c6ad538f2b4fce792fe1e86f397af9c9fd02e1
4
- data.tar.gz: 5fc268898ee98554d7810dc0ce1bae37ee9953aa
3
+ metadata.gz: 12c93fb012d1d27b5ca89ab37547b0f00ad65f8e
4
+ data.tar.gz: d0a51beddbe852ac9e69374bbb9370e7a6bf296c
5
5
  SHA512:
6
- metadata.gz: a04bacd2673fa3782fc91218dff8e54fd777b086a1aea409210b16756c0fd4904a045fc792f10101568df92f243bea717ead2719671ae3f1de9991d374718a11
7
- data.tar.gz: 52fc7bb62a48eaff3f848eea5b13fe8c9d79be1a68c74603e55d24d3c7972354c8a9d390f2544eeb02576f622047386b9d96127779fdb662e2180b2a77fac447
6
+ metadata.gz: 2bc6d4a7f0c928d9da0e11237e41c62c6d9c0ddc15b0d06b5107664b59bf76c9ebc5fa6f040ee1fc2be77b67aedfa9738ad4a0c48e0219bb6a3a8ce76cf0ec03
7
+ data.tar.gz: a552470d47f04d65e62333f9af5d8f27af4779ce3612a5f0757ebd737caa4a91fdccc27e6d890e8289d92aa05668fa14ac59405956e9f1196aad12156a77e650
data/README.md CHANGED
@@ -2,10 +2,11 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/couchrest/couchrest.png)](https://travis-ci.org/couchrest/couchrest)
4
4
 
5
- CouchRest wraps CouchDB's HTTP API using persistent connections with the [HTTPClient gem](https://github.com/nahi/httpclient), managing JSON serialization, and remembering the URI-paths
6
- to CouchDB's API endpoints so you don't have to.
5
+ CouchRest wraps CouchDB's HTTP API using persistent connections with the [HTTPClient gem](https://github.com/nahi/httpclient) managing servers, databases, and JSON document serialization using CouchDB's API endpoints so you don't have to.
7
6
 
8
- CouchRest is designed to make a simple base for application and framework-specific object oriented APIs. CouchRest is Object-Mapper agnostic, the parsed JSON it returns from CouchDB shows up as subclasses of Ruby's Hash. Naked JSON, just as it was mean to be.
7
+ CouchRest is designed to provide a simple base for application and framework-specific object oriented APIs. CouchRest is Object-Mapper agnostic, the JSON objects provided by CouchDB are parsed and returned as Document objects providing a simple Hash-like interface.
8
+
9
+ For more complete modelling support based on ActiveModel, please checkout CouchRest's sister project: [CouchRest Model](https://github.com/couchrest/couchrest_model).
9
10
 
10
11
  ## CouchDB Version
11
12
 
@@ -15,9 +16,30 @@ Tested on latest stable release (1.6.X), but should work on older versions above
15
16
 
16
17
  $ sudo gem install couchrest
17
18
 
18
- ## Modelling
19
+ ## Basic Usage
19
20
 
20
- For more complete modelling support based on ActiveModel, please checkout CouchRest's sister project: [CouchRest Model](https://github.com/couchrest/couchrest_model).
21
+ Getting started with CouchRest is easy. You can send requests directly to a URL using a [RestClient](https://github.com/rest-client/rest-client)-like interface:
22
+
23
+ ```ruby
24
+ CouchRest.put("http://localhost:5984/testdb/doc", 'name' => 'test', 'date' => Date.current)
25
+ ```
26
+
27
+ Or use the lean server and database orientated API to take advantage of persistent and reusable connections:
28
+
29
+ ```ruby
30
+ server = CouchRest.new # assumes localhost by default!
31
+ db = server.database!('testdb') # create db if it doesn't already exist
32
+
33
+ # Save a document, with ID
34
+ db.save_doc('_id' => 'doc', 'name' => 'test', 'date' => Date.current)
35
+
36
+ # Fetch doc
37
+ doc = db.get('doc')
38
+ doc.inspect # #<CouchRest::Document _id: "doc", _rev: "1-defa304b36f9b3ef3ed606cc45d02fe2", name: "test", date: "2015-07-13">
39
+
40
+ # Delete
41
+ db.delete_doc(doc)
42
+ ```
21
43
 
22
44
  ## Running the Specs
23
45
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0.beta2
1
+ 2.0.0.rc1
@@ -1,10 +1,11 @@
1
- == 2.0.0.beta1
1
+ == 2.0.0.rc1
2
2
 
3
3
  * Major Changes
4
4
  * Refactoring to support persisitent HTTP connections with HTTPClient gem (@samlown)
5
5
  * Using Ruby's URI object consistently. (@samlown)
6
6
  * Removing concepts of `Server#available_databases` and `Server#default_databases` (@samlown)
7
7
  * Removing the `Streamer` class, added support for built-in streamer (@samlown)
8
+ * Fixing inline attachment Base64 re-encoding issue (@samlown) Issue#37
8
9
 
9
10
  == 1.2.1 - 2015-06-25
10
11
 
@@ -20,6 +20,7 @@ $:.unshift File.dirname(__FILE__) unless
20
20
  $:.include?(File.dirname(__FILE__)) ||
21
21
  $:.include?(File.expand_path(File.dirname(__FILE__)))
22
22
 
23
+ require 'couchrest/version'
23
24
  require 'couchrest/exceptions'
24
25
  require 'couchrest/connection'
25
26
  require 'couchrest/rest_api'
@@ -379,8 +379,8 @@ module CouchRest
379
379
 
380
380
  def encode_attachments(attachments)
381
381
  attachments.each do |k,v|
382
- next if v['stub']
383
- v['data'] = base64(v['data'])
382
+ next if v['stub'] || v['data'].frozen?
383
+ v['data'] = base64(v['data']).freeze
384
384
  end
385
385
  attachments
386
386
  end
@@ -392,7 +392,7 @@ module CouchRest
392
392
  # Convert a simplified view name into a complete view path. If
393
393
  # the name already starts with a "_" no alterations will be made.
394
394
  def name_to_view_path(name)
395
- name =~ /^([^_].+?)\/(.*)$/ ? "_design/#{$1}/_view/#{$2}" : name
395
+ name =~ /^([^_].*?)\/(.*)$/ ? "_design/#{$1}/_view/#{$2}" : name
396
396
  end
397
397
  end
398
398
  end
@@ -0,0 +1,5 @@
1
+ module CouchRest
2
+
3
+ VERSION = File.read(File.expand_path('../../../VERSION', __FILE__)).strip
4
+
5
+ end
@@ -16,8 +16,10 @@ describe CouchRest do
16
16
  end
17
17
  end
18
18
 
19
- let :mock_server do
20
- CouchRest.new("http://mock")
19
+ describe "version" do
20
+ it "should be there" do
21
+ expect(CouchRest::VERSION).to_not be_empty
22
+ end
21
23
  end
22
24
 
23
25
  describe "getting info" do
@@ -30,17 +32,6 @@ describe CouchRest do
30
32
  end
31
33
  end
32
34
 
33
- it "should restart" do
34
- # we really do not need to perform a proper restart!
35
- stub_request(:post, "http://mock/_restart")
36
- .to_return(:body => "{\"ok\":true}")
37
- mock_server.restart!
38
- end
39
-
40
- it "should provide one-time access to uuids" do
41
- expect(@cr.next_uuid).not_to be_nil
42
- end
43
-
44
35
  describe "initializing a database" do
45
36
  it "should return a db" do
46
37
  db = @cr.database(TESTDB)
@@ -8,14 +8,16 @@ describe CouchRest::Database do
8
8
  @db = @cr.create_db(TESTDB) # rescue nil
9
9
  end
10
10
 
11
- describe "database name including slash" do
12
- it "should escape the name in the URI" do
13
- db = @cr.database("foo/bar")
14
- expect(db.name).to eq "foo/bar"
15
- expect(db.root).to eq URI("#{COUCHHOST}/foo%2Fbar")
16
- expect(db.uri).to eq URI("#{COUCHHOST}/foo%2Fbar")
17
- expect(db.to_s).to eq "#{COUCHHOST}/foo%2Fbar"
18
- expect(db.path).to eq "/foo%2Fbar"
11
+ describe "#initialize" do
12
+ describe "database name including slash" do
13
+ it "should escape the name in the URI" do
14
+ db = @cr.database("foo/bar")
15
+ expect(db.name).to eq "foo/bar"
16
+ expect(db.root).to eq URI("#{COUCHHOST}/foo%2Fbar")
17
+ expect(db.uri).to eq URI("#{COUCHHOST}/foo%2Fbar")
18
+ expect(db.to_s).to eq "#{COUCHHOST}/foo%2Fbar"
19
+ expect(db.path).to eq "/foo%2Fbar"
20
+ end
19
21
  end
20
22
  end
21
23
 
@@ -172,6 +174,13 @@ describe CouchRest::Database do
172
174
  expect(rows.length).to eq 2
173
175
  expect(rows.first['doc']['another']).not_to be_empty
174
176
  end
177
+ it "should accept a short design doc name" do
178
+ res = { 'rows' => [] }
179
+ db = CouchRest.new("http://mock").database('db')
180
+ stub_request(:get, "http://mock/db/_design/a/_view/test")
181
+ .to_return(:body => res.to_json)
182
+ expect(db.view('a/test')).to eql(res)
183
+ end
175
184
  end
176
185
 
177
186
  describe "#changes" do
@@ -398,7 +407,7 @@ describe CouchRest::Database do
398
407
  it 'should be there' do
399
408
  doc = @db.get('mydocwithattachment')
400
409
  attachment = @db.fetch_attachment(doc, 'test.html')
401
- expect(Base64.decode64(attachment)).to eq @attach
410
+ expect(attachment).to eq @attach
402
411
  end
403
412
  end
404
413
 
@@ -406,7 +415,7 @@ describe CouchRest::Database do
406
415
  before(:each) do
407
416
  @attach = "<html><head><title>My Doc</title></head><body><p>Has words.</p></body></html>"
408
417
  @attach2 = "<html><head><title>Other Doc</title></head><body><p>Has more words.</p></body></html>"
409
- @doc = {
418
+ @data = {
410
419
  "_id" => "mydocwithattachment",
411
420
  "field" => ["some value"],
412
421
  "_attachments" => {
@@ -420,7 +429,7 @@ describe CouchRest::Database do
420
429
  }
421
430
  }
422
431
  }
423
- @db.save_doc(@doc)
432
+ @db.save_doc(@data)
424
433
  @doc = @db.get("mydocwithattachment")
425
434
  end
426
435
  it "should save and be indicated" do
@@ -435,6 +444,11 @@ describe CouchRest::Database do
435
444
  attachment = @db.fetch_attachment(@doc,"other.html")
436
445
  expect(attachment).to eq @attach2
437
446
  end
447
+ it "should not re-encode document" do
448
+ @db.save_doc(@data)
449
+ attachment = @db.fetch_attachment(@data,"test.html")
450
+ expect(attachment).to eq @attach
451
+ end
438
452
  end
439
453
 
440
454
  describe "DELETE an attachment directly from the database" do
@@ -2,5 +2,101 @@ require File.expand_path("../../spec_helper", __FILE__)
2
2
 
3
3
  describe CouchRest::Server do
4
4
 
5
-
5
+ let :server do
6
+ CouchRest::Server.new(COUCHHOST)
7
+ end
8
+
9
+ let :mock_server do
10
+ CouchRest::Server.new("http://mock")
11
+ end
12
+
13
+ describe "#initialize" do
14
+ it "should prepare frozen URI object" do
15
+ expect(server.uri).to be_a(URI)
16
+ expect(server.uri).to be_frozen
17
+ expect(server.uri.to_s).to eql(COUCHHOST)
18
+ end
19
+
20
+ it "should clean URI" do
21
+ server = CouchRest::Server.new(COUCHHOST + "/some/path?q=1#fragment")
22
+ expect(server.uri.to_s).to eql(COUCHHOST)
23
+ end
24
+ end
25
+
26
+ describe :connection do
27
+
28
+ it "should be provided" do
29
+ expect(server.connection).to be_a(CouchRest::Connection)
30
+ end
31
+
32
+ it "should cache connection in current thread" do
33
+ server.connection # instantiate
34
+ conns = Thread.current['couchrest.connections']
35
+ expect(server.connection).to eql(conns[COUCHHOST])
36
+ end
37
+
38
+ end
39
+
40
+ describe :databases do
41
+
42
+ it "should provide list of databse names" do
43
+ expect(server.databases).to include(TESTDB)
44
+ end
45
+
46
+ end
47
+
48
+ describe :database do
49
+
50
+ it "should instantiate a new database object" do
51
+ db = server.database(TESTDB)
52
+ expect(db).to be_a(CouchRest::Database)
53
+ expect(db.name).to eql(TESTDB)
54
+ end
55
+
56
+ end
57
+
58
+ describe :database! do
59
+
60
+ let :db_name do
61
+ TESTDB + '_create'
62
+ end
63
+
64
+ it "should instantiate and create database if it doesn't exist" do
65
+ db = server.database!(db_name)
66
+ expect(server.databases).to include(db_name)
67
+ db.delete!
68
+ end
69
+
70
+ end
71
+
72
+ describe :info do
73
+
74
+ it "should provide server info" do
75
+ expect(server.info).to be_a(Hash)
76
+ expect(server.info).to include('couchdb')
77
+ expect(server.info['couchdb']).to eql('Welcome')
78
+ end
79
+
80
+ end
81
+
82
+ describe :restart do
83
+ it "should send restart request" do
84
+ # we really do not need to perform a proper restart!
85
+ stub_request(:post, "http://mock/_restart")
86
+ .to_return(:body => "{\"ok\":true}")
87
+ mock_server.restart!
88
+ end
89
+ end
90
+
91
+ describe :next_uuid do
92
+ it "should provide one-time access to uuids" do
93
+ expect(server.next_uuid).not_to be_nil
94
+ end
95
+
96
+ it "should support providing batch count" do
97
+ server.next_uuid(10)
98
+ expect(server.uuids.length).to eql(9)
99
+ end
100
+ end
101
+
6
102
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couchrest
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta2
4
+ version: 2.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - J. Chris Anderson
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-07-10 00:00:00.000000000 Z
15
+ date: 2015-07-13 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: httpclient
@@ -161,6 +161,7 @@ files:
161
161
  - lib/couchrest/rest_api.rb
162
162
  - lib/couchrest/server.rb
163
163
  - lib/couchrest/support/inheritable_attributes.rb
164
+ - lib/couchrest/version.rb
164
165
  - spec/.gitignore
165
166
  - spec/couchrest/connection_spec.rb
166
167
  - spec/couchrest/couchrest_spec.rb