summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2023-03-27 20:04:00 -0600
committerHombreLaser <sebastian-440@live.com>2023-03-27 20:04:00 -0600
commit35ec25dcb3d57b17a3dc174503b7d20dd4c46e43 (patch)
tree4bf53848d7460947b9c70aa74dc934279d94af55 /spec
parent7b5d00f1bf262cc40b6b9dc21bb42e2dc7c80afe (diff)
Añade specs de Card
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/card.rb12
-rw-r--r--spec/models/card_spec.rb40
2 files changed, 51 insertions, 1 deletions
diff --git a/spec/factories/card.rb b/spec/factories/card.rb
new file mode 100644
index 0000000..ddcafaf
--- /dev/null
+++ b/spec/factories/card.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: true
+
+FactoryBot.define do
+ factory :card, class: 'Card' do
+ number { "#{rand(1000..9999)}-#{rand(1000..9999)}-#{rand(1000..9999)}-#{rand(1000..9999)}" }
+ expiration_day { rand(1..31) }
+ expiration_month { rand(1..12) }
+ expiration_year { rand(1971..2025) }
+ security_code { rand(100..999) }
+ user_account { create(:user_account) }
+ end
+end
diff --git a/spec/models/card_spec.rb b/spec/models/card_spec.rb
index 6f49b4a..11bee2d 100644
--- a/spec/models/card_spec.rb
+++ b/spec/models/card_spec.rb
@@ -1,5 +1,43 @@
+# frozen_string_literal: true
+
require 'rails_helper'
RSpec.describe Card, type: :model do
- pending "add some examples to (or delete) #{__FILE__}"
+ 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