Skip to content

Commit

Permalink
Merge pull request #147 from Casperhr/master
Browse files Browse the repository at this point in the history
Fixed default values for strings
  • Loading branch information
tanner0101 authored Jan 2, 2017
2 parents 97afe99 + 8ffd914 commit 593cdb2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/Fluent/SQL/GeneralSQLSerializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ open class GeneralSQLSerializer: SQLSerializer {
}

if let d = column.default?.string {
clause += "DEFAULT \(d)"
clause += "DEFAULT '\(d)'"
}

return clause.joined(separator: " ")
Expand Down
17 changes: 17 additions & 0 deletions Tests/FluentTests/SchemaCreateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import XCTest
class SchemaCreateTests: XCTestCase {
static let allTests = [
("testCreate", testCreate),
("testStringDefault", testStringDefault),
("testModify", testModify),
("testDelete", testDelete),
]

func testCreate() throws {
Expand All @@ -22,6 +25,20 @@ class SchemaCreateTests: XCTestCase {
XCTAssertEqual(statement, "CREATE TABLE `users` (`id` INTEGER NOT NULL, `name` STRING NOT NULL, `email` STRING NOT NULL, `profile` JSON NOT NULL)")
XCTAssertEqual(values.count, 0)
}

func testStringDefault() throws {
let builder = Schema.Creator("table")

builder.string("string", default: "default")

let sql = builder.schema.sql
let serializer = GeneralSQLSerializer(sql: sql)

let (statement, values) = serializer.serialize()

XCTAssertEqual(statement, "CREATE TABLE `table` (`string` STRING NOT NULL DEFAULT 'default')")
XCTAssertEqual(values.count, 0)
}

func testModify() throws {
let builder = Schema.Modifier("users")
Expand Down

0 comments on commit 593cdb2

Please sign in to comment.