From 043e189c069b779bbee6d33cecf60de7b8344250 Mon Sep 17 00:00:00 2001 From: Ion Biziiac Date: Tue, 27 May 2014 17:17:31 +0300 Subject: [PATCH 1/6] Add cukes for cost types delete confirmation message --- features/cost_types/deletion.feature | 7 ++++++ features/step_definitions/cost_type_steps.rb | 23 ++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/features/cost_types/deletion.feature b/features/cost_types/deletion.feature index 2fc120db61..823d39bb49 100644 --- a/features/cost_types/deletion.feature +++ b/features/cost_types/deletion.feature @@ -36,3 +36,10 @@ Feature: Cost type deletion Then the cost type "cost_type1" should be listed as deleted on the index page + @javascript + Scenario: Click on the "delete" link for a cost type + When I go to the index page of cost types + + Then I expect to click "OK" on a confirmation box saying "Are you sure?" + And I click the delete link for the cost type "cost_type1" + And the confirmation box should have been displayed diff --git a/features/step_definitions/cost_type_steps.rb b/features/step_definitions/cost_type_steps.rb index 6c23d9b840..93f6aa0be2 100644 --- a/features/step_definitions/cost_type_steps.rb +++ b/features/step_definitions/cost_type_steps.rb @@ -47,6 +47,29 @@ When(/^I delete the cost type "(.*?)"$/) do |name| end end +When(/^I click the delete link for the cost type "(.*?)"$/) do |name| + ct = CostType.find_by_name name + + within ("#delete_cost_type_#{ct.id}") do + find('a.submit_cost_type').click + end +end + +When /^I expect to click "([^"]*)" on a confirmation box saying "([^"]*)"$/ do |option, message| + retval = (option == 'OK') ? 'true' : 'false' + page.evaluate_script("window.confirm = function (msg) { + document.cookie = msg + return #{retval} + }") + @expected_message = message.gsub("\\n", "\n") +end + +When /^the confirmation box should have been displayed$/ do + assert page.evaluate_script('document.cookie').include?(@expected_message), + "Expected confirm box with message: '#{@expected_message}'" + + " got: '#{page.evaluate_script('document.cookie')}'" +end + Then(/^the cost type "(.*?)" should not be listed on the index page$/) do |name| if has_css?(".cost_types") From 303abe9c4bb48d2913856fe0e74cbc9b5082d86b Mon Sep 17 00:00:00 2001 From: Ion Biziiac Date: Tue, 27 May 2014 17:18:13 +0300 Subject: [PATCH 2/6] Add translations for cost types delete confirmation message --- config/locales/de.yml | 3 +++ config/locales/en.yml | 3 +++ 2 files changed, 6 insertions(+) diff --git a/config/locales/de.yml b/config/locales/de.yml index 7390e4832a..88c66fdafa 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -203,3 +203,6 @@ de: x_entries: one: "1 Eintrag" other: "%{count} Einträge" + + js: + text_are_you_sure: "Sind Sie sicher?" diff --git a/config/locales/en.yml b/config/locales/en.yml index 8bb43824f1..7ff28c9260 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -203,3 +203,6 @@ en: x_entries: one: "1 Entry" other: "%{count} Entries" + + js: + text_are_you_sure: "Are you sure?" From 1a72d736e58b30b9291fbf7feeec5e0436f21784 Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Fri, 30 May 2014 13:42:59 +0200 Subject: [PATCH 3/6] Add changelog entry --- doc/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 0458f11952..4891f28972 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -20,6 +20,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Changelog +* `#8230` Missing Translation when deleting Cost Type + ## 5.0.4 * `#4024` Fix: Subpages have no unique page titles From cbb792e339a9ac99cc3ba09dedc0e60180b90534 Mon Sep 17 00:00:00 2001 From: Ion Biziiac Date: Mon, 9 Jun 2014 16:04:08 +0300 Subject: [PATCH 4/6] Add specs for rate update with invalid values --- .../hourly_rates_controller_spec.rb | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 spec/controllers/hourly_rates_controller_spec.rb diff --git a/spec/controllers/hourly_rates_controller_spec.rb b/spec/controllers/hourly_rates_controller_spec.rb new file mode 100644 index 0000000000..e2e706fd15 --- /dev/null +++ b/spec/controllers/hourly_rates_controller_spec.rb @@ -0,0 +1,50 @@ +#-- copyright +# OpenProject Costs Plugin +# +# Copyright (C) 2009 - 2014 the OpenProject Foundation (OPF) +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +#++ + +require File.expand_path(File.dirname(__FILE__) + "/../spec_helper.rb") + +describe HourlyRatesController do + let(:user) { FactoryGirl.create(:user) } + let(:admin) { FactoryGirl.create(:admin) } + let(:default_rate) { FactoryGirl.create(:default_hourly_rate, :user => user) } + + describe "PUT update" do + describe "WHEN trying to update with an invalid rate value" do + let(:params) { + { + :id => user.id, + :user => {"existing_rate_attributes" => {"#{default_rate.id}" => {"valid_from" => "#{default_rate.valid_from}", "rate" => "2d5" }}} + } + } + before do + as_logged_in_user admin do + post :update, params + end + end + + it "should render the edit template" do + expect(response).to render_template("edit") + end + + it "should display an error message" do + expect(assigns(:user).default_rates.first.errors.messages[:rate].first).to eq("is not a number") + end + end + end +end From ba89511d301a3c1aab2f0bd9336c6f4ff296193b Mon Sep 17 00:00:00 2001 From: Ion Biziiac Date: Mon, 9 Jun 2014 16:05:26 +0300 Subject: [PATCH 5/6] Fix rate update with invalid values --- app/controllers/hourly_rates_controller.rb | 6 ++---- app/views/hourly_rates/_rate.html.erb | 5 ----- app/views/hourly_rates/edit.html.erb | 4 ++++ lib/open_project/costs/patches/user_patch.rb | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/app/controllers/hourly_rates_controller.rb b/app/controllers/hourly_rates_controller.rb index d07bf923df..516d45b8b9 100644 --- a/app/controllers/hourly_rates_controller.rb +++ b/app/controllers/hourly_rates_controller.rb @@ -89,15 +89,13 @@ class HourlyRatesController < ApplicationController if @user.save flash[:notice] = l(:notice_successful_update) if @project.nil? - redirect_back_or_default(:action => 'show', :id => @user) + redirect_back_or_default(:controller => 'users', :action => 'edit', :id => @user) else redirect_back_or_default(:action => 'show', :id => @user, :project_id => @project) end else if @project.nil? - @rates = DefaultHourlyRate.all( - :conditions => {:user_id => @user}, - :order => "#{DefaultHourlyRate.table_name}.valid_from desc") + @rates = @user.default_rates @rates << @user.default_rates.build({:valid_from => Date.today}) if @rates.empty? else @rates = @user.rates.select{|r| r.project_id == @project.id}.sort { |a,b| b.valid_from <=> a.valid_from } diff --git a/app/views/hourly_rates/_rate.html.erb b/app/views/hourly_rates/_rate.html.erb index a14739f796..68e1f63745 100644 --- a/app/views/hourly_rates/_rate.html.erb +++ b/app/views/hourly_rates/_rate.html.erb @@ -26,13 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. id_prefix = "user_#{new_or_existing}_rate_attributes_#{id_or_index}" name_prefix = "user[#{new_or_existing}_rate_attributes][#{id_or_index}]" classes ||= "" - - @rate = rate - error_messages = error_messages_for 'rate' -%> - -<% unless error_messages.blank? %><%= error_messages %><% end %> <%= fields_for prefix, rate do |rate_form| %> diff --git a/app/views/hourly_rates/edit.html.erb b/app/views/hourly_rates/edit.html.erb index 34fddcfbc1..70fc836828 100644 --- a/app/views/hourly_rates/edit.html.erb +++ b/app/views/hourly_rates/edit.html.erb @@ -36,6 +36,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. <%= labelled_tabular_form_for @user, :url => {:action => 'update', :project_id => @project}, :method => :put do |f| %> <%= back_url_hidden_field_tag %> <%= error_messages_for 'user' %> +<%- @rates.each do |rate| -%> + <%- @rate = rate -%> + <%= error_messages_for 'rate' %> +<%- end -%> diff --git a/lib/open_project/costs/patches/user_patch.rb b/lib/open_project/costs/patches/user_patch.rb index 0426478cf5..6abe14e3df 100644 --- a/lib/open_project/costs/patches/user_patch.rb +++ b/lib/open_project/costs/patches/user_patch.rb @@ -90,7 +90,7 @@ module OpenProject::Costs::Patches::UserPatch def save_rates (default_rates + rates).each do |rate| - rate.save(:validate => false) + return false if !rate.save end end From 6aff59b73d049b40a831ebdd3720c90d4f46248b Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Tue, 10 Jun 2014 11:01:03 +0200 Subject: [PATCH 6/6] Add changelog entry --- doc/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 4891f28972..ddce4a51c6 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Changelog * `#8230` Missing Translation when deleting Cost Type +* `#8233` Changing the default rate with invalid values ## 5.0.4
<%= Rate.human_attribute_name(:valid_from) %>