From 34e16b7d7a88013578014be0402ab686b03f235b Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Tue, 1 Jul 2025 08:40:49 +0200 Subject: lib: Introduce the PlainExporter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This class exports things into plain text. It follows a close format to that of the one for UOC, but without any formatting. Signed-off-by: Miquel Sabaté Solà --- test/controllers/exports_controller_test.rb | 17 +++++++++++++++++ test/fixtures/files/all.txt | 2 ++ 2 files changed, 19 insertions(+) create mode 100644 test/fixtures/files/all.txt (limited to 'test') diff --git a/test/controllers/exports_controller_test.rb b/test/controllers/exports_controller_test.rb index fe94362..0b0ba1d 100644 --- a/test/controllers/exports_controller_test.rb +++ b/test/controllers/exports_controller_test.rb @@ -42,4 +42,21 @@ class ExportsControllerTest < ActionDispatch::IntegrationTest assert_equal @response.body, file_fixture('underscores.uoc.tex').read end + + test 'plain: works' do + get search_exports_url(0, format: 'txt') + + assert_equal @response.body, file_fixture('all.txt').read.strip + assert_equal 'text/plain', @response.media_type + end + + test 'plain: underscore is removed for the title' do + things(:thing1).update!(title: 'This is a _title_ with _many_ underscores') + + get search_exports_url(0, format: 'txt') + + body = @response.body.split("\n") + + assert_includes body.last, 'This is a title with many underscores' + end end diff --git a/test/fixtures/files/all.txt b/test/fixtures/files/all.txt new file mode 100644 index 0000000..49205a9 --- /dev/null +++ b/test/fixtures/files/all.txt @@ -0,0 +1,2 @@ +Sabaté, Miquel; Nom (eds.) (2024). This is a 2. Dins de Some other thing, 22-24. This is a note 2. Publisher 2, Address 2: 2024. +Sabaté, Miquel; Smith, John; cognom2, Nom cognom1; cognom3 cognom4, Nom (2024). This is a title 1. Dins de Some other thing, 22-24. This is a note 1. Publisher 1. -- cgit v1.2.3