Skip to content

Commit

Permalink
Merge pull request #30 from katylouise/katylouise/website-683_fix-sor…
Browse files Browse the repository at this point in the history
…t-bug

[WEBSITE-683] Now sort is case and accent insensitive
  • Loading branch information
Angela Ebirim committed Mar 6, 2017
2 parents b3be720 + c6ce2f1 commit c198150
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 11 deletions.
4 changes: 3 additions & 1 deletion lib/parliament/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def sort_by(*parameters)
grom_nodes = @nodes.dup
grom_nodes.delete_if { |node| rejected << node unless parameters.all? { |param| node.respond_to?(param) } }
grom_nodes.sort_by! do |node|
parameters.map { |param| node.send(param) }
parameters.map do |param|
node.send(param).is_a?(String) ? I18n.transliterate(node.send(param).downcase) : node.send(param)
end
end

rejected.concat(grom_nodes)
Expand Down
2 changes: 1 addition & 1 deletion lib/parliament/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Parliament
VERSION = '0.5.3'.freeze
VERSION = '0.5.4'.freeze
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 24 additions & 2 deletions spec/parliament/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@
it 'returns a response sorted by seatIncumbencyStartDate' do
response = Parliament::Request.new(base_url: 'http://localhost:3030').people('2c196540-13f3-4c07-8714-b356912beceb').get
filtered_response = response.filter('http://id.ukpds.org/schema/SeatIncumbency')
sorted_response = filtered_response.sort_by(:seatIncumbencyStartDate)
sorted_response = filtered_response.sort_by(:start_date)

expect(sorted_response.first.seatIncumbencyStartDate).to eq('1987-06-11')
expect(sorted_response.first.start_date).to eq(DateTime.new(1987, 6, 11))
expect(sorted_response[1].start_date).to eq(DateTime.new(1992, 4, 9))
end
end

Expand All @@ -144,5 +145,26 @@
expect(sorted_response[1].personGivenName).to eq('Sarah')
end
end

context 'sorting strings of different cases' do
it 'returns a response sorted by personFamilyName' do
response = Parliament::Request.new(base_url: 'http://localhost:3030').people.get
sorted_response = response.sort_by(:personFamilyName)

expect(sorted_response.first.personGivenName).to eq('Jane')
expect(sorted_response[1].personGivenName).to eq('Alice')
end
end

context 'sorting strings with accents' do
it 'returns a response sorted by personGivenName' do
response = Parliament::Request.new(base_url: 'http://localhost:3030').people.get
sorted_response = response.sort_by(:personGivenName)

expect(sorted_response.first.personGivenName).to eq('Sarah')
expect(sorted_response[1].personGivenName).to eq('Sóley')
expect(sorted_response[2].personGivenName).to eq('Solomon')
end
end
end
end

0 comments on commit c198150

Please sign in to comment.