diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 85789e2..71e07ce 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -187,22 +187,22 @@ class IssuesController < ApplicationController if request.post? @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today) @time_entry.attributes = params[:time_entry] - attachments = attach_files(@issue, params[:attachments]) - attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)} - - call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal}) - - if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.save - # Log spend time - if User.current.allowed_to?(:log_time, @project) - @time_entry.save - end - if !journal.new_record? - # Only send notification if something was actually changed - flash[:notice] = l(:notice_successful_update) + if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.valid? + attachments = attach_files(@issue, params[:attachments]) + attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)} + call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal}) + if @issue.save + # Log spend time + if User.current.allowed_to?(:log_time, @project) + @time_entry.save + end + if !journal.new_record? + # Only send notification if something was actually changed + flash[:notice] = l(:notice_successful_update) + end + call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal}) + redirect_back_or_default({:action => 'show', :id => @issue}) end - call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal}) - redirect_back_or_default({:action => 'show', :id => @issue}) end end rescue ActiveRecord::StaleObjectError diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 6868734..241da0b 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -62,8 +62,8 @@ class SearchController < ApplicationController # extract tokens from the question # eg. hello "bye bye" => ["hello", "bye bye"] @tokens = @question.scan(%r{((\s|^)"[\s\w]+"(\s|$)|\S+)}).collect {|m| m.first.gsub(%r{(^\s*"\s*|\s*"\s*$)}, '')} - # tokens must be at least 3 character long - @tokens = @tokens.uniq.select {|w| w.length > 2 } + # tokens must be at least 2 characters long + @tokens = @tokens.uniq.select {|w| w.length > 1 } if !@tokens.empty? # no more than 5 tokens to search for diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 1f74011..0f28cc0 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -91,8 +91,8 @@ module IssuesHelper c = IssueCategory.find_by_id(detail.value) and value = c.name if detail.value c = IssueCategory.find_by_id(detail.old_value) and old_value = c.name if detail.old_value when 'fixed_version_id' - v = Version.find_by_id(detail.value) and value = format_version_name(v) if detail.value - v = Version.find_by_id(detail.old_value) and old_value = format_version_name(v) if detail.old_value + v = Version.find_by_id(detail.value) and value = v.name if detail.value + v = Version.find_by_id(detail.old_value) and old_value = v.name if detail.old_value when 'estimated_hours' value = "%0.02f" % detail.value.to_f unless detail.value.blank? old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank? diff --git a/app/models/mailer.rb b/app/models/mailer.rb index dfd2737..9c409af 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -272,6 +272,7 @@ class Mailer < ActionMailer::Base # Overrides default deliver! method to prevent from sending an email # with no recipient, cc or bcc def deliver!(mail = @mail) + set_language_if_valid @initial_language return false if (recipients.nil? || recipients.empty?) && (cc.nil? || cc.empty?) && (bcc.nil? || bcc.empty?) @@ -313,6 +314,7 @@ class Mailer < ActionMailer::Base private def initialize_defaults(method_name) super + @initial_language = current_language set_language_if_valid Setting.default_language from Setting.mail_from diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index dfc6caf..fbbff1a 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -20,7 +20,7 @@ require File.dirname(__FILE__) + '/../test_helper' class MailerTest < ActiveSupport::TestCase include Redmine::I18n include ActionController::Assertions::SelectorAssertions - fixtures :projects, :issues, :users, :members, :member_roles, :documents, :attachments, :news, :tokens, :journals, :journal_details, :changesets, :trackers, :issue_statuses, :enumerations, :messages, :boards, :repositories + fixtures :projects, :enabled_modules, :issues, :users, :members, :member_roles, :roles, :documents, :attachments, :news, :tokens, :journals, :journal_details, :changesets, :trackers, :issue_statuses, :enumerations, :messages, :boards, :repositories def test_generated_links_in_emails ActionMailer::Base.deliveries.clear @@ -296,4 +296,18 @@ class MailerTest < ActiveSupport::TestCase assert_not_nil mail mail end + + def test_mailer_should_not_change_locale + Setting.default_language = 'en' + # Set current language to italian + set_language_if_valid 'it' + # Send an email to a french user + user = User.find(1) + user.language = 'fr' + Mailer.deliver_account_activated(user) + mail = ActionMailer::Base.deliveries.last + assert mail.body.include?('Votre compte') + + assert_equal :it, current_language + end end