Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 344
- Log:
Massive changeset which brings the old, ROOL customised Instiki
version up to date, but without any ROOL customisations in this
latest checked-in version (which is 0.19.1). This is deliberate,
so that it's easy to see the changes made for the ROOL version
in a subsequent changeset. The 'app/views/shared' directory is not
part of Instiki but is kept to maintain the change history with
updated ROOL customisations, some of which involve the same files
in that same directory.
- Author:
- rool
- Date:
- Sat Mar 19 19:52:13 +0000 2011
- Size:
- 3152 Bytes
1 | require File.expand_path(File.dirname(__FILE__) + '/../test_helper') |
2 | require 'fileutils' |
3 | |
4 | class WikiFileTest < ActiveSupport::TestCase |
5 | include FileUtils |
6 | fixtures :webs, :pages, :revisions, :system, :wiki_references |
7 | |
8 | def setup |
9 | @web = webs(:test_wiki) |
10 | mkdir_p("#{RAILS_ROOT}/webs/wiki1/files/") |
11 | rm_rf("#{RAILS_ROOT}/webs/wiki1/files/*") |
12 | WikiFile.delete_all |
13 | end |
14 | |
15 | def test_basic_store_and_retrieve_ascii_file |
16 | @web.wiki_files.create(:file_name => 'binary_file', :description => 'Binary file', :content => "\001\002\003") |
17 | binary = WikiFile.find_by_file_name('binary_file') |
18 | assert_equal "\001\002\003", binary.content |
19 | end |
20 | |
21 | def test_basic_store_and_retrieve_binary_file |
22 | @web.wiki_files.create(:file_name => 'text_file', :description => 'Text file', :content => "abc") |
23 | text = WikiFile.find_by_file_name('text_file') |
24 | assert_equal "abc", text.content |
25 | end |
26 | |
27 | def test_storing_an_image |
28 | rails_gif = File.open("#{RAILS_ROOT}/test/fixtures/rails.gif", 'rb') { |f| f.read } |
29 | assert_equal rails_gif.size, File.size("#{RAILS_ROOT}/test/fixtures/rails.gif") |
30 | |
31 | @web.wiki_files.create(:file_name => 'rails.gif', :description => 'Rails logo', :content => rails_gif) |
32 | |
33 | rails_gif_from_db = WikiFile.find_by_file_name('rails.gif') |
34 | assert_equal rails_gif.size, rails_gif_from_db.content.size |
35 | assert_equal rails_gif, rails_gif_from_db.content |
36 | end |
37 | |
38 | def test_mandatory_fields_validations |
39 | assert_validation(:file_name, '', :fail) |
40 | assert_validation(:file_name, nil, :fail) |
41 | assert_validation(:content, '', :fail) |
42 | assert_validation(:content, nil, :fail) |
43 | end |
44 | |
45 | def test_upload_size_validation |
46 | assert_validation(:content, 'a' * 100.kilobytes, :pass) |
47 | assert_validation(:content, 'a' * (100.kilobytes + 1), :fail) |
48 | end |
49 | |
50 | def test_file_name_size_validation |
51 | assert_validation(:file_name, '', :fail) |
52 | assert_validation(:file_name, 'a', :pass) |
53 | assert_validation(:file_name, 'a' * 50, :pass) |
54 | assert_validation(:file_name, 'a' * 51, :fail) |
55 | end |
56 | |
57 | def test_file_name_pattern_validation |
58 | assert_validation(:file_name, ".. Accep-table File.name", :pass) |
59 | assert_validation(:file_name, "/bad", :fail) |
60 | assert_validation(:file_name, "~bad", :fail) |
61 | assert_validation(:file_name, "..\bad", :fail) |
62 | assert_validation(:file_name, "\001bad", :fail) |
63 | assert_validation(:file_name, ".", :fail) |
64 | assert_validation(:file_name, "..", :fail) |
65 | end |
66 | |
67 | def test_find_by_file_name |
68 | assert_equal @file1, WikiFile.find_by_file_name('file1.txt') |
69 | assert_nil WikiFile.find_by_file_name('unknown_file') |
70 | end |
71 | |
72 | def assert_validation(field, value, expected_result) |
73 | values = {:file_name => '0', :description => '0', :content => '0'} |
74 | raise "WikiFile has no attribute named #{field.inspect}" unless values.has_key?(field) |
75 | values[field] = value |
76 | |
77 | new_object = @web.wiki_files.create(values) |
78 | if expected_result == :pass then assert(new_object.valid?, new_object.errors.inspect) |
79 | elsif expected_result == :fail then assert(!new_object.valid?) |
80 | else raise "Unknown value of expected_result: #{expected_result.inspect}" |
81 | end |
82 | end |
83 | |
84 | end |