Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/grants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def grant_params
params.require(:grant).permit(
:name, :description, :amount_dollars, :amount_cents, :funder_sgid,
:funds_allocation_deadline, :funds_received_on, :eligibility_criteria, :tasks,
:people_funded,
sector_ids: [], category_ids: [],
primary_asset_attributes: [ :id, :file, :_destroy ],
gallery_assets_attributes: [ :id, :file, :_destroy ]
Expand Down
35 changes: 22 additions & 13 deletions app/views/grants/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@
<%= render "shared/errors", resource: @grant if @grant.errors.any? %>

<div class="space-y-6">
<div>
<%= f.input :name,
label: "Grant name",
input_html: { class: "w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-800 shadow-sm" } %>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<%= f.input :name,
label: "Grant name",
input_html: { class: "w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-800 shadow-sm" } %>
</div>
<div>
<%= f.label :amount_dollars, "Funding amount", class: "block text-sm font-medium text-gray-700 mb-1" %>
<div class="relative">
<span class="absolute inset-y-0 left-0 flex items-center pl-3 text-gray-500 text-sm">$</span>
<%= f.number_field :amount_dollars, step: 0.01, value: @grant.amount_dollars,
class: "pl-7 w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-800 shadow-sm" %>
</div>
<p class="mt-1 text-xs text-gray-500">Total scholarship amounts awarded from this grant cannot exceed this.</p>
</div>
</div>

<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
Expand All @@ -27,15 +38,13 @@
label: "Funder",
hint: "The organization or person funding the grant." %>
</div>
<div>
<%= f.label :amount_dollars, "Funding amount", class: "block text-sm font-medium text-gray-700 mb-1" %>
<div class="relative">
<span class="absolute inset-y-0 left-0 flex items-center pl-3 text-gray-500 text-sm">$</span>
<%= f.number_field :amount_dollars, step: 0.01, value: @grant.amount_dollars,
class: "pl-7 w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-800 shadow-sm" %>
</div>
<p class="mt-1 text-xs text-gray-500">Total scholarship amounts awarded from this grant cannot exceed this.</p>
</div>
<label class="flex items-start gap-3 rounded-lg border border-gray-200 bg-white p-4 shadow-sm cursor-pointer hover:bg-gray-50 transition">
<%= f.input_field :people_funded, as: :boolean, class: "mt-0.5 h-4 w-4 text-blue-600 rounded" %>
<span>
<span class="block text-sm font-medium text-gray-800">People-funded (aka Legacy Scholarship)</span>
<span class="block text-xs text-gray-500">Funded by a collection of individuals, usually to honor a loved one.</span>
</span>
</label>
</div>

<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
Expand Down
7 changes: 6 additions & 1 deletion app/views/grants/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
<% end %>
<div class="flex items-start justify-between">
<div>
<h1 class="text-2xl font-semibold text-gray-900"><%= grant.name %></h1>
<div class="flex items-center gap-2 flex-wrap">
<h1 class="text-2xl font-semibold text-gray-900"><%= grant.name %></h1>
<% if @grant.people_funded? %>
<span class="inline-flex items-center rounded-full bg-amber-100 px-2.5 py-0.5 text-xs font-medium text-amber-800">People-funded</span>
<% end %>
</div>
<p class="text-gray-600 mt-1"><%= grant_funder_badge(grant) %></p>
</div>
<% if allowed_to?(:edit?, @grant) %>
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20260814230559_add_people_funded_to_grants.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddPeopleFundedToGrants < ActiveRecord::Migration[8.1]
def up
add_column :grants, :people_funded, :boolean, default: false, null: false
end

def down
remove_column :grants, :people_funded, if_exists: true
end
end
1 change: 1 addition & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@
t.date "funds_allocation_deadline"
t.date "funds_received_on"
t.string "name", null: false
t.boolean "people_funded", default: false, null: false
t.text "tasks"
t.datetime "updated_at", null: false
t.bigint "updated_by_id"
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/grants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@
trait :donated_by_person do
association :funder, factory: :person
end

trait :people_funded do
people_funded { true }
end
end
end
6 changes: 6 additions & 0 deletions spec/models/grant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
end
end

describe "people_funded" do
it "defaults to false" do
expect(Grant.new.people_funded).to be(false)
end
end

describe "validations" do
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_numericality_of(:amount_cents).is_greater_than_or_equal_to(0) }
Expand Down
6 changes: 6 additions & 0 deletions spec/requests/grants_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@
expect(Grant.last.primary_asset.file).to be_attached
end

it "flags the grant as people-funded when checked" do
post grants_url, params: { grant: valid_attributes.merge(people_funded: "1") }

expect(Grant.last).to be_people_funded
end

it "attaches the selected sectors and categories" do
sector = create(:sector, :published)
category = create(:category, :published)
Expand Down