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

Commit

Permalink
Merge pull request #412 from colto/issue/376
Browse files Browse the repository at this point in the history
[Issue #376] Filter Expired Scholarships
  • Loading branch information
apex-omontgomery authored Oct 10, 2018
2 parents 20fae19 + 59c14a4 commit fb08dec
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/api/v1/scholarships_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Api
module V1
class ScholarshipsController < ApiController
def index
render json: Scholarship.all
render json: Scholarship.unexpired
end

def show
Expand Down
2 changes: 2 additions & 0 deletions app/models/scholarship.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class Scholarship < ApplicationRecord
has_many :scholarship_applications

scope :unexpired, -> { where('close_time > ? OR close_time IS NULL', Time.current) }
end
16 changes: 16 additions & 0 deletions test/models/scholarship_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'test_helper'

class ScholarshipTest < ActiveSupport::TestCase
test 'unexpired returns unexpired scholarships' do
nil_date = create :scholarship, close_time: nil
active_date = create :scholarship, close_time: 3.days.from_now

assert_equal Scholarship.unexpired, [nil_date, active_date]
end

test 'unexpired doesn\'t return expired scholarships' do
expired_date = create :scholarship, close_time: 3.days.ago

assert_not_includes Scholarship.unexpired, expired_date
end
end

0 comments on commit fb08dec

Please sign in to comment.