Skip to content
This repository has been archived by the owner on Mar 20, 2018. It is now read-only.

Commit

Permalink
Allow administrators to resend professor emails
Browse files Browse the repository at this point in the history
  • Loading branch information
keith committed Apr 15, 2014
1 parent 7cfba4a commit 9bdee26
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 18 deletions.
8 changes: 1 addition & 7 deletions app/controllers/applicants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,7 @@ def create

if @applicant.save
begin
ApplicantMailer.account_email(@applicant).deliver
@applicant.positions.each do |position|
next if position.professor_emailed
professor = position.professor
ProfessorMailer.pending_recommendation(professor).deliver
position.professor_emailed = true
end
@applicant.send_emails
rescue Errno::ECONNREFUSED
redirect_to @applicant,
notice: 'Your application was saved but the emails failed to send. Save this URL and contact the ASC for assistance'
Expand Down
16 changes: 14 additions & 2 deletions app/controllers/professors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class ProfessorsController < ApplicationController
before_action :signed_in_admin, only: [:index, :destroy]
before_action :set_professor, only: [:show, :edit, :update, :destroy]
before_action :signed_in_admin, only: [:index, :destroy, :email]
before_action :set_professor, only: [:show, :edit, :update, :destroy, :email]

# GET /professors
def index
Expand Down Expand Up @@ -31,6 +31,18 @@ def destroy
redirect_to professors_url, notice: 'Professor was successfully destroyed.'
end

# POST /professors/1/email
def email
begin
ProfessorMailer.pending_recommendation(@professor).deliver
rescue Errno::ECONNREFUSED
redirect_to professors_url,
notice: "The email failed to send. You can manually send the professor their URL: #{ professor_url(@professor) }"
else
redirect_to professors_url, notice: 'The email was sent successfully'
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_professor
Expand Down
4 changes: 4 additions & 0 deletions app/views/professors/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<p id="notice"><%= notice %></p>

<h1>All professors</h1>

<table>
Expand All @@ -9,6 +11,7 @@
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>

Expand All @@ -21,6 +24,7 @@
<td><%= link_to 'Show', professor %></td>
<td><%= link_to 'Edit', edit_professor_path(professor) %></td>
<td><%= link_to 'Delete', professor, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<td><%= link_to 'Email', email_professor_path(professor), method: :post %></td>
</tr>
<% end %>
</tbody>
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
root 'applicants#new'
resources :emails, except: [:new, :create, :destroy]
resources :positions, except: [:new]
resources :professors, except: [:create, :new]
resources :professors, except: [:create, :new] do
post :email, on: :member
end

resources :users, except: [:show]

Expand Down
12 changes: 8 additions & 4 deletions spec/routing/professors_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@
end

it 'routes to #show' do
get('/professors/1').should route_to('professors#show', :id => '1')
get('/professors/1').should route_to('professors#show', id: '1')
end

it 'routes to #edit' do
get('/professors/1/edit').should route_to('professors#edit', :id => '1')
get('/professors/1/edit').should route_to('professors#edit', id: '1')
end

it 'routes to #update' do
put('/professors/1').should route_to('professors#update', :id => '1')
put('/professors/1').should route_to('professors#update', id: '1')
end

it 'routes to #destroy' do
delete('/professors/1').should route_to('professors#destroy', :id => '1')
delete('/professors/1').should route_to('professors#destroy', id: '1')
end

it 'routes to #email' do
post('/professors/1/email').should route_to('professors#email', id: '1')
end
end
end
9 changes: 5 additions & 4 deletions spec/views/professors/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@
assign(:professors, [
stub_model(Professor,
name: 'Name',
email: 'Email',
email: 'addr',
identifier: 'abc'
),
stub_model(Professor,
name: 'Name',
email: 'Email',
email: 'addr',
identifier: 'abc'
)
])
end

it 'renders a list of professors' do
render
# Run the generator again with the --webrat flag if you want to use webrat matchers

assert_select 'tr>td', text: 'Name'.to_s, count: 2
assert_select 'tr>td', text: "Email#{ EMAIL_SUFFIX }".to_s, count: 2
assert_select 'tr>td', text: "addr#{ EMAIL_SUFFIX }".to_s, count: 2
rendered.should match(/Email/)
end
end

0 comments on commit 9bdee26

Please sign in to comment.