Skip to content

Commit

Permalink
case-insensitive gem search
Browse files Browse the repository at this point in the history
  • Loading branch information
trusche committed Nov 20, 2024
1 parent 191cdb6 commit a0d3248
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 44 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ storage
tmp

public/sitemap.xml.gz

app/assets/builds
public/assets
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ In order to set up the application locally:

1. `git clone git@github.com:railsbump/app.git`
2. `bin/setup`
3. `foreman start -f Procfile.dev`
4. Go to http://localhost:3000
3. `rake data:find_or_create_rails_releases`
4. `foreman start -f Procfile.dev`
5. Go to http://localhost:3000

If these steps don't work, please submit a new issue: https://github.com/railsbump/app/issues/new

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/releases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def create
if name == "rails"
RailsReleases::Create.perform_async params.fetch(:version)
else
Gemmy.find_by(name: name)&.then {
Gemmy.find_by_name(name)&.then {
Gemmies::Process.perform_async _1.id
}
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/gemmies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def index
end

def show
@gemmy = Gemmy.find_by!(name: params[:id])
@gemmy = Gemmy.find_by_name!(params[:id])
end

def compat_table
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/rails_releases_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class RailsReleasesController < ApplicationController
def show
@gemmy = Gemmy.find_by!(name: params[:gemmy_id])
@gemmy = Gemmy.find_by_name!(params[:gemmy_id])
@rails_release = RailsRelease.find_by!(version: params[:id].gsub("rails-", "").gsub("-", "."))
end
end
end
11 changes: 11 additions & 0 deletions app/models/gemmy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ class Gemmy < ApplicationRecord

delegate :to_param, :to_s, to: :name

# Find existing by case-insensitive name
def self.find_by_name(name, raise_error: false)
find_by!("LOWER(name) = ?", name.downcase)
rescue ActiveRecord::RecordNotFound => e
raise e if raise_error
end

def self.find_by_name!(name)
find_by_name(name, raise_error: true)
end

# Check all pending compats for compatibility
def check_compatibility
compats.pending.each do |compat|
Expand Down
2 changes: 1 addition & 1 deletion app/models/lockfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def add_gemmies
return if gemmies.any?

gem_names.each do |gem_name|
gemmy = Gemmy.find_by(name: gem_name) || Gemmies::Create.call(gem_name)
gemmy = Gemmy.find_by_name(gem_name) || Gemmies::Create.call(gem_name)
self.gemmies << gemmy
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/gemmies/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def call(name)
raise Error, "Please enter a name."
end

if existing_gemmy = Gemmy.find_by(name: name)
if existing_gemmy = Gemmy.find_by_name(name)
raise AlreadyExists.new(existing_gemmy)
end

Expand Down
66 changes: 34 additions & 32 deletions config/sitemap.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
require "fog-aws"
unless Rails.env.local?
require "fog-aws"

SitemapGenerator::Sitemap.default_host = "https://www.railsbump.org"
SitemapGenerator::Sitemap.public_path = "tmp/sitemaps/" # Temporary storage before uploading to S3
SitemapGenerator::Sitemap.adapter = SitemapGenerator::S3Adapter.new(
fog_provider: "AWS",
fog_directory: "railsbump.org",
fog_region: ENV["AWS_REGION"],
aws_bucket: "railsbump.org",
aws_access_key_id: ENV["AWS_ACCESS_KEY_ID"],
aws_secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
aws_region: ENV["AWS_REGION"]
)
SitemapGenerator::Sitemap.default_host = "https://www.railsbump.org"
SitemapGenerator::Sitemap.public_path = "tmp/sitemaps/" # Temporary storage before uploading to S3
SitemapGenerator::Sitemap.adapter = SitemapGenerator::S3Adapter.new(
fog_provider: "AWS",
fog_directory: "railsbump.org",
fog_region: ENV["AWS_REGION"],
aws_bucket: "railsbump.org",
aws_access_key_id: ENV["AWS_ACCESS_KEY_ID"],
aws_secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
aws_region: ENV["AWS_REGION"]
)

opts = {
create_index: true,
default_host: "https://www.railsbump.org",
compress: false,
public_path: "/tmp",
sitemaps_host: ENV["FOG_URL"],
sitemaps_path: ""
}
opts = {
create_index: true,
default_host: "https://www.railsbump.org",
compress: false,
public_path: "/tmp",
sitemaps_host: ENV["FOG_URL"],
sitemaps_path: ""
}

rails_releases = RailsRelease.order(:version).to_a
rails_releases = RailsRelease.order(:version).to_a

SitemapGenerator::Sitemap.create opts do
# Add static paths
add root_path, changefreq: "daily", priority: 1.0
add new_gemmy_path, changefreq: "monthly"
add new_lockfile_path, changefreq: "monthly"
SitemapGenerator::Sitemap.create opts do
# Add static paths
add root_path, changefreq: "daily", priority: 1.0
add new_gemmy_path, changefreq: "monthly"
add new_lockfile_path, changefreq: "monthly"

# Add dynamic paths for all gemmies
Gemmy.find_each do |gemmy|
add gemmy_path(gemmy), lastmod: gemmy.last_checked_at, changefreq: "weekly", priority: 0.8
# Add dynamic paths for all gemmies
Gemmy.find_each do |gemmy|
add gemmy_path(gemmy), lastmod: gemmy.last_checked_at, changefreq: "weekly", priority: 0.8

rails_releases.each do |rails_release|
add gemmy_rails_release_path(gemmy, rails_release)
rails_releases.each do |rails_release|
add gemmy_rails_release_path(gemmy, rails_release)
end
end
end
end
end
8 changes: 4 additions & 4 deletions spec/controllers/gemmies_controllers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
context "when the gemmy params are valid" do
it "redirects to the new gemmy page" do
post :create, params: { gemmy: { name: "next_rails" } }
expect(response).to redirect_to(gemmy_path(Gemmy.find_by(name: "next_rails")))

expect(response).to redirect_to(gemmy_path(Gemmy.find_by_name("next_rails")))
end

it "creates a record in the database" do
Expand All @@ -18,7 +18,7 @@
context "when the gemmy params are invalid" do
it "renders the new gemmy page" do
post :create, params: { gemmy: { name: "" } }

expect(response).to render_template(:new)
end

Expand All @@ -30,4 +30,4 @@
end
end
end
end
end

0 comments on commit a0d3248

Please sign in to comment.