From 678bf88da351733c760dae7a0f6e79fb14b228e2 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 6 Oct 2023 11:00:50 -0300 Subject: [PATCH] feat: poder generar modelos para los tests --- app/models/site.rb | 2 ++ test/factories/collection.rb | 17 +++++++++++++++++ test/factories/document.rb | 27 +++++++++++++++++++++++++++ test/factories/jekyll.rb | 16 ++++++++++++++++ test/factories/layout.rb | 19 +++++++++++++++++++ test/factories/post.rb | 17 +++++++++++++++++ test/factories/site.rb | 4 ++++ 7 files changed, 102 insertions(+) create mode 100644 test/factories/collection.rb create mode 100644 test/factories/document.rb create mode 100644 test/factories/jekyll.rb create mode 100644 test/factories/layout.rb create mode 100644 test/factories/post.rb diff --git a/app/models/site.rb b/app/models/site.rb index 3ccd27d3..7d44abb5 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -293,6 +293,8 @@ class Site < ApplicationRecord File.directory? path end + attr_writer :jekyll + def jekyll @jekyll ||= begin diff --git a/test/factories/collection.rb b/test/factories/collection.rb new file mode 100644 index 00000000..4f397eb5 --- /dev/null +++ b/test/factories/collection.rb @@ -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 diff --git a/test/factories/document.rb b/test/factories/document.rb new file mode 100644 index 00000000..cb3a3511 --- /dev/null +++ b/test/factories/document.rb @@ -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 diff --git a/test/factories/jekyll.rb b/test/factories/jekyll.rb new file mode 100644 index 00000000..486e26da --- /dev/null +++ b/test/factories/jekyll.rb @@ -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 diff --git a/test/factories/layout.rb b/test/factories/layout.rb new file mode 100644 index 00000000..236ca5fb --- /dev/null +++ b/test/factories/layout.rb @@ -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 diff --git a/test/factories/post.rb b/test/factories/post.rb new file mode 100644 index 00000000..41d8cf7b --- /dev/null +++ b/test/factories/post.rb @@ -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 diff --git a/test/factories/site.rb b/test/factories/site.rb index d9d8720f..0fd7d99e 100644 --- a/test/factories/site.rb +++ b/test/factories/site.rb @@ -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