This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def record_ids_containing_category(category) | |
function = <<-eos | |
function(values) { | |
var data = Riak.mapValuesJson(values)[0]; | |
if(data.category === '#{category}') { | |
return [values.key]; | |
} | |
else { | |
return []; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe Job do | |
before :each do | |
@mock_job_category = JobCategory.create!({:name => "Tester"}) | |
@mock_client = mock_model(Client, {:name => "Test Client"}) | |
@job = Job.new(:name => "test job", :client => @mock_client, :category => @mock_job_category) | |
end | |
describe "preset fields" do | |
def mock_job_category(stubs={}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Admin | |
class JobsController < BaseController | |
def create | |
@job = Job.new(params[:job]) | |
@job.step = @job.category.steps.first | |
if @job.save | |
# Add default PMs | |
@job.preset_fields |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Job < ActiveRecord::Base | |
def preset_fields | |
if category.name == "Repair" || category.name == "Maintenance" | |
quote_sections.create!(:description => "Labour", :amount => 0) | |
quote_sections.create!(:description => "Materials", :amount => 0) | |
quote_sections.create!(:description => "Travel", :amount => 0) | |
quote_sections.create!(:description => "Courier", :amount => 0) | |
end | |
category.base_projects.each do |bp| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe Job do | |
before :each do | |
@mock_client = mock_model(Client, {:name => "Test Client"}) | |
@job = Job.new(:name => "test job", :client => @mock_client, | |
:category => @mock_job_category) | |
end | |
describe "search" do | |
before :each do | |
@category = JobCategory.create!(:name => "Testing search") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Util | |
def gen_dyn_search(str, search_list) | |
return "true" if str.blank? | |
terms = str.split(/\s/) | |
sql = "" | |
terms.each do |term| | |
sql += (sql!="")? " AND (" : "(" | |
inner_sql = "" | |
search_list.each do |item| | |
inner_sql += (inner_sql!="")? " OR " : "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JobsController < ApplicationController | |
def index | |
#blah blah | |
Job.search(gen_dyn_search(params[:search],["jobs.name","jobs.id","jobs.clientpo"]), | |
params[:page], @cond, @join) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Job < ActiveRecord::Base | |
def self.search(search, page=1, cond, join) | |
condition = (cond) ? " AND #{cond}" : "" | |
if join | |
paginate :per_page => 10, :page => page, :joins => join, | |
:order => 'jobs.name', :conditions => "(#{search})#{condition}" | |
else | |
paginate :per_page => 10, :page => page, | |
:order => 'name', :conditions => "(#{search})#{condition}" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var z="http://gist.github.com/",y=document.write,x=$("body"),w=$("p.gist").map(function(b,a){a=$(a);var c=$("a",a),u=c.attr("href");if(c.length&&u.indexOf(z)==0)return{p:a,id:u.substring(z.length)}}).get(),v=function(){if(w.length==0)document.write=y;else{var b=w.shift();document.write=function(){document.write=function(a){b.p.replaceWith(a);v()}};x.append('<scr'+'ipt src="'+z+b.id+'.js"></scr'+'ipt>')}};v(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe Job do | |
before :each do | |
@mock_job_category = JobCategory.create!({:name => "Tester"}) | |
@mock_client = mock_model(Client, {:name => "Test Client"}) | |
@job = Job.new(:name => "test job", :client => @mock_client, | |
:category => @mock_job_category) | |
end | |
describe "work window date range" do | |
before :each do |