Skip to content
Permalink
Browse files

Merge branch 'master' into ignore_byebug_history

  • Loading branch information...
colby-swandale committed Oct 21, 2019
2 parents 29c04a5 + 982e30f commit 862e9b271dcf44b31af799c3bb78c4133f717a5b
@@ -20,3 +20,4 @@ tags
.idea
chef
.byebug_history
public/assets
@@ -20,7 +20,7 @@ gem "jquery-rails"
gem "kaminari"
gem "mail"
gem "newrelic_rpm"
gem "paul_revere", "~> 3.0.0"
gem "paul_revere", "~> 3.1.0"
gem "pg"
gem "rack"
gem "rack-utf8_sanitizer"
@@ -256,8 +256,8 @@ GEM
parallel (1.17.0)
parser (2.6.2.1)
ast (~> 2.4.0)
paul_revere (3.0.0)
rails (>= 5.0, < 6.0)
paul_revere (3.1.0)
rails (>= 5.0, < 6.1)
pg (0.21.0)
pry (0.12.2)
coderay (~> 1.1.0)
@@ -436,7 +436,7 @@ DEPENDENCIES
minitest
mocha
newrelic_rpm
paul_revere (~> 3.0.0)
paul_revere (~> 3.1.0)
pg
pry-byebug
rack
@@ -5,9 +5,6 @@ def show
return unless params[:query]&.is_a?(String)
@error_msg, @gems = ElasticSearcher.new(params[:query], page: @page).search
limit_total_count if @gems.total_count > Gemcutter::SEARCH_MAX_PAGES * Rubygem.default_per_page

@exact_match = Rubygem.name_is(params[:query]).with_versions.first
redirect_to rubygem_path(@exact_match) if @exact_match && @gems.size == 1
end

def advanced
@@ -7,7 +7,6 @@ class GemTypo

DOWNLOADS_THRESHOLD = 10_000_000
SIZE_THRESHOLD = 4
EXCEPTIONS = %w[strait upguard].freeze

def initialize(rubygem_name)
@rubygem_name = rubygem_name.downcase
@@ -16,7 +15,9 @@ def initialize(rubygem_name)

def protected_typo?
return false if @rubygem_name.size < GemTypo::SIZE_THRESHOLD
return false if GemTypo::EXCEPTIONS.include?(@rubygem_name)

gem_typo_exceptions = GemTypoException.all.pluck(:name)
return false if gem_typo_exceptions.include?(@rubygem_name)

protected_gems.each do |protected_gem|
distance = levenshtein_distance(@rubygem_name, protected_gem)
@@ -0,0 +1,11 @@
class GemTypoException < ApplicationRecord
validates :name, presence: true, uniqueness: { case_sensitive: false }
validate :rubygems_name

private

def rubygems_name
gem = Rubygem.new(name: name)
errors.add :name, "Rubygem validation failed: #{gem.errors.full_messages}" if gem.invalid?(:typo_exception)
end
end
@@ -19,7 +19,7 @@ class Rubygem < ApplicationRecord
uniqueness: { case_sensitive: false },
if: :needs_name_validation?
validate :blacklist_names_exclusion
validate :protected_gem_typo, on: :create
validate :protected_gem_typo, on: :create, unless: -> { Array(validation_context).include?(:typo_exception) }

after_create :update_unresolved
before_destroy :mark_unresolved
@@ -110,9 +110,11 @@
<% end %>
</div>

<div class="t-body">
<h2><%= link_to t('notifiers.show.title'), notifier_path %></h2>
</div>
<% if @user.ownerships.any? %>
<div class="t-body">
<h2><%= link_to t('notifiers.show.title'), notifier_path %></h2>
</div>
<% end %>

<div class="t-body">
<h2><%= t '.delete.delete_profile' %></h2>
@@ -9,17 +9,7 @@
<% if @gems %>
<% @subtitle = t('.subtitle', :query => content_tag(:em, h(params[:query]))) %>

