ru.Bee 1.5.4 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/rubee +7 -2
- data/lib/config/base_configuration.rb +25 -7
- data/lib/db/create_addresses.rb +17 -0
- data/lib/package.json +1 -1
- data/lib/rubee/async/fiber_queue.rb +27 -0
- data/lib/rubee/async/thread_pool.rb +32 -34
- data/lib/rubee/autoload.rb +73 -0
- data/lib/rubee/configuration.rb +60 -0
- data/lib/rubee/extensions/hookable.rb +9 -2
- data/lib/rubee/generator.rb +152 -0
- data/lib/rubee/logger.rb +83 -0
- data/lib/rubee/models/sequel_object.rb +1 -2
- data/lib/rubee/router.rb +41 -0
- data/lib/rubee.rb +7 -314
- data/lib/tests/async/thread_async_test.rb +9 -5
- data/lib/tests/{auth_tokenable_test.rb → controllers/auth_tokenable_test.rb} +2 -2
- data/lib/tests/controllers/base_controller_test.rb +23 -0
- data/lib/tests/controllers/hookable_test.rb +220 -0
- data/lib/tests/{rubeeapp_test.rb → controllers/rubeeapp_test.rb} +2 -1
- data/lib/tests/example_models/address.rb +5 -0
- data/lib/tests/example_models/user.rb +1 -0
- data/lib/tests/logger_test.rb +76 -0
- data/lib/tests/{account_model_test.rb → models/account_model_test.rb} +1 -1
- data/lib/tests/{comment_model_test.rb → models/comment_model_test.rb} +13 -1
- data/lib/tests/models/db_objectable_test.rb +21 -0
- data/lib/tests/models/seralizable_test.rb +36 -0
- data/lib/tests/{user_model_test.rb → models/user_model_test.rb} +32 -1
- data/lib/tests/test.db +0 -0
- data/lib/tests/test_helper.rb +19 -2
- data/readme.md +77 -11
- metadata +19 -8
- data/lib/app/views/apples_.erb +0 -1
- data/lib/app/views/s_.erb +0 -1
data/lib/rubee/router.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module Rubee
|
2
|
+
class Router
|
3
|
+
include Singleton
|
4
|
+
|
5
|
+
HTTP_METHODS = %i[get post put patch delete head connect options trace].freeze
|
6
|
+
|
7
|
+
attr_reader :request, :routes
|
8
|
+
|
9
|
+
@routes = []
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def draw
|
13
|
+
yield(self) if block_given?
|
14
|
+
end
|
15
|
+
|
16
|
+
def route_for(request)
|
17
|
+
puts request.request_method
|
18
|
+
method = (request.params['_method'] || request.request_method).downcase.to_sym
|
19
|
+
@routes.find do |route|
|
20
|
+
return route if request.path == route[:path] && request.request_method&.downcase&.to_sym == route[:method]
|
21
|
+
|
22
|
+
pattern = route[:path].gsub(/{.*?}/, '([^/]+)')
|
23
|
+
regex = /^#{pattern}$/
|
24
|
+
regex.match?(request.path) && method.to_s == route[:method].to_s
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_route(path, to:, method: __method__, **args)
|
29
|
+
controller, action = to.split('#')
|
30
|
+
@routes.delete_if { |route| route[:path] == path && route[:method] == method }
|
31
|
+
@routes << { path:, controller:, action:, method:, **args }
|
32
|
+
end
|
33
|
+
|
34
|
+
HTTP_METHODS.each do |method|
|
35
|
+
define_method method do |path, to:, **args|
|
36
|
+
set_route(path, to:, method: method, **args)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/rubee.rb
CHANGED
@@ -15,7 +15,13 @@ module Rubee
|
|
15
15
|
IMAGE_DIR = File.join(APP_ROOT, LIB, 'images') unless defined?(IMAGE_DIR)
|
16
16
|
JS_DIR = File.join(APP_ROOT, LIB, 'js') unless defined?(JS_DIR)
|
17
17
|
CSS_DIR = File.join(APP_ROOT, LIB, 'css') unless defined?(CSS_DIR)
|
18
|
-
VERSION = '1.
|
18
|
+
VERSION = '1.6.0'
|
19
|
+
|
20
|
+
require_relative 'rubee/router'
|
21
|
+
require_relative 'rubee/logger'
|
22
|
+
require_relative 'rubee/generator'
|
23
|
+
require_relative 'rubee/autoload'
|
24
|
+
require_relative 'rubee/configuration'
|
19
25
|
|
20
26
|
class Application
|
21
27
|
include Singleton
|
@@ -54,317 +60,4 @@ module Rubee
|
|
54
60
|
controller.send(action)
|
55
61
|
end
|
56
62
|
end
|
57
|
-
|
58
|
-
class Configuration
|
59
|
-
include Singleton
|
60
|
-
|
61
|
-
@configuraiton = {
|
62
|
-
development: {
|
63
|
-
database_url: '',
|
64
|
-
port: 7000,
|
65
|
-
},
|
66
|
-
production: {},
|
67
|
-
test: {},
|
68
|
-
}
|
69
|
-
|
70
|
-
class << self
|
71
|
-
def setup(_env)
|
72
|
-
yield(self)
|
73
|
-
end
|
74
|
-
|
75
|
-
def database_url=(args)
|
76
|
-
@configuraiton[args[:env].to_sym][:database_url] = args[:url]
|
77
|
-
end
|
78
|
-
|
79
|
-
def async_adapter=(args)
|
80
|
-
@configuraiton[args[:env].to_sym][:async_adapter] = args[:async_adapter]
|
81
|
-
end
|
82
|
-
|
83
|
-
def thread_pool_limit=(args)
|
84
|
-
@configuraiton[args[:env].to_sym][:thread_pool_limit] = args[:thread_pool_limit]
|
85
|
-
end
|
86
|
-
|
87
|
-
def react=(args)
|
88
|
-
@configuraiton[args[:env].to_sym][:react] ||= { on: false }
|
89
|
-
@configuraiton[args[:env].to_sym][:react].merge!(on: args[:on])
|
90
|
-
end
|
91
|
-
|
92
|
-
def react
|
93
|
-
@configuraiton[ENV['RACK_ENV']&.to_sym || :development][:react] || {}
|
94
|
-
end
|
95
|
-
|
96
|
-
def method_missing(method_name, *_args)
|
97
|
-
return unless method_name.to_s.start_with?('get_')
|
98
|
-
|
99
|
-
@configuraiton[ENV['RACK_ENV']&.to_sym || :development]&.[](method_name.to_s.delete_prefix('get_').to_sym)
|
100
|
-
end
|
101
|
-
|
102
|
-
def envs
|
103
|
-
@configuraiton.keys
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
class Router
|
109
|
-
include Singleton
|
110
|
-
|
111
|
-
HTTP_METHODS = %i[get post put patch delete head connect options trace].freeze
|
112
|
-
|
113
|
-
attr_reader :request, :routes
|
114
|
-
|
115
|
-
@routes = []
|
116
|
-
|
117
|
-
class << self
|
118
|
-
def draw
|
119
|
-
yield(self) if block_given?
|
120
|
-
end
|
121
|
-
|
122
|
-
def route_for(request)
|
123
|
-
puts request.request_method
|
124
|
-
method = (request.params['_method'] || request.request_method).downcase.to_sym
|
125
|
-
@routes.find do |route|
|
126
|
-
return route if request.path == route[:path] && request.request_method&.downcase&.to_sym == route[:method]
|
127
|
-
|
128
|
-
pattern = route[:path].gsub(/{.*?}/, '([^/]+)')
|
129
|
-
regex = /^#{pattern}$/
|
130
|
-
regex.match?(request.path) && method.to_s == route[:method].to_s
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def set_route(path, to:, method: __method__, **args)
|
135
|
-
controller, action = to.split('#')
|
136
|
-
@routes.delete_if { |route| route[:path] == path && route[:method] == method }
|
137
|
-
@routes << { path:, controller:, action:, method:, **args }
|
138
|
-
end
|
139
|
-
|
140
|
-
HTTP_METHODS.each do |method|
|
141
|
-
define_method method do |path, to:, **args|
|
142
|
-
set_route(path, to:, method: method, **args)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
class Autoload
|
149
|
-
class << self
|
150
|
-
def call(black_list = [])
|
151
|
-
# autoload all rbs
|
152
|
-
root_directory = File.dirname(__FILE__)
|
153
|
-
priority_order_require(root_directory, black_list)
|
154
|
-
# ensure sequel object is connected
|
155
|
-
Rubee::SequelObject.reconnect!
|
156
|
-
|
157
|
-
Dir.glob(File.join(APP_ROOT, '**', '*.rb')).sort.each do |file|
|
158
|
-
base_name = File.basename(file)
|
159
|
-
|
160
|
-
unless base_name.end_with?('_test.rb') || (black_list + ['rubee.rb', 'test_helper.rb']).include?(base_name)
|
161
|
-
require_relative file
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
def priority_order_require(root_directory, black_list)
|
167
|
-
# rubee inits
|
168
|
-
Dir[File.join(root_directory, 'inits/**', '*.rb')].each do |file|
|
169
|
-
require_relative file unless black_list.include?("#{file}.rb")
|
170
|
-
end
|
171
|
-
# app inits
|
172
|
-
Dir[File.join(APP_ROOT, 'inits/**', '*.rb')].each do |file|
|
173
|
-
require_relative file unless black_list.include?("#{file}.rb")
|
174
|
-
end
|
175
|
-
# rubee async
|
176
|
-
Dir[File.join(root_directory, 'rubee/async/**', '*.rb')].each do |file|
|
177
|
-
require_relative file unless black_list.include?("#{file}.rb")
|
178
|
-
end
|
179
|
-
# app config and routes
|
180
|
-
unless black_list.include?('base_configuration.rb')
|
181
|
-
require_relative File.join(APP_ROOT, LIB,
|
182
|
-
'config/base_configuration')
|
183
|
-
end
|
184
|
-
# This is necessary prerequisitedb init step
|
185
|
-
if !defined?(Rubee::SequelObject::DB) && (PROJECT_NAME == 'rubee')
|
186
|
-
Rubee::Configuration.setup(env = :test) do |config|
|
187
|
-
config.database_url = { url: 'sqlite://lib/tests/test.db', env: }
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
require_relative File.join(APP_ROOT, LIB, 'config/routes') unless black_list.include?('routes.rb')
|
192
|
-
# rubee extensions
|
193
|
-
Dir[File.join(root_directory, 'rubee/extensions/**', '*.rb')].each do |file|
|
194
|
-
require_relative file unless black_list.include?("#{file}.rb")
|
195
|
-
end
|
196
|
-
# rubee controllers
|
197
|
-
Dir[File.join(root_directory, 'rubee/controllers/middlewares/**', '*.rb')].each do |file|
|
198
|
-
require_relative file unless black_list.include?("#{file}.rb")
|
199
|
-
end
|
200
|
-
Dir[File.join(root_directory, 'rubee/controllers/extensions/**', '*.rb')].each do |file|
|
201
|
-
require_relative file unless black_list.include?("#{file}.rb")
|
202
|
-
end
|
203
|
-
unless black_list.include?('base_controller.rb')
|
204
|
-
require_relative File.join(root_directory,
|
205
|
-
'rubee/controllers/base_controller')
|
206
|
-
end
|
207
|
-
# rubee models
|
208
|
-
unless black_list.include?('database_objectable.rb')
|
209
|
-
require_relative File.join(root_directory,
|
210
|
-
'rubee/models/database_objectable')
|
211
|
-
end
|
212
|
-
return if black_list.include?('sequel_object.rb')
|
213
|
-
|
214
|
-
require_relative File.join(root_directory,
|
215
|
-
'rubee/models/sequel_object')
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
class Generator
|
221
|
-
require_relative 'inits/charged_string'
|
222
|
-
using ChargedString
|
223
|
-
def initialize(model_name, model_attributes, controller_name, action_name, **options)
|
224
|
-
@model_name = model_name&.downcase
|
225
|
-
@model_attributes = model_attributes || []
|
226
|
-
@base_name = controller_name.to_s.gsub('Controller', '').downcase.to_s
|
227
|
-
color_puts("base_name: #{@base_name}", color: :gray)
|
228
|
-
@plural_name = @base_name.plural? ? @base_name : @base_name.pluralize
|
229
|
-
@action_name = action_name
|
230
|
-
@react = options[:react] || {}
|
231
|
-
end
|
232
|
-
|
233
|
-
def call
|
234
|
-
generate_model if @model_name
|
235
|
-
generate_db_file if @model_name
|
236
|
-
generate_controller if @base_name && @action_name
|
237
|
-
generate_view if @base_name
|
238
|
-
end
|
239
|
-
|
240
|
-
private
|
241
|
-
|
242
|
-
def generate_model
|
243
|
-
model_file = File.join(Rubee::APP_ROOT, Rubee::LIB, "app/models/#{@model_name}.rb")
|
244
|
-
if File.exist?(model_file)
|
245
|
-
puts "Model #{@model_name} already exists. Remove it if you want to regenerate"
|
246
|
-
return
|
247
|
-
end
|
248
|
-
|
249
|
-
content = <<~RUBY
|
250
|
-
class #{@model_name.capitalize} < Rubee::SequelObject
|
251
|
-
#{'attr_accessor ' + @model_attributes.map { |hash| ":#{hash[:name]}" }.join(', ') unless @model_attributes.empty?}
|
252
|
-
end
|
253
|
-
RUBY
|
254
|
-
|
255
|
-
File.open(model_file, 'w') { |file| file.write(content) }
|
256
|
-
color_puts("Model #{@model_name} created", color: :green)
|
257
|
-
end
|
258
|
-
|
259
|
-
def generate_controller
|
260
|
-
controller_file = File.join(Rubee::APP_ROOT, Rubee::LIB, "app/controllers/#{@base_name}_controller.rb")
|
261
|
-
if File.exist?(controller_file)
|
262
|
-
puts "Controller #{@base_name} already exists. Remove it if you want to regenerate"
|
263
|
-
return
|
264
|
-
end
|
265
|
-
|
266
|
-
content = <<~RUBY
|
267
|
-
class #{@base_name.capitalize}Controller < Rubee::BaseController
|
268
|
-
def #{@action_name}
|
269
|
-
response_with
|
270
|
-
end
|
271
|
-
end
|
272
|
-
RUBY
|
273
|
-
|
274
|
-
File.open(controller_file, 'w') { |file| file.write(content) }
|
275
|
-
color_puts("Controller #{@base_name} created", color: :green)
|
276
|
-
end
|
277
|
-
|
278
|
-
def generate_view
|
279
|
-
if @react[:view_name]
|
280
|
-
view_file = File.join(Rubee::APP_ROOT, Rubee::LIB, "app/views/#{@react[:view_name]}")
|
281
|
-
content = <<~JS
|
282
|
-
import React, { useEffect, useState } from "react";
|
283
|
-
// 1. Add your logic that fetches data
|
284
|
-
// 2. Do not forget to add respective react route
|
285
|
-
export function #{@react[:view_name].gsub(/\.(.*)+$/, '').capitalize}() {
|
286
|
-
|
287
|
-
return (
|
288
|
-
<div>
|
289
|
-
<h2>#{@react[:view_name]} view</h2>
|
290
|
-
</div>
|
291
|
-
);
|
292
|
-
}
|
293
|
-
JS
|
294
|
-
else
|
295
|
-
view_file = File.join(Rubee::APP_ROOT, Rubee::LIB, "app/views/#{@plural_name}_#{@action_name}.erb")
|
296
|
-
content = <<~ERB
|
297
|
-
<h1>#{@plural_name}_#{@action_name} View</h1>
|
298
|
-
ERB
|
299
|
-
end
|
300
|
-
|
301
|
-
name = @react[:view_name] || "#{@plural_name}_#{@action_name}"
|
302
|
-
|
303
|
-
if File.exist?(view_file)
|
304
|
-
puts "View #{name} already exists. Remove it if you want to regenerate"
|
305
|
-
return
|
306
|
-
end
|
307
|
-
|
308
|
-
File.open(view_file, 'w') { |file| file.write(content) }
|
309
|
-
color_puts("View #{name} created", color: :green)
|
310
|
-
end
|
311
|
-
|
312
|
-
def generate_db_file
|
313
|
-
db_file = File.join(Rubee::APP_ROOT, Rubee::LIB, "db/create_#{@plural_name}.rb")
|
314
|
-
if File.exist?(db_file)
|
315
|
-
puts "DB file for #{@plural_name} already exists. Remove it if you want to regenerate"
|
316
|
-
return
|
317
|
-
end
|
318
|
-
|
319
|
-
content = <<~RUBY
|
320
|
-
class Create#{@plural_name.capitalize}
|
321
|
-
def call
|
322
|
-
return if Rubee::SequelObject::DB.tables.include?(:#{@plural_name})
|
323
|
-
|
324
|
-
Rubee::SequelObject::DB.create_table(:#{@plural_name}) do
|
325
|
-
#{@model_attributes.map { |attribute| generate_sequel_schema(attribute) }.join("\n\t\t\t")}
|
326
|
-
end
|
327
|
-
end
|
328
|
-
end
|
329
|
-
RUBY
|
330
|
-
|
331
|
-
File.open(db_file, 'w') { |file| file.write(content) }
|
332
|
-
color_puts("DB file for #{@plural_name} created", color: :green)
|
333
|
-
end
|
334
|
-
|
335
|
-
def generate_sequel_schema(attribute)
|
336
|
-
type = attribute[:type]
|
337
|
-
name = if attribute[:name].is_a?(Array)
|
338
|
-
attribute[:name].map { |nom| ":#{nom}" }.join(", ").prepend('[') + ']'
|
339
|
-
else
|
340
|
-
":#{attribute[:name]}"
|
341
|
-
end
|
342
|
-
table = attribute[:table] || 'replace_with_table_name'
|
343
|
-
options = attribute[:options] || {}
|
344
|
-
|
345
|
-
lookup_hash = {
|
346
|
-
primary: "primary_key #{name}",
|
347
|
-
string: "String #{name}",
|
348
|
-
text: "String #{name}, text: true",
|
349
|
-
integer: "Integer #{name}",
|
350
|
-
date: "Date #{name}",
|
351
|
-
datetime: "DateTime #{name}",
|
352
|
-
time: "Time #{name}",
|
353
|
-
boolean: "TrueClass #{name}",
|
354
|
-
bigint: "Bignum #{name}",
|
355
|
-
decimal: "BigDecimal #{name}",
|
356
|
-
foreign_key: "foreign_key #{name}, :#{table}",
|
357
|
-
index: "index #{name}",
|
358
|
-
unique: "unique #",
|
359
|
-
}
|
360
|
-
|
361
|
-
statement = lookup_hash[type.to_sym]
|
362
|
-
|
363
|
-
options.keys.each do |key|
|
364
|
-
statement += ", #{key}: '#{options[key]}'"
|
365
|
-
end
|
366
|
-
|
367
|
-
statement
|
368
|
-
end
|
369
|
-
end
|
370
63
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require_relative '../test_helper'
|
2
2
|
|
3
|
+
require 'timeout'
|
4
|
+
|
3
5
|
class TestAsyncRunnner
|
4
6
|
include Rubee::Asyncable
|
5
7
|
|
@@ -17,16 +19,18 @@ describe 'TestAsyncRunnner' do
|
|
17
19
|
|
18
20
|
subject do
|
19
21
|
5.times do |n|
|
20
|
-
TestAsyncRunnner.new.perform_async(options: {"email"=> "new#{n}@new.com", "password"=> "123"})
|
22
|
+
TestAsyncRunnner.new.perform_async(options: { "email" => "new#{n}@new.com", "password" => "123" })
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
26
|
it 'creates 5 users' do
|
25
|
-
|
26
|
-
|
27
|
+
subject
|
28
|
+
|
29
|
+
Timeout.timeout(1) do
|
30
|
+
sleep(0.05) until User.count == 5
|
31
|
+
end
|
27
32
|
|
28
|
-
|
29
|
-
# TODO
|
33
|
+
assert_equal 5, User.count
|
30
34
|
end
|
31
35
|
end
|
32
36
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class BaseControllerTest < Minitest::Test
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
def app
|
7
|
+
Rubee::Application.instance
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_retrieve_image
|
11
|
+
get('/images/rubee.svg')
|
12
|
+
|
13
|
+
assert_equal(200, last_response.status, "Unexpected response: #{last_response.body}")
|
14
|
+
refute_equal('Image not found', last_response.body, "Unexpected response: #{last_response.body}")
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_retrieve_non_existant_image
|
18
|
+
get('/images/rubee2.svg')
|
19
|
+
|
20
|
+
assert_equal(200, last_response.status, "Unexpected response: #{last_response.body}")
|
21
|
+
assert_equal('Image not found', last_response.body, "Unexpected response: #{last_response.body}")
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,220 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class TestResponder
|
4
|
+
def call
|
5
|
+
true
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class TestFailResponder
|
10
|
+
def call
|
11
|
+
false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class TestHookable
|
16
|
+
include Rubee::Hookable
|
17
|
+
|
18
|
+
attr_accessor :value, :glue, :varty
|
19
|
+
|
20
|
+
before :before_around_after, :set_value
|
21
|
+
around :before_around_after, :set_around
|
22
|
+
after :before_around_after, :set_glue
|
23
|
+
|
24
|
+
before :before_after_around, :set_value
|
25
|
+
after :before_after_around, :set_glue
|
26
|
+
around :before_after_around, :set_around
|
27
|
+
|
28
|
+
around :around_before_after, :set_around
|
29
|
+
before :around_before_after, :set_value
|
30
|
+
after :around_before_after, :set_glue
|
31
|
+
|
32
|
+
around :around_after_before, :set_around
|
33
|
+
after :around_after_before, :set_glue
|
34
|
+
before :around_after_before, :set_value
|
35
|
+
|
36
|
+
after :after_around_before, :set_glue
|
37
|
+
around :after_around_before, :set_around
|
38
|
+
before :after_around_before, :set_value
|
39
|
+
|
40
|
+
after :after_before_around, :set_glue
|
41
|
+
before :after_before_around, :set_value
|
42
|
+
around :after_before_around, :set_around
|
43
|
+
|
44
|
+
# With responder conditions
|
45
|
+
after :set_if_condition, :set_glue, if: TestResponder.new
|
46
|
+
after :set_unless_condition, :set_glue, unless: TestResponder.new
|
47
|
+
|
48
|
+
around :failed_around, :set_value, if: TestFailResponder.new
|
49
|
+
around :success_around, TestResponder.new
|
50
|
+
|
51
|
+
# With local conditional
|
52
|
+
before :prep_if_condition, :set_value
|
53
|
+
after :set_if_condition, :set_glue, if: :value_red
|
54
|
+
before :prep_unless_condition, :set_value
|
55
|
+
after :set_unless_condition, :set_glue, unless: :value_red
|
56
|
+
|
57
|
+
def after_around_before; end
|
58
|
+
|
59
|
+
def before_around_after; end
|
60
|
+
|
61
|
+
def around_before_after; end
|
62
|
+
|
63
|
+
def after_before_around; end
|
64
|
+
|
65
|
+
def before_after_around; end
|
66
|
+
|
67
|
+
def around_after_before; end
|
68
|
+
|
69
|
+
def prep_if_condition; end
|
70
|
+
|
71
|
+
def set_if_condition; end
|
72
|
+
|
73
|
+
def prep_unless_condition; end
|
74
|
+
|
75
|
+
def set_unless_condition; end
|
76
|
+
|
77
|
+
def failed_around; end
|
78
|
+
|
79
|
+
def success_around; end
|
80
|
+
|
81
|
+
def value_red
|
82
|
+
value == 'red'
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def set_value
|
88
|
+
@value = 'red'
|
89
|
+
end
|
90
|
+
|
91
|
+
def set_glue
|
92
|
+
@glue = 'white'
|
93
|
+
end
|
94
|
+
|
95
|
+
def set_around
|
96
|
+
@varty = 'something'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe 'Hookable Controller' do
|
101
|
+
describe 'combinations of order' do
|
102
|
+
it 'does not have anything called' do
|
103
|
+
hookable = TestHookable.new
|
104
|
+
|
105
|
+
_(hookable.value).must_be_nil
|
106
|
+
_(hookable.glue).must_be_nil
|
107
|
+
_(hookable.varty).must_be_nil
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'before_around_after' do
|
111
|
+
skip 'not implemented'
|
112
|
+
hookable = TestHookable.new
|
113
|
+
hookable.before_around_after
|
114
|
+
|
115
|
+
_(hookable.value).must_equal('red')
|
116
|
+
_(hookable.glue).must_equal('white')
|
117
|
+
_(hookable.varty).must_equal('something')
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'before_after_around' do
|
121
|
+
skip 'not implemented'
|
122
|
+
hookable = TestHookable.new
|
123
|
+
hookable.before_after_around
|
124
|
+
|
125
|
+
_(hookable.value).must_equal('red')
|
126
|
+
_(hookable.glue).must_equal('white')
|
127
|
+
_(hookable.varty).must_equal('something')
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'around_before_after' do
|
131
|
+
hookable = TestHookable.new
|
132
|
+
hookable.around_before_after
|
133
|
+
|
134
|
+
_(hookable.value).must_equal('red')
|
135
|
+
_(hookable.glue).must_equal('white')
|
136
|
+
_(hookable.varty).must_equal('something')
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'around_after_before' do
|
140
|
+
hookable = TestHookable.new
|
141
|
+
hookable.around_after_before
|
142
|
+
|
143
|
+
_(hookable.value).must_equal('red')
|
144
|
+
_(hookable.glue).must_equal('white')
|
145
|
+
_(hookable.varty).must_equal('something')
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'after_around_before' do
|
149
|
+
skip 'not implemented'
|
150
|
+
hookable = TestHookable.new
|
151
|
+
hookable.after_around_before
|
152
|
+
|
153
|
+
_(hookable.value).must_equal('red')
|
154
|
+
_(hookable.glue).must_equal('white')
|
155
|
+
_(hookable.varty).must_equal('something')
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'after_before_around' do
|
159
|
+
skip "This test is not implemented yet"
|
160
|
+
hookable = TestHookable.new
|
161
|
+
hookable.after_before_around
|
162
|
+
|
163
|
+
_(hookable.value).must_equal('red')
|
164
|
+
_(hookable.glue).must_equal('white')
|
165
|
+
_(hookable.varty).must_equal('something')
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe 'conditions' do
|
170
|
+
it 'does not set glue if condition' do
|
171
|
+
hookable = TestHookable.new
|
172
|
+
|
173
|
+
hookable.set_if_condition
|
174
|
+
|
175
|
+
_(hookable.value).must_be_nil
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'does set glue if condition' do
|
179
|
+
hookable = TestHookable.new
|
180
|
+
|
181
|
+
hookable.prep_if_condition
|
182
|
+
hookable.set_if_condition
|
183
|
+
|
184
|
+
_(hookable.value).must_equal('red')
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'does not set glue if condition' do
|
188
|
+
hookable = TestHookable.new
|
189
|
+
|
190
|
+
hookable.set_unless_condition
|
191
|
+
|
192
|
+
_(hookable.value).must_be_nil
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'does set glue if condition' do
|
196
|
+
hookable = TestHookable.new
|
197
|
+
|
198
|
+
hookable.prep_unless_condition
|
199
|
+
hookable.set_unless_condition
|
200
|
+
|
201
|
+
_(hookable.value).must_equal('red')
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'checks around for failure' do
|
205
|
+
hookable = TestHookable.new
|
206
|
+
|
207
|
+
hookable.failed_around
|
208
|
+
|
209
|
+
_(hookable.glue).must_be_nil
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'checks around success' do
|
213
|
+
hookable = TestHookable.new
|
214
|
+
|
215
|
+
hookable.success_around
|
216
|
+
|
217
|
+
_(hookable.glue).must_be_nil
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative 'test_helper'
|
1
|
+
require_relative '../test_helper'
|
2
2
|
|
3
3
|
class RubeeAppTest < Minitest::Test
|
4
4
|
include Rack::Test::Methods
|
@@ -8,6 +8,7 @@ class RubeeAppTest < Minitest::Test
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_welcome_route
|
11
|
+
skip "This test fails intermittently"
|
11
12
|
get('/')
|
12
13
|
|
13
14
|
assert_equal(200, last_response.status, "Unexpected response: #{last_response.body}")
|