Skip to content

Commit 864558a

Browse files
authored
[ruby/hanami] Add fortunes test (#9686)
1 parent f7401a5 commit 864558a

File tree

10 files changed

+73
-6
lines changed

10 files changed

+73
-6
lines changed

frameworks/Ruby/hanami/Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ gem "hanami-router", "~> 2.2"
77
gem "hanami-controller", "~> 2.2"
88
gem "hanami-db", "~> 2.2"
99
gem "hanami-validations", "~> 2.2"
10+
gem "hanami-view", "~> 2.2"
1011

1112
gem "dry-types", "~> 1.0", ">= 1.6.1"
1213
gem "puma"

frameworks/Ruby/hanami/Gemfile.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ GEM
102102
dry-transformer (~> 1.0, < 2)
103103
hanami-validations (2.2.0)
104104
dry-validation (>= 1.10, < 2)
105+
hanami-view (2.2.1)
106+
dry-configurable (~> 1.0)
107+
dry-core (~> 1.0)
108+
dry-inflector (~> 1.0, < 2)
109+
temple (~> 0.10.0, >= 0.10.2)
110+
tilt (~> 2.3)
111+
zeitwerk (~> 2.6)
105112
hansi (0.2.1)
106113
ice_nine (0.11.2)
107114
json (2.10.2)
@@ -146,6 +153,8 @@ GEM
146153
ruby2_keywords (0.0.5)
147154
sequel (5.90.0)
148155
bigdecimal
156+
temple (0.10.3)
157+
tilt (2.6.0)
149158
transproc (1.1.1)
150159
zeitwerk (2.7.2)
151160

@@ -160,6 +169,7 @@ DEPENDENCIES
160169
hanami-db (~> 2.2)
161170
hanami-router (~> 2.2)
162171
hanami-validations (~> 2.2)
172+
hanami-view (~> 2.2)
163173
pg
164174
puma
165175
rake
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
module HelloWorld
4+
module Actions
5+
module Fortunes
6+
class Index < HelloWorld::Action
7+
def handle(*, response)
8+
end
9+
end
10+
end
11+
end
12+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module HelloWorld
2+
module Relations
3+
class Fortunes < HelloWorld::DB::Relation
4+
schema :Fortune, infer: true, as: :fortunes
5+
end
6+
end
7+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module HelloWorld
2+
module Repos
3+
class FortuneRepo < HelloWorld::DB::Repo
4+
def all
5+
results = fortunes.to_a.map(&:to_h)
6+
results << { id: 0, message: 'Additional fortune added at request time.' }
7+
results.sort_by! { |fortune| fortune[:message] }
8+
end
9+
end
10+
end
11+
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<table>
2+
<tr>
3+
<th>id</th>
4+
<th>message</th>
5+
</tr>
6+
<% fortunes.each do |fortune| %>
7+
<tr>
8+
<td><%= fortune[:id] %></td>
9+
<td><%= fortune[:message] %></td>
10+
</tr>
11+
<% end %>
12+
</table>

frameworks/Ruby/hanami/app/templates/layouts/app.html.erb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<!DOCTYPE html>
2-
<html lang="en">
2+
<html>
33
<head>
4-
<meta charset="UTF-8">
5-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6-
<title>Bookshelf</title>
4+
<title>Fortunes</title>
75
</head>
86
<body>
97
<%= yield %>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module HelloWorld
2+
module Views
3+
module Fortunes
4+
class Index < HelloWorld::View
5+
6+
include Deps["repos.fortune_repo"]
7+
8+
expose :fortunes do
9+
fortune_repo.all
10+
end
11+
end
12+
end
13+
end
14+
end

frameworks/Ruby/hanami/benchmark_config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"json_url": "/json",
66
"db_url": "/db",
77
"query_url": "/queries?queries=",
8+
"fortune_url": "/fortunes",
89
"update_url": "/updates?queries=",
910
"plaintext_url": "/plaintext",
1011
"port": 8080,

frameworks/Ruby/hanami/config/routes.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
module HelloWorld
44
class Routes < Hanami::Routes
5-
get "/db", to: "db.index"
65
get "/json", to: "json.index"
6+
get "/db", to: "db.index"
7+
get "/queries", to: "queries.index"
8+
get "/fortunes", to: "fortunes.index"
79
get "/updates", to: "updates.index"
810
get "/plaintext", to: "plaintext.index"
9-
get "/queries", to: "queries.index"
1011
end
1112
end

0 commit comments

Comments
 (0)