Skip to content

Commit

Permalink
Add seeds to dummy
Browse files Browse the repository at this point in the history
  • Loading branch information
hunchr committed Oct 23, 2024
1 parent c994a46 commit bccc83e
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 31 deletions.
2 changes: 2 additions & 0 deletions spec/dummy/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

source "https://rubygems.org"

gem "importmap-rails"
gem "puma"
gem "rails", github: "rails/rails", branch: "main"
gem "hotsheet", path: "../.."
Expand All @@ -11,6 +12,7 @@ group :development, :test do
gem "better_errors"
gem "binding_of_caller"
gem "debug"
gem "faker", require: false
gem "renuocop", require: false
gem "rspec-rails", require: false
end
46 changes: 15 additions & 31 deletions spec/dummy/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/rails/rails.git
revision: fe0fb9fdf04f638996e785d3e291f5fe8bc138a0
revision: fecd069738fed649e85a31f94b47575104b959b4
branch: main
specs:
actioncable (8.1.0.alpha)
Expand Down Expand Up @@ -104,6 +104,7 @@ PATH
rails (>= 7.2.1)
sprockets-rails
stimulus-rails
turbo-rails

GEM
remote: https://rubygems.org/
Expand All @@ -130,10 +131,16 @@ GEM
diff-lcs (1.5.1)
drb (2.2.1)
erubi (1.13.0)
faker (3.5.1)
i18n (>= 1.8.11, < 2)
globalid (1.2.1)
activesupport (>= 6.1)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
importmap-rails (2.0.3)
actionpack (>= 6.0.0)
activesupport (>= 6.0.0)
railties (>= 6.0.0)
io-console (0.7.2)
irb (1.14.1)
rdoc (>= 4.0.0)
Expand Down Expand Up @@ -163,16 +170,8 @@ GEM
net-smtp (0.5.0)
net-protocol
nio4r (2.7.3)
nokogiri (1.16.7-aarch64-linux)
racc (~> 1.4)
nokogiri (1.16.7-arm-linux)
racc (~> 1.4)
nokogiri (1.16.7-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86-linux)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux)
racc (~> 1.4)
parallel (1.26.3)
Expand Down Expand Up @@ -266,16 +265,8 @@ GEM
actionpack (>= 6.1)
activesupport (>= 6.1)
sprockets (>= 3.0.0)
sqlite3 (2.1.0-aarch64-linux-gnu)
sqlite3 (2.1.0-aarch64-linux-musl)
sqlite3 (2.1.0-arm-linux-gnu)
sqlite3 (2.1.0-arm-linux-musl)
sqlite3 (2.1.0-arm64-darwin)
sqlite3 (2.1.0-x86-linux-gnu)
sqlite3 (2.1.0-x86-linux-musl)
sqlite3 (2.1.0-x86_64-darwin)
sqlite3 (2.1.0-x86_64-linux-gnu)
sqlite3 (2.1.0-x86_64-linux-musl)
sqlite3 (2.1.1-arm64-darwin)
sqlite3 (2.1.1-x86_64-linux-gnu)
standard (1.41.1)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
Expand All @@ -293,6 +284,9 @@ GEM
stringio (3.1.1)
thor (1.3.2)
timeout (0.4.1)
turbo-rails (2.0.11)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.6.0)
Expand All @@ -305,25 +299,15 @@ GEM
zeitwerk (2.7.1)

PLATFORMS
aarch64-linux
aarch64-linux-gnu
aarch64-linux-musl
arm-linux
arm-linux-gnu
arm-linux-musl
arm64-darwin
x86-linux
x86-linux-gnu
x86-linux-musl
x86_64-darwin
x86_64-linux
x86_64-linux-gnu
x86_64-linux-musl

DEPENDENCIES
better_errors
binding_of_caller
debug
faker
importmap-rails
puma
rails!
rails_db_manager!
Expand Down
5 changes: 5 additions & 0 deletions spec/dummy/app/models/author.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class Author < ApplicationRecord
enum :gender, { male: "male", female: "female", undefined: "undefined" }, validate: true
end
4 changes: 4 additions & 0 deletions spec/dummy/app/models/post.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Post < ApplicationRecord
end
11 changes: 11 additions & 0 deletions spec/dummy/config/initializers/hotsheet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

Hotsheet.configure do |config|
config.model :Author do |model|
model.included_attributes = %i[name birthdate gender updated_at]
end

config.model :Post do |model|
model.excluded_attributes = %i[created_at updated_at]
end
end
28 changes: 28 additions & 0 deletions spec/dummy/db/migrate/20241022111111_create_authors_and_posts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

class CreateAuthorsAndPosts < ActiveRecord::Migration[8.1]
def change
authors
posts
end

private

def authors
create_table :authors do |t|
t.string :name
t.date :birthdate
t.string :gender
t.timestamps
end
end

def posts
create_table :posts do |t|
t.string :title
t.string :body
t.references :author, foreign_key: true
t.timestamps
end
end
end
34 changes: 34 additions & 0 deletions spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[8.1].define(version: 20_241_022_111_111) do
create_table "authors", force: :cascade do |t|
t.string "name"
t.date "birthdate"
t.string "gender"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "posts", force: :cascade do |t|
t.string "title"
t.string "body"
t.integer "author_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["author_id"], name: "index_posts_on_author_id"
end

add_foreign_key "posts", "authors"
end
14 changes: 14 additions & 0 deletions spec/dummy/db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# frozen_string_literal: true

require "faker"

10.times do
Author.create!(name: Faker::Name.name,
birthdate: Faker::Date.birthday(min_age: 18, max_age: 65),
gender: Author.genders.values.sample)
end

10.times do
Post.create!(title: Faker::Lorem.word,
body: Faker::Lorem.paragraph,
author_id: Author.pluck(:id).sample)
end
File renamed without changes.

0 comments on commit bccc83e

Please sign in to comment.