diff --git a/backend/spec/requests/posts_spec.rb b/backend/spec/requests/posts_spec.rb index c5c0f04..bdea3af 100644 --- a/backend/spec/requests/posts_spec.rb +++ b/backend/spec/requests/posts_spec.rb @@ -290,19 +290,23 @@ RSpec.describe 'Posts API', type: :request do [:title, :url].each do |field| context "when #{field} contains wildcards" do let!(:search_posts) do - ['needle%25end', 'needleX25end', 'needle_end', 'needleXend', 'needleABend'].map do |value| - Post.create!(uploaded_user: user, title: "prefix #{value} suffix", - url: "https://example.com/prefix-#{value}-suffix") + ['needle%25end', 'needleX25end', 'needle_end', 'needleXend', 'needleABend', 'needle%25_end'].map.with_index do |value, index| + Post.create!(uploaded_user: user, + title: field == :title ? "prefix #{value} suffix" : 'url search post', + url: field == :url ? "https://example.com/prefix-#{value}-suffix" : + "https://example.com/title-search-#{index}") end end { 'needle%25end' => [0], 'needle_end' => [2], - 'needle*end' => [0, 1, 2, 3, 4], + 'needle*end' => [0, 1, 2, 3, 4, 5], 'needle?end' => [2, 3], - 'needle%*end' => [0], - 'needle_?nd' => [2] + 'needle%*end' => [0, 5], + 'needle_?nd' => [2], + 'needle%25_end' => [5], + 'needle%25_*end' => [5] }.each do |query, expected_indices| it "matches #{query.inspect} using only * and ? as wildcards" do get '/posts', params: { field => query }