Class | VersionTest
In: | test/unit/version_test.rb
Parent: | Test::Unit::TestCase

Copyright (c) 2006 Logica

### Methods

setup test_various test_various_2 test_xhtmldiff_diff_links

### Public Instance methods

setup()

[Source]

        # File test/unit/version_test.rb, line 21
    21:   def setup
    22:     logger.debug "Test Case: #{name}"
    23:     @oup_20060721 = create_oup_20060721
    24:     @oup_wiki = create_oup_wiki(@oup_20060721)
    25:     @oup_20060728 = create_oup_20060728
    26:     @oup_20060825 = create_oup_20060825
    27:     @andy = users(:andy)
    28:     @tony = users(:tony)
    29:     @cash = users(:cash)
    30:     @emails = ActionMailer::Base::deliveries
    31:     @emails.clear
    32:   end

test_various()

Shows:

1. We cannot checkout to baseline process, only to a Wiki
2. We cannot write the html from a BaselineProcessVersion
3. The path of a BaselineProcessVersion is just the path of the Page

[Source]

        # File test/unit/version_test.rb, line 38
    38:   def test_various
    39:     # 1
    40:     assert_equal [0, 617], [UserVersion.count, BaselineProcessVersion.count]
    41:     page = WikiPage.find(:first, :conditions => ['filename = ? and site_id = ?','test_data,_0ZZFcMlgEdmt3adZL5Dmdw.html', @oup_wiki])
    42:     page.reload
    43:     assert_equal 1, page.versions.size
    44:     assert_equal 0, page.current_version.version
    45:     co = Checkout.new(:user => @andy, :page => page, :site => @oup_20060825, :source_version => page.current_version)
    46:     assert_raise(RuntimeError) {co.save}
    47:     # 2
    48:     assert_raise(NoMethodError) {page.current_version.html = 'version3 from @oup_wiki'}
    49:     # 3
    50:     page = WikiPage.find_by_filename('test_data,_0ZZFcMlgEdmt3adZL5Dmdw.html')
    51:     assert_not_nil page
    52:     version = page.current_version
    53:     assert_equal 0, version.version
    54:     bp_page = BaselineProcessPage.find_by_filename('test_data,_0ZZFcMlgEdmt3adZL5Dmdw.html')
    55:     assert_equal bp_page.path, version.path
    56:   end

test_various_2()

Shows:

1. The first version (version 0) does not have a previous_version
2. We create version 1: previous_version is equal to the first version
3. We create version 2 which has some added text
4. We can rollback changes by creating version 3 based on version 1
5. Shows we can make a version ‘current‘
6. Checkout doesn‘t change the ‘current’ version but checkin does

[Source]

         # File test/unit/version_test.rb, line 65
     65:   def test_various_2
     66:     page = WikiPage.find_by_filename('implementation,_0TeDoMlgEdmt3adZL5Dmdw.html')
     67:     page.reload
     68:     assert_not_nil page.versions
     69:     assert File.exists?(page.path)
     70:     cv0 = page.current_version
     71:     assert_equal BaselineProcessVersion.name, cv0.class.name
     72:     assert_equal 0, cv0.version
     73:     # 1
     74:     assert_equal nil, cv0.previous_version
     75:     # 2
     76:     # creating a new version
     77:     co = Checkout.new(:user => @andy, :page => page, :site => @oup_wiki, :source_version => cv0)
     78:     assert co.save
     79:     co.checkin(@andy)
     80:     cv1 = page.current_version
     81:     assert_equal 1, cv1.version
     82:     assert_equal cv1.previous_version, cv0
     83:     # 3
     84:     co = Checkout.new(:user => @andy, :page => page, :site => @oup_wiki, :source_version => cv1)
     85:     assert co.save
     86:     cv2 = co.version
     87:     assert_nil cv2.version # number is determined on checkin
     88:     cv2.html = cv2.html.gsub('</body>', '####</body>')
     89:     co.checkin(@andy)
     90:     cv2.reload
     91:     assert_equal 2, cv2.version
     92:     assert page.html.include?('####')
     93:     # 4
     94:     co = Checkout.new(:user => @andy, :page => page, :site => @oup_wiki, :source_version => cv1)
     95:     assert co.save
     96:     cv3 = co.version
     97:     h = cv3.html
     98:     assert_not_nil h
     99:     assert !h.include?('####')
    100:     co.checkin(@andy)
    101:     cv3.reload
    102:     assert_equal 3, cv3.version
    103:     assert_equal cv3, page.current_version
    104:     assert !page.html.include?('####')
    105:     # 5
    106:     assert_equal page.current_version, page.last_version # because there is no checkout
    107:     page.current_version = cv1
    108:     assert_equal cv1, page.current_version
    109:     page.current_version = cv2
    110:     assert_equal cv2, page.current_version
    111:     cv2.current = false
    112:     assert cv2.save
    113:     assert cv2 != page.current_version
    114:     assert_equal cv3, page.current_version
    115:     # 6
    116:     page.current_version = cv1 # we make cv1 current
    117:     co = Checkout.new(:user => @andy, :page => page, :site => @oup_wiki, :source_version => cv3)
    118:     assert co.save
    119:     cv4 = co.version
    120:     assert_equal cv1, page.current_version
    121:     co.checkin(@andy)
    122:     cv4.reload
    123:     assert_equal cv4, page.current_version
    124:     assert_equal cv4, page.last_version
    125:     assert page.current_version.current.nil?
    126:   end

