diff --git a/Gemfile b/Gemfile index 001591e..ade405b 100644 --- a/Gemfile +++ b/Gemfile @@ -8,4 +8,4 @@ gem 'rake' gem 'mysql2' gem 'rspec' gem 'byebug' -gem 'activerecord', '~> 4.2.0' +gem 'activerecord', '~> 5.2.3' diff --git a/lib/louisville/extensions/history.rb b/lib/louisville/extensions/history.rb index 6afa098..12acc9e 100644 --- a/lib/louisville/extensions/history.rb +++ b/lib/louisville/extensions/history.rb @@ -27,8 +27,8 @@ def self.included(base) extend ::Louisville::Extensions::History::ClassMethods # If our slug has changed we should manage the history. - after_save :delete_matching_historical_slug, :if => :louisville_slug_changed? - after_save :generate_historical_slug, :if => :louisville_slug_changed? + after_save :delete_matching_historical_slug, if: :louisville_slug_previously_changed? + after_save :generate_historical_slug, if: :louisville_slug_previously_changed? before_destroy :destroy_historical_slugs! end @@ -63,7 +63,7 @@ def delete_matching_historical_slug # Then we generate a new historical slug for the previous value (if there is one). def generate_historical_slug - previous_value = self.send("#{louisville_config[:column]}_was") + previous_value = self.previous_changes[louisville_config[:column]].try(:[], 0) return unless previous_value diff --git a/lib/louisville/slugger.rb b/lib/louisville/slugger.rb index e6dc2b8..70a8748 100644 --- a/lib/louisville/slugger.rb +++ b/lib/louisville/slugger.rb @@ -53,6 +53,9 @@ def louisville_slug_changed? self.send("#{louisville_config[:column]}_changed?") end + def louisville_slug_previously_changed? + self.send("#{louisville_config[:column]}_previously_changed?") + end def apply_louisville_slug value = extract_louisville_slug_value_from_field diff --git a/lib/louisville/version.rb b/lib/louisville/version.rb index 569ac77..639e55d 100644 --- a/lib/louisville/version.rb +++ b/lib/louisville/version.rb @@ -3,7 +3,7 @@ module VERSION MAJOR = 0 MINOR = 0 - PATCH = 4 + PATCH = 6 PRE = nil def self.to_s diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index be63482..e50618a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,6 +7,7 @@ require 'active_record' require 'louisville' +require 'yaml' begin require 'byebug'