fix various tests in mailer, wiki content and issue helper

This commit is contained in:
Tim Felgentreff 2010-09-14 14:25:19 +02:00
parent 4b098d7774
commit 72e7baafdf
9 changed files with 65 additions and 42 deletions

View File

@ -56,7 +56,7 @@ class Mailer < ActionMailer::Base
# issue_edit(journal) => tmail object # issue_edit(journal) => tmail object
# Mailer.deliver_issue_edit(journal) => sends an email to issue recipients # Mailer.deliver_issue_edit(journal) => sends an email to issue recipients
def issue_edit(journal) def issue_edit(journal)
issue = journal.versioned.reload issue = journal.journaled.reload
redmine_headers 'Project' => issue.project.identifier, redmine_headers 'Project' => issue.project.identifier,
'Issue-Id' => issue.id, 'Issue-Id' => issue.id,
'Issue-Author' => issue.author.login 'Issue-Author' => issue.author.login
@ -162,11 +162,11 @@ class Mailer < ActionMailer::Base
cc((message.root.watcher_recipients + message.board.watcher_recipients).uniq - @recipients) cc((message.root.watcher_recipients + message.board.watcher_recipients).uniq - @recipients)
subject "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}" subject "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}"
body :message => message, body :message => message,
:message_url => url_for(message.event_url) :message_url => url_for(message.last_journal.event_url)
render_multipart('message_posted', body) render_multipart('message_posted', body)
end end
# Builds a tmail object used to email the recipients of a project of the specified wiki content was added. # Builds a tmail object used to email the recipients of a project of the specified wiki content was added.
# #
# Example: # Example:
# wiki_content_added(wiki_content) => tmail object # wiki_content_added(wiki_content) => tmail object

View File

@ -29,7 +29,7 @@ class Message < ActiveRecord::Base
if o.parent_id.nil? if o.parent_id.nil?
{:id => o.id} {:id => o.id}
else else
{:id => o.parent_id, :r => o.versioned.id, :anchor => "message-#{o.versioned.id}"} {:id => o.parent_id, :r => o.journaled.id, :anchor => "message-#{o.journaled.id}"}
end.reverse_merge :controller => 'messages', :action => 'show', :board_id => o.board_id end.reverse_merge :controller => 'messages', :action => 'show', :board_id => o.board_id
end), end),
:activity_find_options => { :include => { :board => :project } } :activity_find_options => { :include => { :board => :project } }

View File

@ -61,7 +61,7 @@ class WikiContent < ActiveRecord::Base
# Wiki Content might be large and the data should possibly be compressed # Wiki Content might be large and the data should possibly be compressed
def compress_version_text def compress_version_text
self.text = changes["text"].last if changes["text"] self.text = changes["text"].last if changes["text"]
self.text ||= self.versioned.text self.text ||= self.journaled.text
end end
def text=(plain) def text=(plain)
@ -97,7 +97,26 @@ class WikiContent < ActiveRecord::Base
# Returns the previous version or nil # Returns the previous version or nil
def previous def previous
@previous ||= versioned.journals.at(version - 1) @previous ||= journaled.journals.at(version - 1)
end
# FIXME: Deprecate
def versioned
journaled
end
# FIXME: Deprecate
def versions
journals
end
def version
unless last_journal
# FIXME: This is code that caters for a case that should never happen in the normal code paths!!
update_journal
last_journal.update_attribute(:created_at, updated_on)
end
last_journal.version
end end
end end
end end

View File

