couchobject 0.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,47 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe CouchObject::Response do
4
+ before(:each) do
5
+ @net_response = mock("Net::HTTP::Response")
6
+ @net_response.stub!(:code).and_return(200)
7
+ @net_response.stub!(:body).and_return("{\"foo\":\"bar\"}")
8
+ end
9
+
10
+ it "should get the response code" do
11
+ resp = CouchObject::Response.new(@net_response)
12
+ resp.code.should == 200
13
+ end
14
+
15
+ it "should know if the response was a success" do
16
+ resp = CouchObject::Response.new(@net_response)
17
+ resp.success?.should == true
18
+ end
19
+
20
+ it "should have the body of the response" do
21
+ resp = CouchObject::Response.new(@net_response)
22
+ resp.body.should == "{\"foo\":\"bar\"}"
23
+ end
24
+
25
+ it "should parse the response" do
26
+ @net_response.stub!(:body).and_return("[\"foo\", \"bar\"]")
27
+ resp = CouchObject::Response.new(@net_response)
28
+ resp.parse.parsed_body.should == ["foo", "bar"]
29
+ end
30
+
31
+ it "should parse the response body even if error" do
32
+ @net_response.stub!(:code).and_return(404)
33
+ resp = CouchObject::Response.new(@net_response)
34
+ resp.parse.parsed_body.should == {"foo" => "bar"}
35
+ end
36
+
37
+ it "should return itself when calling parse" do
38
+ resp = CouchObject::Response.new(@net_response)
39
+ resp.parse.should be_instance_of(CouchObject::Response)
40
+ end
41
+
42
+ it "should return its body as a Document with to_document" do
43
+ resp = CouchObject::Response.new(@net_response)
44
+ resp.to_document.should be_instance_of(CouchObject::Document)
45
+ resp.to_document["foo"].should == "bar"
46
+ end
47
+ end
@@ -0,0 +1,149 @@
1
+ # (c) Copyright 2006-2007 Nick Sieger <nicksieger@gmail.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person
4
+ # obtaining a copy of this software and associated documentation files
5
+ # (the "Software"), to deal in the Software without restriction,
6
+ # including without limitation the rights to use, copy, modify, merge,
7
+ # publish, distribute, sublicense, and/or sell copies of the Software,
8
+ # and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18
+ # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19
+ # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'rubygems'
24
+ gem 'ZenTest'
25
+ require 'autotest'
26
+
27
+ class RspecAutotest < Autotest
28
+ attr_accessor :spec_command
29
+ def initialize # :nodoc:
30
+ @spec_command = "spec --diff unified --color"
31
+ super
32
+ @exceptions = %r%^\./(?:coverage|doc)%
33
+ end
34
+
35
+ def tests_for_file(filename)
36
+ case filename
37
+ when /^lib\/.*\.rb$/ then
38
+ impl = File.basename(filename).gsub('_', '_?').sub(/\.rb$/, '')
39
+ @files.keys.select do |k|
40
+ k =~ %r%^spec/.*#{impl}_spec\.rb$%
41
+ end
42
+ when %r%^spec/spec_helper.rb% then
43
+ @files.keys.select do |f|
44
+ f =~ %r%^spec/.*_spec\.rb$%
45
+ end
46
+ when /^spec\/.*_spec\.rb$/ then
47
+ [filename]
48
+ when /#{Regexp.quote(File.basename(__FILE__))}/
49
+ # Don't respond to changes to this file
50
+ []
51
+ else
52
+ @output.puts "Dunno! #{filename}" if $TESTING
53
+ []
54
+ end
55
+ end
56
+
57
+ def handle_results(results)
58
+ failed = results.scan(/^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m)
59
+ @files_to_test = consolidate_failures failed
60
+ unless @files_to_test.empty? then
61
+ hook :red
62
+ else
63
+ hook :green
64
+ end unless $TESTING
65
+ @tainted = true unless @files_to_test.empty?
66
+ end
67
+
68
+ def consolidate_failures(failed)
69
+ filters = Hash.new { |h,k| h[k] = [] }
70
+ failed.each do |spec, failed_trace|
71
+ @files.keys.select{|f| f =~ /spec\//}.each do |f|
72
+ if failed_trace =~ Regexp.new(f)
73
+ filters[f] << spec
74
+ break
75
+ end
76
+ end
77
+ end
78
+ return filters
79
+ end
80
+
81
+ def make_test_cmd(files_to_test)
82
+ cmds = []
83
+ full, partial = files_to_test.partition { |k,v| v.empty? }
84
+
85
+ unless full.empty? then
86
+ classes = full.map {|k,v| k}.flatten.join(' ')
87
+ cmds << "#{spec_command} #{classes}"
88
+ end
89
+
90
+ partial.each do |klass, methods|
91
+ methods.each { |meth| cmds << "#{spec_command} -s #{meth.inspect} #{klass}" }
92
+ end
93
+
94
+ return cmds.join('; ')
95
+ end
96
+ end
97
+
98
+ class RspecOnRailsAutotest < RspecAutotest
99
+ def initialize # :nodoc:
100
+ super
101
+ @exceptions = %r%^\./(?:coverage|db|doc|log|public|script|vendor)%
102
+ end
103
+
104
+ def tests_for_file(filename)
105
+ case filename
106
+ when %r%^spec/fixtures/(.*)s.yml% then
107
+ ["spec/models/#{$1}_spec.rb",
108
+ "spec/controllers/#{$1}_controller_spec.rb"]
109
+ when %r%^spec/models/.*rb$% then
110
+ [filename]
111
+ when %r%^spec/controllers/.*\.rb$% then
112
+ [filename]
113
+ when %r%^spec/views/.*\.rb$% then
114
+ [filename]
115
+ when %r%^spec/helpers/.*\.rb$% then
116
+ [filename]
117
+ when %r%^app/models/(.*)\.rb$% then
118
+ ["spec/models/#{$1}_spec.rb"]
119
+ when %r%^app/helpers/application_helper.rb% then
120
+ @files.keys.select { |f|
121
+ f =~ %r%^spec/controllers/.*_spec\.rb$%
122
+ }
123
+ when %r%^app/helpers/(.*)_helper.rb% then
124
+ ["spec/controllers/#{$1}_controller_spec.rb", "spec/helpers/#{$1}_spec.rb"]
125
+ when %r%^app/controllers/application.rb$% then
126
+ @files.keys.select { |f|
127
+ f =~ %r%^spec/controllers/.*_spec\.rb$%
128
+ }
129
+ when %r%^app/controllers/(.*)\.rb$% then
130
+ ["spec/controllers/#{$1}_spec.rb"]
131
+ when %r%^app/views/layouts/% then
132
+ []
133
+ when %r%^app/views/(.*)/% then
134
+ ["spec/controllers/#{$1}_controller_spec.rb", "spec/views/#{$1}_spec.rb"]
135
+ when %r%^config/routes.rb$% then
136
+ @files.keys.select do |f|
137
+ f =~ %r%^spec/controllers/.*_spec\.rb$%
138
+ end
139
+ when %r%^spec/spec_helper.rb%,
140
+ %r%^config/((boot|environment(s/test)?).rb|database.yml)% then
141
+ @files.keys.select do |f|
142
+ f =~ %r%^spec/(models|controllers)/.*_spec\.rb$%
143
+ end
144
+ else
145
+ @output.puts "Dunno! #{filename}" if $TESTING
146
+ []
147
+ end.uniq.select { |f| @files.has_key? f }
148
+ end
149
+ end
@@ -0,0 +1,74 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe CouchObject::Server do
4
+
5
+ it "should initialize with a URI" do
6
+ server = CouchObject::Server.new("http://localhost:8888")
7
+ server.host.should == "localhost"
8
+ server.port.should == 8888
9
+ end
10
+
11
+ it "should have a connection active when its initialized" do
12
+ server = CouchObject::Server.new("http://localhost:8888")
13
+ server.connection.should_not be(nil)
14
+ server.connection.class.should == Net::HTTP
15
+ end
16
+
17
+ it "should dispatch requests" do
18
+ server = CouchObject::Server.new("http://localhost:8888")
19
+ request = mock(Net::HTTP::Get)
20
+ server.connection.should_receive(:request).with(request).and_return("response")
21
+ server.request(request)
22
+ end
23
+ end
24
+
25
+ describe CouchObject::Server, "Request methods" do
26
+ before(:each) do
27
+ @server = CouchObject::Server.new("http://localhost:8888")
28
+ @mock_request = mock("Net::HTTP::{requestmethod}")
29
+ end
30
+
31
+ it "should have GET" do
32
+ Net::HTTP::Get.should_receive(:new).with("/foo").and_return(@mock_request)
33
+ @server.connection.should_receive(:request).with(@mock_request).and_return("response")
34
+ @server.get("/foo")
35
+ end
36
+
37
+ it "should have POST" do
38
+ Net::HTTP::Post.should_receive(:new).with("/foo").and_return(@mock_request)
39
+ @mock_request.should_receive(:body=).with("bar")
40
+ @mock_request.stub!(:[]=)
41
+ @server.connection.should_receive(:request).with(@mock_request).and_return("response")
42
+ @server.post("/foo", "bar")
43
+ end
44
+
45
+ it "should have PUT" do
46
+ Net::HTTP::Put.should_receive(:new).with("/foo").and_return(@mock_request)
47
+ @mock_request.should_receive(:body=).with("bar")
48
+ @mock_request.stub!(:[]=)
49
+ @server.connection.should_receive(:request).with(@mock_request).and_return("response")
50
+ @server.put("/foo", "bar")
51
+ end
52
+
53
+ it "should have DELETE" do
54
+ Net::HTTP::Delete.should_receive(:new).with("/foo").and_return(@mock_request)
55
+ @server.connection.should_receive(:request).with(@mock_request).and_return("response")
56
+ @server.delete("/foo")
57
+ end
58
+
59
+ it "should POST with application/json as the Content-Type header" do
60
+ Net::HTTP::Post.should_receive(:new).with("/foo").and_return(@mock_request)
61
+ @mock_request.stub!(:body=)
62
+ @mock_request.should_receive(:[]=).with("content-type", "application/json")
63
+ @server.connection.should_receive(:request).with(@mock_request).and_return("response")
64
+ @server.post("/foo", "bar")
65
+ end
66
+
67
+ it "should PUT with application/json as the Content-Tyoe header" do
68
+ Net::HTTP::Put.should_receive(:new).with("/foo").and_return(@mock_request)
69
+ @mock_request.stub!(:body=)
70
+ @mock_request.should_receive(:[]=).with("content-type", "application/json")
71
+ @server.connection.should_receive(:request).with(@mock_request).and_return("response")
72
+ @server.put("/foo", "bar")
73
+ end
74
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse
@@ -0,0 +1,9 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ require File.dirname(__FILE__) + "/../lib/couch_object"
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe CouchObject::Utils do
4
+
5
+ it "should join urls" do
6
+ CouchObject::Utils.join_url("http://x.tld", "foo").should == "http://x.tld/foo"
7
+ CouchObject::Utils.join_url("http://x.tld", "/foo").should == "http://x.tld/foo"
8
+ CouchObject::Utils.join_url("http://x.tld/", "/foo").should == "http://x.tld/foo"
9
+ CouchObject::Utils.join_url("http://x.tld/", "/foo/").should == "http://x.tld/foo/"
10
+ end
11
+
12
+ it "should join two or more relative urls too" do
13
+ CouchObject::Utils.join_url("foo", "bar").should == "foo/bar"
14
+ CouchObject::Utils.join_url("foo/", "/bar").should == "foo/bar"
15
+ CouchObject::Utils.join_url("/foo/", "/bar").should == "foo/bar"
16
+ CouchObject::Utils.join_url("/foo/", "/bar/").should == "foo/bar"
17
+ end
18
+ end
data/spec/view_spec.rb ADDED
@@ -0,0 +1,36 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe CouchObject::View do
4
+
5
+ before(:each) do
6
+ @server = mock("CouchObject::Server mock")
7
+ @db = CouchObject::Database.open("http://localhost:8888/foo")
8
+ @db.server = @server
9
+ @js = "function(doc){ return doc }"
10
+ @response = mock("Net::HTTP::Response")
11
+ @response.stub!(:code).and_return(200)
12
+ @response.stub!(:body).and_return(%Q'{"view":"_foo_view:#{@js}","total_rows":0,"rows":[]}')
13
+ end
14
+
15
+ it "should create a new views" do
16
+ @db.should_receive(:post).with("/foo/_view_myview", @js).and_return(@response)
17
+ CouchObject::View.create(@db, "myview", @js)
18
+ end
19
+
20
+ it "should initialzie with db and name and have a view name" do
21
+ view = CouchObject::View.new(@db, "myview")
22
+ view.name.should == "_view_myview"
23
+ view.db.should == @db
24
+ end
25
+
26
+ it "should delete a view" do
27
+ view = CouchObject::View.new(@db, "myview")
28
+ @db.should_receive(:delete).with("/foo/_view_myview").and_return(true)
29
+ view.delete
30
+ end
31
+
32
+ # it "should query the database with itself"
33
+ # it "should have a ::query singleton for temp view queries"
34
+ # it "should iterate over the results"
35
+ #
36
+ end
@@ -0,0 +1,27 @@
1
+ desc 'Release the website and new gem version'
2
+ task :deploy => [:check_version, :website, :release] do
3
+ puts "Remember to create SVN tag:"
4
+ puts "svn copy svn+ssh://#{RUBYFORGE_USERNAME}@rubyforge.org/var/svn/#{PATH}/trunk " +
5
+ "svn+ssh://#{RUBYFORGE_USERNAME}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
6
+ puts "Suggested comment:"
7
+ puts "Tagging release #{CHANGES}"
8
+ end
9
+
10
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
11
+ task :local_deploy => [:website_generate, :install_gem]
12
+
13
+ task :check_version do
14
+ unless ENV['VERSION']
15
+ puts 'Must pass a VERSION=x.y.z release version'
16
+ exit
17
+ end
18
+ unless ENV['VERSION'] == VERS
19
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
20
+ exit
21
+ end
22
+ end
23
+
24
+ desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
25
+ task :install_gem_no_doc => [:clean, :package] do
26
+ sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
27
+ end
@@ -0,0 +1,7 @@
1
+ task :ruby_env do
2
+ RUBY_APP = if RUBY_PLATFORM =~ /java/
3
+ "jruby"
4
+ else
5
+ "ruby"
6
+ end unless defined? RUBY_APP
7
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,42 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
22
+
23
+ namespace :spec do
24
+ desc "Start Autotest"
25
+ task :autotest do
26
+ require File.join(File.dirname(__FILE__), '..', 'spec', 'rspec_autotest')
27
+ RspecAutotest.run
28
+ end
29
+
30
+ desc "run specs with rcov"
31
+ Spec::Rake::SpecTask.new(:rcov) do |t|
32
+ t.spec_opts = ['--options', "spec/spec.opts"]
33
+ t.spec_files = FileList['spec/**/*_spec.rb']
34
+ t.rcov = true
35
+ t.rcov_dir = './doc/coverage'
36
+ t.rcov_opts = ['--exclude', 'spec\/spec_helper.rb,spec\/rspec_autotest.rb']
37
+ end
38
+ end
39
+
40
+ # desc "Default task is to run specs"
41
+ # task :default => :spec
42
+ Rake.application[:default].prerequisites.gsub! /test/, 'spec'
@@ -0,0 +1,9 @@
1
+ # stubs for the website generation
2
+ # To install the website framework:
3
+ # script/generate website
4
+
5
+ task :website_generate
6
+
7
+ task :website_upload
8
+
9
+ task :website => :publish_docs
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: couchobject
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1
7
+ date: 2007-09-13 00:00:00 +02:00
8
+ summary: CouchObject is a library that maps ruby objects to CouchDb documents
9
+ require_paths:
10
+ - lib
11
+ email: johan@johansorensen.com
12
+ homepage: http://couchobject.rubyforge.org
13
+ rubyforge_project: couchobject
14
+ description: CouchObject is a library that maps ruby objects to CouchDb documents
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - "Johan S\xC3\xB8rensen"
31
+ files:
32
+ - History.txt
33
+ - License.txt
34
+ - Manifest.txt
35
+ - README.txt
36
+ - Rakefile
37
+ - TODO
38
+ - config/hoe.rb
39
+ - config/requirements.rb
40
+ - lib/couch_object.rb
41
+ - lib/couch_object/database.rb
42
+ - lib/couch_object/document.rb
43
+ - lib/couch_object/model.rb
44
+ - lib/couch_object/persistable.rb
45
+ - lib/couch_object/response.rb
46
+ - lib/couch_object/server.rb
47
+ - lib/couch_object/utils.rb
48
+ - lib/couch_object/version.rb
49
+ - lib/couch_object/view.rb
50
+ - log/debug.log
51
+ - script/console
52
+ - script/destroy
53
+ - script/generate
54
+ - setup.rb
55
+ - spec/database_spec.rb
56
+ - spec/document_spec.rb
57
+ - spec/integration/database_integration_spec.rb
58
+ - spec/integration/document_integration_spec.rb
59
+ - spec/integration/integration_helper.rb
60
+ - spec/model_spec.rb
61
+ - spec/persistable_spec.rb
62
+ - spec/response_spec.rb
63
+ - spec/rspec_autotest.rb
64
+ - spec/server_spec.rb
65
+ - spec/spec.opts
66
+ - spec/spec_helper.rb
67
+ - spec/utils_spec.rb
68
+ - spec/view_spec.rb
69
+ - tasks/deployment.rake
70
+ - tasks/environment.rake
71
+ - tasks/rspec.rake
72
+ - tasks/website.rake
73
+ test_files:
74
+ - spec/spec_helper.rb
75
+ rdoc_options:
76
+ - --main
77
+ - README.txt
78
+ extra_rdoc_files:
79
+ - History.txt
80
+ - License.txt
81
+ - Manifest.txt
82
+ - README.txt
83
+ executables: []
84
+
85
+ extensions: []
86
+
87
+ requirements: []
88
+
89
+ dependencies:
90
+ - !ruby/object:Gem::Dependency
91
+ name: json
92
+ version_requirement:
93
+ version_requirements: !ruby/object:Gem::Version::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: 1.1.1
98
+ version: