Skip to content

Commit

Permalink
basic state machine for applicants with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrevich committed Apr 23, 2013
1 parent 11a629a commit f1a734b
Show file tree
Hide file tree
Showing 31 changed files with 540 additions and 95 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ capybara-*.html
/public/system/*
/spec/tmp/*
/tmp/*
/vendor/bundle
/vendor/bundle
# Ignore application configuration
/config/application.yml
18 changes: 10 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,27 @@ source 'http://gems.github.com'

gem 'rails', '~>3.2.12'

gem 'aasm'
#gem 'exception_notification', :require => 'exception_notifier'
gem 'figaro'
gem 'formtastic'
gem 'haml'

gem 'carmen'
gem 'ckeditor'
gem 'client_side_validations'
gem 'cocaine', :git => 'git://github.com/thoughtbot/cocaine.git'
gem 'capistrano'
gem 'devise'
gem 'eventbrite-client'
gem 'figaro' # also look at #https://github.com/Squeegy/rails-settings
gem 'haml'
gem 'jquery-rails', '~> 2.1.0'
gem 'jquery-ui-rails'
gem 'kaminari'
gem 'mysql2'
gem 'paperclip'
gem 'paper_trail'
gem 'rails_admin'
gem 'redcarpet'
gem 'rvm-capistrano'
gem 'state_machine'
gem 'whenever', :require => false


group :assets do
gem 'bootstrap-sass', '~> 2.1.1.0'
gem 'bootstrap-datepicker-rails', :require => 'bootstrap-datepicker-rails', :git => 'git://github.com/Nerian/bootstrap-datepicker-rails.git'
Expand All @@ -45,14 +42,19 @@ group :assets do
end

group :development do
gem 'awesome_print'
gem "better_errors"
gem 'binding_of_caller'
gem 'map_by_method'
gem 'bond'
gem 'crack'
gem 'hirb-unicode'
gem 'meta_request'
gem 'net-http-spy'
gem 'rb-fchange', :require => false
gem 'rb-fsevent', :require => false
gem 'rb-inotify', :require => false
gem 'ruby_gntp'
gem 'ruby-graphviz', :require => 'graphviz'
gem 'simplecov'
gem 'what_methods'
gem 'wirble'
Expand Down
27 changes: 20 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ GEM
remote: http://rubygems.org/
remote: http://gems.github.com/
specs:
aasm (3.0.16)
actionmailer (3.2.13)
actionpack (= 3.2.13)
mail (~> 2.5.3)
Expand Down Expand Up @@ -46,12 +45,14 @@ GEM
multi_json (~> 1.0)
addressable (2.3.4)
arel (3.0.2)
awesome_print (1.1.0)
bcrypt-ruby (3.0.1)
better_errors (0.8.0)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
binding_of_caller (0.7.1)
debug_inspector (>= 0.0.1)
bond (0.4.3)
bootstrap-sass (2.1.1.0)
bourne (1.4.0)
mocha (~> 0.13.2)
Expand Down Expand Up @@ -88,6 +89,7 @@ GEM
execjs
coffee-script-source (1.6.2)
columnize (0.3.6)
crack (0.3.2)
database_cleaner (0.9.1)
debug_inspector (0.0.2)
debugger (1.5.0)
Expand Down Expand Up @@ -129,8 +131,6 @@ GEM
railties (>= 3.1.1)
sass-rails (>= 3.1.1)
formatador (0.2.4)
formtastic (2.2.1)
actionpack (>= 3.0)
guard (1.7.0)
formatador (>= 0.2.4)
listen (>= 0.6.0)
Expand All @@ -147,6 +147,10 @@ GEM
haml (3.1.8)
highline (1.6.18)
hike (1.2.2)
hirb (0.7.1)
hirb-unicode (0.0.5)
hirb (~> 0.5)
unicode-display_width (~> 0.1.1)
http_parser.rb (0.5.3)
httparty (0.8.3)
multi_json (~> 1.0)
Expand All @@ -172,7 +176,6 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
map_by_method (0.8.3)
meta_request (0.2.3)
rack-contrib
railties
Expand All @@ -186,6 +189,7 @@ GEM
multi_xml (0.5.3)
mysql2 (0.3.11)
nested_form (0.3.2)
net-http-spy (0.2.1)
net-scp (1.1.0)
net-ssh (>= 2.6.5)
net-sftp (2.1.1)
Expand Down Expand Up @@ -262,6 +266,7 @@ GEM
ffi (>= 0.5.0)
rdoc (3.12.2)
json (~> 1.4)
redcarpet (2.2.2)
ref (1.0.4)
remotipart (1.0.5)
rspec (2.13.0)
Expand All @@ -279,6 +284,7 @@ GEM
rspec-core (~> 2.13.0)
rspec-expectations (~> 2.13.0)
rspec-mocks (~> 2.13.0)
ruby-graphviz (1.0.8)
ruby_gntp (0.3.4)
rvm-capistrano (1.3.0)
capistrano (>= 2.0.0)
Expand All @@ -305,6 +311,7 @@ GEM
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.7)
state_machine (1.2.0)
therubyracer (0.11.4)
libv8 (~> 3.11.8.12)
ref
Expand All @@ -317,6 +324,7 @@ GEM
uglifier (2.0.1)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
unicode-display_width (0.1.1)
warden (1.2.1)
rack (>= 1.0)
what_methods (1.0.1)
Expand All @@ -331,9 +339,10 @@ PLATFORMS
ruby

DEPENDENCIES
aasm
awesome_print
better_errors
binding_of_caller
bond
bootstrap-datepicker-rails!
bootstrap-sass (~> 2.1.1.0)
capistrano
Expand All @@ -344,6 +353,7 @@ DEPENDENCIES
client_side_validations
cocaine!
coffee-rails (~> 3.2.1)
crack
database_cleaner
debugger
devise
Expand All @@ -352,19 +362,19 @@ DEPENDENCIES
faker
figaro
font-awesome-sass-rails
formtastic
guard-livereload
guard-rspec
haml
hirb-unicode
jquery-rails (~> 2.1.0)
jquery-ui-rails
kaminari
launchy
libv8 (~> 3.11.8)
map_by_method
meta_request
modernizr-rails
mysql2
net-http-spy
paper_trail
paperclip
poltergeist
Expand All @@ -373,13 +383,16 @@ DEPENDENCIES
rb-fchange
rb-fsevent
rb-inotify
redcarpet
rspec-rails (~> 2.0)
ruby-graphviz
ruby_gntp
rvm-capistrano
sass-rails (~> 3.2.3)
shoulda
simplecov
sqlite3
state_machine
therubyracer
uglifier (>= 1.0.3)
what_methods
Expand Down
4 changes: 2 additions & 2 deletions app/assets/stylesheets/reuman.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ footer.container { font-size:0.8em;
.field_with_errors { color:#8A1F11; display:inline;
input { background-color:#FBC2C4; }}

#error_explanation { background-color:#FBC2C4; border:2px solid #8A1F11; font-weight:200; margin:10px 0; padding:7px; text-align:left;
h2 { text-align:left; font-weight:normal; margin:2px -7px 10px -7px; padding:5px 5px 5px 15px; font-size:1.6em; background-color:#FBC2C4; color:#8A1F11; }
#error_explanation { background-color:#f2dede; border:2px solid #eed3d7; color:#b94a48; font-weight:200; margin:10px 0; padding:7px; text-align:left; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px;
h2 { text-align:left; font-weight:normal; margin:2px -7px 10px -7px; padding:5px 5px 5px 15px; font-size:1.6em; background-color:#f2dede; color:#b94a48; }
p { color:#333; font-size:1.4em; font-weight:bold; margin-bottom:0; padding:5px; }
ul { margin:1em 3em; }
ul li { font-size:1.2em; list-style:square; }
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/applicants/academic_records_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Applicants::AcademicRecordsController < ApplicationController
before_filter :authenticate_applicant!
before_filter [:authenticate_applicant!, :set_state]

def edit
current_applicant.records.build unless current_applicant.records.count > 0
Expand All @@ -10,7 +10,9 @@ def edit

def update
if current_applicant.update_attributes params[:applicant]
redirect_to applicants_records_url
current_applicant.can_complete_academic_info? ? current_applicant.complete_academic_info : current_applicant.incomplete_academic_info

redirect_to current_applicant.redirect_url
else
render :edit
end
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/applicants/recommenders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ def update
if recommender_data[1]
params[:applicant][:recommenders_attributes] = recommender_data[1]
if @applicant.update_attributes(params[:applicant])
redirect_to applicants_recommenders_url
current_applicant.can_complete_recommender_info? ? current_applicant.complete_recommender_info : current_applicant.incomplete_recommender_info
redirect_to current_applicant.redirect_url
else
render :edit
end
else
redirect_to applicants_recommenders_url
current_applicant.can_complete_recommender_info? ? current_applicant.complete_recommender_info : current_applicant.incomplete_recommender_info
redirect_to current_applicant.redirect_url
end
end

Expand Down
29 changes: 25 additions & 4 deletions app/controllers/applicants/registrations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
class Applicants::RegistrationsController < Devise::RegistrationsController

before_filter :auth, :only => [:status, :update, :submit]

# GET /resource/edit
def edit
@applicant.set_state
render :edit
end

Expand All @@ -25,7 +27,9 @@ def update
set_flash_message :notice, :updated
# Sign in the applicant bypassing validation in case his password changed
sign_in @applicant, :bypass => true
redirect_to edit_applicant_registration_url
@applicant.set_state

redirect_to @applicant.redirect_url
else
render "edit"
end
Expand All @@ -35,17 +39,34 @@ def update
# Show view of profile
def status
@applicant = current_applicant
@applicant.validates_application_completeness if @applicant
end

# GET /resource/submit
# check that app is complete and mark as submitted, trigger confirmation email and recommendation request.
def submit

if current_applicant && current_applicant.submit_application && current_applicant.errors.empty?
flash[:success] = "Application submitted."
redirect_to current_applicant.redirect_url
else
flash[:error] = "You cannot submit your application until it is complete."
redirect_to current_applicant.redirect_url
end
end

private

def auth
:authenticate_applicant!
redirect_to new_applicant_session_url unless current_applicant
end

# https://github.com/plataformatec/devise/wiki/How-To%3a-Allow-users-to-edit-their-account-without-providing-a-password
# check if we need password to update applicant data
# ie if password or email was changed
# extend this as needed
def needs_password?(applicant, params)
applicant.email != params[:applicant][:email] || !params[:applicant][:password].blank?
end

end
5 changes: 5 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ def log_x_forwarded_by
Rails.logger.info "REMOTE IP: " + request.env["HTTP_X_FORWARDED_FOR"].split(',').first
end
end

def set_state
current_applicant.set_state
end

end
15 changes: 11 additions & 4 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,25 @@ def status_error_messages!


def application_status
if current_applicant.errors.empty?
case current_applicant.state
when 'completed_recommender_info'
status = "Ready to submit"
message = "<p>Your application is ready to submit. Please review your data and click the #{link_to "submit button", submit_application_path } when you are ready to submit your application.</p>"
when 'submitted'
status = "Application submitted"
message = "<p>Your application has been submitted and your recommendation request has been sent. Although you will be updated by email, you can continue to monitor this page for status updates or to make modifications to your application before the deadline.</p>"
when 'completed'
status = "Complete"
message = "<p>Your application is complete. Please review your data and #{link_to "logout", destroy_applicant_session_path, :method => :delete} when finished. You will also recieve an email confirming that your application was submitted.</p>"
else
status = "Incomplete"
message = "<p><strong>Your application is incomplete due to the errors mentioned above. It will not be accepted until all of the necessary data has been added.</strong></p>"
message += "<p>Please go back and #{link_to 'edit', edit_applicant_registration_path } your application.</p>"
message = "<p><strong>Your application is incomplete due to the errors mentioned above. It will not be accepted until all of the necessary data has been added."
message += " Please go back and #{link_to 'edit', edit_applicant_registration_path } your application</strong>.</p>"
end

html = <<-HTML
<div id="application_status" class=#{current_applicant.errors.empty? ? "'alert alert-success'" : "'alert alert-error'"}>
<h3>#{status.upcase}</h3>
<h3>#{status}</h3>
#{message}
</div>
HTML
Expand Down
Loading

0 comments on commit f1a734b

Please sign in to comment.