Skip to content

Commit 4bb721d

Browse files
Merge pull request #174 from sul-dlss/fix_registration
Handle bulk action forms that do not have source properties.
2 parents ec893c3 + 2403590 commit 4bb721d

3 files changed

Lines changed: 34 additions & 7 deletions

File tree

app/controllers/bulk_actions/bulk_action_application_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class BulkActionApplicationController < ApplicationController
99

1010
def new
1111
@bulk_action_form = form_class.new
12-
@bulk_action_form.source = 'results' if @last_search_form.present?
12+
@bulk_action_form.source = 'results' if @last_search_form.present? && @bulk_action_form.respond_to?(:source=)
1313
end
1414

1515
def create
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
5+
RSpec.describe 'Register bulk action' do
6+
let(:user) { create(:user) }
7+
8+
before do
9+
sign_in user
10+
end
11+
12+
describe 'GET new' do
13+
context 'when a last search cookie is present' do
14+
before do
15+
cookies[:last_search] = signed_last_search_cookie
16+
end
17+
18+
it 'renders successfully without error' do
19+
get new_bulk_actions_register_path
20+
21+
expect(response).to have_http_status(:ok)
22+
end
23+
end
24+
end
25+
end

spec/support/cookie_support.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# frozen_string_literal: true
22

3-
def set_last_search_cookie(search_form: SearchForm.new(query: 'test', page: 5), total_results: 10) # rubocop:disable Metrics/AbcSize
3+
def signed_last_search_cookie(search_form: SearchForm.new(query: 'test', page: 5), total_results: 10)
4+
Rails.application
5+
.message_verifier(Rails.application.config.action_dispatch.signed_cookie_salt)
6+
.generate({ form: search_form.attributes, total_results: })
7+
end
8+
9+
def set_last_search_cookie(search_form: SearchForm.new(query: 'test', page: 5), total_results: 10)
410
visit root_path
5-
signed_value = Rails.application
6-
.message_verifier(Rails.application.config.action_dispatch.signed_cookie_salt)
7-
.generate({
8-
form: search_form.attributes, total_results:
9-
})
11+
signed_value = signed_last_search_cookie(search_form:, total_results:)
1012
page.driver.browser.manage.add_cookie(
1113
name: :last_search,
1214
value: signed_value,

0 commit comments

Comments
 (0)