Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added jobs management in admin panel and simple authentication system

  • Loading branch information...
commit e8a40d474957cdb87eea95a2cffff0c1c07ce05d 1 parent df546a2
@wlodars wlodars authored
Showing with 532 additions and 50 deletions.
  1. +10 −0 app/controllers/admin/categories_controller.rb
  2. +37 −0 app/controllers/admin/jobs_controller.rb
  3. +8 −1 app/controllers/application.rb
  4. +27 −0 app/controllers/sessions_controller.rb
  5. +5 −0 app/helpers/admin/categories_helper.rb
  6. +9 −0 app/helpers/admin/jobs_helper.rb
  7. +0 −1  app/helpers/application_helper.rb
  8. +2 −2 app/helpers/categories_helper.rb
  9. +1 −1  app/helpers/jobs_helper.rb
  10. +11 −0 app/helpers/sessions_helper.rb
  11. +20 −0 app/models/admin.rb
  12. +5 −0 app/views/admin/categories/_list.html.haml
  13. +3 −0  app/views/admin/categories/show.html.haml
  14. +24 −0 app/views/admin/jobs/_jobs_table.html.haml
  15. +1 −0  app/views/admin/jobs/destroy.js.rjs
  16. +2 −0  app/views/admin/jobs/index.html.haml
  17. +51 −0 app/views/admin/jobs/show.html.haml
  18. +1 −0  app/views/admin/jobs/update.js.rjs
  19. +16 −0 app/views/layouts/_admin_header.html.haml
  20. +19 −0 app/views/layouts/admin.html.haml
  21. +1 −1  app/views/layouts/application.html.haml
  22. 0  app/views/session/_login_status.html.haml
  23. +5 −0 app/views/sessions/_login_status.html.haml
  24. +12 −0 app/views/sessions/new.html.haml
  25. +11 −4 config/routes.rb
  26. +4 −0 db/fixtures/admins.rb
  27. +15 −0 db/migrate/20080703181307_create_admins.rb
  28. +8 −1 db/schema.rb
  29. BIN  public/images/icon-delete.png
  30. 0  public/images/icon_accept.gif
  31. BIN  public/images/icon_activate.gif
  32. +60 −0 public/stylesheets/styles.css
  33. +11 −0 test/fixtures/admins.yml
  34. +8 −6 test/fixtures/categories.yml
  35. +6 −6 test/fixtures/job_types.yml
  36. +22 −18 test/fixtures/jobs.yml
  37. +4 −6 test/fixtures/locations.yml
  38. +14 −0 test/functional/admin/categories_controller_test.rb
  39. +43 −0 test/functional/admin/jobs_controller_test.rb
  40. +5 −3 test/functional/jobs_controller_test.rb
  41. +30 −0 test/functional/sessions_controller_test.rb
  42. +3 −0  test/test_helper.rb
  43. +18 −0 test/unit/admin_test.rb
