Skip to content

Commit

Permalink
When User is not logged in then display only open positions
Browse files Browse the repository at this point in the history
Otherwise display applied, job seekers, and unapplied positions
  • Loading branch information
Rodney Degracia committed Dec 22, 2011
1 parent 85c85f6 commit 92e2f1d
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 26 deletions.
10 changes: 10 additions & 0 deletions app/controllers/dashboard_controller.rb
Expand Up @@ -3,6 +3,16 @@ class DashboardController < ApplicationController
def index
@open_positions = Position.open_positions
@job_seekers = Profile.find_all_by_available(true) || []

if current_user == nil
@applied_positions = []
@unapplied_positions = []
else
@applied_positions = current_user.applications
@unapplied_positions = Position.unapplied_by(current_user)
end


end

end
37 changes: 26 additions & 11 deletions app/views/dashboard/index.html.erb
@@ -1,26 +1,41 @@
<h1>jobs.familab.org</h1>
<hr>
<div class = "unapplied">
<div class = "open">
<%=
render(:partial => "positions/unapplied",
:locals =>{ :unapplied_positions => @open_positions })
render(:partial => "positions/open",
:locals =>{ :open_positions => @open_positions })
%>
</div>
<hr>
<div class = "job_seekers">
<%=
render(:partial => "profiles/job_seekers",
:locals =>{ :job_seekers => @job_seekers })
%>
</div>
<hr>

<% if user_signed_in? %>
<%= link_to 'Create Job Position', new_position_path %> |
<% if current_user.profile != nil %>
<%= link_to 'Profile', profile_path(current_user.profile) %>
<% else %>
<%= link_to 'Profile', new_profile_path %>
<% end %>

<div class = "unapplied">
<%=
render(:partial => "positions/unapplied",
:locals =>{ :unapplied_positions => @unapplied_positions })
%>
</div>
<hr>
<div class = "job_seekers">
<%=
render(:partial => "profiles/job_seekers",
:locals =>{ :job_seekers => @job_seekers })
%>
</div>
<hr>
<div class = "applied">
<%=
render(:partial => "positions/applied",
:locals =>{ :applied_positions => @applied_positions })
%>
<hr>

<% end %>


26 changes: 26 additions & 0 deletions app/views/positions/_open.html.erb
@@ -0,0 +1,26 @@
<h3>Open Positions</h3>

<table>
<tr>
<th>Title</th>
<th>Description</th>
<th>Rate</th>
<th>Open</th>
<th></th>
<th></th>
<th></th>
</tr>

<% open_positions.each do |position| %>
<tr>
<td><%= position.title %></td>
<td><%= position.description %></td>
<td><%= position.rate %></td>
<td><%= position.open %></td>
<td><%= link_to 'Show', position %></td>
</tr>
<% end %>
</table>

<br />

5 changes: 5 additions & 0 deletions features/step_definitions/login_steps.rb
Expand Up @@ -8,8 +8,13 @@
end

Then /^the dashboard will display open positions$/ do
user1 = FactoryGirl.create(:bob)
position = FactoryGirl.create(:rails_dev)
user1.positions << position
user1.save

visit root_path

page.should have_content('Rails Developer')
end

Expand Down
64 changes: 62 additions & 2 deletions spec/controllers/dashboard_controller_spec.rb
@@ -1,6 +1,11 @@
require 'spec_helper'

describe DashboardController do

# devise rspec, see #spec/spec_helper.rb
# allows subject.current_user to exist within the controller spec
login_user

describe "GET index" do
it "gets open positions" do

Expand All @@ -13,19 +18,74 @@
Position.should_receive(:open_positions).and_return(open_positions)

get :index

open_positions = Position.open_positions
assigns(:open_positions).should eql(open_positions)

response.should render_template(root_path)
end

it "gets job seekers" do
profile1 = FactoryGirl.create :alvin_profile
profile2 = FactoryGirl.create :bob_profile
job_seekers = [subject.current_user.profile, profile1, profile2]

