public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/glsamaker:master commit in: app/models/, test/unit/, test/fixtures/
@ 2011-02-25 19:43 Alex Legler
  0 siblings, 0 replies; only message in thread
From: Alex Legler @ 2011-02-25 19:43 UTC (permalink / raw
  To: gentoo-commits

commit:     0f84779616d454f69f74002d3d754c2043381da9
Author:     Alex Legler <alex <AT> a3li <DOT> li>
AuthorDate: Fri Feb 25 19:21:50 2011 +0000
Commit:     Alex Legler <a3li <AT> gentoo <DOT> org>
CommitDate: Fri Feb 25 19:21:50 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/glsamaker.git;a=commit;h=0f847796

Add a deep_copy method to the Revision model

The method copies all linked models (bugs, packages, revisions) as well.
Adding some extra fixtures to test this

---
 app/models/revision.rb       |   15 +++++++++++++++
 test/fixtures/bugs.yml       |   16 ++++++++++------
 test/fixtures/packages.yml   |   24 +++++++++++++++++-------
 test/fixtures/references.yml |   14 ++++++--------
 test/unit/revision_test.rb   |   28 +++++++++++++++++++++++++---
 5 files changed, 73 insertions(+), 24 deletions(-)

diff --git a/app/models/revision.rb b/app/models/revision.rb
index 7b462ef..241c2c2 100644
--- a/app/models/revision.rb
+++ b/app/models/revision.rb
@@ -55,4 +55,19 @@ class Revision < ActiveRecord::Base
       b.update_cached_metadata
     end
   end
+  
+  # Creates a deep copy of a previous revision, copying all bugs, references and packages,
+  # incrementing the revision ID by one.
+  # <b>The caller must take care of deleting this revision again in case any error occurs later.</b>
+  def deep_copy
+    new_rev = clone
+    new_rev.revid = glsa.next_revid
+    
+    references.each {|reference| new_rev.references << reference.clone }
+    packages.each {|package| new_rev.packages << package.clone }
+    bugs.each {|bug| new_rev.bugs << bug.clone }
+    
+    new_rev.save!
+    new_rev
+  end
 end

diff --git a/test/fixtures/bugs.yml b/test/fixtures/bugs.yml
index 5bf0293..f275338 100644
--- a/test/fixtures/bugs.yml
+++ b/test/fixtures/bugs.yml
@@ -1,7 +1,11 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+bug_one:
+  bug_id: 236060
+  title: dev-lang/ruby <1.8.6_p287-r1 REXML DoS Vulnerability (CVE-2008-3790)
+  whiteboard: "B3? [glsa]"
+  revision_id: 1
 
-# one:
-#   column: value
-#
-# two:
-#   column: value
+bug_two:
+  bug_id: 260006
+  title: "<dev-lang/ruby-{1.8.6_p287-r{5, 12}, 1.8.7_p72-r2}: X.509 certificate spoofing vulnerability (CVE-2009-0642)"
+  whiteboard: "B4 [noglsa]"
+  revision_id: 1
\ No newline at end of file

diff --git a/test/fixtures/packages.yml b/test/fixtures/packages.yml
index 5bf0293..1512bbc 100644
--- a/test/fixtures/packages.yml
+++ b/test/fixtures/packages.yml
@@ -1,7 +1,17 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-
-# one:
-#   column: value
-#
-# two:
-#   column: value
+package_one:
+  my_type: vulnerable
+  atom: dev-lang/ruby
+  version: 1.8.7_p334
+  comp: <
+  arch: *
+  automatic: 1
+  revision_id: 1
+  
+package_two:
+  my_type: unaffected
+  atom: dev-lang/ruby
+  version: 1.8.7_p334
+  comp: >=
+  arch: *
+  automatic: 1
+  revision_id: 1  
\ No newline at end of file

diff --git a/test/fixtures/references.yml b/test/fixtures/references.yml
index 826c663..50867bd 100644
--- a/test/fixtures/references.yml
+++ b/test/fixtures/references.yml
@@ -1,13 +1,11 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-
 reference_one:
   id: 1
   revision_id: 2
   title: Reference 1 Title
   url: http://reference-1-title.com/ref.html
-
-# one:
-#   column: value
-#
-# two:
-#   column: value
+  
+reference_two:
+  id: 2
+  revision_id: 1
+  title: Reference 2 Title
+  url: http://reference-2-title.com/ref.html
\ No newline at end of file

diff --git a/test/unit/revision_test.rb b/test/unit/revision_test.rb
index f50f1af..8514302 100644
--- a/test/unit/revision_test.rb
+++ b/test/unit/revision_test.rb
@@ -1,8 +1,30 @@
 require 'test_helper'
 
 class RevisionTest < ActiveSupport::TestCase
-  # Replace this with your real tests.
-  test "the truth" do
-    assert true
+  test "deep copy" do
+    revision = revisions(:revision_one)
+    new_revision = revision.deep_copy
+    
+    assert_equal(revision.title, new_revision.title)
+    assert_equal(revision.glsa_id, new_revision.glsa_id)
+    assert_equal(revision.access, new_revision.access)
+    assert_equal(revision.product, new_revision.product)
+    assert_equal(revision.category, new_revision.category)
+    assert_equal(revision.severity, new_revision.severity)
+    assert_equal(revision.synopsis, new_revision.synopsis)
+    assert_equal(revision.background, new_revision.background)
+    assert_equal(revision.description, new_revision.description)
+    assert_equal(revision.impact, new_revision.impact)
+    assert_equal(revision.workaround, new_revision.workaround)
+    assert_equal(revision.resolution, new_revision.resolution)
+    
+    # Assuming that if the bug ID is copied, so is the rest
+    assert_equal(revision.bugs.map{|bug| bug.bug_id}.sort, new_revision.bugs.map{|bug| bug.bug_id}.sort)
+    
+    assert_equal(revision.references.map{|ref| ref.url}.sort, new_revision.references.map{|ref| ref.url}.sort)
+    assert_equal(
+      revision.packages.map{|pkg| "#{pkg.comp}#{pkg.atom}-#{pkg.version}"}.sort,
+      new_revision.packages.map{|pkg| "#{pkg.comp}#{pkg.atom}-#{pkg.version}"}.sort
+    )
   end
 end



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2011-02-25 19:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-25 19:43 [gentoo-commits] proj/glsamaker:master commit in: app/models/, test/unit/, test/fixtures/ Alex Legler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox