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

ANW-1182: bugfix for 500 error thrown in date calculator #2561

Merged
merged 2 commits into from
Jan 24, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend/app/controllers/date_calculator_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def calculate

def create_date
begin
date = JSONModel(:date).from_hash(params[:date].to_hash)
date = params.require(:date).permit(JSONModel(:date).schema["properties"].keys).to_hash
date = JSONModel(:date).from_hash(date)

record = JSONModel(params[:record_type].intern).find(params[:record_id])

Expand Down
34 changes: 34 additions & 0 deletions frontend/spec/controllers/date_calculator_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

require 'spec_helper'
require 'rails_helper'

describe DateCalculatorController, type: :controller do
render_views

before(:each) do
set_repo($repo)
end

it "manages 4 digit years in params" do
allow(controller).to receive(:user_must_have).and_return(true)
resource = create(:json_resource)
allow(JSONModel(:resource)).to receive(:find).and_return(resource)

params = { "record_uri" => resource.uri,
"record_type" => "resource",
"record_id" => resource.id, "date"=>{"lock_version"=>"", "label"=>"creation", "expression"=>"", "date_type"=>"inclusive", "begin"=>"1900", "end"=>"1901", "certainty"=>"", "era"=>"", "calendar"=>""}
}

user = build(:json_user).save(password: "saa2020")
user = User.find(user)
group = create(:json_group,
member_usernames: [user.username],
grants_permissions: ["view_repository", "update_resource_record", "delete_event_record"])
session = User.login(user.username, "saa2020")
User.establish_session(controller, session, user.username)
controller.send(:load_repository_list)
post :create_date, params: params
expect(response.status).to eq(200)
end
end