Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 38 update after running #39

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Routes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function extend_params(params::Params, v::DynamicNode, p::String)
params
end

typealias Route (RouteNode,Union(Function,Nothing)) # ('/about', function()...)
typealias Route @compat Tuple{ RouteNode,Union(Function,Nothing) } # ('/about', function()...)
isequal(r::Route, v) = isequal(r[1], v)
ismatch(r::Route, v) = ismatch(r[1], v)
isequal(node::RouteNode, route::Route) = isequal(node, route[1])
Expand Down
13 changes: 13 additions & 0 deletions src/Trees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ end
function insert!(tree::Tree, values::Array)
if isempty(values)
tree
elseif length(values) == 1
# for last value,
# if it has already in the tree.children, update it with the last value
# if it is not in the tree.children, push it in the tree.children.
leaf = Tree(values[1])

i = findfirst((t) -> isequal(t.value, leaf.value), tree.children)

if i != 0 # the leaf has already in the tree.children, replace it
tree.children[i] = leaf
else
push!(tree.children, leaf)
end
elseif ischild(values[1], tree)
t = getchild(tree, values[1])
insert!(t, values[2:end])
Expand Down
33 changes: 33 additions & 0 deletions test/Trees_test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module TreesTest
using FactCheck
include("../src/Trees.jl")

facts("Tree") do
t = Tree(:root)
insert!(t, [:a, :b, :c])

context("ischild") do
@fact ischild(:a, t) => true

@fact ischild(:b, t) => false
@fact ischild(:c, t) => false
@fact ischild(:d, t) => false
end

context("getchild") do
@fact getchild(t, :a).value => :a

@fact getchild(t, :b) => nothing
end

context("search") do
tree = Tree(:root)
insert!(tree, [:a, :b])
insert!(tree, [:a, :b])
@fact tree.value => :root

@fact tree.children[1].value => :a
end
end

end
16 changes: 16 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ using FactCheck
import Requests
req = Requests

include("Trees_test.jl")

app = Morsel.app()

get(app, "/") do req, res
Expand Down Expand Up @@ -87,3 +89,17 @@ facts("redirect") do
@fact response.status => 302
@fact response.headers["Location"] => "/"
end

# test for issue 38: https://github.com/JuliaWeb/Morsel.jl/issues/38
facts("shuold update routes") do
get(app, "/update_route") do req, res
"Original"
end

get(app, "/update_route") do req, res
"Updated"
end

response = req.get("http://localhost:8000/update_route")
@fact response.data => "Updated"
end