This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:info_neon: Chuyên mục MIL - Monday I learn - 011 | |
Cách sử dụng `with` cùng với `allow` và `allow_any_instance_of`. | |
Dạng allow(A).to receive(:method).and_return some_thing | |
Có ý nghĩa: Khi gọi method với bất kì tham số nào thì sẽ trả về some_thing | |
Dạng allow(A).to receive(:method).with(:some_params).and_return some_thing | |
Có ý nghĩa: Khi gọi method với param cụ thể :some_params thì sẽ trả về some_thing | |
Nếu truyền sai tham số thì sẽ bị raise lỗi. | |
`Please stub a default value first if message might be received with other args as well.` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:info_neon: Chuyên mục MIL - Monday I learn - 012 | |
Một chút tin tức mới về rails 7.1 | |
1. Github vừa mới public một Mysql client đang được sử dụng trong Github và nó đã được thêm vào rails. Bạn có thể sử dựng nó thay thế cho mysql2. | |
"Trilogy is a client library for MySQL-compatible database servers, designed for performance, flexibility, and ease of embedding." | |
Ref: https://github.com/rails/rails/pull/47880 | |
2. Thay đổi cách validate độ dài password với BCrypt. Trước sử dụng count kí tự điều này có thể không thoả mãn validate phía BCrypt là 72 byte. Sau chuyển thành kiểm tra theo byte và thêm một key cho I18n `:password_too_long`. | |
"This Pull Request has been created because we identified a need to improve password length validation for BCrypt compatibility in the ActiveModel::SecurePassword module. The current validation only considers the character count, which may not accurately reflect the byte size limit imposed by BCrypt." | |
Ref: https://github.com/rails/rails/pull/47708 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:info_neon: Chuyên mục MIL - Monday I learn - 013 | |
Nhân tiện mượn được a Vượng cuốn sách Làm chủ các mẫu thiết kế kinh điển trong lập trình của tác giả Tạ Văn Dũng thì em cũng mang tới chương trình làm chủ các mẫu thiết kế trong 1 ngày. (Just for funs) | |
Singleton pattern - pattern thuộc vào nhóm khởi tạo. | |
Nó được nghĩ ra để giúp đảm bảo một class chỉ có một object instance duy nhất và là nơi truy cập duy nhất trong hệ thống. | |
Ví dụ thực tế: | |
Trong ứng dụng Rails có nhiều loại connection DB, Redis, ... thì chúng ta không thể cứ mỗi lần dùng lại khởi tạo một object DB, Redis để dùng. Việc này sẽ tốn tài nguyên và hiệu suất không cao. Do đó chúng ta có thể nghĩ ngay tới Singleton pattern để giải quyết vấn đề này. | |
Có một số lưu ý khi sử dụng Singleton: Race condition - nói nom na là việc ứng dụng chạy nhiều thread đồng thời và cùng truy cập tới tài nguyên chung. Nếu implement pattern không tốt thì 1 class có thể có nhiều hơn 1 object. |
OlderNewer