1 |
commit: 0f84779616d454f69f74002d3d754c2043381da9 |
2 |
Author: Alex Legler <alex <AT> a3li <DOT> li> |
3 |
AuthorDate: Fri Feb 25 19:21:50 2011 +0000 |
4 |
Commit: Alex Legler <a3li <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Feb 25 19:21:50 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/glsamaker.git;a=commit;h=0f847796 |
7 |
|
8 |
Add a deep_copy method to the Revision model |
9 |
|
10 |
The method copies all linked models (bugs, packages, revisions) as well. |
11 |
Adding some extra fixtures to test this |
12 |
|
13 |
--- |
14 |
app/models/revision.rb | 15 +++++++++++++++ |
15 |
test/fixtures/bugs.yml | 16 ++++++++++------ |
16 |
test/fixtures/packages.yml | 24 +++++++++++++++++------- |
17 |
test/fixtures/references.yml | 14 ++++++-------- |
18 |
test/unit/revision_test.rb | 28 +++++++++++++++++++++++++--- |
19 |
5 files changed, 73 insertions(+), 24 deletions(-) |
20 |
|
21 |
diff --git a/app/models/revision.rb b/app/models/revision.rb |
22 |
index 7b462ef..241c2c2 100644 |
23 |
--- a/app/models/revision.rb |
24 |
+++ b/app/models/revision.rb |
25 |
@@ -55,4 +55,19 @@ class Revision < ActiveRecord::Base |
26 |
b.update_cached_metadata |
27 |
end |
28 |
end |
29 |
+ |
30 |
+ # Creates a deep copy of a previous revision, copying all bugs, references and packages, |
31 |
+ # incrementing the revision ID by one. |
32 |
+ # <b>The caller must take care of deleting this revision again in case any error occurs later.</b> |
33 |
+ def deep_copy |
34 |
+ new_rev = clone |
35 |
+ new_rev.revid = glsa.next_revid |
36 |
+ |
37 |
+ references.each {|reference| new_rev.references << reference.clone } |
38 |
+ packages.each {|package| new_rev.packages << package.clone } |
39 |
+ bugs.each {|bug| new_rev.bugs << bug.clone } |
40 |
+ |
41 |
+ new_rev.save! |
42 |
+ new_rev |
43 |
+ end |
44 |
end |
45 |
|
46 |
diff --git a/test/fixtures/bugs.yml b/test/fixtures/bugs.yml |
47 |
index 5bf0293..f275338 100644 |
48 |
--- a/test/fixtures/bugs.yml |
49 |
+++ b/test/fixtures/bugs.yml |
50 |
@@ -1,7 +1,11 @@ |
51 |
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html |
52 |
+bug_one: |
53 |
+ bug_id: 236060 |
54 |
+ title: dev-lang/ruby <1.8.6_p287-r1 REXML DoS Vulnerability (CVE-2008-3790) |
55 |
+ whiteboard: "B3? [glsa]" |
56 |
+ revision_id: 1 |
57 |
|
58 |
-# one: |
59 |
-# column: value |
60 |
-# |
61 |
-# two: |
62 |
-# column: value |
63 |
+bug_two: |
64 |
+ bug_id: 260006 |
65 |
+ title: "<dev-lang/ruby-{1.8.6_p287-r{5, 12}, 1.8.7_p72-r2}: X.509 certificate spoofing vulnerability (CVE-2009-0642)" |
66 |
+ whiteboard: "B4 [noglsa]" |
67 |
+ revision_id: 1 |
68 |
\ No newline at end of file |
69 |
|
70 |
diff --git a/test/fixtures/packages.yml b/test/fixtures/packages.yml |
71 |
index 5bf0293..1512bbc 100644 |
72 |
--- a/test/fixtures/packages.yml |
73 |
+++ b/test/fixtures/packages.yml |
74 |
@@ -1,7 +1,17 @@ |
75 |
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html |
76 |
- |
77 |
-# one: |
78 |
-# column: value |
79 |
-# |
80 |
-# two: |
81 |
-# column: value |
82 |
+package_one: |
83 |
+ my_type: vulnerable |
84 |
+ atom: dev-lang/ruby |
85 |
+ version: 1.8.7_p334 |
86 |
+ comp: < |
87 |
+ arch: * |
88 |
+ automatic: 1 |
89 |
+ revision_id: 1 |
90 |
+ |
91 |
+package_two: |
92 |
+ my_type: unaffected |
93 |
+ atom: dev-lang/ruby |
94 |
+ version: 1.8.7_p334 |
95 |
+ comp: >= |
96 |
+ arch: * |
97 |
+ automatic: 1 |
98 |
+ revision_id: 1 |
99 |
\ No newline at end of file |
100 |
|
101 |
diff --git a/test/fixtures/references.yml b/test/fixtures/references.yml |
102 |
index 826c663..50867bd 100644 |
103 |
--- a/test/fixtures/references.yml |
104 |
+++ b/test/fixtures/references.yml |
105 |
@@ -1,13 +1,11 @@ |
106 |
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html |
107 |
- |
108 |
reference_one: |
109 |
id: 1 |
110 |
revision_id: 2 |
111 |
title: Reference 1 Title |
112 |
url: http://reference-1-title.com/ref.html |
113 |
- |
114 |
-# one: |
115 |
-# column: value |
116 |
-# |
117 |
-# two: |
118 |
-# column: value |
119 |
+ |
120 |
+reference_two: |
121 |
+ id: 2 |
122 |
+ revision_id: 1 |
123 |
+ title: Reference 2 Title |
124 |
+ url: http://reference-2-title.com/ref.html |
125 |
\ No newline at end of file |
126 |
|
127 |
diff --git a/test/unit/revision_test.rb b/test/unit/revision_test.rb |
128 |
index f50f1af..8514302 100644 |
129 |
--- a/test/unit/revision_test.rb |
130 |
+++ b/test/unit/revision_test.rb |
131 |
@@ -1,8 +1,30 @@ |
132 |
require 'test_helper' |
133 |
|
134 |
class RevisionTest < ActiveSupport::TestCase |
135 |
- # Replace this with your real tests. |
136 |
- test "the truth" do |
137 |
- assert true |
138 |
+ test "deep copy" do |
139 |
+ revision = revisions(:revision_one) |
140 |
+ new_revision = revision.deep_copy |
141 |
+ |
142 |
+ assert_equal(revision.title, new_revision.title) |
143 |
+ assert_equal(revision.glsa_id, new_revision.glsa_id) |
144 |
+ assert_equal(revision.access, new_revision.access) |
145 |
+ assert_equal(revision.product, new_revision.product) |
146 |
+ assert_equal(revision.category, new_revision.category) |
147 |
+ assert_equal(revision.severity, new_revision.severity) |
148 |
+ assert_equal(revision.synopsis, new_revision.synopsis) |
149 |
+ assert_equal(revision.background, new_revision.background) |
150 |
+ assert_equal(revision.description, new_revision.description) |
151 |
+ assert_equal(revision.impact, new_revision.impact) |
152 |
+ assert_equal(revision.workaround, new_revision.workaround) |
153 |
+ assert_equal(revision.resolution, new_revision.resolution) |
154 |
+ |
155 |
+ # Assuming that if the bug ID is copied, so is the rest |
156 |
+ assert_equal(revision.bugs.map{|bug| bug.bug_id}.sort, new_revision.bugs.map{|bug| bug.bug_id}.sort) |
157 |
+ |
158 |
+ assert_equal(revision.references.map{|ref| ref.url}.sort, new_revision.references.map{|ref| ref.url}.sort) |
159 |
+ assert_equal( |
160 |
+ revision.packages.map{|pkg| "#{pkg.comp}#{pkg.atom}-#{pkg.version}"}.sort, |
161 |
+ new_revision.packages.map{|pkg| "#{pkg.comp}#{pkg.atom}-#{pkg.version}"}.sort |
162 |
+ ) |
163 |
end |
164 |
end |