2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe UnsubscribeKey do
|
2016-06-16 21:27:52 -04:00
|
|
|
|
|
|
|
describe 'post unsubscribe key' do
|
|
|
|
it 'can generate a correct url' do
|
|
|
|
post = Fabricate(:post)
|
|
|
|
url = post.unsubscribe_url(post.user)
|
|
|
|
|
|
|
|
route = Rails.application.routes.recognize_path(url)
|
|
|
|
|
|
|
|
key = UnsubscribeKey.find_by(key: route[:key])
|
|
|
|
|
|
|
|
expect(key.post_id).to eq(post.id)
|
|
|
|
expect(key.topic_id).to eq(post.topic_id)
|
|
|
|
expect(key.unsubscribe_key_type).to eq("topic")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'key' do
|
|
|
|
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
2022-06-21 14:49:47 -04:00
|
|
|
let!(:key) { UnsubscribeKey.create_key_for(user, UnsubscribeKey::DIGEST_TYPE) }
|
2016-06-16 21:27:52 -04:00
|
|
|
|
|
|
|
it 'has a temporary key' do
|
|
|
|
expect(key).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#user_for_key' do
|
|
|
|
|
|
|
|
it 'can be used to find the user' do
|
|
|
|
expect(UnsubscribeKey.user_for_key(key)).to eq(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil with an invalid key' do
|
|
|
|
expect(UnsubscribeKey.user_for_key('asdfasdf')).to be_blank
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|