<% if @exact_match %>
<header class="gems__header">
<p class="gems__meter"><%= t '.exact_match' %></p>
</header>
<% content_for :head do %>
<link rel="prerender prefetch" href="<%= rubygem_url(@exact_match) %>">
<% end %>
<%= render partial: 'rubygems/rubygem', object: @exact_match %>
<% end %>

<header class="gems__header push">
<header class="gems__header push--s">
<p class="gems__meter"><%= page_entries_info(@gems, :entry_name => 'gem').html_safe %></p>
</header>

@@ -64,4 +64,31 @@
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker

# Rubygems.org checks for the presence of an env variable called PROFILE that
# switches several settings to a more "production-like" value for profiling
# and benchmarking the application locally. All changes you make to the app
# will require restart.
if ENV['PROFILE']
config.cache_classes = true
config.eager_load = true

config.logger = ActiveSupport::Logger.new(STDOUT)
config.log_level = :info

config.public_file_server.enabled = true
config.public_file_server.headers = {
'Cache-Control' => 'max-age=315360000, public',
'Expires' => 'Thu, 31 Dec 2037 23:55:55 GMT'
}
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
config.assets.compile = false
config.assets.digest = true
config.assets.debug = false

config.active_record.migration_error = false
config.active_record.verbose_query_logs = false
config.action_view.cache_template_loading = true
end
end
@@ -322,7 +322,6 @@ de:
downloads:
updated:
show:
exact_match: Exakte Übereinstimmung
subtitle: für %{query}
month_update:
week_update:
@@ -332,7 +332,6 @@ en:
downloads: Downloads
updated: Updated
show:
exact_match: Exact match
subtitle: for %{query}
month_update: Updated last month (%{count})
week_update: Updated last week (%{count})
@@ -332,7 +332,6 @@ es:
downloads: Descargas
updated: Actualizada
show:
exact_match: Coincidencia exacta
subtitle: para %{query}
month_update: Actualizadas en el último mes (%{count})
week_update: Actualizadas en la última semana (%{count})
@@ -322,7 +322,6 @@ fr:
downloads: Téléchargements
updated: Mis à jour
show:
exact_match: Titre exact
subtitle: pour %{query}
month_update:
week_update:
@@ -322,7 +322,6 @@ ja:
downloads: ダウンロード数
updated: 更新日
show:
exact_match: 完全一致
subtitle: '%{query}の検索結果'
month_update:
week_update:
@@ -322,7 +322,6 @@ nl:
downloads:
updated:
show:
exact_match: Exacte match
subtitle: voor %{query}
month_update:
week_update:
@@ -322,7 +322,6 @@ pt-BR:
downloads:
updated:
show:
exact_match: Busca exata
subtitle: para %{query}
month_update:
week_update:
@@ -322,7 +322,6 @@ zh-CN:
downloads: 下载数
updated: 更新时间
show:
exact_match: 精确匹配
subtitle: "%{query}"
month_update:
week_update:
@@ -322,7 +322,6 @@ zh-TW:
downloads: 下載數
updated: 最後更新時間
show:
exact_match: 完全符合
subtitle: "%{query}"
month_update:
week_update:
@@ -0,0 +1,10 @@
class CreateGemTypoExceptions < ActiveRecord::Migration[5.2]
def change
create_table :gem_typo_exceptions do |t|
t.string :name
t.text :info

t.timestamps
end
end
end
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_04_26_190518) do
ActiveRecord::Schema.define(version: 2019_08_31_172741) do

# These are extensions that must be enabled in order to support this database
enable_extension "hstore"
@@ -67,6 +67,13 @@
t.index ["version_id", "rubygem_id", "count"], name: "index_gem_downloads_on_version_id_and_rubygem_id_and_count"
end

create_table "gem_typo_exceptions", force: :cascade do |t|
t.string "name"
t.text "info"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "linksets", id: :serial, force: :cascade do |t|
t.integer "rubygem_id"
t.string "home"
@@ -101,4 +101,16 @@ namespace :gemcutter do
puts "Done."
end
end

