require File.dirname(__FILE__) + '/../test_helper' class PatchVersionTest < Test::Unit::TestCase fixtures :patches, :patch_versions def test_text_methods patch_contents = 'The patch contents per se' p = Patch.create(:title => 'Some patch', :description => 'Patch description', :filename => 'some_patch.diff', :program_id => 1, :created_by => 1, :text => patch_contents) assert_equal(patch_contents, p.text) patch_file_path = File.join(PatchVersion.patch_dir, p.latest_version.id.to_s) assert_equal(patch_contents, File.read(patch_file_path)) end def test_version_setting p1 = Patch.find(1) p2 = Patch.find(2) pv = PatchVersion.create(:for_upstream_version => '3.0', :text => 'Foobar', :patch => p1) assert_equal(2, p1.patch_versions.count) assert_equal(2, pv.version) pv.patch = p2 pv.save assert_equal(1, p1.patch_versions.count) assert_equal(3, p2.patch_versions.count) assert_equal(3, pv.version) end end