From 1a879357643717acad82125d8db6d73af05a6b2b Mon Sep 17 00:00:00 2001 From: BrokenEagle Date: Tue, 23 Jun 2020 05:46:25 +0000 Subject: [PATCH] Fix the tag matches option The split function was mistakenly used instead of the match function. --- app/models/post_version.rb | 2 +- test/functional/post_versions_controller_test.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/post_version.rb b/app/models/post_version.rb index a6be23df2..a38ee2779 100644 --- a/app/models/post_version.rb +++ b/app/models/post_version.rb @@ -33,7 +33,7 @@ class PostVersion < ApplicationRecord end def tag_matches(string) - tag = string.split(/\S+/)[0] + tag = string.match(/\S+/)[0] return all if tag.nil? tag = "*#{tag}*" unless tag =~ /\*/ where_ilike(:tags, tag) diff --git a/test/functional/post_versions_controller_test.rb b/test/functional/post_versions_controller_test.rb index a57914cff..521d99adb 100644 --- a/test/functional/post_versions_controller_test.rb +++ b/test/functional/post_versions_controller_test.rb @@ -41,6 +41,13 @@ class PostVersionsControllerTest < ActionDispatch::IntegrationTest assert_response :success assert_equal @post.versions[1].id, response.parsed_body[0]["id"].to_i end + + should "list all versions for search[tag_matches]" do + get post_versions_path, as: :json, params: { search: { tag_matches: "tagme" }} + assert_response :success + assert_equal @post.versions[0].id, response.parsed_body[0]["id"].to_i + assert_equal 1, response.parsed_body.length + end end context "undo action" do