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

Fix: rename values with no language tags from "none" to :none #154

Merged
merged 1 commit into from
May 7, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/goo/sparql/mixins/solution_lang_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def set_value(model, predicate, value, &block)
end

if requested_lang.eql?(:ALL) || requested_lang.is_a?(Array)
language = "@none" if no_lang?(language)
language = :none if no_lang?(language)
store_objects_by_lang(model.id, predicate, value, language)
end
end
Expand Down Expand Up @@ -85,9 +85,9 @@ def model_group_by_lang(model)
def group_by_lang(values)
return values.to_a if values.all?{|x| x.is_a?(RDF::URI) || !x.respond_to?(:language) }

values = values.group_by { |x| x.respond_to?(:language) && x.language ? x.language.to_s.downcase.to_sym : "@none" }
values = values.group_by { |x| x.respond_to?(:language) && x.language ? x.language.to_s.downcase.to_sym : :none }

no_lang = values["@none"] || []
no_lang = values[:none] || []
return no_lang if !no_lang.empty? && no_lang.all? { |x| x.respond_to?(:plain?) && !x.plain? }

values
Expand All @@ -113,7 +113,7 @@ def literal?(object)

def store_objects_by_lang(id, predicate, object, language)
# store objects in this format: [id][predicate][language] = [objects]
return if requested_lang.is_a?(Array) && !requested_lang.include?(language.upcase) && !language.eql?('@none')
return if requested_lang.is_a?(Array) && !requested_lang.include?(language.upcase) && !language.eql?(:none)

language_key = language.downcase

Expand Down
4 changes: 2 additions & 2 deletions test/test_languages_filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_one_language
def test_multiple_languages
# select all languages
RequestStore.store[:requested_lang] = :all
expected_result = {:en=>["John Doe"], :fr=>["Jean Dupont"], "@none"=>["Juan Pérez"]}
expected_result = {:en=>["John Doe"], :fr=>["Jean Dupont"], :none=>["Juan Pérez"]}
person = ExamplePerson.find(@@person_id).in(@@db).include(:label).first
assert_equal expected_result.values.flatten.sort, person.label.sort

Expand Down Expand Up @@ -88,7 +88,7 @@ def test_map_attribute_with_languages
assert_equal ["Jean Dupont", "Juan Pérez"].sort, person.label.sort


expected_result = {:en=>["John Doe"], :fr=>["Jean Dupont"], "@none"=>["Juan Pérez"]}
expected_result = {:en=>["John Doe"], :fr=>["Jean Dupont"], :none=>["Juan Pérez"]}
RequestStore.store[:requested_lang] = [:en, :fr]
person = ExamplePerson.find(@@person_id).in(@@db).include(:unmapped).first
ExamplePerson.map_attributes(person)
Expand Down