Skip to content
This repository was archived by the owner on Dec 3, 2019. It is now read-only.

Commit fb08dec

Browse files
Merge pull request #412 from colto/issue/376
[Issue #376] Filter Expired Scholarships
2 parents 20fae19 + 59c14a4 commit fb08dec

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

app/controllers/api/v1/scholarships_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Api
22
module V1
33
class ScholarshipsController < ApiController
44
def index
5-
render json: Scholarship.all
5+
render json: Scholarship.unexpired
66
end
77

88
def show

app/models/scholarship.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
class Scholarship < ApplicationRecord
22
has_many :scholarship_applications
3+
4+
scope :unexpired, -> { where('close_time > ? OR close_time IS NULL', Time.current) }
35
end

test/models/scholarship_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require 'test_helper'
2+
3+
class ScholarshipTest < ActiveSupport::TestCase
4+
test 'unexpired returns unexpired scholarships' do
5+
nil_date = create :scholarship, close_time: nil
6+
active_date = create :scholarship, close_time: 3.days.from_now
7+
8+
assert_equal Scholarship.unexpired, [nil_date, active_date]
9+
end
10+
11+
test 'unexpired doesn\'t return expired scholarships' do
12+
expired_date = create :scholarship, close_time: 3.days.ago
13+
14+
assert_not_includes Scholarship.unexpired, expired_date
15+
end
16+
end

0 commit comments

Comments
 (0)