Skip to content

Commit f79c677

Browse files
committed
Add new initialiser to help repositories
1 parent 4ca3b12 commit f79c677

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Sources/SteamPress/Models/BlogPost.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ public final class BlogPost: Codable {
2929
self.lastEdited = nil
3030
self.published = published
3131
}
32+
33+
public init(blogID: Int? = nil, title: String, contents: String, authorID: Int, creationDate: Date, slugUrl: String,
34+
published: Bool) {
35+
self.blogID = blogID
36+
self.title = title
37+
self.contents = contents
38+
self.author = authorID
39+
self.created = creationDate
40+
self.slugUrl = slugUrl
41+
self.lastEdited = nil
42+
self.published = published
43+
}
3244
}
3345

3446
// MARK: - BlogPost Utilities

Tests/SteamPressTests/BlogTests/PostTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,9 @@ class PostTests: XCTestCase {
7777
XCTAssertEqual(tags.first?.name, tag1Name)
7878
XCTAssertEqual(tags.last?.name, tag2Name)
7979
}
80+
81+
func testExtraInitialiserWorks() throws {
82+
let post = BlogPost(blogID: 1, title: "title", contents: "contents", authorID: 1, creationDate: Date(), slugUrl: "slug-url", published: true)
83+
XCTAssertEqual(post.blogID, 1)
84+
}
8085
}

0 commit comments

Comments
 (0)