Skip to content

Commit

Permalink
feat(plans): add model
Browse files Browse the repository at this point in the history
  • Loading branch information
castrolem committed Aug 15, 2019
1 parent 2758d51 commit bb60a8b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/models/plan.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

class Plan < ApplicationRecord
validates :name, :description, :amount, presence: true
validates :amount, numericality: true
end
9 changes: 9 additions & 0 deletions spec/factories/plans.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

FactoryBot.define do
factory :plan do
name { Faker::Lorem.words(number: 4) }
description { Faker::Lorem.paragraph }
amount { Faker::Number.decimal(l_digits: 2, r_digits: 2) }
end
end
23 changes: 23 additions & 0 deletions spec/models/plans_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Plan, type: :model do
let(:plan) { FactoryBot.build_stubbed(:plan) }

subject { plan }

describe 'attributes' do
it { is_expected.to respond_to(:name) }
it { is_expected.to respond_to(:description) }
it { is_expected.to respond_to(:amount) }
it { is_expected.to be_valid }
end

describe 'validations' do
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_presence_of(:description) }
it { is_expected.to validate_presence_of(:amount) }
it { is_expected.to allow_value(1235.123).for(:amount) }
end
end
File renamed without changes.

0 comments on commit bb60a8b

Please sign in to comment.