Skip to content

Commit

Permalink
Override the default posts factory
Browse files Browse the repository at this point in the history
More interesting and useful test data
  • Loading branch information
sfnelson authored and Katalyst committed Sep 20, 2023
1 parent e920a20 commit a951fa5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/tasks/dummy.thor
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Dummy < Thor

inside("spec/dummy") do
run <<~SH
rails g koi:admin Post name:string title:string content:rich_text active:boolean ordinal:integer published_on:date
rails g koi:admin Post name:string title:string content:rich_text active:boolean published_on:date
SH

run "rails db:migrate"
Expand Down
4 changes: 3 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
ENV["RAILS_ENV"] ||= "test"
require File.expand_path("dummy/spec/rails_helper", __dir__)

Dir[Koi::Engine.root.join("spec", "support", "**", "*.rb")].each { |f| require f }
Dir[Koi::Engine.root.join("spec", "support", "**", "*.rb")].each do |f|
require f unless f.include?("templates")
end

RSpec.configure do |config|
config.include ViewComponent::TestHelpers, type: :component
Expand Down
2 changes: 1 addition & 1 deletion spec/support/templates/db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

Koi::Engine.load_seed

FactoryBot.create_list(:post, 25, active: true, published_on: 15.days.ago)
FactoryBot.create_list(:post, 25)
FactoryBot.create_list(:post, 5, active: false)
11 changes: 11 additions & 0 deletions spec/support/templates/spec/factories/posts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

FactoryBot.define do
factory :post do
name { Faker::Book.author }
title { Faker::Book.title }
content { Faker::HTML.sandwich }
active { true }
published_on { Faker::Date.backward }
end
end
4 changes: 3 additions & 1 deletion spec/system/index/pagination_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

RSpec.describe "index/pagination" do
let(:admin) { create(:admin) }
let!(:posts) { create_list(:post, 25) }
let(:posts) { Post.order(name: :asc) }

before do
create_list(:post, 25)

visit "/admin"

fill_in "Email", with: admin.email
Expand Down

0 comments on commit a951fa5

Please sign in to comment.