Profile.stub(:job_seekers).and_return(job_seekers)
Profile.should_receive(:job_seekers).and_return(job_seekers)

get :index

job_seekers = Profile.job_seekers
assigns(:job_seekers).should eql(job_seekers)

response.should render_template(root_path)
end

it "gets positions applied" do
it "gets positions the current user has applied to" do

p1 = FactoryGirl.create :php_dev
subject.current_user.applications << p1

p2 = FactoryGirl.create :rails_dev

p3 = FactoryGirl.create :perl_dev
subject.current_user.applications << p3

applied_positions = [p1, p3]

get :index

assigns(:applied_positions).should eql(applied_positions)

response.should render_template(root_path)
end

it "gets positions not applied" do
it "gets positions the current user has not applied" do

other_user = FactoryGirl.create :bob

p1 = FactoryGirl.create :php_dev
subject.current_user.applications << p1

p2 = FactoryGirl.create :rails_dev
other_user.positions << p2
other_user.save

p3 = FactoryGirl.create :perl_dev
subject.current_user.applications << p3
subject.current_user.save

applied_positions = [p1, p3]

Position.stub(:unapplied).with(subject.current_user).and_return([p2])
Position.should_receive(:unapplied).and_return([p2])

get :index

unapplied_positions = Position.unapplied(subject.current_user)
assigns(:unapplied_positions).should eql(unapplied_positions)

response.should render_template(root_path)
end
end
end
23 changes: 10 additions & 13 deletions spec/views/dashboard/index.html.erb_spec.rb
Expand Up @@ -36,22 +36,19 @@
rendered.should =~ /PHP Developer/
end

it "does not display applied jobs" do
it "displays open jobs" do
current_user = mock_model(Profile, :firstname => 'Alvin', :lastname => "Alva", :jobtitle => 'PHP Developer')
position1 = mock_model(Position, :title => "PHP Developer", :description => 'PHP Developer', :rate => '1.0', :job_applicants => [current_user])
position1 = mock_model(Position, :title => "PHP Developer", :description => 'PHP Developer', :rate => '1.0', :user_id => current_user, :open => true)

@applied_positions = [position1]
other_user = mock_model(Profile, :firstname => 'Bob', :lastname => "Barker", :jobtitle => 'Rails Developer')
position2 = mock_model(Position, :title => "Perl Developer", :description => 'Perl Developer', :rate => '1.0', :user_id => other_user, :open => true)

render :partial => "positions/applied", :locals => {:applied_positions => @applied_positions}
@open_positions = [position1, position2]

rendered.should !~ /PHP Developer/
render :partial => "positions/open", :locals => {:open_positions => @open_positions}

rendered.should =~ /PHP Developer/
rendered.should =~ /Perl Developer/
end

end


# @positions = [position1, position2, position3]
#
# render(:partial => 'positions/open', :locals => { :positions => @positions})
#
# rendered.should contain("PHP Developer")
20 changes: 20 additions & 0 deletions spec/views/positions/_open.html.erb_spec.rb
@@ -0,0 +1,20 @@
require 'spec_helper'

describe 'positions/_open.html.erb' do

it "displays open jobs" do
current_user = mock_model(Profile, :firstname => 'Alvin', :lastname => "Alva", :jobtitle => 'PHP Developer')
position1 = mock_model(Position, :title => "PHP Developer", :description => 'PHP Developer', :rate => '1.0', :user_id => current_user, :open => true)

other_user = mock_model(Profile, :firstname => 'Bob', :lastname => "Barker", :jobtitle => 'Rails Developer')
position2 = mock_model(Position, :title => "Perl Developer", :description => 'Perl Developer', :rate => '1.0', :user_id => other_user, :open => true)

@open_positions = [position1, position2]

render :partial => "positions/open", :locals => {:open_positions => @open_positions}

rendered.should =~ /PHP Developer/
rendered.should =~ /Perl Developer/
end

end

0 comments on commit 92e2f1d

Please sign in to comment.