test_xhtmldiff_diff_links()

[Source]

         # File test/unit/version_test.rb, line 128
    128:   def test_xhtmldiff_diff_links
    129:     page = WikiPage.find_by_filename('implementation,_0TeDoMlgEdmt3adZL5Dmdw.html')
    130:     # setup the page html
    131:     page_html = IO.readlines(File.expand_path("test/unit/version_test/xp_environment,3.754748120034442E-307.html", RAILS_ROOT)).join
    132:     page.html = page_html
    133:     for i in 1..3
    134:       co = Checkout.new(:user => @andy, :page => page, :site => @oup_wiki, :source_version => page.current_version)
    135:       assert co.save
    136:       assert_equal nil, co.version.version
    137:       co.checkin(@andy)
    138:       cv = page.current_version
    139:       assert_equal i, cv.version
    140:       assert_not_nil cv.page_id
    141:     end
    142:     page.reload
    143:     assert_equal 4, page.versions.size
    144:     html0 = IO.readlines(File.expand_path("test/unit/version_test/xp_environment,3.754748120034442E-307.html_EPFWIKI_BL2_v0.html", RAILS_ROOT)).join
    145:     html1 = IO.readlines(File.expand_path("test/unit/version_test/xp_environment,3.754748120034442E-307.html_EPFWIKI_BL2_v1.html", RAILS_ROOT)).join
    146:     html2 = IO.readlines(File.expand_path("test/unit/version_test/xp_environment,3.754748120034442E-307.html_EPFWIKI_BL2_v2.html", RAILS_ROOT)).join
    147:     version1 = page.versions[1]
    148:     version2 = page.versions[2]
    149:     version3 = page.versions[3]
    150:     assert_equal [1,2,3],[version1.version, version2.version, version3.version]
    151:     version1.html = html0
    152:     version2.html = html1
    153:     version3.html = html2
    154:     assert_equal 0, @emails.size
    155:     [[version2,version1],[version3,version2]].each do |versions|
    156:       versions[0].xhtmldiffpage(versions[1])
    157:       assert_equal "#{versions[0].relpath_to_diff(versions[1])} generated 0 email", "#{versions[0].relpath_to_diff(versions[1])} generated #{@emails.size} email"
    158:     end
    159:     html3 = IO.readlines(File.expand_path("test/unit/version_test/architect.html_EPFWIKI_BL1_v0.html", RAILS_ROOT)).join
    160:     html4 = IO.readlines(File.expand_path("test/unit/version_test/architect.html_EPFWIKI_BL1_v1.html", RAILS_ROOT)).join
    161:     version4 = page.versions[1]
    162:     version5 = page.versions[2]
    163:     version4.html = html3
    164:     version5.html = html4
    165:     version5.xhtmldiffpage(version4)
    166:     page = WikiPage.find_by_filename('implementation,_0TeDoMlgEdmt3adZL5Dmdw.html')
    167:     versions = []
    168:     versions << ['xp_programmer.html_EPFWIKI_BL2_v0.html', page.versions[1], '']
    169:     versions << ['xp_programmer.html_EPFWIKI_BL2_v1.html', page.versions[2], '']
    170:     versions.each do |v|
    171:       v[2] = v[1].html # save the html, so we can rollback changes
    172:       v[1].html = IO.readlines(File.expand_path("test/unit/version_test/#{v[0]}", RAILS_ROOT)).join
    173:     end
    174:     #links  = versions[0][1].diff_links(versions[1][1])  # new, removed
    175:     #assert_equal [["href=\"./../../xp/guidances/concepts/coding_standard,8.8116853923311E-307.html\""],
    176:     #["href=\"http://www.demo.epfwiki.net/wikis/openup/openup_basic/customcategories/resources/GetStarted_48.gif\""]],
    177:     #links
    178:   end

[Validate]