From 8e6b74a99fe44cccbbd98b90240005c99cb583f5 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Tue, 19 Jun 2018 23:49:36 +0200 Subject: [PATCH 1/5] Remove duplicated stub --- test/test_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index db0c67fd7..72c0848b4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -77,7 +77,6 @@ def stub_search_random(term, baseproject, opts = {}) # rubocop:enable Metrics/BlockLength xpath = "@project = '#{baseproject}' and contains-ic(@name, '#{term}') and path/project='#{baseproject}'" - stub_content("api.opensuse.org/search/published/binary/id?match=#{URI.escape(xpath)}", builder.to_xml) stub_content("https://api.opensuse.org/search/published/binary/id?match=#{URI.escape(xpath)}", builder.to_xml) end From a9ac4ad1b1032c55f51fe2fe22d5ea6040e38b03 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Wed, 20 Jun 2018 09:12:43 +0200 Subject: [PATCH 2/5] Remove superfluous space in xpath --- app/models/seeker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/seeker.rb b/app/models/seeker.rb index ced2bcffd..183a7ef0b 100644 --- a/app/models/seeker.rb +++ b/app/models/seeker.rb @@ -29,7 +29,7 @@ def self.search(query, baseproject, project = nil, exclude_filter = nil, exclude xpath_items << "contains-ic(@name, " + substring_words + ")" end words.select {|word| word.match(/^".+"$/) }.map {|word| word.gsub("\"", "") }.each do |word| - xpath_items << "@name = '#{word.gsub(/['"()]/, "")}' " + xpath_items << "@name = '#{word.gsub(/['"()]/, "")}'" end xpath_items << "path/project='#{baseproject}'" unless baseproject.blank? xpath_items << "not(contains-ic(@project, '#{exclude_filter}'))" if (!exclude_filter.blank? && project.blank?) From 7a137e8b72b245424d88107b1023f31b632b190c Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Wed, 20 Jun 2018 11:33:24 +0200 Subject: [PATCH 3/5] Show flash notice for default searches also in the single package view When a search has a single result, the result is redirected to the single package details page. It makes sense to show the notice in both cases, and the test checks for it. --- app/views/package/show.html.erb | 2 ++ app/views/search/_default_searches.html.erb | 7 +++++++ app/views/search/_find_results.html.erb | 8 +------- 3 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 app/views/search/_default_searches.html.erb diff --git a/app/views/package/show.html.erb b/app/views/package/show.html.erb index e7e024bfb..db1b03bf9 100644 --- a/app/views/package/show.html.erb +++ b/app/views/package/show.html.erb @@ -1,3 +1,5 @@ +<%= render :partial => 'search/default_searches' if @search_term %> + <% if @packages.blank? %>
diff --git a/app/views/search/_default_searches.html.erb b/app/views/search/_default_searches.html.erb new file mode 100644 index 000000000..cb764a40a --- /dev/null +++ b/app/views/search/_default_searches.html.erb @@ -0,0 +1,7 @@ +<% if DEFAULT_SEARCHES[@search_term] %> +
+
+ <%=DEFAULT_SEARCHES[@search_term].html_safe %> +
+
+<% end %> diff --git a/app/views/search/_find_results.html.erb b/app/views/search/_find_results.html.erb index 2f614d914..a21909ba8 100644 --- a/app/views/search/_find_results.html.erb +++ b/app/views/search/_find_results.html.erb @@ -1,13 +1,7 @@
- <% if DEFAULT_SEARCHES[@search_term] %> -
-
- <%=DEFAULT_SEARCHES[@search_term].html_safe %> -
-
- <% end %> + <%= render :partial => 'search/default_searches' if @search_term %> <%= render :partial => 'search/category_header' if @category %> From cdb9ae6766f6a29c092f955a477dca2f93171131 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Wed, 20 Jun 2018 11:38:22 +0200 Subject: [PATCH 4/5] Add missing stubs for search tests --- test/test_helper.rb | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 72c0848b4..50df651a2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -45,19 +45,27 @@ def stub_search_random(term, baseproject, opts = {}) repo = baseproject.tr(':', '_') project = "home:#{user}" filepath = "#{project.gsub(':', ':/')}/#{repo}/#{arch}/#{file}" - xml.binary do - xml.name bin - xml.project project - xml.package pkg - xml.repository repo - xml.version ver - xml.release rel - xml.arch arch - xml.filename file - xml.filepath filepath - xml.baseproject project - xml.type 'rpm' + exact_match_builder = Nokogiri::XML::Builder.new do |exact_xml| + exact_xml.collection(matches: 1) do + [xml, exact_xml].each do |x| + x.binary do + x.name bin + x.project project + x.package pkg + x.repository repo + x.version ver + x.release rel + x.arch arch + x.filename file + x.filepath filepath + x.baseproject project + x.type 'rpm' + end + end + end end + xpath = "@name = '#{bin}'" + stub_content("https://api.opensuse.org/search/published/binary/id?match=#{URI.escape(xpath)}", exact_match_builder.to_xml) builder_fileinfo = Nokogiri::XML::Builder.new do |info_xml| info_xml.fileinfo(filename: file) do info_xml.name bin @@ -71,6 +79,7 @@ def stub_search_random(term, baseproject, opts = {}) end end stub_content("https://api.opensuse.org/published/#{project}/#{repo}/#{arch}/#{file}?view=fileinfo", builder_fileinfo.to_xml) + stub_content("https://api.opensuse.org/source/#{project}/_attribute/OBS:QualityCategory", "") end end end From 90be335a08f69d34fc7922998302628bf5633cce Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Wed, 20 Jun 2018 13:53:28 +0200 Subject: [PATCH 5/5] Remove no longer needed superfluous space from stub --- test/test_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 50df651a2..1200c4f95 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -100,7 +100,7 @@ def stub_search_random(term, baseproject, opts = {}) stub_remote_file("https://download.opensuse.org/tumbleweed/repo/oss/repodata/#{APPDATA_CHECKSUM}-appdata.xml.gz", "appdata.xml.gz") stub_remote_file("https://download.opensuse.org/tumbleweed/repo/non-oss/repodata/#{APPDATA_NON_OSS_CHECKSUM}-appdata.xml.gz", "appdata-non-oss.xml.gz") - stub_remote_file("https://api.opensuse.org/search/published/binary/id?match=@name%20=%20'pidgin'%20", "pidgin.xml") + stub_remote_file("https://api.opensuse.org/search/published/binary/id?match=@name%20=%20'pidgin'", "pidgin.xml") stub_remote_file("https://api.opensuse.org/published/openSUSE:13.1/standard/i586/pidgin-2.10.7-4.1.3.i586.rpm?view=fileinfo", "pidgin-fileinfo.xml") stub_content("https://api.opensuse.org/source/openSUSE:13.1/_attribute/OBS:QualityCategory", "") end