Add command to filter by tag
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
class Command::FilterByTag < Command
|
||||
store_accessor :data, :tag_id, :params
|
||||
|
||||
validates_presence_of :tag_id
|
||||
|
||||
def title
|
||||
"Filter by tag ##{tag&.title || tag_id} "
|
||||
end
|
||||
|
||||
def execute
|
||||
redirect_to cards_path(**params.merge(tag_ids: [ tag_id ]))
|
||||
end
|
||||
|
||||
private
|
||||
def tag
|
||||
Tag.find_by_id(tag_id)
|
||||
end
|
||||
end
|
||||
@@ -23,6 +23,8 @@ class Command::Parser
|
||||
Command::Assign.new(assignee_ids: assignees_from(command_arguments).collect(&:id), card_ids: cards.ids)
|
||||
when "/close"
|
||||
Command::Close.new(card_ids: cards.ids, reason: command_arguments.join(" "))
|
||||
when /^#/
|
||||
Command::FilterByTag.new(tag_id: tag_from(string).id, params: filter.as_params)
|
||||
when /^@/
|
||||
Command::GoToUser.new(user_id: assignee_from(command_name)&.id)
|
||||
else
|
||||
@@ -44,6 +46,11 @@ class Command::Parser
|
||||
User.all.find { |user| user.mentionable_handles.include?(string_without_at) }
|
||||
end
|
||||
|
||||
def tag_from(string)
|
||||
title = string.gsub(/^#/, "")
|
||||
Tag.find_or_create_by!(title: title)
|
||||
end
|
||||
|
||||
def parse_free_string(string)
|
||||
if cards = multiple_cards_from(string)
|
||||
Command::FilterCards.new(card_ids: cards.ids, params: filter.as_params)
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
require "test_helper"
|
||||
|
||||
class Command::FilterByCardTest < ActionDispatch::IntegrationTest
|
||||
include CommandTestHelper
|
||||
|
||||
setup do
|
||||
@tag = tags(:web)
|
||||
end
|
||||
|
||||
test "redirects to the cards index filtering by cards" do
|
||||
result = execute_command "##{@tag.title}"
|
||||
|
||||
assert_equal cards_path(indexed_by: "newest", tag_ids: [ @tag.id ]), result.url
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user