Merge pull request #9 from finnlabs/feature/rails3_fix_cost_type_deletion

fixes cost_type deletion
pull/6827/head
sschu 12 years ago
commit 80cec805aa
  1. 4
      app/controllers/cost_types_controller.rb
  2. 7
      app/helpers/costlog_helper.rb
  3. 7
      app/views/cost_types/_list.html.erb
  4. 8
      app/views/cost_types/_list_deleted.html.erb
  5. 18
      features/cost_types/deletion.feature
  6. 15
      features/step_definitions/cost_steps.rb
  7. 51
      features/step_definitions/cost_type_steps.rb
  8. 2
      features/support/path.rb

@ -80,8 +80,10 @@ class CostTypesController < ApplicationController
def toggle_delete
@cost_type.deleted_at = @cost_type.deleted_at ? nil : DateTime.now()
@cost_type.default = false
if request.post? && @cost_type.save
if @cost_type.save
flash[:notice] = @cost_type.deleted_at ? l(:notice_successful_delete) : l(:notice_successful_restore)
redirect_back_or_default(:action => 'index')
end
end

@ -95,5 +95,10 @@ module CostlogHelper
value.gsub(',', '.')
BigDecimal.new(value)
end
end
def to_currency_with_empty(rate)
rate.nil? ?
"0.0" :
number_to_currency(rate.rate)
end
end

@ -20,8 +20,7 @@
<%= content_tag :td, link_to(cost_type.name, {:controller => '/cost_types', :action => 'edit', :id => cost_type}) %>
<%= content_tag :td, cost_type.unit %>
<%= content_tag :td, cost_type.unit_plural %>
<% rate = cost_type.rate_at(@fixed_date) %>
<%= content_tag :td, number_to_currency( rate ? rate.rate : 0.0), :class => "currency", :id => "cost_type_#{cost_type.id}_rate"%>
<%= content_tag :td, to_currency_with_empty(cost_type.rate_at(@fixed_date)), :class => "currency", :id => "cost_type_#{cost_type.id}_rate"%>
<td>
<%= form_for cost_type, :url => { :controller => '/cost_types', :action => 'set_rate', :id => cost_type } do |f| %>
<label class="hidden-for-sighted" for="<%= "rate_field_#{cost_type.id}" %>"><%= l(:caption_set_rate) %></label>
@ -31,7 +30,9 @@
</td>
<%= content_tag :td, cost_type.is_default? ? image_tag('check.png', :alt => l(:general_text_Yes)) : "" %>
<td>
<%= form_for cost_type, :url => { :controller => '/cost_types', :action => 'toggle_delete', :id => cost_type } do |f| %>
<%= form_for cost_type, :url => toggle_delete_cost_type_path(cost_type),
:html => { :id => "delete_cost_type_#{cost_type.id}",
:class => "delete_cost_type" } do |f| %>
<%= image_submit_tag "locked.png", :alt => l(:button_lock), :title => l(:button_lock), :onclick => "return confirm('#{escape_javascript(l(:text_are_you_sure))}')" %>
<% end %>
</td>

@ -3,7 +3,7 @@
<% if cost_types.empty? %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% else %>
<table class="list cost_types">
<table class="list cost_types deleted_cost_types">
<thead><tr>
<%= sort_header_tag "name", :caption => l(:caption_cost_type) %>
<%= sort_header_tag "unit", :caption => l(:caption_cost_type_unit_name) %>
@ -19,10 +19,12 @@
<%= content_tag :td, cost_type.name %>
<%= content_tag :td, cost_type.unit %>
<%= content_tag :td, cost_type.unit_plural %>
<%= content_tag :td, number_to_currency(cost_type.rate_at(@fixed_date).rate), :class => "currency" %>
<%= content_tag :td, to_currency_with_empty(cost_type.rate_at(@fixed_date)), :class => "currency" %>
<%= content_tag :td, cost_type.deleted_at.to_date %>
<td>
<%= form_for :cost_type, cost_type, toggle_delete_cost_type_path(cost_type) do |f| %>
<%= form_for cost_type, :url => toggle_delete_cost_type_path(cost_type),
:html => { :id => "restore_cost_type_#{cost_type.id}",
:class => "restore_cost_type" } do |f| %>
<%= image_submit_tag "unlock.png" , :alt => l(:button_unlock), :title => l(:button_unlock) %>
<% end %>
</td>

@ -0,0 +1,18 @@
Feature: Cost type deletion
Background:
Given there is 1 cost type with the following:
| name | cost_type1 |
And I am already logged in as "admin"
Scenario: Deleting a cost type
When I delete the cost type "cost_type1"
Then the cost type "cost_type1" should not be listed on the index page
@javascript
Scenario: Deleted cost types are listed as deleted
When I delete the cost type "cost_type1"
Then the cost type "cost_type1" should be listed as deleted on the index page

@ -8,21 +8,6 @@ Given /^the project "([^\"]+)" has (\d+) [Cc]ost(?: )?[Ee]ntr(?:ies|y)$/ do |pro
end
end
Given /^there is 1 cost type with the following:$/ do |table|
ct = CostType.generate
send_table_to_object(ct, table, {
:cost_rate => Proc.new do |o,v|
FactoryGirl.create(:cost_rate, :rate => v,
:cost_type => o)
end,
:name => Proc.new do |o,v|
o.name = v
o.unit = v
o.unit_plural = "#{v}s"
o.save!
end})
end
Given /^there (?:is|are) (\d+) (default )?hourly rate[s]? with the following:$/ do |num, is_default, table|
if is_default
hr = DefaultHourlyRate.spawn

@ -0,0 +1,51 @@
Given /^there is 1 cost type with the following:$/ do |table|
ct = CostType.generate
send_table_to_object(ct, table, {
:cost_rate => Proc.new do |o,v|
FactoryGirl.create(:cost_rate, :rate => v,
:cost_type => o)
end,
:name => Proc.new do |o,v|
o.name = v
o.unit = v
o.unit_plural = "#{v}s"
o.save!
end})
end
When(/^I delete the cost type "(.*?)"$/) do |name|
step %{I go to the index page of cost types}
ct = CostType.find_by_name name
within ("#delete_cost_type_#{ct.id}") do
find('input[type=image]', :visible => true).click
end
if page.driver.is_a? Capybara::Selenium::Driver
# confirm "really delete?"
page.driver.browser.switch_to.alert.accept
end
end
Then(/^the cost type "(.*?)" should not be listed on the index page$/) do |name|
if has_css?(".cost_types")
within ".cost_types" do
should_not have_link(name)
end
end
end
Then(/^the cost type "(.*?)" should be listed as deleted on the index page$/) do |name|
check(I18n.t(:caption_show_locked))
click_link(I18n.t(:button_apply))
within ".deleted_cost_types" do
should have_text(name)
end
end

@ -10,6 +10,8 @@ module CostNavigationHelpers
when /^the show page (?:of|for) the budget "(.+)?"$/
budget = CostObject.find_by_subject($1)
"/cost_objects/#{budget.id}"
when /^the index page (?:of|for) cost types$/
"/cost_types"
else
super
end

Loading…
Cancel
Save