Skip to content

Commit

Permalink
[#3264] Added Journal migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
edavis10 committed Nov 12, 2009
1 parent 9737a07 commit 65af7b6
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/redmine_merge.rb
Expand Up @@ -13,6 +13,7 @@ def self.migrate
SourceIssueCategory.migrate
SourceIssue.migrate
SourceIssueRelation.migrate
SourceJournal.migrate
end

class Mapper
Expand Down
17 changes: 17 additions & 0 deletions app/models/source_journal.rb
@@ -0,0 +1,17 @@
class SourceJournal < ActiveRecord::Base
include SecondDatabase
set_table_name :journals

belongs_to :journalized, :polymorphic => true
belongs_to :issue, :class_name => 'SourceIssue', :foreign_key => :journalized_id

def self.migrate
all.each do |source_journals|

j = Journal.new
j.attributes = source_journals.attributes
j.issue = Issue.find_by_subject(source_journals.issue.subject)
j.save!
end
end
end
40 changes: 40 additions & 0 deletions test/unit/source_journal_test.rb
@@ -0,0 +1,40 @@
require File.dirname(__FILE__) + '/../test_helper'

class SourceJournalTest < Test::Unit::TestCase
context "#migrate" do
setup do
User.anonymous # preload

# Make sure Journals are associating correctly and not that they
# just happen to match ids.
@project = Project.generate!
@tracker = Tracker.generate!
@project.trackers << @tracker
@enumeration = Enumeration.generate!(:opt => 'IPRI')
Issue.generate!(:tracker => @tracker, :project => @project, :priority => @enumeration)

SourceUser.migrate
SourceTracker.migrate
SourceIssueStatus.migrate
SourceEnumeration.migrate_issue_priorities
SourceProject.migrate
SourceVersion.migrate
SourceIssueCategory.migrate
SourceIssue.migrate

end

should_add_each_record_from_the_source_to_the_destination(Journal, 2) { SourceJournal.migrate }

should "keep the issue associations" do
SourceJournal.migrate

issue = Issue.find_by_subject("Can't print recipes")
assert issue
assert_equal 2, issue.journals.count
assert issue.journals.collect(&:notes).include? "Journal notes"
assert issue.journals.collect(&:notes).include? "Some notes with Redmine links: #2, r2."
end

end
end

0 comments on commit 65af7b6

Please sign in to comment.