Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
Since upgrading to ruby 2.6.x there have been some tests failures. This commit
fixes this situation by upgrading some gems.

Moreover, since 1e5d2ac, the UrlValidator class
was not being called by the webhook model. I had to re-arrange things a bit to
make this part of the code work again.

Signed-off-by: Miquel Sabaté Solà <msabate@suse.com>
  • Loading branch information
mssola committed Feb 22, 2019
1 parent 1e5d2ac commit 262291a
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 73 deletions.
90 changes: 46 additions & 44 deletions Gemfile.lock
Expand Up @@ -44,7 +44,7 @@ GEM
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.5.2)
addressable (2.6.0)
public_suffix (>= 2.0.2, < 4.0)
aes_key_wrap (1.0.1)
annotate (2.7.4)
Expand All @@ -55,7 +55,7 @@ GEM
arel (9.0.0)
ast (2.4.0)
attr_required (1.0.1)
autoprefixer-rails (9.4.3)
autoprefixer-rails (9.4.8)
execjs
awesome_print (1.8.0)
axiom-types (0.1.1)
Expand All @@ -68,13 +68,13 @@ GEM
bindex (0.5.0)
binman (5.1.0)
opener (>= 0.1.0, < 1)
bootstrap-sass (3.4.0)
bootstrap-sass (3.4.1)
autoprefixer-rails (>= 5.2.1)
sassc (>= 2.0.0)
brakeman (4.3.1)
brakeman (4.4.0)
builder (3.2.3)
byebug (10.0.2)
capybara (3.10.1)
byebug (11.0.0)
capybara (3.13.2)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
Expand Down Expand Up @@ -104,7 +104,7 @@ GEM
database_cleaner (1.7.0)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
devise (4.5.0)
devise (4.6.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0, < 6.0)
Expand All @@ -116,16 +116,16 @@ GEM
excon (>= 0.47.0)
multi_json
equalizer (0.0.11)
erubi (1.7.1)
ethon (0.11.0)
erubi (1.8.0)
ethon (0.12.0)
ffi (>= 1.3.0)
excon (0.62.0)
execjs (2.7.0)
factory_bot (4.11.1)
activesupport (>= 3.0.0)
factory_bot_rails (4.11.1)
factory_bot (~> 4.11.1)
railties (>= 3.0.0)
factory_bot (5.0.1)
activesupport (>= 4.2.0)
factory_bot_rails (5.0.1)
factory_bot (~> 5.0.0)
railties (>= 4.2.0)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
ffaker (2.10.0)
Expand All @@ -140,9 +140,9 @@ GEM
octokit (~> 2.0.0)
yajl-ruby
gli (2.8.1)
globalid (0.4.1)
globalid (0.4.2)
activesupport (>= 4.2.0)
grape (1.2.2)
grape (1.2.3)
activesupport
builder
mustermann-grape (~> 1.0.0)
Expand All @@ -157,10 +157,10 @@ GEM
grape-swagger-entity (0.3.2)
grape-entity (>= 0.5.0)
grape-swagger (>= 0.31.0)
grape-swagger-rails (0.3.0)
grape-swagger-rails (0.3.1)
railties (>= 3.2.12)
gravatar_image_tag (1.2.0)
guard (2.14.2)
guard (2.15.0)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
lumberjack (>= 1.0.12, < 2.0)
Expand All @@ -177,13 +177,13 @@ GEM
guard-rubocop (1.3.0)
guard (~> 2.0)
rubocop (~> 0.20)
hashdiff (0.3.7)
hashdiff (0.3.8)
hashie (3.6.0)
hashie-forbidden_attributes (0.1.1)
hashie (>= 3.0)
hirb (0.7.3)
httpclient (2.8.3)
i18n (1.5.2)
i18n (1.5.3)
concurrent-ruby (~> 1.0)
ice_nine (0.11.2)
io-like (0.3.0)
Expand Down Expand Up @@ -223,7 +223,7 @@ GEM
marcel (0.3.3)
mimemagic (~> 0.3.2)
method_source (0.9.2)
mimemagic (0.3.2)
mimemagic (0.3.3)
mini_mime (1.0.1)
mini_portile2 (2.4.0)
minitest (5.11.3)
Expand All @@ -237,7 +237,7 @@ GEM
nenv (0.3.0)
net-ldap (0.16.1)
nio4r (2.3.1)
nokogiri (1.9.1)
nokogiri (1.10.1)
mini_portile2 (~> 2.4.0)
notiffany (0.1.1)
nenv (~> 0.1)
Expand Down Expand Up @@ -285,36 +285,37 @@ GEM
validate_url
webfinger (>= 1.0.1)
orm_adapter (0.5.0)
paint (2.0.1)
paint (2.1.0)
parallel (1.13.0)
parser (2.6.0.0)
ast (~> 2.4.0)
pg (1.1.3)
pg (1.1.4)
poltergeist (1.18.1)
capybara (>= 2.1, < 4)
cliver (~> 0.3.1)
websocket-driver (>= 0.2.0)
polyglot (0.3.5)
powerpack (0.1.2)
pry (0.12.0)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-rails (0.3.7)
pry-rails (0.3.9)
pry (>= 0.10.4)
psych (3.1.0)
public_activity (1.6.3)
actionpack (>= 3.0.0)
activerecord (>= 3.0)
i18n (>= 0.5.0)
railties (>= 3.0.0)
public_suffix (3.0.3)
puma (3.12.0)
pundit (2.0.0)
pundit (2.0.1)
activesupport (>= 3.0.0)
rack (2.0.6)
rack-accept (0.4.5)
rack (>= 0.4)
rack-cors (1.0.2)
rack-mini-profiler (1.0.0)
rack-mini-profiler (1.0.2)
rack (>= 1.2.0)
rack-oauth2 (1.9.3)
activesupport
Expand All @@ -340,10 +341,10 @@ GEM
bundler (>= 1.3.0)
railties (= 5.2.2)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.2)
actionpack (~> 5.x, >= 5.0.1)
actionview (~> 5.x, >= 5.0.1)
activesupport (~> 5.x)
rails-controller-testing (1.0.4)
actionpack (>= 5.0.1.x)
actionview (>= 5.0.1.x)
activesupport (>= 5.0.1.x)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
Expand All @@ -366,10 +367,10 @@ GEM
rb-inotify (0.10.0)
ffi (~> 1.0)
redcarpet (3.4.0)
regexp_parser (1.2.0)
responders (2.4.0)
actionpack (>= 4.2.0, < 5.3)
railties (>= 4.2.0, < 5.3)
regexp_parser (1.3.0)
responders (2.4.1)
actionpack (>= 4.2.0, < 6.0)
railties (>= 4.2.0, < 6.0)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
Expand All @@ -382,7 +383,7 @@ GEM
rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-rails (3.8.1)
rspec-rails (3.8.2)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
Expand All @@ -391,11 +392,12 @@ GEM
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rubocop (0.63.1)
rubocop (0.65.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1)
psych (>= 3.1.0)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.4.0)
Expand Down Expand Up @@ -427,7 +429,7 @@ GEM
shoulda-context (~> 1.0, >= 1.0.1)
shoulda-matchers (~> 3.0)
shoulda-context (1.2.2)
shoulda-matchers (3.1.2)
shoulda-matchers (3.1.3)
activesupport (>= 4.0.0)
simplecov (0.16.1)
docile (~> 1.1)
Expand All @@ -451,15 +453,15 @@ GEM
temple (0.8.0)
thor (0.20.3)
thread_safe (0.3.6)
tilt (2.0.8)
tilt (2.0.9)
timecop (0.9.1)
treetop (1.6.10)
polyglot (~> 0.3)
typhoeus (1.3.1)
ethon (>= 0.9.0)
tzinfo (1.2.5)
thread_safe (~> 0.1)
uglifier (4.1.19)
uglifier (4.1.20)
execjs (>= 0.3.0, < 3)
unicode-display_width (1.4.1)
uri_template (0.5.3)
Expand All @@ -475,8 +477,8 @@ GEM
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
equalizer (~> 0.0, >= 0.0.9)
warden (1.2.7)
rack (>= 1.0)
warden (1.2.8)
rack (>= 2.0.6)
web-console (3.7.0)
actionview (>= 5.0)
activemodel (>= 5.0)
Expand All @@ -485,7 +487,7 @@ GEM
webfinger (1.1.0)
activesupport
httpclient (>= 2.4)
webmock (3.4.2)
webmock (3.5.1)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
Expand Down
10 changes: 1 addition & 9 deletions app/models/webhook.rb
Expand Up @@ -45,15 +45,7 @@ class Webhook < ApplicationRecord
has_many :deliveries, class_name: "WebhookDelivery", dependent: :destroy, inverse_of: "webhook"
has_many :headers, class_name: "WebhookHeader", dependent: :destroy, inverse_of: "webhook"

