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

Model should set authentication token value before validation #316

Open
wants to merge 1 commit 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
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def token_generator

module ClassMethods
def acts_as_token_authenticatable(options = {})
before_save :ensure_authentication_token
before_validation :ensure_authentication_token
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you want add following line too

validates :authentication_token, presence: true, uniqueness: true

end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ def generate_token
end
end

describe 'which supports the :before_save hook' do
describe 'which supports the :before_validation hook' do

context 'when it acts as token authenticatable' do
it 'ensures its instances have an authentication token before being saved (1)', rspec_3_error: true, public: true do
some_class = @subjects.first

expect(some_class).to receive(:before_save).with(:ensure_authentication_token)
expect(some_class).to receive(:before_validation).with(:ensure_authentication_token)
some_class.acts_as_token_authenticatable
end

it 'ensures its instances have an authentication token before being saved (2)', rspec_3_error: true, public: true do
some_child_class = @subjects.last

expect(some_child_class).to receive(:before_save).with(:ensure_authentication_token)
expect(some_child_class).to receive(:before_validation).with(:ensure_authentication_token)
some_child_class.acts_as_token_authenticatable
end
end
Expand Down