From 69ead0f5ebc293b9ebd508e6dc7e112062f28e67 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Sat, 28 Dec 2019 14:20:50 +0000 Subject: [PATCH] #10: fixes bug 10, all tests pass, no regression expected. --- src/adl/to_psql.clj | 7 ++--- test/adl/to_psql_test.clj | 54 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/adl/to_psql.clj b/src/adl/to_psql.clj index 8f9c0e4..f08b80e 100644 --- a/src/adl/to_psql.clj +++ b/src/adl/to_psql.clj @@ -320,7 +320,8 @@ (let [view-name (safe-name (str "lv_" (:table (:attrs entity))) :sql) entity-properties (filter #(= (:type (:attrs %)) "entity") - (properties entity))] + (properties entity)) + tn (safe-name (-> entity :attrs :table) :sql)] (s/join "\n" (remove @@ -345,8 +346,8 @@ (= (:type (:attrs %)) "entity") (list (emit-convenience-entity-field % entity application (field-name %)) - (str (safe-name entity) "." (field-name %))) - (str (safe-name entity) "." (field-name %))) + (str tn "." (field-name %))) + (str tn "." (field-name %))) (remove #(#{"link" "list"} (:type (:attrs %))) (all-properties entity) )))))) diff --git a/test/adl/to_psql_test.clj b/test/adl/to_psql_test.clj index f01ad0d..1f41c81 100644 --- a/test/adl/to_psql_test.clj +++ b/test/adl/to_psql_test.clj @@ -493,6 +493,56 @@ should-not-find #"animal.name AS dam_expanded"] ;; (print actual) ;; see what we've got (is (re-find should-find actual)) - (is (nil? (re-find should-not-find actual)))) + (is (nil? (re-find should-not-find actual))))))) - ))) +(deftest bug-10-test + (testing "Correct table names in convenience view select queries + see [bug 10](https://github.com/simon-brooke/adl/issues/10)" + (let [app + {:tag :application, + :attrs {:version "0.0.1", + :name "pastoralist", + :xmlns:adl "http://bowyer.journeyman.cc/adl/1.4.1/", + :xmlns:html "http://www.w3.org/1999/xhtml", + :xmlns "http://bowyer.journeyman.cc/adl/1.4.1/"}, + :content [{:tag :documentation, + :attrs nil, + :content ["A web-app intended to be used by pastoralists in managing + pastures, grazing, and animals."]} + {:tag :entity, + :attrs + {:volatility "5", + :magnitude "3", + :name "event-type", + :table "event-type"}, + :content + [{:tag :key, + :attrs nil, + :content + [{:tag :property, + :attrs + {:distinct "system", + :immutable "true", + :column "id", + :name "id", + :type "integer", + :required "true"}, + :content + [{:tag :generator, :attrs {:action "native"}, :content nil}]}]} + {:tag :property, + :attrs {:size "80", :type "string", :name "summary"}, + :content nil} + {:tag :property, + :attrs {:type "text", :name "description"}, + :content nil} + {:tag :property, + :attrs {:default "1", :type "integer", :name "n-holdings"},} + {:tag :property, + :attrs {:default "1", :type "integer", :name "n-pastures"}} + {:tag :property, + :attrs {:default "1", :type "integer", :name "n-animals"}}]}]} + should-find #"event_type.description" + should-not-find #"event-type.description" + actual (emit-convenience-view (child app #(= (-> % :attrs :name) "event-type")) app)] + (is (re-find should-find actual)) + (is (nil? (re-find should-not-find actual))))))