class TestActAttach
Public Instance Methods
test_attach()
click to toggle source
# File vendor/qwik/lib/qwik/act-attach.rb, line 157 def test_attach # Only member can access attach form. res = session('/test/.attach') ok_title('Members Only') t_add_user # Check directory. ok_eq('.test/data/test', @site.path.to_s) attach_path = @site.path+'.attach' ok_eq('.test/data/test/.attach', attach_path.to_s) filename = 't.txt' file = attach_path+filename file.unlink if file.exist? # See form. res = session('/test/.attach') ok_title('Attach file') ok_xp([:form, {:method=>'post', :action=>nil, :enctype=>'multipart/form-data'}, [:input, {:type=>'file', :name=>'content'}], [:br], [:input, {:value=>'attach', :type=>'submit'}]], "//div[@class='msg']/form") # Try to get a file. But there is no file yet. res = session('/test/.attach/t.txt') ok_title('No such file') d = @dir+'.attach' d.erase_all_for_test if d.exist? # Put a file. res = session('POST /test/.attach') {|req| req.query.update('content'=>t_make_content('t.txt', 't')) } ok_title('File attachment completed') # Get the file. res = session('/test/.attach/t.txt') ok_eq('text/plain', res['Content-Type']) ok_eq('t', res.body) # Put a file with same file name again. # The file is saved as another filename. res = session('POST /test/.attach') {|req| req.query.update('content'=>t_make_content('t.txt', 't2')) } ok_title('File attachment completed') # Show the list of attached files. res = session('/test/.attach') ok_title('Attach file') ok_xp([:form, {:method=>'post', :action=>nil, :enctype=>'multipart/form-data'}, [:input, {:type=>'file', :name=>'content'}], [:br], [:input, {:value=>'attach', :type=>'submit'}]], "//div[@class='msg']/form") ok_xp([:a, {:href=>'/test/.attach/1-t.txt'}, '1-t.txt'], '//ul/li/a[1]') ok_xp([:a, {:href=>'/test/.attach?c=del&f=1-t.txt'}, 'Delete'], '//ul/li/a[2]') ok_xp([:a, {:href=>'/test/.attach/t.txt'}, 't.txt'], '//ul/li[2]/a[1]') ok_xp([:a, {:href=>'/test/.attach?c=del&f=t.txt'}, 'Delete'], '//ul/li[2]/a[2]') # Show a form to delete the file. res = session('/test/.attach?c=del&f=t.txt') ok_title('Confirm file deletion') # Delete it. res = session('POST /test/.attach?c=del&f=t.txt') ok_title('The file has been deleted.') # Try to delete it again. But the file is already deleted. res = session('POST /test/.attach?c=del&f=t.txt') ok_title('Already deleted.') # Try to get file agin. But the file is already deleted. res = session('/test/.attach/t.txt') ok_title('No such file') end
test_attach_to_page()
click to toggle source
# File vendor/qwik/lib/qwik/act-attach.rb, line 287 def test_attach_to_page t_add_user page = @site.create_new page.store('t') # See form. res = session('/test/1.attach') ok_title('Attach file') ok_xp([:form, {:method=>'post', :action=>nil, :enctype=>'multipart/form-data'}, [:input, {:type=>'file', :name=>'content'}], [:br], [:input, {:value=>'attach', :type=>'submit'}]], "//div[@class='msg']/form") end
test_attach_with_dir()
click to toggle source
# File vendor/qwik/lib/qwik/act-attach.rb, line 267 def test_attach_with_dir t_add_user d = @dir+'.attach' d.erase_all_for_test if d.exist? # Try to get a file. res = session('/test/.attach/.thumb/t.jpg') ok_title('No such file') thumb_dir = d+'.thumb' thumb_dir.check_directory thumb = thumb_dir+'t.jpg' thumb.put('dummy') res = session('/test/.attach/.thumb/t.jpg') ok_eq('dummy', res.body) ok_eq('image/jpeg', @res['Content-Type']) end
test_attach_with_rewrite()
click to toggle source
# File vendor/qwik/lib/qwik/act-attach.rb, line 241 def test_attach_with_rewrite t_add_user file = @site.attach.path('t.txt') file.unlink if file.exist? # See the page. ok_wi([], '{{ref}}') page = @site['1'] ok_eq('{{ref}}', page.load) # Put a file. res = session('POST /test/1.attach') {|req| req.query.update('content'=>t_make_content('t.txt', 't')) } ok_title('File attachment completed') ok_eq('{{ref(t.txt)}}', page.load) res = session('/test/1.html') ok_xp([:div, {:class=>"section"}, [[:div, {:class=>'ref'}, [:a, {:href=>'.attach/t.txt'}, 't.txt']]]], "//div[@class='section']") end