Skip to content

Commit 41df432

Browse files
committed
test: Small update for the dummy app
1 parent fbb6c88 commit 41df432

5 files changed

Lines changed: 92 additions & 7 deletions

File tree

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
lint:
2-
bin/rubocop
1+
specs:
2+
RUBYOPT='-rbundler/setup -rrbs/test/setup' RBS_TEST_TARGET='TinyAdmin::*' bin/rspec
33

4-
test:
5-
bin/rspec
4+
server:
5+
cd spec/dummy_rails/ && bin/rails s
66

7-
test_rbs:
8-
RUBYOPT='-rbundler/setup -rrbs/test/setup' RBS_TEST_TARGET='TinyAdmin::*' bin/rspec
7+
seed:
8+
cd spec/dummy_rails/ && bin/rails db:migrate && bin/rails db:seed

spec/dummy_rails/db/schema.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.1].define(version: 2018_06_07_053857) do
13+
ActiveRecord::Schema[7.2].define(version: 2018_06_07_053857) do
1414
create_table "authors", force: :cascade do |t|
1515
t.string "name"
1616
t.integer "age"

spec/dummy_rails/db/seeds.rb

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# 1. Clean up existing data to ensure a fresh start
2+
puts "Cleaning database..."
3+
PostTag.destroy_all
4+
Tag.destroy_all
5+
Post.destroy_all
6+
Profile.destroy_all
7+
Author.destroy_all
8+
9+
# 2. Create Tags
10+
puts "Creating tags..."
11+
tech_tag = Tag.create!(name: "Technology")
12+
travel_tag = Tag.create!(name: "Travel")
13+
food_tag = Tag.create!(name: "Food")
14+
15+
# 3. Create Authors and their Profiles (One-to-One)
16+
puts "Creating authors and profiles..."
17+
authors_data = [
18+
{ name: "Alice Smith", age: 30, email: "alice@example.com", bio: "Tech enthusiast and coder." },
19+
{ name: "Bob Jones", age: 45, email: "bob@example.com", bio: "Global traveler and food critic." }
20+
]
21+
22+
authors_data.each do |data|
23+
author = Author.create!(
24+
name: data[:name],
25+
age: data[:age],
26+
email: data[:email]
27+
)
28+
29+
# Create the associated profile
30+
Profile.create!(
31+
author: author,
32+
description: data[:bio]
33+
)
34+
end
35+
36+
# 4. Create Posts for Authors (One-to-Many)
37+
puts "Creating posts..."
38+
alice = Author.find_by(email: "alice@example.com")
39+
bob = Author.find_by(email: "bob@example.com")
40+
41+
post1 = Post.create!(
42+
title: "The Future of Rails 7",
43+
description: "Exploring the new features in the latest Rails update.",
44+
state: 1,
45+
category: "Software",
46+
dt: Date.today,
47+
position: 1.0,
48+
published: true,
49+
author: alice
50+
)
51+
52+
post2 = Post.create!(
53+
title: "Best Pasta in Rome",
54+
description: "A deep dive into the culinary wonders of Italy.",
55+
state: 1,
56+
category: "Lifestyle",
57+
dt: Date.yesterday,
58+
position: 2.0,
59+
published: true,
60+
author: bob
61+
)
62+
63+
# 5. Associate Posts with Tags (Many-to-Many)
64+
puts "Linking posts to tags..."
65+
# Alice's post is tech
66+
PostTag.create!(post: post1, tag: tech_tag)
67+
68+
# Bob's post is travel AND food
69+
PostTag.create!(post: post2, tag: travel_tag)
70+
PostTag.create!(post: post2, tag: food_tag)
71+
72+
puts "Successfully seeded #{Author.count} authors, #{Post.count} posts, and #{Tag.count} tags!"

spec/dummy_rails/public/bootstrap.bundle.min.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/dummy_rails/public/bootstrap.min.css

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)