Permalink
Browse files

Merge remote-tracking branch 'origin/master'

Conflicts:
	yesod/scaffold/Handler/Home.hs.cg
	yesod/scaffold/config/routes.cg
	yesod/scaffold/project.cabal.cg
	yesod/yesod.cabal
  • Loading branch information...
snoyberg committed Mar 20, 2012
2 parents 0618c5f + 6c492d2 commit b0b755cd8070fdff04751dd9f986293f8ad9438d
View
@@ -12,4 +12,4 @@ pkgs=( ./yesod-routes
./yesod-auth
./yesod-sitemap
./yesod-default
- ./yesod )
+ ./yesod )
@@ -82,7 +82,6 @@ library
, conduit >= 0.3 && < 0.4
, resourcet >= 0.3 && < 0.4
, lifted-base >= 0.1 && < 0.2
-
exposed-modules: Yesod.Content
Yesod.Core
Yesod.Dispatch
@@ -19,10 +19,10 @@ import Data.List (foldl')
-- |
--
--- This function will generate a single clause that will address all your
--- routing needs. It takes three arguments. The third (a list of 'Resource's)
--- is self-explanatory. We\'ll discuss the first two. But first, let\'s cover
--- the terminology.
+-- This function will generate a single clause that will address all
+-- your routing needs. It takes four arguments. The fourth (a list of
+-- 'Resource's) is self-explanatory. We\'ll discuss the first
+-- three. But first, let\'s cover the terminology.
--
-- Dispatching involves a master type and a sub type. When you dispatch to the
-- top level type, master and sub are the same. Each time to dispatch to
@@ -63,7 +63,23 @@ import Data.List (foldl')
-- > dispatcher :: master -> sub -> (Route sub -> Route master) -> app -> handler sub master -> Text -> [Text] -> app
--
-- Where the parameters mean master, sub, toMaster, 404 response, 405 response,
--- request method and path pieces.
+-- request method and path pieces. This is the second argument of our function.
+--
+-- Finally, we need a way to decide which of the possible formats
+-- should the handler send the data out. Think of each URL holding an
+-- abstract object which has multiple representation (JSON, plain HTML
+-- etc). Each client might have a preference on which format it wants
+-- the abstract object in. For example, a javascript making a request
+-- (on behalf of a browser) might prefer a JSON object over a plain
+-- HTML file where as a user browsing with javascript disabled would
+-- want the page in HTML. The third argument is a function that
+-- converts the abstract object to the desired representation
+-- depending on the preferences sent by the client.
+--
+-- The typical values for the first three arguments are,
+-- @'yesodRunner'@ for the first, @'yesodDispatch'@ for the second and
+-- @fmap 'chooseRep'@.
+
mkDispatchClause :: Q Exp -- ^ runHandler function
-> Q Exp -- ^ dispatcher function
-> Q Exp -- ^ fixHandler function
View
@@ -0,0 +1,25 @@
+The following license covers this documentation, and the source code, except
+where otherwise indicated.
+
+Copyright 2010, Nubis. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
@@ -0,0 +1,75 @@
+# TestWaiPersistent - Pragmatic integration tests for haskell web applications using WAI and Persistent
+
+yesod-test is designed for testing web applications built using wai and persistent.
+It's main goal is to encourage integration and system testing of web applications by making everything /easy to test/.
+
+Your tests are like browser sessions that keep track of cookies and the last
+visited page. You can perform assertions on the content of HTML responses,
+using css selectors to explore the document more easily.
+
+You can also easily build requests using forms present in the current page.
+This is very useful for testing web applications built in yesod for example,
+were your forms may have field names generated by the framework or a randomly
+generated "\_token" field.
+
+Your database is also directly available so you can use runDB to set up
+backend pre-conditions, or to assert that your session is having the desired effect.
+
+The testing facilities behind the scenes are HUnit and HSpec.
+
+This is the helloworld and kitchen sink. In this case for testing a yesod app.
+
+```haskell
+
+ import Yesod
+ import Yesod.Static
+ import qualified MySite.Settings as Settings
+ import MySite.Models
+
+ main :: IO a
+ main = do
+ cfg <- (loadConfig Test) >>= either fail return
+ st <- static Settings.staticDir
+ Settings.withConnectionPool (connStr cfg) $ \cnPool -> do
+ -- ... Perhaps some code here to truncate your test database?
+ app <- toWaiApp $ MyApp st cfg
+ runTests app cnPool $ mySuite
+
+ mySuite = do
+ describe "Basic navigation and assertions" $ do
+ it "Gets a page that has a form, with auto generated fields and token" $ do
+ get_ "url/of/page/with/form" -- Load a page
+ statusIs 200 -- Assert the status was success
+
+ bodyContains "Hello Person" -- Assert any part of the document contains some text.
+
+ -- Perform a css queries and assertions.
+ htmlCount "form .main" 1 -- It matches 1 element
+ htmlAllContain "h1#mainTitle" "Sign Up Now!" -- All matches have some text
+
+ -- Performs the post using the current page to extract field values:
+ post "url/to/post/to" $ do
+ addNonce -- Add the _nonce field with the currently shown value
+
+ -- Lookup field by the text on the labels pointing to them.
+ byLabel "Email:" "gustavo@cerati.com"
+ byLabel "Password:" "secret"
+ byLabel "Confirm:" "secret"
+
+ it "Sends another form, this one has a file" $ do
+ post "url/to/post/file/to" $ do
+ -- You can add files this easy, you still have to provide the mime type manually though.
+ addFile "file_field_name" "path/to/local/file" "image/jpeg"
+
+ -- And of course you can add any field if you know it's name
+ byName "answer" "42"
+
+ statusIs 302
+
+ describe "Db access, still very raw" $ do
+ it "selects the list" $ do
+ msgs <- testDB $ do (selectList [] [] :: SqlPersist IO [(Key SqlPersist Message, Message)])
+ assertEqual "One Message in the DB" 1 (DL.length msgs)
+
+```
+
View
@@ -0,0 +1,7 @@
+#!/usr/bin/env runhaskell
+
+> module Main where
+> import Distribution.Simple
+
+> main :: IO ()
+> main = defaultMain
Oops, something went wrong.

0 comments on commit b0b755c

Please sign in to comment.