Skip to content

Commit

Permalink
update to latest kemalyst
Browse files Browse the repository at this point in the history
  • Loading branch information
drujensen committed Jul 27, 2017
1 parent f0a4ac0 commit 29491a7
Show file tree
Hide file tree
Showing 20 changed files with 118 additions and 115 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Expand Up @@ -5,5 +5,4 @@
/.crystal/
/.shards/
.env


!shards.lock
2 changes: 1 addition & 1 deletion Dockerfile
@@ -1,4 +1,4 @@
FROM drujensen/crystal:0.22.0-1
FROM drujensen/crystal:0.23/1

ENV KGEN_VERSION 0.6.2

Expand Down
20 changes: 10 additions & 10 deletions config/application.cr
@@ -1,4 +1,4 @@
require "../src/controllers/session_controller"
require "../src/middleware/authenticate"

Kemalyst::Application.config do |config|
# Set the binding host ip address. Defaults to "0.0.0.0"
Expand Down Expand Up @@ -31,14 +31,14 @@ Kemalyst::Application.config do |config|
# file.

config.handlers.clear
config.handlers << Crack::Handler::Logger.instance(config.logger)
config.handlers << Crack::Handler::Error.instance
config.handlers << Crack::Handler::Static.instance
config.handlers << Crack::Handler::Session.instance
config.handlers << Crack::Handler::Flash.instance
config.handlers << Crack::Handler::Params.instance
config.handlers << Crack::Handler::CSRF.instance
config.handlers << Crack::Handler::Method.instance
config.handlers << SessionController::Authenticate.instance
config.handlers << Kemalyst::Handler::Logger.instance(config.logger)
config.handlers << Kemalyst::Handler::Error.instance
config.handlers << Kemalyst::Handler::Static.instance
config.handlers << Kemalyst::Handler::Session.instance
config.handlers << Kemalyst::Handler::Flash.instance
config.handlers << Kemalyst::Handler::Params.instance
config.handlers << Kemalyst::Handler::CSRF.instance
config.handlers << Kemalyst::Handler::Method.instance
config.handlers << Authenticate.new
config.handlers << Kemalyst::Handler::Router.instance
end
2 changes: 1 addition & 1 deletion config/flash.cr
@@ -1,4 +1,4 @@
Crack::Handler::Flash.config do |config|
Kemalyst::Handler::Flash.config do |config|
# The cookie name to hold the flash messages
config.key = "_blog.flash"
end
Expand Down
8 changes: 4 additions & 4 deletions config/routes.cr
Expand Up @@ -2,11 +2,11 @@ require "../src/controllers/*"

include Kemalyst::Handler

get "/", home, index
get "/", HomeController, :index

get "/login", session, new
post "/session", session, create
get "/logout", session, delete
get "/login", SessionController, :new
post "/session", SessionController, :create
get "/logout", SessionController, :delete

resources Post
resources User
Expand Down
2 changes: 1 addition & 1 deletion config/session.cr
@@ -1,4 +1,4 @@
Crack::Handler::Session.config do |config|
Kemalyst::Handler::Session.config do |config|
# The cookie name to hold the session data
config.key = "_blog.session"

Expand Down
2 changes: 1 addition & 1 deletion config/static.cr
@@ -1,4 +1,4 @@
Crack::Handler::Static.config do |config|
Kemalyst::Handler::Static.config do |config|
# set the public folder. Defaults to `/public`
# config.public_folder = "./public"
end
8 changes: 8 additions & 0 deletions db/seeds.cr
@@ -0,0 +1,8 @@
require "kemalyst"
require "../config/*"

user = User.new
user.name = "Admin"
user.email = "admin@example.com"
user.password = "password"
user.save
22 changes: 11 additions & 11 deletions shard.lock
@@ -1,9 +1,5 @@
version: 1.0
shards:
crack:
github: kemalyst/crack
version: 0.1.5

db:
github: crystal-lang/crystal-db
version: 0.4.2
Expand All @@ -12,13 +8,13 @@ shards:
github: dukex/expect.cr
commit: 17c31a0f42815cd914a630852bb2ee0da6a39dc0

granite_orm:
github: kemalyst/granite-orm
version: 0.6.2

kemalyst:
github: kemalyst/kemalyst
version: 0.8.7
version: 0.12.0

kemalyst-model:
github: kemalyst/kemalyst-model
version: 0.7.0

kemalyst-spec:
github: kemalyst/kemalyst-spec
Expand All @@ -44,6 +40,10 @@ shards:
github: ysbaddaden/pool
version: 0.2.3

quartz-mailer:
github: amber-crystal/quartz-mailer
commit: 203c6ac78e670a6d86eb33cb4ee4220b5fa5eb4d

radix:
github: luislavena/radix
version: 0.3.8
Expand All @@ -62,9 +62,9 @@ shards:

slang:
github: jeromegn/slang
commit: f86dbdec0fb2b63054a2656113b0f66939aa6058
commit: b817c89c7e5ae39562710c0d6c7f42cee685e14f

smtp:
github: raydf/smtp.cr
commit: 1301f244fd1e251244b0a9fb7f8bc817da9c8854
commit: 36854c38435ce104914cb6f44e08c23d8defd143

8 changes: 2 additions & 6 deletions shard.yml
Expand Up @@ -9,16 +9,12 @@ license: MIT
dependencies:
kemalyst:
github: kemalyst/kemalyst
version: ~> 0.8.0

granite_orm:
github: kemalyst/granite-orm
version: ~> 0.6.0
kemalyst-model:
github: kemalyst/kemalyst-model

kemalyst-spec:
github: kemalyst/kemalyst-spec
version: ~> 0.1.0


