Skip to content

Commit a0d3248

Browse files
committed
case-insensitive gem search
1 parent 191cdb6 commit a0d3248

File tree

10 files changed

+61
-44
lines changed

10 files changed

+61
-44
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ storage
2121
tmp
2222

2323
public/sitemap.xml.gz
24+
25+
app/assets/builds
26+
public/assets

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ In order to set up the application locally:
4747

4848
1. `git clone [email protected]:railsbump/app.git`
4949
2. `bin/setup`
50-
3. `foreman start -f Procfile.dev`
51-
4. Go to http://localhost:3000
50+
3. `rake data:find_or_create_rails_releases`
51+
4. `foreman start -f Procfile.dev`
52+
5. Go to http://localhost:3000
5253

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

app/controllers/api/releases_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def create
66
if name == "rails"
77
RailsReleases::Create.perform_async params.fetch(:version)
88
else
9-
Gemmy.find_by(name: name)&.then {
9+
Gemmy.find_by_name(name)&.then {
1010
Gemmies::Process.perform_async _1.id
1111
}
1212
end

app/controllers/gemmies_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def index
2323
end
2424

2525
def show
26-
@gemmy = Gemmy.find_by!(name: params[:id])
26+
@gemmy = Gemmy.find_by_name!(params[:id])
2727
end
2828

2929
def compat_table
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class RailsReleasesController < ApplicationController
22
def show
3-
@gemmy = Gemmy.find_by!(name: params[:gemmy_id])
3+
@gemmy = Gemmy.find_by_name!(params[:gemmy_id])
44
@rails_release = RailsRelease.find_by!(version: params[:id].gsub("rails-", "").gsub("-", "."))
55
end
6-
end
6+
end

app/models/gemmy.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ class Gemmy < ApplicationRecord
99

1010
delegate :to_param, :to_s, to: :name
1111

12+
# Find existing by case-insensitive name
13+
def self.find_by_name(name, raise_error: false)
14+
find_by!("LOWER(name) = ?", name.downcase)
15+
rescue ActiveRecord::RecordNotFound => e
16+
raise e if raise_error
17+
end
18+
19+
def self.find_by_name!(name)
20+
find_by_name(name, raise_error: true)
21+
end
22+
1223
# Check all pending compats for compatibility
1324
def check_compatibility
1425
compats.pending.each do |compat|

app/models/lockfile.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def add_gemmies
4141
return if gemmies.any?
4242

4343
gem_names.each do |gem_name|
44-
gemmy = Gemmy.find_by(name: gem_name) || Gemmies::Create.call(gem_name)
44+
gemmy = Gemmy.find_by_name(gem_name) || Gemmies::Create.call(gem_name)
4545
self.gemmies << gemmy
4646
end
4747
end

app/services/gemmies/create.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def call(name)
3131
raise Error, "Please enter a name."
3232
end
3333

34-
if existing_gemmy = Gemmy.find_by(name: name)
34+
if existing_gemmy = Gemmy.find_by_name(name)
3535
raise AlreadyExists.new(existing_gemmy)
3636
end
3737

config/sitemap.rb

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
1-
require "fog-aws"
1+
unless Rails.env.local?
2+
require "fog-aws"
23

3-
SitemapGenerator::Sitemap.default_host = "https://www.railsbump.org"
4-
SitemapGenerator::Sitemap.public_path = "tmp/sitemaps/" # Temporary storage before uploading to S3
5-
SitemapGenerator::Sitemap.adapter = SitemapGenerator::S3Adapter.new(
6-
fog_provider: "AWS",
7-
fog_directory: "railsbump.org",
8-
fog_region: ENV["AWS_REGION"],
9-
aws_bucket: "railsbump.org",
10-
aws_access_key_id: ENV["AWS_ACCESS_KEY_ID"],
11-
aws_secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
12-
aws_region: ENV["AWS_REGION"]
13-
)
4+
SitemapGenerator::Sitemap.default_host = "https://www.railsbump.org"
5+
SitemapGenerator::Sitemap.public_path = "tmp/sitemaps/" # Temporary storage before uploading to S3
6+
SitemapGenerator::Sitemap.adapter = SitemapGenerator::S3Adapter.new(
7+
fog_provider: "AWS",
8+
fog_directory: "railsbump.org",
9+
fog_region: ENV["AWS_REGION"],
10+
aws_bucket: "railsbump.org",
11+
aws_access_key_id: ENV["AWS_ACCESS_KEY_ID"],
12+
aws_secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
13+
aws_region: ENV["AWS_REGION"]
14+
)
1415

15-
opts = {
16-
create_index: true,
17-
default_host: "https://www.railsbump.org",
18-
compress: false,
19-
public_path: "/tmp",
20-
sitemaps_host: ENV["FOG_URL"],
21-
sitemaps_path: ""
22-
}
16+
opts = {
17+
create_index: true,
18+
default_host: "https://www.railsbump.org",
19+
compress: false,
20+
public_path: "/tmp",
21+
sitemaps_host: ENV["FOG_URL"],
22+
sitemaps_path: ""
23+
}
2324

24-
rails_releases = RailsRelease.order(:version).to_a
25+
rails_releases = RailsRelease.order(:version).to_a
2526

26-
SitemapGenerator::Sitemap.create opts do
27-
# Add static paths
28-
add root_path, changefreq: "daily", priority: 1.0
29-
add new_gemmy_path, changefreq: "monthly"
30-
add new_lockfile_path, changefreq: "monthly"
27+
SitemapGenerator::Sitemap.create opts do
28+
# Add static paths
29+
add root_path, changefreq: "daily", priority: 1.0
30+
add new_gemmy_path, changefreq: "monthly"
31+
add new_lockfile_path, changefreq: "monthly"
3132

32-
# Add dynamic paths for all gemmies
33-
Gemmy.find_each do |gemmy|
34-
add gemmy_path(gemmy), lastmod: gemmy.last_checked_at, changefreq: "weekly", priority: 0.8
33+
# Add dynamic paths for all gemmies
34+
Gemmy.find_each do |gemmy|
35+
add gemmy_path(gemmy), lastmod: gemmy.last_checked_at, changefreq: "weekly", priority: 0.8
3536

36-
rails_releases.each do |rails_release|
37-
add gemmy_rails_release_path(gemmy, rails_release)
37+
rails_releases.each do |rails_release|
38+
add gemmy_rails_release_path(gemmy, rails_release)
39+
end
3840
end
3941
end
40-
end
42+
end

spec/controllers/gemmies_controllers_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
context "when the gemmy params are valid" do
66
it "redirects to the new gemmy page" do
77
post :create, params: { gemmy: { name: "next_rails" } }
8-
9-
expect(response).to redirect_to(gemmy_path(Gemmy.find_by(name: "next_rails")))
8+
9+
expect(response).to redirect_to(gemmy_path(Gemmy.find_by_name("next_rails")))
1010
end
1111

1212
it "creates a record in the database" do
@@ -18,7 +18,7 @@
1818
context "when the gemmy params are invalid" do
1919
it "renders the new gemmy page" do
2020
post :create, params: { gemmy: { name: "" } }
21-
21+
2222
expect(response).to render_template(:new)
2323
end
2424

@@ -30,4 +30,4 @@
3030
end
3131
end
3232
end
33-
end
33+
end

0 commit comments

Comments
 (0)