Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
O
OHR Support
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
97
Issues
97
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
OHR Support
Commits
e7883b87
Commit
e7883b87
authored
Jun 10, 2011
by
Eric Davis
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ticket/release-v2.0.0/445-initial-journal-tracking' into release-v2.0.0
parents
731de487
33e3a713
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
21 deletions
+65
-21
20100714111651_generalize_journals.rb
db/migrate/20100714111651_generalize_journals.rb
+43
-20
journal_test.rb
test/unit/journal_test.rb
+21
-0
changes.rb
...ts_as_journalized/lib/redmine/acts/journalized/changes.rb
+1
-1
No files found.
db/migrate/20100714111651_generalize_journals.rb
View file @
e7883b87
...
...
@@ -46,6 +46,49 @@ class GeneralizeJournals < ActiveRecord::Migration
t
.
remove
:journalized_type
end
# Build initial journals for all activity providers
providers
=
Redmine
::
Activity
.
providers
.
collect
{
|
k
,
v
|
v
.
collect
(
&
:constantize
)
}.
flatten
.
compact
.
uniq
providers
.
each
do
|
p
|
next
unless
p
.
table_exists?
# Objects not in the DB yet need creation journal entries
p
.
find
(
:all
).
each
do
|
o
|
# Create initial journals
new_journal
=
o
.
journals
.
build
# Mock up a list of changes for the creation journal based on Class defaults
new_attributes
=
o
.
class
.
new
.
attributes
.
except
(
o
.
class
.
primary_key
,
o
.
class
.
inheritance_column
,
:updated_on
,
:updated_at
,
:lock_version
,
:lft
,
:rgt
)
creation_changes
=
{}
new_attributes
.
each
do
|
name
,
default_value
|
# Set changes based on the initial value to current. Can't get creation value without
# rebuiling the object history
creation_changes
[
name
]
=
[
default_value
,
o
.
send
(
name
)]
# [initial_value, creation_value]
end
new_journal
.
changes
=
creation_changes
new_journal
.
version
=
1
if
o
.
respond_to?
(
:author
)
new_journal
.
user
=
o
.
author
elsif
o
.
respond_to?
(
:user
)
new_journal
.
user
=
o
.
user
end
new_journal
.
save
# Backdate journal
if
o
.
respond_to?
(
:created_at
)
new_journal
.
update_attribute
(
:created_at
,
o
.
created_at
)
elsif
o
.
respond_to?
(
:created_on
)
new_journal
.
update_attribute
(
:created_at
,
o
.
created_on
)
end
p
"Updating
#{
o
}
"
end
end
# Migrate journal changes now
JournalDetails
.
all
.
each
do
|
detail
|
journal
=
Journal
.
find
(
detail
.
journal_id
)
changes
=
journal
.
changes
||
{}
...
...
@@ -59,26 +102,6 @@ class GeneralizeJournals < ActiveRecord::Migration
journal
.
update_attribute
(
:changes
,
changes
.
to_yaml
)
end
# Create creation journals for all activity providers
providers
=
Redmine
::
Activity
.
providers
.
collect
{
|
k
,
v
|
v
.
collect
(
&
:constantize
)
}.
flatten
.
compact
.
uniq
providers
.
each
do
|
p
|
next
unless
p
.
table_exists?
# Objects not in the DB yet need creation journal entries
p
.
find
(
:all
).
each
do
|
o
|
unless
o
.
last_journal
o
.
send
(
:update_journal
)
created_at
=
nil
[
:created_at
,
:created_on
,
:updated_at
,
:updated_on
].
each
do
|
m
|
if
o
.
respond_to?
m
created_at
=
o
.
send
(
m
)
break
end
end
p
"Updating
#{
o
}
"
o
.
last_journal
.
update_attribute
(
:created_at
,
created_at
)
if
created_at
and
o
.
last_journal
end
end
end
# drop_table :journal_details
end
...
...
test/unit/journal_test.rb
View file @
e7883b87
...
...
@@ -58,4 +58,25 @@ class JournalTest < ActiveSupport::TestCase
end
assert_equal
0
,
ActionMailer
::
Base
.
deliveries
.
size
end
test
"creating the initial journal should track the changes from creation"
do
@project
=
Project
.
generate!
issue
=
Issue
.
new
do
|
i
|
i
.
project
=
@project
i
.
subject
=
"Test initial journal"
i
.
tracker
=
@project
.
trackers
.
first
i
.
author
=
User
.
generate!
i
.
description
=
"Some content"
end
assert_difference
(
"Journal.count"
)
do
assert
issue
.
save
end
journal
=
issue
.
reload
.
journals
.
first
assert_equal
[
""
,
"Test initial journal"
],
journal
.
changes
[
"subject"
]
assert_equal
[
0
,
@project
.
id
],
journal
.
changes
[
"project_id"
]
assert_equal
[
nil
,
"Some content"
],
journal
.
changes
[
"description"
]
end
end
vendor/plugins/acts_as_journalized/lib/redmine/acts/journalized/changes.rb
View file @
e7883b87
...
...
@@ -45,7 +45,7 @@ module Redmine::Acts::Journalized
base
.
class_eval
do
include
InstanceMethods
after_
updat
e
:merge_journal_changes
after_
sav
e
:merge_journal_changes
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment