Skip to content

Commit

Permalink
couch : from test/ to spec/
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Nov 30, 2010
1 parent 4652ab0 commit 14ed926
Show file tree
Hide file tree
Showing 19 changed files with 694 additions and 658 deletions.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--colour --format documentation
18 changes: 13 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


require 'lib/rufus/jig/version.rb'

require 'rubygems'
Expand All @@ -11,7 +10,17 @@ require 'rake'

require 'rake/clean'
CLEAN.include('pkg', 'tmp', 'html', 'rdoc')
task :default => [ :clean ]

#
# SPEC / TEST

#task :spec => :check_dependencies do
task :spec do
sh 'rspec spec/'
end
task :test => :spec

task :default => :spec


#
Expand All @@ -30,18 +39,17 @@ Jeweler::Tasks.new do |gem|
An HTTP client, greedy with JSON content, GETting conditionally.
Uses Patron and Yajl-ruby whenever possible.
Uses Yajl-ruby whenever possible.
}
gem.email = 'jmettraux@gmail.com'
gem.homepage = 'http://github.com/jmettraux/rufus-jig/'
gem.authors = [ 'John Mettraux', 'Kenneth Kalmer' ]
gem.rubyforge_project = 'rufus'

gem.test_file = 'test/test.rb'

gem.add_dependency 'rufus-lru'
gem.add_dependency 'rufus-json', '>= 0.2.5'
gem.add_development_dependency 'rake'
gem.add_development_dependency 'rspec', '~> 2.2.0'
gem.add_development_dependency 'yard'
gem.add_development_dependency 'jeweler'
gem.add_development_dependency 'patron'
Expand Down
2 changes: 2 additions & 0 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@

[ ] netp : close() impl

[ ] views : couch#query(view, opts) ?

53 changes: 42 additions & 11 deletions rufus-jig.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

