File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
config/initializers/tenanting Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change 11module AccountSlug
2- PATTERN = /(\d {7,})/
3- FORMAT = "%07d"
2+ PATTERN = /(\d +)/
43 PATH_INFO_MATCH = /\A (\/ #{ AccountSlug ::PATTERN } )/
54
65 class Extractor
@@ -40,7 +39,7 @@ def call(env)
4039 end
4140
4241 def self . decode ( slug ) slug . to_i end
43- def self . encode ( id ) FORMAT % id end
42+ def self . encode ( id ) id . to_s end
4443end
4544
4645Rails . application . config . middleware . insert_after Rack ::TempfileReaper , AccountSlug ::Extractor
Original file line number Diff line number Diff line change @@ -44,6 +44,15 @@ class AccountSlugExtractorTest < ActiveSupport::TestCase
4444 assert_nil captured . fetch ( :current_account )
4545 end
4646
47+ test "encodes account IDs without zero-padding" do
48+ assert_equal "1" , AccountSlug . encode ( 1 )
49+ end
50+
51+ test "decodes both padded and non-padded slugs" do
52+ assert_equal 123 , AccountSlug . decode ( "123" )
53+ assert_equal 123 , AccountSlug . decode ( "0000123" )
54+ end
55+
4756 private
4857 def call_with_env ( path , extra_env = { } )
4958 captured = { }
You can’t perform that action at this time.
0 commit comments