blob: 11bee2dadd8e043ad4479044f7dc0b6714cf9683 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Card, type: :model do
let(:card) { build(:card) }
it { should belong_to(:user_account)}
it { should validate_presence_of(:number) }
it { should validate_presence_of(:security_code) }
it { should validate_presence_of(:expiration_year) }
it { should validate_presence_of(:expiration_month) }
it { should validate_presence_of(:expiration_day) }
it { should validate_numericality_of(:expiration_year) }
describe 'expiration_month' do
it "can't be less than 1 or greater than 12" do
card.expiration_month = 0
expect(card.save).to be_falsey
card.expiration_month = 13
expect(card.save).to be_falsey
end
end
describe 'expiration_day' do
it "can't be less than 1 or greater than 31" do
card.expiration_day = 0
expect(card.save).to be_falsey
card.expiration_day = 32
expect(card.save).to be_falsey
end
end
describe '#expiration_date' do
it 'renders the expiration date in a friendly format' do
card.expiration_year = 2025
card.expiration_month = 3
card.expiration_day = 24
expect(card.expiration_date).to eq('24/3/2025')
end
end
end
|