Skip to content
Closed
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ group :development, :test do
gem 'factory_bot_rails', '~> 6.5.0'
gem 'jettywrapper', '>=1.4.0', git: 'https://github.com/samvera-deprecated/jettywrapper.git', branch: 'master'
# gem 'json_spec'
gem 'rails-controller-testing'
gem 'rspec-its', '~> 2.0.0'
gem 'rspec-rails', '~> 8.0.0'
gem 'selenium-webdriver', '~> 4.11'
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@ GEM
activesupport (= 8.0.4)
bundler (>= 1.15.0)
railties (= 8.0.4)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
activesupport (>= 5.0.1.rc1)
rails-dom-testing (2.3.0)
activesupport (>= 5.0.0)
minitest
Expand Down Expand Up @@ -760,6 +764,7 @@ DEPENDENCIES
premailer-rails
puma (~> 5.2)
rails (= 8.0.4)
rails-controller-testing
rainbow
resque (~> 2.7.0)
resque-scheduler (>= 4.10.2)
Expand Down
2 changes: 1 addition & 1 deletion app/components/blacklight/search_bar_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<% before_input_groups.each do |input_group| %>
<%= input_group %>
<% end %>
<div class="input-group bradley">
<div class="input-group">
<%= prepend %>

<% if search_fields.length > 1 %>
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/users/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def new
render 'users/sessions/new'
end

# This is needed if not using database authenticable (see https://github.com/heartcombo/devise/wiki/OmniAuth:-Overview#using-omniauth-without-other-authentications)
# This is needed if not using database authenticatable (see https://github.com/heartcombo/devise/wiki/OmniAuth:-Overview#using-omniauth-without-other-authentications)
def new_session_path(scope)
new_user_session_path # this accomodates Users namespace of the controller
new_user_session_path # this accommodates Users namespace of the controller
end

private
Expand Down
6 changes: 3 additions & 3 deletions app/models/site_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# like you would if accessing a typical singleton class in Ruby
class SiteConfiguration < ApplicationRecord
SINGLETON_GUARD_VALUE = 0
DOWNLOADS_ENABLED_MESSAGE_DEF = 'Downloading has been temporarily disabled for Academic Commons. Contact an administrator for more information.' # rubocop:disable Layout/LineLength
DOWNLOADS_DISABLED_MESSAGE_DEFAULT = 'Downloading has been temporarily disabled for Academic Commons. Contact an administrator for more information.' # rubocop:disable Layout/LineLength

# The singleton_guard column is a unique column that must be set to 0
# This ensures that only one record of type SiteConfiguration is ever created
Expand All @@ -22,7 +22,7 @@ class SiteConfiguration < ApplicationRecord
def self.instance
where(singleton_guard: 0).first_or_create! do |site_config|
site_config.downloads_enabled = true
site_config.downloads_message = DOWNLOADS_ENABLED_MESSAGE_DEF
site_config.downloads_message = DOWNLOADS_DISABLED_MESSAGE_DEFAULT
site_config.deposits_enabled = true
site_config.alert_message = ''
site_config.singleton_guard = SINGLETON_GUARD_VALUE
Expand All @@ -34,7 +34,7 @@ def self.downloads_enabled
end

def self.downloads_message
return DOWNLOADS_ENABLED_MESSAGE_DEF if instance.downloads_message == ''
return DOWNLOADS_DISABLED_MESSAGE_DEFAULT if instance.downloads_message == ''

instance.downloads_message
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/email_preferences/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

<%= form_with model: [:admin, @email_preference], local: true, data: { turbo: false } do |f| %>
<%= form_with model: [:admin, @email_preference], local: true, id: 'email-preference-form', data: { turbo: false } do |f| %>
<p>
<%= f.label :uni %>
<%= f.text_field :uni %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% title 'Admin' %>

