rufus-jig 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.txt CHANGED
@@ -1,6 +1,12 @@
1
1
 
2
2
  = rufus-jig CHANGELOG.txt
3
3
 
4
+ == rufus-jig - 0.1.9 released 2009/12/29
5
+
6
+ - Couch now handling conflict re-get by itself
7
+ - :re_put_ok => false option for Rufus::Jig::Couch
8
+ (refusing puts on deleted documents)
9
+
4
10
 
5
11
  == rufus-jig - 0.1.8 released 2009/12/25
6
12
 
@@ -49,16 +49,17 @@ module Rufus::Jig
49
49
  [ doc_or_path['_id'], doc_or_path ]
50
50
  end
51
51
 
52
- #if opts[:update_rev] && payload.is_a?(Hash) && payload['_rev']
53
- # pre = get(path)
54
- # payload['_rev'] = prev['_rev']
55
- #end
52
+ if @opts[:re_put_ok] == false && payload['_rev']
53
+ cur = get(path)
54
+ return true if cur.nil?
55
+ return cur if cur['_rev'] != payload['_rev']
56
+ end
56
57
 
57
58
  path = adjust(path)
58
59
 
59
60
  r = @http.put(path, payload, :content_type => :json, :cache => false)
60
61
 
61
- return true if r == true
62
+ return @http.get(path) if r == true
62
63
  # conflict
63
64
 
64
65
  if opts[:update_rev] && doc_or_path.is_a?(Hash)
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Rufus
3
3
  module Jig
4
- VERSION = '0.1.8'
4
+ VERSION = '0.1.9'
5
5
  end
6
6
  end
7
7
 
data/rufus-jig.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rufus-jig}
8
- s.version = "0.1.8"
8
+ s.version = "0.1.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Mettraux", "Kenneth Kalmer"]
12
- s.date = %q{2009-12-25}
12
+ s.date = %q{2009-12-29}
13
13
  s.description = %q{
14
14
  Json Internet Get.
15
15
 
@@ -41,6 +41,7 @@ Gem::Specification.new do |s|
41
41
  "test/couch_base.rb",
42
42
  "test/ct_0_couch.rb",
43
43
  "test/ct_1_couchdb.rb",
44
+ "test/ct_2_couchdb_options.rb",
44
45
  "test/server.rb",
45
46
  "test/test.rb",
46
47
  "test/ut_0_http_get.rb",
data/test/couch_base.rb CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- $: << lib unless $:.include?(lib)
3
+ $:.unshift(lib) unless $:.include?(lib)
4
4
 
5
5
  require 'rubygems'
6
6
  require 'yajl'
data/test/ct_1_couchdb.rb CHANGED
@@ -33,7 +33,7 @@ class CtCouchDbTest < Test::Unit::TestCase
33
33
  @c.close
34
34
  end
35
35
 
36
- def test_put_doc
36
+ def test_put
37
37
 
38
38
  r = @c.put('_id' => 'coffee0', 'type' => 'espresso')
39
39
 
@@ -44,11 +44,21 @@ class CtCouchDbTest < Test::Unit::TestCase
44
44
  assert_not_nil doc['_rev']
45
45
  end
46
46
 
47
- def test_put_doc_fail
47
+ def test_put_fail
48
48
 
49
49
  r = @c.put('_id' => 'coffee1', 'type' => 'espresso')
50
50
 
51
- assert_equal true, r
51
+ assert_match /^1-.+$/, r['_rev']
52
+ end
53
+
54
+ def test_put_conflict
55
+
56
+ r = @c.put(
57
+ '_id' => 'coffee1',
58
+ 'type' => 'espresso',
59
+ '_rev' => '2-47844552aae09c41a0ffffffffffffff')
60
+
61
+ assert_match /^1-.+$/, r['_rev']
52
62
  end
53
63
 
54
64
  def test_put_update_rev
@@ -73,21 +83,35 @@ class CtCouchDbTest < Test::Unit::TestCase
73
83
  assert_not_equal rev, doc['_rev']
74
84
  end
75
85
 
76
- def test_get_doc
86
+ def test_re_put
87
+
88
+ doc = @c.get('coffee1')
89
+ @c.delete(doc)
90
+
91
+ assert_nil @c.get('coffee1')
92
+
93
+ doc['whatever'] = 'else'
94
+
95
+ r = @c.put(doc)
96
+
97
+ assert_not_nil @c.get('coffee1')['_rev']
98
+ end
99
+
100
+ def test_get
77
101
 
78
102
  doc = @c.get('coffee1')
79
103
 
80
104
  assert_not_nil doc['_rev']
81
105
  end
82
106
 
83
- def test_get_missing_doc
107
+ def test_get_404
84
108
 
85
109
  doc = @c.get('tea0')
86
110
 
87
111
  assert_nil doc
88
112
  end
89
113
 
90
- def test_delete_doc
114
+ def test_delete
91
115
 
92
116
  doc = @c.get('coffee1')
93
117
 
@@ -99,7 +123,7 @@ class CtCouchDbTest < Test::Unit::TestCase
99
123
  Rufus::Jig::Http.new('127.0.0.1', 5984).get('/rufus_jig_test/coffee1'))
