Created
October 2, 2011 22:42
-
-
Save batasrki/1258062 to your computer and use it in GitHub Desktop.
Example model preset fields spec
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={}) | |
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