<p class="admin-intro-message">
Choose an item from the Adminstration menu.
Choose an item from the Administration menu.
</p>
14 changes: 8 additions & 6 deletions app/views/admin/site_configurations/_alert_message_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<%= form_with url: admin_site_configuration_path, method: :patch, local: true, data: { turbo: false } do |form| %>
<div>
<%= form.text_area :alert_message, value: SiteConfiguration.alert_message %>
</div>
<%= form.submit 'Submit', class: 'btn btn-primary' %>
<% end %>
<div id='alert-message-form'>
<%= form_with url: admin_site_configuration_path, method: :patch, local: true do |form| %>
<div>
<%= form.text_area :alert_message, value: SiteConfiguration.alert_message %>
</div>
<%= form.submit 'Submit', class: 'btn btn-primary' %>
<% end %>
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="mt-3">
<div class="mt-3" id='downloads-message-form'>
<%= form_with url: admin_site_configuration_path, method: :patch, local: true, data: { turbo: false } do |form| %>
<%= form.text_area :downloads_message, value: SiteConfiguration.downloads_message %>
<%= form.submit 'Save Message', class: 'btn btn-primary' %>
Expand Down
22 changes: 12 additions & 10 deletions app/views/admin/site_configurations/_toggle_deposits_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<%= form_with url: admin_site_configuration_path, method: :patch, local: true, data: { turbo: false } do |form| %>
<% if SiteConfiguration.deposits_enabled %>
<% action_label = "Disable Deposits" %>
<% enable = false %>
<% else %>
<% action_label = "Enable Deposits" %>
<% enable = true %>
<div id='deposits-toggle-form'>
<%= form_with url: admin_site_configuration_path, method: :patch, local: true, data: { turbo: false } do |form| %>
<% if SiteConfiguration.deposits_enabled %>
<% action_label = "Disable Deposits" %>
<% enable = false %>
<% else %>
<% action_label = "Enable Deposits" %>
<% enable = true %>
<% end %>
<%= form.hidden_field :deposits_enabled, value: enable %>
<%= form.submit action_label, class: "btn btn-primary" %>
<% end %>
<%= form.hidden_field :deposits_enabled, value: enable %>
<%= form.submit action_label, class: "btn btn-primary" %>
<% end %>
</div>
26 changes: 14 additions & 12 deletions app/views/admin/site_configurations/_toggle_downloads_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<%= form_with url: admin_site_configuration_path, method: :patch, local: true, data: { turbo: false } do |form| %>
<% if SiteConfiguration.downloads_enabled %>
<% action_label = "Disable Downloads" %>
<% enable = false %>
<% else %>
<% action_label = "Enable Downloads" %>
<% enable = true %>
<div id='downloads-toggle-form'>
<%= form_with url: admin_site_configuration_path, method: :patch, local: true, data: { turbo: false } do |form| %>
<% if SiteConfiguration.downloads_enabled %>
<% action_label = "Disable Downloads" %>
<% enable = false %>
<% else %>
<% action_label = "Enable Downloads" %>
<% enable = true %>
<% end %>
<div>
<%= form.hidden_field :downloads_enabled, value: enable %>
<%= form.submit action_label, class: "btn btn-primary" %>
</div>
<% end %>
<div>
<%= form.hidden_field :downloads_enabled, value: enable %>
<%= form.submit action_label, class: "btn btn-primary" %>
</div>
<% end %>
</div>
2 changes: 2 additions & 0 deletions app/views/errors/forbidden.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<%# ERROR CODE 403 %>

<h2>Forbidden</h2>

<p>You do not have access.</p>
Expand Down
2 changes: 2 additions & 0 deletions app/views/errors/internal_server_error.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<%# ERROR CODE 500 %>

<h2>Internal Server Error</h2>

<p>The server has encountered an unexpected error.</p>
2 changes: 2 additions & 0 deletions app/views/errors/not_found.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<%# ERROR CODE 404 %>

<h2>Not Found</h2>

<p>The page you are looking for doesn't exist. Please try again or visit our <%= link_to 'homepage', root_path %>.</p>
2 changes: 2 additions & 0 deletions app/views/errors/record_not_found.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<%# ERROR CODE 404 for Blacklight Records %>

<h2>Record Not Found</h2>

<p>This item does not exist in Academic Commons or may have been removed.</p>
Expand Down
2 changes: 1 addition & 1 deletion app/views/user/my_works.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<% unless @pending_works.empty? %>
<h3>Pending Works</h3>
<table class="table small">
<table class="table small" id="pending-works-table">
<% @pending_works.each do |document| %>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See rationale above - could this become 'data-id'?

<tr>
<td><%= document.title %></td>
Expand Down
10 changes: 10 additions & 0 deletions spec/factories/email_preference.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

FactoryBot.define do
factory :email_preference do
id { 1 }
uni { 'testuser' }
unsubscribe { false }
email { 'testuser@example.com' }
end
end
122 changes: 122 additions & 0 deletions spec/features/admin/email_preferences_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# frozen_string_literal: true

require 'rails_helper'

describe 'admin email preferences management', type: :feature do
include_context 'admin user for feature'

before do
FactoryBot.create(:email_preference)
end

it 'redirects to login if not authorized' do
logout(:user)
visit admin_email_preferences_path
expect(page).to have_current_path new_user_session_path
end

context 'when visiting email preferences index page' do
before do
visit admin_email_preferences_path
end

it 'displays the email preferences list' do
expect(page).to have_content 'Email Preferences'
expect(page).to have_content 'testuser@example.com'
end

