Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added companies review

  • Loading branch information...
commit 86bad3686317232255e9dcd60640b302ca210163 1 parent 24bc857
@wlodars wlodars authored
View
13 app/controllers/companies_controller.rb
@@ -1,2 +1,13 @@
-class CompaniesController < ApplicationController
+class CompaniesController < ApplicationController
+
+ # GET /companies
+ def index
+ @companies = Job.companies_count
+ end
+
+ # GET /jobs_at/1
+ def jobs_at
+ @company = Job.find_company(params[:company])
+ @jobs = @company ? Job.find_all_by_company(@company) : nil
+ end
end
View
14 app/helpers/companies_helper.rb
@@ -1,2 +1,16 @@
module CompaniesHelper
+ def companies_tag_cloud(companies, classes)
+ max, min = 0, 0
+ companies.each { |t|
+ max = t.count.to_i if t.count.to_i > max
+ min = t.count.to_i if t.count.to_i < min
+ }
+
+ divisor = ((max - min) / classes.size) + 1
+
+ companies.each { |t|
+ yield t.name, t.count, url_encode(t.name), classes[(t.count.to_i - min) / divisor]
+ }
+
+ end
end
View
17 app/models/job.rb
@@ -85,6 +85,23 @@ def feed_html
end
+ def self.companies_count
+ all :select => 'company as name, COUNT(*) as count',
+ :conditions => 'is_active = true',
+ :order => 'company',
+ :group => 'company'
+ end
+
+ def self.find_company(company)
+ companies = all :select => 'DISTINCT company'
+
+ companies.each do |comp|
+ return comp.company if ERB::Util.url_encode(comp.company) == company
+ end
+
+ nil
+ end
+
protected
def format_fields
self.description_html = format_html(self.description)
View
10 app/views/companies/index.html.haml
@@ -0,0 +1,10 @@
+%h3.page-heading Companies that published here
+
+- companies_tag_cloud @companies, %w(company-tag-1 company-tag-2 company-tag-3 company-tag-4 company-tag-5 company-tag-6) do |name, count, url, css_class|
+ %span{:class => css_class}
+ = link_to h(name) + " (" + count + ")", jobs_at_path(:company => url)
+
+%p{:style => "margin-top:20px"}
+ Total
+ %strong= @companies.size
+ companies
View
6 app/views/companies/jobs_at.html.haml
@@ -0,0 +1,6 @@
+#job-listings
+ - unless @jobs.nil?
+ %h2= "Jobs at #{@company}"
+ = partial 'jobs/parts/post_table', :jobs => @jobs
+ - else
+ %h2= "There aren't any company called \"#{params[:company]}\""
View
2  app/views/layouts/_footer.html.haml
@@ -32,7 +32,7 @@
Misc:
= br
- = link_to "Companies", "#companies"
+ = link_to "Companies", companies_url
= br
= link_to "Sitemap", "#sitemap"
View
9 config/routes.rb
@@ -1,7 +1,7 @@
ActionController::Routing::Routes.draw do |map|
- map.login '/login', :controller => 'sessions', :action => 'new'
- map.logout '/logout', :controller => 'sessions', :action => 'destroy'
+ map.login 'login', :controller => 'sessions', :action => 'new'
+ map.logout 'logout', :controller => 'sessions', :action => 'destroy'
map.resource :session
map.resources :jobs, :member => {
@@ -11,13 +11,16 @@
:report_spam => :post
}
+ map.resources :companies
+ map.jobs_at 'jobs_at/:company', :controller => 'companies', :action => 'jobs_at'
+
map.resources :job_requests, :collection => {:success => :get}
map.resources :categories
map.resource :search, :controller => "Search"
map.resources :pages
- map.admin '/admin', :controller => 'admin/jobs', :action => 'index'
+ 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
View
27 test/functional/companies_controller_test.rb
@@ -1,8 +1,29 @@
require 'test_helper'
class CompaniesControllerTest < ActionController::TestCase
- # Replace this with your real tests.
- def test_truth
- assert true
+
+ def test_should_get_companies_index
+ get :index
+ assert_response :success
+ end
+
+ def test_should_show_companies_list
+ get :index
+ assert_not_nil assigns(:companies)
+ end
+
+ def test_should_have_css_class
+ get :index
+ assert_tag :tag => "span", :attributes => {:class => "company-tag-2"}
+ end
+
+ def test_should_show_jobs_at
+ get :jobs_at, :company => ERB::Util.url_encode(jobs(:one).company)
+ assert_not_nil assigns(:jobs)
+ end
+
+ def test_should_not_show_jobs_at
+ get :jobs_at, :company => "some fake url"
+ assert_nil assigns(:jobs)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.