rails/activesupport/lib
Nick Hengeveld 5623f7f1a3 Return a copy of the source string when transliterating
Co-authored-by: Adam Hess <hparker@github.com>

Fixes an issue where parameterizing strings was mutating the source, eg:

```ruby
require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  gem "rails", github: "rails/rails", branch: "main"
  gem "sqlite3"
end

require "active_record"
require "minitest/autorun"
require "logger"

ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(STDOUT)

ActiveRecord::Schema.define do
  create_table :posts, force: true do |t|
    t.text :name
    t.text :slug
  end
end

class Post < ActiveRecord::Base
  validate :generate_slug

  def generate_slug
    self.slug = name.parameterize
  end
end

class BugTest < Minitest::Test
  def test_name_gets_corrupted
    post = Post.create!(name: "hi there")

    assert_equal "hi there", post.name # This test fails, "hi-there"
  end
end
```
2022-11-30 16:55:46 +00:00
..
active_support Return a copy of the source string when transliterating 2022-11-30 16:55:46 +00:00
active_support.rb Add ActiveSupport.deprecator 2022-10-25 15:06:39 -05:00