relaxo-query-server 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZDVhYmYxZWNlYmQwNmQzNGRmYzdiYzJhMTQxY2Y3MTY2N2E1MjBlNw==
5
- data.tar.gz: !binary |-
6
- MDUzMmI3YjIzNWZmMzU3NTNjNDBmNmUwYTVmM2ExYjU2NzMzMWYyNA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- YTgxMjllODIyMjhmM2JmYzA2ODMxZmM0M2I2YWQ1MjRhYzE0ZDgyYmFhMjQy
10
- ZGVjYzEwMzQ5MDBiOTNkNjIwYmM1NTJiZDc0MDg4OGFkNGM3NmNkNmIzNjA3
11
- ZjY1ZjRiYzJhMzQxOGQ5MmZjMWQzNzJlMGVkYjZmMTNkOTMzNzY=
12
- data.tar.gz: !binary |-
13
- YmJhZjVhNmU4ZmRiM2FiMTc1NWU2Nzg4MDRmYTgwNDU1MDYyODE2YmU4ZDIy
14
- M2UwZTJhOTI1NDBlNWFmMWFiMzYyNWNiMDI5NDljMzNhYTIyNDllNmZiOTli
15
- MGQ1YzcxOTZkOTAzZDlhMjY3NGUyZWMyYmIyY2M5M2ExYTAxNmY=
2
+ SHA1:
3
+ metadata.gz: 78944e73c0640d81426a896195caf1dac016cccf
4
+ data.tar.gz: 32d6f60802a40842fbea80820c1914f06e6409cf
5
+ SHA512:
6
+ metadata.gz: 5df2161444eee230a5eff87830986c5b060ea38d53e3823c48bc94c3a54969760c6ba91bd7bcb23a30673afafe654901305476efa7aec2c956b3e8c58a941f32
7
+ data.tar.gz: 403b146fb25f50a0dfc71b6d8cc845159c86d0491954d505af9f08419f64db569d0598ca68386c526779a1a0a96bdd0f887b4d42fa65492c728406f110038728
@@ -0,0 +1,9 @@
1
+
2
+ SimpleCov.start do
3
+ add_filter "/spec/"
4
+ end
5
+
6
+ if ENV['TRAVIS']
7
+ require 'coveralls'
8
+ Coveralls.wear!
9
+ end
@@ -1,11 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "1.8.7"
4
- - "1.9.2"
5
- - "1.9.3"
6
- - jruby-18mode # JRuby in 1.8 mode
7
- - jruby-19mode # JRuby in 1.9 mode
8
- - rbx-18mode
9
- - rbx-19mode
3
+ - 2.0
4
+ - 2.1
5
+ - 2.2
10
6
  services:
11
7
  - couchdb
8
+ env: COVERAGE=true
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in relaxo-query-server.gemspec
4
4
  gemspec
5
5
 
6
- platforms :jruby do
7
- gem 'jruby-openssl'
6
+ group :test do
7
+ gem 'simplecov'
8
+ gem 'coveralls', require: false
8
9
  end
data/README.md CHANGED
@@ -2,11 +2,10 @@
2
2
 
3
3
  The Relaxo Query Server implements the CouchDB Query Server protocol for CouchDB 1.1.0+. It provides a comprehensive Ruby-style view server along with full support for Design Document based processing.
4
4
 
5
- For more information and examples please see the main [project page][1].
6
-
7
- [1]: http://www.codeotaku.com/projects/relaxo/query-server
8
5
 
