eee-c-couch_design_docs 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,43 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{couch_design_docs}
5
+ s.version = "1.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Chris Strom"]
9
+ s.date = %q{2009-07-12}
10
+ s.default_executable = %q{couch_design_docs}
11
+ s.description = %q{Manage CouchDB views.}
12
+ s.email = %q{chris@eeecooks.com}
13
+ s.executables = ["couch_design_docs"]
14
+ s.extra_rdoc_files = ["History.txt", "README.txt", "bin/couch_design_docs"]
15
+ s.files = ["History.txt", "README.txt", "Rakefile", "bin/couch_design_docs", "couch_design_docs.gemspec", "fixtures/a/b/c.js", "fixtures/a/b/d.js", "lib/couch_design_docs.rb", "lib/couch_design_docs/directory.rb", "lib/couch_design_docs/store.rb", "spec/couch_design_docs_spec.rb", "spec/spec_helper.rb", "test/test_couch_design_docs.rb"]
16
+ s.has_rdoc = true
17
+ s.homepage = %q{http://github.com/eee-c/couch_design_docs}
18
+ s.rdoc_options = ["--main", "README.txt"]
19
+ s.require_paths = ["lib"]
20
+ s.rubyforge_project = %q{couch_design_docs}
21
+ s.rubygems_version = %q{1.3.1}
22
+ s.summary = %q{Manage CouchDB views}
23
+ s.test_files = ["test/test_couch_design_docs.rb"]
24
+
25
+ if s.respond_to? :specification_version then
26
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
27
+ s.specification_version = 2
28
+
29
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
30
+ s.add_runtime_dependency(%q<json>, [">= 0"])
31
+ s.add_runtime_dependency(%q<jchris-couchrest>, [">= 0"])
32
+ s.add_development_dependency(%q<bones>, [">= 2.5.1"])
33
+ else
34
+ s.add_dependency(%q<json>, [">= 0"])
35
+ s.add_dependency(%q<jchris-couchrest>, [">= 0"])
36
+ s.add_dependency(%q<bones>, [">= 2.5.1"])
37
+ end
38
+ else
39
+ s.add_dependency(%q<json>, [">= 0"])
40
+ s.add_dependency(%q<jchris-couchrest>, [">= 0"])
41
+ s.add_dependency(%q<bones>, [">= 2.5.1"])
42
+ end
43
+ end
@@ -2,7 +2,7 @@
2
2
  module CouchDesignDocs
3
3
 
4
4
  # :stopdoc:
5
- VERSION = '1.0.0'
5
+ VERSION = '1.0.1'
6
6
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
7
7
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
8
8
  # :startdoc:
@@ -1,4 +1,4 @@
1
- require 'rest_client'
1
+ require 'restclient'
2
2
  require 'json'
3
3
 
4
4
  module CouchDesignDocs
@@ -11,10 +11,37 @@ module CouchDesignDocs
11
11
 
12
12
  def load(h)
13
13
  h.each_pair do |document_name, doc|
14
- RestClient.put "#{url}/_design/#{document_name}",
15
- doc.to_json,
16
- :content_type => 'application/json'
14
+ Store.put!("#{url}/_design/#{document_name}", doc)
17
15
  end
18
16
  end
17
+
18
+ # Create or replace the document located at "path" with the
19
+ # Hash document "doc"
20
+ def self.put!(path, doc)
21
+ self.put(path, doc)
22
+ rescue RestClient::RequestFailed
23
+ self.delete_and_put(path, doc)
24
+ end
25
+
26
+ def self.delete_and_put(path, doc)
27
+ self.delete(path)
28
+ self.put(path, doc)
29
+ end
30
+
31
+ def self.put(path, doc)
32
+ RestClient.put path,
33
+ doc.to_json,
34
+ :content_type => 'application/json'
35
+ end
36
+
37
+ def self.delete(path)
38
+ # retrieve existing to obtain the revision
39
+ old = self.get(path)
40
+ RestClient.delete(path + "?rev=#{old['_rev']}")
41
+ end
42
+
43
+ def self.get(path)
44
+ JSON.parse(RestClient.get(path))
45
+ end
19
46
  end
20
47
  end
@@ -22,6 +22,38 @@ describe Store do
22
22
  }
23
23
  end
24
24
 
25
+ it "should be able to put a new document" do
26
+ Store.
27
+ should_receive(:put).
28
+ with("uri", { })
29
+
30
+ Store.put!("uri", { })
31
+ end
32
+
33
+ it "should delete existing docs if first put fails" do
34
+ Store.
35
+ stub!(:put).
36
+ and_raise(RestClient::RequestFailed)
37
+
38
+ Store.
39
+ should_receive(:delete_and_put).
40
+ with("uri", { })
41
+
42
+ Store.put!("uri", { })
43
+ end
44
+
45
+ it "should be able to delete and put" do
46
+ Store.
47
+ should_receive(:delete).
48
+ with("uri")
49
+
50
+ Store.
51
+ should_receive(:put).
52
+ with("uri", { })
53
+
54
+ Store.delete_and_put("uri", { })
55
+ end
56
+
25
57
  it "should be able to load a hash into design docs" do
26
58
  RestClient.
27
59
  should_receive(:put).
@@ -30,6 +62,24 @@ describe Store do
30
62
  :content_type => 'application/json')
31
63
  @it.load(@hash)
32
64
  end
65
+
66
+ it "should be able to retrieve an existing document" do
67
+ RestClient.
68
+ stub!(:get).
69
+ and_return('{"_rev":"1234"}')
70
+
71
+ Store.get("uri").should == { '_rev' => "1234" }
72
+ end
73
+
74
+ it "should be able to delete an existing document" do
75
+ Store.stub!(:get).and_return({ '_rev' => '1234' })
76
+
77
+ RestClient.
78
+ should_receive(:delete).
79
+ with("uri?rev=1234")
80
+
81
+ Store.delete("uri")
82
+ end
33
83
  end
34
84
  end
35
85
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eee-c-couch_design_docs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Strom
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-11 00:00:00 -07:00
12
+ date: 2009-07-12 00:00:00 -07:00
13
13
  default_executable: couch_design_docs
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -57,6 +57,7 @@ files:
57
57
  - README.txt
58
58
  - Rakefile
59
59
  - bin/couch_design_docs
60
+ - couch_design_docs.gemspec
60
61
  - fixtures/a/b/c.js
61
62
  - fixtures/a/b/d.js
62
63
  - lib/couch_design_docs.rb