Permalink
Browse files

Provide tests for reverse_dependencies model helpers

  • Loading branch information...
1 parent c31cf0f commit 6dfe2df7313ea84c22e968450f07a2dcc73ad6fb @alup alup committed Mar 4, 2013
Showing with 62 additions and 0 deletions.
  1. +31 −0 test/unit/rubygem_test.rb
  2. +31 −0 test/unit/version_test.rb
View
@@ -142,6 +142,37 @@ class RubygemTest < ActiveSupport::TestCase
end
end
+ context ".reverse_dependencies" do
+ setup do
+ @dep_rubygem = create(:rubygem)
+ @gem_one = create(:rubygem)
+ @gem_two = create(:rubygem)
+ @gem_three = create(:rubygem)
+ @gem_four = create(:rubygem)
+ @version_one_latest = create(:version, :rubygem => @gem_one, :number => '0.2')
+ @version_one_earlier = create(:version, :rubygem => @gem_one, :number => '0.1')
+ @version_two_latest = create(:version, :rubygem => @gem_two, :number => '1.0')
+ @version_two_earlier = create(:version, :rubygem => @gem_two, :number => '0.5')
+ @version_three = create(:version, :rubygem => @gem_three, :number => '1.7')
+ @version_four = create(:version, :rubygem => @gem_four, :number => '3.9')
+
+ @version_one_latest.dependencies << create(:dependency, :version => @version_one_latest, :rubygem => @dep_rubygem)
+ @version_two_earlier.dependencies << create(:dependency, :version => @version_two_earlier, :rubygem => @dep_rubygem)
+ @version_three.dependencies << create(:dependency, :version => @version_three, :rubygem => @dep_rubygem)
+ end
+
+ should "return all depended rubygems" do
+ gem_list = Rubygem.reverse_dependencies(@dep_rubygem.name)
+
+ assert_equal 3, gem_list.size
+
+ assert gem_list.include?(@gem_one)
+ assert gem_list.include?(@gem_two)
+ assert gem_list.include?(@gem_three)
+ assert ! gem_list.include?(@gem_four)
+ end
+ end
+
context "with a rubygem" do
setup do
@rubygem = build(:rubygem, :linkset => nil)
View
@@ -58,6 +58,37 @@ class VersionTest < ActiveSupport::TestCase
end
end
+ context ".reverse_dependencies" do
+ setup do
+ @dep_rubygem = create(:rubygem)
+ @gem_one = create(:rubygem)
+ @gem_two = create(:rubygem)
+ @gem_three = create(:rubygem)
+ @version_one_latest = create(:version, :rubygem => @gem_one, :number => '0.2')
+ @version_one_earlier = create(:version, :rubygem => @gem_one, :number => '0.1')
+ @version_two_latest = create(:version, :rubygem => @gem_two, :number => '1.0')
+ @version_two_earlier = create(:version, :rubygem => @gem_two, :number => '0.5')
+ @version_three = create(:version, :rubygem => @gem_three, :number => '1.7')
+
+ @version_one_latest.dependencies << create(:dependency, :version => @version_one_latest, :rubygem => @dep_rubygem)
+ @version_two_earlier.dependencies << create(:dependency, :version => @version_two_earlier, :rubygem => @dep_rubygem)
+ @version_three.dependencies << create(:dependency, :version => @version_three, :rubygem => @dep_rubygem)
+ end
+
+ should "return all depended gem versions" do
+ version_list = Version.reverse_dependencies(@dep_rubygem.name)
+
+ assert_equal 3, version_list.size
+
+ assert version_list.include?(@version_one_latest)
+ assert version_list.include?(@version_two_earlier)
+ assert version_list.include?(@version_three)
+ assert ! version_list.include?(@version_one_earlier)
+ assert ! version_list.include?(@version_two_latest)
+ end
+ end
+
+
context "updated gems" do
setup do
Timecop.freeze Date.today

0 comments on commit 6dfe2df

Please sign in to comment.