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

Observe ActiveRecord conventions #67

Merged
merged 3 commits into from Aug 14, 2015
Merged
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
8 changes: 6 additions & 2 deletions lib/activeuuid/uuid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class UUID
# duck typing activerecord 3.1 dirty hack )
def gsub *; self; end

def ==(another_uuid)
self.to_s == another_uuid.to_s
end

def next
self.class.random_create
end
Expand All @@ -18,11 +22,11 @@ def quoted_id
end

def as_json(options = nil)
hexdigest.upcase
to_s
end

def to_param
hexdigest.upcase
to_s
end

def self.serialize(value)
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/uuid_mokeypatch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
let(:sql_out) { "x'e4618518cb9f11e1aa7c14dae903e06a'" }

its(:quoted_id) {should == sql_out}
its(:as_json) {should == hex}
its(:to_param) {should == hex}
its(:as_json) {should == uuid.to_s}
its(:to_param) {should == uuid.to_s}
its(:next) {should be_a(described_class)}
end

Expand Down