Skip to content

Commit

Permalink
Do not validate uniqueness if nothing changed
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmetal committed Feb 18, 2021
1 parent a2b38c6 commit f46f100
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
28 changes: 14 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
PATH
remote: .
specs:
uuidable (0.2.4)
uuidable (0.2.5)
activerecord (>= 4.2, < 6.1)
uuidtools (>= 2.1, < 3)

GEM
remote: https://rubygems.org/
specs:
activemodel (5.2.4.4)
activesupport (= 5.2.4.4)
activerecord (5.2.4.4)
activemodel (= 5.2.4.4)
activesupport (= 5.2.4.4)
arel (>= 9.0)
activesupport (5.2.4.4)
activemodel (6.0.3.5)
activesupport (= 6.0.3.5)
activerecord (6.0.3.5)
activemodel (= 6.0.3.5)
activesupport (= 6.0.3.5)
activesupport (6.0.3.5)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.2, >= 2.2.2)
addressable (2.4.0)
arel (9.0.0)
ast (2.3.0)
backports (3.6.8)
concurrent-ruby (1.1.7)
concurrent-ruby (1.1.8)
diff-lcs (1.2.5)
ethon (0.8.1)
ffi (>= 1.3.0)
Expand All @@ -40,12 +39,12 @@ GEM
net-http-persistent (>= 2.7)
net-http-pipeline
highline (1.7.8)
i18n (1.8.5)
i18n (1.8.9)
concurrent-ruby (~> 1.0)
json (2.3.1)
launchy (2.4.3)
addressable (~> 2.3)
minitest (5.14.2)
minitest (5.14.3)
multi_json (1.11.2)
multipart-post (2.0.0)
net-http-persistent (2.9.4)
Expand Down Expand Up @@ -93,11 +92,12 @@ GEM
typhoeus (~> 0.6, >= 0.6.8)
typhoeus (0.8.0)
ethon (>= 0.8.0)
tzinfo (1.2.7)
tzinfo (1.2.9)
thread_safe (~> 0.1)
unicode-display_width (1.3.0)
uuidtools (2.1.5)
uuidtools (2.2.0)
websocket (1.2.2)
zeitwerk (2.4.2)

PLATFORMS
ruby
Expand Down
2 changes: 1 addition & 1 deletion lib/uuidable/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module ClassMethods

def uuidable(as_param: true)
after_initialize { self.uuid = Uuidable.generate_uuid if attributes.keys.include?('uuid') && uuid.blank? }
validates :uuid, presence: true, uniqueness: true
validates :uuid, presence: true, uniqueness: true, if: :uuid_changed?

if as_param
define_method :to_param do
Expand Down
2 changes: 1 addition & 1 deletion lib/uuidable/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Uuidable
VERSION = '0.2.4'.freeze
VERSION = '0.2.5'.freeze
end

0 comments on commit f46f100

Please sign in to comment.