Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from minostro/master
Browse files Browse the repository at this point in the history
Implement a new method called find_obfuscated
  • Loading branch information
mguymon committed May 11, 2013
2 parents 30efd7d + 8fffe7a commit 27dc45a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/obfuscate/obfuscatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ def find_by_obfuscated_id( text )
find_by_id( clarify_id( text ) )
end

# Find by obfuscated_id
# @raises ActiveRecord::RecordNotFound
# @return [Object]
def find_obfuscated( text )
find( clarify_id( text ) )
end

# Clarifies obfuscated Model id
# @return [String]
def clarify_id( text )
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/obfuscate/ofuscatable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
ActiveRecord::Base.method_defined?( :find_by_obfuscated_id ).should be_false
end

it "should give a hoot and not pollute" do
ActiveRecord::Base.method_defined?( :find_obfuscated ).should be_false
end

it "should have config" do
Message.obfuscatable_config.salt.should eql "message salt"
end
Expand Down Expand Up @@ -61,6 +65,14 @@
it "should find_by_obfuscated_id" do
Message.find_by_obfuscated_id( model.obfuscated_id ).should eql model
end

it "should find_obfuscated" do
Message.find_obfuscated(model.obfuscated_id).should eql model
end

it "raises ActiveRecord::RecordNotFound retreiving a not existing model" do
expect { Message.find_obfuscated('NOT_EXIST') }.to raise_error(ActiveRecord::RecordNotFound)
end
end
end

Expand Down

0 comments on commit 27dc45a

Please sign in to comment.