Skip to content

Commit

Permalink
Merge branch 'bzr/golem' of /Users/distler/Sites/code/instiki
Browse files Browse the repository at this point in the history
  • Loading branch information
distler committed Dec 27, 2009
2 parents 47439e9 + 601331b commit dce19f6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
16 changes: 15 additions & 1 deletion app/models/wiki.rb
Expand Up @@ -27,14 +27,28 @@ def edit_web(old_address, new_address, name, markup, color, additional_style, sa
if not (web = Web.find_by_address(old_address))
raise Instiki::ValidationError.new("Web with address '#{old_address}' does not exist")
end

old_files_path = web.files_path

web.update_attributes(:address => new_address, :name => name, :markup => markup, :color => color,
:additional_style => additional_style, :safe_mode => safe_mode, :password => password, :published => published,
:brackets_only => brackets_only, :count_pages => count_pages, :allow_uploads => allow_uploads, :max_upload_size => max_upload_size)
@webs = nil
raise Instiki::ValidationError.new("There is already a web with address '#{new_address}'") unless web.errors.on(:address).nil?
web
move_files(old_files_path, web.files_path)
end

def move_files(old_path, new_path)
return if new_path == old_path
default_path = Rails.root.join("webs", "files")
FileUtils.rmdir(new_path)
if [old_path, new_path].include? default_path
File.rename(old_path, new_path)
FileUtils.rmdir(old_path.parent) unless old_path == default_path
else
File.rename(old_path.parent, new_path.parent)
end
end

def read_page(web_address, page_name)
ApplicationController.logger.debug "Reading page '#{page_name}' from web '#{web_address}'"
Expand Down
5 changes: 3 additions & 2 deletions app/views/admin/edit_web.rhtml
Expand Up @@ -71,7 +71,8 @@
Stylesheet tweaks &gt;&gt;</a>
<em>
- add or change styles used by this web; styles defined here take precedence over
instiki.css. Hint: View HTML source of a page you want to style to find ID names on individual
instiki.css.<br/>
Hint: View HTML source of a page you want to style to find ID names on individual
tags.</em>
<br/>
<textarea id="additionalStyle" class="disableAutoComplete" cols="50" rows="20"
Expand All @@ -96,7 +97,7 @@
<div class="help">
You can turn on a read-only version of this web that's accessible even when the regular web
is password protected.
The published version is accessible through URLs like /wiki/published/HomePage.
The published version is accessible through URLs like /<%= @web.address %>/published/HomePage.
</div>
<div class="inputBox">
<input type="checkbox" id="published" name="published" class="disableAutoComplete" <%= 'checked="checked"' if @web.published? %> />
Expand Down
14 changes: 12 additions & 2 deletions test/functional/admin_controller_test.rb
Expand Up @@ -25,6 +25,7 @@ class << @request.session
@elephant = pages(:elephant)
@web = webs(:test_wiki)
@home = @page = pages(:home_page)
FileUtils.rm_rf("#{RAILS_ROOT}/webs/renamed_wiki1")
end

def test_create_system_form_displayed
Expand Down Expand Up @@ -116,7 +117,8 @@ def test_edit_web_no_form

def test_edit_web_form_submitted
@wiki.system.update_attribute(:password, 'pswd')

@web.save

process('edit_web', 'system_password' => 'pswd',
'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1',
'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever',
Expand All @@ -137,11 +139,14 @@ def test_edit_web_form_submitted
assert @web.count_pages?
assert @web.allow_uploads?
assert_equal 300, @web.max_upload_size
assert File.directory? Rails.root.join("webs", "renamed_wiki1", "files")
assert !File.exist?(Rails.root.join("webs", "wiki1"))
end

def test_edit_web_web_password_mismatch
@wiki.system.update_attribute(:password, 'pswd')

@web.save

process('edit_web', 'system_password' => 'pswd',
'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1',
'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever',
Expand All @@ -151,10 +156,13 @@ def test_edit_web_web_password_mismatch

assert_response :success
assert @response.has_template_object?('error')
assert File.directory? Rails.root.join("webs", "wiki1", "files")
assert !File.exist?(Rails.root.join("webs", "renamed_wiki1"))
end

def test_edit_web_opposite_values
@wiki.system.update_attribute(:password, 'pswd')
@web.save

process('edit_web', 'system_password' => 'pswd',
'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1',
Expand All @@ -170,6 +178,8 @@ def test_edit_web_opposite_values
assert !@web.brackets_only?
assert !@web.count_pages?
assert !@web.allow_uploads?
assert File.directory? Rails.root.join("webs", "renamed_wiki1", "files")
assert !File.exist?(Rails.root.join("webs", "wiki1"))
end

def test_edit_web_wrong_password
Expand Down
2 changes: 1 addition & 1 deletion test/functional/file_controller_test.rb
Expand Up @@ -24,7 +24,7 @@ class << @request.session
@wiki = Wiki.new
WikiFile.delete_all
require 'fileutils'
FileUtils.rm_rf("#{RAILS_ROOT}/webs/wiki1/files")
FileUtils.rm_rf("#{RAILS_ROOT}/webs/wiki1")
end

def test_file_upload_form
Expand Down

0 comments on commit dce19f6

Please sign in to comment.