Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 5 2 regression #1

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/friendly_id/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,11 @@ def friendly_id
# Either the friendly_id, or the numeric id cast to a string.
def to_param
if friendly_id_config.routes == :friendly
friendly_id.presence.to_param || super
if has_changes_to_save? && (diff = saved_changes[friendly_id_config.query_field] || changes[friendly_id_config.query_field])
diff.first || diff.second
else
friendly_id.presence.to_param || super
end
else
super
end
Expand Down
7 changes: 4 additions & 3 deletions test/slugged_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,12 @@ class Journalist < ActiveRecord::Base
transaction do
journalist = Journalist.new :name => 'Clark Kent', :active => true
assert journalist.save
journalist.reload
journalist.name = 'Superman'
journalist.slug = nil
journalist.slug = 'not-so-super-man'
journalist.active = nil
refute journalist.save
assert_equal 'superman', journalist.to_param
assert_equal 'clark-kent', journalist.to_param
end
end

Expand All @@ -543,7 +544,7 @@ class Journalist < ActiveRecord::Base
journalist = Journalist.new :name => 'Clark Kent', :active => true
assert journalist.save
journalist.name = 'x'
journalist.slug = nil
journalist.slug = "no-clark"
journalist.active = nil
refute journalist.save
assert_equal 'clark-kent', journalist.to_param
Expand Down