Gem::Specification.new do |s|
s.name = %q{rufus-jig}
s.version = "0.1.23"
s.version = "1.0.0"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["John Mettraux", "Kenneth Kalmer"]
s.date = %q{2010-10-01}
s.date = %q{2010-11-30}
s.description = %q{
Json Interwebs Get.
An HTTP client, greedy with JSON content, GETting conditionally.
Uses Patron and Yajl-ruby whenever possible.
Uses Yajl-ruby whenever possible.
}
s.email = %q{jmettraux@gmail.com}
s.extra_rdoc_files = [
Expand All @@ -24,6 +24,7 @@ Gem::Specification.new do |s|
]
s.files = [
".gitignore",
".rspec",
"CHANGELOG.txt",
"CREDITS.txt",
"LICENSE.txt",
Expand All @@ -42,18 +43,21 @@ Gem::Specification.new do |s|
"lib/rufus/jig/path.rb",
"lib/rufus/jig/version.rb",
"rufus-jig.gemspec",
"spec/couch/couch_attachements_spec.rb",
"spec/couch/couch_continuous.rb",
"spec/couch/couch_db_spec.rb",
"spec/couch/couch_spec.rb",
"spec/couch/couch_views_spec.rb",
"spec/couch/tweet.png",
"spec/couch_url.txt",
"spec/spec_helper.rb",
"spec/support/couch_helper.rb",
"test/base.rb",
"test/bm/bm0.rb",
"test/bm/bm1.rb",
"test/conc/put_vs_delete.rb",
"test/couch_base.rb",
"test/couch_url.txt",
"test/ct_0_couch.rb",
"test/ct_1_couchdb.rb",
"test/ct_2_couchdb_options.rb",
"test/ct_3_couchdb_views.rb",
"test/ct_4_attachments.rb",
"test/ct_5_couchdb_continuous.rb",
"test/cut_0_auth_couch.rb",
"test/server.rb",
"test/test.rb",
Expand All @@ -74,10 +78,34 @@ Gem::Specification.new do |s|
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{rufus}
s.rubygems_version = %q{1.3.6}
s.rubygems_version = %q{1.3.5}
s.summary = %q{An HTTP client, greedy with JSON content, GETting conditionally.}
s.test_files = [
"test/test.rb"
"spec/couch/couch_attachements_spec.rb",
"spec/couch/couch_continuous.rb",
"spec/couch/couch_db_spec.rb",
"spec/couch/couch_spec.rb",
"spec/couch/couch_views_spec.rb",
"spec/spec_helper.rb",
"spec/support/couch_helper.rb",
"test/base.rb",
"test/bm/bm0.rb",
"test/bm/bm1.rb",
"test/conc/put_vs_delete.rb",
"test/couch_base.rb",
"test/cut_0_auth_couch.rb",
"test/server.rb",
"test/test.rb",
"test/tt_0_get_timeout.rb",
"test/ut_0_http_get.rb",
"test/ut_1_http_post.rb",
"test/ut_2_http_delete.rb",
"test/ut_3_http_put.rb",
"test/ut_4_http_prefix.rb",
"test/ut_5_http_misc.rb",
"test/ut_6_args.rb",
"test/ut_7_parse_uri.rb",
"test/ut_8_auth.rb"
]

if s.respond_to? :specification_version then
Expand All @@ -88,6 +116,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency(%q<rufus-lru>, [">= 0"])
s.add_runtime_dependency(%q<rufus-json>, [">= 0.2.5"])
s.add_development_dependency(%q<rake>, [">= 0"])
s.add_development_dependency(%q<rspec>, ["~> 2.2.0"])
s.add_development_dependency(%q<yard>, [">= 0"])
s.add_development_dependency(%q<jeweler>, [">= 0"])
s.add_development_dependency(%q<patron>, [">= 0"])
Expand All @@ -97,6 +126,7 @@ Gem::Specification.new do |s|
s.add_dependency(%q<rufus-lru>, [">= 0"])
s.add_dependency(%q<rufus-json>, [">= 0.2.5"])
s.add_dependency(%q<rake>, [">= 0"])
s.add_dependency(%q<rspec>, ["~> 2.2.0"])
s.add_dependency(%q<yard>, [">= 0"])
s.add_dependency(%q<jeweler>, [">= 0"])
s.add_dependency(%q<patron>, [">= 0"])
Expand All @@ -107,6 +137,7 @@ Gem::Specification.new do |s|
s.add_dependency(%q<rufus-lru>, [">= 0"])
s.add_dependency(%q<rufus-json>, [">= 0.2.5"])
s.add_dependency(%q<rake>, [">= 0"])
s.add_dependency(%q<rspec>, ["~> 2.2.0"])
s.add_dependency(%q<yard>, [">= 0"])
s.add_dependency(%q<jeweler>, [">= 0"])
s.add_dependency(%q<patron>, [">= 0"])
Expand Down
113 changes: 113 additions & 0 deletions spec/couch/attachements_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

#
# specifying rufus-jig
#
# Tue Nov 30 09:12:59 JST 2010
#

require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')


describe Rufus::Jig::Couch do

context 'with attachments' do

before(:each) do

h = Rufus::Jig::Http.new(couch_url)
begin
h.delete('/rufus_jig_test')
rescue Exception => e
#p e
end

h.put('/rufus_jig_test', '')
h.close

@c = Rufus::Jig::Couch.new(couch_url, 'rufus_jig_test')

@c.put('_id' => 'thedoc', 'function' => 'recipient for attachements')
@d = @c.get('thedoc')
end

after(:each) do

@c.close
end

describe '#attach' do

it 'attaches' do

@c.attach(
'thedoc', @d['_rev'], 'message', 'this is a message',
:content_type => 'text/plain')

@c.get('thedoc/message').should == 'this is a message'
end

it 'attaches with the right content-type' do

@c.attach(
'thedoc', @d['_rev'], 'message', 'this is a message',
:content_type => 'text/plain')

r = @c.get('thedoc/message', :raw => true)
r.status.should == 200
r.headers['Content-Type'].should == 'text/plain'
end

it 'returns the couch response' do

r = @c.attach(
'thedoc', @d['_rev'], 'message', 'this is a message',
:content_type => 'text/plain')

r.keys.sort.should == %w[ id ok rev ]
end

it 'raises if it failed' do

lambda {
@c.attach(
'thedoc', '999-123e', 'message', 'this is a message',
:content_type => 'text/plain')
}.should raise_error
end
end

describe '#detach' do

before (:each) do

r = @c.attach(
'thedoc', @d['_rev'],
'image', File.read(File.join(File.dirname(__FILE__), 'tweet.png')),
:content_type => 'image/png')
@d['_rev'] = r['rev']
end

it 'detaches' do

@c.detach('thedoc', @d['_rev'], 'image')

@c.get('thedoc/image').should == nil
end

it 'returns the couch response' do

r = @c.detach('thedoc', @d['_rev'], 'image')

r.keys.sort.should == %w[ id ok rev ]
end

it 'raises if it failed' do

lambda {
@c.detach('thedoc', '999-12340e', 'image')
}.should raise_error
end
end
end
end

97 changes: 97 additions & 0 deletions spec/couch/continuous.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# encoding: UTF-8

#
# specifying rufus-jig
#
# Tue Nov 30 10:16:03 JST 2010
#

require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')


describe Rufus::Jig::Couch do

context 'and feed=continuous' do

before(:each) do

h = Rufus::Jig::Http.new(couch_url)

begin
h.delete('/rufus_jig_test')
rescue Exception => e
#p e
end
h.put('/rufus_jig_test', '')
h.close

@c = Rufus::Jig::Couch.new(couch_url, 'rufus_jig_test')
end

after(:each) do

@c.close
end

describe '#on_change' do

it 'intercepts changes' do

stack = []

t = Thread.new do
@c.on_change { |doc_id, deleted| stack << doc_id }
end

@c.put('_id' => 'angel0', 'name' => 'samael')
@c.put('_id' => 'angel1', 'name' => 'raphael')

sleep 0.500
t.kill

stack.size.should == 2
end

it 'intercepts changes and docs' do

stack = []

Thread.abort_on_exception = true

t = Thread.new do
@c.on_change { |doc_id, deleted, doc| stack << doc }
end

@c.put('_id' => 'angel2', 'name' => 'samael')
@c.put('_id' => 'angel3', 'name' => 'ゆきひろ')

sleep 0.500
t.kill

stack[1]['name'].should == 'ゆきひろ'
end

it 'intercepts changes and among them, doc deletions' do

stack = []

Thread.abort_on_exception = true

t = Thread.new do
@c.on_change { |doc_id, deleted, doc| stack << [ doc_id, deleted ] }
end

@c.put('_id' => 'angel4', 'name' => 'samael')
sleep 0.077
@c.delete(@c.get('angel4'))

sleep 0.500
t.kill

([["angel4", false], ["angel4", true]] == stack ||
[["angel4", true]] == stack).should == true
end
end
end
end

Loading

0 comments on commit 14ed926

Please sign in to comment.