Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COR-785: 'Agnostic' Webpage URLs #504

Merged
merged 5 commits into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/interactors/get_webpage_feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 14 additions & 1 deletion app/models/webpage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
12 changes: 0 additions & 12 deletions semaphore_ci/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down