Commit 91398d8a15ab6e0d30d539ade51aaa9b197d3eeb
1 parent
9a139d20
Exists in
master
and in
29 other branches
r267@sede: terceiro | 2007-07-29 23:41:06 -0300
ActionItem0: several stuff; working on design editor git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@271 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
14 changed files
with
295 additions
and
148 deletions
Show diff stats
vendor/plugins/design/lib/acts_as_design.rb
... | ... | @@ -25,6 +25,13 @@ class ActiveRecord::Base |
25 | 25 | serialize :design_data |
26 | 26 | attr_protected :design_data |
27 | 27 | |
28 | + after_create do |design| | |
29 | + template = Design::Template.find(design.template) | |
30 | + while design.boxes.size < template.number_of_boxes | |
31 | + design.boxes << Design::Box.new(:name => 'Block') | |
32 | + end | |
33 | + end | |
34 | + | |
28 | 35 | def design_data |
29 | 36 | self[:design_data] ||= Hash.new |
30 | 37 | end | ... | ... |
vendor/plugins/design/lib/design.rb
1 | 1 | require 'design/controller_methods' |
2 | 2 | |
3 | 3 | require 'design/fixed_design_holder' |
4 | -require 'design/proxy_design_holder' | |
4 | +require 'design/template' | |
5 | 5 | |
6 | 6 | require 'design/helper' |
7 | 7 | require 'design/editor' |
... | ... | @@ -22,7 +22,7 @@ module Design |
22 | 22 | |
23 | 23 | if config.has_key?(:holder) |
24 | 24 | holder_variable_name = config[:holder] |
25 | - data[:design] = Design::ProxyDesignHolder.new(self.instance_variable_get("@#{holder_variable_name}")) | |
25 | + data[:design] = self.instance_variable_get("@#{holder_variable_name}") | |
26 | 26 | else |
27 | 27 | options = (config[:fixed].kind_of? Hash) ? config[:fixed] : {} |
28 | 28 | data[:design] = Design::FixedDesignHolder.new(options) | ... | ... |
vendor/plugins/design/lib/design/editor.rb
... | ... | @@ -6,27 +6,52 @@ module Design |
6 | 6 | # from flexible_template |
7 | 7 | module Editor |
8 | 8 | |
9 | - def designer | |
10 | - end | |
11 | - | |
12 | - def flexible_template_edit_template? | |
13 | - @ft_config[:edit_mode] | |
9 | + def design_editor | |
10 | + | |
11 | + if request.post? | |
12 | + design_editor_set_template | |
13 | + design_editor_set_theme | |
14 | + design_editor_set_icon_theme | |
15 | + | |
16 | + if self.class.design_plugin_config[:autosave] && design.respond_to?(:save) | |
17 | + design.save | |
18 | + end | |
19 | + | |
20 | + if request.xhr? | |
21 | + render :text => 'ok' | |
22 | + else | |
23 | + redirect_to :action => 'design_editor' | |
24 | + end | |
25 | + | |
26 | + else | |
27 | + render :action => 'design_editor' | |
28 | + end | |
14 | 29 | end |
15 | - | |
16 | - # Set the default template to the profile | |
17 | - def set_default_template | |
18 | - set_template(design,params[:template_name]) if exist_template? params[:template_name] | |
30 | + | |
31 | + private | |
32 | + | |
33 | + # Set to the owner the template choosed | |
34 | + def design_editor_set_template | |
35 | + if exists_template?(params[:template]) | |
36 | + design.template = params[:template] | |
37 | + end | |
19 | 38 | end |
20 | - | |
21 | - # Set the default theme to the profile | |
22 | - def set_default_theme | |
23 | - set_theme(design,params[:theme_name]) if exist_theme? params[:theme_name] | |
39 | + | |
40 | + # Set to the owner the theme choosed | |
41 | + def design_editor_set_theme | |
42 | + if exists_theme?(params[:theme]) | |
43 | + design.theme = params[:theme] | |
44 | + end | |
24 | 45 | end |
25 | - | |
26 | - # Set the default icons theme to the profile | |
27 | - def set_default_icon_theme | |
28 | - set_icon_theme(design,params[:icon_theme_name]) if exist_icon_theme? params[:icon_theme_name] | |
46 | + | |
47 | + # Set to the owner the icon_theme choosed | |
48 | + def design_editor_set_icon_theme | |
49 | + if request.post? && exists_icon_theme?(params[:icon_theme]) | |
50 | + design.icon_theme = params[:icon_theme] | |
51 | + end | |
29 | 52 | end |
53 | + | |
54 | + # TODO: see below here | |
30 | 55 | |
31 | 56 | def flexible_template_set_sort_mode |
32 | 57 | box = design.boxes.find(params[:box_id]) |
... | ... | @@ -97,23 +122,6 @@ module Design |
97 | 122 | |
98 | 123 | private |
99 | 124 | |
100 | - # Set to the owner the theme choosed | |
101 | - def set_theme(object, theme_name) | |
102 | - object.flexible_template_theme = theme_name | |
103 | - object.save | |
104 | - end | |
105 | - | |
106 | - # Set to the owner the icons theme choosed | |
107 | - def set_icon_theme(object,icon_theme_name) | |
108 | - object.flexible_template_icon_theme = icon_theme_name | |
109 | - object.save | |
110 | - end | |
111 | - | |
112 | - # Set to the owner the template choosed | |
113 | - def set_template(object, template_name) | |
114 | - object.flexible_template_template = template_name | |
115 | - object.save | |
116 | - end | |
117 | 125 | |
118 | 126 | #Load a set of boxes belongs to a owner. We have to situations. |
119 | 127 | # 1 - The owner has equal or more boxes that boxes defined in template. |
... | ... | @@ -154,16 +162,16 @@ module Design |
154 | 162 | number_of_boxes |
155 | 163 | end |
156 | 164 | |
157 | - def exist_template? template | |
158 | - @ft_config[:available_templates].include?(template) | |
165 | + def exists_template?(template) | |
166 | + Design.available_templates.include?(template) | |
159 | 167 | end |
160 | 168 | |
161 | - def exist_theme? theme | |
162 | - @ft_config[:available_themes].include?(theme) | |
169 | + def exists_theme?(theme) | |
170 | + Design.available_themes.include?(theme) | |
163 | 171 | end |
164 | 172 | |
165 | - def exist_icon_theme? icon_theme | |
166 | - @ft_config[:available_icon_themes].include?(icon_theme) | |
173 | + def exists_icon_theme?(icon_theme) | |
174 | + Design.available_icon_themes.include?(icon_theme) | |
167 | 175 | end |
168 | 176 | |
169 | 177 | def parse_path(files_path = [], remove_until = 'public') | ... | ... |
vendor/plugins/design/lib/design/editor/helper.rb
... | ... | @@ -9,9 +9,7 @@ module Design |
9 | 9 | module Helper |
10 | 10 | |
11 | 11 | # draws the user interface for the design editor. |
12 | - def design_display_editor() | |
13 | - # TODO: check this | |
14 | - raise NotImplementedError | |
12 | + def design_display_editor(content) | |
15 | 13 | |
16 | 14 | content = [content_tag( |
17 | 15 | :ul,[ |
... | ... | @@ -33,8 +31,8 @@ module Design |
33 | 31 | ].join("\n"), |
34 | 32 | :class => 'select_options' |
35 | 33 | ), |
36 | - @ft_config[:boxes].map{ |box| | |
37 | - content_tag(:div, edit_blocks(box, main_content) , :id=>"box_#{box.number}") | |
34 | + design.boxes.map { |box| | |
35 | + content_tag(:div, edit_blocks(box, content) , :id=>"box_#{box.number}") | |
38 | 36 | }].join("\n") |
39 | 37 | |
40 | 38 | content = content_tag(:div, content, :id => 'flexible_template_edit_mode') |
... | ... | @@ -57,6 +55,7 @@ module Design |
57 | 55 | # end |
58 | 56 | |
59 | 57 | |
58 | + # FIXME: WTF? | |
60 | 59 | def flexible_template_block_helper_dict(str) |
61 | 60 | { |
62 | 61 | 'plain_content' => _('Plain Content') , |
... | ... | @@ -67,6 +66,70 @@ module Design |
67 | 66 | |
68 | 67 | private |
69 | 68 | |
69 | + ######################################## | |
70 | + # TEMPLATE/THEME/ICON THEME CHANGE BOXES | |
71 | + ######################################## | |
72 | + | |
73 | + # Generate a select option to choose one of the available templates. | |
74 | + # The available templates are those in 'public/templates' | |
75 | + def select_template | |
76 | + available_templates = Design.available_templates | |
77 | + | |
78 | + template_options = options_for_select(available_templates.map{|template| [template, template] }, design.template) | |
79 | + [ select_tag('template', template_options ), | |
80 | + change_template].join("\n") | |
81 | + end | |
82 | + | |
83 | + # Generate a observer to reload a page when a template is selected | |
84 | + def change_template | |
85 | + observe_field( 'template', | |
86 | + :url => {:action => 'design_editor'}, | |
87 | + :with =>"'template=' + escape(value)", | |
88 | + :complete => "document.location.reload();", | |
89 | + :method => :post | |
90 | + ) | |
91 | + end | |
92 | + | |
93 | + # Generate a select option to choose one of the available themes. | |
94 | + # The available themes are those in 'public/themes' | |
95 | + def select_theme | |
96 | + available_themes = Design.available_themes | |
97 | + theme_options = options_for_select(available_themes.map{|theme| [theme, theme] }, design.theme) | |
98 | + [ select_tag('theme', theme_options ), | |
99 | + change_theme].join("\n") | |
100 | + end | |
101 | + | |
102 | + # Generate a observer to reload a page when a theme is selected | |
103 | + def change_theme | |
104 | + observe_field( 'theme', | |
105 | + :url => {:action => 'design_editor'}, | |
106 | + :with =>"'theme=' + escape(value)", | |
107 | + :complete => "document.location.reload();", | |
108 | + :method => :post | |
109 | + ) | |
110 | + end | |
111 | + | |
112 | + # Generate a select option to choose one of the available icons themes. | |
113 | + # The available icons themes are those in 'public/icons' | |
114 | + def select_icon_theme | |
115 | + available_icon_themes = Design.available_icon_themes | |
116 | + icon_theme_options = options_for_select(available_icon_themes.map{|icon_theme| [icon_theme, icon_theme] }, design.icon_theme ) | |
117 | + [ select_tag('icon_theme', icon_theme_options ), | |
118 | + change_icon_theme].join("\n") | |
119 | + end | |
120 | + | |
121 | + # Generate a observer to reload a page when a icons theme is selected | |
122 | + def change_icon_theme | |
123 | + observe_field( 'icon_theme', | |
124 | + :url => {:action => 'design_editor'}, | |
125 | + :with =>"'icon_theme=' + escape(value)", | |
126 | + :complete => "document.location.reload();", | |
127 | + :method => :post | |
128 | + ) | |
129 | + end | |
130 | + | |
131 | + | |
132 | + | |
70 | 133 | ################################################# |
71 | 134 | # TEMPLATES METHODS RELATED |
72 | 135 | ################################################# |
... | ... | @@ -126,7 +189,7 @@ module Design |
126 | 189 | |
127 | 190 | # Allows an draggable element change between diferrents boxes |
128 | 191 | def drag_drop_items(box) |
129 | - boxes = @ft_config[:boxes].reject{|b| b.id == box.id} | |
192 | + boxes = design.boxes.reject{|b| b.id == box.id} | |
130 | 193 | |
131 | 194 | boxes.map{ |b| |
132 | 195 | drop_receiving_element("box_#{box.number}", |
... | ... | @@ -140,24 +203,6 @@ module Design |
140 | 203 | end |
141 | 204 | |
142 | 205 | |
143 | - # Generate a select option to choose one of the available templates. | |
144 | - # The available templates are those in 'public/templates' | |
145 | - def select_template | |
146 | - available_templates = @ft_config[:available_templates] | |
147 | - | |
148 | - template_options = options_for_select(available_templates.map{|template| [template, template] }, @ft_config[:template]) | |
149 | - [ select_tag('template_name', template_options ), | |
150 | - change_template].join("\n") | |
151 | - end | |
152 | - | |
153 | - # Generate a observer to reload a page when a template is selected | |
154 | - def change_template | |
155 | - observe_field( 'template_name', | |
156 | - :url => {:action => 'set_default_template'}, | |
157 | - :with =>"'template_name=' + escape(value) + '&object_id=' + escape(#{@ft_config[:owner].id})", | |
158 | - :complete => "document.location.reload();" | |
159 | - ) | |
160 | - end | |
161 | 206 | |
162 | 207 | def available_blocks |
163 | 208 | #TOD O check if are valids blocks |
... | ... | @@ -230,46 +275,10 @@ module Design |
230 | 275 | |
231 | 276 | end |
232 | 277 | |
233 | - # Generate a select option to choose one of the available themes. | |
234 | - # The available themes are those in 'public/themes' | |
235 | - def select_theme | |
236 | - available_themes = @ft_config[:available_themes] | |
237 | - theme_options = options_for_select(available_themes.map{|theme| [theme, theme] }, @ft_config[:theme]) | |
238 | - [ select_tag('theme_name', theme_options ), | |
239 | - change_theme].join("\n") | |
240 | - end | |
241 | - | |
242 | - # Generate a observer to reload a page when a theme is selected | |
243 | - def change_theme | |
244 | - observe_field( 'theme_name', | |
245 | - :url => {:action => 'set_default_theme'}, | |
246 | - :with =>"'theme_name=' + escape(value) + '&object_id=' + escape(#{@ft_config[:owner].id})", | |
247 | - :complete => "document.location.reload();" | |
248 | - ) | |
249 | - end | |
250 | - | |
251 | - | |
252 | 278 | ################################################# |
253 | 279 | #ICONS THEMES RELATED |
254 | 280 | ################################################# |
255 | 281 | |
256 | - # Generate a select option to choose one of the available icons themes. | |
257 | - # The available icons themes are those in 'public/icons' | |
258 | - def select_icon_theme | |
259 | - available_icon_themes = @ft_config[:available_icon_themes] | |
260 | - icon_theme_options = options_for_select(available_icon_themes.map{|icon_theme| [icon_theme, icon_theme] }, @ft_config[:icon_theme]) | |
261 | - [ select_tag('icon_theme_name', icon_theme_options ), | |
262 | - change_icon_theme].join("\n") | |
263 | - end | |
264 | - | |
265 | - # Generate a observer to reload a page when a icons theme is selected | |
266 | - def change_icon_theme | |
267 | - observe_field( 'icon_theme_name', | |
268 | - :url => {:action => 'set_default_icon_theme'}, | |
269 | - :with =>"'icon_theme_name=' + escape(value) + '&object_id=' + escape(#{@ft_config[:owner].id})", | |
270 | - :complete => "document.location.reload();" | |
271 | - ) | |
272 | - end | |
273 | 282 | |
274 | 283 | |
275 | 284 | end # END OF module Helper | ... | ... |
vendor/plugins/design/lib/design/helper.rb
... | ... | @@ -26,10 +26,19 @@ module Design |
26 | 26 | # |
27 | 27 | # If not blocks are present (e.g. the design holder has no blocks yet), |
28 | 28 | # +content+ is returned right away. |
29 | + # | |
30 | + # If running in design_editor mode | |
29 | 31 | def design_display(content = "") |
30 | 32 | |
33 | + # dispatch to Design::Editor::Helper if running in editor mode | |
34 | + if (self.respond_to?(:design_display_editor) && params[:action] =~ /^design_editor/) | |
35 | + return design_display_editor(content) | |
36 | + end | |
37 | + | |
31 | 38 | # no blocks. nothing to be done |
32 | - return content if design.boxes.empty? | |
39 | + if design.boxes.empty? | |
40 | + return content | |
41 | + end | |
33 | 42 | |
34 | 43 | # Generate all boxes of the current profile and considering the defined |
35 | 44 | # on template. | ... | ... |
... | ... | @@ -0,0 +1,30 @@ |
1 | +module Design | |
2 | + class Template | |
3 | + | |
4 | + def initialize(name, data) | |
5 | + @data = data | |
6 | + @data['name'] = name | |
7 | + end | |
8 | + def self.find(name) | |
9 | + directory = File.join(Design.public_filesystem_root, Design.design_root, 'templates', name) | |
10 | + yaml_files = Dir.glob(File.join(directory, '*.yml')) | |
11 | + | |
12 | + if yaml_files.size != 1 | |
13 | + raise "#{name} is not a valid template. There must be one (and only one) YAML (*.yml) file describing it in #{directory})" | |
14 | + end | |
15 | + | |
16 | + data = YAML.load_file(yaml_files.first) | |
17 | + | |
18 | + self.new(name, data) | |
19 | + end | |
20 | + def name | |
21 | + @data['name'] | |
22 | + end | |
23 | + def title | |
24 | + @data['title'] || name | |
25 | + end | |
26 | + def number_of_boxes | |
27 | + @data['number_of_boxes'] || 3 | |
28 | + end | |
29 | + end | |
30 | +end | ... | ... |
vendor/plugins/design/test/acts_as_design_test.rb
... | ... | @@ -2,6 +2,14 @@ require File.join(File.dirname(__FILE__), 'test_helper') |
2 | 2 | |
3 | 3 | class ActsAsDesignTest < Test::Unit::TestCase |
4 | 4 | |
5 | + def setup | |
6 | + Design.public_filesystem_root = File.join(File.dirname(__FILE__)) | |
7 | + end | |
8 | + | |
9 | + def teardown | |
10 | + Design.public_filesystem_root = nil | |
11 | + end | |
12 | + | |
5 | 13 | def test_should_provide_template_attribute |
6 | 14 | user = DesignTestUser.new |
7 | 15 | assert_equal 'default', user.template |
... | ... | @@ -42,4 +50,13 @@ class ActsAsDesignTest < Test::Unit::TestCase |
42 | 50 | end |
43 | 51 | end |
44 | 52 | |
53 | + def test_should_create_boxes_when_creating | |
54 | + user = DesignTestUser.create!(:name => 'A test user') | |
55 | + | |
56 | + # default template (test/designs/templates/default/default.yml) defines | |
57 | + # 3 boxes | |
58 | + assert_equal 3, Design::Template.find('default').number_of_boxes | |
59 | + assert_equal 3, user.boxes.size | |
60 | + end | |
61 | + | |
45 | 62 | end | ... | ... |
vendor/plugins/design/test/design_editor_test.rb
... | ... | @@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), 'test_helper') |
3 | 3 | class DesignEditorTest < Test::Unit::TestCase |
4 | 4 | |
5 | 5 | def setup |
6 | - @controller = DesignHelperTestController.new | |
6 | + @controller = DesignEditorTestController.new | |
7 | 7 | @request = ActionController::TestRequest.new |
8 | 8 | @response = ActionController::TestResponse.new |
9 | 9 | |
... | ... | @@ -14,4 +14,65 @@ class DesignEditorTest < Test::Unit::TestCase |
14 | 14 | Design.public_filesystem_root = nil |
15 | 15 | end |
16 | 16 | |
17 | + def test_should_render_design_in_editor_mode | |
18 | + get :design_editor | |
19 | + assert_response :success | |
20 | + assert_template 'design_editor' | |
21 | + end | |
22 | + | |
23 | + def test_should_set_new_template | |
24 | + assert_equal 'default', @controller.send(:design).template | |
25 | + post :design_editor, :template => 'empty' | |
26 | + assert_response :redirect | |
27 | + assert_redirected_to :action => 'design_editor' | |
28 | + assert_equal 'empty', @controller.send(:design).template | |
29 | + assert @controller.send(:design).saved? | |
30 | + end | |
31 | + | |
32 | + def test_should_not_set_to_unexisting_template | |
33 | + assert_equal 'default', @controller.send(:design).template | |
34 | + post :design_editor, :template => 'no_existing_template' | |
35 | + assert_response :redirect | |
36 | + assert_redirected_to :action => 'design_editor' | |
37 | + assert_equal 'default', @controller.send(:design).template | |
38 | + assert @controller.send(:design).saved? | |
39 | + end | |
40 | + | |
41 | + | |
42 | + def test_should_set_new_theme | |
43 | + assert_equal 'default', @controller.send(:design).theme | |
44 | + post :design_editor, :theme => 'empty' | |
45 | + assert_response :redirect | |
46 | + assert_redirected_to :action => 'design_editor' | |
47 | + assert_equal 'empty', @controller.send(:design).theme | |
48 | + assert @controller.send(:design).saved? | |
49 | + end | |
50 | + | |
51 | + def test_should_not_set_to_unexisting_theme | |
52 | + assert_equal 'default', @controller.send(:design).theme | |
53 | + post :design_editor, :theme => 'no_existing_theme' | |
54 | + assert_response :redirect | |
55 | + assert_redirected_to :action => 'design_editor' | |
56 | + assert_equal 'default', @controller.send(:design).theme | |
57 | + assert @controller.send(:design).saved? | |
58 | + end | |
59 | + | |
60 | + def test_should_set_new_icon_theme | |
61 | + assert_equal 'default', @controller.send(:design).icon_theme | |
62 | + post :design_editor, :icon_theme => 'empty' | |
63 | + assert_response :redirect | |
64 | + assert_redirected_to :action => 'design_editor' | |
65 | + assert_equal 'empty', @controller.send(:design).icon_theme | |
66 | + assert @controller.send(:design).saved? | |
67 | + end | |
68 | + | |
69 | + def test_should_not_set_to_unexisting_icon_theme | |
70 | + assert_equal 'default', @controller.send(:design).icon_theme | |
71 | + post :design_editor, :icon_theme => 'no_existing_icon_theme' | |
72 | + assert_response :redirect | |
73 | + assert_redirected_to :action => 'design_editor' | |
74 | + assert_equal 'default', @controller.send(:design).icon_theme | |
75 | + assert @controller.send(:design).saved? | |
76 | + end | |
77 | + | |
17 | 78 | end | ... | ... |
vendor/plugins/design/test/design_helper_test.rb
... | ... | @@ -81,6 +81,7 @@ class DesignHelperTest < Test::Unit::TestCase |
81 | 81 | |
82 | 82 | def test_should_generate_all_boxes |
83 | 83 | get :index |
84 | + assert_response :success | |
84 | 85 | assert_tag :tag => 'div', :attributes => { :id => 'box_1' } |
85 | 86 | assert_tag :tag => 'div', :attributes => { :id => 'box_2' } |
86 | 87 | assert_tag :tag => 'div', :attributes => { :id => 'box_3' } |
... | ... | @@ -88,6 +89,7 @@ class DesignHelperTest < Test::Unit::TestCase |
88 | 89 | |
89 | 90 | def test_should_render_array_as_list |
90 | 91 | get :index |
92 | + assert_response :success | |
91 | 93 | assert_tag :tag => 'ul', :descendant => { |
92 | 94 | :tag => 'li', :content => 'item1' |
93 | 95 | } |
... | ... | @@ -101,16 +103,19 @@ class DesignHelperTest < Test::Unit::TestCase |
101 | 103 | |
102 | 104 | def test_should_process_block_returned_as_content |
103 | 105 | get :index |
106 | + assert_response :success | |
104 | 107 | assert_tag :tag => 'a', :attributes => { :href => /controller_linked_from_block/ } |
105 | 108 | end |
106 | 109 | |
107 | 110 | def test_should_put_string_as_is |
108 | 111 | get :index |
112 | + assert_response :success | |
109 | 113 | assert_tag :tag => 'div', :content => "this is a fixed content block hacked for testing", :attributes => { :class => 'block' } |
110 | 114 | end |
111 | 115 | |
112 | 116 | def test_should_provide_javascript_link_if_available |
113 | 117 | get :javascript |
118 | + assert_response :success | |
114 | 119 | assert_tag :tag => 'script', :attributes => { |
115 | 120 | :type => 'text/javascript', |
116 | 121 | :src => '/designs/templates/default/javascripts/one.js' |
... | ... | @@ -123,6 +128,7 @@ class DesignHelperTest < Test::Unit::TestCase |
123 | 128 | |
124 | 129 | def test_should_provide_stylesheet_links_if_available |
125 | 130 | get :template_stylesheets |
131 | + assert_response :success | |
126 | 132 | assert_tag :tag => 'link', :attributes => { |
127 | 133 | :type => 'text/css', |
128 | 134 | :href => '/designs/templates/default/stylesheets/one.css' |
... | ... | @@ -135,6 +141,7 @@ class DesignHelperTest < Test::Unit::TestCase |
135 | 141 | |
136 | 142 | def test_should_provide_theme_stylesheet_links_if_available |
137 | 143 | get :theme_stylesheets |
144 | + assert_response :success | |
138 | 145 | assert_tag :tag => 'link', :attributes => { |
139 | 146 | :type => 'text/css', |
140 | 147 | :href => '/designs/themes/default/one.css' |
... | ... | @@ -143,6 +150,7 @@ class DesignHelperTest < Test::Unit::TestCase |
143 | 150 | |
144 | 151 | def test_should_support_displaying_icons |
145 | 152 | get :icons |
153 | + assert_response :success | |
146 | 154 | assert_tag :tag => 'img', :attributes => { |
147 | 155 | :src => '/designs/icons/default/something.png' |
148 | 156 | } |
... | ... | @@ -153,6 +161,7 @@ class DesignHelperTest < Test::Unit::TestCase |
153 | 161 | |
154 | 162 | def test_should_provide_full_header_tags |
155 | 163 | get :all_header_tags |
164 | + assert_response :success | |
156 | 165 | |
157 | 166 | # template JS |
158 | 167 | assert_tag :tag => 'script', :attributes => { | ... | ... |
vendor/plugins/design/test/designs/templates/default/default.yml
0 → 100644
vendor/plugins/design/test/proxy_design_holder_test.rb
... | ... | @@ -1,43 +0,0 @@ |
1 | -require File.join(File.dirname(__FILE__), 'test_helper') | |
2 | - | |
3 | - | |
4 | -class ProxyDesignHolderTest < Test::Unit::TestCase | |
5 | - | |
6 | - # FIXME: rewrite this test with mocha | |
7 | - def test_design_should_interact_with_sample_holder | |
8 | - design = Design::ProxyDesignHolder.new(SampleHolderForTestingProxyDesignHolder.new) | |
9 | - design.template = 'bli' | |
10 | - assert_equal 'bli', design.template | |
11 | - design.theme = 'bli' | |
12 | - assert_equal 'bli', design.theme | |
13 | - design.icon_theme = 'bli' | |
14 | - assert_equal 'bli', design.icon_theme | |
15 | - design.boxes = [] | |
16 | - assert_equal [], design.boxes | |
17 | - end | |
18 | - | |
19 | - def test_design_user_controller_should_get_a_proper_design | |
20 | - controller = ProxyDesignHolderTestController.new | |
21 | - design = controller.send(:design) | |
22 | - design.template = 'bli' | |
23 | - assert_equal 'bli', design.template | |
24 | - design.theme = 'bli' | |
25 | - assert_equal 'bli', design.theme | |
26 | - design.icon_theme = 'bli' | |
27 | - assert_equal 'bli', design.icon_theme | |
28 | - design.boxes = [] | |
29 | - assert_equal [], design.boxes | |
30 | - end | |
31 | - | |
32 | - def test_should_not_proxy_unrelated_method_calls | |
33 | - # to be safe | |
34 | - assert_nothing_raised do | |
35 | - 1.succ | |
36 | - end | |
37 | - assert_raise NoMethodError do | |
38 | - design = Design::ProxyDesignHolder.new(1) | |
39 | - design.succ | |
40 | - end | |
41 | - end | |
42 | - | |
43 | -end |
vendor/plugins/design/test/test_helper.rb
... | ... | @@ -47,6 +47,15 @@ end |
47 | 47 | |
48 | 48 | class SampleHolderForTestingProxyDesignHolder |
49 | 49 | attr_accessor :template, :theme, :icon_theme, :boxes |
50 | + def initialize | |
51 | + @saved = false | |
52 | + end | |
53 | + def save | |
54 | + @saved = true | |
55 | + end | |
56 | + def saved? | |
57 | + @saved | |
58 | + end | |
50 | 59 | end |
51 | 60 | |
52 | 61 | class ProxyDesignHolderTestController < ActionController::Base |
... | ... | @@ -69,8 +78,26 @@ class InheritanceDesignTestController < ProxyDesignHolderTestController |
69 | 78 | end |
70 | 79 | |
71 | 80 | class DesignEditorTestController < ActionController::Base |
72 | - design_editor :holder => 'sample_object' | |
81 | + | |
82 | + self.template_root = File.join(File.dirname(__FILE__), 'views') | |
83 | + layout 'design_editor_test' | |
84 | + design_editor :holder => 'sample_object', :autosave => true | |
73 | 85 | def initialize |
74 | 86 | @sample_object = SampleHolderForTestingProxyDesignHolder.new |
87 | + @sample_object.template = 'default' | |
88 | + @sample_object.theme = 'default' | |
89 | + @sample_object.icon_theme = 'default' | |
90 | + def @sample_object.id | |
91 | + 1 | |
92 | + end | |
93 | + | |
94 | + box1 = Design::Box.new(:number => 1) | |
95 | + box2 = Design::Box.new(:number => 2) | |
96 | + main_block = Design::MainBlock.new(:position => 1) | |
97 | + box2.blocks << main_block | |
98 | + main_block.box = box2 | |
99 | + main_block.name = 'Main block' | |
100 | + box3 = Design::Box.new(:number => 3) | |
101 | + @sample_object.boxes = [ box1, box2, box3 ] | |
75 | 102 | end |
76 | 103 | end | ... | ... |
vendor/plugins/design/test/views/design_editor_test/design_editor.rhtml
0 → 100644
vendor/plugins/design/test/views/layouts/design_editor_test.rhtml
0 → 100644