Skip to content

Commit

Permalink
Prevent deprecation warnings on update_attributes (#922)
Browse files Browse the repository at this point in the history
  • Loading branch information
parndt committed Nov 5, 2019
1 parent 1381c35 commit f759ba2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
We would like to think our many [contributors](https://github.com/norman/friendly_id/graphs/contributors) for
suggestions, ideas and improvements to FriendlyId.

## Unreleased

* Avoid using deprecated `update_attributes` (Philip Arndt).

## 5.3.0 (2019-09-25)

* Record history when scope changes but slug does not ([#916](https://github.com/norman/friendly_id/pull/916))
Expand Down
1 change: 1 addition & 0 deletions lib/friendly_id/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Configuration
attr_accessor :routes

def initialize(model_class, values = nil)
@base = nil
@model_class = model_class
@defaults = {}
@modules = []
Expand Down
9 changes: 4 additions & 5 deletions test/history_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ def model_class
test "should not be read only when found by slug" do
with_instance_of(model_class) do |record|
refute model_class.friendly.find(record.friendly_id).readonly?
assert record.update_attribute :name, 'foo'
assert record.update_attributes name: 'foo'
assert record.update name: 'foo'
end
end

Expand Down Expand Up @@ -109,10 +108,10 @@ def model_class
first_record = model_class.create! :name => "foo"
second_record = model_class.create! :name => 'another'

second_record.update_attributes :name => 'foo', :slug => nil
second_record.update :name => 'foo', :slug => nil
assert_match(/foo-.*/, second_record.slug)

first_record.update_attributes :name => 'another', :slug => nil
first_record.update :name => 'another', :slug => nil
assert_match(/another-.*/, first_record.slug)
end
end
Expand Down Expand Up @@ -230,7 +229,7 @@ def model_class
record = model_class.create(name: 'paranoid')
assert FriendlyId::Slug.find_by_slug('paranoid').present?

record.update_attribute(:deleted_at, Time.now)
record.update deleted_at: Time.now

orphan_slug = FriendlyId::Slug.find_by_slug('paranoid')
assert orphan_slug.present?, 'Orphaned slug should exist'
Expand Down
4 changes: 2 additions & 2 deletions test/shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module Slugged
my_model_class = Class.new(model_class)
self.class.const_set("Foo", my_model_class)
with_instance_of my_model_class do |record|
record.update_attributes my_model_class.friendly_id_config.slug_column => nil
record.update my_model_class.friendly_id_config.slug_column => nil
record = my_model_class.friendly.find(record.id)
record.class.validate Proc.new {errors.add(:name, "FAIL")}
record.save
Expand Down Expand Up @@ -132,7 +132,7 @@ module Core
test "updating record's other values should not change the friendly_id" do
with_instance_of model_class do |record|
old = record.friendly_id
record.update_attributes! :active => false
record.update! active: false
assert model_class.friendly.find old
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/simple_i18n_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ def setup
class RegressionTest < TestCaseClass
include FriendlyId::Test

test "should not overwrite other locale's slugs on update_attributes" do
test "should not overwrite other locale's slugs on update" do
transaction do
journalist = Journalist.create!(:name => "John Smith")
journalist.set_friendly_id("Juan Fulano", :es)
journalist.save!
assert_equal "john-smith", journalist.to_param
journalist.slug = nil
journalist.update_attributes :name => "Johnny Smith"
journalist.update :name => "Johnny Smith"
assert_equal "johnny-smith", journalist.to_param
I18n.with_locale(:es) do
assert_equal "juan-fulano", journalist.to_param
Expand Down

0 comments on commit f759ba2

Please sign in to comment.