@ -7,7 +7,7 @@ journals_001:
version: 1 version: 1
user_id: 1 user_id: 1
notes: "Journal notes" notes: "Journal notes"
versioned_id: 1 journaled_id: 1
changes: | changes: |
--- ---
status_id: status_id:
@ -24,7 +24,7 @@ journals_002:
version: 2 version: 2
user_id: 2 user_id: 2
notes: "Some notes with Redmine links: #2, r2." notes: "Some notes with Redmine links: #2, r2."
versioned_id: 1 journaled_id: 1
changes: "--- {}" changes: "--- {}"
journals_003: journals_003:
id: 3 id: 3
@ -34,7 +34,7 @@ journals_003:
version: 1 version: 1
user_id: 2 user_id: 2
notes: "A comment with inline image: !picture.jpg!" notes: "A comment with inline image: !picture.jpg!"
versioned_id: 2 journaled_id: 2
changes: "--- {}" changes: "--- {}"
journals_004: journals_004:
id: 4 id: 4
@ -44,7 +44,7 @@ journals_004:
version: 1 version: 1
user_id: 2 user_id: 2
notes: "A comment with a private version." notes: "A comment with a private version."
versioned_id: 6 journaled_id: 6
changes: | changes: |
--- ---
fixed_version_id: fixed_version_id:
@ -58,7 +58,7 @@ journals_005:
version: 0 version: 0
user_id: 1 user_id: 1
notes: notes:
versioned_id: 5 journaled_id: 5
changes: "--- {}" changes: "--- {}"
journals_006: journals_006:
id: 6 id: 6
@ -68,7 +68,7 @@ journals_006:
version: 1 version: 1
user_id: 2 user_id: 2
notes: Page creation notes: Page creation
versioned_id: 1 journaled_id: 1
changes: | changes: |
--- ---
compression: "" compression: ""
@ -86,7 +86,7 @@ journals_007:
version: 2 version: 2
user_id: 1 user_id: 1
notes: Small update notes: Small update
versioned_id: 1 journaled_id: 1
changes: | changes: |
--- ---
compression: "" compression: ""
@ -104,7 +104,7 @@ journals_008:
version: 3 version: 3
user_id: 1 user_id: 1
notes: "" notes: ""
versioned_id: 1 journaled_id: 1
changes: | changes: |
--- ---
compression: "" compression: ""
@ -119,7 +119,7 @@ journals_009:
version: 1 version: 1
user_id: 1 user_id: 1
notes: notes:
versioned_id: 2 journaled_id: 2
changes: | changes: |
--- ---
data: |- data: |-
@ -136,7 +136,7 @@ journals_010:
version: 1 version: 1
user_id: 1 user_id: 1
notes: notes:
versioned_id: 5 journaled_id: 5
changes: --- {} changes: --- {}
journals_011: journals_011:
id: 11 id: 11
@ -146,7 +146,7 @@ journals_011:
version: 1 version: 1
user_id: 2 user_id: 2
notes: "An attachment on a version" notes: "An attachment on a version"
versioned_id: 9 journaled_id: 9
changes: --- {} changes: --- {}
journals_012: journals_012:
id: 12 id: 12
@ -156,7 +156,7 @@ journals_012:
version: 1 version: 1
user_id: 2 user_id: 2
notes: "An attachment on a project" notes: "An attachment on a project"
versioned_id: 8 journaled_id: 8
changes: --- {} changes: --- {}
journals_013: journals_013:
id: 13 id: 13
@ -166,7 +166,7 @@ journals_013:
version: 1 version: 1
user_id: 2 user_id: 2
notes: "An attachment on an issue" notes: "An attachment on an issue"
versioned_id: 7 journaled_id: 7
changes: --- {} changes: --- {}
journals_014: journals_014:
id: 14 id: 14
@ -176,7 +176,7 @@ journals_014:
version: 1 version: 1
user_id: 2 user_id: 2
notes: "An attachment on a document" notes: "An attachment on a document"
versioned_id: 2 journaled_id: 2
changes: --- {} changes: --- {}
journals_015: journals_015:
id: 15 id: 15
@ -186,7 +186,7 @@ journals_015:
version: 1 version: 1
user_id: 2 user_id: 2
notes: "A message journal" notes: "A message journal"
versioned_id: 1 journaled_id: 1
journals_016: journals_016:
id: 16 id: 16
type: "MessageJournal" type: "MessageJournal"
@ -195,7 +195,7 @@ journals_016:
version: 1 version: 1
user_id: 2 user_id: 2
notes: "A message journal" notes: "A message journal"
versioned_id: 2 journaled_id: 2
journals_017: journals_017:
id: 17 id: 17
type: "MessageJournal" type: "MessageJournal"
@ -204,4 +204,4 @@ journals_017:
version: 1 version: 1
user_id: 2 user_id: 2
notes: "A message journal" notes: "A message journal"
versioned_id: 3 journaled_id: 3

