Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drhuffman12/upgrade to crystal 1.1.1 (and 1.2.0-dev) #1

Merged
merged 7 commits into from
Sep 6, 2021
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 7 additions & 2 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
name: couchdb
version: 0.3.0
version: 0.4.0

authors:
- Arnaud Fernandés <arnaud.fernandes@tech-magister.com>
- 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
36 changes: 30 additions & 6 deletions spec/couchdb_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/couchdb.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require "./couchdb/client"
require "./couchdb/database"
require "./couchdb/response"
require "./couchdb/find_query"
require "json_mapping"

module CouchDB

Expand Down
17 changes: 14 additions & 3 deletions src/couchdb/response/server_info.cr
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/couchdb/version.cr
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module CouchDB
VERSION = "0.3.0"
VERSION = {{ `shards version "#{__DIR__}"`.chomp.stringify }}
end