9
6
  [![Build Status](https://secure.travis-ci.org/ioquatix/relaxo-query-server.png)](http://travis-ci.org/ioquatix/relaxo-query-server)
7
+ [![Code Climate](https://codeclimate.com/github/ioquatix/relaxo-query-server.png)](https://codeclimate.com/github/ioquatix/relaxo-query-server)
8
+ [![Coverage Status](https://coveralls.io/repos/ioquatix/relaxo-query-server/badge.svg)](https://coveralls.io/r/ioquatix/relaxo-query-server)
10
9
 
11
10
  ## Installation
12
11
 
@@ -23,7 +22,7 @@ Make sure the `relaxo-query-server` executable is accessible from `$PATH`.
23
22
 
24
23
  `relaxo-query-server` includes a variety of 3rd party modules by default, but it can include other libraries by specifying them on the command line:
25
24
 
26
- relaxo-ruby = ruby1.9 -rdate -rbigdecimal relaxo-query-server
25
+ relaxo-ruby = ruby -rdate -rbigdecimal relaxo-query-server
27
26
 
28
27
  (You can also load code by specifying libraries in your design documents and views.)
29
28
 
@@ -116,7 +115,9 @@ The previous `design.yaml` document can be loaded using the `relaxo` client comm
116
115
 
117
116
  ## License
118
117
 
119
- Copyright (c) 2010, 2012 Samuel G. D. Williams. <http://www.codeotaku.com>
118
+ Released under the MIT license.
119
+
120
+ Copyright, 2015, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
120
121
 
121
122
  Permission is hereby granted, free of charge, to any person obtaining a copy
122
123
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |task|
5
+ task.rspec_opts = ["--require", "simplecov"] if ENV['COVERAGE']
6
+ end
7
+
8
+ task :default => :spec
@@ -17,7 +17,7 @@ ARGV.options do |o|
17
17
  o.separator ""
18
18
  o.separator "Help and Copyright information"
19
19
 
20
- o.on("--safe [level]", "Set the ruby $SAFE level to product the execution environment.") do |level|
20
+ o.on("--safe [level]", "Set the ruby $SAFE level to protect the execution environment.") do |level|
21
21
  OPTIONS[:safe] = level.to_i
22
22
  end
23
23
 
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Relaxo
22
22
  module QueryServer
23
- VERSION = "0.1.3"
23
+ VERSION = "0.1.4"
24
24
  end
25
25
  end
@@ -23,11 +23,12 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
24
24
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
25
25
  spec.require_paths = ["lib"]
26
-
27
- spec.add_development_dependency "bundler", "~> 1.3"
28
- spec.add_development_dependency "rake"
29
26
 
30
- spec.add_dependency "relaxo", "~> 0.4.0"
31
- spec.add_dependency "json", "~> 1.7.3"
27
+ spec.add_dependency "relaxo", "~> 0.4.4"
28
+ spec.add_dependency "json", "~> 1.8"
32
29
  spec.add_dependency "rest-client"
30
+
31
+ spec.add_development_dependency "rspec", "~> 3.1.0"
32
+ spec.add_development_dependency "bundler", "~> 1.3"
33
+ spec.add_development_dependency "rake"
33
34
  end
@@ -0,0 +1,28 @@
1
+
2
+ require_relative 'spec_helper'
3
+
4
+ RSpec.describe "Relaxo Filters" do
5
+ before :all do
6
+ @shell = Relaxo::QueryServer::MockShell.new
7
+ @context = Relaxo::QueryServer::Context.new(@shell, safe: 2)
8
+ end
9
+
10
+ def run_filter(opts={})
11
+ opts[:docs] ||= []
12
+ opts[:req] ||= {}
13
+
14
+ @context.run ["ddoc", "foo", ["filters", "basic"], [opts[:docs], opts[:req]]]
15
+ end
16
+
17
+ it "should apply filters" do
18
+ basic = "lambda{|doc, req| doc['good'] == true}"
19
+ @context.run ["ddoc", "new", "foo", {"filters" => {"basic" => basic}}]
20
+
21
+ docs = (1..3).map do |i|
22
+ {"good" => i.odd?}
23
+ end
24
+
25
+ results = run_filter({:docs => docs})
26
+ expect(results).to be == [true, [true, false, true]]
27
+ end
28
+ end
@@ -1,12 +1,18 @@
1
1
 
2
- require 'helper'
3
2
  require 'relaxo/query_server/library'
4
3
 
5
4
  require 'bigdecimal'
6
5
  require 'bigdecimal/util'
7
6
 
8
- class LibrariesTest < ContextualTestCase
9
- def test_libraries
7
+ require_relative 'spec_helper'
8
+
9
+ RSpec.describe "Libraries" do
10
+ before :all do
11
+ @shell = Relaxo::QueryServer::MockShell.new
12
+ @context = Relaxo::QueryServer::Context.new(@shell, safe: 2)
13
+ end
14
+
15
+ it "should load a library" do
10
16
  root = {
11
17
  'lib' => {
12
18
  'all' => %q{
@@ -24,18 +30,15 @@ class LibrariesTest < ContextualTestCase
24
30
  }
25
31
 
26
32
  object = Relaxo::QueryServer::Library.for(root, 'lib/bar')
27
-
28
- assert_not_nil object
29
- assert object.respond_to? :bar
30
-
31
- assert_equal "10".to_d, object.bar
33
+ expect(object).to be_respond_to :bar
34
+ expect(object.bar).to be == "10".to_d
32
35
 
33
36
  # For efficiency, the same object is returned both times
34
37
  same_object = Relaxo::QueryServer::Library.for(root, 'lib/bar')
35
- assert_equal object, same_object
38
+ expect(same_object).to be object
36
39
  end
37
40
 
38
- def test_map_reduce_libraries
41
+ it "should use library functions for map/reduce" do
39
42
  library_code = %q{
40
43
  def check_bar(doc)
41
44
  yield doc if doc['bar'] == true
@@ -51,12 +54,12 @@ class LibrariesTest < ContextualTestCase
51
54
  }
52
55
 
53
56
  response = @context.run ['add_lib', {'foo' => library_code}]
54
- assert_equal true, response
57
+ expect(response).to be true
55
58
 
56
59
  response = @context.run ['add_fun', map_function_code]
57
- assert_equal true, response
60
+ expect(response).to be true
58
61
 
59
62
  response = @context.run ['map_doc', {'bar' => true}]
60
- assert_equal [[[true, nil]]], response
63
+ expect(response).to be == [[[true, nil]]]
61
64
  end
62
65
  end
@@ -0,0 +1,49 @@
1
+
2
+ require_relative 'spec_helper'
3
+
4
+ RSpec.describe "Lists" do
5
+ before :all do
6
+ @shell = Relaxo::QueryServer::MockShell.new
7
+ @context = Relaxo::QueryServer::Context.new(@shell, safe: 2)
8
+ end
9
+
10
+ def create_design_document name, attributes
11
+ @context.run ['ddoc', 'new', name, attributes]
12
+ end
13
+
14
+ it "should list all items" do
15
+ create_design_document "test", {
16
+ 'lists' => {
17
+ 'entire' => <<-EOF
18
+ lambda{|head,request|
19
+ send "<ul>"
20
+ each do |row|
21
+ send "<li>" + row['count'] + "</li>"
22
+ end
23
+ send "</ul>"
24
+ }
25
+ EOF
26
+ }
27
+ }
28
+
29
+ rows = [
30
+ ["list_row", {"count"=>"Neko"}],
31
+ ["list_row", {"count"=>"Nezumi"}],
32
+ ["list_row", {"count"=>"Zoe"}],
33
+ ["list_end"]
34
+ ]
35
+
36
+ rows.each {|row| @shell.input << row}
37
+
38
+ result = @context.run ['ddoc', 'test', ['lists', 'entire'], [{}, {}]]
39
+
40
+ expect(@shell.output).to be == [
41
+ ["start", ["<ul>"], {:headers=>{}}],
42
+ ["chunks", ["<li>Neko</li>"]],
43
+ ["chunks", ["<li>Nezumi</li>"]],
44
+ ["chunks", ["<li>Zoe</li>"]]
45
+ ]
46
+
47
+ expect(result).to be == ["end", ["</ul>"]]
48
+ end
49
+ end
@@ -0,0 +1,23 @@
1
+
2
+ require_relative 'spec_helper'
3
+
4
+ RSpec.describe "Map Functions" do
5
+ before :all do
6
+ @shell = Relaxo::QueryServer::MockShell.new
7
+ @context = Relaxo::QueryServer::Context.new(@shell, safe: 2)
8
+ end
9
+
10
+ it "should map values using a function" do
11
+ response = @context.run ["add_fun", "lambda{|doc| emit('foo', doc['a']); emit('bar', doc['a'])}"]
12
+ expect(response).to be true
13
+
14
+ response = @context.run ["add_fun", "lambda{|doc| emit('baz', doc['a'])}"]
15
+ expect(response).to be true
16
+
17
+ response = @context.run(["map_doc", {"a" => "b"}])
18
+ expect(response).to be == [
19
+ [["foo", "b"], ["bar", "b"]],
20
+ [["baz", "b"]]
21
+ ]
22
+ end
23
+ end
@@ -0,0 +1,42 @@
1
+
2
+ require_relative 'spec_helper'
3
+
4
+ RSpec.describe "Reduce Functions" do
5
+ before :all do
6
+ @shell = Relaxo::QueryServer::MockShell.new
7
+ @context = Relaxo::QueryServer::Context.new(@shell, safe: 2)
8
+ end
9
+
10
+ it "should reduce values" do
11
+ sum = "lambda{|k,v,r| v.inject &:+ }"
12
+ concat = "lambda{|k,v,r| r ? v.join('_') : v.join(':') }"
13
+
14
+ response = @context.run ["reduce", [sum, concat], (0...10).map{|i|[i,i*2]}]
15
+ expect(response).to be == [true, [90, "0:2:4:6:8:10:12:14:16:18"]]
16
+
17
+ response = @context.run ["rereduce", [sum, concat], (0...10).map{|i|i}]
18
+ expect(response).to be == [true, [45, "0_1_2_3_4_5_6_7_8_9"]]
19
+ end
20
+
21
+ it "should reduce using library functions" do
22
+ library_code = %q{
23
+ def sum(values)
24
+ values.inject(&:+)
25
+ end
26
+ }
27
+
28
+ reduce_function = %q{
29
+ foo = load('foo')
30
+
31
+ lambda {|k,v,r|
32
+ foo.sum(v)
33
+ }
34
+ }
35
+
36
+ response = @context.run ['add_lib', {'foo' => library_code}]
37
+ expect(response).to be true
38
+
39
+ response = @context.run ['reduce', [reduce_function], (0...10).map{|i|[i,i]}]
40
+ expect(response).to be == [true, [45]]
41
+ end
42
+ end
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require_relative 'spec_helper'
4
+
5
+ RSpec.describe "Document Shows" do
6
+ STRING = "lambda{|doc, req| [doc['title'], doc['body']].join(' - ') }"
7
+
8
+ HASH = <<-EOF
9
+ lambda{|doc, req|
10
+ resp = {"code" => 200, "headers" => {"X-Foo" => "Bar"}}
11
+ resp["body"] = [doc['title'], doc['body']].join(' - ')
12
+ resp
13
+ }
14
+ EOF
15
+
16
+ ERROR = "lambda{|doc,req| raise StandardError.new('error message') }"
17
+
18
+ before :all do
19
+ @shell = Relaxo::QueryServer::MockShell.new
20
+ @context = Relaxo::QueryServer::Context.new(@shell, safe: 2)
21
+
22
+ @context.run ["ddoc", "new", "foo", {
23
+ "shows" => {
24
+ "string" => STRING,
25
+ "hash" => HASH,
26
+ "error" => ERROR
27
+ }
28
+ }
29
+ ]
30
+ end
31
+
32
+ def run_show(opts={})
33
+ opts[:doc] ||= {"title" => "foo", "body" => "bar"}
34
+ opts[:req] ||= {}
35
+ opts[:design] ||= "string"
36
+
37
+ @context.run(["ddoc", "foo", ["shows", opts[:design]], [opts[:doc], opts[:req]]])
38
+ end
39
+
40
+ it "should process string" do
41
+ result = run_show
42
+ expect(result).to be == ["resp", {"body" => "foo - bar"}]
43
+ end
44
+
45
+ it "should process hash" do
46
+ result = run_show({:design => "hash"})
47
+ expect(result).to be == ["resp", {"body" => "foo - bar", "headers" => {"X-Foo" => "Bar"}, "code" => 200}]
48
+ end
49
+
50
+ it "should give an error" do
51
+ result = run_show({:design => "error"})
52
+ expect(result[0...3]).to be == ["error", "StandardError", "error message"]
53
+ end
54
+ end
@@ -0,0 +1,6 @@
1
+
2
+ require 'rubygems'
3
+ require 'stringio'
4
+
5
+ require "relaxo/json"
6
+ require "relaxo/query_server"
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require_relative 'spec_helper'
4
+
5
+ RSpec.describe "Document Validations" do
6
+ before :all do
7
+ @shell = Relaxo::QueryServer::MockShell.new
8
+ @context = Relaxo::QueryServer::Context.new(@shell, safe: 2)
9
+ end
10
+
11
+ def create_design_document name, attributes
12
+ @context.run ['ddoc', 'new', name, attributes]
13
+ end
14
+
15
+ it "should run update function" do
16
+ create_design_document "test", {
17
+ "updates" => {
18
+ "bar" => %q{
19
+ lambda{|doc, request| doc['updated'] = true; [doc, 'OK']}
20
+ }
21
+ }
22
+ }
23
+
24
+ document = {"foo" => "bar"}
25
+ response = @context.run ['ddoc', 'test', ['updates', 'bar'], [document, {'method' => 'POST'}]]
26
+
27
+ expect(response).to be == ["up", document.update('updated' => true), {'body' => 'OK'}]
28
+ end
29
+ end
@@ -1,8 +1,18 @@
1
+ #!/usr/bin/env rspec
1
2
 
2
- require 'helper'
3
+ require_relative 'spec_helper'
3
4
 
4
- class ValidationsTest < ContextualTestCase
5
- def test_compiles_functions
5
+ RSpec.describe "Document Validations" do
6
+ before :all do
7
+ @shell = Relaxo::QueryServer::MockShell.new
8
+ @context = Relaxo::QueryServer::Context.new(@shell, safe: 2)
9
+ end
10
+
11
+ def create_design_document name, attributes
12
+ @context.run ['ddoc', 'new', name, attributes]
13
+ end
14
+
15
+ it "should validate document updates" do
6
16
  create_design_document "test", {
7
17
  "validate_doc_update" => %q{
8
18
  lambda{|new_document, old_document, user_context|
@@ -14,9 +24,9 @@ class ValidationsTest < ContextualTestCase
14
24
  }
15
25
 
16
26
  response = @context.run ['ddoc', 'test', ['validate_doc_update'], [{'good' => true}, {'good' => true}, {}]]
17
- assert_equal 1, response
27
+ expect(response).to be == 1
18
28
 
19
29
  response = @context.run ['ddoc', 'test', ['validate_doc_update'], [{'bad' => true}, {'good' => true}, {}]]
20
- assert_equal({'forbidden' => 'bad'}, response)
30
+ expect(response).to be == {'forbidden' => 'bad'}
21
31
  end
22
32
  end
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rspec
2
+
3
+ require_relative 'spec_helper'
4
+
5
+ RSpec.describe "View Functions" do
6
+ before :all do
7
+ @shell = Relaxo::QueryServer::MockShell.new
8
+ @context = Relaxo::QueryServer::Context.new(@shell, safe: 2)
9
+ end
10
+
11
+ it "should compile function" do
12
+ response = @context.run ["add_fun", "lambda {|doc| emit(nil, nil)}"]
13
+ expect(response).to be true
14
+ end
15
+
16
+ it "should have syntax error" do
17
+ response = @context.run ["add_fun", "lambda {"]
18
+ expect(response[0]).to be == "error"
19
+ expect(response[1]).to be == "SyntaxError"
20
+ end
21
+
22
+ it "should fail on non-function" do
23
+ response = @context.run ["add_fun", "10"]
24
+ expect(response[0]).to be == "error"
25
+ expect(response[1]).to be == "Relaxo::QueryServer::CompilationError"
26
+ end
27
+ end
metadata CHANGED
@@ -1,90 +1,103 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaxo-query-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-04 00:00:00.000000000 Z
11
+ date: 2015-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: relaxo
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
20
- type: :development
19
+ version: 0.4.4
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: 0.4.4
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
32
46
  - !ruby/object:Gem::Version
33
47
  version: '0'
34
- type: :development
48
+ type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ! '>='
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
- name: relaxo
56
+ name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ~>
59
+ - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: 0.4.0
48
- type: :runtime
61
+ version: 3.1.0
62
+ type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ~>
66
+ - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: 0.4.0
68
+ version: 3.1.0
55
69
  - !ruby/object:Gem::Dependency
56
- name: json
70
+ name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ~>
73
+ - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: 1.7.3
62
- type: :runtime
75
+ version: '1.3'
76
+ type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ~>
80
+ - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: 1.7.3
82
+ version: '1.3'
69
83
  - !ruby/object:Gem::Dependency
70
- name: rest-client
84
+ name: rake
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - ! '>='
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
89
  version: '0'
76
- type: :runtime
90
+ type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ! '>='
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
- description: ! "\tRelaxo Query Server is a query server for CouchDB which provides
84
- full\n\tsupport for map/reduce functionality using Ruby code. It's main purpose\n\tis
85
- to provide a consistent backend for Ruby based clients to CouchDB.\n\tIn practice,
86
- it allows code to be shared between Ruby based client \n\tapplications and CouchDB
87
- servers.\n"
97
+ description: "\tRelaxo Query Server is a query server for CouchDB which provides full\n\tsupport
98
+ for map/reduce functionality using Ruby code. It's main purpose\n\tis to provide
99
+ a consistent backend for Ruby based clients to CouchDB.\n\tIn practice, it allows
100
+ code to be shared between Ruby based client \n\tapplications and CouchDB servers.\n"
88
101
  email:
89
102
  - samuel.williams@oriontransfer.co.nz
90
103
  executables:
@@ -92,10 +105,12 @@ executables:
92
105
  extensions: []
93
106
  extra_rdoc_files: []
94
107
  files:
95
- - .gitignore
96
- - .travis.yml
108
+ - ".gitignore"
109
+ - ".simplecov"
110
+ - ".travis.yml"
97
111
  - Gemfile
98
112
  - README.md
113
+ - Rakefile
99
114
  - bin/relaxo-query-server
100
115
  - lib/relaxo/query_server.rb
101
116
  - lib/relaxo/query_server/context.rb
@@ -106,18 +121,17 @@ files:
106
121
  - lib/relaxo/query_server/reducer.rb
107
122
  - lib/relaxo/query_server/shell.rb
108
123
  - lib/relaxo/query_server/version.rb
109
- - rakefile.rb
110
124
  - relaxo-query-server.gemspec
111
- - test/helper.rb
112
- - test/test_filters.rb
113
- - test/test_libraries.rb
114
- - test/test_lists.rb
115
- - test/test_map.rb
116
- - test/test_reduce.rb
117
- - test/test_shows.rb
118
- - test/test_updates.rb
119
- - test/test_validations.rb
120
- - test/test_views.rb
125
+ - spec/relaxo/query_server/filters_spec.rb
126
+ - spec/relaxo/query_server/libraries_spec.rb
127
+ - spec/relaxo/query_server/lists_spec.rb
128
+ - spec/relaxo/query_server/map_spec.rb
129
+ - spec/relaxo/query_server/reduce_spec.rb
130
+ - spec/relaxo/query_server/shows_spec.rb
131
+ - spec/relaxo/query_server/spec_helper.rb
132
+ - spec/relaxo/query_server/updates_spec.rb
133
+ - spec/relaxo/query_server/validations_spec.rb
134
+ - spec/relaxo/query_server/view_spec.rb
121
135
  homepage: ''
122
136
  licenses:
123
137
  - MIT
@@ -128,29 +142,29 @@ require_paths:
128
142
  - lib
129
143
  required_ruby_version: !ruby/object:Gem::Requirement
130
144
  requirements:
131
- - - ! '>='
145
+ - - ">="
132
146
  - !ruby/object:Gem::Version
133
147
  version: '0'
134
148
  required_rubygems_version: !ruby/object:Gem::Requirement
135
149
  requirements:
136
- - - ! '>='
150
+ - - ">="
137
151
  - !ruby/object:Gem::Version
138
152
  version: '0'
139
153
  requirements: []
140
154
  rubyforge_project:
141
- rubygems_version: 2.0.2
155
+ rubygems_version: 2.2.2
142
156
  signing_key:
143
157
  specification_version: 4
144
158
  summary: Relaxo Query Server provides support for executing CouchDB functions using
145
159
  Ruby.
146
160
  test_files:
147
- - test/helper.rb
148
- - test/test_filters.rb
149
- - test/test_libraries.rb
150
- - test/test_lists.rb
151
- - test/test_map.rb
152
- - test/test_reduce.rb
153
- - test/test_shows.rb
154
- - test/test_updates.rb
155
- - test/test_validations.rb
156
- - test/test_views.rb
161
+ - spec/relaxo/query_server/filters_spec.rb
162
+ - spec/relaxo/query_server/libraries_spec.rb
163
+ - spec/relaxo/query_server/lists_spec.rb
164
+ - spec/relaxo/query_server/map_spec.rb
165
+ - spec/relaxo/query_server/reduce_spec.rb
166
+ - spec/relaxo/query_server/shows_spec.rb
167
+ - spec/relaxo/query_server/spec_helper.rb
168
+ - spec/relaxo/query_server/updates_spec.rb
169
+ - spec/relaxo/query_server/validations_spec.rb
170
+ - spec/relaxo/query_server/view_spec.rb
@@ -1,9 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new do |t|
5
- t.libs << 'test'
6
- end
7
-
8
- desc "Run tests"
9
- task :default => :test
@@ -1,38 +0,0 @@
1
-
2
- $LOAD_PATH.unshift File.expand_path("../../lib/", __FILE__)
3
-
4
- require 'rubygems'
5
- require 'test/unit'
6
- require 'stringio'
7
-
8
- require "relaxo/json"
9
- require "relaxo/query_server"
10
-
11
- class Test::Unit::TestCase
12
- def self.abstract_test_case!
13
- self.class_eval do
14
- def test_default
15
- end
16
- end
17
- end
18
- end
19
-
20
- class ContextualTestCase < Test::Unit::TestCase
21
- abstract_test_case!
22
-
23
- def setup_context(options)
24
- @shell = Relaxo::QueryServer::MockShell.new
25
- @context = Relaxo::QueryServer::Context.new(@shell, options)
26
- end
27
-
28
- def create_design_document name, attributes
29
- @context.run ['ddoc', 'new', name, attributes]
30
- end
31
-
32
- def setup
33
- setup_context :safe => 2
34
- end
35
-
36
- def teardown
37
- end
38
- end
@@ -1,24 +0,0 @@
1
-
2
- require 'helper'
3
-
4
- class FiltersTest < ContextualTestCase
5
- BASIC = "lambda{|doc, req| doc['good'] == true}"
6
-
7
- def run_filter(opts={})
8
- opts[:docs] ||= []
9
- opts[:req] ||= {}
10
-
11
- @context.run ["ddoc", "foo", ["filters", "basic"], [opts[:docs], opts[:req]]]
12
- end
13
-
14
- def test_filters_updated
15
- @context.run ["ddoc", "new", "foo", {"filters" => {"basic" => BASIC}}]
16
-
17
- docs = (1..3).map do |i|
18
- {"good" => i.odd?}
19
- end
20
-
21
- results = run_filter({:docs => docs})
22
- assert_equal [true, [true, false, true]], results
23
- end
24
- end
@@ -1,46 +0,0 @@
1
-
2
- require 'helper'
3
-
4
- class ListsTest < ContextualTestCase
5
- ENTIRE = <<-RUBY
6
- lambda{|head,request|
7
- send "<ul>"
8
- each do |row|
9
- send "<li>" + row['count'] + "</li>"
10
- end
11
- send "</ul>"
12
- }
13
- RUBY
14
-
15
- def setup
16
- super
17
-
18
- @rows = [
19
- ["list_row", {"count"=>"Neko"}],
20
- ["list_row", {"count"=>"Nezumi"}],
21
- ["list_row", {"count"=>"Zoe"}],
22
- ["list_end"]
23
- ]
24
- end
25
-
26
- def test_lists_rows
27
- create_design_document "test", {
28
- 'lists' => {
29
- 'entire' => ENTIRE
30
- }
31
- }
32
-
33
- @rows.each {|row| @shell.input << row}
34
-
35
- result = @context.run ['ddoc', 'test', ['lists', 'entire'], [{}, {}]]
36
-
37
- assert_equal [
38
- ["start", ["<ul>"], {:headers=>{}}],
39
- ["chunks", ["<li>Neko</li>"]],
40
- ["chunks", ["<li>Nezumi</li>"]],
41
- ["chunks", ["<li>Zoe</li>"]]
42
- ], @shell.output
43
-
44
- assert_equal ["end", ["</ul>"]], result
45
- end
46
- end
@@ -1,20 +0,0 @@
1
-
2
- require 'helper'
3
-
4
- class MapTest < ContextualTestCase
5
- def test_map
6
- response = @context.run ["add_fun", "lambda{|doc| emit('foo', doc['a']); emit('bar', doc['a'])}"]
7
- assert_equal true, response
8
-
9
- response = @context.run ["add_fun", "lambda{|doc| emit('baz', doc['a'])}"]
10
- assert_equal true, response
11
-
12
- response = @context.run(["map_doc", {"a" => "b"}])
13
- expected = [
14
- [["foo", "b"], ["bar", "b"]],
15
- [["baz", "b"]]
16
- ]
17
-
18
- assert_equal expected, response
19
- end
20
- end
@@ -1,38 +0,0 @@
1
-
2
- require 'helper'
3
-
4
- class ReduceTest < ContextualTestCase
5
- SUM = "lambda{|k,v,r| v.inject &:+ }"
6
- CONCAT = "lambda{|k,v,r| r ? v.join('_') : v.join(':') }"
7
-
8
- def test_reduce
9
- response = @context.run ["reduce", [SUM, CONCAT], (0...10).map{|i|[i,i*2]}]
10
- assert_equal [true, [90, "0:2:4:6:8:10:12:14:16:18"]], response
11
-
12
- response = @context.run ["rereduce", [SUM, CONCAT], (0...10).map{|i|i}]
13
- assert_equal [true, [45, "0_1_2_3_4_5_6_7_8_9"]], response
14
- end
15
-
16
- def test_reduce_libraries
17
- library_code = %q{
18
- def sum(values)
19
- values.inject(&:+)
20
- end
21
- }
22
-
23
- reduce_function = %q{
24
- foo = load('foo')
25
-
26
- lambda {|k,v,r|
27
- puts v.inspect
28
- foo.sum(v)
29
- }
30
- }
31
-
32
- response = @context.run ['add_lib', {'foo' => library_code}]
33
- assert_equal true, response
34
-
35
- response = @context.run ['reduce', [reduce_function], (0...10).map{|i|[i,i]}]
36
- assert_equal [true, [45]], response
37
- end
38
- end
@@ -1,53 +0,0 @@
1
-
2
- require 'helper'
3
-
4
- class ShowsTest < ContextualTestCase
5
- STRING = "lambda{|doc, req| [doc['title'], doc['body']].join(' - ') }"
6
- HASH = <<-EOF
7
- lambda{|doc, req|
8
- resp = {"code" => 200, "headers" => {"X-Foo" => "Bar"}}
9
- resp["body"] = [doc['title'], doc['body']].join(' - ')
10
- resp
11
- }
12
- EOF
13
- ERROR = "lambda{|doc,req| raise StandardError.new('error message') }"
14
-
15
- def setup
16
- super
17
-
18
- @context.run ["ddoc", "new", "foo", {
19
- "shows" => {
20
- "string" => STRING,
21
- "hash" => HASH,
22
- "error" => ERROR
23
- }
24
- }
25
- ]
26
- end
27
-
28
- def run_show(opts={})
29
- opts[:doc] ||= {"title" => "foo", "body" => "bar"}
30
- opts[:req] ||= {}
31
- opts[:design] ||= "string"
32
-
33
- @context.run(["ddoc", "foo", ["shows", opts[:design]], [opts[:doc], opts[:req]]])
34
- end
35
-
36
- def test_string
37
- result = run_show
38
- expected = ["resp", {"body" => "foo - bar"}]
39
- assert_equal expected, result
40
- end
41
-
42
- def test_hash
43
- result = run_show({:design => "hash"})
44
- expected = ["resp", {"body" => "foo - bar", "headers" => {"X-Foo" => "Bar"}, "code" => 200}]
45
- assert_equal expected, result
46
- end
47
-
48
- def test_error
49
- result = run_show({:design => "error"})
50
- expected = ["error", "StandardError", "error message"]
51
- assert_equal expected, result[0...3]
52
- end
53
- end
@@ -1,19 +0,0 @@
1
-
2
- require 'helper'
3
-
4
- class UpdatesTest < ContextualTestCase
5
- def test_compiles_functions
6
- create_design_document "test", {
7
- "updates" => {
8
- "bar" => %q{
9
- lambda{|doc, request| doc['updated'] = true; [doc, 'OK']}
10
- }
11
- }
12
- }
13
-
14
- document = {"foo" => "bar"}
15
- response = @context.run ['ddoc', 'test', ['updates', 'bar'], [document, {'method' => 'POST'}]]
16
-
17
- assert_equal ["up", document.update('updated' => true), {'body' => 'OK'}], response
18
- end
19
- end
@@ -1,17 +0,0 @@
1
-
2
- require 'helper'
3
-
4
- class ViewsTest < ContextualTestCase
5
- def test_compiles_functions
6
- response = @context.run ["add_fun", "lambda {|doc| emit(nil, nil)}"]
7
- assert_equal true, response
8
-
9
- response = @context.run ["add_fun", "lambda {"]
10
- assert_equal "error", response[0]
11
- assert_equal "SyntaxError", response[1]
12
-
13
- response = @context.run ["add_fun", "10"]
14
- assert_equal "error", response[0]
15
- assert_equal "Relaxo::QueryServer::CompilationError", response[1]
16
- end
17
- end