100
124
  end
101
125
 
102
- def test_delete_doc_2_args
126
+ def test_delete_2_args
103
127
 
104
128
  doc = @c.get('coffee1')
105
129
 
@@ -109,7 +133,7 @@ class CtCouchDbTest < Test::Unit::TestCase
109
133
  Rufus::Jig::Http.new('127.0.0.1', 5984).get('/rufus_jig_test/coffee1'))
110
134
  end
111
135
 
112
- def test_delete_doc_fail
136
+ def test_delete_conflict
113
137
 
114
138
  doc = @c.get('coffee1')
115
139
 
@@ -0,0 +1,51 @@
1
+
2
+ #
3
+ # testing rufus-jig
4
+ #
5
+ # Tue Dec 29 14:45:22 JST 2009
6
+ #
7
+
8
+ require File.join(File.dirname(__FILE__), 'couch_base')
9
+
10
+
11
+ class CtCouchDbOptionsTest < Test::Unit::TestCase
12
+
13
+ def setup
14
+
15
+ h = Rufus::Jig::Http.new('127.0.0.1', 5984)
16
+
17
+ begin
18
+ h.delete('/rufus_jig_test')
19
+ rescue Exception => e
20
+ #p e
21
+ end
22
+
23
+ h.put('/rufus_jig_test', '')
24
+ h.put('/rufus_jig_test/coffee1', '{"_id":"coffee1","type":"ristretto"}')
25
+
26
+ h.close
27
+
28
+ @c = Rufus::Jig::Couch.new(
29
+ '127.0.0.1', 5984, 'rufus_jig_test', :re_put_ok => false)
30
+ end
31
+
32
+ def teardown
33
+
34
+ @c.close
35
+ end
36
+
37
+ def test_put_gone
38
+
39
+ doc = @c.get('coffee1')
40
+ @c.delete(doc)
41
+
42
+ assert_nil @c.get('coffee1')
43
+
44
+ doc['whatever'] = 'else'
45
+
46
+ r = @c.put(doc)
47
+
48
+ assert_equal true, r
49
+ end
50
+ end
51
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-jig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-12-25 00:00:00 +09:00
13
+ date: 2009-12-29 00:00:00 +09:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -71,6 +71,7 @@ files:
71
71
  - test/couch_base.rb
72
72
  - test/ct_0_couch.rb
73
73
  - test/ct_1_couchdb.rb
74
+ - test/ct_2_couchdb_options.rb
74
75
  - test/server.rb
75
76
  - test/test.rb
76
77
  - test/ut_0_http_get.rb