View File

@ -154,14 +154,14 @@ class ActiveSupport::TestCase
end end
should "use the new value's name" do should "use the new value's name" do
@detail = IssueJournal.generate(:version => 1) @detail = IssueJournal.generate(:version => 1, :journaled => Issue.last)
@detail.update_attribute(:changes, {prop_key => [@old_value.id, @new_value.id]}.to_yaml) @detail.update_attribute(:changes, {prop_key => [@old_value.id, @new_value.id]}.to_yaml)
assert_match @new_value.name, @detail.render_detail(prop_key, true) assert_match @new_value.name, @detail.render_detail(prop_key, true)
end end
should "use the old value's name" do should "use the old value's name" do
@detail = IssueJournal.generate(:version => 1) @detail = IssueJournal.generate(:version => 1, :journaled => Issue.last)
@detail.update_attribute(:changes, {prop_key => [@old_value.id, @new_value.id]}.to_yaml) @detail.update_attribute(:changes, {prop_key => [@old_value.id, @new_value.id]}.to_yaml)
assert_match @old_value.name, @detail.render_detail(prop_key, true) assert_match @old_value.name, @detail.render_detail(prop_key, true)

View File

@ -82,13 +82,13 @@ class ActivityTest < ActiveSupport::TestCase
assert_equal [Attachment], events.collect(&:class).uniq assert_equal [Attachment], events.collect(&:class).uniq
assert_equal %w(Project Version), events.collect(&:container_type).uniq.sort assert_equal %w(Project Version), events.collect(&:container_type).uniq.sort
end end
private private
def find_events(user, options={}) def find_events(user, options={})
events = Redmine::Activity::Fetcher.new(user, options).events(Date.today - 30, Date.today + 1) events = Redmine::Activity::Fetcher.new(user, options).events(Date.today - 30, Date.today + 1)
# Because events are provided by the journals, but we want to test for # Because events are provided by the journals, but we want to test for
# their targets here, transform that # their targets here, transform that
events.group_by(&:versioned).keys events.group_by(&:journaled).keys
end end
end end

View File

@ -44,27 +44,31 @@ class IssuesHelperTest < HelperTestCase
@request ||= ActionController::TestRequest.new @request ||= ActionController::TestRequest.new
end end
def show_detail(journal, html = true)
journal.render_detail(journal.details.first)
end
context "IssuesHelper#show_detail" do context "IssuesHelper#show_detail" do
context "with no_html" do context "with no_html" do
should 'show a changing attribute' do should 'show a changing attribute' do
@detail = JournalDetail.generate!(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio') @detail = IssueJournal.generate!(:changes => {"done_ratio" => [40, 100]}, :journaled => Issue.last)
assert_equal "% Done changed from 40 to 100", show_detail(@detail, true) assert_equal "% Done changed from 40 to 100", show_detail(@detail, true)
end end
should 'show a new attribute' do should 'show a new attribute' do
@detail = JournalDetail.generate!(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio') @detail = IssueJournal.generate!(:changes => {"done_ratio" => [nil, 100]}, :journaled => Issue.last)
assert_equal "% Done set to 100", show_detail(@detail, true) assert_equal "% Done set to 100", show_detail(@detail, true)
end end
should 'show a deleted attribute' do should 'show a deleted attribute' do
@detail = JournalDetail.generate!(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio') @detail = IssueJournal.generate!(:changes => {"done_ratio" => [50, nil]}, :journaled => Issue.last)
assert_equal "% Done deleted (50)", show_detail(@detail, true) assert_equal "% Done deleted (50)", show_detail(@detail, true)
end end
end end
context "with html" do context "with html" do
should 'show a changing attribute with HTML highlights' do should 'show a changing attribute with HTML highlights' do
@detail = JournalDetail.generate!(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio') @detail = IssueJournal.generate!(:changes => {"done_ratio" => [40, 100]}, :journaled => Issue.last)
@response.body = show_detail(@detail, false) @response.body = show_detail(@detail, false)
assert_select 'strong', :text => '% Done' assert_select 'strong', :text => '% Done'
@ -73,7 +77,7 @@ class IssuesHelperTest < HelperTestCase
end end
should 'show a new attribute with HTML highlights' do should 'show a new attribute with HTML highlights' do
@detail = JournalDetail.generate!(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio') @detail = IssueJournal.generate!(:changes => {"done_ratio" => [nil, 100]}, :journaled => Issue.last)
@response.body = show_detail(@detail, false) @response.body = show_detail(@detail, false)
assert_select 'strong', :text => '% Done' assert_select 'strong', :text => '% Done'
@ -81,7 +85,7 @@ class IssuesHelperTest < HelperTestCase
end end
should 'show a deleted attribute with HTML highlights' do should 'show a deleted attribute with HTML highlights' do
@detail = JournalDetail.generate!(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio') @detail = IssueJournal.generate!(:changes => {"done_ratio" => [50, nil]}, :journaled => Issue.last)
@response.body = show_detail(@detail, false) @response.body = show_detail(@detail, false)
assert_select 'strong', :text => '% Done' assert_select 'strong', :text => '% Done'
@ -93,24 +97,24 @@ class IssuesHelperTest < HelperTestCase
context "with a start_date attribute" do context "with a start_date attribute" do
should "format the current date" do should "format the current date" do
@detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'start_date') @detail = IssueJournal.generate!(:changes => {"start_date" => ['2010-01-01', '2010-01-31']}, :journaled => Issue.last)
assert_match "01/31/2010", show_detail(@detail, true) assert_match "01/31/2010", show_detail(@detail, true)
end end
should "format the old date" do should "format the old date" do
@detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'start_date') @detail = IssueJournal.generate!(:changes => {"start_date" => ['2010-01-01', '2010-01-31']}, :journaled => Issue.last)
assert_match "01/01/2010", show_detail(@detail, true) assert_match "01/01/2010", show_detail(@detail, true)
end end
end end
context "with a due_date attribute" do context "with a due_date attribute" do
should "format the current date" do should "format the current date" do
@detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'due_date') @detail = IssueJournal.generate!(:changes => {"due_date" => ['2010-01-01', '2010-01-31']}, :journaled => Issue.last)
assert_match "01/31/2010", show_detail(@detail, true) assert_match "01/31/2010", show_detail(@detail, true)
end end
should "format the old date" do should "format the old date" do
@detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'due_date') @detail = IssueJournal.generate!(:changes => {"due_date" => ['2010-01-01', '2010-01-31']}, :journaled => Issue.last)
assert_match "01/01/2010", show_detail(@detail, true) assert_match "01/01/2010", show_detail(@detail, true)
end end
end end

View File

@ -72,9 +72,9 @@ class WikiContentTest < ActiveSupport::TestCase
end end
def test_fetch_history def test_fetch_history
assert !@page.content.versions.empty? assert !@page.content.journals.empty?
@page.content.versions.each do |version| @page.content.journals.each do |journal|
assert_kind_of String, version.text assert_kind_of String, journal.text
end end
end end

View File

@ -107,7 +107,7 @@ class WikiPageTest < ActiveSupport::TestCase
# make sure that page content and its history are deleted # make sure that page content and its history are deleted
assert WikiContent.find_all_by_page_id(1).empty? assert WikiContent.find_all_by_page_id(1).empty?
content_ids.each do |wiki_content_id| content_ids.each do |wiki_content_id|
assert WikiContent.journal_class.find_all_by_versioned_id(wiki_content_id).empty? assert WikiContent.journal_class.find_all_by_journaled_id(wiki_content_id).empty?
end end
end end