|
1274 | 1274 | expect{ signature.validate! }.to change{ petition.reload.signature_count }.by(0) |
1275 | 1275 | end |
1276 | 1276 |
|
| 1277 | + it "generates a signed_token if it's missing" do |
| 1278 | + signature.update_column(:signed_token, nil) |
| 1279 | + |
| 1280 | + expect { |
| 1281 | + signature.validate! |
| 1282 | + }.to change { |
| 1283 | + signature.reload[:signed_token] |
| 1284 | + }.from(nil).to(be_present) |
| 1285 | + end |
| 1286 | + |
1277 | 1287 | it 'tells the relevant constituency petition journal to record a new signature' do |
1278 | 1288 | expect(ConstituencyPetitionJournal).to receive(:record_new_signature_for).with(signature) |
1279 | 1289 | signature.validate! |
|
1697 | 1707 | end |
1698 | 1708 | end |
1699 | 1709 |
|
| 1710 | + describe "#signed_token" do |
| 1711 | + let(:signature) { FactoryBot.create(:validated_signature) } |
| 1712 | + |
| 1713 | + context "when the underlying column is nil" do |
| 1714 | + before do |
| 1715 | + signature.update_column(:signed_token, nil) |
| 1716 | + end |
| 1717 | + |
| 1718 | + it "generates and saves a new token" do |
| 1719 | + expect { |
| 1720 | + signature.signed_token |
| 1721 | + }.to change { |
| 1722 | + signature.reload[:signed_token] |
| 1723 | + }.from(nil).to(be_present) |
| 1724 | + end |
| 1725 | + end |
| 1726 | + |
| 1727 | + context "when another process has updated the column" do |
| 1728 | + let(:token) { Authlogic::Random.friendly_token } |
| 1729 | + |
| 1730 | + before do |
| 1731 | + signature.update_column(:signed_token, nil) |
| 1732 | + end |
| 1733 | + |
| 1734 | + it "returns the token from the database" do |
| 1735 | + expect(signature).to receive(:signed_token?).and_return(true) |
| 1736 | + expect(signature).to receive(:read_attribute).with(:signed_token).and_return(token) |
| 1737 | + expect(signature.signed_token).to eq(token) |
| 1738 | + end |
| 1739 | + end |
| 1740 | + end |
| 1741 | + |
1700 | 1742 | describe 'email sent timestamps' do |
1701 | 1743 | describe '#get_email_sent_at_for' do |
1702 | 1744 | let(:signature) { FactoryBot.create(:validated_signature) } |
|
0 commit comments