From fe42248334ca3102b2d6d07c5b74cdaf45f3cda2 Mon Sep 17 00:00:00 2001 From: Daniel Huffman Date: Mon, 6 Sep 2021 01:30:16 -0400 Subject: [PATCH 1/7] drhuffman12/upgrade_to_crystal_1.1.1 "json_mapping" is now a shard (https://github.com/crystal-lang/crystal/pull/9527); (Refactor to use JSON::Serializable instead?) --- shard.yml | 5 +++++ src/couchdb.cr | 1 + 2 files changed, 6 insertions(+) diff --git a/shard.yml b/shard.yml index 3ea320f..bd3cd5e 100644 --- a/shard.yml +++ b/shard.yml @@ -8,3 +8,8 @@ authors: crystal: 1.0.0 license: MIT + +dependencies: + json_mapping: + github: crystal-lang/json_mapping.cr + \ No newline at end of file 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 From 0a9ca7e9b4cd749e4c2742411c12db2cae401a2c Mon Sep 17 00:00:00 2001 From: Daniel Huffman Date: Mon, 6 Sep 2021 03:02:13 -0400 Subject: [PATCH 2/7] drhuffman12/upgrade_to_crystal_1.1.1 avoid "Missing ENV key" errors; add more db conn env var's --- spec/spec_helper.cr | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 From c889139ab0cc3ff32452c18c42b21f1a1433e09b Mon Sep 17 00:00:00 2001 From: Daniel Huffman Date: Mon, 6 Sep 2021 03:06:11 -0400 Subject: [PATCH 3/7] drhuffman12/upgrade_to_crystal_1.1.1 TODO: Why "CouchDB::Response::Vendor#version" not getting parsed in? --- src/couchdb/response/server_info.cr | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/couchdb/response/server_info.cr b/src/couchdb/response/server_info.cr index bcfd9d6..1a24a58 100644 --- a/src/couchdb/response/server_info.cr +++ b/src/couchdb/response/server_info.cr @@ -1,11 +1,29 @@ require "json" module CouchDB::Response - + class Vendor include JSON::Serializable property name : String - property version : String + + # property version : String + # NOTE: Above commented out (for now). + # TODO: Why "CouchDB::Response::Vendor#version" not getting parsed in? + # WORK-AROUND: Use 'ServerInfo#version' instead of 'Vendor#version'. + # ERROR: "JSON::SerializableError" + # Missing JSON attribute: version + # parsing CouchDB::Response::Vendor at line 1, column 205 + # parsing CouchDB::Response::ServerInfo#vendor at line 1, column 196 (JSON::SerializableError) + # from /.../crystal/1.0.0/share/crystal/src/json/serialization.cr:159:7 in 'initialize:__pull_for_json_serializable' + # from src/couchdb/response/server_info.cr:12:5 in 'new_from_json_pull_parser' + # from src/couchdb/response/server_info.cr:12:5 in 'new' + # from /.../crystal/1.0.0/share/crystal/src/json/from_json.cr:13:3 in 'from_json' + # from src/couchdb/client.cr:50:18 in 'server_info' + # from spec/couchdb_spec.cr:19:7 in '->' + # ... + # from __libc_start_main + # from _start + # from ??? end class ServerInfo @@ -15,5 +33,4 @@ module CouchDB::Response property version : String property vendor : Vendor end - end From 9894429abfc2243ce5d54f74871b8939372028aa Mon Sep 17 00:00:00 2001 From: Daniel Huffman Date: Mon, 6 Sep 2021 03:30:24 -0400 Subject: [PATCH 4/7] drhuffman12/upgrade_to_crystal_1.1.1 Allow CouchDB '3.x.x' (not just '2.x.x'). (TODO: Add applicable tests for '3.x.x' changes.); TODO: Why "CouchDB::Response::Vendor#version" not getting parsed in? --- spec/couchdb_spec.cr | 36 ++++++++++++++++++++++++----- src/couchdb/response/server_info.cr | 8 +++++++ 2 files changed, 38 insertions(+), 6 deletions(-) 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/src/couchdb/response/server_info.cr b/src/couchdb/response/server_info.cr index 1a24a58..91b2540 100644 --- a/src/couchdb/response/server_info.cr +++ b/src/couchdb/response/server_info.cr @@ -32,5 +32,13 @@ module CouchDB::Response property uuid : String property version : String property vendor : Vendor + + def is_v2? + !(/^2\.\d+\.\d+$/.match(version).nil?) + end + + def is_v3? + !(/^3\.\d+\.\d+$/.match(version).nil?) + end end end From 4f98ddb5b538c7723f8665ffd7e345d359d49556 Mon Sep 17 00:00:00 2001 From: Daniel Huffman Date: Mon, 6 Sep 2021 03:32:08 -0400 Subject: [PATCH 5/7] drhuffman12/upgrade_to_crystal_1.1.1 Bump shard version to "0.4.0"; comment out Crystal version requirement (note compatibility elsewhere?) --- shard.yml | 6 +++--- src/couchdb/version.cr | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/shard.yml b/shard.yml index bd3cd5e..b4da03f 100644 --- a/shard.yml +++ b/shard.yml @@ -1,15 +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 - \ No newline at end of file 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 From 51776b874336163410032453d609e68e3e8b45c6 Mon Sep 17 00:00:00 2001 From: Daniel Huffman Date: Mon, 6 Sep 2021 04:31:18 -0400 Subject: [PATCH 6/7] drhuffman12/upgrade_to_crystal_1.1.1 cleanup re `Vendor#version` --- src/couchdb/response/server_info.cr | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/couchdb/response/server_info.cr b/src/couchdb/response/server_info.cr index 91b2540..17d0743 100644 --- a/src/couchdb/response/server_info.cr +++ b/src/couchdb/response/server_info.cr @@ -7,23 +7,9 @@ module CouchDB::Response property name : String # property version : String - # NOTE: Above commented out (for now). - # TODO: Why "CouchDB::Response::Vendor#version" not getting parsed in? - # WORK-AROUND: Use 'ServerInfo#version' instead of 'Vendor#version'. - # ERROR: "JSON::SerializableError" - # Missing JSON attribute: version - # parsing CouchDB::Response::Vendor at line 1, column 205 - # parsing CouchDB::Response::ServerInfo#vendor at line 1, column 196 (JSON::SerializableError) - # from /.../crystal/1.0.0/share/crystal/src/json/serialization.cr:159:7 in 'initialize:__pull_for_json_serializable' - # from src/couchdb/response/server_info.cr:12:5 in 'new_from_json_pull_parser' - # from src/couchdb/response/server_info.cr:12:5 in 'new' - # from /.../crystal/1.0.0/share/crystal/src/json/from_json.cr:13:3 in 'from_json' - # from src/couchdb/client.cr:50:18 in 'server_info' - # from spec/couchdb_spec.cr:19:7 in '->' - # ... - # from __libc_start_main - # from _start - # from ??? + @[Deprecated("Use `ServerInfo#version` instead of `Vendor#version`.")] + def version + end end class ServerInfo From 29f22c9bc00629cd587d663a9a92a8f86d6229d2 Mon Sep 17 00:00:00 2001 From: Daniel Huffman Date: Mon, 6 Sep 2021 04:58:21 -0400 Subject: [PATCH 7/7] drhuffman12/upgrade_to_crystal_1.1.1 Add myself as a contributor. --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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