Skip to content
This repository has been archived by the owner on Oct 27, 2021. It is now read-only.

Commit

Permalink
Merge pull request #70 from rb-de0/unittests
Browse files Browse the repository at this point in the history
Unit Tests
  • Loading branch information
rb-de0 committed Feb 25, 2018
2 parents e0535f9 + fb29816 commit f304176
Show file tree
Hide file tree
Showing 76 changed files with 4,061 additions and 104 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@ Public/documents/
Public/user
Resources/Views/user

### Dev ###
.vagrant
vendor/bundle
.bundle

### Test ###
.test

# End of https://www.gitignore.io/api/vapor
47 changes: 47 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
os:
- linux
- osx
language: generic
sudo: required
dist: trusty

services:
- mysql

env:
global:
- MYSQL_PASSWORD=''
- MYSQL_PORT=3306

osx_image: xcode9.2
before_install:
- if [ $TRAVIS_OS_NAME == "osx" ]; then
brew update;
brew tap vapor/tap;
brew update;
bundle install --path vendor/bundle;
brew install vapor;
brew install cmysql;
mysql.server start;
else
eval "$(curl -sL https://apt.vapor.sh)";
sudo apt-get install vapor;
sudo apt-get install cmysql;
sudo chmod -R a+rx /usr/;
fi
- mysql -u root -e "set global max_connections = 1000";

script:
- if [ $TRAVIS_OS_NAME == "osx" ]; then
swift build;
swift test;
else
swift build -Xswiftc -DNOJSON;
swift test -Xswiftc -DNOJSON;
fi

after_success:
- if [ $TRAVIS_OS_NAME == "osx" ]; then
swift package generate-xcodeproj;
bundle exec fastlane send_coverage;
fi
3 changes: 2 additions & 1 deletion Config/droplet.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"userfile",
"redis-sessions",
"security-headers",
"csrf"
"csrf",
"message"
],

"//": "Choose which commands this application can run",
Expand Down
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "https://rubygems.org"

gem "fastlane", '2.81.0'
gem "slather"
168 changes: 168 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
GEM
remote: https://rubygems.org/
specs:
CFPropertyList (2.3.6)
activesupport (5.1.5)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
atomos (0.1.2)
babosa (1.0.2)
claide (1.0.2)
clamp (0.6.5)
colored (1.2)
colored2 (3.1.2)
commander-fastlane (4.4.6)
highline (~> 1.7.2)
concurrent-ruby (1.0.5)
declarative (0.0.10)
declarative-option (0.1.0)
domain_name (0.5.20170404)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.2.1)
excon (0.60.0)
faraday (0.14.0)
multipart-post (>= 1.2, < 3)
faraday-cookie_jar (0.0.6)
faraday (>= 0.7.4)
http-cookie (~> 1.0.0)
faraday_middleware (0.12.2)
faraday (>= 0.7.4, < 1.0)
fastimage (2.1.1)
fastlane (2.81.0)
CFPropertyList (>= 2.3, < 4.0.0)
addressable (>= 2.3, < 3.0.0)
babosa (>= 1.0.2, < 2.0.0)
bundler (>= 1.12.0, < 2.0.0)
colored
commander-fastlane (>= 4.4.5, < 5.0.0)
dotenv (>= 2.1.1, < 3.0.0)
excon (>= 0.45.0, < 1.0.0)
faraday (~> 0.9)
faraday-cookie_jar (~> 0.0.6)
faraday_middleware (~> 0.9)
fastimage (>= 2.1.0, < 3.0.0)
gh_inspector (>= 1.1.2, < 2.0.0)
google-api-client (>= 0.13.1, < 0.14.0)
highline (>= 1.7.2, < 2.0.0)
json (< 3.0.0)
mini_magick (~> 4.5.1)
multi_json
multi_xml (~> 0.5)
multipart-post (~> 2.0.0)
plist (>= 3.1.0, < 4.0.0)
public_suffix (~> 2.0.0)
rubyzip (>= 1.1.0, < 2.0.0)
security (= 0.1.3)
slack-notifier (>= 2.0.0, < 3.0.0)
terminal-notifier (>= 1.6.2, < 2.0.0)
terminal-table (>= 1.4.5, < 2.0.0)
tty-screen (>= 0.6.3, < 1.0.0)
tty-spinner (>= 0.8.0, < 1.0.0)
word_wrap (~> 1.0.0)
xcodeproj (>= 1.5.2, < 2.0.0)
xcpretty (>= 0.2.4, < 1.0.0)
xcpretty-travis-formatter (>= 0.0.3)
gh_inspector (1.1.2)
google-api-client (0.13.6)
addressable (~> 2.5, >= 2.5.1)
googleauth (~> 0.5)
httpclient (>= 2.8.1, < 3.0)
mime-types (~> 3.0)
representable (~> 3.0)
retriable (>= 2.0, < 4.0)
googleauth (0.6.2)
faraday (~> 0.12)
jwt (>= 1.4, < 3.0)
logging (~> 2.0)
memoist (~> 0.12)
multi_json (~> 1.11)
os (~> 0.9)
signet (~> 0.7)
highline (1.7.10)
http-cookie (1.0.3)
domain_name (~> 0.5)
httpclient (2.8.3)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
json (2.1.0)
jwt (2.1.0)
little-plugger (1.1.4)
logging (2.2.2)
little-plugger (~> 1.1)
multi_json (~> 1.10)
memoist (0.16.0)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_magick (4.5.1)
mini_portile2 (2.3.0)
minitest (5.11.3)
multi_json (1.13.1)
multi_xml (0.6.0)
multipart-post (2.0.0)
nanaimo (0.2.3)
nokogiri (1.8.2)
mini_portile2 (~> 2.3.0)
os (0.9.6)
plist (3.4.0)
public_suffix (2.0.5)
representable (3.0.4)
declarative (< 0.1.0)
declarative-option (< 0.2.0)
uber (< 0.2.0)
retriable (3.1.1)
rouge (2.0.7)
rubyzip (1.2.1)
security (0.1.3)
signet (0.8.1)
addressable (~> 2.3)
faraday (~> 0.9)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
slack-notifier (2.3.2)
slather (2.4.5)
CFPropertyList (~> 2.2)
activesupport (>= 4.0.2)
clamp (~> 0.6)
nokogiri (~> 1.8.2)
xcodeproj (~> 1.4)
terminal-notifier (1.8.0)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
thread_safe (0.3.6)
tty-cursor (0.5.0)
tty-screen (0.6.4)
tty-spinner (0.8.0)
tty-cursor (>= 0.5.0)
tzinfo (1.2.5)
thread_safe (~> 0.1)
uber (0.1.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.5)
unicode-display_width (1.3.0)
word_wrap (1.0.0)
xcodeproj (1.5.6)
CFPropertyList (~> 2.3.3)
atomos (~> 0.1.2)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.2.3)
xcpretty (0.2.8)
rouge (~> 2.0.7)
xcpretty-travis-formatter (1.0.0)
xcpretty (~> 0.2, >= 0.0.7)