validates :url, presence: true, url: true

# default to http if no protocol has been specified. If unspecified, the URL
# validator will fail.
before_validation do
unless url.nil? || url.blank?
self.url = "http://#{url}" unless url.start_with?("http://", "https://")
end
end
validates :url, presence: true, http: true

before_destroy :update_activities!

Expand Down
31 changes: 31 additions & 0 deletions app/validators/http_validator.rb
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require "uri"

# Validates URLs and transforms them into valid ones if needed.
class HttpValidator < ActiveModel::EachValidator
# Validator for the url.
def validate_each(record, attribute, value)
uri = URI.parse(value)
return if uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)
return if generic_enforce_valid(record, uri, value)

record.errors[attribute] << "is not a valid URL"
rescue URI::InvalidURIError
record.errors[attribute] << "is not a valid URL"
end

# It returns true if the given uri is URI::Generic and the value does not
# start like "ftp://". In this case, it will modify the record so the url is
# set to its proper value.
def generic_enforce_valid(record, uri, value)
return false unless uri.is_a?(URI::Generic)

if value.match(%r{^\w+://.+}).nil?
record.url = "http://" + value
true
else
false
end
end
end
16 changes: 0 additions & 16 deletions app/validators/url_validator.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/tasks/annotate.rake
@@ -1,6 +1,6 @@
# frozen_string_literal: true

if (Rails.env.development? || Rails.env.test?) && ENV["CI"].blank?
if Rails.env.development? && ENV["CI"].blank?
require "annotate"
require "portus/db"

Expand Down
5 changes: 4 additions & 1 deletion spec/models/webhook_spec.rb
Expand Up @@ -33,8 +33,11 @@
it { is_expected.to have_many(:deliveries) }
it { is_expected.to belong_to(:namespace) }

it { is_expected.to validate_presence_of(:url) }
it { is_expected.to allow_value("example.org").for(:url) }
it { is_expected.not_to allow_value("won't work").for(:url) }
it { is_expected.not_to allow_value("ftp:///home/mssola").for(:url) }

it { is_expected.to validate_presence_of(:url) }
it { is_expected.to define_enum_for(:request_method) }
it { is_expected.to allow_value(*request_methods).for(:request_method) }
it { is_expected.to define_enum_for(:content_type) }
Expand Down
5 changes: 3 additions & 2 deletions spec/system/repositories_spec.rb
Expand Up @@ -310,8 +310,9 @@ def find_tag_checkbox(name)
end
end

# TODO: this is flaky on Travis CI for some reason.
if ENV["CI"].blank?
# TODO: this is consistently failing since ruby 2.6.x. Before it was only
# flaky on Travis CI.
if ENV["ALL"].present?
it "A user deletes a repository by deleting all tags" do
%w[lorem ipsum].each_with_index do |digest, idx|
create(:tag, name: "tag#{idx}", author: user, repository: repository, digest: digest,
Expand Down

0 comments on commit 262291a

Please sign in to comment.