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 2, 2024
2 parents 75fd97e + 88bc01e commit ef0d9e3
Show file tree
Hide file tree
Showing 36 changed files with 329 additions and 186 deletions.
1 change: 1 addition & 0 deletions examples/demo/tests/cmd/cli.trycmd
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Commands:
status Migration status
entities Generate entity .rs files from database schema
truncate Truncate data in tables (without dropping)
seed Seed your database with initial data or dump tables to files
help Print this message or the help of the given subcommand(s)

Options:
Expand Down
11 changes: 3 additions & 8 deletions loco-new/base_template/src/app.rs.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use migration::Migrator;
use sea_orm::DatabaseConnection;
{%- endif %}

#[allow(unused_imports)]
use crate::{
controllers
{%- if settings.initializers -%}
Expand Down Expand Up @@ -89,15 +90,9 @@ impl Hooks for App {
{%- endif %}
Ok(())
}
{%- if settings.db %}
#[allow(unused_variables)]
fn register_tasks(tasks: &mut Tasks) {
{%- else %}
fn register_tasks(_tasks: &mut Tasks) {
{%- endif %}
{%- if settings.db %}
tasks.register(tasks::seed::SeedData);
{%- endif %}
// tasks-inject (do not remove)
}
Expand Down
3 changes: 0 additions & 3 deletions loco-new/base_template/src/tasks/mod.rs.t
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
{%- if settings.db %}
pub mod seed;
{%- endif %}
45 changes: 0 additions & 45 deletions loco-new/base_template/src/tasks/seed.rs

This file was deleted.

3 changes: 0 additions & 3 deletions loco-new/base_template/tests/tasks/mod.rs.t
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
{%- if settings.db -%}
pub mod seed;
{%- endif -%}
17 changes: 0 additions & 17 deletions loco-new/base_template/tests/tasks/seed.rs.t

This file was deleted.

4 changes: 1 addition & 3 deletions loco-new/setup.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,15 @@ gen.copy_file("config/production.yaml"); // Production config
// Database-Related Files
// =====================
if db {
gen.copy_template_dir("migration"); // Database migrations directory
gen.copy_template_dir("migration"); // Database migrations directory
gen.copy_dir("src/models"); // Models directory, copied if background enabled
gen.copy_file("src/tasks/seed.rs"); // Task to seed database
gen.copy_dir("src/fixtures"); // Database fixtures directory
gen.copy_template("examples/playground.rs.t"); // Example playground template with DB setup

// Test modules related to database models
gen.copy_file("tests/models/mod.rs"); // Models tests root
gen.copy_dir("tests/models/snapshots"); // Test snapshots for models
gen.copy_template("tests/models/users.rs.t"); // User model test template
gen.copy_template("tests/tasks/seed.rs.t"); // Seed tasks test template
gen.copy_template("tests/requests/prepare_data.rs.t"); // Data preparation template
}

Expand Down
6 changes: 3 additions & 3 deletions loco-new/tests/templates/auth.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::*;

use crate::assertion;
use loco::settings;
use rstest::rstest;

use super::*;
use crate::assertion;

pub fn run_generator(enable_auth: bool) -> TestGenerator {
let settings = settings::Settings {
package_name: "loco-app-test".to_string(),
Expand Down
30 changes: 0 additions & 30 deletions loco-new/tests/templates/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,6 @@ fn test_src_bin_tool_rs(
}
}

#[rstest]
fn test_tasks_mod_rs(#[values(DBOption::None, DBOption::Sqlite, DBOption::Postgres)] db: DBOption) {
let generator = run_generator(db.clone());

let content =
std::fs::read_to_string(generator.path("src/tasks/mod.rs")).expect("could not open file");

if db.enable() {
assertion::string::assert_line_regex(&content, "(?m)^pub mod seed;$");
} else {
assertion::string::assert_str_not_exists(&content, "pub mod seed");
}
}

#[rstest]
fn test_tests_mod_rs(#[values(DBOption::None, DBOption::Sqlite, DBOption::Postgres)] db: DBOption) {
let generator = run_generator(db.clone());
Expand All @@ -149,19 +135,3 @@ fn test_tests_mod_rs(#[values(DBOption::None, DBOption::Sqlite, DBOption::Postgr
assertion::string::assert_str_not_exists(&content, "mod models;");
}
}

#[rstest]
fn test_tests_tasks_mod_rs(
#[values(DBOption::None, DBOption::Sqlite, DBOption::Postgres)] db: DBOption,
) {
let generator = run_generator(db.clone());

let content =
std::fs::read_to_string(generator.path("tests/tasks/mod.rs")).expect("could not open file");

if db.enable() {
assertion::string::assert_line_regex(&content, "(?m)^pub mod seed;$");
} else {
assertion::string::assert_str_not_exists(&content, "pub mod seed");
}
}
4 changes: 2 additions & 2 deletions loco-new/tests/templates/features.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;
use loco::settings;

use super::*;
use crate::assertion;
use loco::settings;

pub fn run_generator(default_features: bool, names: &[&str]) -> TestGenerator {
let settings = settings::Settings {
Expand Down
6 changes: 3 additions & 3 deletions loco-new/tests/templates/initializers.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::*;

use crate::assertion;
use loco::settings;
use rstest::rstest;

use super::*;
use crate::assertion;

pub fn run_generator(initializers: Option<settings::Initializers>) -> TestGenerator {
let settings = settings::Settings {
initializers,
Expand Down
6 changes: 3 additions & 3 deletions loco-new/tests/templates/mailer.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::*;

use crate::assertion;
use loco::settings;
use rstest::rstest;

use super::*;
use crate::assertion;

pub fn run_generator(enable_mailer: bool) -> TestGenerator {
let settings = settings::Settings {
mailer: enable_mailer,
Expand Down
9 changes: 5 additions & 4 deletions loco-new/tests/templates/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::{
path::{Path, PathBuf},
sync::Arc,
};

use loco::{
generator::{self, executer::FileSystem, template},
settings,
};
use rand::{rngs::StdRng, SeedableRng};
use std::{
path::{Path, PathBuf},
sync::Arc,
};

mod asset;
mod auth;
Expand Down
7 changes: 1 addition & 6 deletions loco-new/tests/templates/module_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ fn test_use_name(#[values("src/bin/main.rs", "tests/requests/home.rs")] file: &s

#[rstest]
fn test_use_name_with_db(
#[values(
"tests/models/users.rs",
"tests/requests/prepare_data.rs",
"tests/tasks/seed.rs"
)]
file: &str,
#[values("tests/models/users.rs", "tests/requests/prepare_data.rs")] file: &str,
) {
let generator = super::db::run_generator(DBOption::Sqlite);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: tests/templates/auth.rs
expression: "std::fs::read_to_string(generator.path(\"src/app.rs\")).expect(\"could not open file\")"
snapshot_kind: text
---
use async_trait::async_trait;
use loco_rs::{
Expand All @@ -15,6 +14,7 @@ use loco_rs::{
Result,
};

#[allow(unused_imports)]
use crate::{
controllers,
};
Expand Down Expand Up @@ -51,7 +51,9 @@ impl Hooks for App {
async fn connect_workers(_ctx: &AppContext, _queue: &Queue) -> Result<()> {
Ok(())
}
fn register_tasks(_tasks: &mut Tasks) {

#[allow(unused_variables)]
fn register_tasks(tasks: &mut Tasks) {
// tasks-inject (do not remove)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: tests/templates/auth.rs
expression: "std::fs::read_to_string(generator.path(\"src/app.rs\")).expect(\"could not open file\")"
snapshot_kind: text
---
use async_trait::async_trait;
use loco_rs::{
Expand All @@ -15,6 +14,7 @@ use loco_rs::{
Result,
};

#[allow(unused_imports)]
use crate::{
controllers,
};
Expand Down Expand Up @@ -51,7 +51,9 @@ impl Hooks for App {
async fn connect_workers(_ctx: &AppContext, _queue: &Queue) -> Result<()> {
Ok(())
}
fn register_tasks(_tasks: &mut Tasks) {

#[allow(unused_variables)]
fn register_tasks(tasks: &mut Tasks) {
// tasks-inject (do not remove)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: tests/templates/background.rs
expression: "std::fs::read_to_string(generator.path(\"src/app.rs\")).expect(\"could not open file\")"
snapshot_kind: text
---
use async_trait::async_trait;
use loco_rs::{
Expand All @@ -16,6 +15,7 @@ use loco_rs::{
Result,
};

#[allow(unused_imports)]
use crate::{
controllers
, workers::downloader::DownloadWorker,
Expand Down Expand Up @@ -54,7 +54,9 @@ impl Hooks for App {
queue.register(DownloadWorker::build(ctx)).await?;
Ok(())
}
fn register_tasks(_tasks: &mut Tasks) {

#[allow(unused_variables)]
fn register_tasks(tasks: &mut Tasks) {
// tasks-inject (do not remove)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: tests/templates/background.rs
expression: "std::fs::read_to_string(generator.path(\"src/app.rs\")).expect(\"could not open file\")"
snapshot_kind: text
---
use async_trait::async_trait;
use loco_rs::{
Expand All @@ -16,6 +15,7 @@ use loco_rs::{
Result,
};

#[allow(unused_imports)]
use crate::{
controllers
, workers::downloader::DownloadWorker,
Expand Down Expand Up @@ -54,7 +54,9 @@ impl Hooks for App {
queue.register(DownloadWorker::build(ctx)).await?;
Ok(())
}
fn register_tasks(_tasks: &mut Tasks) {

#[allow(unused_variables)]
fn register_tasks(tasks: &mut Tasks) {
// tasks-inject (do not remove)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: tests/templates/background.rs
expression: "std::fs::read_to_string(generator.path(\"src/app.rs\")).expect(\"could not open file\")"
snapshot_kind: text
---
use async_trait::async_trait;
use loco_rs::{
Expand All @@ -15,6 +14,7 @@ use loco_rs::{
Result,
};

#[allow(unused_imports)]
use crate::{
controllers,
};
Expand Down Expand Up @@ -51,7 +51,9 @@ impl Hooks for App {
async fn connect_workers(_ctx: &AppContext, _queue: &Queue) -> Result<()> {
Ok(())
}
fn register_tasks(_tasks: &mut Tasks) {

#[allow(unused_variables)]
fn register_tasks(tasks: &mut Tasks) {
// tasks-inject (do not remove)
}
}
Loading

0 comments on commit ef0d9e3

Please sign in to comment.