chore: reorganize para current/, rails 8.1, testes e readme
- move app para current/ (estrutura capistrano) - rails 7.2 → 8.1, ruby 3.2, sqlite3 2.x - adiciona primary_key Idinformativo no model - schema.rb completo com todas as tabelas - testes minitest: models (Tag, Informativo, Tema) e controllers - readme atualizado em pt-br com stack e instruções de desenvolvimento - gitignore exclui dump.sql, *.duckdb e sqlite3
This commit is contained in:
37
current/test/controllers/page_controller_test.rb
Normal file
37
current/test/controllers/page_controller_test.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
require "test_helper"
|
||||
|
||||
class PageControllerTest < ActionDispatch::IntegrationTest
|
||||
test "home returns 200" do
|
||||
get root_path
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "busca returns 200 with empty query" do
|
||||
get "/search", params: { q: "" }
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "busca returns 200 with search term" do
|
||||
Informativo.create!(titulo: "Desmatamento na Amazônia")
|
||||
get "/search", params: { q: "Amazônia" }
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "informativo page returns 200 for valid id" do
|
||||
info = Informativo.create!(titulo: "Artigo de teste", markdown: "Conteúdo")
|
||||
get "/informativo/#{info.Idinformativo}"
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "tag page returns 200 for existing tag" do
|
||||
Tag.create!(nome: "biodiversidade")
|
||||
get "/tag/biodiversidade"
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "tema page returns 200 for existing tema" do
|
||||
Tema.create!(cod_tema: 5, tema: "Água", padrao: "Água", param: "agua", count: 0)
|
||||
get "/tema/agua"
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
28
current/test/models/informativo_test.rb
Normal file
28
current/test/models/informativo_test.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
require "test_helper"
|
||||
|
||||
class InformativoTest < ActiveSupport::TestCase
|
||||
test "creates with titulo and sets Datainc automatically" do
|
||||
info = Informativo.create!(titulo: "Novo artigo ambiental")
|
||||
assert_not_nil info.Datainc
|
||||
assert_not_nil info.Idinformativo
|
||||
end
|
||||
|
||||
test "does not overwrite an existing Datainc" do
|
||||
date = Date.new(2010, 6, 1)
|
||||
info = Informativo.create!(titulo: "Artigo antigo", Datainc: date)
|
||||
assert_equal date, info.Datainc
|
||||
end
|
||||
|
||||
test "to_html renders markdown column as HTML" do
|
||||
info = Informativo.create!(titulo: "Test", markdown: "## Título\nConteúdo")
|
||||
html = info.to_html
|
||||
assert_includes html, "<h2>"
|
||||
assert_includes html, "Título"
|
||||
end
|
||||
|
||||
test "temas returns matching tema names" do
|
||||
tema = Tema.create!(cod_tema: 7, tema: "Energia", padrao: "Energia Renovável", count: 0)
|
||||
info = Informativo.create!(titulo: "Solar", tema1: 7)
|
||||
assert_includes info.temas, tema.tema
|
||||
end
|
||||
end
|
||||
27
current/test/models/tag_test.rb
Normal file
27
current/test/models/tag_test.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
require "test_helper"
|
||||
|
||||
class TagTest < ActiveSupport::TestCase
|
||||
test "parameterize sets param on save" do
|
||||
tag = Tag.create!(nome: "Energia Solar")
|
||||
assert_equal "energia-solar", tag.param
|
||||
end
|
||||
|
||||
test "strips whitespace from nome before save" do
|
||||
tag = Tag.create!(nome: " mata ciliar ")
|
||||
assert_equal "mata ciliar", tag.nome
|
||||
end
|
||||
|
||||
test "nome uniqueness is enforced" do
|
||||
Tag.create!(nome: "floresta")
|
||||
dup = Tag.new(nome: "floresta")
|
||||
assert_not dup.valid?
|
||||
end
|
||||
|
||||
test "top returns at most 80 tags ordered by count desc" do
|
||||
Tag.create!(nome: "tag-a", param: "tag-a", count: 100)
|
||||
Tag.create!(nome: "tag-b", param: "tag-b", count: 5)
|
||||
result = Tag.top
|
||||
assert result.first.count >= result.last.count
|
||||
assert result.size <= 80
|
||||
end
|
||||
end
|
||||
22
current/test/models/tema_test.rb
Normal file
22
current/test/models/tema_test.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
require "test_helper"
|
||||
|
||||
class TemaTest < ActiveSupport::TestCase
|
||||
test "informativos returns articles linked to this tema" do
|
||||
tema = Tema.create!(cod_tema: 3, tema: "Clima", padrao: "Mudanças Climáticas", count: 0)
|
||||
info = Informativo.create!(titulo: "IPCC 2010", tema1: 3)
|
||||
assert_includes tema.informativos, info
|
||||
end
|
||||
|
||||
test "infos returns only root temas with padrao, sorted by count desc" do
|
||||
Tema.create!(cod_tema: 1, cod_tema_sub: 0, padrao: "Legislação", count: 500)
|
||||
Tema.create!(cod_tema: 2, cod_tema_sub: 0, padrao: "Fauna e Flora", count: 200)
|
||||
Tema.create!(cod_tema: 3, cod_tema_sub: 1, padrao: "Subtema", count: 999)
|
||||
|
||||
result = Tema.infos
|
||||
names = result.map(&:first)
|
||||
assert_includes names, "Legislação"
|
||||
assert_includes names, "Fauna e Flora"
|
||||
assert_not_includes names, "Subtema"
|
||||
assert result.first[1] >= result.last[1]
|
||||
end
|
||||
end
|
||||
7
current/test/test_helper.rb
Normal file
7
current/test/test_helper.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
ENV["RAILS_ENV"] ||= "test"
|
||||
require_relative "../config/environment"
|
||||
require "rails/test_help"
|
||||
|
||||
class ActiveSupport::TestCase
|
||||
self.use_transactional_tests = true
|
||||
end
|
||||
Reference in New Issue
Block a user