5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-26 08:06:23 +00:00

feat: poder generar modelos para los tests
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
f 2023-10-06 11:00:50 -03:00
parent 74b6899667
commit 678bf88da3
No known key found for this signature in database
7 changed files with 102 additions and 0 deletions

View file

@ -293,6 +293,8 @@ class Site < ApplicationRecord
File.directory? path File.directory? path
end end
attr_writer :jekyll
def jekyll def jekyll
@jekyll ||= @jekyll ||=
begin begin

View file

@ -0,0 +1,17 @@
# frozen_string_literal: true
FactoryBot.define do
factory :collection, class: Jekyll::Collection do
site do
build(:jekyll)
end
label do
('a'..'z').to_a.sample(2).join
end
initialize_with do
new(site, label)
end
end
end

View file

@ -0,0 +1,27 @@
# frozen_string_literal: true
FactoryBot.define do
factory :document, class: Jekyll::Document do
site do
build(:jekyll)
end
collection do
build(:collection, site: site)
end
path do
'2023-01-01-document.markdown'
end
date do
Date.today.to_time
end
initialize_with do
new(path, site: site, collection: collection).tap do |doc|
doc.data['date'] = date
end
end
end
end

16
test/factories/jekyll.rb Normal file
View file

@ -0,0 +1,16 @@
# frozen_string_literal: true
FactoryBot.define do
factory :jekyll, class: Jekyll::Site do
initialize_with do
new(Jekyll.configuration(
'source' => Rails.root.join('test', 'fixtures', 'site').to_s,
'quiet' => true,
'safe' => true,
'watch' => false,
'destination' => Dir.mktmpdir,
'excerpt_separator' => ''
))
end
end
end

19
test/factories/layout.rb Normal file
View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
FactoryBot.define do
factory :layout do
name do
SecureRandom.hex
end
site
meta do
{}
end
metadata do
{}
end
end
end

17
test/factories/post.rb Normal file
View file

@ -0,0 +1,17 @@
# frozen_string_literal: true
FactoryBot.define do
factory :post, class: Post do
site
document
layout
locale do
('a'..'z').to_a.sample(2).join
end
initialize_with do
new(site: site, layout: layout, document: document, locale: locale)
end
end
end

View file

@ -8,6 +8,10 @@ FactoryBot.define do
design design
licencia licencia
jekyll do
build(:jekyll)
end
after :build do |site| after :build do |site|
site.deploys << build(:deploy_local, site: site) site.deploys << build(:deploy_local, site: site)
end end