namespace :typo do
desc "Add names to gem typo exception list\nUsage: rake gemcutter:typo:exception[<gem_name>,<info>]"
task :exception, %i[name info] => %i[environment] do |_task, args|
typo_exception = GemTypoException.new(name: args[:name], info: args[:info])
if typo_exception.save
puts "Added #{args[:name]} to gem typo exception"
else
puts "Error while adding typo exception: #{typo_exception.errors.full_messages}"
end
end
end
end
@@ -2,3 +2,4 @@ User-agent: *
Disallow: /downloads/
Disallow: /gems?letter=*
Disallow: /search?*
Disallow: /names
@@ -135,4 +135,8 @@
status { "pending" }
payload { {} }
end

factory :gem_typo_exception do
name
end
end
@@ -84,18 +84,6 @@ class SearchesControllerTest < ActionController::TestCase
end
end

context "on GET to show with search parameters with a single exact match" do
setup do
@sinatra = create(:rubygem, name: "sinatra")
create(:version, rubygem: @sinatra)
import_and_refresh
get :show, params: { query: "sinatra" }
end

should respond_with :redirect
should redirect_to("the gem") { rubygem_path(@sinatra) }
end

context "on GET to show with non string search parameter" do
setup do
get :show, params: { query: { foo: "bar" } }
@@ -1,7 +1,7 @@
require "test_helper"
require "capybara/minitest"

class NoticationSettings < SystemTest
class NotificationSettingsTest < SystemTest
include Capybara::Minitest::Assertions

test "changing email notification settings" do
@@ -46,7 +46,7 @@ class NoticationSettings < SystemTest

visit edit_profile_path(as: user)

assert_no_text I18n.t("profiles.edit.notifier.email_notifications")
assert_no_text I18n.t("notifiers.show.title")
end

def notifier_on_radio(ownership)
@@ -14,7 +14,6 @@ class SearchTest < SystemTest
click_button "search_submit"

assert page.has_content? "LDAP"
assert page.has_content? "Exact match"

assert page.has_content? "LDAP-PLUS"
end
@@ -36,7 +35,6 @@ class SearchTest < SystemTest
rubygem = create(:rubygem, name: "LDAP")
create(:version, rubygem: rubygem, number: "1.1.1", indexed: true)
create(:version, rubygem: rubygem, number: "2.2.2", indexed: false)
create(:version, rubygem: rubygem, number: "3.3.3", indexed: true)
import_and_refresh

visit search_path
@@ -46,7 +44,6 @@ class SearchTest < SystemTest

assert page.has_content?("1.1.1")
refute page.has_content?("2.2.2")
assert page.has_content?("3.3.3")
end

test "search page with a non valid format" do
@@ -0,0 +1,23 @@
require "test_helper"

class GemTypoExceptionTest < ActiveSupport::TestCase
context "name validations" do
should validate_uniqueness_of(:name).case_insensitive

should "be a valid factory" do
assert build(:gem_typo_exception).valid?
end

should "be invalid with an empty string" do
exception = build(:gem_typo_exception, name: "")
refute exception.valid?
end

should "be invalid when gem name exists" do
create(:rubygem, name: "some")

exception = build(:gem_typo_exception, name: "some")
refute exception.valid?
end
end
end
@@ -36,15 +36,10 @@ class GemTypoTest < ActiveSupport::TestCase
end

should "return false for exceptions" do
old_exceptions = GemTypo::EXCEPTIONS
Kernel.silence_warnings do
GemTypo::EXCEPTIONS = %w[fourss].freeze
end
create(:gem_typo_exception, name: "fourss")

gem_typo = GemTypo.new("fourss")
assert_equal false, gem_typo.protected_typo?
Kernel.silence_warnings do
GemTypo::EXCEPTIONS = old_exceptions
end
end

should "return false for three characher distance" do

0 comments on commit 862e9b2

Please sign in to comment.
You can’t perform that action at this time.