Class | CheckoutTest
In: | test/unit/checkout_test.rb
Parent: | Test::Unit::TestCase

Copyright (c) 2006 Logica

### Methods

setup test_notification_subscription tst01_new tst02_checkin

### Public Instance methods

setup()

[Source]

        # File test/unit/checkout_test.rb, line 20
    20:   def setup
    21:     logger.debug "Test Case: #{name}"
    22:     @oup_20060721 = create_oup_20060721
    23:     @oup_wiki = create_oup_wiki(@oup_20060721)
    24:     @andy = users(:andy)
    25:     @george = users(:george)
    26:     @tony = users(:tony)
    27:     @cash = users(:cash)
    28:   end

test_notification_subscription()

Shows that a user will start receiving notifications about page changes after checkin of a page

[Source]

         # File test/unit/checkout_test.rb, line 171
    171:   def test_notification_subscription
    172:     page = WikiPage.find(:first)
    173:     checkout = Checkout.new(:user => @andy, :page => page, :site => page.site)
    174:     assert checkout.save
    175:     assert !Notification.find_all_users(page, Page.name).include?(@andy)
    176:     checkout.checkin(@andy)
    177:     assert Notification.find_all_users(page, Page.name).include?(@andy)
    178:     checkout = Checkout.create(:user => @andy, :page => page, :site => page.site)
    179:     assert checkout.save
    180:     checkout.checkin(@andy)
    181:     assert Notification.find_all_users(page, Page.name).include?(@andy)
    182:     checkout = Checkout.create(:user => @george, :page => page, :site => page.site)
    183:     assert checkout.save
    184:     checkout.checkin(@george)
    185:     assert Notification.find_all_users(page, Page.name).include?(@george)
    186:   end

tst01_new()

Shows:

1. we cannot check out a page of a baseline process
2. we can check out a page by supplying the user, page and site
3. we cannot check out the same page twice
4. we can undo a checkout

TODO 5. we cannot checkout a page in a site that has not been wikified yet TODO 6. we can supply a note with a checkout TODO 7. checkout removes

[Source]

        # File test/unit/checkout_test.rb, line 38
    38:   def tst01_new
    39:     logger.debug('1 - we cannot check out a page of a baseline process')
    40:     assert_equal 617, @oup_20060721.pages.count
    41:     page = WikiPage.find_by_filename('requirements,_allMQMWfEdqiT9CqkRksWQ.html')
    42:     assert_not_nil page
    43:     version_count = Version.count
    44:     checkout_count = Checkout.count
    45:     html_files_count = Site.files_html(@oup_20060721.path).size
    46:     checkout = Checkout.new(:user => @andy, :page => page, :site => @oup_20060721)
    47:     assert_raise(RuntimeError) {checkout.save} # TODO test for message, how "RuntimeError: Versions can only be created in Wiki sites"
    48:     #assert_equal 'Version can\'t be blank, Site can\'t be a baseline process', checkout.errors.full_messages.join(", ")
    49:     assert_equal version_count, Version.count
    50:     assert_equal checkout_count, Checkout.count
    51:     assert_equal html_files_count, Site.files_html(@oup_20060721.path).size
    52:
    53:     logger.debug('2 - we can check out a page by supplying the user, page and site')
    54:     version_count = Version.count
    55:     checkout_count = Checkout.count
    56:     html_files_count = Site.files_html(@oup_20060721.path).size
    57:     checkout = Checkout.new(:user => @andy, :page => page, :site => @oup_wiki)
    58:     assert checkout.save
    59:     assert_equal version_count + 1, Version.count
    60:     assert_equal checkout_count + 1, Checkout.count
    61:     assert_equal @oup_wiki, checkout.site # created checkout
    62:     assert_equal page, checkout.page
    63:     assert_equal @andy, checkout.user
    64:     version = checkout.version # version created
    65:     assert_equal @andy, version.user
    66:     assert_equal @oup_wiki, version.wiki
    67:     assert_equal page, version.page
    68:     assert File.exists?(version.path)
    69:
    70:     logger.debug('3 - we cannot check out the same page twice')
    71:     checkout = Checkout.new(:user => @andy, :page => page, :site => @oup_wiki)
    72:     assert_raise(RuntimeError) {checkout.save} # Checkout already exists #TODO mixed results with this, caused by page.checkout, that doesn't seem to work
    73:     assert_errors(checkout)
    74:     assert_equal version_count + 1, Version.count # same as before, nothing changed
    75:     assert_equal checkout_count + 1, Checkout.count
    76:
    77:     logger.debug('4 - we can undo a checkout')
    78:     assert_equal 1, Checkout.count
    79:     checkout = Checkout.find(:first)
    80:     assert_kind_of Checkout,  checkout
    81:     assert File.exists?(checkout.version.path)
    82:     version_path = checkout.version.path
    83:     checkout.undo
    84:     assert_equal version_count, Version.count # undo destroys checkout + version
    85:     assert_equal checkout_count, Checkout.count
    86:     assert !File.exists?(version_path)
    87:     checkout = Checkout.new(:user => @andy, :page => page, :site => @oup_wiki, :note => 'My checkout')
    88:     assert checkout.save
    89:     assert_equal 'My checkout', checkout.version.note
    90:   end

