Added cukes for budget operations like creating, copying and modifying budgets

pull/6827/head
Sebastian Schuster 12 years ago
parent 615d0193b2
commit a1d4fc3e87
  1. 4
      app/views/cost_objects/_form.html.erb
  2. 131
      features/create_budget.feature
  3. 46
      features/step_definitions/cost_object_steps.rb
  4. 20
      features/step_definitions/cost_steps.rb
  5. 190
      manage_budget.feature
  6. 7
      spec/factories/material_budget_item_factory.rb
  7. 0
      spec/factories/variable_cost_object_factory.rb

@ -30,7 +30,7 @@
//]]>
</script>
<fieldset>
<fieldset id="material_budget_items">
<legend><%= l(:caption_material_budget) %></legend>
<table class="list material_budget_items" id="material_budget_items">
<thead><tr>
@ -49,7 +49,7 @@
<div style="text-align: right"><%= link_to_function l(:button_add_budget_item), "materialBudgetItemsForm.add()", {:class => "icon icon-add"} %></div>
</fieldset>
<fieldset>
<fieldset id="labor_budget_items">
<legend><%= l(:caption_labor_budget) %></legend>
<table class="list labor_budget_items" id="labor_budget_items">
<thead><tr>

@ -1,22 +1,147 @@
Feature: Creating a Budget
Feature: Managing Budgets
Scenario: Budgets can be created
Background:
Given there is 1 User with:
| Login | testuser |
| Login | testuser |
| firstname | Chuck |
| lastname | Testa |
| default rate | 37 |
And there is 1 Project with the following:
| name | project1 |
| identifier | project1 |
And there is a role "manager"
And the role "manager" may have the following rights:
| edit_cost_objects |
| view_cost_rates |
| view_hourly_rates |
And there is 1 cost type with the following:
| name | cost_type_1 |
| unit | single_unit |
| unit_plural | multi_unit |
| cost_rate | 40 |
And the user "testuser" is a "manager" in the project "project1"
And I am already logged in as "testuser"
Scenario: Empty budgets can be created
When I go to the overview page of the project called "project1"
And I create a budget with the following:
| subject | budget1 |
Then I should be on the show page for the budget "budget1"
And I should see "Successful creation"
And I should see "budget1" within ".cost_object"
@javascript
Scenario: Budgets with cost items can be created adding new cost items
When I go to the overview page of the project called "project1"
And I setup a budget with the following:
| subject | budget1 |
And I create a material item in row 1 with the following:
| units | 10 |
| comment | materialtestcomment |
Then the planned material costs in row 1 should be "400.00 EUR"
When I create a labor item in row 1 with the following:
| hours | 8 |
| comment | labortestcomment |
| user | Chuck Testa |
Then the planned labor costs in row 1 should be "296.00 EUR"
When I add a new material item
And I create a material item in row 2 with the following:
| units | 6 |
| comment | materialtestcomment2 |
Then the planned material costs in row 2 should be "240.00 EUR"
When I add a new labor item
And I create a labor item in row 2 with the following:
| hours | 5 |
| comment | labortestcomment2 |
| user | Chuck Testa |
Then the planned labor costs in row 2 should be "185.00 EUR"
When I create the budget
Then I should be on the show page for the budget "budget1"
And I should see "Successful creation"
And I should see "budget1" within ".cost_object"
And the stored planned material costs in row 1 should be "400.00 EUR"
And the stored planned labor costs in row 1 should be "296.00 EUR"
And the stored planned material costs in row 2 should be "240.00 EUR"
And the stored planned labor costs in row 2 should be "185.00 EUR"
And the stored total planned material costs should be "640.00 EUR"
And the stored total planned labor costs should be "481.00 EUR"
@javascript
Scenario: Budgets can be updated with new cost items
Given there is a budget with the following:
| subject | budget1 |
| author | testuser |
| project | project1 |
And I go to the show page of the budget "budget1"
When I click on "Update"
Then I should be able to update the budget "budget1"
When I create a material item in row 1 with the following:
| units | 10 |
| comment | materialtestcomment |
Then the planned material costs in row 1 should be "400.00 EUR"
When I create a labor item in row 1 with the following:
| hours | 8 |
| comment | labortestcomment |
| user | Chuck Testa |
Then the planned labor costs in row 1 should be "296.00 EUR"
When I click on "Submit"
Then I should be on the show page for the budget "budget1"
And I should see "Successful update"
And the stored planned material costs in row 1 should be "400.00 EUR"
And the stored planned labor costs in row 1 should be "296.00 EUR"
And the stored total planned material costs should be "400.00 EUR"
And the stored total planned labor costs should be "296.00 EUR"
@javascript
Scenario: Budgets can be updated updating existing cost items
Given there is a budget with the following:
| subject | budget1 |
| author | testuser |
| project | project1 |
And the budget "budget1" has the following material items:
| units | comment | cost_type |
| 10 | materialtestcomment | cost_type_1 |
| 6 | materialtestcomment2 | cost_type_1 |
And the budget "budget1" has the following labor items:
| hours | comment | user |
| 8 | labortestcomment | testuser |
| 5 | labortestcomment2 | testuser |
And I go to the show page of the budget "budget1"
And I click on "Update"
Then I should be able to update the budget "budget1"
When I update the material item in row 1 with the following:
| units | 5 |
| comment | changed_materialtestcomment |
Then the planned material costs in row 1 should be "200.00 EUR"
When I update the labor item in row 1 with the following:
| hours | 10 |
| comment | changed_labortestcomment |
| user | Chuck Testa |
Then the planned labor costs in row 1 should be "370.00 EUR"
When I click on "Submit"
Then I should be on the show page for the budget "budget1"
And I should see "Successful update"
And the stored planned material costs in row 1 should be "200.00 EUR"
And the stored planned labor costs in row 1 should be "370.00 EUR"
@javascript
Scenario: Budgets can be copied
Given there is a budget with the following:
| subject | budget1 |
| author | testuser |
| project | project1 |
And the budget "budget1" has the following material items:
| units | comment | cost_type |
| 10 | materialtestcomment | cost_type_1 |
| 6 | materialtestcomment2 | cost_type_1 |
And the budget "budget1" has the following labor items:
| hours | comment | user |
| 8 | labortestcomment | testuser |
| 5 | labortestcomment2 | testuser |
And I go to the show page of the budget "budget1"
When I click on "Copy"
Then I should see "New Budget"
And the planned material costs in row 1 should be "400.00 EUR"
And the planned labor costs in row 1 should be "296.00 EUR"
And the planned material costs in row 2 should be "240.00 EUR"
And the planned labor costs in row 2 should be "185.00 EUR"