PLATFORMS
ruby

DEPENDENCIES
fastlane (= 2.81.0)
slather

BUNDLED WITH
1.16.1
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ let package = Package(
"SwiftSoup",
"Swinject"
]),
.target(name: "Run", dependencies: ["App"])
.target(name: "Run", dependencies: ["App"]),
.testTarget(name: "NoteTests", dependencies: ["App"])
]
)
9 changes: 2 additions & 7 deletions Sources/App/Application/Assembler/DropletAssembly.swift
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import Swinject
import Vapor

// Register some of the services provided by Droplet in the container
class DropletAssembly: Assembly {

private let hash: HashProtocol
private let view: ViewRenderer

init(drop: Droplet) {
hash = drop.hash
view = drop.view
}

func assemble(container: Container) {

container.register(ViewRenderer.self) { [view] r in
return view
}.inObjectScope(.container)


container.register(HashProtocol.self) { [hash] _ in
return hash
}.inObjectScope(.container)
Expand Down
20 changes: 20 additions & 0 deletions Sources/App/Application/Assembler/ViewAssmbly.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Swinject
import Vapor

class ViewAssembly: Assembly {

private let viewCreator: DefaultViewCreator

init(drop: Droplet) {
viewCreator = DefaultViewCreator(renderer: drop.view)
viewCreator.set(drop.config.viewDecorators)
}

func assemble(container: Container) {

container.register(ViewCreator.self) { [viewCreator] _ in
return viewCreator
}.inObjectScope(.container)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ func register(assembly: Assembly) {
assembler.apply(assembly: assembly)
}

func register<Service>(_ service: Service) {
rootContainer.register(type(of: service), factory: { _ in service })
}

func resolve<Service>(_ type: Service.Type, name: String? = nil) -> Service {

guard let service = assembler.resolver.resolve(type, name: name) else {
Expand Down
6 changes: 6 additions & 0 deletions Sources/App/Application/Services/ViewCreator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Vapor
import HTTP

protocol ViewCreator {
func make(_ path: String, _ context: NodeRepresentable, for request: Request) throws -> View
}
22 changes: 22 additions & 0 deletions Sources/App/Application/Services/ViewDecorator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Vapor
import HTTP

protocol ViewDecorator {
func decorate(node: inout Node, with request: Request) throws
}

extension Config {

var viewDecorators: [ViewDecorator] {
get {
return (storage["view-decorators"] as? [ViewDecorator]) ?? []
}
set {
storage["view-decorators"] = newValue
}
}

func addViewDecorator(_ viewDecorator: ViewDecorator) {
viewDecorators = viewDecorators + [viewDecorator]
}
}
6 changes: 5 additions & 1 deletion Sources/App/Configs/ApplicationConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ struct ApplicationConfig: ConfigInitializable {
let hostName = config["note", "hostname"]?.string,
let dateFormat = config["note", "dateFormat"]?.string else {

fatalError("Not found note.json or necessary key.")
self.messageFormat = ""
self.hostName = ""
self.dateFormat = ""
self.meta = nil
return
}

self.messageFormat = messageFormat
Expand Down
11 changes: 3 additions & 8 deletions Sources/App/Controllers/Admin/AdminCategoryController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,12 @@ final class AdminCategoryController: EditableResourceRepresentable {

let category = try Category(request: request)
try category.save()

guard let id = category.id?.int else {
throw Abort.serverError
}
let id = try category.assertId()

return Response(redirect: "/admin/categories/\(id)/edit")

} catch {

return Response(redirect: "/admin/categories/create", with: FormError(error: error, deliverer: Category.self), for: request)
}
}
Expand All @@ -65,9 +62,7 @@ final class AdminCategoryController: EditableResourceRepresentable {

func update(request: Request, category: Category) throws -> ResponseRepresentable {

guard let id = category.id?.int else {
throw Abort.serverError
}
let id = try category.assertId()

do {
try category.update(for: request)
Expand Down
4 changes: 1 addition & 3 deletions Sources/App/Controllers/Admin/AdminImageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ final class AdminImageViewController: EditableResourceRepresentable {

func update(request: Request, image: Image) throws -> ResponseRepresentable {

guard let id = image.id?.int else {
throw Abort.serverError
}
let id = try image.assertId()

do {

Expand Down

0 comments on commit f304176

Please sign in to comment.