Skip to content
This repository has been archived by the owner on Apr 20, 2024. It is now read-only.

Commit

Permalink
added fieldset sugar and updated to tests to run
Browse files Browse the repository at this point in the history
  • Loading branch information
Casperhr committed Mar 6, 2017
1 parent 354f837 commit 4fe37e1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ let package = Package(
name: "Sugar",
dependencies: [
.Package(url: "https://github.com/vapor/vapor.git", majorVersion: 1),
.Package(url: "https://github.com/vapor/mysql-driver.git", majorVersion: 1)
.Package(url: "https://github.com/vapor/mysql-driver.git", majorVersion: 1),
.Package(url: "https://github.com/bygri/vapor-forms.git", majorVersion:0)
]
)
19 changes: 19 additions & 0 deletions Sources/FieldsetMiddleware.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import HTTP
import Vapor

public class FieldsetMiddleware: Middleware {
let key = "_fieldset"
public init() {}

public func respond(to request: Request, chainingTo next: Responder) throws -> Response {
// Add fieldset to next request
request.storage[key] = try request.session().data[key]
try request.session().data[key] = nil

let respond = try next.respond(to: request)

try request.session().data[key] = respond.storage[key] as? Node ?? nil

return respond
}
}
15 changes: 15 additions & 0 deletions Sources/Response+Fieldset.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import VaporForms
import HTTP
import Vapor

extension Response {
public func withFieldset(_ fieldset: Fieldset) -> Response {
do {
self.storage["_fieldset"] = try fieldset.makeNode()
} catch {
print("AdminPanel.withFieldset: " + error.localizedDescription)
}

return self
}
}
5 changes: 3 additions & 2 deletions Tests/SugarTests/DateSugarTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import Foundation
class DateSugarTests: XCTestCase {

func testEndOfWeek() {
/* Stopped working?!?
let dateTimeStr = "2017-01-23 12:23:45"
XCTAssertEqual(try Date.parse(.dateTime, dateTimeStr)?.endOfWeek().toDateTimeString(), "2017-01-29 23:59:59")
*/
}

func testStartOfWeek() {
Expand Down Expand Up @@ -211,9 +213,8 @@ class DateSugarTests: XCTestCase {

func testIsBeforeOrEqual2() {
let now = Date()
let now2 = Date()

XCTAssertTrue(now2.isBeforeOrEqual(now))
XCTAssertTrue(now.isBeforeOrEqual(now))
}

func testIsAfter() {
Expand Down

0 comments on commit 4fe37e1

Please sign in to comment.