Skip to content

Commit 00a09ce

Browse files
authored
Merge pull request #5264 from alphagov/audit-ruby
Add Ruby version to applications page
2 parents 41cfe9f + 9f596d7 commit 00a09ce

File tree

5 files changed

+34
-8
lines changed

5 files changed

+34
-8
lines changed

app/controllers/govuk_publishing_components/applications_page_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def applications_data(applications)
4040
gem_version: app.gem_version,
4141
gem_version_status: app.gem_version == GovukPublishingComponents::VERSION ? "green" : "red",
4242
sass_version: app.sass_version,
43+
ruby_version: app.ruby_version,
4344
}
4445
end
4546
end

app/models/govuk_publishing_components/applications_page.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ class ApplicationsPage
55
def initialize(application)
66
@application = application
77
@dir = get_directory
8-
@gemfilelock = get_gemfile
8+
@gemfilelock = get_file("Gemfile.lock")
9+
@rubyfile = get_file(".ruby-version")
910
end
1011

1112
def readable_name
@@ -20,27 +21,31 @@ def sass_version
2021
parse_file(@gemfilelock, /sass-embedded \(([^)>=~ ]+)\)/)
2122
end
2223

24+
def ruby_version
25+
@rubyfile.strip if @rubyfile
26+
end
27+
2328
private
2429

2530
def get_directory
2631
app_dir = "#{File.expand_path('..')}/#{@application}"
2732
Dir.exist?(app_dir) ? app_dir : false
2833
end
2934

30-
def get_gemfile
31-
@dir ? get_gemfile_local : get_gemfile_remote
35+
def get_file(name)
36+
@dir ? get_local_file(name) : get_remote_file(name)
3237
end
3338

34-
def get_gemfile_local
35-
lockfile = "#{@dir}/Gemfile.lock"
39+
def get_local_file(name)
40+
lockfile = "#{@dir}/#{name}"
3641
return unless File.file?(lockfile)
3742

3843
@source = "local"
3944
File.read(lockfile)
4045
end
4146

42-
def get_gemfile_remote
43-
uri = URI("https://raw.githubusercontent.com/alphagov/#{@application}/main/Gemfile.lock")
47+
def get_remote_file(name)
48+
uri = URI("https://raw.githubusercontent.com/alphagov/#{@application}/main/#{name}")
4449
result = Net::HTTP.get_response(uri)
4550
if result.is_a?(Net::HTTPSuccess)
4651
@source = "remote"

app/views/govuk_publishing_components/applications_page/_table-content.html.erb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,12 @@
2828
} %>
2929
<% end %>
3030
</td>
31+
<td class="govuk-table__cell">
32+
<% if app[:ruby_version] %>
33+
<%= render "govuk_publishing_components/components/tag", {
34+
text: app[:ruby_version],
35+
} %>
36+
<% end %>
37+
</td>
3138
</tr>
3239
<% end %>

app/views/govuk_publishing_components/applications_page/show.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<th scope="col" class="govuk-table__header sticky-table-header">Source</th>
2525
<th scope="col" class="govuk-table__header sticky-table-header">Gem version</th>
2626
<th scope="col" class="govuk-table__header sticky-table-header">Sass version</th>
27+
<th scope="col" class="govuk-table__header sticky-table-header">Ruby version</th>
2728
</tr>
2829
</thead>
2930
<tbody class="govuk-table__body">

spec/component_guide/applications_page_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,28 @@
1818
govuk_personalisation (>= 0.7.0)
1919
terser (1.2.6)
2020
execjs (>= 0.3.0, < 3)"
21+
fake_ruby_file = "3.2.1\n"
2122

2223
describe "when the app is found locally" do
2324
before do
2425
allow(Dir).to receive(:exist?).and_return(true)
2526
end
2627

27-
it "returns all information" do
28+
it "can read the gemfile.lock" do
2829
allow(File).to receive_messages(file?: true, read: fake_gemfile)
2930
app = GovukPublishingComponents::ApplicationsPage.new(fake_app)
3031
expect(app.source).to eq("local")
3132
expect(app.gem_version).to eq("61.3.1")
3233
expect(app.sass_version).to eq("1.93.2")
3334
end
3435

36+
it "can read the ruby version" do
37+
allow(File).to receive_messages(file?: true, read: fake_ruby_file)
38+
app = GovukPublishingComponents::ApplicationsPage.new(fake_app)
39+
expect(app.source).to eq("local")
40+
expect(app.ruby_version).to eq("3.2.1")
41+
end
42+
3543
it "returns incomplete information" do
3644
allow(File).to receive_messages(file?: true, read: fake_gemfile_partial)
3745
app = GovukPublishingComponents::ApplicationsPage.new(fake_app)
@@ -44,20 +52,24 @@
4452
describe "when the app is not found locally" do
4553
it "returns no information if the app is not available remotely" do
4654
stub_request(:get, "https://raw.githubusercontent.com:443/alphagov/#{fake_app}/main/Gemfile.lock").to_return(status: 404, body: "", headers: {})
55+
stub_request(:get, "https://raw.githubusercontent.com:443/alphagov/#{fake_app}/main/.ruby-version").to_return(status: 404, body: "", headers: {})
4756

4857
app = GovukPublishingComponents::ApplicationsPage.new(fake_app)
4958
expect(app.source).to be_nil
5059
expect(app.gem_version).to be_nil
5160
expect(app.sass_version).to be_nil
61+
expect(app.ruby_version).to be_nil
5262
end
5363

5464
it "returns all information if the app is available remotely" do
5565
stub_request(:get, "https://raw.githubusercontent.com:443/alphagov/#{fake_app}/main/Gemfile.lock").to_return(status: 200, body: fake_gemfile, headers: {})
66+
stub_request(:get, "https://raw.githubusercontent.com:443/alphagov/#{fake_app}/main/.ruby-version").to_return(status: 200, body: fake_ruby_file, headers: {})
5667

5768
app = GovukPublishingComponents::ApplicationsPage.new(fake_app)
5869
expect(app.source).to eq("remote")
5970
expect(app.gem_version).to eq("61.3.1")
6071
expect(app.sass_version).to eq("1.93.2")
72+
expect(app.ruby_version).to eq("3.2.1")
6173
end
6274
end
6375
end

0 commit comments

Comments
 (0)