-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
80872: Add ivc_champva_form model, factory and tests
- Loading branch information
Showing
4 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
class IvcChampvaForm < ApplicationRecord | ||
validates :email, presence: true | ||
validates :email, uniqueness: true | ||
|
||
# Add more complex data modeling here outside of CRUD | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :ivc_champva_form do | ||
email { Faker::Internet.email } | ||
first_name { Faker::Name.first_name } | ||
last_name { Faker::Name.last_name } | ||
form_number { '10-10D' } | ||
file_name { Faker::File.file_name } | ||
form_uuid { SecureRandom.uuid } | ||
s3_status { 200 } | ||
pega_status { %w[pending processing completed].sample } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe IvcChampvaForm, type: :model do | ||
describe 'validations' do | ||
it { is_expected.to validate_presence_of(:email) } | ||
it { is_expected.to validate_uniqueness_of(:email) } | ||
end | ||
|
||
describe 'factory' do | ||
it 'is valid' do | ||
expect(build(:ivc_champva_form)).to be_valid | ||
end | ||
end | ||
|
||
describe 'methods' do | ||
describe '#create' do | ||
it 'creates a new form' do | ||
expect { create(:ivc_champva_form) }.to change(IvcChampvaForm, :count).by(1) | ||
end | ||
end | ||
|
||
describe '#update' do | ||
let(:form) { create(:ivc_champva_form) } | ||
|
||
it 'updates an existing form' do | ||
new_email = '[email protected]' | ||
form.update(email: new_email) | ||
expect(form.reload.email).to eq(new_email) | ||
end | ||
end | ||
|
||
describe '#destroy' do | ||
let!(:form) { create(:ivc_champva_form) } | ||
|
||
it 'deletes an existing form' do | ||
expect { form.destroy }.to change(IvcChampvaForm, :count).by(-1) | ||
end | ||
end | ||
end | ||
end |