Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NZSL-164: Show the database version in the footer #1525

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/models/signbank/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ class Record < ApplicationRecord
# to create test records
after_initialize { readonly! unless Rails.env.test? }

def self.database_version
connection.execute('PRAGMA user_version').first['user_version']
end

##
# Useful for testing - related Signbank records don't have primary keys,
# so in this case we consider them equal if they are the same type and
Expand Down
27 changes: 17 additions & 10 deletions app/views/shared/_footer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,24 @@
</div>
<div class="copyright">
<div class="small-10 small-centered medium-8 large-6">
<% if @footer && @footer.first_part %>
<%= link_to((image_tag "https://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png"), "https://creativecommons.org/licenses/by-nc-sa/3.0", target:"_blank" ) %>
<div class="footer-link">
NZSL Dictionary by
<%= link_to "Deaf Studies Research Unit, Victoria University of Wellington", "https://www.victoria.ac.nz/lals/research/projects/dsru.aspx", target: "_blank" %>
is licensed under a
<%= link_to "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.","https://creativecommons.org/licenses/by-nc-sa/4.0/", target: "_blank" %>
<br/>
<%= link_to 'View in NZSL', @footer.path %>
</div>
<%= link_to "https://creativecommons.org/licenses/by-nc-sa/3.0", target:"_blank" do %>
<%= image_tag "https://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png", alt: "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License badge" %>
<% end %>

<div class="footer-link">
NZSL Dictionary by
<%= link_to "Deaf Studies Research Unit, Victoria University of Wellington", "https://www.victoria.ac.nz/lals/research/projects/dsru.aspx", target: "_blank" %>
is licensed under a
<%= link_to "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.","https://creativecommons.org/licenses/by-nc-sa/4.0/", target: "_blank" %>

<% if (version = Signbank::Record.database_version) %>
<br />
Database version <%= version %>.
<% end %>

<br/>
<%= link_to 'View in NZSL', @footer.path if @footer && @footer.first_part %>
</div>
</div>
</div>
</footer>
14 changes: 14 additions & 0 deletions spec/models/signbank/record_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'rails_helper'

RSpec.describe Signbank::Record do
describe '.database_version' do
it 'returns the user version of the database' do
version = 42
allow(Signbank::Record.connection).to receive(:execute)
.with('PRAGMA user_version')
.and_return([{ 'user_version' => version }])

expect(Signbank::Record.database_version).to eq(version)
end
end
end
15 changes: 15 additions & 0 deletions spec/views/shared/_footer.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'rails_helper'

RSpec.describe 'shared/_footer.html.erb' do
it 'renders the database version when available' do
allow(Signbank::Record).to receive(:database_version).and_return(123_456)
render partial: 'shared/footer', locals: { last: false }
expect(rendered).to include 'Database version 123456'
end

it 'does not render the database version if it is unavailable' do
allow(Signbank::Record).to receive(:database_version).and_return(nil)
render partial: 'shared/footer', locals: { last: false }
expect(rendered).not_to include 'Database version 123456'
end
end
Loading