View
10 app/controllers/admin/categories_controller.rb
@@ -0,0 +1,10 @@
+class Admin::CategoriesController < ApplicationController
+ before_filter :login_required
+ layout 'admin'
+
+ # GET /admin/jobs/1
+ def show
+ @category = Category.find_by_value(params[:id])
+ @jobs = @category.jobs.find_all_by_is_active(true, :order => "created_at DESC")
+ end
+end
View
37 app/controllers/admin/jobs_controller.rb
@@ -0,0 +1,37 @@
+class Admin::JobsController < ApplicationController
+ before_filter :login_required
+ layout 'admin'
+
+ # GET /admin/jobs
+ def index
+ @jobs = Job.find_all_by_is_active(false, :order => 'updated_at DESC')
+ end
+
+ # GET /admin/jobs/1
+ def show
+ @job = Job.find(params[:id])
+ end
+
+ # PUT /admin/jobs/1
+ def update
+ @job = Job.find(params[:id])
+
+ respond_to do |format|
+ if @job.update_attributes(:is_active => @job.is_active ? false : true)
+ format.html { redirect_to admin_jobs_url }
+ format.js # admin/jobs/update.js.rjs
+ end
+ end
+ end
+
+ # DELETE /admin/jobs/1
+ def destroy
+ @job = Job.find(params[:id])
+ @job.destroy
+
+ respond_to do |format|
+ format.html { redirect_to admin_jobs_url }
+ format.js # admin/jobs/destroy.js.rjs
+ end
+ end
+end
View
9 app/controllers/application.rb
@@ -13,7 +13,14 @@ class ApplicationController < ActionController::Base
# Uncomment this to filter the contents of submitted sensitive data parameters
# from your application log (in this case, all fields with names like "password").
filter_parameter_logging :password
-
+
+ def login_required
+ unless session[:admin]
+ flash[:notice] = "Please log in."
+ redirect_to login_url
+ end
+ end
+
protected
def production?
ENV["RAILS_ENV"] == "production"
View
27 app/controllers/sessions_controller.rb
@@ -0,0 +1,27 @@
+class SessionsController < ApplicationController
+ layout 'admin'
+
+ def new
+ if session[:admin]
+ redirect_to admin_url
+ end
+ end
+
+ def create
+ admin = Admin.authenticate(params[:login], params[:password])
+ if admin
+ session[:admin] = admin
+ flash[:notice] = "You are logged as #{admin.login}"
+ redirect_to admin_url
+ else
+ flash[:error] = "Invalid login or password!"
+ render :action => :new
+ end
+ end
+
+ def destroy
+ reset_session
+ flash[:notice] = "You've been logged out."
+ redirect_to login_url
+ end
+end
View
5 app/helpers/admin/categories_helper.rb
@@ -0,0 +1,5 @@
+module Admin::CategoriesHelper
+ def admin_category_nav_item(category)
+ category_nav_item(category, true)
+ end
+end
View
9 app/helpers/admin/jobs_helper.rb
@@ -0,0 +1,9 @@
+module Admin::JobsHelper
+ def activation_image_tag(job)
+ activate = "activate"
+ unless job.is_active
+ activate = "de" + activate
+ end
+ image_tag("icon_#{activate}.gif", :alt => activate.capitalize, :id => "activate_#{job.id}")
+ end
+end
View
1  app/helpers/application_helper.rb
@@ -22,5 +22,4 @@ def error_message_for(record, attribute, error_msg = nil)
return content_tag(:div, error_msg || error_list.join(", "), :class => "error-message")
end
end
-
end
View
4 app/helpers/categories_helper.rb
@@ -1,5 +1,5 @@
module CategoriesHelper
- def category_nav_item(category)
+ def category_nav_item(category, admin = false)
li_options = {}
@@ -8,7 +8,7 @@ def category_nav_item(category)
li_options[:class] = "selected"
end
- link = link_to "<span>#{category.name}</span><span class='cnr'>&nbsp;</span>", category_url(category), :title => category.name
+ link = link_to "<span>#{category.name.pluralize}</span><span class='cnr'>&nbsp;</span>", (admin ? admin_category_url(category) : category_url(category)), :title => category.name.pluralize
return content_tag(:li, link, li_options)
end
View
2  app/helpers/jobs_helper.rb
@@ -17,7 +17,7 @@ def job_location_text(job)
puts ", #{job.location}"
elsif !job.location.blank?
haml_tag :span, "in", :class => "la"
- puts " #{job.location}"
+ puts " #{job.location.name}"
end
end
end
View
11 app/helpers/sessions_helper.rb
@@ -0,0 +1,11 @@
+module SessionsHelper
+ # checks if user is logged in
+ def logged_in?
+ session[:admin] ? true : false
+ end
+
+ # returns currently logged admin
+ def current_user
+ session[:admin]
+ end
+end
View
20 app/models/admin.rb
@@ -0,0 +1,20 @@
+require 'digest/sha1'
+
+class Admin < ActiveRecord::Base
+ validates_length_of :login, :within => 3..40
+ validates_length_of :password, :within => 5..40
+ validates_presence_of :login, :password
+ validates_uniqueness_of :login
+
+ attr_protected :id
+
+ def self.authenticate(login, pass)
+ a = find_by_login(login)
+ a && Admin.encrypt(pass) == a.password ? a : nil
+ end
+
+ protected
+ def self.encrypt(pass)
+ Digest::SHA1.hexdigest(pass)
+ end
+end
View
5 app/views/admin/categories/_list.html.haml
@@ -0,0 +1,5 @@
+#categories
+ %ul
+ - Category.list.each do |category|
+ = admin_category_nav_item(category)
+ = clear
View
3  app/views/admin/categories/show.html.haml
@@ -0,0 +1,3 @@
+.job-listings
+ %h2= "Jobs for " + @category.name.pluralize
+ = partial "admin/jobs/jobs_table", :jobs => @jobs
View
24 app/views/admin/jobs/_jobs_table.html.haml
@@ -0,0 +1,24 @@
+- unless jobs.empty?
+ -# Display Job Posts
+ %table.job-posts{:cellspacing => 0}
+ - jobs.each do |job|
+ %tr.job_item{:id => "job_" + job.id.to_s}
+ %td
+ = job_type_image(job.job_type)
+ = link_to job.title, admin_job_url(job), :title => job.title
+ %span.la at
+ = job_location_text(job)
+
+ -# display time
+ %td.time-posted
+ = image_tag "clock.gif", :class => "vert-middle"
+ = job.created_at.to_s(:job_listing)
+
+ %td{:style => 'text-align:left;width:15%'}
+ -# activate/deactivate link
+ = link_to_remote(activation_image_tag(job), :url => admin_job_url(job.id), :method => :put)
+ -# delete link
+ = link_to_remote(image_tag("icon-delete.png", :alt => 'Delete'), :url => admin_job_url(job.id), :confirm => 'Are you sure you want to delete this post?', :method => :delete)
+
+- else
+ #no-ads No jobs, yet.
View
1  app/views/admin/jobs/destroy.js.rjs
@@ -0,0 +1 @@
+page["job_#{@job.id}"].visual_effect :fade, "job_#{@job.id}"
View
2  app/views/admin/jobs/index.html.haml
@@ -0,0 +1,2 @@
+%h2 Inactive jobs
+= partial "admin/jobs/jobs_table", :jobs => @jobs
View
51 app/views/admin/jobs/show.html.haml
@@ -0,0 +1,51 @@
+- if @job
+ = br
+ = link_to '« go back', admin_category_url(@job.category)
+ #job_details
+ -# display job outdated warning if applicable
+ - if @job.created_at < 40.days.ago
+ .old-ad
+ This job ad has been posted over 40 days ago...
+
+ -# show applicants count
+ .applied-to-job
+ = @job.job_applicants.size
+ %p
+ - if @job.job_applicants.size != 1
+ applicants
+ - else
+ applicant
+
+ -# show job title
+ %h2
+ = job_type_image(@job.job_type)
+ = @job.title
+
+ -# show job location
+ %p
+ %span.fading at
+ - unless @job.url.blank? or @job.url == "http://"
+ = link_to @job.company, @job.url
+ - else
+ %strong= @job.company
+
+ - if @job.located_at == "Anywhere"
+ %strong= "(" + @job.located_at + ")"
+ - else
+ %span.fading in
+ %strong= @job.located_at
+
+ -# show job description
+ .job-description
+ = @job.description_html
+ = br
+
+ #job_bottom
+ #number_views
+ Published at:
+ %strong= @job.created_at.to_s(:post_listing_date)
+ = br
+ Viewed:
+ %strong= pluralize(@job.view_count, "time")
+ = clear
+
View
1  app/views/admin/jobs/update.js.rjs
@@ -0,0 +1 @@
+page.replace "activate_#{@job.id}", activation_image_tag(@job)
View
16 app/views/layouts/_admin_header.html.haml
@@ -0,0 +1,16 @@
+#header
+ %h1#logo= link_to AppConfig.site_name, root_path
+ - if logged_in?
+ %ul#top
+ %li= link_to "Pages", "#"
+ = bull
+ %li= link_to "Categories", "#"
+ = bull
+ %li= link_to "Change your password", "#"
+ = bull
+ %li= link_to "Logout", logout_path
+
+ = partial "layouts/flash_boxes"
+
+- unless logged_in?
+ #categs-nav
View
19 app/views/layouts/admin.html.haml
@@ -0,0 +1,19 @@
+!!! Strict
+%html{html_attrs}
+ %head
+ %meta{"http-equiv" => "Content-type", "content" => "text/html; charset=utf-8"}
+
+ = title :site => AppConfig.site_name
+ = stylesheets
+ = javascripts
+
+ = feed_links
+
+ %body
+ #container
+ = partial "layouts/admin_header"
+ - if logged_in?
+ = partial "admin/categories/list"
+
+ #content
+ = yield
View
2  app/views/layouts/application.html.haml
@@ -11,7 +11,7 @@
%body
#container
- = partial "session/login_status"
+ = partial "sessions/login_status"
= partial "layouts/header"
= partial "search/searchbox"
= partial "categories/list"
View
0  app/views/session/_login_status.html.haml
No changes.
View
5 app/views/sessions/_login_status.html.haml
@@ -0,0 +1,5 @@
+.login_status
+ - if logged_in?
+ = "You are logged as #{current_user.login} " + link_to('Logout', logout_path)
+ - else
+ = link_to 'Login', login_path
View
12 app/views/sessions/new.html.haml
@@ -0,0 +1,12 @@
+- form_tag session_path, :id => 'publish_form' do
+ %fieldset
+ %legend Login
+ %table{:border => 0, :cellspacing => 2, :cellpadding => 2}
+ %tr
+ %td.publish-label Username:
+ %td= text_field_tag :login, params[:login], :size => 40
+ %tr
+ %td.publish-label Password:
+ %td= password_field_tag :password, params[:password], :size => 40
+ %fieldset
+ = submit_tag 'Login', :id => 'submit'
View
15 config/routes.rb
@@ -1,5 +1,9 @@
ActionController::Routing::Routes.draw do |map|
+ map.login '/login', :controller => 'sessions', :action => 'new'
+ map.logout '/logout', :controller => 'sessions', :action => 'destroy'
+ map.resource :session
+
map.resources :jobs, :member => {
:verify => :any,
:apply => :post,
@@ -11,10 +15,13 @@
map.resources :categories
map.resource :search, :controller => "Search"
- # map.namespace :admin do |admin|
- # # Directs /admin/jobs/* to Admin::JobsController (app/controllers/admin/jobs_controller.rb)
- # admin.resources :jobs
- # end
+ map.admin '/admin', :controller => 'admin/jobs', :action => 'index'
+ map.namespace :admin do |admin|
+ # Directs /admin/jobs/* to Admin::JobsController (app/controllers/admin/jobs_controller.rb)
+ admin.resources :jobs
+ # Directs /admin/categories/* to Admin::CategoriesController (app/controllers/admin/categories_controller.rb)
+ admin.resources :categories
+ end
map.root :controller => "jobs"
View
4 db/fixtures/admins.rb
@@ -0,0 +1,4 @@
+Admin.seed(:login, :password) do |s|
+ s.login = 'admin'
+ s.password = 'd033e22ae348aeb5660fc2140aec35850c4da997' # admin
+end
View
15 db/migrate/20080703181307_create_admins.rb
@@ -0,0 +1,15 @@
+class CreateAdmins < ActiveRecord::Migration
+ def self.up
+ create_table :admins do |t|
+ t.string :login
+ t.string :password
+
+ t.timestamps
+ end
+
+ end
+
+ def self.down
+ drop_table :admins
+ end
+end
View
9 db/schema.rb
@@ -9,7 +9,14 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20080628140740) do
+ActiveRecord::Schema.define(:version => 20080703181307) do
+
+ create_table "admins", :force => true do |t|
+ t.string "login"
+ t.string "password"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
create_table "categories", :force => true do |t|
t.string "name"
View
BIN  public/images/icon-delete.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
0  public/images/icon_accept.gif 100755 → 100644
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  public/images/icon_activate.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
60 public/stylesheets/styles.css
@@ -889,3 +889,63 @@ label.request-label {
.error a {color:#8a1f11;}
.notice a {color:#514721;}
.success a {color:#264409;}
+
+.login_status {text-align:right; margin-right: 20px;}
+
+#publish_form {}
+#publish_form fieldset, #promo_form fieldset {
+ background-color: #f5f5f5;
+ border: 1px solid #ccc;
+ margin: 0 0 5px 0;
+ padding: 10px;
+}
+#publish_form fieldset legend {
+ font-weight: bold;
+ color: #555;
+ font-size: 12px;
+}
+#publish_form input, #publish_form textarea, #frm-send-to-friend input, #frm-send-edit-link input, #apply-online input, #apply-online textarea, #promo_form input {
+ border: 1px solid #ccc;
+ padding: 5px;
+ font-size: 12px;
+ font-family: Helvetica, Arial, sans-serif;
+}
+#publish_form input:focus, #search input:hover, #publish_form textarea:focus, #search textarea:hover, #frm-send-to-friend input:focus,
+#frm-send-to-friend input:hover, #frm-send-edit-link input:focus, #frm-send-edit-link input:hover, #apply-online input:focus, #apply-online input:hover, #apply-online textarea:focus, #apply-online textarea:hover, #promo_form input:focus, #promo_form input:hover {
+ border: 1px solid #7F635F;
+}
+#publish_form input#submit, #send-to-friend input#submit, #frm-send-edit-link input#submit, #apply-online input#submit, #promo_form input#submit {
+ background-color: #0099CC;
+ color: #fff;
+ border: 1px solid #009988;
+ cursor: pointer;
+ cursor: hand;
+}
+#publish_form input#submit:hover, #send-to-friend input#submit:hover, #apply-online input#submit:hover, #promo_form input#submit:hover {
+ background-color: #00aaee;
+}
+#publish_form label.small {
+ color: #555;
+ font-size: 12px;
+}
+#publish_form input.no-border {
+ border: 0;
+}
+
+td.publish-label {
+ width: 100px;
+}
+
+div#categs-nav {
+ background:#0099CC none repeat scroll 0% 0%;
+ float:left;
+ font-size:11px;
+ margin-top:25px;
+ padding-bottom:6px;
+ width:950px;
+}
+
+#no-ads {
+ color:#555555;
+ margin-top:10px;
+}
View
11 test/fixtures/admins.yml
@@ -0,0 +1,11 @@
+bob:
+ login: bob
+ password: a94a8fe5ccb19ba61c4c0873d391e987982fbbd3 # test
+
+mark:
+ login: mark
+ password: a94a8fe5ccb19ba61c4c0873d391e987982fbbd3 # longtest
+
+admin:
+ login: admin
+ password: d033e22ae348aeb5660fc2140aec35850c4da997 # admin
View
14 test/fixtures/categories.yml
@@ -1,7 +1,9 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+programmer:
+ name: Programmers
+ value: programmers
+ position: 1
-# one:
-# column: value
-#
-# two:
-# column: value
+designer:
+ name: Designers
+ value: designers
+ position: 2
View
12 test/fixtures/job_types.yml
@@ -1,7 +1,7 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+full-time:
+ name: Full-time
+ value: fulltime
-# one:
-# column: value
-#
-# two:
-# column: value
+part-time:
+ name: Part-time
+ value: parttime
View
40 test/fixtures/jobs.yml
@@ -1,25 +1,29 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-
one:
- title: MyString
- description: MyText
- company: MyString
- url: MyString
- apply: MyString
+ title: web developer
+ description: temporary description
+ company: Foo Inc
+ url: http://www.xyz.pl
+ apply: null
is_temp: false
- is_active: false
- outside_location: MyString
- poster_email: MyString
+ is_active: true
+ outside_location:
+ poster_email: temp@temp.us
apply_online: false
+ job_type: full-time
+ category: programmer
+ location: seatle
two:
- title: MyString
- description: MyText
- company: MyString
- url: MyString
- apply: MyString
- is_temp: false
+ title: graphic
+ description: some description
+ company: Some company
+ url: www.xxx.xx
+ apply: null
+ is_temp: true
is_active: false
- outside_location: MyString
- poster_email: MyString
+ outside_location:
+ poster_email: admin@admin.sd
apply_online: false
+ job_type: part-time
+ category: designer
+ location: tampa
View
10 test/fixtures/locations.yml
@@ -1,7 +1,5 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+seatle:
+ name: Seattle, WA
-# one:
-# column: value
-#
-# two:
-# column: value
+tampa:
+ name: Tampa, FL
View
14 test/functional/admin/categories_controller_test.rb
@@ -0,0 +1,14 @@
+require 'test_helper'
+
+class Admin::CategoriesControllerTest < ActionController::TestCase
+ def test_should_show_active_jobs_in_category
+ login_as(:mark)
+ get :show, :id => categories(:programmer).name
+ assert_response :success
+ assert_not_nil assigns(:jobs)
+ assigns(:jobs).each do |job|
+ assert_equal categories(:programmer).name, job.category.name
+ assert job.is_active
+ end
+ end
+end
View
43 test/functional/admin/jobs_controller_test.rb
@@ -0,0 +1,43 @@
+require 'test_helper'
+
+class Admin::JobsControllerTest < ActionController::TestCase
+ def test_should_get_inactive_jobs_index
+ login_as(:admin)
+ get :index
+ assert_response :success
+ end
+
+ def test_should_destroy_inactive_job
+ login_as(:bob)
+ assert_difference('Job.count', -1) do
+ xhr :delete, :destroy, :id => jobs(:one).id
+ end
+ assert_response :success
+ end
+
+ def test_should_activate_inactive_job
+ login_as(:admin)
+ get :index
+ assert_equal 1, assigns(:jobs).size
+ assert_equal false, jobs(:two).is_active
+ xhr :put, :update, :id => jobs(:two).id
+ assert_response :success
+ jobs(:two).reload
+ assert jobs(:two).is_active
+ get :index
+ assert_equal 0, assigns(:jobs).size
+ end
+
+ def test_should_deactivate_active_job
+ login_as(:admin)
+ get :index
+ assert_equal 1, assigns(:jobs).size
+ assert jobs(:one).is_active
+ xhr :put, :update, :id => jobs(:one).id
+ assert_response :success
+ jobs(:one).reload
+ assert_equal false, jobs(:one).is_active
+ get :index
+ assert_equal 2, assigns(:jobs).size
+ end
+end
View
8 test/functional/jobs_controller_test.rb
@@ -14,10 +14,11 @@ def test_should_get_new
def test_should_create_job
assert_difference('Job.count') do
- post :create, :job => { }
+ post :create, :job => {:title => 'developer', :description => 'Excellent payment! ;)',
+ :company => 'Foo', :poster_email => 'fooinc@temp.com'}
end
- assert_redirected_to job_path(assigns(:job))
+ assert_redirected_to verify_job_path(assigns(:job))
end
def test_should_show_job
@@ -31,7 +32,8 @@ def test_should_get_edit
end
def test_should_update_job
- put :update, :id => jobs(:one).id, :job => { }
+ put :update, :id => jobs(:one).id, :job => { :title => 'developer', :description => 'Excellent payment! ;)',
+ :company => 'Foo', :poster_email => 'fooinc@temp.com'}
assert_redirected_to job_path(assigns(:job))
end
View
30 test/functional/sessions_controller_test.rb
@@ -0,0 +1,30 @@
+require 'test_helper'
+
+class SessionsControllerTest < ActionController::TestCase
+
+ def test_should_login_and_redirect
+ post :create, :login => "bob", :password => "test"
+ assert session[:admin]
+ assert_response :redirect
+ assert_redirected_to admin_jobs_url
+ end
+
+ def test_should_fail_login_and_not_redirect
+ post :create, :login => 'quentin', :password => 'bad password'
+ assert_nil session[:admin]
+ assert_response :success
+ end
+
+ def test_should_login_and_logout
+ post :create, :login => "admin", :password => "admin"
+ assert session[:admin]
+ assert_response :redirect
+ assert_redirected_to admin_jobs_url
+
+ get :destroy
+ assert_nil session[:admin]
+ assert_response :redirect
+ assert_redirected_to login_url
+ end
+
+end
View
3  test/test_helper.rb
@@ -35,4 +35,7 @@ class Test::Unit::TestCase
fixtures :all
# Add more helper methods to be used by all tests here...
+ def login_as(admin)
+ @request.session[:admin] = admin ? admins(admin) : nil
+ end
end
View
18 test/unit/admin_test.rb
@@ -0,0 +1,18 @@
+require 'test_helper'
+
+class AdminTest < ActiveSupport::TestCase
+ self.use_instantiated_fixtures = true
+
+ def test_authentication
+ assert_equal @mark, Admin.authenticate("mark", "longtest")
+
+ # wrong username
+ assert_nil Admin.authenticate("adminnn", "admin")
+
+ #wrong password
+ assert_nil Admin.authenticate("bob", "wrongpass")
+
+ #wrong login and pass
+ assert_nil Admin.authenticate("nonbob", "wrongpass")
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.