Skip to content

Commit

Permalink
Fix allowing options to have no separator
Browse files Browse the repository at this point in the history
  • Loading branch information
stevegeek committed Apr 29, 2024
1 parent 5ea1740 commit 695e5f1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion encoded_id-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
# Uncomment to register a new dependency of your gem
spec.add_dependency "activesupport", ">= 6.0", "< 8.0"
spec.add_dependency "activerecord", ">= 6.0", "< 8.0"
spec.add_dependency "encoded_id", "~> 1.0.0.rc3"
spec.add_dependency "encoded_id", "~> 1.0.0.rc4"
spec.add_development_dependency "appraisal"

# For more information and examples about making a new gem, check out our
Expand Down
4 changes: 2 additions & 2 deletions lib/encoded_id/rails/encoder_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def encoded_id_coder(options = {})
EncodedId::Rails::Coder.new(
salt: options[:salt] || encoded_id_salt,
id_length: options[:id_length] || config.id_length,
character_group_size: options[:character_group_size] || config.character_group_size,
character_group_size: options.key?(:character_group_size) ? options[:character_group_size] : config.character_group_size,
alphabet: options[:alphabet] || config.alphabet,
separator: options[:separator] || config.group_separator
separator: options.key?(:separator) ? options[:separator] : config.group_separator
)
end
end
Expand Down
14 changes: 14 additions & 0 deletions test/encoded_id/test_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,20 @@ def test_it_gets_encoded_id_with_options
}))
end

def test_it_gets_encoded_id_with_options_with_nil_group_size
assert_match(/[^_]+/, MyModel.encode_encoded_id(model.id, {
character_group_size: nil,
separator: "_"
}))
end

def test_it_gets_encoded_id_with_options_with_nil_group_size
assert_match(/.{8}/, MyModel.encode_encoded_id(model.id, {
character_group_size: 3,
separator: nil
}))
end

def test_it_decodes_id
assert_equal [model.id], MyModel.decode_encoded_id(model.encoded_id)
end
Expand Down

0 comments on commit 695e5f1

Please sign in to comment.