diff --git a/README.md b/README.md index 8c0c095..8456c9e 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,4 @@ https://docs.couchdb.org/en/2.3.1/api/database/find.html#sort-syntax ## Original Project Contributors (what I've forked) - [TechMagister](https://github.com/TechMagister) Arnaud Fernandés - creator, maintainer - [Schniz](https://github.com/Schniz) Gal Schlezinger - contributor - - - - +- [drhuffman12](https://github.com/drhuffman12) Daniel Huffman - contributor diff --git a/shard.yml b/shard.yml index 3ea320f..b4da03f 100644 --- a/shard.yml +++ b/shard.yml @@ -1,10 +1,15 @@ name: couchdb -version: 0.3.0 +version: 0.4.0 authors: - Arnaud Fernandés - fork maintained by vectorselector -crystal: 1.0.0 +# NOTE: Instead of hard-coding version in this file, specify 'works with' elsewise (e.g.: Release notes?) +# crystal: 1.0.0 license: MIT + +dependencies: + json_mapping: + github: crystal-lang/json_mapping.cr diff --git a/spec/couchdb_spec.cr b/spec/couchdb_spec.cr index 48d00f1..9da2197 100644 --- a/spec/couchdb_spec.cr +++ b/spec/couchdb_spec.cr @@ -3,14 +3,38 @@ require "./spec_helper" require "../src/couchdb/client" describe CouchDB do + it "version in shard.yml matches version in CouchDB::VERSION" do + (`shards version .`).strip.should eq(CouchDB::VERSION) + end describe CouchDB::Client do - it "should get server info" do - client = new_client - info = client.server_info - info.couchdb.should eq "Welcome" - info.version.should match /^2\.\d+\.\d+$/ - info.vendor.name.should eq "The Apache Software Foundation" + context "should get server info re" do + it "couchdb" do + client = new_client + info = client.server_info + info.couchdb.should eq "Welcome" + end + + context "version" do + context "is supported version of" do + it "2.x.x or 3.x.x" do + client = new_client + info = client.server_info + + # DEBUG: Which CouchDb Version is it? + p! info.is_v2? if info.is_v2? + p! info.is_v3? if info.is_v3? + + (info.is_v2? || info.is_v3?).should be_true + end + end + end + + it "vendor.name" do + client = new_client + info = client.server_info + info.vendor.name.should eq "The Apache Software Foundation" + end end it "should create a database named testdb" do diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index 45712ce..9c26190 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -3,7 +3,12 @@ require "spec" require "../src/couchdb" def new_client : CouchDB::Client - couchdb_url = ENV["TEST_DB"]? || "http://admin:password@localhost:5984" + un = ENV.keys.includes?("TEST_DB_UN") ? ENV["TEST_DB_UN"] : "admin" + pw = ENV.keys.includes?("TEST_DB_PW") ? ENV["TEST_DB_PW"] : "password" + ip = ENV.keys.includes?("TEST_DB_IP") ? ENV["TEST_DB_IP"] : "localhost" + port = ENV.keys.includes?("TEST_DB_PORT") ? ENV["TEST_DB_PORT"] : "5984" + couchdb_url = ENV.keys.includes?("TEST_DB") ? ENV["TEST_DB"] : "http://#{un}:#{pw}@#{ip}:#{port}" + CouchDB::Client.new couchdb_url end diff --git a/src/couchdb.cr b/src/couchdb.cr index 8f08e81..0e39e6b 100644 --- a/src/couchdb.cr +++ b/src/couchdb.cr @@ -3,6 +3,7 @@ require "./couchdb/client" require "./couchdb/database" require "./couchdb/response" require "./couchdb/find_query" +require "json_mapping" module CouchDB diff --git a/src/couchdb/response/server_info.cr b/src/couchdb/response/server_info.cr index bcfd9d6..17d0743 100644 --- a/src/couchdb/response/server_info.cr +++ b/src/couchdb/response/server_info.cr @@ -1,11 +1,15 @@ require "json" module CouchDB::Response - + class Vendor include JSON::Serializable property name : String - property version : String + + # property version : String + @[Deprecated("Use `ServerInfo#version` instead of `Vendor#version`.")] + def version + end end class ServerInfo @@ -14,6 +18,13 @@ module CouchDB::Response property uuid : String property version : String property vendor : Vendor - end + def is_v2? + !(/^2\.\d+\.\d+$/.match(version).nil?) + end + + def is_v3? + !(/^3\.\d+\.\d+$/.match(version).nil?) + end + end end diff --git a/src/couchdb/version.cr b/src/couchdb/version.cr index eefc210..8beaa20 100644 --- a/src/couchdb/version.cr +++ b/src/couchdb/version.cr @@ -1,3 +1,3 @@ module CouchDB - VERSION = "0.3.0" + VERSION = {{ `shards version "#{__DIR__}"`.chomp.stringify }} end