public

model

  • Download Gist
app/models/report/employer_application_report.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
module Report
 
class EmployerApplicationReport
 
attr_accessor :job, :archived
 
def initialize(options = {})
options ||= {}
options.reverse_merge!(:archived => false)
options.each do |k, v|
send("#{k}=", v) if respond_to?("#{k}=")
end
end
 
def applications
if archived
job.job_applications.all
else
job.job_applications.active
end
end
 
end
 
end
integrated_spec.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
require 'spec_helper'
 
describe Report::EmployerApplicationReport do
 
let(:report) { Report::EmployerApplicationReport.new }
 
describe "#archived" do
it 'defaults to false' do
report.archived.should be_false
end
end
 
describe "#applications" do
 
before do
@job = Factory(:active_job)
Factory(:job_application, :job => @job)
Factory(:job_application, :job => @job, :archived_at => Time.zone.now)
end
 
context "with a job" do
before do
report.job = @job
end
 
context "when archived is false" do
before do
report.archived = false
end
 
it 'returns unarchived applications for the job' do
report.applications.should == @job.job_applications.active
end
end
 
context "when archived is true" do
before do
report.archived = true
end
 
it 'returns all applications for the job' do
report.applications.should == @job.job_applications
end
end
end
 
end
 
end
unit_spec.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
require 'spec_helper'
 
describe Report::EmployerApplicationReport do
 
let(:report) { Report::EmployerApplicationReport.new }
 
describe "#archived" do
it 'defaults to false' do
report.archived.should be_false
end
end
 
describe "#applications" do
 
before do
@job = Factory.stub(:active_job)
@applications = []
@applications << Factory.stub(:job_application, :job => @job)
@applications << Factory.stub(:job_application, :job => @job, :archived_at => Time.zone.now)
@job.stub_chain(:job_applications, :all => @applications)
@job.stub_chain(:job_applications, :active => [@applications.first])
end
 
context "with a job" do
before do
report.job = @job
end
 
context "when archived is false" do
before do
report.archived = false
end
 
it 'returns unarchived applications for the job' do
report.applications.should == [@applications.first]
end
end
 
context "when archived is true" do
before do
report.archived = true
end
 
it 'returns all applications for the job' do
report.applications.should == @applications
end
end
end
 
end
 
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.