Skip to content

Commit 8dc0f2c

Browse files
authored
Merge pull request #6284 from piyush828-design/6821_no_validation_for_email
BUG: no validation for email in new fund request form
2 parents 292921d + 995418d commit 8dc0f2c

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

app/models/fund_request.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class FundRequest < ApplicationRecord
2+
validates :submitter_email, presence: true
23
end
34

45
# == Schema Information

app/views/fund_requests/new.html.erb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@
1111
<!-- ========== card start ========== -->
1212
<div class="card-style mb-50">
1313
<%= form_with(model: @fund_request, local: true, url: casa_case_fund_request_path(@casa_case), method: :post) do |form| %>
14+
15+
<% if @fund_request.errors.any? %>
16+
<% @fund_request.errors.full_messages.each do |msg| %>
17+
<p><%= msg %></p>
18+
<% end %>
19+
<% end %>
20+
1421
<div class="input-style-1">
15-
<%= form.label :submitter_email, "Your email" %>
16-
<%= form.text_field :submitter_email, class: "form-control", required: true, value: current_user.email %>
22+
<%= form.label :submitter_email, "Your email" %>
23+
<%= form.email_field :submitter_email, class: "form-control", required: false, value: current_user.email %>
1724
</div>
1825

1926
<div class="input-style-1">

spec/models/fund_request_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require "rails_helper"
2+
3+
RSpec.describe FundRequest, type: :model do
4+
it { is_expected.to validate_presence_of(:submitter_email) }
5+
end

spec/system/casa_cases/fund_requests/new_spec.rb

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
require "rails_helper"
22

3-
RSpec.describe "casa_cases/fund_requests/new", type: :system do
4-
it "creates a fund request for the casa case" do
5-
org = create(:casa_org)
6-
volunteer = create(:volunteer, :with_casa_cases, casa_org: org)
7-
casa_case = volunteer.casa_cases.first
3+
RSpec.describe "fund_requests/new", type: :system do
4+
let(:org) { create(:casa_org) }
5+
let(:volunteer) { create(:volunteer, :with_casa_cases, casa_org: org) }
6+
let(:casa_case) { volunteer.casa_cases.first }
87

8+
before do
99
sign_in volunteer
1010
visit new_casa_case_fund_request_path(casa_case)
11+
end
1112

13+
it "creates a fund request for the casa case" do
1214
aggregate_failures do
1315
expect(page).to have_field "Your email", with: volunteer.email
1416
expect(page).to have_field "Name or case number of youth", with: casa_case.case_number
@@ -43,4 +45,18 @@
4345
expect(fr.youth_name).to eq casa_case.case_number
4446
end
4547
end
48+
49+
it "shows error when submitter email is blank" do
50+
fill_in "Your email", with: ""
51+
fill_in "Amount of payment", with: "100"
52+
fill_in "Deadline", with: "2022-12-31"
53+
fill_in "Request is for", with: "Fun outing"
54+
fill_in "Name of payee", with: "Minnie Mouse"
55+
56+
expect {
57+
click_on "Submit Fund Request"
58+
}.not_to change(FundRequest, :count)
59+
60+
expect(page).to have_content("Submitter email can't be blank")
61+
end
4662
end

0 commit comments

Comments
 (0)