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

Make to_param behave as in default AR models #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion lib/obfuscate_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def obfuscate_id_default_spin

module InstanceMethods
def to_param
ObfuscateId.hide(self.id, self.class.obfuscate_id_spin)
ObfuscateId.hide(self.id, self.class.obfuscate_id_spin) if self.id
end

# Override ActiveRecord::Persistence#reload
Expand Down
3 changes: 1 addition & 2 deletions spec/dummy/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

gem 'obfuscate_id', '~> 0.2.0'
gem 'obfuscate_id', path: '../../'

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
Expand All @@ -44,4 +44,3 @@ group :development, :test do
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end

8 changes: 8 additions & 0 deletions spec/models/post_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,12 @@
should eq([post1, post2])
end
end

context 'When not persisted yet' do
let (:new_post) { Post.new content: "one" }

it 'has no param' do
expect(new_post.to_param).to be_nil
end
end
end