Skip to content

Commit

Permalink
Add new initialiser to help repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
0xTim committed Apr 17, 2020
1 parent 4ca3b12 commit f79c677
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Sources/SteamPress/Models/BlogPost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ public final class BlogPost: Codable {
self.lastEdited = nil
self.published = published
}

public init(blogID: Int? = nil, title: String, contents: String, authorID: Int, creationDate: Date, slugUrl: String,
published: Bool) {
self.blogID = blogID
self.title = title
self.contents = contents
self.author = authorID
self.created = creationDate
self.slugUrl = slugUrl
self.lastEdited = nil
self.published = published
}
}

// MARK: - BlogPost Utilities
Expand Down
5 changes: 5 additions & 0 deletions Tests/SteamPressTests/BlogTests/PostTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,9 @@ class PostTests: XCTestCase {
XCTAssertEqual(tags.first?.name, tag1Name)
XCTAssertEqual(tags.last?.name, tag2Name)
}

func testExtraInitialiserWorks() throws {
let post = BlogPost(blogID: 1, title: "title", contents: "contents", authorID: 1, creationDate: Date(), slugUrl: "slug-url", published: true)
XCTAssertEqual(post.blogID, 1)
}
}

0 comments on commit f79c677

Please sign in to comment.