This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-08
Channels
- # aws (4)
- # beginners (81)
- # boot (65)
- # cljs-dev (10)
- # cljsjs (1)
- # cljsrn (12)
- # clojure (26)
- # clojure-austin (2)
- # clojure-dusseldorf (2)
- # clojure-russia (123)
- # clojure-spec (23)
- # clojure-uk (12)
- # clojurescript (36)
- # cursive (11)
- # datomic (39)
- # events (1)
- # hoplon (25)
- # incanter (4)
- # leiningen (3)
- # off-topic (5)
- # om (31)
- # re-frame (24)
- # reagent (13)
- # ring-swagger (2)
- # rum (10)
- # untangled (3)
- # yada (10)
@sb you'll either need to create a server endpoint to inform the client (the browser) the user is authenticated or have the server send the extra element down in the html payload, depending on whether you're rendering html on the server or using a client library on the browser to render page
which method are you using to render the html? the server (hiccup maybe?) or the client (reagent maybe?)
either way it will involve some logic in here
(def secured-app
(-> ring-app
(friend/authenticate {:credential-fn (partial creds/bcrypt-credential-fn users)
:workflows [(workflows/interactive-form)]})
; ...required Ring middlewares ...
))
after you get past friend/authenticate, you'll either add the extra element to the hiccup based on the fact they're logged in
if you're using reagent or something, i'd have to look into friend's details to see if they add tokens to the response which your reagent code could use to determine you're 'logged in'
then I see this message : ExceptionInfo Unable to construct gen at: [:name] for: :name
Use (s/def ::name #{"z4"})
@alexmiller thanks
Use a set for any spec that enumerates values
In reagent I want to have make on-click event that is given the id of the parent element of the event. How should I do this?
I have tried something like wrapping the whole component with let, but it seems that the event doesn't seem to get the values once it is called
I have these specs :
(s/def :image/tiles
(s/coll-of (s/keys :req-un [::url] ):min-count 1 :max-count 1))
(s/def ::name #{"z4"})
(s/def :image/levels
(s/keys :req-un [::name :image/tiles]))
(s/def :image/body
(s/keys :reg-un [:image/levels]))
(s/def :image/response
(s/keys :req-un [:image/body]))
when I do (s/exercise :image/response)
I see only these results :
([{:body {}} {:body {}}] [{:body {}} {:body {}}] [{:body {}} {:body {}}] [{:body {}} {:body {}}] [{:body {}} {:body {}}] [{:body {}} {:body {}}] [{:body {}} {:body {}}] [{:body {}} {:body {}}] [{:body {}} {:body {}}] [{:body {}} {:body {}}])
How can I take care that something like this is schown :
{
"levels": [{
"tiles": [{
"url": ""
},
one question , I have made this spec to test a function :
(s/fdef get-image-url
:args (s/cat :response :image/response)
:ret :image/object)
but when I do (stest/summarize-results (stest/check 'paintings2/api-get/get-image-url'))
here are the specs :
(s/def ::url string?)
(s/def :image/tiles
(s/coll-of (s/keys :req-un [::url] ):min-count 1 :max-count 1))
(s/def :image/name #{"z4"})
(s/def :image/levels
(s/coll-of (s/keys :req-un [:image/name :image/tiles]) :min-count 1 :max-count 1 ))
(s/def :image/body
(s/keys :req-un [:image/levels]))
(s/def :image/response
(s/keys :req-un [:image/body]))
(s/def :image/object
(s/keys :req-un [::url]))
and here the function that needs to be tested :
(defn get-image-url
"Reads the image-url"
[response]
(let [art-objects (-> response
:body
:levels)
url (filter #(= (:name %) "z4") art-objects)
tiles (:tiles (first url))
image (get-in tiles [0 :url])]
{:tiles image}))
stest/check
takes a fully namespace-qualified symbol, so you want
(stest/check `paintings2/api-get/get-image-url)
(notice the backtick)one last question : I have this spec
(s/def :image/tiles
(s/coll-of (s/keys :req-un [::url] ) :min-count 1 :max-count 1))
and this one
(s/def :image/levels
(s/coll-of (s/keys :req-un [:image/name :image/tiles]) :min-count 1 :max-count 1))
why do I see this failing test :
{:cause "Specification-based check failed",
:via [{:type clojure.lang.ExceptionInfo,
:at [clojure.core$ex_info
invokeStatic
"core.clj"
4725],
:message "Specification-based check failed",
:data {:clojure.spec/problems ({:path [:ret],
:pred (contains?
%
:url),
:via [],
:val {:tiles ""},
:in []}),
:clojure.spec.test/val {:tiles ""},
:clojure.spec.test/args ({:body {:levels [{:name "z4",
:tiles [{:url ""}]}]}}),
:clojure.spec/failure :check-failed}}],
so it wil be something like this {:tiles "http://image.com/image " }
yes, but in your fn spec you say that it returns an image/object
:
(s/fdef get-image-url
:args (s/cat :response :image/response)
:ret :image/object)
oke, I have this function :
(defn get-image-url
"Reads the image-url"
[response]
(let [art-objects (-> response
:body
:levels)
url (filter #(= (:name %) "z4") art-objects)
tiles (:tiles (first url))
image (get-in tiles [0 :url])]
{:tiles image}))
yes, try replacing :ret
in your fn spec with image/tiles
and see if that solves your problem š
yep, I still see this error :
({:failure {:cause "Specification-based check failed",
:via [{:type clojure.lang.ExceptionInfo,
:at [clojure.core$ex_info
invokeStatic
"core.clj"
4725],
:message "Specification-based check failed",
:data {:clojure.spec/problems ({:path [:ret],
:pred map?,
:via [],
:val [:tiles ""],
:in [0]}),
:clojure.spec.test/val {:tiles ""},
:clojure.spec.test/args ({:body {:levels [{:name "z4",
:tiles [{:url ""}]}]}}),
:clojure.spec/failure :check-failed}}],
I use tiles but I have also said this :
(s/def :image/tiles
(s/coll-of (s/keys :req-un [::url] ) :min-count 1 :max-count 1))
(let [album-id (:id album)]
[:ul {:on-click (fn []
(swap! opened not)
(when-not ((keyword album-id) @album-songs)
(GET (str "/song/album/" album-id)
{:handler (fn [response]
(swap! album-songs assoc (keyword album-id) (js->clj response)))
:error-handler error-handler})))}
(:name album]))