Commit 416a5be0d8e0b350c0295fe56c210999915e6c0f
1 parent
438ab96e
Exists in
master
and in
29 other branches
ActionItem152: removed design plugin; adding a home-made block manager
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1202 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
39 changed files
with
592 additions
and
58 deletions
Show diff stats
app/controllers/admin/admin_panel_controller.rb
app/controllers/admin/edit_template_controller.rb
app/controllers/application.rb
... | ... | @@ -5,7 +5,14 @@ class ApplicationController < ActionController::Base |
5 | 5 | helper :document |
6 | 6 | helper :language |
7 | 7 | |
8 | - design :holder => 'environment' | |
8 | + def boxes_holder | |
9 | + environment | |
10 | + end | |
11 | + | |
12 | + def boxes_editor? | |
13 | + false | |
14 | + end | |
15 | + protected :boxes_editor? | |
9 | 16 | |
10 | 17 | def self.no_design_blocks |
11 | 18 | @no_design_blocks = true | ... | ... |
... | ... | @@ -0,0 +1,52 @@ |
1 | +class BoxOrganizerController < ApplicationController | |
2 | + | |
3 | + def move_block | |
4 | + @block = boxes_holder.blocks.find(params[:id].gsub(/^block-/, '')) | |
5 | + | |
6 | + @source_box = @block.box | |
7 | + | |
8 | + target_position = nil | |
9 | + | |
10 | + if (params[:target] =~ /before-block-([0-9]+)/) | |
11 | + block_before = boxes_holder.blocks.find($1) | |
12 | + target_position = block_before.position | |
13 | + | |
14 | + @target_box = block_before.box | |
15 | + else | |
16 | + (params[:target] =~ /end-of-box-([0-9])+/) | |
17 | + | |
18 | + @target_box = boxes_holder.boxes.find($1) | |
19 | + end | |
20 | + | |
21 | + if (@source_box != @target_box) | |
22 | + @block.remove_from_list | |
23 | + @block.box = @target_box | |
24 | + end | |
25 | + | |
26 | + if target_position.nil? | |
27 | + # insert in the end of the box | |
28 | + @block.insert_at(@target_box.blocks.size + 1) | |
29 | + @block.move_to_bottom | |
30 | + else | |
31 | + # insert the block in the given position | |
32 | + @block.insert_at(@block.position && @block.position < target_position ? target_position - 1 : target_position) | |
33 | + end | |
34 | + | |
35 | + @block.save! | |
36 | + | |
37 | + @target_box.reload | |
38 | + end | |
39 | + | |
40 | + def move_block_down | |
41 | + @block = boxes_holder.blocks.find(params[:id]) | |
42 | + @block.move_lower | |
43 | + redirect_to :back | |
44 | + end | |
45 | + | |
46 | + def move_block_up | |
47 | + @block = boxes_holder.blocks.find(params[:id]) | |
48 | + @block.move_higher | |
49 | + redirect_to :back | |
50 | + end | |
51 | + | |
52 | +end | ... | ... |
app/controllers/my_profile/cms_controller.rb
... | ... | @@ -2,7 +2,9 @@ class CmsController < MyProfileController |
2 | 2 | |
3 | 3 | protect 'post_content', :profile, :only => [:edit, :new, :reorder, :delete] |
4 | 4 | |
5 | - design :holder => :profile | |
5 | + def boxes_holder | |
6 | + profile | |
7 | + end | |
6 | 8 | |
7 | 9 | include CmsHelper |
8 | 10 | |
... | ... | @@ -11,6 +13,7 @@ class CmsController < MyProfileController |
11 | 13 | TextileArticle, |
12 | 14 | RssFeed, |
13 | 15 | UploadedFile, |
16 | + ImageGallery, | |
14 | 17 | ] |
15 | 18 | |
16 | 19 | def view | ... | ... |
app/controllers/my_profile/profile_editor_controller.rb
... | ... | @@ -4,7 +4,8 @@ class ProfileEditorController < MyProfileController |
4 | 4 | |
5 | 5 | helper :profile |
6 | 6 | |
7 | - design_editor :holder => 'profile',:autosave => true, :block_types => :block_types | |
7 | + # FIXME | |
8 | + #design_editor :holder => 'profile',:autosave => true, :block_types => :block_types | |
8 | 9 | |
9 | 10 | |
10 | 11 | def block_types | ... | ... |
app/controllers/public/account_controller.rb
app/controllers/public/category_controller.rb
... | ... | @@ -5,7 +5,9 @@ class CategoryController < ApplicationController |
5 | 5 | #FIXME This is not necessary because the application controller define the envrioment |
6 | 6 | # as the default holder |
7 | 7 | |
8 | - design :holder => 'environment' | |
8 | + def boxes_holder | |
9 | + environment | |
10 | + end | |
9 | 11 | |
10 | 12 | def load_default_enviroment |
11 | 13 | @environment = Environment.default | ... | ... |
app/controllers/public/home_controller.rb
app/helpers/application_helper.rb
... | ... | @@ -5,6 +5,8 @@ module ApplicationHelper |
5 | 5 | include PermissionName |
6 | 6 | |
7 | 7 | include LightboxHelper |
8 | + | |
9 | + include BoxesHelper | |
8 | 10 | |
9 | 11 | # Displays context help. You can pass the content of the help message as the |
10 | 12 | # first parameter or using template code inside a block passed to this |
... | ... | @@ -144,14 +146,6 @@ module ApplicationHelper |
144 | 146 | end |
145 | 147 | end |
146 | 148 | |
147 | - def search_box | |
148 | - [form_tag({:controller => 'search', :action => 'index'}, :method => 'get'), | |
149 | - design_display_button_submit('find', '', :title => _('Search')), | |
150 | - text_field_tag( 'query', _('your search here'), :id => "input_search", :onfocus => 'javascript: if (this.value == %s) { this.value = ""; }' % _('your search here').inspect, :onblur => "javascript: if (this.value == '') { this.value = %s}" % _('your search here').inspect), | |
151 | - '</form>', | |
152 | - ].join("\n") | |
153 | - end | |
154 | - | |
155 | 149 | def footer |
156 | 150 | # FIXME: add some information from the environment |
157 | 151 | [ |
... | ... | @@ -267,7 +261,11 @@ module ApplicationHelper |
267 | 261 | end |
268 | 262 | |
269 | 263 | def button(type, label, url, html_options = {}) |
270 | - design_display_button(type, label, url, { :class => 'with_text' }.merge(html_options)) | |
264 | + the_class = "button #{type}" | |
265 | + if html_options.has_key?(:class) | |
266 | + the_class << ' ' << html_options[:class] | |
267 | + end | |
268 | + link_to(content_tag('span', label), url, html_options.merge(:class => the_class )) | |
271 | 269 | end |
272 | 270 | |
273 | 271 | def submit_button(type, label, html_options = {}) |
... | ... | @@ -275,20 +273,28 @@ module ApplicationHelper |
275 | 273 | |
276 | 274 | html_options[:class] = [html_options[:class], 'submit'].compact.join(' ') |
277 | 275 | |
278 | - bt_submit = design_display_button_submit(type, label, { :class => 'with_text' }.merge(html_options)) | |
279 | - content_tag('p', bt_submit + bt_cancel, :class => 'submitline') | |
276 | + the_class = "button with_text #{type}" | |
277 | + if html_options.has_key?(:class) | |
278 | + the_class << ' ' << html_options[:class] | |
279 | + end | |
280 | + | |
281 | + bt_submit = submit_tag(label, html_options.merge(:class => the_class)) | |
280 | 282 | |
283 | + content_tag('p', bt_submit + bt_cancel, :class => 'submitline') | |
281 | 284 | end |
282 | 285 | |
283 | 286 | def button_to_function(type, label, js_code, html_options = {}) |
284 | - #design_display_function_button(type, label, js_code, { :class => 'with_text' }.merge(html_options)) | |
285 | 287 | html_options[:class] = "" unless html_options[:class] |
286 | 288 | html_options[:class] << " button #{type}" |
287 | 289 | link_to_function(label, js_code, html_options) |
288 | 290 | end |
289 | 291 | |
290 | - def icon(icon_name) | |
291 | - design_display_icon(icon_name) | |
292 | + def icon(icon_name, html_options = {}) | |
293 | + the_class = "button #{icon_name}" | |
294 | + if html_options.has_key?(:class) | |
295 | + the_class << ' ' << html_options[:class] | |
296 | + end | |
297 | + content_tag('div', '', html_options.merge(:class => the_class)) | |
292 | 298 | end |
293 | 299 | |
294 | 300 | def button_bar(options = {}, &block) | ... | ... |
... | ... | @@ -0,0 +1,109 @@ |
1 | +module BoxesHelper | |
2 | + | |
3 | + def box_decorator | |
4 | + @box_decorator || DontMoveBlocks | |
5 | + end | |
6 | + | |
7 | + def with_box_decorator(dec, &block) | |
8 | + @box_decorator = dec | |
9 | + result = block.call | |
10 | + @box_decorator = DontMoveBlocks | |
11 | + | |
12 | + result | |
13 | + end | |
14 | + | |
15 | + def display_boxes_editor(holder) | |
16 | + with_box_decorator self do | |
17 | + content_tag('div', display_boxes(holder, '<' + _('Main content') + '>'), :id => 'box-organizer') | |
18 | + end | |
19 | + end | |
20 | + | |
21 | + def display_boxes(holder, main_content) | |
22 | + boxes = holder.boxes.first(holder.boxes_limit) | |
23 | + content = boxes.reverse.map { |item| display_box(item, main_content) }.join("\n") | |
24 | + content = main_content if (content.blank?) | |
25 | + content_tag('div', content, :class => 'boxes', :id => 'boxes' ) | |
26 | + end | |
27 | + | |
28 | + def display_box(box, main_content) | |
29 | + content_tag('div', content_tag('div', display_box_content(box, main_content), :class => 'blocks'), :class => 'box', :id => "box-#{box.position}" ) | |
30 | + end | |
31 | + | |
32 | + def display_updated_box(box) | |
33 | + with_box_decorator self do | |
34 | + display_box_content(box, '<' + _('Main content') + '>') | |
35 | + end | |
36 | + end | |
37 | + | |
38 | + def display_box_content(box, main_content) | |
39 | + box.blocks.map { |item| display_block(item, main_content) }.join("\n") + box_decorator.block_target(box) | |
40 | + end | |
41 | + | |
42 | + def display_block(block, main_content = nil) | |
43 | + content = block.content(main_content) | |
44 | + result = | |
45 | + case content | |
46 | + when Hash | |
47 | + content_tag('iframe', '', :src => url_for(content)) | |
48 | + when String | |
49 | + if content =~ /^https?:\/\// | |
50 | + content_tag('iframe', '', :src => content) | |
51 | + else | |
52 | + content | |
53 | + end | |
54 | + end | |
55 | + | |
56 | + classes = ['block', block.class.name.underscore.gsub('_', '-') ].uniq.join(' ') | |
57 | + | |
58 | + box_decorator.block_target(block.box, block) + content_tag('div', result + box_decorator.block_move_buttons(block), :class => classes, :id => "block-#{block.id}") + box_decorator.block_handle(block) | |
59 | + end | |
60 | + | |
61 | + module DontMoveBlocks | |
62 | + # does nothing | |
63 | + def self.block_target(box, block = nil) | |
64 | + '' | |
65 | + end | |
66 | + # does nothing | |
67 | + def self.block_handle(block) | |
68 | + '' | |
69 | + end | |
70 | + def self.block_move_buttons(block) | |
71 | + '' | |
72 | + end | |
73 | + end | |
74 | + | |
75 | + # generates a place where you can drop a block and get the block moved to | |
76 | + # there. | |
77 | + # | |
78 | + # If +block+ is not nil, then it means "place the dropped block before this | |
79 | + # one.". Otherwise, it means "place the dropped block at the end of the | |
80 | + # list" | |
81 | + # | |
82 | + # +box+ is always needed | |
83 | + def block_target(box, block = nil) | |
84 | + id = | |
85 | + if block.nil? | |
86 | + "end-of-box-#{box.id}" | |
87 | + else | |
88 | + "before-block-#{block.id}" | |
89 | + end | |
90 | + | |
91 | + content_tag('div', ' ', :id => id, :class => 'block-target' ) + drop_receiving_element(id, :url => { :action => 'move_block', :target => id }, :accept => 'block', :hoverclass => 'block-target-hover') | |
92 | + end | |
93 | + | |
94 | + # makes the given block draggable so it can be moved away. | |
95 | + def block_handle(block) | |
96 | + draggable_element("block-#{block.id}", :revert => true) | |
97 | + end | |
98 | + | |
99 | + def block_move_buttons(block) | |
100 | + buttons = [] | |
101 | + | |
102 | + # FIXME hardcoded paths !!! | |
103 | + buttons << link_to(image_tag('/designs/icons/default/gtk-go-up.png', :alt => _('Move block up')), { :action => 'move_block_up', :id => block.id }, { :method => 'post' }) unless block.first? | |
104 | + buttons << link_to(image_tag('/designs/icons/default/gtk-go-down.png', :alt => _('Move block down')), { :action => 'move_block_down' ,:id => block.id }, { :method => 'post'}) unless block.last? | |
105 | + | |
106 | + content_tag('div', buttons.join("\n"), :class => 'block-move-buttons') | |
107 | + end | |
108 | + | |
109 | +end | ... | ... |
... | ... | @@ -0,0 +1,13 @@ |
1 | +class Block < ActiveRecord::Base | |
2 | + acts_as_list :scope => :box | |
3 | + belongs_to :box | |
4 | + | |
5 | + def content(main_content = nil) | |
6 | + "This is block number %d" % self.id | |
7 | + end | |
8 | + | |
9 | + def editor | |
10 | + { :controller => 'block_editor', :id => self.id } | |
11 | + end | |
12 | + | |
13 | +end | ... | ... |
app/models/environment.rb
... | ... | @@ -25,7 +25,14 @@ class Environment < ActiveRecord::Base |
25 | 25 | # Relationships and applied behaviour |
26 | 26 | # ################################################# |
27 | 27 | |
28 | - acts_as_design | |
28 | + acts_as_having_boxes | |
29 | + | |
30 | + after_create do |env| | |
31 | + 3.times do | |
32 | + env.boxes << Box.new | |
33 | + end | |
34 | + env.boxes.first.blocks << MainBlock.new | |
35 | + end | |
29 | 36 | |
30 | 37 | # One Environment can be reached by many domains |
31 | 38 | has_many :domains, :as => :owner | ... | ... |
app/models/link_block.rb
app/models/profile.rb
... | ... | @@ -14,7 +14,7 @@ class Profile < ActiveRecord::Base |
14 | 14 | |
15 | 15 | acts_as_accessible |
16 | 16 | |
17 | - acts_as_design | |
17 | + acts_as_having_boxes | |
18 | 18 | |
19 | 19 | acts_as_searchable :fields => [ :name, :identifier ] |
20 | 20 | |
... | ... | @@ -81,6 +81,13 @@ class Profile < ActiveRecord::Base |
81 | 81 | self.environment ||= Environment.default |
82 | 82 | end |
83 | 83 | |
84 | + after_create do |profile| | |
85 | + 3.times do | |
86 | + profile.boxes << Box.new | |
87 | + end | |
88 | + profile.boxes.first.blocks << MainBlock.new | |
89 | + end | |
90 | + | |
84 | 91 | # Returns information about the profile's owner that was made public by |
85 | 92 | # him/her. |
86 | 93 | # | ... | ... |
app/models/recent_documents_block.rb
... | ... | @@ -0,0 +1,8 @@ |
1 | +from = "box-#{@source_box.position}" | |
2 | +to = "box-#{@target_box.position}" | |
3 | + | |
4 | +page.replace_html(from, display_updated_box(@source_box)) | |
5 | +page.replace_html(to, display_updated_box(@target_box)) | |
6 | + | |
7 | +page.visual_effect(:highlight, from) | |
8 | +page.visual_effect(:highlight, to) unless (from == to) | ... | ... |
app/views/layouts/application.rhtml
... | ... | @@ -10,12 +10,17 @@ |
10 | 10 | </title> |
11 | 11 | <meta name="description" content="FIXME: Descriptions of Noosfero" /> |
12 | 12 | <meta name="keywords" content="Noosfero, Community, Open Source" /> |
13 | - <%= design_all_header_tags %> | |
14 | 13 | <%= stylesheet_link_tag 'common' %> |
15 | 14 | <%= stylesheet_link_tag 'help' %> |
16 | 15 | <%= stylesheet_link_tag 'menu' %> |
17 | 16 | <%= stylesheet_link_tag 'button' %> |
18 | 17 | <%= stylesheet_link_tag 'search' %> |
18 | + <%= stylesheet_link_tag 'blocks' %> | |
19 | + | |
20 | + <%# FIXME %> | |
21 | + <%= stylesheet_link_tag '/designs/templates/default/stylesheets/style.css' %> | |
22 | + | |
23 | + <%= javascript_include_tag(:defaults) %> | |
19 | 24 | <%= javascript_include_tag 'menu' %> |
20 | 25 | <%= include_lightbox_header %> |
21 | 26 | <%# cms stuff %> |
... | ... | @@ -70,10 +75,15 @@ |
70 | 75 | <div id='header_content'> |
71 | 76 | </div> |
72 | 77 | |
73 | - <% if uses_design_blocks? %> | |
74 | - <%= design_display(yield) %> | |
75 | - <% else %> | |
78 | + <% if @controller.send(:boxes_editor?) %> | |
76 | 79 | <%= yield %> |
80 | + <%= display_boxes_editor(@controller.boxes_holder) %> | |
81 | + <% else %> | |
82 | + <% if uses_design_blocks? %> | |
83 | + <%= display_boxes(@controller.boxes_holder, yield) %> | |
84 | + <% else %> | |
85 | + <%= yield %> | |
86 | + <% end %> | |
77 | 87 | <% end %> |
78 | 88 | |
79 | 89 | </div><!-- id="content" --> | ... | ... |
config/environment.rb
... | ... | @@ -80,6 +80,7 @@ require 'noosfero/transliterations' |
80 | 80 | |
81 | 81 | require 'acts_as_filesystem' |
82 | 82 | require 'acts_as_searchable' |
83 | +require 'acts_as_having_boxes' | |
83 | 84 | |
84 | 85 | # to the hell, I want all my models loaded before the application run anything |
85 | 86 | Dir.glob("#{RAILS_ROOT}/app/models/*.rb").each do |model| | ... | ... |
db/migrate/001_add_design_support.rb
1 | 1 | class AddDesignSupport < ActiveRecord::Migration |
2 | 2 | def self.up |
3 | - create_table :design_boxes do |t| | |
4 | - t.column :name, :string | |
5 | - t.column :title, :string | |
6 | - t.column :number, :integer | |
3 | + | |
4 | + create_table :boxes do |t| | |
7 | 5 | t.column :owner_type, :string |
8 | 6 | t.column :owner_id, :integer |
7 | + | |
8 | + # acts_as_list | |
9 | + t.column :position, :integer | |
9 | 10 | end |
10 | 11 | |
11 | - create_table :design_blocks do |t| | |
12 | + create_table :blocks do |t| | |
12 | 13 | t.column :title, :string |
13 | 14 | t.column :box_id, :integer |
14 | - t.column :position, :integer | |
15 | 15 | t.column :type, :string |
16 | 16 | t.column :settings, :text |
17 | + | |
18 | + # acts_as_list | |
19 | + t.column :position, :integer | |
17 | 20 | end |
18 | 21 | |
19 | 22 | end |
20 | 23 | |
21 | 24 | def self.down |
22 | - drop_table :design_boxes | |
23 | - drop_table :design_blocks | |
25 | + drop_table :boxes | |
26 | + drop_table :blocks | |
24 | 27 | end |
25 | 28 | |
26 | 29 | end | ... | ... |
... | ... | @@ -0,0 +1,36 @@ |
1 | +module ActsAsHavingBoxes | |
2 | + | |
3 | + module ClassMethods | |
4 | + def acts_as_having_boxes | |
5 | + has_many :boxes, :as => :owner, :dependent => :destroy, :order => 'position' | |
6 | + self.send(:include, ActsAsHavingBoxes) | |
7 | + end | |
8 | + end | |
9 | + | |
10 | + module BlockArray | |
11 | + def find(id) | |
12 | + select { |item| item.id == id.to_i }.first | |
13 | + end | |
14 | + end | |
15 | + | |
16 | + def blocks(reload = false) | |
17 | + if (reload) | |
18 | + @blocks = nil | |
19 | + end | |
20 | + if @blocks.nil? | |
21 | + @blocks = boxes.inject([]) do |acc,obj| | |
22 | + acc.concat(obj.blocks) | |
23 | + end | |
24 | + @blocks.send(:extend, BlockArray) | |
25 | + end | |
26 | + @blocks | |
27 | + end | |
28 | + | |
29 | + # returns 3 unless the class table has a boxes_limit column. In that case | |
30 | + # return the value of the column. | |
31 | + def boxes_limit | |
32 | + self[:boxes_limit] || 3 | |
33 | + end | |
34 | +end | |
35 | + | |
36 | +ActiveRecord::Base.extend(ActsAsHavingBoxes::ClassMethods) | ... | ... |
lib/needs_profile.rb
public/designs/icons/default/README
... | ... | @@ -34,6 +34,8 @@ gtk-find.png Nuovo stock/ |
34 | 34 | gtk-go-back-ltr.png Nuovo stock/ |
35 | 35 | gtk-media-next-ltr.png Nuovo stock/ |
36 | 36 | gtk-add.png Nuovo stock/ |
37 | +gtk-go-up.png Nuovo stock/ | |
38 | +gtk-go-down.png Nuovo stock/ | |
37 | 39 | ### END OF ICONS LISTING ### |
38 | 40 | |
39 | 41 | Licensing of GNOME themes | ... | ... |
1 KB
public/designs/icons/default/gtk-go-up.png
public/designs/icons/default/style.css
... | ... | @@ -14,3 +14,5 @@ |
14 | 14 | .button.back { background-image: url(gtk-go-back-ltr.png); } |
15 | 15 | .button.next { background-image: url(gtk-media-next-ltr.png); } |
16 | 16 | .button.add { background-image: url(gtk-add.png); } |
17 | +.button.up { background-image: url(gtk-go-up.png); } | |
18 | +.button.down { background-image: url(gtk-go-down.png); } | ... | ... |
... | ... | @@ -0,0 +1,58 @@ |
1 | + | |
2 | +/* main box */ | |
3 | +#box-1 { | |
4 | + margin-left: 210px; | |
5 | + margin-right: 210px; | |
6 | +} | |
7 | + | |
8 | +#box-2 { | |
9 | + float: left; | |
10 | + width: 200px; | |
11 | +} | |
12 | + | |
13 | +#box-3 { | |
14 | + float: right; | |
15 | + width: 200px; | |
16 | +} | |
17 | + | |
18 | + | |
19 | +.block { | |
20 | + margin: 5px; | |
21 | + padding: 5px; | |
22 | +} | |
23 | + | |
24 | +.block-target { | |
25 | + margin: 5px; | |
26 | + height: 2px; | |
27 | + height: 15px; | |
28 | + border: 1px dashed #e0e0e0; | |
29 | +} | |
30 | + | |
31 | +.block-target-hover { | |
32 | + background: #ffd; | |
33 | + border: 1px solid red; | |
34 | + height: 30px; | |
35 | +} | |
36 | + | |
37 | +.block iframe { | |
38 | + width: 100%; | |
39 | + border: none; | |
40 | +} | |
41 | + | |
42 | +/*********************************************************** | |
43 | + * put borders around boxes and blocks when organizing boxes | |
44 | + ***********************************************************/ | |
45 | + | |
46 | +#box-organizer .box { | |
47 | + border: 1px solid #ccc; | |
48 | +} | |
49 | + | |
50 | +#box-organizer #box-1 .block { | |
51 | + border: 2px dashed green; | |
52 | +} | |
53 | +#box-organizer #box-2 .block { | |
54 | + border: 2px dashed red; | |
55 | +} | |
56 | +#box-organizer #box-3 .block { | |
57 | + border: 2px dashed blue; | |
58 | +} | ... | ... |
test/functional/application_controller_test.rb
... | ... | @@ -107,7 +107,7 @@ class ApplicationControllerTest < Test::Unit::TestCase |
107 | 107 | |
108 | 108 | should 'use design plugin to generate blocks' do |
109 | 109 | get :index |
110 | - assert_tag :tag => 'div', :attributes => { :id => 'boxes', :class => 'design_boxes' } | |
110 | + assert_tag :tag => 'div', :attributes => { :id => 'boxes', :class => 'boxes' } | |
111 | 111 | end |
112 | 112 | |
113 | 113 | should 'not use design plugin when tells so' do |
... | ... | @@ -116,6 +116,6 @@ class ApplicationControllerTest < Test::Unit::TestCase |
116 | 116 | end |
117 | 117 | @controller = NoDesignBlocksTestController.new |
118 | 118 | get :index |
119 | - assert_no_tag :tag => 'div', :attributes => { :id => 'boxes', :class => 'design_boxes' } | |
119 | + assert_no_tag :tag => 'div', :attributes => { :id => 'boxes', :class => 'boxes' } | |
120 | 120 | end |
121 | 121 | end | ... | ... |
... | ... | @@ -0,0 +1,135 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | +require 'profile_design_controller' | |
3 | + | |
4 | +class ProfileDesignController; def rescue_action(e) raise e end; end | |
5 | + | |
6 | +class ProfileDesignControllerTest < Test::Unit::TestCase | |
7 | + | |
8 | + def setup | |
9 | + @controller = ProfileDesignController.new | |
10 | + @request = ActionController::TestRequest.new | |
11 | + @response = ActionController::TestResponse.new | |
12 | + | |
13 | + holder = create_user('designtestuser').person | |
14 | + holder.save! | |
15 | + | |
16 | + @box1 = Box.new | |
17 | + @box2 = Box.new | |
18 | + @box3 = Box.new | |
19 | + | |
20 | + holder.boxes << @box1 | |
21 | + holder.boxes << @box2 | |
22 | + holder.boxes << @box3 | |
23 | + | |
24 | + ###### BOX 1 | |
25 | + @b1 = Block.new | |
26 | + @box1.blocks << @b1 | |
27 | + @b1.save! | |
28 | + | |
29 | + @b2 = Block.new | |
30 | + @box1.blocks << @b2 | |
31 | + @b2.save! | |
32 | + | |
33 | + ###### BOX 2 | |
34 | + @b3 = Block.new | |
35 | + @box2.blocks << @b3 | |
36 | + @b3.save! | |
37 | + | |
38 | + @b4 = MainBlock.new | |
39 | + @box2.blocks << @b4 | |
40 | + @b4.save! | |
41 | + | |
42 | + @b5 = Block.new | |
43 | + @box2.blocks << @b5 | |
44 | + @b5.save! | |
45 | + | |
46 | + @b6 = Block.new | |
47 | + @box2.blocks << @b6 | |
48 | + @b6.save! | |
49 | + | |
50 | + ###### BOX 3 | |
51 | + @b7 = Block.new | |
52 | + @box3.blocks << @b7 | |
53 | + @b7.save! | |
54 | + | |
55 | + @b8 = Block.new | |
56 | + @box3.blocks << @b8 | |
57 | + @b8.save! | |
58 | + | |
59 | + @request.env['HTTP_REFERER'] = '/editor' | |
60 | + | |
61 | + @controller.expects(:boxes_holder).returns(holder).at_least_once | |
62 | + end | |
63 | + | |
64 | + def test_should_move_block_to_the_end_of_another_block | |
65 | + get :move_block, :profile => 'ze', :id => "block-#{@b1.id}", :target => "end-of-box-#{@box2.id}" | |
66 | + | |
67 | + assert_response :success | |
68 | + | |
69 | + @b1.reload | |
70 | + @box2.reload | |
71 | + | |
72 | + assert_equal @box2, @b1.box | |
73 | + assert @b1.in_list? | |
74 | + assert_equal @box2.blocks.size, @b1.position # i.e. assert @b1.last? | |
75 | + end | |
76 | + | |
77 | + def test_should_move_block_to_the_middle_of_another_block | |
78 | + # block 4 is in box 2 | |
79 | + get :move_block, :profile => 'ze', :id => "block-#{@b1.id}", :target => "before-block-#{@b4.id}" | |
80 | + | |
81 | + assert_response :success | |
82 | + | |
83 | + @b1.reload | |
84 | + @b4.reload | |
85 | + | |
86 | + assert_equal @b4.box, @b1.box | |
87 | + assert @b1.in_list? | |
88 | + assert_equal @b4.position - 1, @b1.position | |
89 | + end | |
90 | + | |
91 | + def test_block_can_be_moved_up | |
92 | + get :move_block, :profile => 'ze', :id => "block-#{@b4.id}", :target => "before-block-#{@b3.id}" | |
93 | + | |
94 | + assert_response :success | |
95 | + @b4.reload | |
96 | + @b3.reload | |
97 | + | |
98 | + assert_equal @b3.position - 1, @b4.position | |
99 | + end | |
100 | + | |
101 | + def test_block_can_be_moved_down | |
102 | + assert_equal [1,2,3], [@b3,@b4,@b5].map {|item| item.position} | |
103 | + | |
104 | + # b3 -> before b5 | |
105 | + get :move_block, :profile => 'ze', :id => "block-#{@b3.id}", :target => "before-block-#{@b5.id}" | |
106 | + | |
107 | + [@b3,@b4,@b5].each do |item| | |
108 | + item.reload | |
109 | + end | |
110 | + | |
111 | + assert_equal [1,2,3], [@b4, @b3, @b5].map {|item| item.position} | |
112 | + end | |
113 | + | |
114 | + def test_should_be_able_to_move_block_directly_down | |
115 | + post :move_block_down, :profile => 'ze', :id => @b1.id | |
116 | + assert_response :redirect | |
117 | + | |
118 | + @b1.reload | |
119 | + @b2.reload | |
120 | + | |
121 | + assert_equal [1,2], [@b2,@b1].map {|item| item.position} | |
122 | + end | |
123 | + | |
124 | + def test_should_be_able_to_move_block_directly_up | |
125 | + post :move_block_up, :profile => 'ze', :id => @b2.id | |
126 | + assert_response :redirect | |
127 | + | |
128 | + @b1.reload | |
129 | + @b2.reload | |
130 | + | |
131 | + assert_equal [1,2], [@b2,@b1].map {|item| item.position} | |
132 | + end | |
133 | + | |
134 | +end | |
135 | + | ... | ... |
test/functional/region_validators_controller_test.rb
... | ... | @@ -27,7 +27,7 @@ class RegionValidatorsControllerTest < Test::Unit::TestCase |
27 | 27 | environment.regions << region |
28 | 28 | assert !region.new_record? |
29 | 29 | |
30 | - @controller.expects(:environment).returns(environment) | |
30 | + @controller.expects(:environment).returns(environment).at_least_once | |
31 | 31 | |
32 | 32 | get :region, :id => region.id |
33 | 33 | ... | ... |
test/integration/routing_test.rb
... | ... | @@ -80,12 +80,13 @@ class RoutingTest < ActionController::IntegrationTest |
80 | 80 | assert_routing('/cat', :controller => 'category', :action => 'index') |
81 | 81 | end |
82 | 82 | |
83 | - def test_routing_to_controllers_inside_design_blocks_directory | |
84 | - assert_routing('/block/cojones/favorite_links_profile/show/1', :profile => 'cojones', :controller => 'favorite_links_profile', :action => 'show', :id => '1') | |
85 | - assert_routing('/block/cojones/favorite_links_profile/save', :profile => 'cojones', :controller => 'favorite_links_profile', :action => 'save') | |
83 | + #FIXME remove this if design_blocks is not going to be used; or uncomment otherwise; | |
84 | + #def test_routing_to_controllers_inside_design_blocks_directory | |
85 | + # assert_routing('/block/cojones/favorite_links_profile/show/1', :profile => 'cojones', :controller => 'favorite_links_profile', :action => 'show', :id => '1') | |
86 | + # assert_routing('/block/cojones/favorite_links_profile/save', :profile => 'cojones', :controller => 'favorite_links_profile', :action => 'save') | |
86 | 87 | |
87 | - assert_routing('/block/cojones/list_block/show/1', :profile => 'cojones', :controller => 'list_block', :action => 'show', :id => '1') | |
88 | - end | |
88 | + # assert_routing('/block/cojones/list_block/show/1', :profile => 'cojones', :controller => 'list_block', :action => 'show', :id => '1') | |
89 | + #end | |
89 | 90 | |
90 | 91 | def test_tag_viewing |
91 | 92 | assert_routing('/tag', :controller => 'search', :action => 'tags') | ... | ... |
... | ... | @@ -0,0 +1,16 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class ActsAsHavingBoxesTest < Test::Unit::TestCase | |
4 | + | |
5 | + should 'be able to find blocks by id' do | |
6 | + env = Environment.create!(:name => 'my test environment') | |
7 | + env.boxes.destroy_all | |
8 | + | |
9 | + env.boxes << Box.new | |
10 | + block = Block.new | |
11 | + env.boxes.first.blocks << block | |
12 | + | |
13 | + assert_equal block, env.blocks.find(block.id) | |
14 | + end | |
15 | + | |
16 | +end | ... | ... |
test/unit/environment_test.rb
... | ... | @@ -199,13 +199,24 @@ class EnvironmentTest < Test::Unit::TestCase |
199 | 199 | assert env_boxes > 0 |
200 | 200 | assert env_blocks > 0 |
201 | 201 | |
202 | - boxes = Design::Box.count | |
203 | - blocks = Design::Block.count | |
202 | + boxes = Box.count | |
203 | + blocks = Block.count | |
204 | 204 | |
205 | 205 | env.destroy |
206 | 206 | |
207 | - assert_equal boxes - env_boxes, Design::Box.count | |
208 | - assert_equal blocks - env_blocks, Design::Block.count | |
207 | + assert_equal boxes - env_boxes, Box.count | |
208 | + assert_equal blocks - env_blocks, Block.count | |
209 | + end | |
210 | + | |
211 | + should 'have boxes and blocks upon creation' do | |
212 | + environment = Environment.create!(:name => 'a test environment') | |
213 | + assert environment.boxes.size > 0 | |
214 | + assert environment.blocks.size > 0 | |
215 | + end | |
216 | + | |
217 | + should 'have at least one MainBlock upon creation' do | |
218 | + environment = Environment.create!(:name => 'a test environment') | |
219 | + assert(environment.blocks.any? { |block| block.kind_of? MainBlock }) | |
209 | 220 | end |
210 | 221 | |
211 | 222 | end | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -200,21 +200,34 @@ class ProfileTest < Test::Unit::TestCase |
200 | 200 | assert_equal profile, Profile['testprofile'] |
201 | 201 | end |
202 | 202 | |
203 | + should 'have boxes and blocks upon creation' do | |
204 | + profile = Profile.create!(:name => 'test profile', :identifier => 'testprofile') | |
205 | + | |
206 | + assert profile.boxes.size > 0 | |
207 | + assert profile.blocks.size > 0 | |
208 | + end | |
209 | + | |
210 | + should 'have at least one MainBlock upon creation' do | |
211 | + profile = Profile.create!(:name => 'test profile', :identifier => 'testprofile') | |
212 | + assert(profile.blocks.any? { |block| block.kind_of? MainBlock }) | |
213 | + end | |
214 | + | |
203 | 215 | should 'remove boxes and blocks when removing profile' do |
204 | - profile = Profile.create!(:name => 'test environment', :identifier => 'testenv') | |
216 | + profile = Profile.create!(:name => 'test profile', :identifier => 'testprofile') | |
205 | 217 | |
206 | 218 | profile_boxes = profile.boxes.size |
207 | 219 | profile_blocks = profile.blocks.size |
220 | + | |
208 | 221 | assert profile_boxes > 0 |
209 | 222 | assert profile_blocks > 0 |
210 | 223 | |
211 | - boxes = Design::Box.count | |
212 | - blocks = Design::Block.count | |
224 | + boxes = Box.count | |
225 | + blocks = Block.count | |
213 | 226 | |
214 | 227 | profile.destroy |
215 | 228 | |
216 | - assert_equal boxes - profile_boxes, Design::Box.count | |
217 | - assert_equal blocks - profile_blocks, Design::Block.count | |
229 | + assert_equal boxes - profile_boxes, Box.count | |
230 | + assert_equal blocks - profile_blocks, Block.count | |
218 | 231 | end |
219 | 232 | |
220 | 233 | should 'provide url to itself' do | ... | ... |