mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-26 00:06:21 +00:00
feat: poder generar modelos para los tests
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
parent
74b6899667
commit
678bf88da3
7 changed files with 102 additions and 0 deletions
|
@ -293,6 +293,8 @@ class Site < ApplicationRecord
|
|||
File.directory? path
|
||||
end
|
||||
|
||||
attr_writer :jekyll
|
||||
|
||||
def jekyll
|
||||
@jekyll ||=
|
||||
begin
|
||||
|
|
17
test/factories/collection.rb
Normal file
17
test/factories/collection.rb
Normal 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
|
27
test/factories/document.rb
Normal file
27
test/factories/document.rb
Normal 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
16
test/factories/jekyll.rb
Normal 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
19
test/factories/layout.rb
Normal 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
17
test/factories/post.rb
Normal 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
|
|
@ -8,6 +8,10 @@ FactoryBot.define do
|
|||
design
|
||||
licencia
|
||||
|
||||
jekyll do
|
||||
build(:jekyll)
|
||||
end
|
||||
|
||||
after :build do |site|
|
||||
site.deploys << build(:deploy_local, site: site)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue