mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Update links to n8n server
This commit is contained in:
17
db/migrate/20240502035220_update_n8n_url.rb
Normal file
17
db/migrate/20240502035220_update_n8n_url.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# We got a new n8n server.
|
||||
# But we still have some database rows with a URL to the old server.
|
||||
class UpdateN8nUrl < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
execute <<~SQL.squish
|
||||
UPDATE connected_apps
|
||||
SET data = replace(
|
||||
data::text,
|
||||
'n8n.openfoodnetwork.org.uk',
|
||||
'n8n.openfoodnetwork.org'
|
||||
)::jsonb
|
||||
WHERE data IS NOT NULL;
|
||||
SQL
|
||||
end
|
||||
end
|
||||
50
spec/migrations/20240502035220_update_n8n_url_spec.rb
Normal file
50
spec/migrations/20240502035220_update_n8n_url_spec.rb
Normal file
@@ -0,0 +1,50 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
require_relative '../../db/migrate/20240502035220_update_n8n_url'
|
||||
|
||||
describe UpdateN8nUrl do
|
||||
# We may want to move this to a support file if this syntax is useful in
|
||||
# other places. Reference:
|
||||
# - https://stackoverflow.com/a/34969429/3377535
|
||||
RSpec::Matchers.define_negated_matcher :not_change, :change
|
||||
|
||||
let(:enterprise) { create(:enterprise) }
|
||||
let(:old_data) {
|
||||
{
|
||||
link: "https://link-to-form",
|
||||
destroy: "https://n8n.openfoodnetwork.org.uk/webhook/remove-enterprise?key=abc&id=123",
|
||||
}
|
||||
}
|
||||
let(:new_data) {
|
||||
{
|
||||
link: "https://link-to-form",
|
||||
destroy: "https://n8n.openfoodnetwork.org/webhook/remove-enterprise?key=abc&id=123",
|
||||
}
|
||||
}
|
||||
|
||||
it "updates old connected app links" do
|
||||
app = ConnectedApp.create!(enterprise:, data: old_data,)
|
||||
|
||||
expect {
|
||||
subject.up
|
||||
app.reload
|
||||
}.to change {
|
||||
app.data["destroy"]
|
||||
}.to("https://n8n.openfoodnetwork.org/webhook/remove-enterprise?key=abc&id=123")
|
||||
.and not_change {
|
||||
app.data["link"]
|
||||
}
|
||||
end
|
||||
|
||||
it "keeps new connected app links" do
|
||||
app = ConnectedApp.create!(enterprise:, data: new_data,)
|
||||
|
||||
expect {
|
||||
subject.up
|
||||
app.reload
|
||||
}.not_to change {
|
||||
app.data
|
||||
}
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user