diff --git a/app/interactors/get_webpage_feed.rb b/app/interactors/get_webpage_feed.rb index 294b55456..4c50a76e9 100644 --- a/app/interactors/get_webpage_feed.rb +++ b/app/interactors/get_webpage_feed.rb @@ -4,7 +4,8 @@ class GetWebpageFeed def call webpage = ::Webpage webpage = webpage.find_by_tenant_id(context.tenant) if context.tenant - webpage = webpage.find_by_protocol_agnostic_url(protocol_agnostic_url(context.params.url)).first + webpage = webpage.agnostic_find_by_url(context.params.url) + context.webpage = webpage end diff --git a/app/models/webpage.rb b/app/models/webpage.rb index 6c815ec61..26124304e 100644 --- a/app/models/webpage.rb +++ b/app/models/webpage.rb @@ -5,7 +5,7 @@ class Webpage < ApplicationRecord serialize :tables_widget serialize :charts_widget - scope :find_by_protocol_agnostic_url, ->(suffix) { where('url LIKE :suffix', suffix: "%#{suffix}") } + scope :agnostic_guess_by_url, ->(url) { where('url LIKE :url', url: "%#{url}%") } acts_as_paranoid acts_as_taggable_on :seo_keywords @@ -16,6 +16,11 @@ class Webpage < ApplicationRecord accepts_nested_attributes_for :snippets + def self.agnostic_find_by_url(url) + url = protocol_agnostic_url(url) + agnostic_guess_by_url(url).find { |webpage| protocol_agnostic_url(webpage.url) == url } + end + def tables_widget_yaml tables_widget.to_yaml end @@ -63,4 +68,12 @@ def accordion_group_widget_json def accordion_group_widget_json= p self.accordion_group_widget = JSON.parse(p, quirks_mode: true) # Quirks mode will let us parse a null JSON object end + + private + + def self.protocol_agnostic_url(url) + uri = Addressable::URI.parse(url) + path = uri.path == '/' ? uri.path : uri.path.chomp('/') + "://#{uri.authority}#{path}" + end end diff --git a/semaphore_ci/setup.sh b/semaphore_ci/setup.sh index ab8f4123b..9676e380b 100755 --- a/semaphore_ci/setup.sh +++ b/semaphore_ci/setup.sh @@ -16,18 +16,6 @@ bundle exec rake bower:install:development echo "bundle exec rake webpack:ensure_assets_compiled" bundle exec rake webpack:ensure_assets_compiled -echo "ES Install" -sudo service elasticsearch stop -if ! [ -e .semaphore-cache/elasticsearch-2.4.1.deb ]; then (cd .semaphore-cache; curl -OL https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-2.4.1.deb); fi -sudo dpkg -i --force-confnew .semaphore-cache/elasticsearch-2.4.1.deb -sudo service elasticsearch start - -echo "sleep 5" -sleep 5 - -echo "ES Version Check" -curl -XGET 'http://localhost:9200' - echo "bundle exec rake db:setup" bundle exec rake db:setup