Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
kaplanelad authored Dec 17, 2024
2 parents ef0d9e3 + 1e20bb1 commit da42aa0
Show file tree
Hide file tree
Showing 107 changed files with 5,560 additions and 1,581 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/loco-rs-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ jobs:
permissions:
contents: read

services:
postgres:
image: postgres
env:
POSTGRES_DB: postgres_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- "5432:5432"
# Set health checks to wait until postgres has started
options: --health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Checkout the code
uses: actions/checkout@v4
Expand All @@ -58,3 +73,5 @@ jobs:
with:
command: test
args: --all-features --workspace --exclude loco-gen --exclude loco
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres_test
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@

## Unreleased

* feat: `cargo loco routes` will now pretty-print routes
* fix: guard jwt error behind feature flag. [https://github.com/loco-rs/loco/pull/1032](https://github.com/loco-rs/loco/pull/1032)
* fix: logger file_appender not using the seperated format setting. [https://github.com/loco-rs/loco/pull/1036](https://github.com/loco-rs/loco/pull/1036)
* seed cli command. [https://github.com/loco-rs/loco/pull/1046](https://github.com/loco-rs/loco/pull/1046)
* Updated validator to 0.19. [https://github.com/loco-rs/loco/pull/993](https://github.com/loco-rs/loco/pull/993)
* Testing helpers: simplified function calls + adding html selector. [https://github.com/loco-rs/loco/pull/1047](https://github.com/loco-rs/loco/pull/1047)
### Breaking Changes
#### Updated Import Paths
The testing module import path has been updated. To adapt your code, update imports from:
```rust
use loco_rs::testing;
```
to:
```rust
use testing::prelude::*;
```
#### Simplified Function Calls
Function calls within the testing module no longer require the testing:: prefix. Update your code accordingly. For example:

Before:
```rust
let boot = testing::boot_test::<App>().await.unwrap();
```

After:
```rust
let boot = boot_test::<App>().await.unwrap();
```
* implement commands to manage background jobs. [https://github.com/loco-rs/loco/pull/1071](https://github.com/loco-rs/loco/pull/1071)


## v0.13.2

* static fallback now returns 200 and not 404 [https://github.com/loco-rs/loco/pull/991](https://github.com/loco-rs/loco/pull/991)
Expand Down
11 changes: 9 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,19 @@ Just clone the project and run `cargo test`.
You can see how we test in [.github/workflows](.github/workflows/)

#### Snapshots
To update/create a snapshots we are using [insta](https://github.com/mitsuhiko/insta). all you need to do is install insta (cargo install cargo-insta) and run the following command:
We use [insta](https://github.com/mitsuhiko/insta) for snapshot testing, which helps us detect changes in output formats and behavior. To work with snapshots:

1. Install the insta CLI tool:
```sh
cargo install cargo-insta
```

2. Run tests and review/update snapshots:
```sh
cargo insta test --review
```

In case of cli changes we snapshot the binary commands. in case of changes run the following command yo update the CLI snapshot
For CLI-related changes, we maintain separate snapshots of binary command outputs. To update these CLI snapshots:
```sh
LOCO_CI_MODE=true TRYCMD=overwrite cargo test
```
Expand Down
22 changes: 20 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ default = [
]
auth_jwt = ["dep:jsonwebtoken"]
cli = ["dep:clap"]
testing = ["dep:axum-test"]
testing = ["dep:axum-test", "dep:scraper"]
with-db = ["dep:sea-orm", "dep:sea-orm-migration", "loco-gen/with-db"]
# Storage features
all_storage = ["storage_aws_s3", "storage_azure", "storage_gcp"]
Expand All @@ -45,6 +45,8 @@ cache_inmem = ["dep:moka"]
bg_redis = ["dep:rusty-sidekiq", "dep:bb8"]
bg_pg = ["dep:sqlx", "dep:ulid"]
bg_sqlt = ["dep:sqlx", "dep:ulid"]
## Testing feature flags
integration_test = []

[dependencies]
loco-gen = { version = "0.13.2", path = "./loco-gen" }
Expand All @@ -53,6 +55,13 @@ backtrace_printer = { version = "1.3.0" }
# cli
clap = { version = "4.4.7", features = ["derive"], optional = true }
colored = "2"
reqwest = { version = "0.12.7", features = [
"charset",
"http2",
"json",
"macos-system-configuration",
"rustls-tls",
], default-features = false }


sea-orm = { version = "1.1.0", features = [
Expand Down Expand Up @@ -104,7 +113,7 @@ byte-unit = "4.0.19"
argon2 = { version = "0.5.2", features = ["std"] }
rand = { version = "0.8.5", features = ["std"] }
jsonwebtoken = { version = "9.3.0", optional = true }
validator = { version = "0.18.1", features = ["derive"] }
validator = { version = "0.19.0", features = ["derive"] }
futures-util = "0.3"
tower = { workspace = true }
hyper = "1.1"
Expand Down Expand Up @@ -143,6 +152,8 @@ ulid = { version = "1", optional = true }
rusty-sidekiq = { version = "0.11.0", default-features = false, optional = true }
bb8 = { version = "0.8.1", optional = true }

scraper = { version = "0.21.0", optional = true }

[workspace.dependencies]

chrono = { version = "0.4", features = ["serde"] }
Expand Down Expand Up @@ -188,3 +199,10 @@ tree-fs = { version = "0.2.1" }
reqwest = { version = "0.12.7" }
serial_test = "3.1.1"
tower = { workspace = true, features = ["util"] }
sqlx = { version = "0.8.2", default-features = false, features = [
"macros",
"json",
"postgres",
"chrono",
"sqlite",
] }
13 changes: 9 additions & 4 deletions README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<h3>
<!-- <snip id="description" inject_from="yaml"> -->
🚂 *Loco* - Rust on Rails.
🚂 Loco is Rust on Rails.
<!--</snip> -->
</h3>

Expand Down Expand Up @@ -45,7 +45,7 @@
<!-- <snip id="quick-installation-command" inject_from="yaml" template="sh"> -->
```sh
cargo install loco
cargo install sea-orm-cli # Для работы с базами данных
cargo install sea-orm-cli # Only when DB is needed
```
<!-- </snip> -->

Expand All @@ -56,13 +56,18 @@ cargo install sea-orm-cli # Для работы с базами данных
```sh
❯ loco new
✔ ❯ App name? · myapp
✔ ❯ What would you like to build? · SaaS app (with DB and user auth)
✔ ❯ What would you like to build? · Saas App with client side rendering
✔ ❯ Select a DB Provider · Sqlite
✔ ❯ Select your background worker type · Async (in-process tokio async tasks)
✔ ❯ Select an asset serving configuration · Client (configures assets for frontend serving)

🚂 Loco app generated successfully in:
myapp/

- assets: You've selected `clientside` for your asset serving configuration.
Next step, build your frontend:
$ cd frontend/
$ npm install && npm run build
```
<!-- </snip> -->
Expand Down
4 changes: 2 additions & 2 deletions docs-site/config.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# The URL the site will be built for
base_url = "https://loco.rs"
title = "Loco"
description = "Loco is a productivity-first web and service framework in Rust"
title = "Loco.rs - Productivity-first Rust Fullstack Web Framework"
description = "Loco.rs is like Ruby on Rails for Rust. Use it to quickly build and deploy Rust based apps from zero to production."


# Whether to automatically compile all Sass files in the sass directory
Expand Down
2 changes: 1 addition & 1 deletion docs-site/content/casts/003-scaffolding-crud-with-html.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ id = "EircfwF8c0E"

Reference material for this episode:

* Loco.rs docs: [routes in controllers](https://loco.rs/docs/getting-started/scaffold/)
* Loco.rs docs: [routes in controllers](https://loco.rs/docs/the-app/controller/#routes-in-controllers)
* The [SaaS starter](https://loco.rs/docs/starters/saas/)
* The [REST API starter](https://loco.rs/docs/starters/rest-api/)
8 changes: 4 additions & 4 deletions docs-site/content/casts/005-testing-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ id = "485JlLA-T6U"

Reference material for this episode:

* Loco.rs docs: [routes in controllers](https://loco.rs/docs/the-app/task/)
* The [SaaS starter](https://loco.rs/docs/starters/saas/)
* The [REST API starter](https://loco.rs/docs/starters/rest-api/)
* The [Lightweight starter](https://loco.rs/docs/starters/service/)
* Loco.rs docs: [routes in controllers](https://loco.rs/docs/processing/task/)
* The [SaaS starter](https://loco.rs/docs/getting-started/starters/#saas-starter)
* The [REST API starter](https://loco.rs/docs/getting-started/starters/#rest-api-starter)
* The [Lightweight starter](https://loco.rs/docs/getting-started/starters/#lightweight-service-starter)
2 changes: 1 addition & 1 deletion docs-site/content/casts/006-mailers.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ id = "ieGeihxLGC8"

Reference material for this episode:

* Loco.rs docs: [Mailers](https://loco.rs/docs/the-app/mailers/)
* Loco.rs docs: [Mailers](https://loco.rs/docs/processing/mailers/)
34 changes: 15 additions & 19 deletions docs-site/content/docs/getting-started/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,7 @@ pub async fn list(State(ctx): State<AppContext>) -> Result<Response> {
}

pub async fn add(State(ctx): State<AppContext>, Json(params): Json<Params>) -> Result<Response> {
let mut item = ActiveModel {
..Default::default()
};
let mut item: ActiveModel = Default::default();
params.update(&mut item);
let item = item.insert(&ctx.db).await?;
format::json(item)
Expand Down Expand Up @@ -586,7 +584,7 @@ pub fn routes() -> Routes {
.add("/", post(add))
.add("/:id", get(get_one))
.add("/:id", delete(remove))
.add("/:id", post(update))
.add("/:id", patch(update))
}
```
Expand Down Expand Up @@ -678,7 +676,7 @@ pub fn routes() -> Routes {
// .add("/", get(list))
// .add("/:id", get(get_one))
// .add("/:id", delete(remove))
// .add("/:id", post(update))
// .add("/:id", patch(update))
}
```
Expand Down Expand Up @@ -800,6 +798,8 @@ use loco_rs::task::Vars;
use crate::models::users;
pub struct UserReport;
#[async_trait]
impl Task for UserReport {
fn task(&self) -> TaskInfo {
Expand Down Expand Up @@ -855,9 +855,7 @@ Go back to `src/controllers/comments.rs` and take a look at the `add` function:
```rust
pub async fn add(State(ctx): State<AppContext>, Json(params): Json<Params>) -> Result<Response> {
let mut item = ActiveModel {
..Default::default()
};
let mut item: ActiveModel = Default::default();
params.update(&mut item);
let item = item.insert(&ctx.db).await?;
format::json(item)
Expand All @@ -872,16 +870,14 @@ async fn add(
State(ctx): State<AppContext>,
Json(params): Json<Params>,
) -> Result<Response> {
// we only want to make sure it exists
let _current_user = crate::models::users::Model::find_by_pid(&ctx.db, &auth.claims.pid).await?;

// next, update
// homework/bonus: make a comment _actually_ belong to user (user_id)
let mut item = ActiveModel {
..Default::default()
};
params.update(&mut item);
let item = item.insert(&ctx.db).await?;
format::json(item)
// we only want to make sure it exists
let _current_user = crate::models::users::Model::find_by_pid(&ctx.db, &auth.claims.pid).await?;

// next, update
// homework/bonus: make a comment _actually_ belong to user (user_id)
let mut item: ActiveModel = Default::default();
params.update(&mut item);
let item = item.insert(&ctx.db).await?;
format::json(item)
}
```
4 changes: 3 additions & 1 deletion docs-site/content/docs/infrastructure/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,12 @@ async fn upload_file(
By testing file storage in your controller you can follow this example:

```rust
use loco_rs::testing::prelude::*;

#[tokio::test]
#[serial]
async fn can_register() {
testing::request::<App, _, _>(|request, ctx| async move {
request::<App, _, _>(|request, ctx| async move {
let file_content = "loco file upload";
let file_part = Part::bytes(file_content.as_bytes()).file_name("loco.txt");

Expand Down
5 changes: 3 additions & 2 deletions docs-site/content/docs/processing/mailers.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,19 @@ Test Description:
- Retrieve the mailer instance from the context and call the deliveries() function, which contains information about the number of sent emails and their content.

```rust
use loco_rs::testing::prelude::*;
#[tokio::test]
#[serial]
async fn can_register() {
configure_insta!();
testing::request::<App, Migrator, _, _>(|request, ctx| async move {
request::<App, Migrator, _, _>(|request, ctx| async move {
// Create a request for user registration.
// Now you can call the context mailer and use the deliveries function.
with_settings!({
filters => testing::cleanup_email()
filters => cleanup_email()
}, {
assert_debug_snapshot!(ctx.mailer.unwrap().deliveries());
});
Expand Down
12 changes: 11 additions & 1 deletion docs-site/content/docs/processing/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,17 @@ Generate the task:

<!-- <snip id="generate-task-help-command" inject_from="yaml" action="exec" template="sh"> -->
```sh
cd ./examples/demo && cargo loco generate task --help
Generate a Task based on the given name

Usage: demo_app-cli generate task [OPTIONS] <NAME>

Arguments:
<NAME> Name of the thing to generate

Options:
-e, --environment <ENVIRONMENT> Specify the environment [default: development]
-h, --help Print help
-V, --version Print version
```
<!-- </snip> -->

Expand Down
Loading

0 comments on commit da42aa0

Please sign in to comment.