Skip to content

Commit

Permalink
Handle proposal cutoff dates.
Browse files Browse the repository at this point in the history
Use timecop to freeze time in tests. Do not allow users to create, view new,
view edit or update proposals after the cutoff date.
  • Loading branch information
Brett Chalupa committed Mar 14, 2014
1 parent d234219 commit 0d5e4c5
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ group :test do
gem 'capybara', '~> 2.2'
gem 'poltergeist', '~> 1.5'
gem 'launchy'
gem 'timecop'
end
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ GEM
thread_safe (0.2.0)
atomic (>= 1.1.7, < 2)
tilt (1.4.1)
timecop (0.7.1)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
Expand Down Expand Up @@ -288,4 +289,5 @@ DEPENDENCIES
sdoc
simple_form (~> 3.0)
sqlite3
timecop
uglifier (>= 1.3.0)
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Proposals

Proposals is a Ruby on Rails application that handles Call for Proposals.
Proposals is a Ruby on Rails and Ember application that handles Call for Proposals.

## Configuring Cutoff Date

In `application.rb`, set `config.cutoff_date` to the date when proposals close.
For example `config.cutoff_date = "March 17th, 2014".to_date`. Tests use a date
that is 60 days in the future and Timecop to test the future.
7 changes: 7 additions & 0 deletions app/controllers/proposals_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class ProposalsController < ApplicationController
before_filter :require_authentication!
before_filter :require_before_close_date!, only: [:create, :new, :edit, :update]

def index
@proposals = current_user.proposals
Expand Down Expand Up @@ -57,4 +58,10 @@ def proposal_params
params.require(:proposal).permit(:title, :abstract, :notes, :pitch,
user_attributes: [:name, :email, :photo, :website, :bio, :twitter, :github])
end

def require_before_close_date!
if Time.now > Proposals::Application.config.cutoff_date
redirect_to root_path, alert: "Proposals are closed, sorry."
end
end
end
2 changes: 2 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@
config.active_support.deprecation = :stderr

config.action_mailer.default_url_options = { host: 'cfp.burlingtonrubyconference.com' }

config.cutoff_date = Date.today + 60
end
40 changes: 40 additions & 0 deletions test/controllers/proposals_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,44 @@ class ProposalsControllerTest < ActionController::TestCase
delete :destroy, id: @rails_doesnt_scale.id
assert_response 401
end

test 'should not allow user to GET new proposal after close date' do
sign_in @brett

Timecop.freeze(Date.today + 400000) do
get :new
assert_redirected_to root_path
assert_equal "Proposals are closed, sorry.", flash[:alert]
end
end

test 'should not allow user to create a proposal after close date' do
sign_in @brett

Timecop.freeze(Date.today + 400000) do
post :create, proposal: { title: 'Great Talk', abstract: 'Best talk' }
assert_redirected_to root_path
assert_equal "Proposals are closed, sorry.", flash[:alert]
end
end

test 'should not allow user to edit a proposal after close date' do
sign_in @brett

Timecop.freeze(Date.today + 400000) do
get :edit, id: @rails_doesnt_scale
assert_redirected_to root_path
assert_equal "Proposals are closed, sorry.", flash[:alert]
end
end

test 'should not allow user to update a proposal after close date' do
sign_in @brett

Timecop.freeze(Date.today + 400000) do
patch :update, id: @rails_doesnt_scale.id, proposal: { title: "Rails Does Scale" }
assert_redirected_to root_path
assert_equal "Proposals are closed, sorry.", flash[:alert]
end
end
end

0 comments on commit 0d5e4c5

Please sign in to comment.