fix past courses being shown

This commit is contained in:
Torsten Ruger 2016-11-05 17:27:18 +02:00
parent 3f7e6b6175
commit 0d966f3f6f
5 changed files with 25 additions and 5 deletions

View File

@ -1,6 +1,6 @@
module AppliesHelper
def course_select
Course.all.order(:name).map { |c| [c.full_name, c.id ] }
Course.where("start > ?" , Time.now).order(:start).map { |c| [c.full_name, c.id ] }
end
def plan_select

View File

@ -5,7 +5,7 @@ FactoryGirl.define do
end
extra "With Extras"
sequence :start do |n|
Time.now - 2.weeks + (n*2).weeks
end
Time.now - 3.weeks + (n*2).weeks
end
end
end

View File

@ -12,7 +12,7 @@ feature 'Applies' do
scenario 'Send Application' do
within "#apply_primary_choice_course_id" do
courses = page.find_all("option")
expect(courses.length).to be 3
expect(courses.length).to be 2
end
end

View File

@ -0,0 +1,20 @@
RSpec.describe AppliesHelper, type: :helper do
def make_list(times)
times.each do |t|
create( :course , start: Time.now + t.weeks)
end
end
it "shows 2 courses when 3 are created (because 1 is in the past)" do
make_list [-2 , 2, 2]
expect(helper.course_select.length).to eq( 2 )
end
it "shows 5 of 5 future courses" do
make_list [2, 4 , 6 , 8 , 10]
helper.course_select.each do |options|
course = Course.find options[1]
expect((course.start - DateTime.now).to_i).to be < 150
end
end
end

View File

@ -22,6 +22,6 @@ RSpec.describe Course, type: :model do
it "the second course is in the future" do
create :course
course2 = create :course
expect((course2.start - DateTime.now).to_i).to be < 250
expect((course2.start - DateTime.now).to_i).to be < 400
end
end