tst02_checkin()

Shows:

1. an admin or user cannot checkin a file of another user
2. owner (who is not an admin) can checkin
3. cadmin can check in
4. html can be supplied during checkin

TODO 5. don‘t supply html which will checkin using the version file

1. the version file does not contain wiki tags
2. after checkin the page does

[Source]

         # File test/unit/checkout_test.rb, line 100
    100:   def tst02_checkin
    101:     page = WikiPage.find_by_filename('artifact,_fdRfkBUJEdqrUt4zetC1gg.html')
    102:     assert page.html.include?('body onload')
    103:     checkout = Checkout.new(:user => @tony, :page => page, :site => @oup_wiki, :note => 'Another checkout')
    104:     assert checkout.save
    105:     assert_kind_of Checkout,  checkout
    106:     assert File.exists?(checkout.version.path)
    107:     checkout.reload
    108:     checkout_id = checkout.id
    109:
    110:     logger.debug('1 - an admin or user cannot checkin a file of another user')
    111:     assert_raise(RuntimeError) {checkout.checkin(@andy)}
    112:     assert_raise(RuntimeError) {checkout.checkin(@cash)}
    113:
    114:     logger.debug('2 - owner (who is not an admin) can checkin')
    115:     checkout.checkin(@tony)
    116:     assert !Checkout.exists?(checkout_id)
    117:
    118:     logger.debug('3 - cadmin can check in')
    119:     checkout = Checkout.new(:user => @tony, :page => page, :site => @oup_wiki, :note => 'Another checkout')
    120:     assert checkout.save!
    121:     checkout_id = checkout.id
    122:     checkout.checkin(@george)
    123:     assert !Checkout.exists?(checkout_id)
    124:
    125:     logger.debug('4 - html can be supplied during checkin')
    126:     checkout = Checkout.new(:user => @tony, :page => page, :site => @oup_wiki, :note => 'Another checkout')
    127:     assert checkout.save!
    128:     version = checkout.version
    129:     checkout_id = checkout.id
    130:     html = checkout.version.html
    131:     html = html.gsub('making responsibility easy to identify','##replaced text##')
    132:     checkout.checkin(@tony, html)
    133:     assert !Checkout.exists?(checkout_id)
    134:     assert version.html.index('##replaced text##')
    135:     assert page.html.index('##replaced text##')
    136:
    137:     logger.debug('5 - don\'t supply html which will checkin using the version file')
    138:
    139:     logger.debug('6 - the version file does not contain wiki tags')
    140:     checkout = Checkout.new(:user => @tony, :page => page, :site => @oup_wiki, :note => 'Another checkout')
    141:     assert checkout.save!
    142:     version = checkout.version
    143:     html_version = version.html
    144:     html_page = version.page.html
    145:     # removed stuff in version file
    146:     assert_equal nil, html_version.index('body onload') # onload was removed
    147:     assert_equal nil, html_version.index('<!-- epfwiki head start -->') # wiki stuff removed
    148:     assert_equal nil, html_version.index('<!-- epfwiki iframe start -->')
    149:     # replaced stuff in version file
    150:     assert_not_nil html_version.index(Page.TREEBROWSER_PLACEHOLDER)
    151:     # assert_not_nil html_version.index('<!-- copyright statement -->')
    152:     # stuff to be removed from page
    153:     assert_not_nil html_page.index('body onload')
    154:     # stuff to be replace in page
    155:     assert_not_nil  html_page.index('treebrowser.js')
    156:     assert_not_nil  html_page.index('class="copyright"')
    157:
    158:     logger.debug('7 - after checkin the page does')
    159:     html_version = html_version.gsub('making responsibility easy to identify','##replaced text##')
    160:     checkout.checkin(@tony, html_version)
    161:     html_page = version.page.html
    162:     # stuff to be removed from page back in page
    163:     assert_not_nil html_page.index('##replaced text##')
    164:     assert_not_nil html_page.index('body onload')
    165:     # stuff to be replaced in page back in page
    166:     assert_not_nil  html_page.index('treebrowser.js')
    167:     assert_not_nil  html_page.index('class="copyright"')
    168:   end

[Validate]