Skip to content

Commit

Permalink
Merge pull request #3435 from DMPRoadmap/aaron/rails7-copy
Browse files Browse the repository at this point in the history
Fix PostgreSQL GitHub Action and Tests For Rails 7 Upgrade
  • Loading branch information
aaronskiba committed Aug 19, 2024
2 parents bda5b6e + 5d06d6b commit d2a1eac
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
# Stub out the Rails credentials file so that we can start the Rails app
- name: 'Setup Credentials'
run: EDITOR='echo "$(cat config/credentials.yml.mysql2)" >' bundle exec rails credentials:edit
run: EDITOR="sh -c 'echo \"$(cat config/credentials.yml.mysql2)\" > \$1' --" bundle exec rails credentials:edit

# Set the path to the wkhtmltopdf executable
- name: 'Determine wkhtmltopdf location'
Expand All @@ -54,8 +54,8 @@ jobs:

- name: 'Build out the test database'
run: |
bundle exec rails db:create RAILS_ENV=test
bundle exec rails db:schema:load RAILS_ENV=test
DISABLE_SPRING=1 bundle exec rails db:create RAILS_ENV=test
DISABLE_SPRING=1 bundle exec rails db:schema:load RAILS_ENV=test
- name: 'Run any pending database migrations'
run: bin/rails db:migrate RAILS_ENV=test
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
- name: 'Setup Credentials'
run: |
# generate a default credential file and key
EDITOR='echo "$(cat config/credentials.yml.postgresql)" >' bundle exec rails credentials:edit
EDITOR="sh -c 'echo \"$(cat config/credentials.yml.postgresql)\" > \$1' --" bundle exec rails credentials:edit
# Set the path to the wkhtmltopdf executable
- name: 'Determine wkhtmltopdf location'
Expand All @@ -79,7 +79,7 @@ jobs:
# Initialize the DB
- name: 'Setup Test DB'
run: |
bundle exec rails db:setup RAILS_ENV=test
DISABLE_SPRING=1 bundle exec rails db:setup RAILS_ENV=test
bundle exec rails db:migrate RAILS_ENV=test
# Prebuild the CSS, JS and image assets
Expand Down
9 changes: 5 additions & 4 deletions app/javascript/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ import './src/superAdmin/notifications/edit';
import './src/superAdmin/themes/newEdit';
import './src/superAdmin/users/edit';

// Since we're using Webpacker to manage JS we need to startup Rails' Unobtrusive JS
// and Turbo. ActiveStorage and ActionCable would also need to be in here
// if we decide to implement either before Rails 6
require('@rails/ujs').start();
// We need to startup Rails' Unobtrusive JS and Turbo.
// ActiveStorage and ActionCable would also need
// to be in here if we decide to implement either.
import Rails from "@rails/ujs";
Rails.start();

// TODO: Disabled turbo for the time being because our custom JS is not
// properly setup to work with it. We should review the docs:
Expand Down
2 changes: 1 addition & 1 deletion app/models/org.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class Org < ApplicationRecord
before_validation :check_for_missing_logo_file

# This gives all managed orgs api access whenever saved or updated.
before_save :ensure_api_access, if: lambda(&:managed?)
before_save :ensure_api_access, if: -> { managed? }

# If the physical logo file is no longer on disk we do not want it to prevent the
# model from saving. This typically happens when you copy the database to another
Expand Down
2 changes: 1 addition & 1 deletion app/models/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class Template < ApplicationRecord
# overwriting the accessors. We want to ensure this template is published
# before we remove the published_version
# That being said, there's a potential race_condition where we have multiple-published-versions
after_update :reconcile_published, if: lambda(&:published?)
after_update :reconcile_published, if: -> { published? }

# ==========
# = Scopes =
Expand Down
5 changes: 4 additions & 1 deletion app/views/org_admin/templates/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
placement: 'right' }%>
<div class="form-check">
<%= f.label(:visibility) do %>
<%= f.check_box(:visibility, checked: f.object.visibility == 'organisationally_visible') %>
<%= f.check_box(:visibility,
{ checked: f.object.organisationally_visible? },
f.object.class.visibilities[:organisationally_visible],
f.object.class.visibilities[:publicly_visible]) %>
<%= _('for internal %{org_name} use only') % { org_name: f.object.org.name } %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/org_admin/templates/_show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<!-- If the Org is a funder and another org type then allow then to set the visibility -->
<dt><%= _('Visibility') %></dt>
<dd>
<% if template.visibility == 'organisationally_visible' %>
<% if template.organisationally_visible? %>
<%= _('for internal %{org_name} use only') % {org_name: template.org.name} %>
<% else %>
<%= _('available to the public') + (template.published? ? '' : ' (once published)') %>
Expand Down
2 changes: 1 addition & 1 deletion bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if valid_db
cp ".env.#{db_adapter}", '.env'

puts "\n== Preparing credentials file =="
system! "EDITOR='echo \"$(cat config/credentials.yml.#{db_adapter})\" >' bin/rails credentials:edit"
system!("EDITOR=\"sh -c 'echo \\\"$(cat config/credentials.yml.#{db_adapter})\\\" > \\\"\\\$1\\\"' --\" bin/rails credentials:edit")

# Set the editor based on the platform
ENV['EDITOR'] = Gem.win_platform? ? 'code --wait' : 'vim'
Expand Down
4 changes: 2 additions & 2 deletions spec/models/template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@
end

it 'sets visibility to Organisationally visible' do
expect(subject.visibility).to eql(Template.visibilities['organisationally_visible'])
expect(subject.organisationally_visible?).to eql(true)
end

it 'sets is_default to false' do
Expand Down Expand Up @@ -1152,7 +1152,7 @@
end

it 'sets the visibility to Organisationally visible' do
expect(subject.visibility).to eql(Template.visibilities['organisationally_visible'])
expect(subject.organisationally_visible?).to eql(true)
end

it 'sets is_default to false' do
Expand Down
6 changes: 3 additions & 3 deletions spec/requests/api/v1/authentication_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@

it 'calls the Api::Jwt::AuthenticationService' do
Api::V1::Auth::Jwt::AuthenticationService.any_instance.expects(:call).at_most(1)
post api_v1_authenticate_path, params: @payload.to_json
post api_v1_authenticate_path, params: @payload, as: :json
end
it 'renders /api/v1/error template if authentication fails' do
errs = [Faker::Lorem.sentence]
Api::V1::Auth::Jwt::AuthenticationService.any_instance
.stubs(:call).returns(nil)
.stubs(:errors).returns(errs)
post api_v1_authenticate_path, params: @payload.to_json
post api_v1_authenticate_path, params: @payload, as: :json
expect(response.code).to eql('401')
expect(response).to render_template('api/v1/error')
end
it 'returns a JSON Web Token' do
token = Api::V1::Auth::Jwt::JsonWebToken.encode(payload: @payload)
Api::V1::Auth::Jwt::AuthenticationService.any_instance.stubs(:call)
.returns(token)
post api_v1_authenticate_path, params: @payload.to_json
post api_v1_authenticate_path, params: @payload, as: :json
expect(response.code).to eql('200')
expect(response).to render_template('api/v1/token')
end
Expand Down

0 comments on commit d2a1eac

Please sign in to comment.