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
# 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
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?
# 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?)
private
def initialize_defaults(method_name)
super
+ @initial_language = current_language
set_language_if_valid Setting.default_language
from Setting.mail_from
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
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