@ -8,3 +8,49 @@ When(/^I create a budget with the following:$/) do |table|
click_button(I18n.t(:button_create), :exact => true)
end
When(/^I create the budget$/) do
click_button(I18n.t(:button_create), :exact => true)
end
When(/^I setup a budget with the following:$/) do |table|
rows = table.rows_hash
steps %Q{And I toggle the "Budgets" submenu
And I follow "New Budget" within "#main-menu"
And I fill in "Subject" with "#{rows['subject']}"}
end
When(/^I (?:create|update) (?:a|the) (labor|material) item in row (\d+) with the following:$/) do | type, row_nr, table|
rows = table.rows_hash
unit = (type == 'labor') ? 'hours' : 'units'
page.find("##{type}_budget_items_body tr:nth-child(#{row_nr}) .units input").set(rows[unit])
page.find("##{type}_budget_items_body tr:nth-child(#{row_nr}) .comment input").set(rows['comment'])
if type == 'labor'
page.find(:xpath, "//tbody[@id='#{type}_budget_items_body']/tr[#{row_nr}]//option[contains(., '#{rows['user']}')]").select_option
end
end
When(/^I add a new (labor|material) item$/) do | type|
steps %Q{ When I click on "Add Planned Costs" within "fieldset##{type}_budget_items" }
end
Then (/^the planned (labor|material) costs in row (\d+) should be (.+)$/) do | type, row_nr, amount|
steps %Q{ Then I should see #{amount} within "##{type}_budget_items_body tr:nth-child(#{row_nr}) td.currency" }
end
Then (/^the stored planned (labor|material) costs in row (\d+) should be (.+)$/) do | type, row_nr, amount|
steps %Q{ Then I should see #{amount} within ".splitcontentleft .#{type}_budget_items.list tr:nth-child(#{row_nr}) td.currency" }
end
Then (/^the stored total planned (labor|material) costs should be (.+)$/) do | type, amount|
steps %Q{ Then I should see #{amount} within ".splitcontentleft .#{type}_budget_items.list tr:last-child td.currency" }
end
Then (/^I should be able to update the budget "(.+)"$/) do | budget |
steps %Q{ Then I should be on the show page for the budget "#{budget}"
And I should see "Update" within "div#update" }
end

@ -165,7 +165,7 @@ Given /^users have times and the cost type "([^\"]*)" logged on the issue "([^\"
end
end
Given /^there is a variable cost object with the following:$/ do |table|
Given /^there is a (?:variable cost object|budget) with the following:$/ do |table|
cost_object = FactoryGirl.build(:variable_cost_object)
table_hash = table.rows_hash
@ -189,3 +189,21 @@ Given /^I update the variable cost object "([^"]*)" with the following:$/ do |su
cost_object.save!
end
Given /^the (?:variable cost object|budget) "(.+)" has the following labor items:$/ do |subject, table|
cost_object = VariableCostObject.find_by_subject(subject)
table.hashes.each do | hash |
user = User.find_by_login(hash['user']) || User.find_by_name(hash['user']) || cost_object.project.members.first.principal
FactoryGirl.create(:labor_budget_item, :user => user, :cost_object => cost_object, :comments => hash['comment'], :hours => hash['hours'])
end
end
Given /^the (?:variable cost object|budget) "(.+)" has the following material items:$/ do |subject, table|
cost_object = VariableCostObject.find_by_subject(subject)
table.hashes.each do | hash |
cost_type = CostType.find_by_name(hash['cost_type']) || Cost_type.first
FactoryGirl.create(:material_budget_item, :cost_type => cost_type, :cost_object => cost_object, :comments => hash['comment'], :units => hash['units'])
end
end

@ -0,0 +1,190 @@
Feature: Managing Budgets
Background:
Given there is 1 User with:
| Login | testuser |
| firstname | Chuck |
| lastname | Testa |
| default rate | 37 |
And there is 1 Project with the following:
| name | project1 |
| identifier | project1 |
And there is a role "manager"
And the role "manager" may have the following rights:
| edit_cost_objects |
| view_cost_rates |
| view_hourly_rates |
And there is 1 cost type with the following:
| name | cost_type_1 |
| unit | single_unit |
| unit_plural | multi_unit |
| cost_rate | 40 |
And the user "testuser" is a "manager" in the project "project1"
And I am already logged in as "testuser"
Scenario: Empty budgets can be created
When I go to the overview page of the project called "project1"
And I create a budget with the following:
| subject | budget1 |
Then I should be on the show page for the budget "budget1"
And I should see "Successful creation"
And I should see "budget1" within ".cost_object"
@javascript
Scenario: Budgets with cost items can be created adding new cost items
When I go to the overview page of the project called "project1"
And I setup a budget with the following:
| subject | budget1 |
And I create a material item in row 1 with the following:
| units | 10 |
| comment | materialtestcomment |
Then the planned material costs in row 1 should be "400.00 EUR"
When I create a labor item in row 1 with the following:
| hours | 8 |
| comment | labortestcomment |
| user | Chuck Testa |
Then the planned labor costs in row 1 should be "296.00 EUR"
When I add a new material item
And I create a material item in row 2 with the following:
| units | 6 |
| comment | materialtestcomment2 |
Then the planned material costs in row 2 should be "240.00 EUR"
When I add a new labor item
When I create a labor item in row 2 with the following:
| hours | 5 |
| comment | labortestcomment2 |
| user | Chuck Testa |
Then the planned labor costs in row 2 should be "185.00 EUR"
When I create the budget
Then I should be on the show page for the budget "budget1"
And I should see "Successful creation"
And I should see "budget1" within ".cost_object"
And the stored planned material costs in row 1 should be "400.00 EUR"
And the stored planned labor costs in row 1 should be "296.00 EUR"
And the stored planned material costs in row 2 should be "240.00 EUR"
And the stored planned labor costs in row 2 should be "185.00 EUR"
And the stored total planned material costs should be "640.00 EUR"
And the stored total planned labor costs should be "481.00 EUR"
@javascript
Scenario: Budgets can be updated with new cost items
Given there is a budget with the following:
| subject | budget1 |
| author | testuser |
| project | project1 |
And I go to the show page of the budget "budget1"
When I click on "Update"
Then I should be on the show page for the budget "budget1"
And I should see "Update"
When I create a material item in row 1 with the following:
| units | 10 |
| comment | materialtestcomment |
Then the planned material costs in row 1 should be "400.00 EUR"
When I create a labor item in row 1 with the following:
| hours | 8 |
| comment | labortestcomment |
| user | Chuck Testa |
Then the planned labor costs in row 1 should be "296.00 EUR"
When I click on "Submit"
Then I should be on the show page for the budget "budget1"
And I should see "Successful update"
And the stored planned material costs in row 1 should be "400.00 EUR"
And the stored planned labor costs in row 1 should be "296.00 EUR"
And the stored total planned material costs should be "400.00 EUR"
And the stored total planned labor costs should be "296.00 EUR"
@javascript
Scenario: Budgets can be updated updating existing cost items
Given there is a budget with the following:
| subject | budget1 |
| author | testuser |
| project | project1 |
And the budget "budget1" has the following labor items:
| hours | comment | user |
| 8 | labortestcomment | testuser |
| 5 | labortestcomment2 | testuser |
And I go to the show page of the budget "budget1"
And I start debugging
#TODO: above is duplicate until here, replace with test setup
When I click on "Update"
Then I should be on the show page for the budget "budget1"
And I should see "Update"
When I create a material item in row 1 with the following:
| units | 10 |
| comment | materialtestcomment |
Then the planned material costs in row 1 should be "400.00 EUR"
#When I create a labor item in row 1 with the following:
# | hours | 8 |
# | comment | labortestcomment |
# | user | Chuck Testa |
#Then the planned labor costs in row 1 should be "296.00 EUR"
When I click on "Submit"
Then I should be on the show page for the budget "budget1"
And I should see "Successful update"
And the stored planned material costs in row 1 should be "400.00 EUR"
And the stored planned labor costs in row 1 should be "296.00 EUR"
And the stored total planned material costs should be "400.00 EUR"
And the stored total planned labor costs should be "296.00 EUR"
#TODO: above is duplicate until here, replace with test setup
When I click on "Update"
Then I should be on the show page for the budget "budget1"
And I should see "Update"
When I update the material item in row 1 with the following:
| units | 5 |
| comment | changed_materialtestcomment |
Then the planned material costs in row 1 should be "200.00 EUR"
When I update the labor item in row 1 with the following:
| hours | 10 |
| comment | changed_labortestcomment |
| user | Chuck Testa |
Then the planned labor costs in row 1 should be "370.00 EUR"
When I click on "Submit"
Then I should be on the show page for the budget "budget1"
And I should see "Successful update"
And the stored planned material costs in row 1 should be "200.00 EUR"
And the stored planned labor costs in row 1 should be "370.00 EUR"
And the stored total planned material costs should be "200.00 EUR"
And the stored total planned labor costs should be "370.00 EUR"
@javascript
Scenario: Budgets can be copied
When I go to the overview page of the project called "project1"
And I setup a budget with the following:
| subject | budget1 |
And I create a material item in row 1 with the following:
| units | 10 |
| comment | materialtestcomment |
Then the planned material costs in row 1 should be "400.00 EUR"
When I create a labor item in row 1 with the following:
| hours | 8 |
| comment | labortestcomment |
| user | Chuck Testa |
Then the planned labor costs in row 1 should be "296.00 EUR"
When I add a new material item
And I create a material item in row 2 with the following:
| units | 6 |
| comment | materialtestcomment2 |
Then the planned material costs in row 2 should be "240.00 EUR"
When I add a new labor item
When I create a labor item in row 2 with the following:
| hours | 5 |
| comment | labortestcomment2 |
| user | Chuck Testa |
Then the planned labor costs in row 2 should be "185.00 EUR"
When I create the budget
Then I should be on the show page for the budget "budget1"
And I should see "Successful creation"
And I should see "budget1" within ".cost_object"
And the stored planned material costs in row 1 should be "400.00 EUR"
And the stored planned labor costs in row 1 should be "296.00 EUR"
And the stored planned material costs in row 2 should be "240.00 EUR"
And the stored planned labor costs in row 2 should be "185.00 EUR"
And the stored total planned material costs should be "640.00 EUR"
And the stored total planned labor costs should be "481.00 EUR"
#TODO: above is duplicate until here, replace with test setup
When I click on "Copy"
Then I should see "New Budget"
And the planned material costs in row 1 should be "400.00 EUR"
And the planned labor costs in row 1 should be "296.00 EUR"
And the planned material costs in row 2 should be "240.00 EUR"
And the planned labor costs in row 2 should be "185.00 EUR"

@ -0,0 +1,7 @@
FactoryGirl.define do
factory :material_budget_item do
association :cost_type, :factory => :cost_type
association :cost_object, :factory => :variable_cost_object
units 0.0
end
end
Loading…
Cancel
Save