public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
catch bad theme errors

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2299 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Sat Sep 30 18:38:05 -0700 2006
commit  9a57b2f81680201a6b586591841361a3adc541a2
tree    4823fb2c19b6c0280e0374c73e576e9d4f7a76aa
parent  95e32c73a846455f29e9216cd90c9a874de73d7e
...
36
37
38
39
 
40
41
42
...
49
50
51
 
 
52
53
54
...
36
37
38
 
39
40
41
42
...
49
50
51
52
53
54
55
56
0
@@ -36,7 +36,7 @@ class Admin::ThemesController < Admin::BaseController
0
   def import
0
     return unless request.post?
0
     unless params[:theme] && params[:theme].size > 0 && theme_content_types.include?(params[:theme].content_type.strip)
0
- flash.now[:error] = "Invalid theme upload."
0
+ flash.now[:error] = "Invalid theme uploaded."
0
       return
0
     end
0
     filename = params[:theme].original_filename
0
@@ -49,6 +49,8 @@ class Admin::ThemesController < Admin::BaseController
0
       site.import_theme zip_file, filename
0
       flash[:notice] = "The '#{filename}' theme has been imported."
0
       redirect_to :action => 'index'
0
+ rescue
0
+ flash.now[:error] = "Invalid theme uploaded: [#{$!.class.name}] #{$!}"
0
     ensure
0
       theme_site_path.rmtree
0
     end
...
38
39
40
 
 
 
41
42
43
...
38
39
40
41
42
43
44
45
46
0
@@ -38,6 +38,9 @@ class Theme
0
       end
0
     end
0
     dest.basename.to_s
0
+ rescue
0
+ dest.rmtree if dest.exist?
0
+ raise ThemeError.new(dest, $!.message)
0
   end
0
 
0
   def initialize(base)
...
129
130
131
 
 
 
 
 
 
 
 
132
133
...
129
130
131
132
133
134
135
136
137
138
139
140
141
0
@@ -129,4 +129,12 @@ class MissingTemplateError < StandardError
0
     @templates = templates
0
     super "No template found for #{template_type}, checked #{templates.to_sentence}."
0
   end
0
+end
0
+
0
+class ThemeError < StandardError
0
+ attr_reader :theme
0
+ def initialize(theme, message)
0
+ @theme = theme
0
+ super message
0
+ end
0
 end
0
\ No newline at end of file
...
57
58
59
60
 
61
62
63
...
57
58
59
 
60
61
62
63
0
@@ -57,7 +57,7 @@ Fixtures.class_eval do
0
   end
0
 end
0
 
0
-THEME_ROOT = File.join(RAILS_ROOT, 'tmp/themes') unless Object.const_defined?(:THEME_ROOT)
0
+THEME_ROOT = RAILS_PATH + 'tmp/themes' unless Object.const_defined?(:THEME_ROOT)
0
 THEME_FILES = [
0
   'about.yml',
0
   'preview.png',
...
1
2
3
 
4
5
6
...
8
9
10
11
 
12
13
14
15
 
16
17
18
19
 
20
21
22
...
24
25
26
27
 
28
29
30
...
35
36
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
...
1
2
 
3
4
5
6
...
8
9
10
 
11
12
13
14
 
15
16
17
18
 
19
20
21
22
...
24
25
26
 
27
28
29
30
...
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
0
@@ -1,6 +1,6 @@
0
 require File.dirname(__FILE__) + '/../test_helper'
0
 
0
-class ThemeTest < Test::Unit::TestCase
0
+context "Theme" do
0
   fixtures :sites
0
 
0
   def setup
0
@@ -8,15 +8,15 @@ class ThemeTest < Test::Unit::TestCase
0
     @theme = sites(:first).theme
0
   end
0
 
0
- def test_should_find_preview
0
+ specify "should find preview" do
0
     assert @theme.preview.exist?
0
   end
0
 
0
- def test_should_respond_to_to_param_for_routes
0
+ specify "should respond to to_param for routes" do
0
     assert_equal 'current', @theme.to_param
0
   end
0
 
0
- def test_should_export_files
0
+ specify "should export files" do
0
     @theme.export 'foo', :to => THEME_ROOT
0
     
0
     THEME_FILES.each do |path|
0
@@ -24,7 +24,7 @@ class ThemeTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
- def test_should_export_files_as_zip
0
+ specify "should export files as zip" do
0
     @theme.export_as_zip 'foo', :to => THEME_ROOT
0
     
0
     assert File.exists?(File.join(THEME_ROOT, 'foo.zip'))
0
@@ -35,4 +35,21 @@ class ThemeTest < Test::Unit::TestCase
0
       end
0
     end
0
   end
0
+
0
+ specify "should import files" do
0
+ dest = THEME_ROOT + 'site-1/other/hemingway'
0
+ Theme.import THEME_ROOT + 'site-1/hemingway.zip', :to => dest
0
+ assert dest.exist?
0
+ THEME_FILES.each do |file|
0
+ assert((dest + file).exist?, "#{file} does not exist")
0
+ end
0
+ end
0
+
0
+ specify "should not import bad theme" do
0
+ dest = THEME_ROOT + 'site-1/other/hemingway'
0
+ assert_raise ThemeError do
0
+ Theme.import THEME_ROOT + 'site-1/bad-hemingway.zip', :to => dest
0
+ end
0
+ assert !dest.exist?
0
+ end
0
 end

Comments

    No one has commented yet.