Merge pull request #18 from github/prefix-in-tests
Allow setting a prefix in test
This commit is contained in:
Коммит
832d74309d
|
@ -6,6 +6,16 @@ module Chatops::Controller::TestCaseHelpers
|
|||
request.env["CHATOPS_TESTING_AUTH"] = true
|
||||
end
|
||||
|
||||
def chatops_prefix(prefix = nil)
|
||||
# We abuse request.env here so that rails will cycle this with each test.
|
||||
# If we used an instance variable, one would always need to be resetting
|
||||
# it.
|
||||
if prefix
|
||||
request.env["CHATOPS_TESTING_PREFIX"] = prefix
|
||||
end
|
||||
request.env["CHATOPS_TESTING_PREFIX"]
|
||||
end
|
||||
|
||||
def chatop(method, params = {})
|
||||
args = params.dup.symbolize_keys
|
||||
user = args.delete :user
|
||||
|
@ -31,7 +41,8 @@ module Chatops::Controller::TestCaseHelpers
|
|||
matchers = json_response["methods"].map { |name, metadata|
|
||||
metadata = metadata.dup
|
||||
metadata["name"] = name
|
||||
metadata["regex"] = Regexp.new("^#{metadata["regex"]}$", "i")
|
||||
prefix = chatops_prefix ? "#{chatops_prefix} " : ""
|
||||
metadata["regex"] = Regexp.new("^#{prefix}#{metadata["regex"]}$", "i")
|
||||
metadata
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module ChatopsController
|
||||
VERSION = "3.0.1"
|
||||
VERSION = "3.0.2"
|
||||
end
|
||||
|
|
|
@ -365,6 +365,12 @@ describe ActionController::Base, type: :controller do
|
|||
chat "too bad that this message doesn't start with where can i deploy foobar", "bhuga"
|
||||
}.to raise_error(Chatops::Controller::TestCaseHelpers::NoMatchingCommandRegex)
|
||||
end
|
||||
|
||||
it "allows setting a v2 prefix" do
|
||||
chatops_prefix "test-prefix"
|
||||
chat "test-prefix where can i deploy foobar --this-is-sparta", "bhuga"
|
||||
expect(request.params["chatop"]).to eq "wcid"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче