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
# Mailer.deliver_issue_edit(journal) => sends an email to issue recipients
def issue_edit(journal)
issue = journal.versioned.reload
issue = journal.journaled.reload
redmine_headers 'Project' => issue.project.identifier,
'Issue-Id' => issue.id,
'Issue-Author' => issue.author.login
@ -162,11 +162,11 @@ class Mailer < ActionMailer::Base
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}"
body :message => message,
:message_url => url_for(message.event_url)
:message_url => url_for(message.last_journal.event_url)
render_multipart('message_posted', body)
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:
# wiki_content_added(wiki_content) => tmail object

View File

@ -29,7 +29,7 @@ class Message < ActiveRecord::Base
if o.parent_id.nil?
{:id => o.id}
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),
: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
def compress_version_text
self.text = changes["text"].last if changes["text"]
self.text ||= self.versioned.text
self.text ||= self.journaled.text
end
def text=(plain)
@ -97,7 +97,26 @@ class WikiContent < ActiveRecord::Base
# Returns the previous version or nil
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

View File

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

View File

@ -154,14 +154,14 @@ class ActiveSupport::TestCase
end
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)
assert_match @new_value.name, @detail.render_detail(prop_key, true)
end
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)
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 %w(Project Version), events.collect(&:container_type).uniq.sort
end
private
def find_events(user, options={})
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
# their targets here, transform that
events.group_by(&:versioned).keys
events.group_by(&:journaled).keys
end
end

View File

@ -44,27 +44,31 @@ class IssuesHelperTest < HelperTestCase
@request ||= ActionController::TestRequest.new
end
def show_detail(journal, html = true)
journal.render_detail(journal.details.first)
end
context "IssuesHelper#show_detail" do
context "with no_html" 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)
end
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)
end
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)
end
end
context "with html" 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)
assert_select 'strong', :text => '% Done'
@ -73,7 +77,7 @@ class IssuesHelperTest < HelperTestCase
end
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)
assert_select 'strong', :text => '% Done'
@ -81,7 +85,7 @@ class IssuesHelperTest < HelperTestCase
end
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)
assert_select 'strong', :text => '% Done'
@ -93,24 +97,24 @@ class IssuesHelperTest < HelperTestCase
context "with a start_date attribute" 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)
end
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)
end
end
context "with a due_date attribute" 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)
end
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)
end
end

View File

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

View File

@ -107,7 +107,7 @@ class WikiPageTest < ActiveSupport::TestCase
# make sure that page content and its history are deleted
assert WikiContent.find_all_by_page_id(1).empty?
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