it 'has link to create new email preference' do
expect(page).to have_link 'Create New Email Preference', href: new_admin_email_preference_path
end

it 'has edit buttons for each email preference' do
expect(page).to have_link 'Edit', href: edit_admin_email_preference_path(EmailPreference.first)
end

it 'has delete buttons for each email preference' do
expect(page).to have_button 'Destroy'
end
end

context 'when creating a new email preference' do
before do
visit new_admin_email_preference_path
end

it 'has the email preference form' do
expect(page).to have_content 'New Email Preference'
expect(page).to have_selector('[id="email-preference-form"]')
end

it 'has a go back to index link' do
expect(page).to have_link 'Back to Email Preferences', href: admin_email_preferences_path
end

it 'flashes error when creating with missing uni' do
fill_in 'email_preference[uni]', with: ''
click_button 'Create Email preference'
expect(page).to have_css 'div.alert-dismissible'
end

it 'displays the created email preference when successful' do
fill_in 'email_preference[uni]', with: 'newuser123'
check 'email_preference[unsubscribe]'
fill_in 'email_preference[email]', with: 'newuser123preference@example.com'
click_button 'Create Email preference'
expect(page).to have_content 'Email Preference'
expect(page).to have_content 'newuser123'
expect(page).to have_content 'true'
expect(page).to have_content 'newuser123preference@example.com'
end

it 'flashes success message when created successfully' do
fill_in 'email_preference[uni]', with: 'newuser123'
check 'email_preference[unsubscribe]'
fill_in 'email_preference[email]', with: 'newuser123preference@example.com'
click_button 'Create Email preference'
expect(page).to have_content 'Successfully created email preference.'
end

context 'when editing an existing email preference' do
before do
visit edit_admin_email_preference_path(EmailPreference.first)
end

it 'has the email preference form' do
expect(page).to have_content 'Edit Email Preference'
expect(page).to have_selector('[id="email-preference-form"]')
end

it 'displays existing values in the form fields' do
expect(find_field('email_preference[uni]').value).to eq 'testuser'
expect(find_field('email_preference[unsubscribe]').checked?).to be false
expect(find_field('email_preference[email]').value).to eq 'testuser@example.com'
end

it 'has a go back to index link' do
expect(page).to have_link 'Back to Email Preferences', href: admin_email_preferences_path
end

it 'flashes error when updating with missing uni' do
fill_in 'email_preference[uni]', with: ''
click_button 'Update Email preference'
expect(page).to have_css 'div.alert-dismissible'
end

it 'displays the updated email preference when successful' do
check 'email_preference[unsubscribe]'
fill_in 'email_preference[email]', with: 'updateduser@example.com'
click_button 'Update Email preference'
expect(page).to have_content 'testuser' # not changed
expect(page).to have_content 'true'
expect(page).to have_content 'updateduser@example.com'
end

it 'flashes success message when updated successfully' do
fill_in 'email_preference[email]', with: 'updateduser123@example.com'
click_button 'Update Email preference'
expect(page).to have_content 'Successfully updated email preference.'
end
end
end
end
38 changes: 38 additions & 0 deletions spec/features/admin/featured_search_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,48 @@
fill_in 'featured_search[url]', with: feature_url
fill_in 'featured_search[description]', with: description
click_button 'Submit'
sleep(1) # unfortunately, without this many of these tests fail indeterminately
end

it 'renders document title' do
expect(page).to have_content "Edit featured search at #{slug}"
end

describe 'after creating a featured search', js: false do
let(:new_featured_search) { FeaturedSearch.find_by(slug: slug) }
it 'appears in the list features panel' do
visit admin_featured_searches_path
expect(page).to have_content 'Featured Searches'
expect(page).to have_content slug
end

it 'has slug link to edit the featured search' do
visit admin_featured_searches_path
expect(page).to have_link slug, href: edit_admin_featured_search_path(new_featured_search)
end

it 'has filter-value link to edit the featured search' do
visit admin_featured_searches_path
expect(page).to have_link filter_value, href: edit_admin_featured_search_path(new_featured_search)
end

it 'the slug is a valid search link' do
visit "/detail/#{new_featured_search.slug}"
expect(page).to have_current_path("/search?f%5Bfeatured_search%5D%5B%5D=#{new_featured_search.slug}")
end

it 'has link to delete the featured search' do
visit admin_featured_searches_path
expect(page).to have_link 'Delete', href: admin_featured_search_path(new_featured_search)
end

it 'clicking delete renders a confirmation dialog', js: true do
visit admin_featured_searches_path
accept_confirm do
click_link 'Delete', href: admin_featured_search_path(new_featured_search)
end
expect(page).to have_content "Deleted feature at #{slug}!"
end
end
end
end
Loading
Loading