Skip to content

Commit

Permalink
Avoid triggering ambigous slash warnings
Browse files Browse the repository at this point in the history
Ignoring those warnings is not working on `rake test` anyway.
  • Loading branch information
janko committed Dec 19, 2024
1 parent 55a66f5 commit c118003
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
28 changes: 14 additions & 14 deletions test/integration/instrumentation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ class InstrumentationTest < IntegrationTest
visit "/login"
end

assert_match /Processing by RodauthController#login as HTML/, logged
refute_match /Parameters/, logged
assert_match(/Processing by RodauthController#login as HTML/, logged)
refute_match(/Parameters/, logged)
if ::Rails.gem_version >= Gem::Version.new("6.0")
assert_match /Completed 200 OK in \d+ms \(Views: \d+ms | ActiveRecord: \d+\.\d+ms | Allocations: \d+\)/, logged
assert_match(/Completed 200 OK in \d+ms \(Views: \d+ms | ActiveRecord: \d+\.\d+ms | Allocations: \d+\)/, logged)
else
assert_match /Completed 200 OK in \d+ms \(Views: \d+ms | ActiveRecord: \d+\.\d+ms\)/, logged
assert_match(/Completed 200 OK in \d+ms \(Views: \d+ms | ActiveRecord: \d+\.\d+ms\)/, logged)
end
end

Expand All @@ -22,44 +22,44 @@ class InstrumentationTest < IntegrationTest
{ "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT" => "application/json" }
end

assert_match /Processing by ActionController::API#login as JSON/, logged
assert_match /Parameters: {"login"=>"user@example\.com", "password"=>"secret"}/, logged
assert_match /Completed 401 Unauthorized/, logged
assert_match(/Processing by ActionController::API#login as JSON/, logged)
assert_match(/Parameters: {"login" ?=> ?"user@example\.com", "password" ?=> ?"secret"}/, logged)
assert_match(/Completed 401 Unauthorized/, logged)
end

test "logs redirects" do
logged = capture_log do
visit "/change-password"
end

assert_match /Processing by RodauthController#change_password as HTML/, logged
assert_match /Redirected to \/login/, logged
assert_match /Completed 302 Found/, logged
assert_match(/Processing by RodauthController#change_password as HTML/, logged)
assert_match(/Redirected to \/login/, logged)
assert_match(/Completed 302 Found/, logged)
end

test "handles early response via callback" do
logged = capture_log do
visit "/login?early_return=true"
end

assert_match /Processing by RodauthController#login as HTML/, logged
assert_match /Completed 201 Created in \d+ms/, logged
assert_match(/Processing by RodauthController#login as HTML/, logged)
assert_match(/Completed 201 Created in \d+ms/, logged)
end

test "logs response status when redirecting inside controller" do
logged = capture_log do
visit "/auth2"
end

assert_match /Completed 302 Found/, logged
assert_match(/Completed 302 Found/, logged)
end

test "logs response status when halting inside controller" do
logged = capture_log do
visit "/auth_json"
end

assert_match /Completed 401 Unauthorized/, logged
assert_match(/Completed 401 Unauthorized/, logged)
end

private
Expand Down
1 change: 0 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
ENV["RAILS_ENV"] = "test"

require "warning"
Warning.ignore(:ambiguous_slash, __dir__)
Gem.path.each { |path| Warning.ignore(//, path) } # ignore warnings in dependencies

require "bundler/setup"
Expand Down

0 comments on commit c118003

Please sign in to comment.