mysql:
github: crystal-lang/crystal-mysql
Expand Down
14 changes: 7 additions & 7 deletions spec/controllers/post_controller_spec.cr
Expand Up @@ -12,46 +12,46 @@ describe PostController do
Post.clear
end

describe PostController::Index do
describe "index" do
it "renders all the posts" do
subject = create_subject
get "/posts"
response.body.should contain "test"
end
end

describe PostController::Show do
describe "show" do
it "renders a single post" do
subject = create_subject
get "/posts/#{subject.id}"
response.body.should contain "test"
end
end

describe PostController::New do
describe "new" do
it "render new template" do
get "/posts/new"
response.body.should contain "New Post"
end
end

describe PostController::Create do
describe "create" do
it "creates a post" do
post "/posts", body: "title=testing"
subject_list = Post.all
subject_list.size.should eq 1
end
end

describe PostController::Edit do
describe "edit" do
it "renders edit template" do
subject = create_subject
get "/posts/#{subject.id}/edit"
response.body.should contain "Edit Post"
end
end

describe PostController::Update do
describe "update" do
it "updates a post" do
subject = create_subject
patch "/posts/#{subject.id}", body: "title=test2"
Expand All @@ -60,7 +60,7 @@ describe PostController do
end
end

describe PostController::Delete do
describe "delete" do
it "deletes a post" do
subject = create_subject
delete "/posts/#{subject.id}"
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/session_controller_spec.cr
Expand Up @@ -2,17 +2,17 @@ require "./spec_helper"

describe SessionController do

describe SessionController::New do
describe "new" do
it "renders the view" do
end
end

describe SessionController::Create do
describe "create" do
it "renders the view" do
end
end

describe SessionController::Delete do
describe "delete" do
it "renders the view" do
end
end
Expand Down
14 changes: 7 additions & 7 deletions spec/controllers/user_controller_spec.cr
Expand Up @@ -12,46 +12,46 @@ describe UserController do
User.clear
end

describe UserController::Index do
describe "index" do
it "renders all the users" do
subject = create_subject
get "/users"
response.body.should contain "test"
end
end

describe UserController::Show do
describe "show" do
it "renders a single user" do
subject = create_subject
get "/users/#{subject.id}"
response.body.should contain "test"
end
end

describe UserController::New do
describe "new" do
it "render new template" do
get "/users/new"
response.body.should contain "New User"
end
end

describe UserController::Create do
describe "create" do
it "creates a user" do
post "/users", body: "name=testing"
subject_list = User.all
subject_list.size.should eq 1
end
end

describe UserController::Edit do
describe "edit" do
it "renders edit template" do
subject = create_subject
get "/users/#{subject.id}/edit"
response.body.should contain "Edit User"
end
end

describe UserController::Update do
describe "update" do
it "updates a user" do
subject = create_subject
patch "/users/#{subject.id}", body: "name=test2"
Expand All @@ -60,7 +60,7 @@ describe UserController do
end
end

describe UserController::Delete do
describe "delete" do
it "deletes a user" do
subject = create_subject
delete "/users/#{subject.id}"
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/home_controller.cr
Expand Up @@ -2,7 +2,7 @@ require "../models/post"
require "markdown"

class HomeController < Kemalyst::Controller
action Index do
def index
posts = Post.all("WHERE posts.published = true
ORDER BY created_at DESC")
html render("home/index.slang", "main.slang")
Expand Down
30 changes: 15 additions & 15 deletions src/controllers/post_controller.cr
@@ -1,67 +1,67 @@
require "../models/post"

class PostController < Kemalyst::Controller
action Index do
def index
posts = Post.all("ORDER BY created_at DESC")
html render("post/index.slang", "main.slang")
end

action Show do
def show
if post = Post.find params["id"]
html render("post/show.slang", "main.slang")
else
context.flash["warning"] = "Post with ID #{params["id"]} Not Found"
flash["warning"] = "Post with ID #{params["id"]} Not Found"
redirect "/posts"
end
end

action New do
def new
post = Post.new
html render("post/new.slang", "main.slang")
end

action Create do
def create
post = Post.new(params.to_h.select(["title", "body", "published"]))

if post.valid? && post.save
context.flash["success"] = "Created Post successfully."
flash["success"] = "Created Post successfully."
redirect "/posts"
else
context.flash["danger"] = "Could not create Post!"
flash["danger"] = "Could not create Post!"
html render("post/new.slang", "main.slang")
end
end

action Edit do
def edit
if post = Post.find params["id"]
html render("post/edit.slang", "main.slang")
else
context.flash["warning"] = "Post with ID #{params["id"]} Not Found"
flash["warning"] = "Post with ID #{params["id"]} Not Found"
redirect "/posts"
end
end

action Update do
def update
if post = Post.find(params["id"])
post.set_attributes(params.to_h.select(["title", "body", "published"]))
if post.valid? && post.save
context.flash["success"] = "Updated Post successfully."
flash["success"] = "Updated Post successfully."
redirect "/posts"
else
context.flash["danger"] = "Could not update Post!"
flash["danger"] = "Could not update Post!"
html render("post/edit.slang", "main.slang")
end
else
context.flash["warning"] = "Post with ID #{params["id"]} Not Found"
flash["warning"] = "Post with ID #{params["id"]} Not Found"
redirect "/posts"
end
end

action Delete do
def delete
if post = Post.find params["id"]
post.destroy
else
context.flash["warning"] = "Post with ID #{params["id"]} Not Found"
flash["warning"] = "Post with ID #{params["id"]} Not Found"
end
redirect "/posts"
end
Expand Down

0 comments on commit 29491a7

Please sign in to comment.