Class | SitesControllerTest
In: | test/functional/sites_controller_test.rb
Parent: | Test::Unit::TestCase

### Methods

setup teardown test_index test_list test_new test_new_wiki test_new_wiki_job_daily test_new_wiki_post test_obsolete test_update_wiki test_wikify_now

### Public Instance methods

setup()

[Source]

        # File test/functional/sites_controller_test.rb, line 24
    24:   def setup
    25:     logger.debug "Test Case: #{name}"
    26:     @controller = SitesController.new
    27:     @request    = ActionController::TestRequest.new
    28:     @response   = ActionController::TestResponse.new
    29:     @andy, @george, @tony = users(:andy), users(:george), users(:tony) # admin, cadmin, user
    30:     @emails = ActionMailer::Base::deliveries
    31:     @emails.clear
    32:     get :list
    33:   end

teardown()

[Source]

        # File test/functional/sites_controller_test.rb, line 35
    35:   def teardown
    36:     [ENV['EPFWIKI_SITES_PATH'], ENV['EPFWIKI_WIKIS_PATH']].each do |p|
    37:       FileUtils.rm_r(p) if File.exists?(p)
    38:       File.makedirs(p)
    39:     end
    40:   end

test_index()

[Source]

        # File test/functional/sites_controller_test.rb, line 42
    42:   def test_index
    43:     get :index
    44:     assert_redirected_to :controller => 'login'
    45:     session['user'] = @tony
    46:     assert_not_nil(session['user'])
    47:   end

test_list()

[Source]

        # File test/functional/sites_controller_test.rb, line 49
    49:   def test_list
    50:     get :list
    51:     assert_redirected_to :controller => 'login'
    52:     session['user'] = @tony
    53:     get :list
    54:     assert_response :success
    55:     assert_template 'list'
    56:     assert_not_nil assigns(:baseline_processes)
    57:     assert_not_nil assigns(:wikis)
    58:   end

test_new()

Shows:

1. Need to be an admin to create a baseline process
2. Admin get link to create baseline process
3. Admin can upload baseline process

[Source]

         # File test/functional/sites_controller_test.rb, line 64
     64:   def test_new
     65:     # 1
     66:     session['user'] = @tony
     67:     get :new
     68:     assert_unot_admin_message
     69:     # 2
     70:     session['user'] = @andy
     71:     get :list
     72:     assert_response :success
     73:     assert_tag :tag => 'a', :attributes => {:href => "/sites/new"}
     74:     # 3
     75:     get :new
     76:     assert_response :success
     77:     assert assigns(:site)
     78:     assert assigns(:baseline_processes)
     79:     assert assigns(:folders)
     80:     assert assigns(:folders).empty?
     81:     assert assigns(:baseline_processes).empty?
     82:     assert_response :success
     83:     #post :upload, :site => nil TODO how to test this here
     84:     #assert_not_nil assigns(:site)
     85:     #assert_errors
     86:     #assert_equal "Folder can't be blank, File can't be blank", assigns(:site).errors.full_messages.join(", ")
     87:     assert_equal 0, Site.count
     88:     @oup_20060721 = create_oup_20060721
     89:     @oup_20060728 = create_oup_20060728
     90:     @oup_20060825 = create_oup_20060825
     91:     @oup_20060721.destroy
     92:     @oup_20060728.destroy
     93:     @oup_20060825.destroy
     94:     get :new
     95:     assert_equal ['oup_20060721', 'oup_20060728', 'oup_20060825'], assigns(:folders)
     96:     assigns(:folders).each do |folder|
     97:       assert_tag :tag => 'option', :content => folder
     98:     end
     99:     site_count = Site.count
    100:     assert session['user'].admin?
    101:     post :new, :site => {:title => 'oup_20060721', :folder => assigns(:folders)[0], :description => 'test03_new'}
    102:     assert_not_nil assigns(:baseline_processes)
    103:     assert_not_nil assigns(:folders)
    104:     site = assigns(:site)
    105:     assert_not_nil site
    106:     assert_no_errors(site)
    107:     assert site.valid?
    108:     assert_redirected_to :action => 'list'
    109:     assert_equal site_count + 1, Site.count
    110:     assert_equal ::FLASH_RECORD_CREATED, flash['success']
    111:   end

test_new_wiki()

Shows:

1. Only admins can create wikis
2. Admin can request form to create a new wiki

[Source]

         # File test/functional/sites_controller_test.rb, line 116
    116:   def test_new_wiki
    117:     @oup_20060721 = create_oup_20060721
    118:     # 1
    119:     session['user'] = @tony
    120:     get :new_wiki
    121:     assert_unot_admin_message
    122:     # 2
    123:     session['user'] = @andy
    124:     assert @andy.admin?
    125:     get :new_wiki
    126:     assert_not_nil assigns(:wiki)
    127:     assert_field 'wiki_folder'
    128:     assert_tag :tag => 'textarea', :attributes => {:id => 'wiki_description', :name => 'wiki[description]'}
    129:     assert_field 'wiki_title'
    130:   end

test_new_wiki_job_daily()

Shows

1. Admin requests creation of Wiki
2. Content is wikified using job_daily (an email is sent if the job fails)

[Source]

         # File test/functional/sites_controller_test.rb, line 181
    181:   def test_new_wiki_job_daily
    182:     # 1
    183:     get :new_wiki
    184:     session['user'] = @andy
    185:     #baseline_process = Site.find_by_title('openup0721')
    186:     #assert_not_nil baseline_process
    187:     @oup_20060721 = create_oup_20060721
    188:     post :new_wiki, :wiki => {:folder => 'openup2', :title => 'OpenUP Wiki2', :description => 'Wiki for OpenUP created in tst06_new_wiki2'}
    189:     openupwiki2 = Site.find_by_folder('openup2')
    190:     assert_not_nil openupwiki2
    191:     assert_equal 'Pending', openupwiki2.status
    192:     # 2
    193:     @emails.clear
    194:     update = Update.new(:user => @andy, :baseline_process => @oup_20060721, :wiki => openupwiki2)
    195:     assert update.save
    196:     job_daily
    197:     openupwiki2.reload
    198:     assert_equal [], Update.find_todo
    199:     assert_equal(3, @emails.size) # scheduled, started, finished
    200:     assert_equal 'Ready', openupwiki2.status
    201:   end

test_new_wiki_post()

Shows:

1. Admin can create a Wiki (note: the Wiki is empty after create)

[Source]

         # File test/functional/sites_controller_test.rb, line 134
    134:   def test_new_wiki_post
    135:     @emails.clear
    136:     # 1
    137:     get :new_wiki
    138:     session['user'] = @andy
    139:     @oup_20060721 = create_oup_20060721
    140:     post :new_wiki, :wiki => {:folder => 'openup', :title => 'OpenUP Wiki', :description => 'Wiki for OpenUP created in test05_new_wiki_post', :baseline_process => @oup_20060721}
    141:     assert_redirected_to :action => 'description'
    142:     assert SitesController::FLASH_WIKI_SITE_CREATED, flash['success']
    143:     wiki = assigns(:wiki)
    144:     assert_not_nil wiki
    145:     # 2
    146:   end

test_obsolete()

Shows:

1. Cannot make a Wiki obsolete with a get request
2. Ordinary users cannot make a Wiki obsolete
3. Admin users can make a Wiki obsolete

[Source]

         # File test/functional/sites_controller_test.rb, line 258
    258:   def test_obsolete
    259:     wiki = create_templates
    260:     assert wiki.obsolete_on.nil?
    261:     # 1
    262:     session['user'] = @george
    263:     get :obsolete, :id => wiki.id
    264:     assert_illegal_get
    265:     # 2
    266:     session['user'] = @tony
    267:     get :obsolete, :id => wiki.id
    268:     assert_unot_admin_message
    269:     session['user'] = @andy
    270:     post :obsolete, :id => wiki.id
    271:     wiki.reload
    272:     assert !wiki.obsolete_on.nil?
    273:     assert_equal @andy.id, wiki.obsolete_by
    274:   end

test_update_wiki()

Shows

1. Wikis can be updated from the ‘description’ page
2. Admin can schedule an update (create an update record) (ordinary user cannot)
3. Admin can cancel an update
4. Admin can do update_now

