[#4180] Add Hourly Deliverables.

This commit is contained in:
Eric Davis
2010-07-01 16:02:33 -07:00
parent 5b098a43e5
commit 498b7b633d
6 changed files with 100 additions and 15 deletions
+5 -2
View File
@@ -12,13 +12,16 @@ class DeliverablesController < InheritedResources::Base
def create
@deliverable = begin_of_association_chain.deliverables.build(params[:deliverable])
@deliverable.type = 'FixedDeliverable'
if params[:deliverable] && params[:deliverable][:type] && ['FixedDeliverable','HourlyDeliverable'].include?(params[:deliverable][:type])
@deliverable.type = params[:deliverable][:type]
end
create! { contract_url(@project, @contract) }
end
def update
@deliverable = begin_of_association_chain.deliverables.find_by_id(params[:id])
@deliverable.attributes = params[:fixed_deliverable] # TODO: hardcoded
params[:deliverable] = params[:fixed_deliverable] || params[:hourly_deliverable]
@deliverable.attributes = params[:deliverable]
update! { contract_url(@project, @contract) }
end
+13
View File
@@ -0,0 +1,13 @@
class HourlyDeliverable < Deliverable
unloadable
# Associations
# Validations
# Accessors
def short_type
'H'
end
end
+5 -5
View File
@@ -1,6 +1,6 @@
<% form.inputs do %>
<%= form.input :title, :required => true %>
<%= form.input :type, :required => true, :as => :select, :collection => [["Fixed", "FixedDeliverable"]] %>
<%= form.input :type, :required => true, :as => :select, :collection => [["Fixed", "FixedDeliverable"],["Hourly", "HourlyDeliverable"]] %>
<%= form.input :manager, :required => true, :collection => @project.users %>
<%= form.input :start_date, :as => :string, :input_html => {:size => 10}, :hint => calendar_for('deliverable_start_date') %>
<%= form.input :end_date, :as => :string, :input_html => {:size => 10}, :hint => calendar_for('deliverable_end_date') %>
@@ -8,12 +8,12 @@
<% unless resource.new_record? %>
<li class="boolean optional">
<%= label('deliverable', 'feature_sign_off') %>
<%= check_box 'deliverable', 'feature_sign_off' %>
<%= label(resource.class.to_s.underscore, 'feature_sign_off') %>
<%= check_box resource.class.to_s.underscore, 'feature_sign_off' %>
</li>
<li class="boolean optional">
<%= label('deliverable', 'warranty_sign_off') %>
<%= check_box 'deliverable', 'warranty_sign_off' %>
<%= label(resource.class.to_s.underscore, 'warranty_sign_off') %>
<%= check_box resource.class.to_s.underscore, 'warranty_sign_off' %>
</li>
<% end %>
+7
View File
@@ -37,6 +37,7 @@ class ContractsShowTest < ActionController::IntegrationTest
@deliverable1 = FixedDeliverable.generate!(:contract => @contract, :manager => @manager)
@deliverable2 = FixedDeliverable.generate!(:contract => @contract, :manager => @manager)
@deliverable3 = HourlyDeliverable.generate!(:contract => @contract, :manager => @manager)
visit_contract_page(@contract)
assert_select "table#deliverables" do
@@ -46,6 +47,12 @@ class ContractsShowTest < ActionController::IntegrationTest
assert_select "td.title", :text => /#{deliverable.title}/
assert_select "td.manager", :text => /#{deliverable.manager.name}/
end
[@deliverable3].each do |deliverable|
assert_select "td.end-date", :text => /#{format_date(deliverable.end_date)}/
assert_select "td.type", :text => "H"
assert_select "td.title", :text => /#{deliverable.title}/
assert_select "td.manager", :text => /#{deliverable.manager.name}/
end
end
end
+39 -8
View File
@@ -9,17 +9,19 @@ class DeliverablesEditTest < ActionController::IntegrationTest
@manager = User.generate!
@role = Role.generate!
User.add_to_project(@manager, @project, @role)
@deliverable = FixedDeliverable.generate!(:contract => @contract, :manager => @manager, :title => 'The Title')
@fixed_deliverable = FixedDeliverable.generate!(:contract => @contract, :manager => @manager, :title => 'The Title')
@hourly_deliverable = HourlyDeliverable.generate!(:contract => @contract, :manager => @manager, :title => 'An Hourly')
end
should "allow any user to edit the deliverable" do
should "allow any user to edit the Fixed deliverable" do
visit_contract_page(@contract)
click_link_within "#fixed_deliverable_#{@deliverable.id}", 'Edit'
click_link_within "#fixed_deliverable_#{@fixed_deliverable.id}", 'Edit'
assert_response :success
assert_template 'deliverables/edit'
assert_select "form#edit_fixed_deliverable_#{@deliverable.id}" do
assert_select "input#fixed_deliverable_title[value=?]", /#{@deliverable.title}/
assert_select "form#edit_fixed_deliverable_#{@fixed_deliverable.id}" do
assert_select "input#fixed_deliverable_title[value=?]", /#{@fixed_deliverable.title}/
assert_select "select#fixed_deliverable_type" do
assert_select "option[selected=selected][value=FixedDeliverable]"
end
@@ -33,9 +35,38 @@ class DeliverablesEditTest < ActionController::IntegrationTest
assert_response :success
assert_template 'contracts/show'
assert_equal "An updated title", @deliverable.reload.title
assert @deliverable.reload.warranty_sign_off?
assert @deliverable.reload.feature_sign_off?
assert_equal "An updated title", @fixed_deliverable.reload.title
assert_equal "FixedDeliverable", @fixed_deliverable.reload.type
assert @fixed_deliverable.reload.warranty_sign_off?
assert @fixed_deliverable.reload.feature_sign_off?
end
should "allow any user to edit the Hourly deliverable" do
visit_contract_page(@contract)
click_link_within "#hourly_deliverable_#{@hourly_deliverable.id}", 'Edit'
assert_response :success
assert_template 'deliverables/edit'
assert_select "form#edit_hourly_deliverable_#{@hourly_deliverable.id}" do
assert_select "input#hourly_deliverable_title[value=?]", /#{@hourly_deliverable.title}/
assert_select "select#hourly_deliverable_type" do
assert_select "option[selected=selected][value=HourlyDeliverable]"
end
end
fill_in "Title", :with => 'An updated title'
check "Feature Sign Off"
check "Warranty Sign Off"
click_button "Save"
assert_response :success
assert_template 'contracts/show'
assert_equal "An updated title", @hourly_deliverable.reload.title
assert_equal "HourlyDeliverable", @hourly_deliverable.reload.type
assert @hourly_deliverable.reload.warranty_sign_off?
assert @hourly_deliverable.reload.feature_sign_off?
end
end
+31
View File
@@ -72,4 +72,35 @@ class DeliverablesNewTest < ActionController::IntegrationTest
assert_equal @manager, @deliverable.manager
assert_equal 1000.0, @deliverable.total.to_f
end
should "create a new Hourly deliverable" do
@manager = User.generate!
@role = Role.generate!
User.add_to_project(@manager, @project, @role)
visit_contract_page(@contract)
click_link 'Add New'
assert_response :success
fill_in "Title", :with => 'A New Deliverable'
select "Hourly", :from => "Type"
select @manager.name, :from => "Manager"
fill_in "Start", :with => '2010-01-01'
fill_in "End Date", :with => '2010-12-31'
fill_in "Notes", :with => 'Some notes on the deliverable'
click_button "Save"
assert_response :success
assert_template 'contracts/show'
@deliverable = Deliverable.last
assert_equal "A New Deliverable", @deliverable.title
assert_equal @contract, @deliverable.contract
assert_equal "HourlyDeliverable", @deliverable.type
assert_equal '2010-01-01', @deliverable.start_date.to_s
assert_equal '2010-12-31', @deliverable.end_date.to_s
assert_equal @manager, @deliverable.manager
end
end