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

Prevent solr error when missing parent ids #13

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
30 changes: 17 additions & 13 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
type: string
bundler_version:
type: string
default: 2.0.2
default: 2.5.18
ffmpeg_version:
type: string
default: 4.1.4
Expand Down Expand Up @@ -38,18 +38,22 @@ workflows:
ci:
jobs:
- bundle_and_test:
name: "ruby2-7_rails7-0"
ruby_version: "2.7.6"
rails_version: "7.0.4"
name: "ruby3-3_rails7-2"
ruby_version: "3.3.4"
rails_version: "7.2.1"
- bundle_and_test:
name: "ruby2-7_rails6-1"
ruby_version: "2.7.6"
rails_version: "6.1.7"
name: "ruby3-2_rails7-1"
ruby_version: "3.2.5"
rails_version: "7.1.4"
- bundle_and_test:
name: "ruby2-7_rails6-0"
ruby_version: "2.7.6"
rails_version: "6.0.6"
name: "ruby3-1_rails7-1"
ruby_version: "3.1.6"
rails_version: "7.1.4"
- bundle_and_test:
name: "ruby2-7_rails5-2"
ruby_version: "2.7.6"
rails_version: "5.2.8.1"
name: "ruby3-2_rails7-0"
ruby_version: "3.2.5"
rails_version: "7.0.8.4"
- bundle_and_test:
name: "ruby3-1_rails7-0"
ruby_version: "3.1.6"
rails_version: "7.0.8.4"
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ gemspec
gem 'byebug'
gem 'pry-byebug' unless ENV['CI']
gem 'psych', '< 4' # pinned to less than 4 due to ActiveFedora not specifying this restriction

gem 'active-fedora', git: 'https://github.com/samvera/active_fedora.git', branch: 'further_along_the_rails'
9 changes: 9 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ require 'active_fedora/rake_support'
require 'bundler'
Bundler::GemHelper.install_tasks

# This is to fix a breaking change with Ruby 3.2 where some methods
# in fcrepo_wrapper use the removed `File.exists?` alias, preventing
# tests from being set up.
class File
class << self
alias exists? exist?
end
end

masaball marked this conversation as resolved.
Show resolved Hide resolved
require 'rspec/core/rake_task'
desc 'Run tests only'
RSpec::Core::RakeTask.new(:rspec) do |spec|
Expand Down
5 changes: 4 additions & 1 deletion lib/speedy_af/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ def gather_reflections(proxy_hash, opts)

def query_for_belongs_to(proxy_hash, _opts)
proxy_hash.collect do |_id, proxy|
proxy.belongs_to_reflections.collect { |_name, reflection| "id:#{proxy.attrs[predicate_for_reflection(reflection).to_sym]}" }
proxy.belongs_to_reflections.collect do |_name, reflection|
id = proxy.attrs[predicate_for_reflection(reflection).to_sym]
id.blank? ? nil : "id:#{id}"
end.compact
end.flatten.join(" OR ")
end

Expand Down
11 changes: 10 additions & 1 deletion spec/integration/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
end

it '.to_query' do
expect(book.to_query('book_id')).to eq("book_id=#{URI.encode(book.id, /[^\-_.!~*'()a-zA-Z\d;?:@&=+$,\[\]]/)}")
expect(book.to_query('book_id')).to eq("book_id=#{URI::Parser.new.escape(book.id, /[^\-_.!~*'()a-zA-Z\d;?:@&=+$,\[\]]/)}")
end

context 'reflections' do
Expand Down Expand Up @@ -105,6 +105,15 @@
expect(book_presenter).not_to be_real
end

context 'missing parent id' do
let(:book) { Book.new title: 'Ordered Things', publisher: 'ActiveFedora Performance LLC', library: nil }
it 'does not cause belongs_to reflections to error' do
expect(book_presenter.library_id).to be_nil
expect(book_presenter.library).to be_nil
expect(book_presenter).not_to be_real
end
end

context 'preloaded subresources' do
let(:book_presenter) { described_class.find(book.id, load_reflections: true) }

Expand Down
1 change: 0 additions & 1 deletion speedy-af.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Gem::Specification.new do |s|
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {spec}/*`.split("\n")

s.add_dependency 'active-fedora', '>= 11.0.0'
s.add_dependency 'activesupport', '> 5.2'
s.add_development_dependency 'solr_wrapper'
s.add_development_dependency 'fcrepo_wrapper'
Expand Down