From 35ec25dcb3d57b17a3dc174503b7d20dd4c46e43 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Mon, 27 Mar 2023 20:04:00 -0600 Subject: AƱade specs de Card MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/card.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'app/models') diff --git a/app/models/card.rb b/app/models/card.rb index ae2b1e5..594ae43 100644 --- a/app/models/card.rb +++ b/app/models/card.rb @@ -1,3 +1,20 @@ +# frozen_string_literal: true + +# Card +# number: string +# expiration_month: integer +# expiration_year: integer +# expiration_day: integer +# security_code: integer class Card < ApplicationRecord belongs_to :user_account + validates :number, presence: true, uniqueness: true, length: { is: 16 } + validates :expiration_year, presence: true, numericality: { greater_than: 1970 } + validates :expiration_month, presence: true, inclusion: { in: 1..12 } + validates :expiration_day, presence: true, inclusion: { in: 1..31 } + validates :security_code, presence: true + + def expiration_date + "#{expiration_day}/#{expiration_month}/#{expiration_year}" + end end -- cgit v1.2.3