mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-22 00:57:26 +00:00
Add instagram handler validator
update entreprise model to match the correct pattern for instagram attribute & add migration to correct wrong links in db + test
This commit is contained in:
committed by
Jean-Baptiste Bellet
parent
fdf3a0d7b7
commit
bfd396e644
@@ -0,0 +1,29 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class UpdateEnterpriseInstagramLinks < ActiveRecord::Migration[6.1]
|
||||
class Enterprise < ActiveRecord::Base
|
||||
def strip_url(url)
|
||||
url&.sub(%r{(https?://)?}, '')
|
||||
end
|
||||
|
||||
def correct_instagram_url(url)
|
||||
url && strip_url(url.downcase).sub(%r{www.instagram.com/}, '').sub(%r{instagram.com/},
|
||||
'').delete("@")
|
||||
end
|
||||
|
||||
def instagram
|
||||
correct_instagram_url self[:instagram]
|
||||
end
|
||||
end
|
||||
|
||||
def up
|
||||
Enterprise.where.not(instagram: nil).find_each do |enterprise|
|
||||
enterprise.update!(instagram: enterprise.instagram)
|
||||
enterprise.save!
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
||||
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2022_11_16_095826) do
|
||||
ActiveRecord::Schema.define(version: 2022_12_08_150521) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
Reference in New Issue
Block a user