forked from edavis10/redmine_merge_redmine
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |