Remove code related to Fizzy Do /command support and filtering
https://3.basecamp.com/2914079/buckets/37331921/messages/8961776532
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class Command::AddCardTest < ActionDispatch::IntegrationTest
|
||||
include CommandTestHelper
|
||||
|
||||
setup do
|
||||
Current.session = sessions(:david)
|
||||
@card = cards(:text)
|
||||
end
|
||||
|
||||
test "create a new untitled card" do
|
||||
result = assert_difference -> { users(:david).accessible_cards.count }, +1 do
|
||||
execute_command "/add", context_url: collection_card_url(@card.collection, @card)
|
||||
end
|
||||
|
||||
new_card = users(:david).accessible_cards.last
|
||||
assert_equal "", new_card.title
|
||||
assert_equal @card.collection, new_card.collection
|
||||
assert_equal collection_card_path(new_card.collection, new_card, focus_on_title: true), result.url
|
||||
end
|
||||
|
||||
test "create a new titled card" do
|
||||
result = assert_difference -> { users(:david).accessible_cards.count }, +1 do
|
||||
execute_command "/add Review report", context_url: collection_card_url(@card.collection, @card)
|
||||
end
|
||||
|
||||
new_card = users(:david).accessible_cards.last
|
||||
assert_equal "Review report", new_card.title
|
||||
assert_equal @card.collection, new_card.collection
|
||||
assert_equal collection_card_path(new_card.collection, new_card, focus_on_title: true), result.url
|
||||
end
|
||||
|
||||
test "undo card creation" do
|
||||
command = parse_command "/add", context_url: collection_cards_url(@card.collection)
|
||||
command.execute
|
||||
|
||||
assert_difference -> { users(:david).accessible_cards.count }, -1 do
|
||||
command.undo
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,43 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class Command::Ai::ParserTest < ActionDispatch::IntegrationTest
|
||||
include CommandTestHelper, VcrTestHelper
|
||||
|
||||
setup do
|
||||
freeze_timestamps
|
||||
end
|
||||
|
||||
test "parse command strings into a composite command containing the individual commands" do
|
||||
command = parse_command "assign @kevin and close"
|
||||
|
||||
assert_equal "assign @kevin and close", command.line
|
||||
assert_instance_of Command::Composite, command
|
||||
commands = command.commands
|
||||
|
||||
assert_instance_of Command::Assign, commands.first
|
||||
assert_instance_of Command::Close, commands.last
|
||||
end
|
||||
|
||||
test "resolve filter string params as ids" do
|
||||
command = parse_command "cards assigned to kevin, tagged with #web, in the collection writebook"
|
||||
|
||||
url = command.commands.first.url
|
||||
query_string = URI.parse(url).query
|
||||
params = Rack::Utils.parse_nested_query(query_string).with_indifferent_access
|
||||
|
||||
assert_equal [ users(:kevin).id.to_s ], params[:assignee_ids]
|
||||
assert_equal [ collections(:writebook).id.to_s ], params[:collection_ids]
|
||||
assert_equal [ tags(:web).id.to_s ], params[:tag_ids]
|
||||
end
|
||||
|
||||
test "if the AI translator emitted an unknown command, this will result in a regular search (not on AI recursion)" do
|
||||
Command::Ai::Translator.any_instance.stubs(:translate).returns(commands: [ "/missing" ])
|
||||
|
||||
command = parse_command "assign @kevin and close"
|
||||
assert command.commands.one?
|
||||
|
||||
search_command = command.commands.first
|
||||
assert search_command.is_a?(Command::Search)
|
||||
assert_equal "/missing", search_command.terms
|
||||
end
|
||||
end
|
||||
@@ -1,196 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class Command::Ai::TranslatorTest < ActionDispatch::IntegrationTest
|
||||
include VcrTestHelper
|
||||
|
||||
setup do
|
||||
@user = users(:david)
|
||||
|
||||
freeze_timestamps
|
||||
end
|
||||
|
||||
test "filter by assignments" do
|
||||
# List context
|
||||
assert_command({ context: { assignee_ids: [ "jz" ] } }, "cards assigned to jz")
|
||||
assert_command({ context: { assignee_ids: [ "jz" ] } }, "issues assigned to jz")
|
||||
assert_command({ context: { assignee_ids: [ "jz" ] } }, "bugs assigned to jz")
|
||||
assert_command({ context: { assignee_ids: [ "kevin" ] } }, "stuff assigned to kevin")
|
||||
assert_command({ context: { assignee_ids: [ "jz" ] } }, "assigned to jz")
|
||||
assert_command({ context: { assignment_status: "unassigned" } }, "unassigned cards")
|
||||
assert_command({ context: { assignment_status: "unassigned" } }, "not assigned")
|
||||
assert_command({ context: { assignee_ids: [ "jorge" ], terms: [ "performance" ] } }, "cards about performance assigned to jorge")
|
||||
|
||||
# Card context
|
||||
assert_command({ context: { assignee_ids: [ "jz" ] } }, "cards assigned to jz", context: :card)
|
||||
end
|
||||
|
||||
test "filter by terms" do
|
||||
assert_command({ context: { terms: [ "backups" ] } }, "cards about backups")
|
||||
assert_command({ context: { terms: [ "cables" ] } }, "issues about cables")
|
||||
assert_command({ context: { terms: [ "infrastructure" ] } }, "infrastructure bugs")
|
||||
assert_command({ context: { terms: [ "infrastructure" ] } }, "bugs about infrastructure")
|
||||
assert_command({ context: { terms: [ "infrastructure" ] } }, "infrastructure stuff")
|
||||
assert_command({ context: { terms: [ "red cars" ] } }, "issues about red cars")
|
||||
end
|
||||
|
||||
test "filter by tag" do
|
||||
# List context
|
||||
assert_command({ context: { tag_ids: [ "design" ] } }, "cards tagged with design")
|
||||
assert_command({ context: { tag_ids: [ "design" ] } }, "cards tagged with #design")
|
||||
assert_command({ context: { tag_ids: [ "design" ] } }, "#design cards")
|
||||
|
||||
# Card context
|
||||
assert_command({ context: { tag_ids: [ "design" ] } }, "cards tagged with design")
|
||||
end
|
||||
|
||||
test "filter by indexed_by" do
|
||||
# List context
|
||||
assert_command({ context: { indexed_by: "closed" } }, "closed cards")
|
||||
assert_command({ context: { indexed_by: "closed" } }, "completed cards")
|
||||
assert_command({ context: { indexed_by: "closed" } }, "completed")
|
||||
|
||||
assert_command({ context: { indexed_by: "newest" } }, "recent cards")
|
||||
assert_command({ context: { indexed_by: "latest" } }, "cards with recent activity")
|
||||
|
||||
assert_command({ context: { indexed_by: "stalled" } }, "stalled cards")
|
||||
assert_command({ context: { indexed_by: "stalled" } }, "stagnated cards")
|
||||
end
|
||||
|
||||
test "filter by stage" do
|
||||
assert_command({ context: { stage_ids: [ "uphill" ] } }, "cards in uphill")
|
||||
assert_command({ context: { stage_ids: [ "on hold" ] } }, "on hold cards")
|
||||
end
|
||||
|
||||
test "filter by card id" do
|
||||
assert_command({ context: { card_ids: [ cards(:logo).id ] } }, "this card", context: :card)
|
||||
|
||||
assert_command({ context: { card_ids: [ 123 ] } }, "card 123")
|
||||
assert_command({ context: { card_ids: [ 123, 456 ] } }, "card 123, 456")
|
||||
assert_command({ commands: [ "/search 123" ] }, "123") # Notice existing cards will be intercepted earlier
|
||||
end
|
||||
|
||||
test "filter by time ranges" do
|
||||
assert_command({ context: { closure: "thisweek", indexed_by: "closed" } }, "cards completed this week")
|
||||
assert_command({ context: { creation: "thisweek", tag_ids: [ "design" ], creator_ids: [ "jz" ] } }, "cards created this week by jz tagged as #design")
|
||||
assert_command({ context: { creation: "thismonth", creator_ids: [ "gabriel", "michael" ] } }, "cards created by gabriel or michael this month")
|
||||
end
|
||||
|
||||
test "acts on cards passing their ids" do
|
||||
assert_command({ context: { card_ids: [ 123, 456 ] }, commands: [ "/close" ] }, "close 123 and 456")
|
||||
assert_command({ context: { card_ids: [ 123 ] }, commands: [ "/close" ] }, "close 123")
|
||||
assert_command({ context: { card_ids: [ 1, 5, 9 ] }, commands: [ "/assign #{users(:david).to_gid}" ] }, "assign 1, 5 and 9 to myself")
|
||||
end
|
||||
|
||||
test "filter by collections" do
|
||||
assert_command({ context: { collection_ids: [ "Writebook" ] } }, "writebook collection")
|
||||
assert_command({ context: { collection_ids: [ "basecamp 5" ] } }, "basecamp 5 collection")
|
||||
assert_command({ context: { collection_ids: [ "Writebook" ] } }, "writebook")
|
||||
end
|
||||
|
||||
test "closing soon and falling back soon" do
|
||||
assert_command({ context: { indexed_by: "falling_back_soon" } }, "cards to be reconsidered soon")
|
||||
assert_command({ context: { assignee_ids: [ users(:david).to_gid.to_s ], indexed_by: "closing_soon" } }, "my cards that are going to be auto closed")
|
||||
end
|
||||
|
||||
test "close cards" do
|
||||
# List context
|
||||
assert_command({ commands: [ "/close" ] }, "close")
|
||||
assert_command({ commands: [ "/close not now" ] }, "close as not now")
|
||||
assert_command({ context: { assignee_ids: [ "jz" ] }, commands: [ "/close" ] }, "close cards assigned to jz")
|
||||
|
||||
# Card context
|
||||
assert_command({ commands: [ "/close" ] }, "close", context: :card)
|
||||
end
|
||||
|
||||
test "reopen cards" do
|
||||
# List context
|
||||
assert_command({ commands: [ "/reopen" ] }, "reopen")
|
||||
assert_command({ context: { assignee_ids: [ "jz" ] }, commands: [ "/reopen" ] }, "reopen cards assigned to jz")
|
||||
assert_command({ context: { closure: "thisweek", indexed_by: "closed" }, commands: [ "/reopen" ] }, "reopen cards closed this week")
|
||||
|
||||
# Card context
|
||||
assert_command({ commands: [ "/reopen" ] }, "reopen", context: :card)
|
||||
end
|
||||
|
||||
test "assign cards" do
|
||||
# List context
|
||||
assert_command({ commands: [ "/assign jz" ] }, "assign to jz")
|
||||
assert_command({ context: { tag_ids: [ "design" ] }, commands: [ "/assign jz" ] }, "assign cards tagged with #design to jz", context: :card)
|
||||
end
|
||||
|
||||
test "tag cards" do
|
||||
# List context
|
||||
assert_command({ commands: [ "/tag #design" ] }, "tag with #design")
|
||||
end
|
||||
|
||||
test "move cards between considering and doing" do
|
||||
assert_command({ commands: [ "/consider" ] }, "consider")
|
||||
assert_command({ commands: [ "/consider" ] }, "move to consider")
|
||||
|
||||
assert_command({ commands: [ "/do" ] }, "do")
|
||||
assert_command({ commands: [ "/do" ] }, "move to doing")
|
||||
end
|
||||
|
||||
test "assign stages to card" do
|
||||
assert_command({ commands: [ "/stage in progress" ] }, "move to stage in progress")
|
||||
assert_command({ commands: [ "/stage in progress" ] }, "move to in progress")
|
||||
end
|
||||
|
||||
test "visit screens" do
|
||||
assert_command({ commands: [ "/user #{@user.to_gid}" ] }, "my profile")
|
||||
assert_command({ commands: [ "/visit #{edit_user_path(@user, script_name: nil)}" ] }, "edit my profile")
|
||||
assert_command({ commands: [ "/visit #{account_settings_path(script_name: nil)}" ] }, "manage users")
|
||||
assert_command({ commands: [ "/visit #{account_settings_path(script_name: nil)}" ] }, "account settings")
|
||||
|
||||
assert_command({ commands: [ "/user mike" ] }, "mike profile page")
|
||||
end
|
||||
|
||||
test "view users profiles" do
|
||||
assert_command({ commands: [ "/user kevin" ] }, "view kevin")
|
||||
assert_command({ commands: [ "/user john" ] }, "view john profile")
|
||||
end
|
||||
|
||||
test "create cards" do
|
||||
assert_command({ commands: [ "/add" ] }, "add card")
|
||||
assert_command({ commands: [ "/add new task" ] }, "add card new task")
|
||||
assert_command({ commands: [ "/add" ] }, "create card")
|
||||
assert_command({ commands: [ "/add urgent issue" ] }, "create card urgent issue")
|
||||
end
|
||||
|
||||
test "filter by closed by" do
|
||||
assert_command({ context: { closer_ids: [ users(:david).to_gid.to_s ], indexed_by: "closed" } }, "cards closed by me")
|
||||
assert_command({ context: { closure: "thisweek", closer_ids: [ "jorge", "kevin" ], indexed_by: "closed" } }, "cards closed by Jorge or kevin this week")
|
||||
end
|
||||
|
||||
test "default to search" do
|
||||
assert_command({ commands: [ "/search backups" ] }, "backups")
|
||||
end
|
||||
|
||||
test "combine commands and filters" do
|
||||
assert_command(
|
||||
{ context: { card_ids: [ 176, 170 ] }, commands: [ "/do", "/assign #{users(:david).to_gid}", "/stage investigating" ] },
|
||||
"Move 176 and 170 to doing, assign to me and set the stage to Investigating")
|
||||
assert_command(
|
||||
{ context: { tag_ids: [ "design" ] }, commands: [ "/assign andy", "/tag #v2" ] },
|
||||
"assign andy to the current #design cards and tag them with #v2")
|
||||
assert_command(
|
||||
{ context: { assignee_ids: [ "andy" ] }, commands: [ "/close", "/assign kevin" ] },
|
||||
"close cards assigned to andy and assign them to kevin")
|
||||
assert_command(
|
||||
{ context: { tag_ids: [ "design" ] }, commands: [ "/assign andy", "/tag #v2" ] },
|
||||
"assign cards tagged with #design to andy and tag them with #v2")
|
||||
end
|
||||
|
||||
private
|
||||
def assert_command(expected, query, context: :list)
|
||||
assert_equal expected, translate(query, context:)
|
||||
end
|
||||
|
||||
def translate(query, user: @user, context: :list)
|
||||
raise "Context must be :card or _list" unless context.in?(%i[ card list ])
|
||||
url = context == :card ? card_url(cards(:logo)) : cards_url
|
||||
context = Command::Parser::Context.new(user, url: url, script_name: integration_session.default_url_options[:script_name])
|
||||
translator = Command::Ai::Translator.new(context)
|
||||
translator.translate(query)
|
||||
end
|
||||
end
|
||||
@@ -1,46 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class Command::AssignTest < ActionDispatch::IntegrationTest
|
||||
include CommandTestHelper
|
||||
|
||||
setup do
|
||||
Current.session = sessions(:david)
|
||||
@card = cards(:text)
|
||||
end
|
||||
|
||||
test "assign card on perma" do
|
||||
assert_difference -> { @card.assignees.count }, +2 do
|
||||
execute_command "/assign @kevin @david", context_url: collection_card_url(@card.collection, @card)
|
||||
end
|
||||
|
||||
assert_includes @card.assignees.reload, users(:david)
|
||||
assert_includes @card.assignees, users(:kevin)
|
||||
end
|
||||
|
||||
test "assign cards on cards' index page" do
|
||||
execute_command "/assign @kevin @david", context_url: collection_cards_url(@card.collection)
|
||||
|
||||
cards(:logo, :text, :layout).each do |card|
|
||||
assert_includes card.assignees.reload, users(:david)
|
||||
assert_includes card.assignees, users(:kevin)
|
||||
end
|
||||
end
|
||||
|
||||
test "undo assignment" do
|
||||
Assignment.destroy_all
|
||||
command = parse_command "/assign @kevin @david", context_url: collection_cards_url(@card.collection)
|
||||
|
||||
command.execute
|
||||
|
||||
cards(:logo, :text, :layout).each do |card|
|
||||
assert_includes card.assignees.reload, users(:david)
|
||||
assert_includes card.assignees, users(:kevin)
|
||||
end
|
||||
|
||||
command.reload.undo
|
||||
|
||||
cards(:logo, :text, :layout).each do |card|
|
||||
assert_empty card.reload.assignees.reload
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,15 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class Command::FilterTest < ActionDispatch::IntegrationTest
|
||||
include CommandTestHelper
|
||||
|
||||
setup do
|
||||
Current.session = sessions(:david)
|
||||
end
|
||||
|
||||
test "clear the filters keeping the selected collections" do
|
||||
result = execute_command "/clear", context_url: "?card_ids%5B%5D=1&card_ids%5B%5D=2&collection_ids%5B%5D=#{collections(:writebook).id}&indexed_by=newest&terms%5B%5D=jorge"
|
||||
|
||||
assert_equal cards_path(indexed_by: "newest", collection_ids: [ collections(:writebook).id ]), result.url
|
||||
end
|
||||
end
|
||||
@@ -1,51 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class Command::CloseTest < ActionDispatch::IntegrationTest
|
||||
include CommandTestHelper
|
||||
|
||||
setup do
|
||||
Current.session = sessions(:david)
|
||||
@card = cards(:text)
|
||||
end
|
||||
|
||||
test "close card on perma" do
|
||||
assert_changes -> { @card.reload.closed? }, from: false, to: true do
|
||||
execute_command "/close", context_url: collection_card_url(@card.collection, @card)
|
||||
end
|
||||
|
||||
assert_equal Closure::Reason.default, @card.closure.reason
|
||||
assert_equal users(:david), @card.closed_by
|
||||
end
|
||||
|
||||
test "close card on perma with reason" do
|
||||
assert_changes -> { @card.reload.closed? }, from: false, to: true do
|
||||
execute_command "/close Not now", context_url: collection_card_url(@card.collection, @card)
|
||||
end
|
||||
|
||||
assert_equal users(:david), @card.closed_by
|
||||
assert_equal "Not now", @card.closure.reason
|
||||
end
|
||||
|
||||
test "close cards on cards' index page" do
|
||||
cards = cards(:logo, :text, :layout)
|
||||
cards.each(&:reopen)
|
||||
|
||||
execute_command "/close", context_url: collection_cards_url(@card.collection)
|
||||
|
||||
assert cards.map(&:reload).all?(&:closed?)
|
||||
end
|
||||
|
||||
test "undo close" do
|
||||
cards = cards(:logo, :text, :layout)
|
||||
cards.each(&:reopen)
|
||||
|
||||
command = parse_command "/close", context_url: collection_cards_url(@card.collection)
|
||||
command.execute
|
||||
|
||||
assert cards.map(&:reload).all?(&:closed?)
|
||||
|
||||
command.undo
|
||||
|
||||
assert cards.map(&:reload).all?(&:open?)
|
||||
end
|
||||
end
|
||||
@@ -1,52 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class Command::CompositeTest < ActionDispatch::IntegrationTest
|
||||
include CommandTestHelper
|
||||
|
||||
test "execute commands in order and return an array with the results" do
|
||||
command = Command::Composite.new(commands: [ build_command(result: "1"), build_command(result: "2") ])
|
||||
assert_equal [ "1", "2" ], command.execute
|
||||
end
|
||||
|
||||
test "undo the commands in reverse order" do
|
||||
command = Command::Composite.new(commands: [ build_command(result: "1", undoable: true), build_command(result: "2", undoable: true) ])
|
||||
assert_equal [ "2", "1" ], command.undo
|
||||
end
|
||||
|
||||
test "undoable if some of the commands is" do
|
||||
assert_not Command::Composite.new(commands: [ build_command(undoable: false), build_command(undoable: false) ]).undoable?
|
||||
assert Command::Composite.new(commands: [ build_command(undoable: true), build_command(undoable: false) ]).undoable?
|
||||
end
|
||||
|
||||
test "needs confirmation if some of the command does" do
|
||||
assert_not Command::Composite.new(commands: [ build_command(needs_confirmation: false), build_command(needs_confirmation: false) ]).needs_confirmation?
|
||||
assert Command::Composite.new(commands: [ build_command(needs_confirmation: true), build_command(needs_confirmation: false) ]).needs_confirmation?
|
||||
end
|
||||
|
||||
private
|
||||
def build_command(...)
|
||||
TestCommand.new(...)
|
||||
end
|
||||
|
||||
class TestCommand < Command
|
||||
attribute :result
|
||||
attribute :undoable
|
||||
attribute :needs_confirmation
|
||||
|
||||
def execute
|
||||
result
|
||||
end
|
||||
|
||||
def undo
|
||||
result
|
||||
end
|
||||
|
||||
def undoable?
|
||||
undoable
|
||||
end
|
||||
|
||||
def needs_confirmation?
|
||||
needs_confirmation
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,40 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class Command::ConsiderTest < ActionDispatch::IntegrationTest
|
||||
include CommandTestHelper
|
||||
|
||||
setup do
|
||||
Current.session = sessions(:david)
|
||||
@card = cards(:text)
|
||||
@card.engage
|
||||
end
|
||||
|
||||
test "consider card on perma" do
|
||||
assert_changes -> { @card.reload.considering? }, from: false, to: true do
|
||||
execute_command "/consider", context_url: collection_card_url(@card.collection, @card)
|
||||
end
|
||||
end
|
||||
|
||||
test "consider cards on index page" do
|
||||
cards = cards(:logo, :text, :layout)
|
||||
cards.each(&:engage)
|
||||
|
||||
execute_command "/consider", context_url: collection_cards_url(@card.collection)
|
||||
|
||||
assert cards.map(&:reload).all?(&:considering?)
|
||||
end
|
||||
|
||||
test "undo consider" do
|
||||
cards = cards(:logo, :text, :layout)
|
||||
cards.each(&:engage)
|
||||
|
||||
command = parse_command "/consider", context_url: collection_cards_url(@card.collection)
|
||||
command.execute
|
||||
|
||||
assert cards.map(&:reload).all?(&:considering?)
|
||||
|
||||
command.undo
|
||||
|
||||
assert cards.map(&:reload).all?(&:doing?)
|
||||
end
|
||||
end
|
||||
@@ -1,40 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class Command::DoTest < ActionDispatch::IntegrationTest
|
||||
include CommandTestHelper
|
||||
|
||||
setup do
|
||||
Current.session = sessions(:david)
|
||||
@card = cards(:text)
|
||||
@card.reconsider
|
||||
end
|
||||
|
||||
test "do card on perma" do
|
||||
assert_changes -> { @card.reload.doing? }, from: false, to: true do
|
||||
execute_command "/do", context_url: collection_card_url(@card.collection, @card)
|
||||
end
|
||||
end
|
||||
|
||||
test "do cards on index page" do
|
||||
cards = cards(:logo, :text, :layout)
|
||||
cards.each(&:reconsider)
|
||||
|
||||
execute_command "/do", context_url: collection_cards_url(@card.collection)
|
||||
|
||||
assert cards.map(&:reload).all?(&:doing?)
|
||||
end
|
||||
|
||||
test "undo do" do
|
||||
cards = cards(:logo, :text, :layout)
|
||||
cards.each(&:reconsider)
|
||||
|
||||
command = parse_command "/do", context_url: collection_cards_url(@card.collection)
|
||||
command.execute
|
||||
|
||||
assert cards.map(&:reload).all?(&:doing?)
|
||||
|
||||
command.undo
|
||||
|
||||
assert cards.map(&:reload).all?(&:considering?)
|
||||
end
|
||||
end
|
||||
@@ -1,15 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class Command::FilterByCardTest < ActionDispatch::IntegrationTest
|
||||
include CommandTestHelper
|
||||
|
||||
setup do
|
||||
@tag = tags(:web)
|
||||
end
|
||||
|
||||
test "redirect to the cards index filtering by cards" do
|
||||
result = execute_command "##{@tag.title}"
|
||||
|
||||
assert_equal cards_path(tag_ids: [ @tag.id ]), result.url
|
||||
end
|
||||
end
|
||||
@@ -1,21 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class Command::FilterCardsTest < ActionDispatch::IntegrationTest
|
||||
include CommandTestHelper
|
||||
|
||||
setup do
|
||||
@card_ids = cards(:logo, :layout).collect(&:id)
|
||||
end
|
||||
|
||||
test "redirect to the cards index filtering by cards" do
|
||||
result = execute_command "#{@card_ids.join(" ")}"
|
||||
|
||||
assert_equal cards_path(card_ids: @card_ids), result.url
|
||||
end
|
||||
|
||||
test "respect existing filters" do
|
||||
result = execute_command "#{@card_ids.join(",")}", context_url: "http://37signals.fizzy.localhost:3006/cards?collection_ids%5B%5D=#{collections(:writebook).id}"
|
||||
|
||||
assert_equal cards_path(collection_ids: [ collections(:writebook).id ], card_ids: @card_ids), result.url
|
||||
end
|
||||
end
|
||||
@@ -3,12 +3,8 @@ require "test_helper"
|
||||
class Command::GoToCardTest < ActionDispatch::IntegrationTest
|
||||
include CommandTestHelper
|
||||
|
||||
include VcrTestHelper
|
||||
|
||||
setup do
|
||||
@card = cards(:logo)
|
||||
|
||||
freeze_timestamps
|
||||
end
|
||||
|
||||
test "redirect to the card perma" do
|
||||
@@ -20,10 +16,7 @@ class Command::GoToCardTest < ActionDispatch::IntegrationTest
|
||||
test "result in a regular search if the card does not exist" do
|
||||
command = parse_command "123"
|
||||
|
||||
assert command.valid?
|
||||
|
||||
result = command.execute
|
||||
assert_equal 1, result.size
|
||||
assert_equal search_path(q: "123"), result.first.url
|
||||
assert_equal search_path(q: "123"), result.url
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class Command::GoToUserTest < ActionDispatch::IntegrationTest
|
||||
include CommandTestHelper
|
||||
|
||||
test "redirect to the user perma with @" do
|
||||
result = execute_command "@kevin"
|
||||
|
||||
assert_equal user_path(users(:kevin)), result.url
|
||||
end
|
||||
|
||||
test "redirect to the user perma with /user" do
|
||||
result = execute_command "/user kevin"
|
||||
|
||||
assert_equal user_path(users(:kevin)), result.url
|
||||
end
|
||||
|
||||
test "result in an invalid command if the user does not exist" do
|
||||
command = parse_command "@not_a_user"
|
||||
assert !command.valid?
|
||||
end
|
||||
end
|
||||
@@ -1,115 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class Command::Parser::ContextTest < ActiveSupport::TestCase
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
setup do
|
||||
@user = users(:david)
|
||||
@context = Command::Parser::Context.new(@user, url: cards_path)
|
||||
|
||||
Card.find_each(&:reindex)
|
||||
Comment.find_each(&:reindex)
|
||||
end
|
||||
|
||||
test "viewing a single card" do
|
||||
context = Command::Parser::Context.new(@user, url: card_path(cards(:layout)))
|
||||
|
||||
assert context.viewing_card_contents?
|
||||
assert_not context.viewing_list_of_cards?
|
||||
|
||||
assert_equal 1, context.cards.count
|
||||
assert_equal cards(:layout).id, context.cards.first.id
|
||||
end
|
||||
|
||||
test "viewing cards index" do
|
||||
context = Command::Parser::Context.new(@user, url: cards_path)
|
||||
|
||||
assert context.viewing_list_of_cards?
|
||||
assert_not context.viewing_card_contents?
|
||||
|
||||
assert_equal @user.filters.from_params(FilterScoped::DEFAULT_PARAMS).cards.published.count, context.cards.count
|
||||
end
|
||||
|
||||
test "viewing search results" do
|
||||
context = Command::Parser::Context.new(@user, url: search_path(q: "layout"))
|
||||
|
||||
assert context.viewing_list_of_cards?
|
||||
assert_not context.viewing_card_contents?
|
||||
|
||||
expected_cards = @user.accessible_cards.where(id: @user.search("layout").select(:card_id))
|
||||
|
||||
assert_equal expected_cards.count, context.cards.count
|
||||
assert_equal expected_cards.pluck(:id).sort, context.cards.pluck(:id).sort
|
||||
end
|
||||
|
||||
test "unrecognized URL pattern" do
|
||||
context = Command::Parser::Context.new(@user, url: filters_path)
|
||||
|
||||
assert_not context.viewing_card_contents?
|
||||
assert_not context.viewing_list_of_cards?
|
||||
|
||||
assert_empty context.cards
|
||||
end
|
||||
|
||||
test "find_user by handle" do
|
||||
assert_equal users(:david), @context.find_user("david")
|
||||
assert_equal users(:david), @context.find_user("@david")
|
||||
assert_equal users(:jz), @context.find_user("jz")
|
||||
assert_equal users(:kevin), @context.find_user("kevin")
|
||||
assert_nil @context.find_user("nonexistent")
|
||||
end
|
||||
|
||||
test "find_user by GID" do
|
||||
david_gid = users(:david).to_gid.to_s
|
||||
assert_equal users(:david), @context.find_user(david_gid)
|
||||
|
||||
jz_gid = users(:jz).to_gid.to_s
|
||||
assert_equal users(:jz), @context.find_user(jz_gid)
|
||||
|
||||
assert_nil @context.find_user("invalid-gid")
|
||||
end
|
||||
|
||||
test "find_workflow_stage" do
|
||||
card_context = Command::Parser::Context.new(@user, url: card_path(cards(:logo)))
|
||||
|
||||
assert_equal workflow_stages(:qa_triage), card_context.find_workflow_stage("triage")
|
||||
assert_equal workflow_stages(:qa_in_progress), card_context.find_workflow_stage("in progress")
|
||||
assert_equal workflow_stages(:qa_on_hold), card_context.find_workflow_stage("on hold")
|
||||
assert_equal workflow_stages(:qa_review), card_context.find_workflow_stage("review")
|
||||
|
||||
assert_equal workflow_stages(:qa_in_progress), card_context.find_workflow_stage("progress")
|
||||
|
||||
assert_nil card_context.find_workflow_stage("nonexistent")
|
||||
end
|
||||
|
||||
test "find_tag with title" do
|
||||
assert_equal tags(:web), @context.find_tag("web")
|
||||
assert_equal tags(:web), @context.find_tag("#web")
|
||||
assert_equal tags(:mobile), @context.find_tag("mobile")
|
||||
|
||||
assert_nil @context.find_tag("nonexistent")
|
||||
end
|
||||
|
||||
test "find_tag by GID" do
|
||||
web_gid = tags(:web).to_gid.to_s
|
||||
assert_equal tags(:web), @context.find_tag(web_gid)
|
||||
|
||||
mobile_gid = tags(:mobile).to_gid.to_s
|
||||
assert_equal tags(:mobile), @context.find_tag(mobile_gid)
|
||||
|
||||
assert_nil @context.find_tag("invalid-gid")
|
||||
end
|
||||
|
||||
test "find_collection" do
|
||||
assert_equal collections(:writebook), @context.find_collection("Writebook")
|
||||
assert_equal collections(:writebook), @context.find_collection("writebook")
|
||||
|
||||
assert_equal collections(:private), @context.find_collection("Private collection")
|
||||
assert_equal collections(:private), @context.find_collection("private collection")
|
||||
|
||||
assert_equal collections(:writebook), @context.find_collection("write")
|
||||
assert_equal collections(:private), @context.find_collection("private")
|
||||
|
||||
assert_nil @context.find_collection("nonexistent")
|
||||
end
|
||||
end
|
||||
@@ -1,29 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
# The parser is tested through the tests of specific commands. See +Command::AssignTests+, etc.
|
||||
class Command::ParserTest < ActionDispatch::IntegrationTest
|
||||
include CommandTestHelper, VcrTestHelper
|
||||
|
||||
setup do
|
||||
freeze_timestamps
|
||||
end
|
||||
|
||||
test "the parsed command contains the raw line" do
|
||||
result = parse_command "assign @kevin"
|
||||
assert_equal "assign @kevin", result.line
|
||||
end
|
||||
|
||||
test "supports expressions in plain text" do
|
||||
command = parse_command "/assign @kevin"
|
||||
assert command.is_a?(Command::Assign)
|
||||
assert_equal [ users(:kevin) ], command.assignees
|
||||
end
|
||||
|
||||
test "supports expressions in rich text" do
|
||||
command = parse_command <<~HTML
|
||||
<p>/assign #{ActionText::Attachment.from_attachable(users(:kevin)).to_html}</p>
|
||||
HTML
|
||||
assert command.is_a?(Command::Assign)
|
||||
assert_equal [ users(:kevin) ], command.assignees
|
||||
end
|
||||
end
|
||||
@@ -1,42 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class Command::ReopenTest < ActionDispatch::IntegrationTest
|
||||
include CommandTestHelper
|
||||
|
||||
setup do
|
||||
Current.session = sessions(:david)
|
||||
@card = cards(:text)
|
||||
@card.close(user: users(:david))
|
||||
end
|
||||
|
||||
test "reopen card on perma" do
|
||||
assert_changes -> { @card.reload.open? }, from: false, to: true do
|
||||
execute_command "/reopen", context_url: collection_card_url(@card.collection, @card)
|
||||
end
|
||||
|
||||
assert_nil @card.closed_by
|
||||
end
|
||||
|
||||
test "reopen cards on cards' index page" do
|
||||
cards = cards(:logo, :text, :layout)
|
||||
cards.each { |card| card.close }
|
||||
|
||||
execute_command "/reopen", context_url: collection_cards_url(@card.collection, indexed_by: "closed")
|
||||
|
||||
assert cards.map(&:reload).all?(&:open?)
|
||||
end
|
||||
|
||||
test "undo reopen" do
|
||||
cards = cards(:logo, :text, :layout)
|
||||
cards.each { |card| card.close(user: users(:david)) }
|
||||
|
||||
command = parse_command "/reopen", context_url: collection_cards_url(@card.collection, indexed_by: "closed")
|
||||
command.execute
|
||||
|
||||
assert cards.map(&:reload).all?(&:open?)
|
||||
|
||||
command.undo
|
||||
|
||||
assert cards.map(&:reload).all?(&:closed?)
|
||||
end
|
||||
end
|
||||
@@ -1,11 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class Command::SearchTest < ActionDispatch::IntegrationTest
|
||||
include CommandTestHelper
|
||||
|
||||
test "redirect to the user perma" do
|
||||
result = execute_command "/search something"
|
||||
|
||||
assert_equal search_path(q: "something"), result.url
|
||||
end
|
||||
end
|
||||
@@ -1,47 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class Command::StageTest < ActionDispatch::IntegrationTest
|
||||
include CommandTestHelper
|
||||
|
||||
setup do
|
||||
Current.session = sessions(:david)
|
||||
@card = cards(:text)
|
||||
@new_stage = workflow_stages(:qa_review)
|
||||
@original_stage = @card.stage
|
||||
end
|
||||
|
||||
test "move card to a new stage on perma" do
|
||||
assert_changes -> { @card.reload.stage }, from: @original_stage, to: @new_stage do
|
||||
execute_command "/stage #{@new_stage.name}", context_url: collection_card_url(@card.collection, @card)
|
||||
end
|
||||
end
|
||||
|
||||
test "move cards on cards' index page" do
|
||||
cards = [ cards(:logo), cards(:layout), cards(:text) ]
|
||||
|
||||
execute_command "/stage #{@new_stage.name}", context_url: collection_cards_url(@card.collection)
|
||||
|
||||
cards.each do |card|
|
||||
assert_equal @new_stage, card.reload.stage
|
||||
end
|
||||
end
|
||||
|
||||
test "undo stage change" do
|
||||
cards = [ cards(:logo), cards(:layout), cards(:text) ]
|
||||
cards.each { it.change_stage_to @original_stage }
|
||||
|
||||
command = parse_command "/stage #{@new_stage.name}", context_url: collection_cards_url(@card.collection)
|
||||
command.execute
|
||||
|
||||
cards.each do |card|
|
||||
assert_equal @new_stage, card.reload.stage
|
||||
end
|
||||
|
||||
command.undo
|
||||
|
||||
# Verify cards moved back to original stages
|
||||
cards.each do |card|
|
||||
assert_equal @original_stage, card.reload.stage
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,47 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class Command::TagTest < ActionDispatch::IntegrationTest
|
||||
include CommandTestHelper
|
||||
|
||||
setup do
|
||||
Current.session = sessions(:david)
|
||||
@card = cards(:text)
|
||||
@tag = tags(:web)
|
||||
end
|
||||
|
||||
test "tag card on perma with existing tag" do
|
||||
assert_changes -> { @card.tagged_with?(@tag) }, from: false, to: true do
|
||||
execute_command "/tag #{@tag.title}", context_url: collection_card_url(@card.collection, @card)
|
||||
end
|
||||
end
|
||||
|
||||
test "tag card on perma with new tag" do
|
||||
assert_difference -> { @card.tags.count }, +1 do
|
||||
execute_command "/tag some-new-tag", context_url: collection_card_url(@card.collection, @card)
|
||||
end
|
||||
|
||||
assert_equal "some-new-tag", @card.tags.last.title
|
||||
end
|
||||
|
||||
test "tag several cards on cards' index page" do
|
||||
cards = cards(:logo, :text, :layout)
|
||||
cards.each { it.taggings.destroy_all }
|
||||
|
||||
execute_command "/tag #{@tag.title}", context_url: collection_cards_url(@card.collection)
|
||||
|
||||
cards.each { assert it.reload.tagged_with?(@tag) }
|
||||
end
|
||||
|
||||
test "undo tagged cards" do
|
||||
cards = cards(:logo, :text, :layout)
|
||||
cards.each { it.taggings.destroy_all }
|
||||
|
||||
command = parse_command "/tag #{@tag.title}", context_url: collection_cards_url(@card.collection)
|
||||
command.execute
|
||||
|
||||
cards.each { assert it.reload.tagged_with?(@tag) }
|
||||
|
||||
command.undo
|
||||
cards.each { assert_not it.reload.tagged_with?(@tag) }
|
||||
end
|
||||
end
|
||||
@@ -1,36 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class Command::VisitUrlTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@user = users(:david)
|
||||
@card = cards(:logo)
|
||||
@script_name = integration_session.default_url_options[:script_name]
|
||||
end
|
||||
|
||||
test "visit a path without the account slug" do
|
||||
result = visit_command("/foo/1234/bar").execute
|
||||
|
||||
assert_kind_of Command::Result::Redirection, result
|
||||
assert_equal "#{@script_name}/foo/1234/bar", result.url
|
||||
end
|
||||
|
||||
test "visit a path with the account slug" do
|
||||
result = visit_command("#{@script_name}/foo/1234/bar").execute
|
||||
|
||||
assert_kind_of Command::Result::Redirection, result
|
||||
assert_equal "#{@script_name}/foo/1234/bar", result.url
|
||||
end
|
||||
|
||||
test "visit an object path" do
|
||||
result = visit_command(@card).execute
|
||||
|
||||
assert_kind_of Command::Result::Redirection, result
|
||||
assert_equal @card, result.url
|
||||
end
|
||||
|
||||
private
|
||||
def visit_command(url)
|
||||
context = Command::Parser::Context.new(@user, url: collection_card_url(@card.collection, @card), script_name: integration_session.default_url_options[:script_name])
|
||||
Command::VisitUrl.new(url: url, context: context)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user