[Source]

         # File test/functional/sites_controller_test.rb, line 208
    208:   def test_update_wiki
    209:     # 1
    210:     @oup_20060721 = create_oup_20060721
    211:     @oupwiki = create_oup_wiki(@oup_20060721)
    212:     get :description, :id => @oupwiki.id
    213:     assert_redirected_to :controller => 'login'
    214:     session['user'] = @tony
    215:     get :description, :id => @oupwiki.id
    216:     BaselineProcess.find(:all).each do |bp|
    217:       assert_match "/sites/update/#{@oupwiki.id}?baseline_process_id=#{bp.id}", @response.body
    218:     end
    219:     # 2
    220:     session['user'] = @tony
    221:     post :update
    222:     assert_unot_admin_message
    223:     session['user'] =  @andy
    224:     cnt = Update.count
    225:     post :update, :id => @oupwiki.id, :baseline_process_id => @oup_20060721.id
    226:     assert_equal 1+cnt, Update.count
    227:     assert_redirected_to :action => 'description', :id => @oupwiki.id
    228:     # 3
    229:     assert_equal 1, Update.find_todo.size
    230:     update = Update.find_todo[0]
    231:     session['user'] = @tony
    232:     post :update_cancel, :id => @oupwiki.id , :update_id => update.id
    233:     assert_unot_admin_message
    234:     session['user'] = @andy
    235:     post :update_cancel, :id => @oupwiki.id , :update_id => update.id
    236:     assert_equal cnt, Update.count
    237:     assert_equal 0, Update.find_todo.size
    238:     # 4
    239:     @emails.clear
    240:     update = Update.new(:wiki => @oupwiki, :baseline_process => @oup_20060721, :user => @andy)
    241:     assert update.save
    242:     assert_equal(1, @emails.size) # scheduled
    243:     session['user'] = @tony
    244:     post :update_now, :update_id => update.id
    245:     assert_unot_admin_message
    246:     session['user'] = @andy
    247:     @emails.clear
    248:     post :update_now, :update_id => update.id
    249:     assert_equal SitesController::FLASH_WIKI_UPDATE_SUCCESS, flash['success']
    250:     assert_equal [], Update.find_todo
    251:     assert_equal(2, @emails.size) # started, created
    252:   end

test_wikify_now()

Shows

1. Ordinary users cannot do wikify now
2. Admin can wikify content directly

[Source]

         # File test/functional/sites_controller_test.rb, line 151
    151:   def test_wikify_now
    152:     @emails.clear
    153:     get 'list'
    154:     # 1.
    155:     session['user'] = @tony
    156:     @oup_20060721 = create_oup_20060721
    157:     wiki = Wiki.new(:folder => 'openup', :title => 'OpenUP Wiki', :user_id => session['user'].id)
    158:     assert wiki.save
    159:     assert_equal 'Pending', wiki.status
    160:     update = Update.new(:wiki => wiki, :baseline_process => @oup_20060721, :user => session['user'])
    161:     assert update.save
    162:     get :update_now, :update_id => update.id
    163:     assert_unot_admin_message
    164:     # 2
    165:     session['user'] = @andy
    166:     post :update_now, :update_id => update.id
    167:     assert_equal(4, @emails.size)
    168:     assert_equal ["[EPF Wiki - Test Enviroment] SCHEDULED creation new Wiki OpenUP Wiki using Baseline Process oup_20060721",
    169:  "[EPF Wiki - Test Enviroment] Autorisation Problem Detected",
    170:  "[EPF Wiki - Test Enviroment] STARTED creating New Wiki OpenUP Wiki using Baseline Process oup_20060721",
    171:  "[EPF Wiki - Test Enviroment] FINISHED creating new Wiki OpenUP Wiki using Baseline Process oup_20060721"],
    172:  [@emails[0].subject, @emails[1].subject, @emails[2].subject, @emails[3].subject]
    173:     assert_equal 'Ready', wiki.status
    174:     wiki.reload
    175:     assert_equal wiki.baseline_process, @oup_20060721
    176:   end

[Validate]