2019-03-26 15:32:20 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-04-27 18:48:26 +00:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class SiteTest < ActiveSupport::TestCase
|
|
|
|
setup do
|
|
|
|
@user = Usuaria.find('f@kefir.red')
|
|
|
|
@path = File.join(Site.site_path_for(@user), 'cyber-women.com')
|
|
|
|
reset_git_repo(@path)
|
|
|
|
@site = @user.sites.select { |s| s.name == 'cyber-women.com' }.first
|
|
|
|
@site.read
|
|
|
|
end
|
|
|
|
|
2019-03-26 15:32:20 +00:00
|
|
|
test 'El directorio es un sitio jekyll' do
|
2018-04-27 18:48:26 +00:00
|
|
|
assert Site.jekyll?(@path)
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'Un directorio se puede cargar como un sitio Jekyll' do
|
|
|
|
jekyll = Site.load_jekyll @path
|
|
|
|
|
|
|
|
assert_equal Jekyll::Site, jekyll.class
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'Los artículos no están ordenados si a alguno le falta orden' do
|
|
|
|
assert_not @site.ordered?
|
|
|
|
assert @site.reorder_collection!
|
|
|
|
assert @site.ordered?
|
|
|
|
end
|
2018-04-30 18:51:39 +00:00
|
|
|
|
|
|
|
test 'No podemos poner órdenes arbitrarios' do
|
|
|
|
total = @site.posts.count
|
2019-03-26 15:32:20 +00:00
|
|
|
new_order = Hash[total.times.map { |i| [i.to_s, rand(total)] }]
|
2018-04-30 18:51:39 +00:00
|
|
|
|
|
|
|
assert_not @site.reorder_collection('posts', new_order)
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'Si les damos un orden alternativo los reordenamos' do
|
|
|
|
total = @site.posts.count
|
2019-03-26 15:32:20 +00:00
|
|
|
order = total.times.map(&:to_s)
|
2018-04-30 18:51:39 +00:00
|
|
|
new_order = Hash[order.zip(order.shuffle)]
|
|
|
|
|
|
|
|
assert @site.reorder_collection('posts', new_order)
|
2018-05-02 17:23:45 +00:00
|
|
|
|
|
|
|
# podemos hacer este test porque reordenar los posts no ordena el
|
|
|
|
# array
|
2019-03-26 15:32:20 +00:00
|
|
|
new_order.each do |k, v|
|
2018-05-02 17:23:45 +00:00
|
|
|
v = v.to_i
|
|
|
|
k = k.to_i
|
|
|
|
assert_equal v, @site.posts[k].order
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'Podemos reordenar solo una parte de los artículos' do
|
|
|
|
total = @site.posts.count
|
2019-03-26 15:32:20 +00:00
|
|
|
order = (total - rand(total - 1)).times.map(&:to_s)
|
2018-05-02 17:23:45 +00:00
|
|
|
new_order = Hash[order.zip(order.shuffle)]
|
|
|
|
|
|
|
|
assert @site.reorder_collection('posts', new_order)
|
|
|
|
|
|
|
|
# podemos hacer este test porque reordenar los posts no ordena el
|
|
|
|
# array
|
2019-03-26 15:32:20 +00:00
|
|
|
new_order.each do |k, v|
|
2018-05-02 17:23:45 +00:00
|
|
|
v = v.to_i
|
|
|
|
k = k.to_i
|
|
|
|
assert_equal v, @site.posts[k].order
|
|
|
|
end
|
2018-04-30 18:51:39 +00:00
|
|
|
end
|
2018-05-11 16:24:30 +00:00
|
|
|
|
|
|
|
test 'Un sitio tiene traducciones' do
|
|
|
|
assert_equal %w[ar es en], @site.translations
|
|
|
|
assert @site.i18n?
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'El idioma por defecto es el idioma actual de la plataforma' do
|
|
|
|
assert_equal 'es', @site.default_lang
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'El sitio tiene layouts' do
|
|
|
|
assert_equal %w[anexo archive default feed header.ar header.en
|
2019-03-26 15:32:20 +00:00
|
|
|
header.es header license.ar license.en license.es license pandoc
|
|
|
|
politicas sesion simple style ].sort, @site.layouts
|
2018-05-11 16:24:30 +00:00
|
|
|
end
|
2018-04-27 18:48:26 +00:00
|
|
|
end
|