Skip to content

Commit

Permalink
Finish up the functional tests
Browse files Browse the repository at this point in the history
Tweak up install/uninstall

Add some notes to the README and config
  • Loading branch information
UnderpantsGnome committed Jan 10, 2007
1 parent e2c464f commit 7f57a20
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 116 deletions.
17 changes: 15 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Q: What is it?
A: A Rails like way to use the FCKeditor in a Rails app, it basically works
just like the normal helpers.

It supports the "default" upload interface, I've though about mcpuk support
It supports the "default" upload interface, I've thought about mcpuk support
but since I'm not even using this in any projects currently I don't have the
need or the time to implement all that mcpuk does. Maybe one of these days.

Expand Down Expand Up @@ -38,6 +38,13 @@ Basic install:
engines
fckeditor_on_rails

By default it attempts to copy a functional test into your project, if you
don't want it running the tests just remove
test/functional/fckeditor_controller_test.rb

Uninstall:
./script/plugin uninstall fckeditor_on_rails
This will also remove the installed functional test

Contact:
Michael Moen
Expand All @@ -47,9 +54,15 @@ Contact:

History:
2007-01-05 (0.1.0)
Clean up that ugly code a bit
Clean up that ugly code a bit, Ok it was almost a rewrite, it was ugly
Make it plugin ready for Rails 1.2
Move the config to YAML
Clean up and add some tests

2005-09-11 (0.0.1) - Initial

Thanks goes out to the following for patches:
Gregg Kellogg
Markus Kristo
Scott Carson
Gabriel Birke
25 changes: 10 additions & 15 deletions app/controllers/fckeditor_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class FckeditorController < ApplicationController
layout false

def index
render(:nothing => true) unless RAILS_ENV == 'development'
render :nothing => true unless RAILS_ENV == 'development'
end

def connector
Expand Down Expand Up @@ -41,14 +41,13 @@ def get_folders_and_files
end
end

render 'fckeditor/files_and_folders'
render :template => 'fckeditor/files_and_folders'
end

# create a new directory
def create_folder
begin
new_dir = @options[:dir] + params[:NewFolderName]
Dir.mkdir(new_dir)
Dir.mkdir(File.join(@options[:dir], params[:NewFolderName]))
rescue Errno::EEXIST
# directory already exists
@error = 101
Expand All @@ -59,7 +58,7 @@ def create_folder
# any other error
@error = 110
end
render 'fckeditor/create_folder'
render :template => 'fckeditor/create_folder'
end

# upload a new file
Expand All @@ -68,9 +67,8 @@ def create_folder
# not sure how to catch invalid file name yet
# I'm thinking there should be a permission denied error as well
def upload_file
counter = 1
counter = 1
@file_name = params[:NewFile].original_filename

# break it up into file and extension
# we need this to check the types and to build new names if necessary
ext = File.extname(@file_name)
Expand All @@ -93,7 +91,7 @@ def upload_file
@error = 202
end

render 'fckeditor/upload_file'
render :template => 'fckeditor/upload_file'
end

def type_allowed(filetype, ext)
Expand All @@ -105,18 +103,15 @@ def type_allowed(filetype, ext)

def get_options
@error = 0
@options = {
:base_dir => File.join('public', Fckeditor.config[:uploads] || 'UserFiles')
}
@options[:url] = "/#{@options[:base_dir]}/#{params[:Type]}/#{params[:CurrentFolder]}".gsub(/\/+/, '/')
@options[:dir] = File.join(RAILS_ROOT, @options[:url])
@options = {}
@options[:url] = "/#{Fckeditor.config[:upload_dir]}/#{params[:Type]}/#{params[:CurrentFolder]}".gsub(/\/+/, '/')
@options[:dir] = File.join('public', @options[:url])
end

def sanitize_directory
if params[:CurrentFolder]
clean = File.expand_path(@options[:base_dir])
clean = File.expand_path(File.join(RAILS_ROOT, 'public', Fckeditor.config[:upload_dir]))
dirty = File.expand_path(@options[:dir])

unless dirty.starts_with?(clean)
render :nothing => true, :status => 403
false
Expand Down
14 changes: 11 additions & 3 deletions config/fckeditor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
# this path starts at public/ so your settings should account for that
:upload_dir: '/UserFiles/'

# the starting point for uploaded files URLs
:url_base: '/'

# toolbar for fckeditor to use, can be overridden on the fly
:toolbar_set: 'Default'

# this controls what files are allowed to be uploaded for different Types
# if there is only a deny anything other than those listed will be allowed
# if there is only an allow only those listed would be allowed
# if neither exist anything can be uploaded, not a good idea
# the settings here are just a starting point, pay special attention to
# file deny and add anything you don't want anybody to be able to upload
:file_types:
Expand Down Expand Up @@ -62,7 +66,11 @@
- '.mpg'
- '.mpeg'

:development:
:development:

:test:
:upload_dir: '../test/UserFiles'
# just like the test DB, do not let this point to the same place as your
# default location, as the tests will rm_rf this dir, leaving this is fine
# if you don't want it running the tests you can remove
# test/functional/fckeditor_controller_test.rb
:test:
:upload_dir: '../vendor/plugins/fckeditor_on_rails/test/UserFiles/'
18 changes: 11 additions & 7 deletions install.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
require 'fileutils'

FileUtils.ln_s(
File.join(File.dirname(__FILE__), 'test', 'fckeditor_controller_test.rb'),
File.join(File.dirname(__FILE__), '..', '..', 'test', 'functional',
'fckeditor_controller_test.rb')
dest_file = File.join(File.dirname(__FILE__), '..', '..', '..', 'test',
'functional', 'fckeditor_controller_test.rb')

FileUtils.rm(dest_file) rescue nil

FileUtils.cp(
File.join(File.dirname(__FILE__), 'test', 'functional', 'fckeditor_controller_test.rb'),
dest_file
) rescue puts <<-EOM
Unable to link the functional test, if you want to include fckeditor_on_rails
in your testing copy test/functional/fckeditor_controller_test.rb from the
plugin directory into your app
Unable to copy the functional test, if you want to include fckeditor_on_rails
in your testing copy #{File.dirname(__FILE__)}/test/functional/fckeditor_controller_test.rb
from the plugin directory into test/functional/
EOM
1 change: 1 addition & 0 deletions test/files/bad_file.exe
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is just a text file to test upload blocking
Loading

0 comments on commit 7f57a20

Please sign in to comment.