diff --git a/Changelog.md b/Changelog.md index f9fef0ab7..2a7bd1855 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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)) diff --git a/lib/friendly_id/configuration.rb b/lib/friendly_id/configuration.rb index 5e3d70220..d835278da 100644 --- a/lib/friendly_id/configuration.rb +++ b/lib/friendly_id/configuration.rb @@ -25,6 +25,7 @@ class Configuration attr_accessor :routes def initialize(model_class, values = nil) + @base = nil @model_class = model_class @defaults = {} @modules = [] diff --git a/test/history_test.rb b/test/history_test.rb index debdc4e37..294dfb322 100644 --- a/test/history_test.rb +++ b/test/history_test.rb @@ -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 @@ -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 @@ -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' diff --git a/test/shared.rb b/test/shared.rb index aabe0b940..213774312 100644 --- a/test/shared.rb +++ b/test/shared.rb @@ -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 @@ -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 diff --git a/test/simple_i18n_test.rb b/test/simple_i18n_test.rb index f9a452fa8..4ab6d9bb7 100644 --- a/test/simple_i18n_test.rb +++ b/test/simple_i18n_test.rb @@ -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