Skip to content
This repository was archived by the owner on Sep 30, 2025. It is now read-only.

Commit 7954604

Browse files
committed
Rename filterParams, simplify spec and add hspec-expectations-lifted
1 parent 71b36ff commit 7954604

5 files changed

Lines changed: 18 additions & 10 deletions

File tree

package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ tests:
6363
dependencies:
6464
- QuickCheck
6565
- hspec
66+
- hspec-expectations-lifted
6667
- quickcheck-classes
6768
- yesod-core
6869
- yesod-paginator

src/Yesod/Paginator/Widgets.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Yesod.Paginator.Widgets
99
, ellipsedWith
1010

1111
-- * Exported for testing
12-
, filterParams
12+
, buildParams
1313
) where
1414

1515
import Yesod.Paginator.Prelude
@@ -181,14 +181,14 @@ getUpdateGetParams
181181
getUpdateGetParams pageParamName = do
182182
params <- handlerToWidget $ reqGetParams <$> getRequest
183183
pure
184-
$ \number -> filterParams pageParamName number params
184+
$ \number -> buildParams pageParamName number params
185185

186186
renderGetParams :: [(Text, Text)] -> Text
187187
renderGetParams [] = ""
188188
renderGetParams ps = "?" <> T.intercalate "&" (map renderGetParam ps)
189189
where renderGetParam (k, v) = encodeText k <> "=" <> encodeText v
190190

191-
filterParams :: Show a => PageParamName -> a -> [(Text, Text)] -> [(Text, Text)]
192-
filterParams pageParamName number params =
191+
buildParams :: Show a => PageParamName -> a -> [(Text, Text)] -> [(Text, Text)]
192+
buildParams pageParamName number params =
193193
let name = unPageParamName pageParamName
194194
in [(name, tshow number)] <> filter ((/=) name . fst) params

test/SpecHelper.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ module SpecHelper
1010
, module X
1111
) where
1212

13-
import Test.Hspec as X
13+
import Test.Hspec as X hiding (shouldBe)
14+
import Test.Hspec.Expectations.Lifted as HspecLifted
1415
import Yesod.Core
1516
import Yesod.Paginator as X
1617
import Yesod.Paginator.Prelude as X
@@ -62,3 +63,6 @@ getEllipsedParamNameR total per elements pageParamName = do
6263

6364
withApp :: SpecWith (TestApp App) -> Spec
6465
withApp = before $ pure (App, id)
66+
67+
shouldBe :: (HasCallStack, Eq a, Show a) => a -> a -> YesodExample site ()
68+
shouldBe a b = a `HspecLifted.shouldBe` b

test/Yesod/Paginator/WidgetsSpec.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ spec = withApp $ do
189189
, "</ul>"
190190
]
191191

192-
describe "filterParams" $ it "works" $ do
192+
describe "buildParams" $ it "works" $ do
193193
let pageParamName = PageParamName "p"
194194
pageNumber :: Int
195195
pageNumber = 3
@@ -202,7 +202,9 @@ spec = withApp $ do
202202
, ("ids[]", "2")
203203
]
204204

205-
assertEq
206-
"filters page params not equal to the page number but keeps query params with the same name"
207-
(filterParams pageParamName pageNumber params)
208-
[("p", "3"), ("foo", "bar"), ("ids[]", "1"), ("ids[]", "2")]
205+
buildParams pageParamName pageNumber params
206+
`shouldBe` [ ("p", "3")
207+
, ("foo", "bar")
208+
, ("ids[]", "1")
209+
, ("ids[]", "2")
210+
]

yesod-paginator.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ test-suite test
116116
QuickCheck
117117
, base <5
118118
, hspec
119+
, hspec-expectations-lifted
119120
, quickcheck-classes
120121
, yesod-core
121122
, yesod-paginator

0 commit comments

Comments
 (0)