Skip to content

Instantly share code, notes, and snippets.

@batasrki
Created October 2, 2011 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save batasrki/1258062 to your computer and use it in GitHub Desktop.
Save batasrki/1258062 to your computer and use it in GitHub Desktop.
Example model preset fields spec
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={})
mock_model(JobCategory, stubs)
end
def mock_base_project(stubs={})
mock_model(BaseProject, stubs)
end
it "should create quote sections related to the repair category" do
category = mock_job_category({:name => "Repair", :base_projects => []})
@job.category = category
@job.save
@job.preset_fields
@job.quote_sections.size.should == 4
end
it "should have a quote section named Labour for a repair category job" do
category = mock_job_category({:name => "Repair", :base_projects => []})
@job.category = category
@job.save
@job.preset_fields
@job.quote_sections.map(&:description).should include("Labour")
end
it "should create projects related to the digital category" do
base_project = BaseProject.create!({:project_category => mock_model(ProjectCategory,
{:name => "Test PJ"})})
category = mock_job_category({:name => "Digital", :base_projects => [base_project],
:steps => [mock_model(Step, :name => "test step")]})
base_project.project_category_id.should_not be_nil
@job.category = category
@job.save
@job.preset_fields
@job.projects.size.should == 1
end
it "should create projects related to the lithography category" do
base_project = BaseProject.create!({:project_category => mock_model(ProjectCategory,
{:name => "Test PJ"})})
category = mock_job_category({:name => "Lithography", :base_projects => [base_project]})
@job.category = category
@job.save
@job.preset_fields
@job.projects.size.should == 1
end
it "should not create quote_sections nor projects if the corresponding job categories aren't selected" do
category = mock_job_category({:name => "Rollout", :base_projects => []})
@job.category = category
@job.save
@job.preset_fields
@job.projects.should be_blank
@job.quote_sections.should be_blank
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment