Skip to content

Commit 5dcee73

Browse files
authored
Merge pull request #84 from phillmv/fix_static_mode
Fix static mode tests
2 parents 724631a + 451d325 commit 5dcee73

25 files changed

+237
-48
lines changed

.github/workflows/continuous_integration.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ jobs:
2626
tags: arquivo-test:latest
2727
- name: run the test
2828
run: docker run arquivo-test:latest
29+
- name: run the test
30+
run: STATIC_PLS=1 docker run -e STATIC_PLS arquivo-test:latest
31+
32+
2933

3034

3135
# run_rails_test:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ yarn-debug.log*
3838
/.nix-gems
3939
/.nix-node
4040
# /vendor/cache
41+
# we vendor the gems, but not the installed paths
42+
/vendor/ruby
4143
*.DS_Store
4244

4345
# use this to customize your .env entries

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ RUN gem update --system --no-document && \
2323
RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
2424
--mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
2525
apt-get update -qq && \
26-
apt-get install --no-install-recommends -y curl git openssh-client libsqlite3-0
26+
apt-get install --no-install-recommends -y curl git openssh-client libsqlite3-0 wget
2727

2828

2929
RUN useradd rails --create-home --shell /bin/bash

app/controllers/application_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def check_imports
2020
def resync_with_remotes
2121
last_checked_at = session[:synced_remotes_at]
2222
if last_checked_at.nil? || last_checked_at < 15.minutes.ago
23-
PullAllFromGit.perform_later
23+
PullAllFromGit.perform_later unless Arquivo.static?
2424
end
2525
session[:synced_remotes_at] = Time.current
2626
end

app/controllers/entries_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def index
1212
# GET /entries/1.json
1313
def show
1414
if @entry.document?
15+
# TODO: why import these at all why not just open the frigging thing?
1516
blob = @entry.files.blobs.first
1617
expires_in ActiveStorage.service_urls_expire_in
1718
redirect_to rails_blob_path(blob, disposition: params[:disposition])

app/helpers/url_helper.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@ def self.entry_params(entry)
1616
name_with_path = "#{name}_path".to_sym
1717
define_method name_with_path do |entry, opts = {}|
1818
if Arquivo.static?
19-
RailsUrlHelpers.send(name_with_path, entry, opts.except(:notebook).merge(format: "html"))
19+
# A year and a half later, I don't remember _why_ I started forcing
20+
# .html urls in links (isn't this breaking document downloads?)
21+
# my impression is I made this distinction in order to force
22+
# downloaded urls to be stored with .html extension so they can
23+
# be served statically – but i'm not entirely sure this is The Correct Way
24+
these_opts = opts.except(:notebook)
25+
if entry.append_html_extension?
26+
these_opts = these_opts.merge(format: "html")
27+
end
28+
RailsUrlHelpers.send(name_with_path, entry, these_opts)
2029
else
2130
RailsUrlHelpers.send(name_with_path, entry, opts.merge(UrlHelper.entry_params(entry)))
2231
end

app/models/ad_hoc_markdown_importer.rb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def find_or_create_notebook
2929
notebook = Notebook.find_by(name: notebook_name)
3030
if notebook.nil?
3131
notebook = Notebook.create(name: notebook_name,
32-
import_path: notebook_path)
32+
import_path: notebook_path,
33+
skip_local_sync: true)
3334
else
3435
notebook.update(import_path: notebook_path)
3536
end
@@ -70,16 +71,10 @@ def process_import_path(notebook)
7071

7172
filename = File.basename(identifier)
7273
if !entry.files.blobs.find_by(filename: filename)
73-
# TODO 2023-11-23: mimic the same blob lifecycle handling from create_blob_and_file to avoid the async stuff noted below.
7474
blob = ActiveStorage::Blob.create_and_upload!(io: File.open(file_path),
75-
filename: filename)
76-
77-
# run analysis step synchronously, so we skip the async job.
78-
# for reasons i don't comprehend, in dev mode at least
79-
# ActiveStorage::AnalyzeJob just hangs there indefinitely, doing
80-
# naught to improve our lot, and this is very frustrating and further
81-
# i have close to zero desire to debug ActiveJob async shenanigans
82-
blob.analyze
75+
filename: filename,
76+
metadata: { "analyzed" => true })
77+
8378
entry.files.create(blob_id: blob.id, created_at: blob.created_at)
8479
end
8580
end

app/models/entry.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ def clear_cached_blob_filenames
213213
end
214214
# --
215215

216+
def append_html_extension?
217+
note? || calendar? || bookmark?
218+
end
219+
216220
def note?
217221
kind.nil?
218222
end

app/models/entry_linker.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,19 @@ def blacklisted_paths
4646
end
4747

4848
if Arquivo.static?
49-
return []
50-
end
49+
contact_path = Rails.application.routes.url_helpers.contact_path(query: "")
50+
tag_path = Rails.application.routes.url_helpers.tag_path(query: "")
51+
@blacklisted_paths = [contact_path, tag_path]
52+
else
5153

52-
# don't want to consider autogen tag and contact urls to be a "link"
53-
# since we keep track of those references separately ¯\_(ツ)_/¯
54-
# TODO: rewrite this to handle Arquivo.static urls
55-
tag_search_path = Rails.application.routes.url_helpers.search_path(owner: notebook.owner, notebook: notebook, query: "#")
56-
contact_search_path = Rails.application.routes.url_helpers.search_path(owner: notebook.owner, notebook: notebook, query: "@")
54+
# don't want to consider autogen tag and contact urls to be a "link"
55+
# since we keep track of those references separately ¯\_(ツ)_/¯
56+
# TODO: rewrite this to be handled in their respective pipelines (a data attr? a context variable?) so we're not doing this funny business
57+
tag_search_path = Rails.application.routes.url_helpers.search_path(owner: notebook.owner, notebook: notebook, query: "#")
58+
contact_search_path = Rails.application.routes.url_helpers.search_path(owner: notebook.owner, notebook: notebook, query: "@")
5759

58-
@blacklisted_paths = [tag_search_path, contact_search_path]
60+
@blacklisted_paths = [tag_search_path, contact_search_path]
61+
end
5962
end
6063

6164
def link!

app/models/sync_from_disk.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def create_blob_and_file(entry, blob_attr, entry_files_path)
164164
end
165165
blob_attr["metadata"]["analyzed"] = true
166166

167-
blob = ActiveStorage::Blob.create(blob_attr)
167+
blob = ActiveStorage::Blob.create!(blob_attr)
168168
blob.upload_without_unfurling(File.open(new_attachment_filepath))
169169

170170
entry.files.create(blob_id: blob.id, created_at: blob.created_at)

0 commit comments

Comments
 (0)