ru.Bee 1.10.0 → 1.10.1
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/lib/rubee/cli/test.rb +57 -1
- data/lib/rubee.rb +1 -1
- data/lib/tests/logger_test.rb +6 -0
- data/lib/tests/test.db +0 -0
- data/readme.md +28 -20
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e34bf9669d522ca579263e0ea388b8157f443f362991a36b7e76b73b69d49467
|
4
|
+
data.tar.gz: a58a62af03a502867bbd61316b4983a2114dc2d5a64e5744941c3bcb03776c70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0e8688ef9c4c8ae50552e5db73964ae477b036383eb10cf7194df7edf31b58f7e9fb143689e61f6445750933d9dec9815ffd7e67d0cd0cf684df96b90fd9df3
|
7
|
+
data.tar.gz: ea6871cf13344b5d235eff69b7fc6df7cd98e9061aeaa593b682b9a35071f73a7dad8a5012778bf55a64b8f1ef49ffdc4ad49cc6bf702cbacfa39410a1f2368c
|
data/lib/rubee/cli/test.rb
CHANGED
@@ -9,15 +9,71 @@ module Rubee
|
|
9
9
|
def test(argv)
|
10
10
|
ENV['RACK_ENV'] = 'test'
|
11
11
|
file_name = argv[1] # Get the first argument
|
12
|
+
line = argv[2]&.start_with?('--line=') ? argv[2].split('=')[1] : nil
|
12
13
|
lib = Rubee::PROJECT_NAME == 'rubee' ? '/lib' : ''
|
13
|
-
if file_name
|
14
|
+
if file_name && !line
|
14
15
|
color_puts("Running #{file_name} test ...", color: :yellow)
|
15
16
|
exec("ruby -Itest -e \"require '.#{lib}/tests/#{file_name}'\"")
|
17
|
+
elsif file_name && line
|
18
|
+
color_puts("Running #{file_name} test at line #{line} ...", color: :yellow)
|
19
|
+
test_name = find_test_at_line(".#{lib}/tests/#{file_name}", line)
|
20
|
+
exec("ruby -Itest .#{lib}/tests/#{file_name} -n #{test_name}")
|
16
21
|
else
|
17
22
|
color_puts('Running all tests ...', color: :yellow)
|
18
23
|
exec("ruby -Itest -e \"Dir.glob('.#{lib}/tests/**/*_test.rb').each { |file| require file }\"")
|
19
24
|
end
|
20
25
|
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def find_test_at_line(file, line)
|
30
|
+
source = File.read(file).lines
|
31
|
+
name = nil
|
32
|
+
kind = nil
|
33
|
+
|
34
|
+
# 1. Look backwards from the line
|
35
|
+
source[0...line.to_i].reverse_each do |l|
|
36
|
+
if l =~ /^\s*def\s+(test_\w+)/
|
37
|
+
name = ::Regexp.last_match(1)
|
38
|
+
kind = :method
|
39
|
+
break
|
40
|
+
elsif l =~ /^\s*describe\s+['"](.*)['"]/
|
41
|
+
name = ::Regexp.last_match(1)
|
42
|
+
kind = :spec
|
43
|
+
break
|
44
|
+
elsif l =~ /^\s*it\s+['"](.*)['"]/
|
45
|
+
name = ::Regexp.last_match(1)
|
46
|
+
kind = :spec
|
47
|
+
break
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# 2. If nothing was found, fallback to first def/it in the file
|
52
|
+
if name.nil?
|
53
|
+
source.each do |l|
|
54
|
+
if l =~ /^\s*def\s+(test_\w+)/
|
55
|
+
name = ::Regexp.last_match(1)
|
56
|
+
kind = :method
|
57
|
+
break
|
58
|
+
elsif l =~ /^\s*describe\s+['"](.*)['"]/
|
59
|
+
name = ::Regexp.last_match(1)
|
60
|
+
kind = :spec
|
61
|
+
break
|
62
|
+
elsif l =~ /^\s*it\s+['"](.*)['"]/
|
63
|
+
name = ::Regexp.last_match(1)
|
64
|
+
kind = :spec
|
65
|
+
break
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# 3. Return correct `-n` filter
|
71
|
+
if kind == :spec
|
72
|
+
"/#{Regexp.escape(name)}/"
|
73
|
+
else
|
74
|
+
name
|
75
|
+
end
|
76
|
+
end
|
21
77
|
end
|
22
78
|
end
|
23
79
|
end
|
data/lib/rubee.rb
CHANGED
@@ -16,7 +16,7 @@ module Rubee
|
|
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
18
|
ROOT_PATH = File.expand_path(File.join(__dir__, '..')) unless defined?(ROOT_PATH)
|
19
|
-
VERSION = '1.10.
|
19
|
+
VERSION = '1.10.1'
|
20
20
|
|
21
21
|
require_relative 'rubee/router'
|
22
22
|
require_relative 'rubee/logger'
|
data/lib/tests/logger_test.rb
CHANGED
@@ -19,12 +19,14 @@ end
|
|
19
19
|
describe 'Rubee::Logger' do
|
20
20
|
describe 'logger' do
|
21
21
|
it 'exists' do
|
22
|
+
puts "logger exists"
|
22
23
|
_(Rubee::Logger).wont_be_nil
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
27
|
describe '.warn' do
|
27
28
|
it 'output message' do
|
29
|
+
puts "warn output message"
|
28
30
|
output = capture_stdout { Rubee::Logger.warn(message: 'test') }
|
29
31
|
|
30
32
|
assert_includes(output, "WARN test")
|
@@ -33,6 +35,7 @@ describe 'Rubee::Logger' do
|
|
33
35
|
|
34
36
|
describe '.info' do
|
35
37
|
it 'output message' do
|
38
|
+
puts "info output message"
|
36
39
|
output = capture_stdout { Rubee::Logger.info(message: 'test') }
|
37
40
|
|
38
41
|
assert_includes(output, "INFO test")
|
@@ -49,6 +52,7 @@ describe 'Rubee::Logger' do
|
|
49
52
|
|
50
53
|
describe '.critical' do
|
51
54
|
it 'output message' do
|
55
|
+
puts "critical output message"
|
52
56
|
output = capture_stdout { Rubee::Logger.critical(message: 'test') }
|
53
57
|
|
54
58
|
assert_includes(output, "CRITICAL test")
|
@@ -57,6 +61,7 @@ describe 'Rubee::Logger' do
|
|
57
61
|
|
58
62
|
describe '.debug' do
|
59
63
|
it 'output message' do
|
64
|
+
puts "debug output message"
|
60
65
|
output = capture_stdout { Rubee::Logger.debug(object: User.new(email: 'ok@ok.com', password: 123)) }
|
61
66
|
|
62
67
|
assert_includes(output, "DEBUG #<User:")
|
@@ -65,6 +70,7 @@ describe 'Rubee::Logger' do
|
|
65
70
|
|
66
71
|
describe 'when custom logger defined in the configuration' do
|
67
72
|
it 'uses custom logger' do
|
73
|
+
puts "CUSTOM INFO test"
|
68
74
|
Rubee::Configuration.setup(env = :test) { _1.logger = { logger: CustomLogger, env: } }
|
69
75
|
|
70
76
|
output = capture_stdout { Rubee::Logger.info(message: 'test') }
|
data/lib/tests/test.db
CHANGED
Binary file
|
data/readme.md
CHANGED
@@ -164,7 +164,9 @@ rubee test models/user_model_test.rb
|
|
164
164
|
attributes: [
|
165
165
|
{ name: 'id', type: :primary },
|
166
166
|
{ name: 'colour', type: :string },
|
167
|
-
{ name: 'weight', type: :integer }
|
167
|
+
{ name: 'weight', type: :integer },
|
168
|
+
{ name: 'created', type: :datetime },
|
169
|
+
{ name: 'updated', type: :datetime },
|
168
170
|
]
|
169
171
|
}
|
170
172
|
end
|
@@ -251,7 +253,7 @@ irb(main):015> user = User.new(email: "llo@ok.com", password: 543)
|
|
251
253
|
|
252
254
|
Save record in db
|
253
255
|
```Ruby
|
254
|
-
=> #<User:0x000000010cda23b8 @email="llo@ok.com", @password=543>
|
256
|
+
=> #<User:0x000000010cda23b8 @email="llo@ok.com", @password=543, @created="2025-09-28 22:03:07.011332 -0400", @updated="2025-09-28 22:03:07.011332 -0400">
|
255
257
|
irb(main):018> user.save
|
256
258
|
=> true
|
257
259
|
```
|
@@ -259,7 +261,7 @@ irb(main):018> user.save
|
|
259
261
|
Update record with new value
|
260
262
|
```Ruby
|
261
263
|
irb(main):019> user.update(email: "update@email.com")
|
262
|
-
=> #<User:0x000000010c39b298 @email="update@email.com", @id=3, @password="543">
|
264
|
+
=> #<User:0x000000010c39b298 @email="update@email.com", @id=3, @password="543" @created="2025-09-28 22:03:07.011332 -0400", @updated="2025-09-28 22:03:07.011332 -0400">
|
263
265
|
```
|
264
266
|
|
265
267
|
Check whether it includes id
|
@@ -273,13 +275,13 @@ irb(main):016> user.persisted?
|
|
273
275
|
Get the record from the database
|
274
276
|
```Ruby
|
275
277
|
irb(main):011> user = User.last
|
276
|
-
=> #<User:0x000000010ccea178 @email="ok23@ok.com", @id=2, @password="123">
|
278
|
+
=> #<User:0x000000010ccea178 @email="ok23@ok.com", @id=2, @password="123", @created="2025-09-28 22:03:07.011332 -0400", @updated="2025-09-28 22:03:07.011332 -0400">
|
277
279
|
irb(main):012> user.email = "new@ok.com"
|
278
280
|
=> "new@ok.com"
|
279
281
|
irb(main):013> user
|
280
|
-
=> #<User:0x000000010ccea178 @email="new@ok.com", @id=2, @password="123">
|
282
|
+
=> #<User:0x000000010ccea178 @email="new@ok.com", @id=2, @password="123", @created="2025-09-28 22:03:07.011332 -0400", @updated="2025-09-28 22:03:07.011332 -0400">
|
281
283
|
irb(main):014> user.reload
|
282
|
-
=> #<User:0x000000010c488548 @email="ok23@ok.com", @id=2, @password="123"> # not persited data was updated from db
|
284
|
+
=> #<User:0x000000010c488548 @email="ok23@ok.com", @id=2, @password="123", @created="2025-09-28 22:03:07.011332 -0400", @updated="2025-09-28 22:03:07.011332 -0400"> # not persited data was updated from db
|
283
285
|
```
|
284
286
|
|
285
287
|
Assign attributes without persisiting it to db
|
@@ -297,24 +299,24 @@ irb(main):005> User.where(email: "ok23@ok.com")
|
|
297
299
|
Get all record
|
298
300
|
```Ruby
|
299
301
|
irb(main):001> User.all
|
300
|
-
=> [#<User:0x000000010c239a30 @email="ok@ok.com", @id=1, @password="password">]
|
302
|
+
=> [#<User:0x000000010c239a30 @email="ok@ok.com", @id=1, @password="password", @created="2025-09-28 22:03:07.011332 -0400", @updated="2025-09-28 22:03:07.011332 -0400">]
|
301
303
|
```
|
302
304
|
Find by id
|
303
305
|
```Ruby
|
304
306
|
irb(main):002> user = User.find 1
|
305
|
-
=> #<User:0x000000010c2f7cd8 @email="ok@ok.com", @id=1, @password="password">
|
307
|
+
=> #<User:0x000000010c2f7cd8 @email="ok@ok.com", @id=1, @password="password", @created="2025-09-28 22:03:07.011332 -0400", @updated="2025-09-28 22:03:07.011332 -0400">
|
306
308
|
```
|
307
309
|
|
308
310
|
Get last record
|
309
311
|
```Ruby
|
310
312
|
irb(main):003> User.last
|
311
|
-
=> #<User:0x000000010c2f7cd8 @email="ok@ok.com", @id=1, @password="password">
|
313
|
+
=> #<User:0x000000010c2f7cd8 @email="ok@ok.com", @id=1, @password="password", @created="2025-09-28 22:03:07.011332 -0400", @updated="2025-09-28 22:03:07.011332 -0400">
|
312
314
|
```
|
313
315
|
|
314
316
|
Create new persited record
|
315
317
|
```Ruby
|
316
318
|
irb(main):004> User.create(email: "ok23@ok.com", password: 123)
|
317
|
-
=> #<User:0x000000010c393818 @email="ok23@ok.com", @id=2, @password=123>
|
319
|
+
=> #<User:0x000000010c393818 @email="ok23@ok.com", @id=2, @password=123, @created="2025-09-28 22:03:07.011332 -0400", @updated="2025-09-28 22:03:07.011332 -0400">
|
318
320
|
```
|
319
321
|
|
320
322
|
Destroy record and all related records
|
@@ -326,7 +328,7 @@ irb(main):021> user.destroy(cascade: true)
|
|
326
328
|
Destroy all records one by one
|
327
329
|
```Ruby
|
328
330
|
irb(main):022> User.destroy_all
|
329
|
-
=> [#<User:0x000000010d42df98 @email="ok@ok.com", @id=1, @password="password">, #<User:0x000000010d42de80 @email="ok23@ok.com", @id=2, @password="123"
|
331
|
+
=> [#<User:0x000000010d42df98 @email="ok@ok.com", @id=1, @password="password", @created="2025-09-28 22:03:07.011332 -0400", @updated="2025-09-28 22:03:07.011332 -0400">, #<User:0x000000010d42de80 @email="ok23@ok.com", @id=2, @password="123", @created="2025-09-28 22:03:07.011332 -0400", @updated="2025-09-28 22:03:07.011332 -0400">>
|
330
332
|
irb(main):023> User.all
|
331
333
|
=> []
|
332
334
|
```
|
@@ -335,19 +337,19 @@ Use complex queries chains and when ready serialize it back to Rubee object.
|
|
335
337
|
```Ruby
|
336
338
|
# user model
|
337
339
|
class User < Rubee::SequelObject
|
338
|
-
attr_accessor :id, :email, :password
|
340
|
+
attr_accessor :id, :email, :password, :created, :updated
|
339
341
|
owns_many :comments, over: :posts
|
340
342
|
end
|
341
343
|
|
342
344
|
# comment model
|
343
345
|
class Comment < Rubee::SequelObject
|
344
|
-
attr_accessor :id, :text, :user_id
|
346
|
+
attr_accessor :id, :text, :user_id, :created, :updated
|
345
347
|
owns_many :users, over: :posts
|
346
348
|
end
|
347
349
|
|
348
|
-
# join post
|
350
|
+
# join post modenl
|
349
351
|
class Post < Rubee::SequelObject
|
350
|
-
attr_accessor :id, :user_id, :comment_id
|
352
|
+
attr_accessor :id, :user_id, :comment_id, :created, :updated
|
351
353
|
holds :comment
|
352
354
|
holds :user
|
353
355
|
end
|
@@ -362,11 +364,11 @@ irb(main):005> post = Post.new(user_id: user.id, comment_id: comment.id)
|
|
362
364
|
irb(main):006> post.save
|
363
365
|
=> true
|
364
366
|
irb(main):007> comment
|
365
|
-
=> #<Comment:0x000000012281a650 @id=21, @text="test">
|
367
|
+
=> #<Comment:0x000000012281a650 @id=21, @text="test", @created=2025-09-28 22:03:07.011332 -0400, @updated=2025-09-28 22:03:07.011332 -0400>
|
366
368
|
irb(main):008> result = Comment.dataset.join(:posts, comment_id: :id)
|
367
369
|
irb(main):009> .where(comment_id: Comment.where(text: "test").last.id)
|
368
370
|
irb(main):010> .then { |dataset| Comment.serialize(dataset) }
|
369
|
-
=> [#<Comment:0x0000000121889998 @id=30, @text="test", @user_id=702>]
|
371
|
+
=> [#<Comment:0x0000000121889998 @id=30, @text="test", @user_id=702, @created=2025-09-28 22:03:07.011332 -0400, @updated=2025-09-28 22:03:07.011332 -0400>]
|
370
372
|
```
|
371
373
|
This is recommended when you want to run one query and serialize it back to Rubee object only once.
|
372
374
|
So it may safe some resources.
|
@@ -432,7 +434,9 @@ Rubee::Router.draw do |router|
|
|
432
434
|
attributes: [
|
433
435
|
{ name: 'id', type: :primary },
|
434
436
|
{ name: 'colour', type: :string },
|
435
|
-
{ name: 'weight', type: :integer }
|
437
|
+
{ name: 'weight', type: :integer },
|
438
|
+
{ name: 'created', type: :datetime },
|
439
|
+
{ name: 'updated', type: :datetime },
|
436
440
|
]
|
437
441
|
}
|
438
442
|
end
|
@@ -527,7 +531,9 @@ Rubee::Router.draw do |router|
|
|
527
531
|
attributes: [
|
528
532
|
{ name: 'id', type: :primary },
|
529
533
|
{ name: 'colour', type: :string },
|
530
|
-
{ name: 'weight', type: :integer }
|
534
|
+
{ name: 'weight', type: :integer },
|
535
|
+
{ name: 'created', type: :datetime },
|
536
|
+
{ name: 'updated', type: :datetime },
|
531
537
|
]
|
532
538
|
}
|
533
539
|
end
|
@@ -571,7 +577,9 @@ Rubee::Router.draw do |router|
|
|
571
577
|
name: 'cabage',
|
572
578
|
attributes: [
|
573
579
|
{ name: 'id', type: :primary },
|
574
|
-
{ name: 'name', type: :string }
|
580
|
+
{ name: 'name', type: :string },
|
581
|
+
{ name: 'created', type: :datetime },
|
582
|
+
{ name: 'updated', type: :datetime },
|
575
583
|
]
|
576
584
|
},
|
577
585
|
namespace: :admin # mandatory option for supporting namespacing
|