Commit 635cd8782fc752519c73497ce54375138b7a1e7f

Authored by Evandro Junior
2 parents 647e3fdb a5c0c0f3

Merge branch 'AI3132-create_settings_items_for_comments' into AI3074-community_dashboard

Showing 97 changed files with 1868 additions and 308 deletions   Show diff stats
app/controllers/box_organizer_controller.rb
@@ -80,6 +80,22 @@ class BoxOrganizerController < ApplicationController @@ -80,6 +80,22 @@ class BoxOrganizerController < ApplicationController
80 render :action => 'edit', :layout => false 80 render :action => 'edit', :layout => false
81 end 81 end
82 82
  83 + def search_autocomplete
  84 + if request.xhr? and params[:query]
  85 + search = params[:query]
  86 + path_list = if boxes_holder.is_a?(Environment) && boxes_holder.enabled?('use_portal_community') && boxes_holder.portal_community
  87 + boxes_holder.portal_community.articles.find(:all, :conditions=>"name ILIKE '%#{search}%' or path ILIKE '%#{search}%'", :limit=>20).map { |content| "/{portal}/"+content.path }
  88 + elsif boxes_holder.is_a?(Profile)
  89 + boxes_holder.articles.find(:all, :conditions=>"name ILIKE '%#{search}%' or path ILIKE '%#{search}%'", :limit=>20).map { |content| "/{profile}/"+content.path }
  90 + else
  91 + []
  92 + end
  93 + render :json => path_list.to_json
  94 + else
  95 + redirect_to "/"
  96 + end
  97 + end
  98 +
83 def save 99 def save
84 @block = boxes_holder.blocks.find(params[:id]) 100 @block = boxes_holder.blocks.find(params[:id])
85 @block.update_attributes(params[:block]) 101 @block.update_attributes(params[:block])
app/controllers/embed_controller.rb 0 → 100644
@@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
  1 +class EmbedController < ApplicationController
  2 + layout 'embed'
  3 +
  4 + def block
  5 + @block = Block.find(params[:id])
  6 + if !@block.embedable? || !@block.visible?
  7 + render 'unavailable.rhtml', :status => 403
  8 + end
  9 + rescue ActiveRecord::RecordNotFound
  10 + render 'not_found.rhtml', :status => 404
  11 + end
  12 +
  13 +end
app/controllers/my_profile/maps_controller.rb
@@ -31,23 +31,11 @@ class MapsController &lt; MyProfileController @@ -31,23 +31,11 @@ class MapsController &lt; MyProfileController
31 end 31 end
32 32
33 def search_city 33 def search_city
34 -  
35 - term = params[:term];  
36 -  
37 - regions = NationalRegion.search_city(term + "%", true).map {|r|{ :label => r.city , :category => r.state}}  
38 -  
39 - render :json => regions  
40 - 34 + render :json => MapsHelper.search_city(params[:term])
41 end 35 end
42 36
43 def search_state 37 def search_state
44 -  
45 - term = params[:term];  
46 -  
47 - regions = NationalRegion.search_state(term + "%", true).map {|r|{ :label => r.state}}  
48 -  
49 - render :json => regions  
50 - 38 + render :json => MapsHelper.search_state(params[:term])
51 end 39 end
52 40
53 end 41 end
app/controllers/public/account_controller.rb
@@ -250,15 +250,19 @@ class AccountController &lt; ApplicationController @@ -250,15 +250,19 @@ class AccountController &lt; ApplicationController
250 end 250 end
251 end 251 end
252 252
253 - def check_url 253 + def check_valid_name
254 @identifier = params[:identifier] 254 @identifier = params[:identifier]
255 valid = Person.is_available?(@identifier, environment) 255 valid = Person.is_available?(@identifier, environment)
256 if valid 256 if valid
257 @status = _('This login name is available') 257 @status = _('This login name is available')
258 @status_class = 'validated' 258 @status_class = 'validated'
259 - else 259 + elsif !@identifier.empty?
  260 + @suggested_usernames = suggestion_based_on_username(@identifier)
260 @status = _('This login name is unavailable') 261 @status = _('This login name is unavailable')
261 @status_class = 'invalid' 262 @status_class = 'invalid'
  263 + else
  264 + @status_class = 'invalid'
  265 + @status = _('This field can\'t be blank')
262 end 266 end
263 render :partial => 'identifier_status' 267 render :partial => 'identifier_status'
264 end 268 end
@@ -291,6 +295,23 @@ class AccountController &lt; ApplicationController @@ -291,6 +295,23 @@ class AccountController &lt; ApplicationController
291 render :text => user_data.to_json, :layout => false, :content_type => "application/javascript" 295 render :text => user_data.to_json, :layout => false, :content_type => "application/javascript"
292 end 296 end
293 297
  298 + def search_cities
  299 + if request.xhr? and params[:state_name] and params[:city_name]
  300 + render :json => MapsHelper.search_city(params[:city_name], params[:state_name])
  301 + else
  302 + render :json => [].to_json
  303 + end
  304 + end
  305 +
  306 + def search_state
  307 + if request.xhr? and params[:state_name]
  308 + render :json => MapsHelper.search_state(params[:state_name])
  309 + else
  310 + render :json => [].to_json
  311 + end
  312 + end
  313 +
  314 +
294 protected 315 protected
295 316
296 def redirect? 317 def redirect?
app/controllers/public/content_viewer_controller.rb
@@ -50,7 +50,7 @@ class ContentViewerController &lt; ApplicationController @@ -50,7 +50,7 @@ class ContentViewerController &lt; ApplicationController
50 end 50 end
51 51
52 # At this point the page will be showed 52 # At this point the page will be showed
53 - @page.hit 53 + @page.hit unless user_is_a_bot?
54 54
55 @page = FilePresenter.for @page 55 @page = FilePresenter.for @page
56 56
@@ -111,6 +111,15 @@ class ContentViewerController &lt; ApplicationController @@ -111,6 +111,15 @@ class ContentViewerController &lt; ApplicationController
111 @comments = @plugins.filter(:unavailable_comments, @comments) 111 @comments = @plugins.filter(:unavailable_comments, @comments)
112 @comments_count = @comments.count 112 @comments_count = @comments.count
113 @comments = @comments.without_reply.paginate(:per_page => per_page, :page => params[:comment_page] ) 113 @comments = @comments.without_reply.paginate(:per_page => per_page, :page => params[:comment_page] )
  114 + @comment_order = params[:comment_order].nil? ? 'oldest' : params[:comment_order]
  115 +
  116 + if request.xhr? and params[:comment_order]
  117 + if @comment_order == 'newest'
  118 + @comments = @comments.reverse
  119 + end
  120 +
  121 + return render :partial => 'comment/comment', :collection => @comments
  122 + end
114 123
115 if params[:slideshow] 124 if params[:slideshow]
116 render :action => 'slideshow', :layout => 'slideshow' 125 render :action => 'slideshow', :layout => 'slideshow'
@@ -176,4 +185,13 @@ class ContentViewerController &lt; ApplicationController @@ -176,4 +185,13 @@ class ContentViewerController &lt; ApplicationController
176 allowed 185 allowed
177 end 186 end
178 187
  188 + def user_is_a_bot?
  189 + user_agent= request.env["HTTP_USER_AGENT"]
  190 + user_agent.blank? ||
  191 + user_agent.match(/bot/) ||
  192 + user_agent.match(/spider/) ||
  193 + user_agent.match(/crawler/) ||
  194 + user_agent.match(/\(.*https?:\/\/.*\)/)
  195 + end
  196 +
179 end 197 end
app/controllers/public/events_controller.rb
@@ -21,7 +21,7 @@ class EventsController &lt; PublicController @@ -21,7 +21,7 @@ class EventsController &lt; PublicController
21 21
22 def events_by_day 22 def events_by_day
23 @date = build_date(params[:year], params[:month], params[:day]) 23 @date = build_date(params[:year], params[:month], params[:day])
24 - @events = profile.events.by_day(@date) 24 + @events = profile.events.by_day(@date).paginate(:per_page => per_page, :page => params[:page])
25 render :partial => 'events' 25 render :partial => 'events'
26 end 26 end
27 27
app/helpers/account_helper.rb
@@ -12,4 +12,17 @@ module AccountHelper @@ -12,4 +12,17 @@ module AccountHelper
12 _('Checking if e-mail address is already taken...') 12 _('Checking if e-mail address is already taken...')
13 end 13 end
14 end 14 end
  15 +
  16 + def suggestion_based_on_username(requested_username='')
  17 + return "" if requested_username.empty?
  18 + usernames = []
  19 + 3.times do
  20 + begin
  21 + valid_name = requested_username + rand(1000).to_s
  22 + end while (usernames.include?(valid_name) || !Person.is_available?(valid_name, environment))
  23 + usernames << valid_name
  24 + end
  25 + usernames
  26 + end
  27 +
15 end 28 end
app/helpers/boxes_helper.rb
@@ -65,7 +65,7 @@ module BoxesHelper @@ -65,7 +65,7 @@ module BoxesHelper
65 end 65 end
66 66
67 def display_box_content(box, main_content) 67 def display_box_content(box, main_content)
68 - context = { :article => @page, :request_path => request.path, :locale => locale, :params => request.params } 68 + context = { :article => @page, :request_path => request.path, :locale => locale, :params => request.params, :user => user }
69 box_decorator.select_blocks(box.blocks.includes(:box), context).map { |item| display_block(item, main_content) }.join("\n") + box_decorator.block_target(box) 69 box_decorator.select_blocks(box.blocks.includes(:box), context).map { |item| display_block(item, main_content) }.join("\n") + box_decorator.block_target(box)
70 end 70 end
71 71
@@ -219,6 +219,17 @@ module BoxesHelper @@ -219,6 +219,17 @@ module BoxesHelper
219 buttons << thickbox_inline_popup_icon(:help, _('Help on this block'), {}, "help-on-box-#{block.id}") << content_tag('div', content_tag('h2', _('Help')) + content_tag('div', block.help, :style => 'margin-bottom: 1em;') + thickbox_close_button(_('Close')), :style => 'display: none;', :id => "help-on-box-#{block.id}") 219 buttons << thickbox_inline_popup_icon(:help, _('Help on this block'), {}, "help-on-box-#{block.id}") << content_tag('div', content_tag('h2', _('Help')) + content_tag('div', block.help, :style => 'margin-bottom: 1em;') + thickbox_close_button(_('Close')), :style => 'display: none;', :id => "help-on-box-#{block.id}")
220 end 220 end
221 221
  222 + if block.embedable?
  223 + embed_code = block.embed_code
  224 + embed_code = instance_eval(&embed_code) if embed_code.respond_to?(:call)
  225 + html = content_tag('div',
  226 + content_tag('h2', _('Embed block code')) +
  227 + content_tag('div', _('Below, you''ll see a field containing embed code for the block. Just copy the code and paste it into your website or blogging software.'), :style => 'margin-bottom: 1em;') +
  228 + content_tag('textarea', embed_code, :style => 'margin-bottom: 1em; width:100%; height:40%;', :readonly => 'readonly') +
  229 + thickbox_close_button(_('Close')), :style => 'display: none;', :id => "embed-code-box-#{block.id}")
  230 + buttons << thickbox_inline_popup_icon(:embed, _('Embed code'), {}, "embed-code-box-#{block.id}") << html
  231 + end
  232 +
222 content_tag('div', buttons.join("\n") + tag('br', :style => 'clear: left'), :class => 'button-bar') 233 content_tag('div', buttons.join("\n") + tag('br', :style => 'clear: left'), :class => 'button-bar')
223 end 234 end
224 235
app/helpers/maps_helper.rb 0 → 100644
@@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
  1 +module MapsHelper
  2 + def self.search_city term, state=""
  3 + cities = if state.empty?
  4 + NationalRegion.search_city(term + "%", true)
  5 + else
  6 + NationalRegion.search_city(term + "%", true, state)
  7 + end
  8 + cities.map {|r|{ :label => r.city , :category => r.state}}
  9 + end
  10 +
  11 + def self.search_state term
  12 + NationalRegion.search_state(term + "%", true).map {|r|{ :label => r.state}}
  13 + end
  14 +end
app/helpers/token_helper.rb
@@ -27,7 +27,7 @@ module TokenHelper @@ -27,7 +27,7 @@ module TokenHelper
27 hintText: #{options[:hint_text].to_json}, 27 hintText: #{options[:hint_text].to_json},
28 noResultsText: #{options[:no_results_text].to_json}, 28 noResultsText: #{options[:no_results_text].to_json},
29 searchingText: #{options[:searching_text].to_json}, 29 searchingText: #{options[:searching_text].to_json},
30 - searchDelay: #{options[:serach_delay].to_json}, 30 + searchDelay: #{options[:search_delay].to_json},
31 preventDuplicates: #{options[:prevent_duplicates].to_json}, 31 preventDuplicates: #{options[:prevent_duplicates].to_json},
32 backspaceDeleteItem: #{options[:backspace_delete_item].to_json}, 32 backspaceDeleteItem: #{options[:backspace_delete_item].to_json},
33 queryParam: #{name.to_json}, 33 queryParam: #{name.to_json},
app/models/block.rb
@@ -16,17 +16,36 @@ class Block &lt; ActiveRecord::Base @@ -16,17 +16,36 @@ class Block &lt; ActiveRecord::Base
16 16
17 named_scope :enabled, :conditions => { :enabled => true } 17 named_scope :enabled, :conditions => { :enabled => true }
18 18
  19 + def embedable?
  20 + false
  21 + end
  22 +
  23 + def embed_code
  24 + me = self
  25 + lambda do
  26 + content_tag('iframe', '',
  27 + :src => url_for(:controller => 'embed', :action => 'block', :id => me.id, :only_path => false),
  28 + :frameborder => 0,
  29 + :width => 1024,
  30 + :height => 768,
  31 + :class => "embed block #{me.class.name.to_css_class}"
  32 + )
  33 + end
  34 + end
  35 +
19 # Determines whether a given block must be visible. Optionally a 36 # Determines whether a given block must be visible. Optionally a
20 # <tt>context</tt> must be specified. <tt>context</tt> must be a hash, and 37 # <tt>context</tt> must be specified. <tt>context</tt> must be a hash, and
21 # may contain the following keys: 38 # may contain the following keys:
22 # 39 #
23 # * <tt>:article</tt>: the article being viewed currently 40 # * <tt>:article</tt>: the article being viewed currently
24 # * <tt>:language</tt>: in which language the block will be displayed 41 # * <tt>:language</tt>: in which language the block will be displayed
  42 + # * <tt>:user</tt>: the logged user
25 def visible?(context = nil) 43 def visible?(context = nil)
26 return false if display == 'never' 44 return false if display == 'never'
27 45
28 if context 46 if context
29 return false if language != 'all' && language != context[:locale] 47 return false if language != 'all' && language != context[:locale]
  48 + return false unless display_to_user?(context[:user])
30 49
31 begin 50 begin
32 return self.send("display_#{display}", context) 51 return self.send("display_#{display}", context)
@@ -38,6 +57,10 @@ class Block &lt; ActiveRecord::Base @@ -38,6 +57,10 @@ class Block &lt; ActiveRecord::Base
38 true 57 true
39 end 58 end
40 59
  60 + def display_to_user?(user)
  61 + display_user == 'all' || (user.nil? && display_user == 'not_logged') || (user && display_user == 'logged')
  62 + end
  63 +
41 def display_always(context) 64 def display_always(context)
42 true 65 true
43 end 66 end
@@ -68,6 +91,14 @@ class Block &lt; ActiveRecord::Base @@ -68,6 +91,14 @@ class Block &lt; ActiveRecord::Base
68 # the homepage of its owner. 91 # the homepage of its owner.
69 settings_items :display, :type => :string, :default => 'always' 92 settings_items :display, :type => :string, :default => 'always'
70 93
  94 +
  95 + # The condition for displaying a block to users. It can assume the following values:
  96 + #
  97 + # * <tt>'all'</tt>: the block is always displayed
  98 + # * <tt>'logged'</tt>: the block is displayed to logged users only
  99 + # * <tt>'not_logged'</tt>: the block is displayed only to not logged users
  100 + settings_items :display_user, :type => :string, :default => 'all'
  101 +
71 # The block can be configured to be displayed in all languages or in just one language. It can assume any locale of the environment: 102 # The block can be configured to be displayed in all languages or in just one language. It can assume any locale of the environment:
72 # 103 #
73 # * <tt>'all'</tt>: the block is always displayed 104 # * <tt>'all'</tt>: the block is always displayed
@@ -171,12 +202,20 @@ class Block &lt; ActiveRecord::Base @@ -171,12 +202,20 @@ class Block &lt; ActiveRecord::Base
171 'never' => __('Don\'t display'), 202 'never' => __('Don\'t display'),
172 } 203 }
173 204
174 - def display_options 205 + def display_options_available
175 DISPLAY_OPTIONS.keys 206 DISPLAY_OPTIONS.keys
176 end 207 end
177 208
178 - def display_option_label(option)  
179 - DISPLAY_OPTIONS[option] 209 + def display_options
  210 + DISPLAY_OPTIONS.slice(*display_options_available)
  211 + end
  212 +
  213 + def display_user_options
  214 + @display_user_options ||= {
  215 + 'all' => __('All users'),
  216 + 'logged' => __('Logged'),
  217 + 'not_logged' => __('Not logged'),
  218 + }
180 end 219 end
181 220
182 def duplicate 221 def duplicate
app/models/link_list_block.rb
@@ -70,6 +70,8 @@ class LinkListBlock &lt; Block @@ -70,6 +70,8 @@ class LinkListBlock &lt; Block
70 def expand_address(address) 70 def expand_address(address)
71 add = if owner.respond_to?(:identifier) 71 add = if owner.respond_to?(:identifier)
72 address.gsub('{profile}', owner.identifier) 72 address.gsub('{profile}', owner.identifier)
  73 + elsif owner.is_a?(Environment) && owner.enabled?('use_portal_community') && owner.portal_community
  74 + address.gsub('{portal}', owner.portal_community.identifier)
73 else 75 else
74 address 76 address
75 end 77 end
app/models/main_block.rb
@@ -24,7 +24,7 @@ class MainBlock &lt; Block @@ -24,7 +24,7 @@ class MainBlock &lt; Block
24 false 24 false
25 end 25 end
26 26
27 - def display_options 27 + def display_options_available
28 ['always', 'except_home_page'] 28 ['always', 'except_home_page']
29 end 29 end
30 30
app/models/national_region.rb
@@ -12,7 +12,7 @@ class NationalRegion &lt; ActiveRecord::Base @@ -12,7 +12,7 @@ class NationalRegion &lt; ActiveRecord::Base
12 adtional_contions = ""; 12 adtional_contions = "";
13 13
14 if like 14 if like
15 - operator = "like" 15 + operator = "ilike"
16 find_return = :all 16 find_return = :all
17 end 17 end
18 18
@@ -41,7 +41,7 @@ class NationalRegion &lt; ActiveRecord::Base @@ -41,7 +41,7 @@ class NationalRegion &lt; ActiveRecord::Base
41 find_return = :first 41 find_return = :first
42 42
43 if like 43 if like
44 - operator = "like" 44 + operator = "ilike"
45 find_return = :all 45 find_return = :all
46 end 46 end
47 47
app/models/text_article.rb
@@ -20,4 +20,23 @@ class TextArticle &lt; Article @@ -20,4 +20,23 @@ class TextArticle &lt; Article
20 def can_display_versions? 20 def can_display_versions?
21 true 21 true
22 end 22 end
  23 +
  24 + before_save :set_relative_path
  25 +
  26 + def set_relative_path
  27 + parsed = Hpricot(self.body.to_s)
  28 + parsed.search('img[@src]').map { |i| change_element_path(i, 'src') }
  29 + parsed.search('a[@href]').map { |i| change_element_path(i, 'href') }
  30 + self.body = parsed.to_s
  31 + end
  32 +
  33 + def change_element_path(el, attribute)
  34 + fullpath = /(https?):\/\/(#{environment.default_hostname})(:\d+)?(\/.*)/.match(el[attribute])
  35 + if fullpath
  36 + domain = fullpath[2]
  37 + path = fullpath[4]
  38 + el[attribute] = path if domain == environment.default_hostname
  39 + end
  40 + end
  41 +
23 end 42 end
app/views/account/_identifier_status.rhtml
1 <div class='status-identifier'> 1 <div class='status-identifier'>
2 - <p><span class='<%= @status_class %>'><%= @status %></span></p> 2 +
  3 + <span class='<%= @status_class %>'><%= @status %></span>
  4 + <% if @suggested_usernames %>
  5 + <div class='suggested_usernames'>
  6 + <%= _('Available: ') %>
  7 + <% @suggested_usernames.each do |username| %>
  8 + <a href='#'><%= username %></a>
  9 + <% end %>
  10 + </div>
  11 + <% end %>
3 <script type="text/javascript"> 12 <script type="text/javascript">
4 jQuery('#user_login').removeClass('<%= validation_classes %>'); 13 jQuery('#user_login').removeClass('<%= validation_classes %>');
5 jQuery('#user_login').addClass('<%= @status_class %>'); 14 jQuery('#user_login').addClass('<%= @status_class %>');
  15 + jQuery('.suggested_usernames a').click(function(e) {
  16 + e.preventDefault();
  17 +
  18 + fill_username(this.innerHTML);
  19 + });
6 </script> 20 </script>
7 </div> 21 </div>
app/views/account/_signup_form.rhtml
@@ -7,6 +7,8 @@ @@ -7,6 +7,8 @@
7 7
8 <% @profile_data = @person %> 8 <% @profile_data = @person %>
9 9
  10 +<%= javascript_include_tag('sign_up_password_rate') %>
  11 +
10 <%= error_messages_for :user, :person, :header_message => _('The account could not be created') %> 12 <%= error_messages_for :user, :person, :header_message => _('The account could not be created') %>
11 13
12 <% labelled_form_for :user, @user, :html => { :multipart => true, :id => 'signup-form', :honeypot => true } do |f| %> 14 <% labelled_form_for :user, @user, :html => { :multipart => true, :id => 'signup-form', :honeypot => true } do |f| %>
@@ -35,24 +37,30 @@ @@ -35,24 +37,30 @@
35 <%= required text_field(:user, :login, :id => 'user_login', 37 <%= required text_field(:user, :login, :id => 'user_login',
36 :onchange => 'this.value = convToValidUsername(this.value);') %> 38 :onchange => 'this.value = convToValidUsername(this.value);') %>
37 <div id='url-check'><p>&nbsp;</p></div> 39 <div id='url-check'><p>&nbsp;</p></div>
  40 + <span id='checking-message' class='checking' style='display:none'><%= _('Checking availability of login name...') %></span>
38 </div> 41 </div>
39 <%= content_tag(:small, _('Choose your login name carefully! It will be your network access and you will not be able to change it later.'), :id => 'signup-balloon') %> 42 <%= content_tag(:small, _('Choose your login name carefully! It will be your network access and you will not be able to change it later.'), :id => 'signup-balloon') %>
40 <br style="clear: both;" /> 43 <br style="clear: both;" />
41 </div> 44 </div>
42 </div> 45 </div>
43 - <%= observe_field 'user_login',  
44 - :url => { :action => 'check_url' },  
45 - :with => 'identifier',  
46 - :update => 'url-check',  
47 - :loading => "jQuery('#user_login').removeClass('#{validation_classes}').addClass('checking');  
48 - jQuery('#url-check').html('<p><span class=\"checking\">#{checking_message(:url)}</span></p>');",  
49 - :complete => "jQuery('#user_login').removeClass('checking')"  
50 - %>  
51 - 46 + <%= javascript_include_tag "signup_form" %>
52 <div id='signup-password'> 47 <div id='signup-password'>
53 <%= required f.password_field(:password, :id => 'user_pw') %> 48 <%= required f.password_field(:password, :id => 'user_pw') %>
54 <%= content_tag(:small,_('Choose a password that you can remember easily. It must have at least 4 characters.'), :id => 'password-balloon') %> 49 <%= content_tag(:small,_('Choose a password that you can remember easily. It must have at least 4 characters.'), :id => 'password-balloon') %>
55 - <div id='fake-check'><p>&nbsp;</p></div> 50 + <div id='password-rate'>
  51 + <p><span class="invalid hidden" id='result-short'>
  52 + <%=_('Short') %>
  53 + </span></p>
  54 + <p><span class="invalid hidden" id='result-bad'>
  55 + <%=_('Bad') %>
  56 + </span></p>
  57 + <p><span class="invalid hidden" id='result-good'>
  58 + <%=_('Good') %>
  59 + </span></p>
  60 + <p><span class="invalid hidden" id='result-strong'>
  61 + <%=_('Strong') %>
  62 + </span></p>
  63 + </div>
56 </div> 64 </div>
57 65
58 <div id='signup-password-confirmation'> 66 <div id='signup-password-confirmation'>
@@ -182,4 +190,9 @@ jQuery(function($) { @@ -182,4 +190,9 @@ jQuery(function($) {
182 else $(this).addClass('validated'); 190 else $(this).addClass('validated');
183 }); 191 });
184 }); 192 });
  193 +
  194 +function fill_username(element){
  195 + jQuery('#url-check').html("<p><span class='checking'><%= _('This login name is available') %></span></p>")
  196 + jQuery('#user_login').val(element).addClass('validated').removeClass('invalid')
  197 +}
185 </script> 198 </script>
app/views/box_organizer/_link_list_block.rhtml
  1 +<%= javascript_include_tag "edit-link-list.js" %>
  2 +
1 <strong><%= _('Links') %></strong> 3 <strong><%= _('Links') %></strong>
2 <div id='edit-link-list-block'> 4 <div id='edit-link-list-block'>
3 -<table id='links' class='noborder'>  
4 - <tr>  
5 - <th><%= _('Icon') %></th>  
6 - <th><%= _('Name') %></th>  
7 - <th><%= _('Address') %></th>  
8 - <th><%= _('Title') %></th>  
9 - <th><%= _('Target') %></th>  
10 - </tr>  
11 - <% for link in @block.links do %>  
12 - <tr>  
13 - <td><%= icon_selector(link['icon']) %></td>  
14 - <td><%= text_field_tag 'block[links][][name]', link[:name], :class => 'link-name', :maxlength => 20 %></td>  
15 - <td class='cel-address'><%= text_field_tag 'block[links][][address]', link[:address], :class => 'link-address' %></td>  
16 - <td><%= text_field_tag 'block[links][][title]', link[:title], :class => 'link-title' %></td>  
17 - <td><%= select_tag('block[links][][target]', options_for_select(LinkListBlock::TARGET_OPTIONS, link[:target])) %></td>  
18 - </tr>  
19 - <% end %>  
20 -</table> 5 + <ul class='link-list-header'>
  6 + <li class='link-list-icon'><%= _('Icon') %></li>
  7 + <li class='link-list-name'><%= _('Name') %></li>
  8 + <li class='link-list-address'><%= _('Address') %></li>
  9 + <li class='link-list-target'><%= _('Target') %></li>
  10 + </ul>
  11 + <ul id="dropable-link-list">
  12 + <% for link in @block.links do %>
  13 + <li>
  14 + <ul class="link-list-row">
  15 + <li>
  16 + <%= icon_selector(link['icon']) %>
  17 + </li>
  18 + <li>
  19 + <%= text_field_tag 'block[links][][name]', link[:name], :class => 'link-name', :maxlength => 20 %>
  20 + </li>
  21 + <li>
  22 + <%= text_field_tag 'block[links][][address]', link[:address], :class => 'link-address' %>
  23 + </li>
  24 + <li>
  25 + <%= select_tag('block[links][][target]', options_for_select(LinkListBlock::TARGET_OPTIONS, link[:target])) %>
  26 + </li>
  27 + <li>
  28 + <%= button_without_text(:delete, _('Delete'), "#" , :class=>"delete-link-list-row") %>
  29 + </li>
  30 + </ul>
  31 + </li>
  32 + <% end %>
  33 + </ul>
  34 + <input type="hidden" id="page_url" value="<%=url_for(:action=>'search_autocomplete')%>" />
21 </div> 35 </div>
22 36
23 <%= link_to_function(_('New link'), nil, :class => 'button icon-add with-text') do |page| 37 <%= link_to_function(_('New link'), nil, :class => 'button icon-add with-text') do |page|
24 - page.insert_html :bottom, 'links', content_tag('tr',  
25 - content_tag('td', icon_selector('ok')) +  
26 - content_tag('td', text_field_tag('block[links][][name]', '', :maxlength => 20)) +  
27 - content_tag('td', text_field_tag('block[links][][address]', nil, :class => 'link-address'), :class => 'cel-address') +  
28 - content_tag('td', text_field_tag('block[links][][title]', '', :class => 'link-title')) +  
29 - content_tag('td', select_tag('block[links][][target]', options_for_select(LinkListBlock::TARGET_OPTIONS, '_self'))) 38 + page.insert_html :bottom, 'dropable-link-list', content_tag('li',
  39 + content_tag('ul',
  40 + content_tag('li', icon_selector('ok')) +
  41 + content_tag('li', text_field_tag('block[links][][name]', '', :maxlength => 20)) +
  42 + content_tag('li', text_field_tag('block[links][][address]', nil, :class => 'link-address')) +
  43 + content_tag('li', select_tag('block[links][][target]',
  44 + options_for_select(LinkListBlock::TARGET_OPTIONS, '_self'))) +
  45 + content_tag('li', button_without_text(:delete, _('Delete'), "#" , :class=>"delete-link-list-row")),
  46 + :class=>"link-list-row new_link_row")
30 ) + 47 ) +
31 - javascript_tag("$('edit-link-list-block').scrollTop = $('edit-link-list-block').scrollHeight") 48 + javascript_tag("new_link_action()")
32 end %> 49 end %>
app/views/box_organizer/edit.rhtml
@@ -7,13 +7,14 @@ @@ -7,13 +7,14 @@
7 7
8 <%= render :partial => partial_for_class(@block.class) %> 8 <%= render :partial => partial_for_class(@block.class) %>
9 9
10 - <%= labelled_form_field _('Display this block:'), '' %>  
11 - <div style='margin-left: 10px'>  
12 - <% @block.display_options.each do |option| %>  
13 - <%= radio_button(:block, :display, option) %>  
14 - <%= label_tag("block_display_#{option}", _(@block.display_option_label(option))) %>  
15 - <br/>  
16 - <% end %> 10 + <div class="display">
  11 + <%= labelled_form_field _('Display this block:'),
  12 + select_tag('block[display]', options_from_collection_for_select(@block.display_options, :first, :last, @block.display))
  13 + %>
  14 + </div>
  15 + <div class="display_user">
  16 + <%= labelled_form_field _('Display to users:'), '' %>
  17 + <%= select_tag('block[display_user]', options_from_collection_for_select(@block.display_user_options, :first, :last, @block.display_user)) %>
17 </div> 18 </div>
18 19
19 <%= labelled_form_field(_('Show for:'), select(:block, :language, [ [ _('all languages'), 'all']] + environment.locales.map {|key, value| [value, key]} )) %> 20 <%= labelled_form_field(_('Show for:'), select(:block, :language, [ [ _('all languages'), 'all']] + environment.locales.map {|key, value| [value, key]} )) %>
app/views/content_viewer/view_page.rhtml
@@ -80,8 +80,26 @@ @@ -80,8 +80,26 @@
80 </h3> 80 </h3>
81 <% end %> 81 <% end %>
82 82
83 - <% if @page.accept_comments? && @comments.count > 1 %> 83 + <% if @page.accept_comments? && @comments_count > 1 %>
84 <%= link_to(_('Post a comment'), '#', :class => 'display-comment-form', :id => 'top-post-comment-button', :onclick => "jQuery('#page-comment-form .display-comment-form').first().click();") %> 84 <%= link_to(_('Post a comment'), '#', :class => 'display-comment-form', :id => 'top-post-comment-button', :onclick => "jQuery('#page-comment-form .display-comment-form').first().click();") %>
  85 +
  86 + <%= hidden_field_tag("page_url", url_for(:controller=>'content_viewer', :action=>'view_page', :profile=>profile.identifier)) %>
  87 + <%= javascript_include_tag "comment_order.js" %>
  88 + <div class="comment-order">
  89 + <% form_tag({:controller=>'content_viewer' , :action=>'view_page'}, {:method=>'get', :id=>"form_order"}) do %>
  90 + <%= select_tag 'comment_order', options_for_select({_('Oldest first')=>'oldest', _('Newest first')=>'newest'}, @comment_order) %>
  91 + <% end %>
  92 + </div>
  93 + <% end %>
  94 +
  95 + <% if @page.accept_comments? and @comments.count > 1 %>
  96 + <%= hidden_field_tag("page_url", url_for(:controller=>'content_viewer', :action=>'view_page', :profile=>profile.identifier)) %>
  97 + <%= javascript_include_tag "comment_order.js" %>
  98 + <div class="comment-order">
  99 + <% form_tag({:controller=>'content_viewer' , :action=>'view_page'}, {:method=>'get', :id=>"form_order"}) do %>
  100 + <%= select_tag 'comment_order', options_for_select({_('Oldest first')=>'oldest', _('Newest first')=>'newest'}, @comment_order) %>
  101 + <% end %>
  102 + </div>
85 <% end %> 103 <% end %>
86 104
87 <ul class="article-comments-list"> 105 <ul class="article-comments-list">
app/views/embed/block.html.erb 0 → 100644
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +<%= display_block(@block) %>
app/views/embed/not_found.rhtml 0 → 100644
@@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
  1 +<div id='not-found'>
  2 + <p>
  3 + <%= _('You may have clicked an expired link or mistyped the address.') %>
  4 + <%= _('If you clicked a link that was in another site, or was given to you by someone else, it would be nice if you tell them that their link is not valid anymore.') %>
  5 + </p>
  6 +</div>
app/views/embed/unavailable.rhtml 0 → 100644
@@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
  1 +<div id='unavailable'>
  2 + <p><%= _('Embed unavailable.') %></p>
  3 +</div>
app/views/layouts/embed.rhtml 0 → 100644
@@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
  1 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2 +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<%= html_language %>" lang="<%= html_language %>">
  3 + <head>
  4 + <title>Noosfero embed block</title>
  5 + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6 + <%= noosfero_stylesheets %>
  7 + <%= noosfero_javascript %>
  8 + </head>
  9 + <body class="<%= h body_classes %>">
  10 + <div id="embed">
  11 + <div id="wrap-1">
  12 + <div id="wrap-2">
  13 + <div id="content">
  14 + <div id="content-inner">
  15 + <div class="boxes" id="boxes">
  16 + <div class="box box-1" id="box-1">
  17 + <div class="blocks">
  18 + <%= yield %>
  19 + </div>
  20 + </div>
  21 + </div>
  22 + </div>
  23 + </div>
  24 + </div>
  25 + </div>
  26 + </div>
  27 +
  28 + <script type="text/javascript">
  29 + jQuery(document).ready(function(){
  30 + jQuery('a').attr('target','_blank');
  31 + });
  32 + </script>
  33 +
  34 + </body>
  35 +</html>
app/views/profile_editor/_person_form.rhtml
@@ -19,8 +19,8 @@ @@ -19,8 +19,8 @@
19 <%= optional_field(@person, 'birth_date', labelled_form_field(_('Birth date'), '<div class="select-birth-date">' + pick_date(:profile_data, :birth_date, {:start_year => (Date.today.year - 100), :end_year => (Date.today.year - 5)}) + '</div>')) %> 19 <%= optional_field(@person, 'birth_date', labelled_form_field(_('Birth date'), '<div class="select-birth-date">' + pick_date(:profile_data, :birth_date, {:start_year => (Date.today.year - 100), :end_year => (Date.today.year - 5)}) + '</div>')) %>
20 <%= optional_field(@person, 'nationality', f.text_field(:nationality, :rel => _('Nationality'))) %> 20 <%= optional_field(@person, 'nationality', f.text_field(:nationality, :rel => _('Nationality'))) %>
21 <%= optional_field(@person, 'country', select_country(_('Country'), 'profile_data', 'country', {:class => 'type-select'})) %> 21 <%= optional_field(@person, 'country', select_country(_('Country'), 'profile_data', 'country', {:class => 'type-select'})) %>
22 -<%= optional_field(@person, 'state', f.text_field(:state, :rel => _('State'))) %>  
23 -<%= optional_field(@person, 'city', f.text_field(:city, :rel => _('City'))) %> 22 +<%= optional_field(@person, 'state', f.text_field(:state, :id => 'state_field', :rel => _('State'))) %>
  23 +<%= optional_field(@person, 'city', f.text_field(:city, :id => 'city_field', :rel => _('City'))) %>
24 <%= optional_field(@person, 'zip_code', labelled_form_field(_('ZIP code'), text_field(:profile_data, :zip_code, :rel => _('ZIP code')))) %> 24 <%= optional_field(@person, 'zip_code', labelled_form_field(_('ZIP code'), text_field(:profile_data, :zip_code, :rel => _('ZIP code')))) %>
25 <%= optional_field(@person, 'address', labelled_form_field(_('Address (street and number)'), text_field(:profile_data, :address, :rel => _('Address')))) %> 25 <%= optional_field(@person, 'address', labelled_form_field(_('Address (street and number)'), text_field(:profile_data, :address, :rel => _('Address')))) %>
26 <%= optional_field(@person, 'address_reference', labelled_form_field(_('Address reference'), text_field(:profile_data, :address_reference, :rel => _('Address reference')))) %> 26 <%= optional_field(@person, 'address_reference', labelled_form_field(_('Address reference'), text_field(:profile_data, :address_reference, :rel => _('Address reference')))) %>
@@ -36,6 +36,7 @@ @@ -36,6 +36,7 @@
36 </div> 36 </div>
37 <% end %> 37 <% end %>
38 38
  39 +<%= javascript_include_tag('city_state_validation') %>
39 <script type='text/javascript'> 40 <script type='text/javascript'>
40 function toggle_text_field(id, span_id) { 41 function toggle_text_field(id, span_id) {
41 if ($(id).value == "Others") { 42 if ($(id).value == "Others") {
app/views/shared/_organization_custom_fields.rhtml
@@ -13,8 +13,8 @@ @@ -13,8 +13,8 @@
13 <%= optional_field(profile, 'address_reference', labelled_form_field(_('Address reference'), text_field(object_name, :address_reference))) %> 13 <%= optional_field(profile, 'address_reference', labelled_form_field(_('Address reference'), text_field(object_name, :address_reference))) %>
14 <%= optional_field(profile, 'district', labelled_form_field(_('District'), text_field(object_name, :district))) %> 14 <%= optional_field(profile, 'district', labelled_form_field(_('District'), text_field(object_name, :district))) %>
15 <%= optional_field(profile, 'zip_code', labelled_form_field(_('ZIP code'), text_field(object_name, :zip_code))) %> 15 <%= optional_field(profile, 'zip_code', labelled_form_field(_('ZIP code'), text_field(object_name, :zip_code))) %>
16 -<%= optional_field(profile, 'city', f.text_field(:city)) %>  
17 -<%= optional_field(profile, 'state', f.text_field(:state)) %> 16 +<%= optional_field(profile, 'city', f.text_field(:city, :id =>'city_field')) %>
  17 +<%= optional_field(profile, 'state', f.text_field(:state,:id =>'state_field')) %>
18 <%= optional_field(profile, 'country', select_country(_('Country'), object_name, 'country', {:class => 'type-select'})) %> 18 <%= optional_field(profile, 'country', select_country(_('Country'), object_name, 'country', {:class => 'type-select'})) %>
19 <%= optional_field(profile, 'tag_list', f.text_field(:tag_list)) %> 19 <%= optional_field(profile, 'tag_list', f.text_field(:tag_list)) %>
20 20
@@ -29,3 +29,4 @@ @@ -29,3 +29,4 @@
29 <%= optional_field(profile, 'acronym', f.text_field(:acronym)) %> 29 <%= optional_field(profile, 'acronym', f.text_field(:acronym)) %>
30 <%= optional_field(profile, 'foundation_year', f.text_field(:foundation_year)) %> 30 <%= optional_field(profile, 'foundation_year', f.text_field(:foundation_year)) %>
31 <% end %> 31 <% end %>
  32 +<%= javascript_include_tag('city_state_validation') %>
config/routes.rb
@@ -31,6 +31,9 @@ ActionController::Routing::Routes.draw do |map| @@ -31,6 +31,9 @@ ActionController::Routing::Routes.draw do |map|
31 map.connect 'thumbnails/*stuff', :controller => 'not_found', :action => 'nothing' 31 map.connect 'thumbnails/*stuff', :controller => 'not_found', :action => 'nothing'
32 map.connect 'user_themes/*stuff', :controller => 'not_found', :action => 'nothing' 32 map.connect 'user_themes/*stuff', :controller => 'not_found', :action => 'nothing'
33 33
  34 + # embed controller
  35 + map.embed 'embed/:action/:id', :controller => 'embed', :id => /\d+/
  36 +
34 # online documentation 37 # online documentation
35 map.doc 'doc', :controller => 'doc', :action => 'index' 38 map.doc 'doc', :controller => 'doc', :action => 'index'
36 map.doc_section 'doc/:section', :controller => 'doc', :action => 'section' 39 map.doc_section 'doc/:section', :controller => 'doc', :action => 'section'
features/balloon.feature
@@ -8,6 +8,7 @@ Feature: balloon @@ -8,6 +8,7 @@ Feature: balloon
8 And the following communities 8 And the following communities
9 | identifier | name | 9 | identifier | name |
10 | sample | Sample | 10 | sample | Sample |
  11 + And I am logged in as "joaosilva"
11 12
12 @selenium 13 @selenium
13 Scenario: I should not see trigger if not enabled 14 Scenario: I should not see trigger if not enabled
features/categories_block.feature
@@ -24,16 +24,12 @@ Feature: categories_block @@ -24,16 +24,12 @@ Feature: categories_block
24 | owner | type | 24 | owner | type |
25 | environment | CategoriesBlock | 25 | environment | CategoriesBlock |
26 And I am logged in as admin 26 And I am logged in as admin
  27 + And I go to /admin/environment_design
  28 + And display ".button-bar"
27 29
28 - # Note that this @ignore-hidden-elements only works for seeing hidden  
29 - # elements. It actually doesn't work for following hidden link or pressing  
30 - # hidden buttons. That's why it's necessary to use this display hack to show  
31 - # the link.  
32 - @selenium @ignore-hidden-elements 30 + @selenium
33 Scenario: List just product categories 31 Scenario: List just product categories
34 - Given I go to /admin/environment_design  
35 - And display ".categories-block .button-bar"  
36 - And I follow "Edit" within ".categories-block" 32 + Given I follow "Edit" within ".categories-block"
37 And I check "Product" 33 And I check "Product"
38 When I press "Save" 34 When I press "Save"
39 Then I should see "Food" 35 Then I should see "Food"
@@ -42,11 +38,9 @@ Feature: categories_block @@ -42,11 +38,9 @@ Feature: categories_block
42 And "Steak" should not be visible within "span#category-name" 38 And "Steak" should not be visible within "span#category-name"
43 And "Fiction" should not be visible within "span#category-name" 39 And "Fiction" should not be visible within "span#category-name"
44 40
45 - @selenium @ignore-hidden-elements 41 + @selenium
46 Scenario: Show submenu if it exists 42 Scenario: Show submenu if it exists
47 - Given I go to /admin/environment_design  
48 - And display ".categories-block .button-bar"  
49 - And I follow "Edit" within ".categories-block" 43 + Given I follow "Edit" within ".categories-block"
50 And I check "Product" 44 And I check "Product"
51 And I press "Save" 45 And I press "Save"
52 Then I should see "Food" 46 Then I should see "Food"
@@ -61,11 +55,9 @@ Feature: categories_block @@ -61,11 +55,9 @@ Feature: categories_block
61 And I should see "Steak" 55 And I should see "Steak"
62 And I should not see "Fiction" 56 And I should not see "Fiction"
63 57
64 - @selenium @ignore-hidden-elements 58 + @selenium
65 Scenario: Show only one submenu per time 59 Scenario: Show only one submenu per time
66 - Given I go to /admin/environment_design  
67 - And display ".categories-block .button-bar"  
68 - And I follow "Edit" within ".categories-block" 60 + Given I follow "Edit" within ".categories-block"
69 And I check "Product" 61 And I check "Product"
70 And I press "Save" 62 And I press "Save"
71 Then I should see "Book" 63 Then I should see "Book"
@@ -73,20 +65,16 @@ Feature: categories_block @@ -73,20 +65,16 @@ Feature: categories_block
73 When I follow "block_2_category_2" 65 When I follow "block_2_category_2"
74 Then I should see "Literature" 66 Then I should see "Literature"
75 67
76 - @selenium @ignore-hidden-elements 68 + @selenium
77 Scenario: List just general categories 69 Scenario: List just general categories
78 - Given I go to /admin/environment_design  
79 - And display ".categories-block .button-bar"  
80 - And I follow "Edit" within ".categories-block" 70 + Given I follow "Edit" within ".categories-block"
81 And I check "Generic category" 71 And I check "Generic category"
82 When I press "Save" 72 When I press "Save"
83 Then I should see "Wood" 73 Then I should see "Wood"
84 74
85 - @selenium @ignore-hidden-elements 75 + @selenium
86 Scenario: List just regions 76 Scenario: List just regions
87 - Given I go to /admin/environment_design  
88 - And display ".categories-block .button-bar"  
89 - And I follow "Edit" within ".categories-block" 77 + Given I follow "Edit" within ".categories-block"
90 And I check "Region" 78 And I check "Region"
91 When I press "Save" 79 When I press "Save"
92 Then I should see "Bahia" 80 Then I should see "Bahia"
features/comment.feature
@@ -39,7 +39,7 @@ Feature: comment @@ -39,7 +39,7 @@ Feature: comment
39 When I press "Post comment" 39 When I press "Post comment"
40 Then I should see "Hey ho, let's go" 40 Then I should see "Hey ho, let's go"
41 41
42 - @selenium 42 + @selenium-fixme
43 Scenario: redirect to right place after comment a picture 43 Scenario: redirect to right place after comment a picture
44 Given the following files 44 Given the following files
45 | owner | file | mime | 45 | owner | file | mime |
@@ -97,3 +97,41 @@ Feature: comment @@ -97,3 +97,41 @@ Feature: comment
97 Given I am on /booking/article-to-comment 97 Given I am on /booking/article-to-comment
98 And I follow "Post a comment" 98 And I follow "Post a comment"
99 Then "Post a comment" should not be visible within "#article" 99 Then "Post a comment" should not be visible within "#article"
  100 +
  101 + @selenium
  102 + Scenario: the newest post from a forum should be displayed first.
  103 + Given the following users
  104 + | login | name |
  105 + | joaosilva | Joao Silva |
  106 + And the following forums
  107 + | owner | name |
  108 + | joaosilva | Forum |
  109 + And the following articles
  110 + | owner | name | parent |
  111 + | joaosilva | Post one | Forum |
  112 + And the following comments
  113 + | article | author | title | body |
  114 + | Post one | joaosilva | Hi all | Hi all |
  115 + | Post one | joaosilva | Hello | Hello |
  116 + When I go to /joaosilva/forum/post-one
  117 + And I select "Newest first" from "comment_order" within ".comment-order"
  118 + Then I should see "Hello" within ".article-comment"
  119 +
  120 + @selenium
  121 + Scenario: the oldest post from a forum should be displayed first.
  122 + Given the following users
  123 + | login | name |
  124 + | joaosilva | Joao Silva |
  125 + And the following forums
  126 + | owner | name |
  127 + | joaosilva | Forum |
  128 + And the following articles
  129 + | owner | name | parent |
  130 + | joaosilva | Post one | Forum |
  131 + And the following comments
  132 + | article | author | title | body |
  133 + | Post one | joaosilva | Hi all | Hi all |
  134 + | Post one | joaosilva | Hello | Hello |
  135 + When I go to /joaosilva/forum/post-one
  136 + And I select "Oldest first" from "comment_order" within ".comment-order"
  137 + Then I should see "Hi all" within ".article-comment"
features/short_filename.feature
@@ -1,21 +0,0 @@ @@ -1,21 +0,0 @@
1 -Feature: sitemap  
2 - As a noosfero user  
3 - I want to list articles  
4 -  
5 - Background:  
6 - Given I am on the homepage  
7 - And the following users  
8 - | login | name |  
9 - | joaosilva | Joao Silva |  
10 - And the following files  
11 - | owner | file | mime |  
12 - | joaosilva | AGENDA_CULTURA_-_FESTA_DE_VAQUEIROS_PONTO_DE_SERRA_PRETA_BAIXA.txt | text/plain |  
13 -  
14 - Scenario: view a folder page  
15 - When I am on /profile/joaosilva/sitemap  
16 - Then I should see "AGENDA_CULTURA_-_FESTA_DE_VAQUEIRO(...).txt"  
17 -  
18 - Scenario: view the CMS  
19 - Given I am logged in as "joaosilva"  
20 - When I am on /myprofile/joaosilva/cms  
21 - Then I should see "AGENDA_CULTURA_-_FESTA_DE_VAQUEIROS_PONTO_DE_SERRA_(...).txt"  
features/signup.feature
@@ -29,10 +29,20 @@ Feature: signup @@ -29,10 +29,20 @@ Feature: signup
29 And I press "Log in" 29 And I press "Log in"
30 Then I should be logged in as "josesilva" 30 Then I should be logged in as "josesilva"
31 31
  32 + @selenium
  33 + Scenario: show error message if username is already used
  34 + Given the following users
  35 + | login |
  36 + | josesilva |
  37 + When I go to signup page
  38 + And I fill in "Username" with "josesilva"
  39 + And I fill in "e-Mail" with "josesilva1"
  40 + Then I should see "This login name is unavailable"
  41 +
32 Scenario: be redirected if user goes to signup page and is logged 42 Scenario: be redirected if user goes to signup page and is logged
33 Given the following users 43 Given the following users
34 | login | name | 44 | login | name |
35 - | joaosilva | Joao Silva | 45 + | joaosilva | joao silva |
36 Given I am logged in as "joaosilva" 46 Given I am logged in as "joaosilva"
37 And I go to signup page 47 And I go to signup page
38 Then I should be on joaosilva's control panel 48 Then I should be on joaosilva's control panel
lib/feed_handler.rb
@@ -51,7 +51,6 @@ class FeedHandler @@ -51,7 +51,6 @@ class FeedHandler
51 end 51 end
52 52
53 def process(container) 53 def process(container)
54 - RAILS_DEFAULT_LOGGER.info("Processing %s with id = %d" % [container.class.name, container.id])  
55 begin 54 begin
56 container.class.transaction do 55 container.class.transaction do
57 if container.update_errors > FeedHandler.max_errors && container.fetched_at < (Time.now - FeedHandler.disabled_period) 56 if container.update_errors > FeedHandler.max_errors && container.fetched_at < (Time.now - FeedHandler.disabled_period)
lib/file_presenter.rb
@@ -50,6 +50,10 @@ class FilePresenter @@ -50,6 +50,10 @@ class FilePresenter
50 nil 50 nil
51 end 51 end
52 52
  53 + def download?(view=nil)
  54 + false
  55 + end
  56 +
53 def short_description 57 def short_description
54 file_type = if content_type.present? 58 file_type = if content_type.present?
55 content_type.sub(/^application\//, '').sub(/^x-/, '').sub(/^image\//, '') 59 content_type.sub(/^application\//, '').sub(/^x-/, '').sub(/^image\//, '')
lib/noosfero/plugin.rb
@@ -16,14 +16,7 @@ class Noosfero::Plugin @@ -16,14 +16,7 @@ class Noosfero::Plugin
16 end 16 end
17 17
18 def init_system 18 def init_system
19 - enabled_plugins = Dir.glob(File.join(Rails.root, 'config', 'plugins', '*'))  
20 - if Rails.env.test? && !enabled_plugins.include?(File.join(Rails.root, 'config', 'plugins', 'foo'))  
21 - enabled_plugins << File.join(Rails.root, 'plugins', 'foo')  
22 - end  
23 -  
24 - enabled_plugins.select do |entry|  
25 - File.directory?(entry)  
26 - end.each do |dir| 19 + available_plugins.each do |dir|
27 load_plugin dir 20 load_plugin dir
28 end 21 end
29 end 22 end
@@ -76,12 +69,19 @@ class Noosfero::Plugin @@ -76,12 +69,19 @@ class Noosfero::Plugin
76 klass(plugin_name) 69 klass(plugin_name)
77 end 70 end
78 71
79 - def all  
80 - @all ||= [] 72 + def available_plugins
  73 + unless @available_plugins
  74 + path = File.join(Rails.root, 'config', 'plugins', '*')
  75 + @available_plugins = Dir.glob(path).select{ |i| File.directory?(i) }
  76 + if Rails.env.test? && !@available_plugins.include?(File.join(Rails.root, 'config', 'plugins', 'foo'))
  77 + @available_plugins << File.join(Rails.root, 'plugins', 'foo')
  78 + end
  79 + end
  80 + @available_plugins
81 end 81 end
82 82
83 - def inherited(subclass)  
84 - all << subclass.to_s unless all.include?(subclass.to_s) 83 + def all
  84 + @all ||= available_plugins.map{ |dir| (File.basename(dir) + "_plugin").camelize }
85 end 85 end
86 86
87 def public_name 87 def public_name
lib/tasks/plugins_tests.rake
@@ -25,51 +25,87 @@ def plugin_disabled_warning(plugin) @@ -25,51 +25,87 @@ def plugin_disabled_warning(plugin)
25 puts "E: you should enable #{plugin} plugin before running it's tests!" 25 puts "E: you should enable #{plugin} plugin before running it's tests!"
26 end 26 end
27 27
28 -def run_tests(name, files_glob)  
29 - files = Dir.glob(files_glob)  
30 - if files.empty?  
31 - puts "I: no tests to run (#{name})" 28 +def task2ext(task)
  29 + (task == :selenium || task == :cucumber) ? :feature : :rb
  30 +end
  31 +
  32 +def task2profile(task, plugin)
  33 + if task == :cucumber
  34 + return plugin
  35 + elsif task == :selenium
  36 + return "#{plugin}_selenium"
32 else 37 else
33 - sh 'testrb', '-Itest', *files 38 + return 'default'
34 end 39 end
35 end 40 end
36 41
37 -def run_cucumber(name, profile, files_glob)  
38 - files = Dir.glob(files_glob)  
39 - if files.empty?  
40 - puts "I: no tests to run #{name}" 42 +def filename2plugin(filename)
  43 + filename.split('/')[1]
  44 +end
  45 +
  46 +def task2folder(task)
  47 + result = case task.to_sym
  48 + when :units
  49 + :unit
  50 + when :functionals
  51 + :functional
  52 + when :integration
  53 + :integration
  54 + when :cucumber
  55 + :features
  56 + when :selenium
  57 + :features
  58 + end
  59 +
  60 + return result
  61 +end
  62 +
  63 +def run_test(name, files)
  64 + files = Array(files)
  65 + plugin = filename2plugin(files.first)
  66 + if name == :cucumber || name == :selenium
  67 + run_cucumber task2_profile(name, plugin), files
41 else 68 else
42 - sh 'xvfb-run', 'ruby', '-S', 'cucumber', '--profile', profile.to_s, '--format', ENV['CUCUMBER_FORMAT'] || 'progress' , *files 69 + run_testrb files
43 end 70 end
44 end 71 end
45 72
46 -def plugin_test_task(name, plugin, files_glob)  
47 - desc "Run #{name} tests for #{plugin_name(plugin)}"  
48 - task name => 'db:test:plugins:prepare' do |t|  
49 - if plugin_enabled?(plugin)  
50 - run_tests t.name, files_glob  
51 - else  
52 - plugin_disabled_warning(plugin) 73 +def run_testrb(files)
  74 + sh 'testrb', '-Itest', *files
  75 +end
  76 +
  77 +def run_cucumber(profile, files)
  78 + sh 'xvfb-run', 'ruby', '-S', 'cucumber', '--profile', profile.to_s, '--format', ENV['CUCUMBER_FORMAT'] || 'progress' , *files
  79 +end
  80 +
  81 +def custom_run(name, files, run=:individually)
  82 + case run
  83 + when :all
  84 + run_test name, files
  85 + when :individually
  86 + files.each do |file|
  87 + run_test name, file
53 end 88 end
  89 + when :by_plugin
54 end 90 end
55 end 91 end
56 92
57 -def plugin_cucumber_task(name, plugin, files_glob)  
58 - desc "Run #{name} tests for #{plugin_name(plugin)}"  
59 - task name => 'db:test:plugins:prepare' do |t|  
60 - if plugin_enabled?(plugin)  
61 - run_cucumber t.name, plugin, files_glob  
62 - else  
63 - plugin_disabled_warning(plugin)  
64 - end 93 +def run_tests(name, plugins, run=:individually)
  94 + plugins = Array(plugins)
  95 + glob = "plugins/{#{plugins.join(',')}}/test/#{task2folder(name)}/**/*.#{task2ext(name)}"
  96 + files = Dir.glob(glob)
  97 + if files.empty?
  98 + puts "I: no tests to run #{name}"
  99 + else
  100 + custom_run(name, files, run)
65 end 101 end
66 end 102 end
67 103
68 -def plugin_selenium_task(name, plugin, files_glob) 104 +def plugin_test_task(name, plugin, run=:individually)
69 desc "Run #{name} tests for #{plugin_name(plugin)}" 105 desc "Run #{name} tests for #{plugin_name(plugin)}"
70 task name => 'db:test:plugins:prepare' do |t| 106 task name => 'db:test:plugins:prepare' do |t|
71 if plugin_enabled?(plugin) 107 if plugin_enabled?(plugin)
72 - run_cucumber t.name, "#{plugin}_selenium", files_glob 108 + run_tests(name, plugin, run)
73 else 109 else
74 plugin_disabled_warning(plugin) 110 plugin_disabled_warning(plugin)
75 end 111 end
@@ -98,28 +134,28 @@ namespace :test do @@ -98,28 +134,28 @@ namespace :test do
98 namespace :noosfero_plugins do 134 namespace :noosfero_plugins do
99 all_plugins.each do |plugin| 135 all_plugins.each do |plugin|
100 namespace plugin do 136 namespace plugin do
101 - plugin_test_task :units, plugin, "plugins/#{plugin}/test/unit/**/*.rb"  
102 - plugin_test_task :functionals, plugin, "plugins/#{plugin}/test/functional/**/*.rb"  
103 - plugin_test_task :integration, plugin, "plugins/#{plugin}/test/integration/**/*.rb"  
104 - plugin_cucumber_task :cucumber, plugin, "plugins/#{plugin}/features/**/*.feature"  
105 - plugin_selenium_task :selenium, plugin, "plugins/#{plugin}/features/**/*.feature" 137 + plugin_test_task :units, plugin
  138 + plugin_test_task :functionals, plugin
  139 + plugin_test_task :integration, plugin
  140 + plugin_test_task :cucumber, plugin
  141 + plugin_test_task :selenium, plugin
106 end 142 end
107 143
108 test_sequence_task(plugin, plugin, "#{plugin}:units", "#{plugin}:functionals", "#{plugin}:integration", "#{plugin}:cucumber", "#{plugin}:selenium") 144 test_sequence_task(plugin, plugin, "#{plugin}:units", "#{plugin}:functionals", "#{plugin}:integration", "#{plugin}:cucumber", "#{plugin}:selenium")
109 end 145 end
110 146
111 - { :units => :unit , :functionals => :functional , :integration => :integration }.each do |taskname,folder| 147 + [:units, :functionals, :integration].each do |taskname|
112 task taskname => 'db:test:plugins:prepare' do |t| 148 task taskname => 'db:test:plugins:prepare' do |t|
113 - run_tests t.name, "plugins/{#{enabled_plugins.join(',')}}/test/#{folder}/**/*.rb" 149 + run_tests taskname, enabled_plugins
114 end 150 end
115 end 151 end
116 152
117 task :cucumber => 'db:test:plugins:prepare' do |t| 153 task :cucumber => 'db:test:plugins:prepare' do |t|
118 - run_cucumber t.name, :default, "plugins/{#{enabled_plugins.join(',')}}/test/features/**/*.features" 154 + run_tests :cucumber, enabled_plugins
119 end 155 end
120 156
121 task :selenium => 'db:test:plugins:prepare' do |t| 157 task :selenium => 'db:test:plugins:prepare' do |t|
122 - run_cucumber t.name, :selenium, "plugins/{#{enabled_plugins.join(',')}}/test/features/**/*.features" 158 + run_tests :selenium, enabled_plugins
123 end 159 end
124 160
125 task :temp_enable_all_plugins do 161 task :temp_enable_all_plugins do
plugins/anti_spam/lib/anti_spam_plugin/wrapper.rb
@@ -2,9 +2,10 @@ class AntiSpamPlugin::Wrapper &lt; SimpleDelegator @@ -2,9 +2,10 @@ class AntiSpamPlugin::Wrapper &lt; SimpleDelegator
2 include Rakismet::Model 2 include Rakismet::Model
3 3
4 @@wrappers = [] 4 @@wrappers = []
  5 + cattr_accessor :wrappers
5 6
6 def self.wrap(object) 7 def self.wrap(object)
7 - wrapper = @@wrappers.find { |wrapper| wrapper.wraps?(object) } 8 + wrapper = wrappers.find { |wrapper| wrapper.wraps?(object) }
8 wrapper ? wrapper.new(object) : object 9 wrapper ? wrapper.new(object) : object
9 end 10 end
10 11
@@ -13,6 +14,10 @@ class AntiSpamPlugin::Wrapper &lt; SimpleDelegator @@ -13,6 +14,10 @@ class AntiSpamPlugin::Wrapper &lt; SimpleDelegator
13 end 14 end
14 15
15 def self.inherited(child) 16 def self.inherited(child)
16 - @@wrappers << child 17 + wrappers << child
17 end 18 end
18 end 19 end
  20 +
  21 +Dir.glob(File.join(AntiSpamPlugin.root_path, 'lib', 'anti_spam_plugin', '*_wrapper.rb')) do |file|
  22 + load(file)
  23 +end
plugins/comment_group/test/functional/comment_group_plugin_profile_controller_test.rb
@@ -36,10 +36,10 @@ class CommentGroupPluginProfileControllerTest &lt; ActionController::TestCase @@ -36,10 +36,10 @@ class CommentGroupPluginProfileControllerTest &lt; ActionController::TestCase
36 end 36 end
37 37
38 should 'show first page comments only' do 38 should 'show first page comments only' do
39 - comment1 = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'secondpage', :group_id => 0)  
40 - comment2 = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'firstpage 1', :group_id => 0)  
41 - comment3 = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'firstpage 2', :group_id => 0)  
42 - comment4 = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'firstpage 3', :group_id => 0) 39 + comment1 = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :created_at => Time.now, :body => 'secondpage', :group_id => 0)
  40 + comment2 = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :created_at => Time.now - 1.day, :body => 'firstpage 1', :group_id => 0)
  41 + comment3 = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :created_at => Time.now - 2.days, :body => 'firstpage 2', :group_id => 0)
  42 + comment4 = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :created_at => Time.now - 3.days, :body => 'firstpage 3', :group_id => 0)
43 xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :group_id => 0 43 xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :group_id => 0
44 assert_match /firstpage 1/, @response.body 44 assert_match /firstpage 1/, @response.body
45 assert_match /firstpage 2/, @response.body 45 assert_match /firstpage 2/, @response.body
plugins/community_track/lib/community_track_plugin/track_card_list_block.rb
@@ -12,4 +12,8 @@ class CommunityTrackPlugin::TrackCardListBlock &lt; CommunityTrackPlugin::TrackList @@ -12,4 +12,8 @@ class CommunityTrackPlugin::TrackCardListBlock &lt; CommunityTrackPlugin::TrackList
12 'track_card' 12 'track_card'
13 end 13 end
14 14
  15 + def embedable?
  16 + true
  17 + end
  18 +
15 end 19 end
plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb
@@ -10,7 +10,7 @@ end @@ -10,7 +10,7 @@ end
10 class ContentViewerControllerTest < ActionController::TestCase 10 class ContentViewerControllerTest < ActionController::TestCase
11 11
12 def setup 12 def setup
13 - @profile = fast_create(Community) 13 + @profile = Community.create!(:name => 'Sample community', :identifier => 'sample-community')
14 @track = create_track('track', @profile) 14 @track = create_track('track', @profile)
15 @step = CommunityTrackPlugin::Step.create!(:name => 'step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today, :tool_type => TinyMceArticle.name) 15 @step = CommunityTrackPlugin::Step.create!(:name => 'step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today, :tool_type => TinyMceArticle.name)
16 16
@@ -87,43 +87,35 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -87,43 +87,35 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
87 end 87 end
88 88
89 should 'render a div with block id for track list block' do 89 should 'render a div with block id for track list block' do
90 - box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name)  
91 - @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box)  
92 - @profile.boxes << box 90 + @block = CommunityTrackPlugin::TrackListBlock.create!(:box => @profile.boxes.last)
93 get :view_page, @step.url 91 get :view_page, @step.url
94 assert_tag :tag => 'div', :attributes => { :class => 'track_list', :id => "track_list_#{@block.id}" } 92 assert_tag :tag => 'div', :attributes => { :class => 'track_list', :id => "track_list_#{@block.id}" }
95 end 93 end
96 94
97 should 'render a div with block id for track card list block' do 95 should 'render a div with block id for track card list block' do
98 - box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name)  
99 - @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box)  
100 - @profile.boxes << box 96 + @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => @profile.boxes.last)
101 get :view_page, @step.url 97 get :view_page, @step.url
102 assert_tag :tag => 'div', :attributes => { :class => 'track_list', :id => "track_list_#{@block.id}" } 98 assert_tag :tag => 'div', :attributes => { :class => 'track_list', :id => "track_list_#{@block.id}" }
103 end 99 end
104 100
105 should 'render tracks in track list block' do 101 should 'render tracks in track list block' do
106 - box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name)  
107 - @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box)  
108 - @profile.boxes << box 102 + @block = CommunityTrackPlugin::TrackListBlock.create!(:box => @profile.boxes.last)
109 get :view_page, @step.url 103 get :view_page, @step.url
  104 + file = File.open('result.html', 'w+')
  105 + file.write(@response.body)
  106 + file.close
110 assert_tag :tag => 'div', :attributes => { :class => "item category_#{@track.category_name}" }, :descendant => { :tag => 'div', :attributes => { :class => 'steps' }, :descendant => { :tag => 'span', :attributes => { :class => "step #{@block.status_class(@step)}" } } } 107 assert_tag :tag => 'div', :attributes => { :class => "item category_#{@track.category_name}" }, :descendant => { :tag => 'div', :attributes => { :class => 'steps' }, :descendant => { :tag => 'span', :attributes => { :class => "step #{@block.status_class(@step)}" } } }
111 end 108 end
112 109
113 should 'render tracks in track card list block' do 110 should 'render tracks in track card list block' do
114 - box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name)  
115 - @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box)  
116 - @profile.boxes << box 111 + @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => @profile.boxes.last)
117 get :view_page, @step.url 112 get :view_page, @step.url
118 assert_tag :tag => 'div', :attributes => { :class => "item_card category_#{@track.category_name}" }, :descendant => { :tag => 'div', :attributes => { :class => 'track_content' } } 113 assert_tag :tag => 'div', :attributes => { :class => "item_card category_#{@track.category_name}" }, :descendant => { :tag => 'div', :attributes => { :class => 'track_content' } }
119 assert_tag :tag => 'div', :attributes => { :class => "item_card category_#{@track.category_name}" }, :descendant => { :tag => 'div', :attributes => { :class => 'track_stats' } } 114 assert_tag :tag => 'div', :attributes => { :class => "item_card category_#{@track.category_name}" }, :descendant => { :tag => 'div', :attributes => { :class => 'track_stats' } }
120 end 115 end
121 116
122 should 'render link to display more tracks in track list block' do 117 should 'render link to display more tracks in track list block' do
123 - box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name)  
124 - @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box)  
125 - @profile.boxes << box  
126 - 118 + @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => @profile.boxes.last)
127 (@block.limit+1).times { |i| create_track("track#{i}", @profile) } 119 (@block.limit+1).times { |i| create_track("track#{i}", @profile) }
128 120
129 get :view_page, @step.url 121 get :view_page, @step.url
@@ -131,9 +123,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -131,9 +123,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
131 end 123 end
132 124
133 should 'render link to show all tracks in track list block' do 125 should 'render link to show all tracks in track list block' do
134 - box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name)  
135 - @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box)  
136 - @profile.boxes << box 126 + @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => @profile.boxes.last)
137 @block.more_another_page = true 127 @block.more_another_page = true
138 @block.save! 128 @block.save!
139 129
plugins/pg_search/lib/ext/active_record.rb
@@ -2,11 +2,9 @@ require_dependency &#39;active_record&#39; @@ -2,11 +2,9 @@ require_dependency &#39;active_record&#39;
2 2
3 class ActiveRecord::Base 3 class ActiveRecord::Base
4 def self.pg_search_plugin_search(query) 4 def self.pg_search_plugin_search(query)
5 - query.gsub!(/\|/,' ')  
6 - formatted_query = query.split.map{|w| w += ":*"}.join('|')  
7 - 5 + filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|')
8 if defined?(self::SEARCHABLE_FIELDS) 6 if defined?(self::SEARCHABLE_FIELDS)
9 - where("to_tsvector('simple', #{pg_search_plugin_fields}) @@ to_tsquery('#{formatted_query}')") 7 + where("to_tsvector('simple', #{pg_search_plugin_fields}) @@ to_tsquery('#{filtered_query}')")
10 else 8 else
11 raise "No searchable fields defined for #{self.name}" 9 raise "No searchable fields defined for #{self.name}"
12 end 10 end
plugins/pg_search/test/unit/pg_search_plugin_test.rb
@@ -21,6 +21,11 @@ class PgSearchPluginTest &lt; ActiveSupport::TestCase @@ -21,6 +21,11 @@ class PgSearchPluginTest &lt; ActiveSupport::TestCase
21 assert_includes search(Profile, 'admin deb'), profile2 21 assert_includes search(Profile, 'admin deb'), profile2
22 end 22 end
23 23
  24 + should 'locate profile escaping special characters' do
  25 + profile = fast_create(Profile, :name => 'John', :identifier => 'waterfall')
  26 + assert_includes search(Profile, ') ( /\/\/\/\/\ o_o oOo o_o /\/\/\/\/\ ) ((tx waterfall)'), profile
  27 + end
  28 +
24 # TODO This feature is available only on Postgresql 9.0 29 # TODO This feature is available only on Postgresql 9.0
25 # http://www.postgresql.org/docs/9.0/static/unaccent.html 30 # http://www.postgresql.org/docs/9.0/static/unaccent.html
26 # should 'ignore accents' do 31 # should 'ignore accents' do
plugins/recent_content/test/unit/recent_content_block_test.rb
@@ -61,9 +61,9 @@ class RecentContentBlockTest &lt; ActiveSupport::TestCase @@ -61,9 +61,9 @@ class RecentContentBlockTest &lt; ActiveSupport::TestCase
61 61
62 root = fast_create(Blog, :name => 'test-blog', :profile_id => profile.id) 62 root = fast_create(Blog, :name => 'test-blog', :profile_id => profile.id)
63 63
64 - a1 = fast_create(TextileArticle, :name => 'article #1', :profile_id => profile.id, :parent_id => root.id)  
65 - a2 = fast_create(TextileArticle, :name => 'article #2', :profile_id => profile.id, :parent_id => root.id)  
66 - a3 = fast_create(TextileArticle, :name => 'article #3', :profile_id => profile.id, :parent_id => root.id) 64 + a1 = fast_create(TextileArticle, :name => 'article #1', :profile_id => profile.id, :parent_id => root.id, :created_at => Time.now - 2.days)
  65 + a2 = fast_create(TextileArticle, :name => 'article #2', :profile_id => profile.id, :parent_id => root.id, :created_at => Time.now - 1.days)
  66 + a3 = fast_create(TextileArticle, :name => 'article #3', :profile_id => profile.id, :parent_id => root.id, :created_at => Time.now)
67 67
68 block = RecentContentBlock.new 68 block = RecentContentBlock.new
69 block.stubs(:holder).returns(profile) 69 block.stubs(:holder).returns(profile)
plugins/relevant_content/lib/ext/article.rb 0 → 100644
@@ -0,0 +1,95 @@ @@ -0,0 +1,95 @@
  1 +require_dependency 'article'
  2 +
  3 +class Article
  4 +
  5 + named_scope :relevant_content, :conditions => ["articles.published = true and (articles.type != 'UploadedFile' and articles.type != 'Blog' and articles.type != 'RssFeed') OR articles.type is NULL"]
  6 +
  7 + def self.articles_columns
  8 + Article.column_names.map {|c| "articles.#{c}"} .join(",")
  9 + end
  10 +
  11 + def self.most_accessed(owner, limit = nil)
  12 + conditions = owner.kind_of?(Environment) ? ["hits > 0"] : ["profile_id = ? and hits > 0", owner.id]
  13 + result = Article.relevant_content.find(
  14 + :all,
  15 + :order => 'hits desc',
  16 + :limit => limit,
  17 + :conditions => conditions)
  18 + result.paginate({:page => 1, :per_page => limit})
  19 + end
  20 +
  21 + def self.most_commented_relevant_content(owner, limit)
  22 + conditions = owner.kind_of?(Environment) ? ["comments_count > 0"] : ["profile_id = ? and comments_count > 0", owner.id]
  23 + result = Article.relevant_content.find(
  24 + :all,
  25 + :order => 'comments_count desc',
  26 + :limit => limit,
  27 + :conditions => conditions)
  28 + result.paginate({:page => 1, :per_page => limit})
  29 + end
  30 +
  31 + def self.more_positive_votes(owner, limit = nil)
  32 + conditions = owner.kind_of?(Environment) ? {'votes.voteable_type' => 'Article'} : ["profile_id = ? and votes.voteable_type = ? ", owner.id, 'Article']
  33 + result = Article.relevant_content.find(
  34 + :all,
  35 + :order => 'sum(vote) desc',
  36 + :group => 'voteable_id, ' + articles_columns,
  37 + :limit => limit,
  38 + :having => ['sum(vote) > 0'],
  39 + :conditions => conditions,
  40 + :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id')
  41 + result.paginate({:page => 1, :per_page => limit})
  42 + end
  43 +
  44 + def self.more_negative_votes(owner, limit = nil)
  45 + conditions = owner.kind_of?(Environment) ? {'votes.voteable_type' => 'Article'} : ["profile_id = ? and votes.voteable_type = 'Article' ", owner.id]
  46 + result = Article.relevant_content.find(
  47 + :all,
  48 + :order => 'sum(vote) asc',
  49 + :group => 'voteable_id, ' + articles_columns,
  50 + :limit => limit,
  51 + :having => ['sum(vote) < 0'],
  52 + :conditions => conditions,
  53 + :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id'
  54 + )
  55 + result.paginate({:page => 1, :per_page => limit})
  56 + end
  57 +
  58 + def self.most_liked(owner, limit = nil)
  59 + conditions = owner.kind_of?(Environment) ? ["votes.voteable_type = 'Article' and vote > 0"] : ["votes.voteable_type = 'Article' and vote > 0 and profile_id = ? ", owner.id]
  60 + result = Article.relevant_content.find(
  61 + :all,
  62 + :select => articles_columns,
  63 + :order => 'count(voteable_id) desc',
  64 + :group => 'voteable_id, ' + articles_columns,
  65 + :limit => limit,
  66 + :conditions => conditions,
  67 + :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id')
  68 + result.paginate({:page => 1, :per_page => limit})
  69 + end
  70 +
  71 + def self.most_disliked(owner, limit = nil)
  72 + conditions = owner.kind_of?(Environment) ? ["votes.voteable_type = 'Article' and vote < 0"] : ["votes.voteable_type = 'Article' and vote < 0 and profile_id = ? ", owner.id]
  73 + result = Article.relevant_content.find(
  74 + :all,
  75 + :order => 'count(voteable_id) desc',
  76 + :group => 'voteable_id, ' + articles_columns,
  77 + :limit => limit,
  78 + :conditions => conditions,
  79 + :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id')
  80 + result.paginate({:page => 1, :per_page => limit})
  81 + end
  82 +
  83 + def self.most_voted(owner, limit = nil)
  84 + conditions = owner.kind_of?(Environment) ? ["votes.voteable_type = 'Article'"] : ["votes.voteable_type = 'Article' and profile_id = ? ", owner.id]
  85 + result = Article.relevant_content.find(
  86 + :all,
  87 + :select => articles_columns,
  88 + :order => 'count(voteable_id) desc',
  89 + :group => 'voteable_id, ' + articles_columns,
  90 + :limit => limit,
  91 + :conditions => conditions,
  92 + :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id')
  93 + result.paginate({:page => 1, :per_page => limit})
  94 + end
  95 +end
plugins/relevant_content/lib/relevant_content_plugin.rb 0 → 100644
@@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
  1 +class RelevantContentPlugin < Noosfero::Plugin
  2 +
  3 + def self.plugin_name
  4 + "Relevant Content Plugin"
  5 + end
  6 +
  7 + def self.plugin_description
  8 + _("A plugin that lists the most accessed, most commented, most liked and most disliked contents.")
  9 + end
  10 +
  11 + def self.extra_blocks
  12 + {
  13 + RelevantContentPlugin::RelevantContentBlock => {}
  14 + }
  15 + end
  16 +
  17 + def stylesheet?
  18 + true
  19 + end
  20 +
  21 +end
plugins/relevant_content/lib/relevant_content_plugin/relevant_content_block.rb 0 → 100644
@@ -0,0 +1,93 @@ @@ -0,0 +1,93 @@
  1 +class RelevantContentPlugin::RelevantContentBlock < Block
  2 + def self.description
  3 + _('Relevant content')
  4 + end
  5 +
  6 + def default_title
  7 + _('Relevant content')
  8 + end
  9 +
  10 + def help
  11 + _('This block lists the most popular content.')
  12 + end
  13 +
  14 + settings_items :limit, :type => :integer, :default => 5
  15 + settings_items :show_most_read, :type => :boolean, :default => 1
  16 + settings_items :show_most_commented, :type => :boolean, :default => 1
  17 + settings_items :show_most_liked, :type => :boolean, :default => 1
  18 + settings_items :show_most_disliked, :type => :boolean, :default => 0
  19 + settings_items :show_most_voted, :type => :boolean, :default => 1
  20 +
  21 + include ActionController::UrlWriter
  22 + def content(args={})
  23 +
  24 + content = block_title(title)
  25 +
  26 + if self.show_most_read
  27 + docs = Article.most_accessed(owner, self.limit)
  28 + if !docs.blank?
  29 + subcontent = ""
  30 + subcontent += content_tag(:span, _("Most read articles"), :class=>"title mread") + "\n"
  31 + subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n"))
  32 + content += content_tag(:div, subcontent, :class=>"block mread") + "\n"
  33 + end
  34 + end
  35 +
  36 + if self.show_most_commented
  37 + docs = Article.most_commented_relevant_content(owner, self.limit)
  38 + if !docs.blank?
  39 + subcontent = ""
  40 + subcontent += content_tag(:span, _("Most commented articles"), :class=>"title mcommented") + "\n"
  41 + subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n"))
  42 + content += content_tag(:div, subcontent, :class=>"block mcommented") + "\n"
  43 + end
  44 + end
  45 +
  46 + if owner.kind_of?(Environment)
  47 + env = owner
  48 + else
  49 + env = owner.environment
  50 + end
  51 +
  52 + if env.plugin_enabled?(VotePlugin)
  53 + if self.show_most_liked
  54 + docs = Article.more_positive_votes(owner, self.limit)
  55 + if !docs.blank?
  56 + subcontent = ""
  57 + subcontent += content_tag(:span, _("Most liked articles"), :class=>"title mliked") + "\n"
  58 + subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n"))
  59 + content += content_tag(:div, subcontent, :class=>"block mliked") + "\n"
  60 + end
  61 + end
  62 + if self.show_most_disliked
  63 + docs = Article.more_negative_votes(owner, self.limit)
  64 + if !docs.blank?
  65 + subcontent = ""
  66 + subcontent += content_tag(:span, _("Most disliked articles"), :class=>"title mdisliked") + "\n"
  67 + subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n"))
  68 + content += content_tag(:div, subcontent, :class=>"block mdisliked") + "\n"
  69 + end
  70 + end
  71 +
  72 + if self.show_most_voted
  73 + docs = Article.most_voted(owner, self.limit)
  74 + if !docs.blank?
  75 + subcontent = ""
  76 + subcontent += content_tag(:span, _("Most voted articles"), :class=>"title mvoted") + "\n"
  77 + subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n"))
  78 + content += content_tag(:div, subcontent, :class=>"block mvoted") + "\n"
  79 + end
  80 + end
  81 + end
  82 + return content
  83 + end
  84 +
  85 + def timeout
  86 + 4.hours
  87 + end
  88 +
  89 + def self.expire_on
  90 + { :profile => [:article], :environment => [:article] }
  91 + end
  92 +
  93 +end
0 \ No newline at end of file 94 \ No newline at end of file
plugins/relevant_content/public/style.css 0 → 100644
@@ -0,0 +1,79 @@ @@ -0,0 +1,79 @@
  1 +#content .relevant-content-plugin_relevant-content-block {
  2 + padding: 10px 0px 10px 10px;
  3 + word-wrap: break-word;
  4 +}
  5 +
  6 +.relevant-content-plugin_relevant-content-block ul {
  7 + margin: 0px;
  8 + padding: 0px 0px 0px 20px;
  9 +}
  10 +.relevant-content-plugin_relevant-content-block li {
  11 + margin: 0px;
  12 + padding: 0px;
  13 + list-style: none
  14 +}
  15 +.relevant-content-plugin_relevant-content-block a {
  16 + text-decoration: none;
  17 +}
  18 +.relevant-content-plugin_relevant-content-block .block-footer-content {
  19 + font-size: 10px;
  20 +}
  21 +.relevant-content-plugin_relevant-content-block .block-footer-content a:hover {
  22 + text-decoration: underline;
  23 +}
  24 +
  25 +.relevant-content-plugin_relevant-content-block p {
  26 + text-align:center;
  27 +}
  28 +
  29 +.relevant-content-plugin_relevant-content-block p.like{
  30 + background-image: url('images/positive-hand.png');
  31 + background-repeat: no-repeat;
  32 + min-width: 50px;
  33 + text-align:center;
  34 +}
  35 +
  36 +.relevant-content-plugin_relevant-content-block p.dislike{
  37 + background-image: url('images/negative-hand.png');
  38 + background-repeat: no-repeat;
  39 + min-width: 50px;
  40 + text-align:center;
  41 +}
  42 +
  43 +
  44 +.relevant-content-plugin_relevant-content-block {
  45 + //overflow: hidden;
  46 + display: block;
  47 + width: 100%;
  48 +}
  49 +
  50 +
  51 +.relevant-content-cover img {
  52 + width: 100%;
  53 +}
  54 +
  55 +.relevant-content-plugin_relevant-content-block span.title {
  56 + display: block;
  57 + margin: 20px 0px 0px;
  58 + padding: 0px 0px 0px 20px;
  59 +}
  60 +
  61 +.relevant-content-plugin_relevant-content-block span.title.mread {
  62 +
  63 +}
  64 +
  65 +.relevant-content-plugin_relevant-content-block span.title.mcommented {
  66 +
  67 +}
  68 +
  69 +.relevant-content-plugin_relevant-content-block span.title.mliked {
  70 +
  71 +}
  72 +
  73 +.relevant-content-plugin_relevant-content-block span.title.mdisliked {
  74 +
  75 +}
  76 +
  77 +.relevant-content-plugin_relevant-content-block span.title.mvoted {
  78 +
  79 +}
plugins/relevant_content/test/test_helper.rb 0 → 100644
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +require File.dirname(__FILE__) + '/../../../test/test_helper'
plugins/relevant_content/test/unit/article.rb 0 → 100644
@@ -0,0 +1,148 @@ @@ -0,0 +1,148 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +require 'comment_controller'
  4 +# Re-raise errors caught by the controller.
  5 +class CommentController; def rescue_action(e) raise e end; end
  6 +
  7 +class RelevantContentBlockTest < ActiveSupport::TestCase
  8 +
  9 + include AuthenticatedTestHelper
  10 + fixtures :users, :environments
  11 +
  12 + def setup
  13 + @controller = CommentController.new
  14 + @request = ActionController::TestRequest.new
  15 + @response = ActionController::TestResponse.new
  16 + @profile = create_user('testinguser').person
  17 + @environment = @profile.environment
  18 + end
  19 + attr_reader :profile, :environment
  20 +
  21 + def enable_vote_plugin
  22 + enabled = false
  23 + environment=Environment.default
  24 + if Noosfero::Plugin.all.include?('VotePlugin')
  25 + if not environment.enabled_plugins.include?(:vote)
  26 + environment.enable_plugin(Vote)
  27 + environment.save!
  28 + end
  29 + enabled = true
  30 + end
  31 + enabled
  32 + end
  33 +
  34 + should 'list most commented articles' do
  35 + Article.delete_all
  36 + a1 = create(TextileArticle, :name => "art 1", :profile_id => profile.id)
  37 + a2 = create(TextileArticle, :name => "art 2", :profile_id => profile.id)
  38 + a3 = create(TextileArticle, :name => "art 3", :profile_id => profile.id)
  39 +
  40 + 2.times { Comment.create(:title => 'test', :body => 'asdsad', :author => profile, :source => a2).save! }
  41 + 4.times { Comment.create(:title => 'test', :body => 'asdsad', :author => profile, :source => a3).save! }
  42 +
  43 + # should respect the order (more commented comes first)
  44 + assert_equal a3.name, profile.articles.most_commented_relevant_content(Environment.default, 3).first.name
  45 + # It is a2 instead of a1 since it does not list articles without comments
  46 + assert_equal a2.name, profile.articles.most_commented_relevant_content(Environment.default, 3).last.name
  47 + end
  48 +
  49 +
  50 + should 'find the most voted' do
  51 + if not enable_vote_plugin
  52 + return
  53 + end
  54 + article = fast_create(Article, {:name=>'2 votes'})
  55 + 2.times{
  56 + person = fast_create(Person)
  57 + person.vote_for(article)
  58 + }
  59 + article = fast_create(Article, {:name=>'10 votes'})
  60 + 10.times{
  61 + person = fast_create(Person)
  62 + person.vote_for(article)
  63 + }
  64 + article = fast_create(Article, {:name=>'5 votes'})
  65 + 5.times{
  66 + person = fast_create(Person)
  67 + person.vote_for(article)
  68 + }
  69 + articles = Article.most_voted(Environment.default, 5)
  70 + assert_equal '10 votes', articles.first.name
  71 + assert_equal '2 votes', articles.last.name
  72 + end
  73 +
  74 + should 'list the most postive' do
  75 + if not enable_vote_plugin
  76 + return
  77 + end
  78 + article = fast_create(Article, {:name=>'23 votes for 20 votes against'})
  79 + 20.times{
  80 + person = fast_create(Person)
  81 + person.vote_against(article)
  82 + }
  83 + 23.times{
  84 + person = fast_create(Person)
  85 + person.vote_for(article)
  86 + }
  87 + article = fast_create(Article, {:name=>'10 votes for 5 votes against'})
  88 + 10.times{
  89 + person = fast_create(Person)
  90 + person.vote_for(article)
  91 + }
  92 + 5.times{
  93 + person = fast_create(Person)
  94 + person.vote_against(article)
  95 + }
  96 + article = fast_create(Article, {:name=>'2 votes against'})
  97 + 2.times{
  98 + person = fast_create(Person)
  99 + person.vote_against(article)
  100 + }
  101 +
  102 + article = fast_create(Article, {:name=>'7 votes for'})
  103 + 7.times{
  104 + person = fast_create(Person)
  105 + person.vote_for(article)
  106 + }
  107 + articles = Article.more_positive_votes(Environment.default, 5)
  108 + assert_equal '7 votes for', articles.first.name
  109 + assert_equal '23 votes for 20 votes against', articles.last.name
  110 + end
  111 +
  112 + should 'list the most negative' do
  113 + if not enable_vote_plugin
  114 + return
  115 + end
  116 + article = fast_create(Article, {:name=>'23 votes for 29 votes against'})
  117 + 29.times{
  118 + person = fast_create(Person)
  119 + person.vote_against(article)
  120 + }
  121 + 23.times{
  122 + person = fast_create(Person)
  123 + person.vote_for(article)
  124 + }
  125 + article = fast_create(Article, {:name=>'10 votes for 15 votes against'})
  126 + 10.times{
  127 + person = fast_create(Person)
  128 + person.vote_for(article)
  129 + }
  130 + 15.times{
  131 + person = fast_create(Person)
  132 + person.vote_against(article)
  133 + }
  134 + article = fast_create(Article, {:name=>'2 votes against'})
  135 + 2.times{
  136 + person = fast_create(Person)
  137 + person.vote_against(article)
  138 + }
  139 + article = fast_create(Article, {:name=>'7 votes for'})
  140 + 7.times{
  141 + person = fast_create(Person)
  142 + person.vote_for(article)
  143 + }
  144 + articles = Article.more_negative_votes(Environment.default, 5)
  145 + assert_equal '23 votes for 29 votes against', articles.first.name
  146 + assert_equal '2 votes against', articles.last.name
  147 + end
  148 +end
0 \ No newline at end of file 149 \ No newline at end of file
plugins/relevant_content/test/unit/relevant_content_block_test.rb 0 → 100644
@@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +require 'comment_controller'
  4 +# Re-raise errors caught by the controller.
  5 +class CommentController; def rescue_action(e) raise e end; end
  6 +
  7 +class RelevantContentBlockTest < ActiveSupport::TestCase
  8 +
  9 + include AuthenticatedTestHelper
  10 + fixtures :users, :environments
  11 +
  12 + def setup
  13 + @controller = CommentController.new
  14 + @request = ActionController::TestRequest.new
  15 + @response = ActionController::TestResponse.new
  16 +
  17 + @profile = create_user('testinguser').person
  18 + @environment = @profile.environment
  19 + end
  20 + attr_reader :profile, :environment
  21 +
  22 + should 'have a default title' do
  23 + relevant_content_block = RelevantContentPlugin::RelevantContentBlock.new
  24 + block = Block.new
  25 + assert_not_equal block.default_title, relevant_content_block.default_title
  26 + end
  27 +
  28 + should 'have a help tooltip' do
  29 + relevant_content_block = RelevantContentPlugin::RelevantContentBlock.new
  30 + block = Block.new
  31 + assert_not_equal "", relevant_content_block.help
  32 + end
  33 +
  34 + should 'describe itself' do
  35 + assert_not_equal Block.description, RelevantContentPlugin::RelevantContentBlock.description
  36 + end
  37 +
  38 + should 'is editable' do
  39 + block = RelevantContentPlugin::RelevantContentBlock.new
  40 + assert block.editable?
  41 + end
  42 +
  43 + should 'expire' do
  44 + assert_equal RelevantContentPlugin::RelevantContentBlock.expire_on, {:environment=>[:article], :profile=>[:article]}
  45 + end
  46 +
  47 +end
plugins/relevant_content/test/unit/relevant_content_plugin_test.rb 0 → 100644
@@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class RelevantContentPluginTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @plugin = RelevantContentPlugin.new
  7 + end
  8 +
  9 + should 'be a noosfero plugin' do
  10 + assert_kind_of Noosfero::Plugin, @plugin
  11 + end
  12 +
  13 + should 'have name' do
  14 + assert_equal 'Relevant Content Plugin', RelevantContentPlugin.plugin_name
  15 + end
  16 +
  17 + should 'have description' do
  18 + assert_equal _("A plugin that lists the most accessed, most commented, most liked and most disliked contents."), RelevantContentPlugin.plugin_description
  19 + end
  20 +
  21 + should 'have stylesheet' do
  22 + assert @plugin.stylesheet?
  23 + end
  24 +
  25 + should "return RelevantContentBlock in extra_blocks class method" do
  26 + assert RelevantContentPlugin.extra_blocks.keys.include?(RelevantContentPlugin::RelevantContentBlock)
  27 + end
  28 +
  29 +end
plugins/relevant_content/views/box_organizer/relevant_content_plugin/_relevant_content_block.rhtml 0 → 100644
@@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
  1 +<div id='edit-relevant-content-block'>
  2 + <%= labelled_form_field _('Limit of items per category'), text_field(:block, :limit, :size => 3) %>
  3 + <%= labelled_check_box _('Display most accessed content'), "block[show_most_read]", 1 ,@block.show_most_read %><BR>
  4 + <%= labelled_check_box _('Display most commented content'), "block[show_most_commented]", 1 ,@block.show_most_commented %><BR>
  5 + <%= labelled_check_box _('Display most liked content'), "block[show_most_liked]", 1 ,@block.show_most_liked %><BR>
  6 + <%= labelled_check_box _('Display most voted content'), "block[show_most_voted]", 1 ,@block.show_most_voted %><BR>
  7 + <%= labelled_check_box _('Display most disliked content'), "block[show_most_disliked]", 1 , @block.show_most_disliked %><BR>
  8 +</div>
0 \ No newline at end of file 9 \ No newline at end of file
plugins/relevant_content/views/environment_design/relevant_content_plugin 0 → 120000
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +../box_organizer/relevant_content_plugin
0 \ No newline at end of file 2 \ No newline at end of file
plugins/relevant_content/views/profile_design/relevant_content_plugin 0 → 120000
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +../box_organizer/relevant_content_plugin
0 \ No newline at end of file 2 \ No newline at end of file
public/designs/icons/tango/style.css
1 /******************SMALL ICONS********************/ 1 /******************SMALL ICONS********************/
  2 +.icon-embed { background-image: url(Tango/16x16/apps/utilities-terminal.png) }
2 .icon-edit { background-image: url(Tango/16x16/apps/text-editor.png) } 3 .icon-edit { background-image: url(Tango/16x16/apps/text-editor.png) }
3 .icon-home { background-image: url(Tango/16x16/actions/go-home.png) } 4 .icon-home { background-image: url(Tango/16x16/actions/go-home.png) }
4 .icon-home-not { background-image: url(mod/16x16/actions/go-home-not.png) } 5 .icon-home-not { background-image: url(mod/16x16/actions/go-home-not.png) }
public/designs/themes/base/style.css
@@ -1275,6 +1275,11 @@ hr.pre-posts, hr.sep-posts { @@ -1275,6 +1275,11 @@ hr.pre-posts, hr.sep-posts {
1275 padding-right: 9px; 1275 padding-right: 9px;
1276 } 1276 }
1277 1277
  1278 +.comment-order {
  1279 + float: right;
  1280 + display: block;
  1281 +}
  1282 +
1278 .comment-from-owner .comment-created-at { 1283 .comment-from-owner .comment-created-at {
1279 color: #333; 1284 color: #333;
1280 } 1285 }
public/images/drag-and-drop.png 0 → 100644

1.11 KB

public/javascripts/application.js
@@ -1101,4 +1101,4 @@ jQuery(document).ready(function(){ @@ -1101,4 +1101,4 @@ jQuery(document).ready(function(){
1101 jQuery("#article_has_terms_of_use").click(function(){ 1101 jQuery("#article_has_terms_of_use").click(function(){
1102 showHideTermsOfUse(); 1102 showHideTermsOfUse();
1103 }); 1103 });
1104 -});  
1105 \ No newline at end of file 1104 \ No newline at end of file
  1105 +});
public/javascripts/city_state_validation.js 0 → 100644
@@ -0,0 +1,60 @@ @@ -0,0 +1,60 @@
  1 +(function($){
  2 + autoCompleteStateCity($);
  3 + $('[id$="_country"]').change(function(){
  4 + autoCompleteStateCity($);
  5 + })
  6 +})(jQuery);
  7 +
  8 +function autoCompleteStateCity($) {
  9 + var country_selected = $('[id$="_country"] option:selected').val()
  10 + if(country_selected == "BR")
  11 + {
  12 + $('#state_field').autocomplete({
  13 + source : function(request, response){
  14 + $.ajax({
  15 + type: "GET",
  16 + url: '/account/search_state',
  17 + data: {state_name: request.term},
  18 + success: function(result){
  19 + response(result);
  20 + },
  21 + error: function(ajax, stat, errorThrown) {
  22 + console.log('Link not found : ' + errorThrown);
  23 + }
  24 + });
  25 + },
  26 +
  27 + minLength: 3
  28 + });
  29 +
  30 + $('#city_field').autocomplete({
  31 + source : function(request, response){
  32 + $.ajax({
  33 + type: "GET",
  34 + url: '/account/search_cities',
  35 + data: {city_name: request.term, state_name: $("#state_field").val()},
  36 + success: function(result){
  37 + response(result);
  38 + },
  39 + error: function(ajax, stat, errorThrown) {
  40 + console.log('Link not found : ' + errorThrown);
  41 + }
  42 + });
  43 + },
  44 +
  45 + minLength: 3
  46 + });
  47 + }
  48 + else
  49 + {
  50 + if ($('#state_field').data('autocomplete')) {
  51 + $('#state_field').autocomplete("destroy");
  52 + $('#state_field').removeData('autocomplete');
  53 + }
  54 +
  55 + if ($('#city_field').data('autocomplete')) {
  56 + $('#city_field').autocomplete("destroy");
  57 + $('#city_field').removeData('autocomplete');
  58 + }
  59 + }
  60 +}
public/javascripts/comment_order.js 0 → 100644
@@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
  1 +function send_order(order, url) {
  2 + open_loading(DEFAULT_LOADING_MESSAGE);
  3 +
  4 + jQuery.ajax({
  5 + url:url,
  6 + data: {"comment_order":order},
  7 + success: function(response) {
  8 + close_loading();
  9 + jQuery(".article-comments-list").html(response);
  10 + },
  11 + error: function() { close_loading() }
  12 + });
  13 +}
  14 +
  15 +
  16 +jQuery(document).ready(function(){
  17 + jQuery("#comment_order").change(function(){
  18 + var url = jQuery("#page_url").val();
  19 + send_order(this.value, url);
  20 + });
  21 +});
0 \ No newline at end of file 22 \ No newline at end of file
public/javascripts/edit-link-list.js 0 → 100644
@@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
  1 +function send_ajax(source_url) {
  2 + jQuery(".link-address").autocomplete({
  3 + source : function(request, response){
  4 + jQuery.ajax({
  5 + type: "GET",
  6 + url: source_url,
  7 + data: {query: request.term},
  8 + success: function(result){
  9 + response(result);
  10 + },
  11 + error: function(ajax, stat, errorThrown) {
  12 + console.log('Link not found : ' + errorThrown);
  13 + }
  14 + });
  15 + },
  16 +
  17 + minLength: 3
  18 + });
  19 +}
  20 +
  21 +function new_link_action(){
  22 + send_ajax(jQuery("#page_url").val());
  23 +
  24 + jQuery(".delete-link-list-row").click(function(){
  25 + jQuery(this).parent().parent().remove();
  26 + return false;
  27 + });
  28 +
  29 + jQuery(document).scrollTop(jQuery('#dropable-link-list').scrollTop());
  30 +}
  31 +
  32 +jQuery(document).ready(function(){
  33 + new_link_action();
  34 +
  35 + jQuery("#dropable-link-list").sortable({
  36 + revert: true,
  37 + axis: "y"
  38 + });
  39 +});
0 \ No newline at end of file 40 \ No newline at end of file
public/javascripts/sign_up_password_rate.js 0 → 100644
@@ -0,0 +1,121 @@ @@ -0,0 +1,121 @@
  1 +// This jQuery plugin is written by firas kassem [2007.04.05] and was modified to fit noosfero
  2 +// Firas Kassem phiras.wordpress.com || phiras at gmail {dot} com
  3 +// for more information : http://phiras.wordpress.com/2007/04/08/password-strength-meter-a-jquery-plugin/
  4 +
  5 +var blankPass = -1
  6 +var shortPass = 0
  7 +var badPass = 1
  8 +var goodPass = 2
  9 +var strongPass = 3
  10 +
  11 +
  12 +function passwordStrength(password,username)
  13 +{
  14 + score = 0
  15 +
  16 + if(password.length == 0) return blankPass
  17 +
  18 + //password < 4
  19 + if (password.length < 4 ) { return shortPass }
  20 +
  21 + //password == username
  22 + if (password.toLowerCase()==username.toLowerCase()) badPass
  23 +
  24 + //password length
  25 + score += password.length * 4
  26 + score += ( checkRepetition(1,password).length - password.length ) * 1
  27 + score += ( checkRepetition(2,password).length - password.length ) * 1
  28 + score += ( checkRepetition(3,password).length - password.length ) * 1
  29 + score += ( checkRepetition(4,password).length - password.length ) * 1
  30 +
  31 + //password has 3 numbers
  32 + if (password.match(/(.*[0-9].*[0-9].*[0-9])/)) score += 5
  33 +
  34 + //password has 2 sybols
  35 + if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) score += 5
  36 +
  37 + //password has Upper and Lower chars
  38 + if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) score += 10
  39 +
  40 + //password has number and chars
  41 + if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/)) score += 15
  42 + //
  43 + //password has number and symbol
  44 + if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/)) score += 15
  45 +
  46 + //password has char and symbol
  47 + if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/)) score += 15
  48 +
  49 + //password is just a nubers or chars
  50 + if (password.match(/^\w+$/) || password.match(/^\d+$/) ) score -= 10
  51 +
  52 + //verifing 0 < score < 100
  53 + if ( score < 0 ) score = 0
  54 + if ( score > 100 ) score = 100
  55 +
  56 + if (score < 34 ) return badPass
  57 + if (score < 68 ) return goodPass
  58 + return strongPass
  59 +}
  60 +
  61 +function checkRepetition(pLen,str)
  62 +{
  63 + res = ""
  64 + for ( i=0; i<str.length ; i++ )
  65 + {
  66 + repeated=true
  67 + for (j=0;j < pLen && (j+i+pLen) < str.length;j++)
  68 + repeated=repeated && (str.charAt(j+i)==str.charAt(j+i+pLen))
  69 + if (j<pLen) repeated=false
  70 + if (repeated)
  71 + {
  72 + i+=pLen-1
  73 + repeated=false
  74 + }
  75 + else
  76 + {
  77 + res+=str.charAt(i)
  78 + }
  79 + }
  80 + return res
  81 +}
  82 +
  83 +jQuery(document).ready(function() {
  84 + jQuery('#user_pw').keyup(function()
  85 + {
  86 + var result = passwordStrength(jQuery('#user_pw').val(),jQuery('#user_login').val())
  87 + if(result == blankPass)
  88 + {
  89 + showRateField('#result-blank')
  90 + } else
  91 + if(result == shortPass)
  92 + {
  93 + showRateField('#result-short')
  94 + } else
  95 + if( result == badPass )
  96 + {
  97 + showRateField('#result-bad')
  98 + } else
  99 + if( result == goodPass )
  100 + {
  101 + showRateField('#result-good')
  102 + } else
  103 + if( result == strongPass )
  104 + {
  105 + showRateField('#result-strong')
  106 + }
  107 +
  108 + })
  109 +})
  110 +
  111 +function showRateField(validation)
  112 +{
  113 + jQuery('#result-blank').addClass('hidden')
  114 + jQuery('#result-short').addClass('hidden')
  115 + jQuery('#result-bad').addClass('hidden')
  116 + jQuery('#result-good').addClass('hidden')
  117 + jQuery('#result-strong').addClass('hidden')
  118 +
  119 + jQuery(validation).removeClass('hidden')
  120 +
  121 +}
0 \ No newline at end of file 122 \ No newline at end of file
public/javascripts/signup_form.js 0 → 100644
@@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
  1 +function verifyLoginLoad() {
  2 + jQuery('#user_login').removeClass('available unavailable valid validated invalid checking').addClass('checking');
  3 + jQuery('#url-check').html(jQuery('#checking-message').html());
  4 +}
  5 +
  6 +function verifyLoginAjax(value) {
  7 + verifyLoginLoad();
  8 +
  9 + jQuery.get(
  10 + "/account/check_valid_name",
  11 + {'identifier': encodeURIComponent(value)},
  12 + function(request){
  13 + jQuery('#user_login').removeClass('checking');
  14 + jQuery("#url-check").html(request);
  15 + }
  16 + );
  17 +}
  18 +
  19 +jQuery(document).ready(function(){
  20 + jQuery("#user_login").blur(function(){
  21 + verifyLoginAjax(this.value);
  22 + });
  23 +});
public/stylesheets/application.css
@@ -1859,20 +1859,70 @@ a.button.disabled, input.disabled { @@ -1859,20 +1859,70 @@ a.button.disabled, input.disabled {
1859 text-decoration: none; 1859 text-decoration: none;
1860 } 1860 }
1861 /* ==> blocks/link-list-block.css <<= */ 1861 /* ==> blocks/link-list-block.css <<= */
1862 -  
1863 #edit-link-list-block { 1862 #edit-link-list-block {
1864 - width: 820px; 1863 + width: 620px;
  1864 + position: relative;
  1865 + left: -24px;
1865 } 1866 }
1866 -  
1867 -#edit-link-list-block table {  
1868 - width: auto;  
1869 - margin-bottom: 10px; 1867 +.link-list-header {
  1868 + width: 98%;
  1869 + height: 25px;
  1870 + padding: 10px 1px 10px 10px;
  1871 + margin-bottom: 5px;
  1872 + cursor: pointer;
1870 } 1873 }
1871 -#edit-link-list-block table .cel-address {  
1872 - width: 220px; 1874 +.link-list-header li {
  1875 + list-style-type: none;
  1876 + display: inline;
  1877 + font-weight: bold;
  1878 + font-size: 14px;
  1879 + text-align: center;
1873 } 1880 }
1874 -#edit-link-list-block table .cel-address input {  
1875 - width: 100%; 1881 +#dropable-link-list {
  1882 + padding-left: 23px;
  1883 + margin-top: -12px;
  1884 +}
  1885 +#dropable-link-list li {
  1886 + list-style-type: none;
  1887 +}
  1888 +.link-list-row {
  1889 + line-height: 25px;
  1890 + margin-bottom: 5px;
  1891 + padding: 10px 1px 10px 10px;
  1892 + cursor: pointer;
  1893 + width: 97%;
  1894 +}
  1895 +.link-list-row:hover {
  1896 + background: #ddd url(/images/drag-and-drop.png) no-repeat;
  1897 + background-position: 98% 15px;
  1898 +}
  1899 +.link-list-row li {
  1900 + list-style-type: none;
  1901 + display: inline;
  1902 + margin-left: 5px;
  1903 +}
  1904 +.link-list-row li div {
  1905 + float: left;
  1906 + margin-top: 4px;
  1907 +}
  1908 +.link-list-row li a {
  1909 + line-height: 27px !important;
  1910 + padding-right: 5px;
  1911 +}
  1912 +.link-list-icon {
  1913 + margin-left: 14px;
  1914 +}
  1915 +.link-list-name {
  1916 + margin-left: 40px;
  1917 +}
  1918 +.link-list-address {
  1919 + margin-left: 90px;
  1920 +}
  1921 +.link-list-target {
  1922 + margin-left: 77px;
  1923 +}
  1924 +.new_link_row li {
  1925 + margin-left: 7px;
1876 } 1926 }
1877 #content .link-list-block { 1927 #content .link-list-block {
1878 padding: 10px 0px 10px 10px; 1928 padding: 10px 0px 10px 10px;
@@ -5990,8 +6040,14 @@ li.profile-activity-item.upload_image .activity-gallery-images-count-1 img { @@ -5990,8 +6040,14 @@ li.profile-activity-item.upload_image .activity-gallery-images-count-1 img {
5990 text-align: right; 6040 text-align: right;
5991 } 6041 }
5992 6042
  6043 +#url-check .suggested_usernames,
  6044 +#url-check .suggested_usernames a {
  6045 + color: #005000;
  6046 +}
  6047 +
5993 #email-check, 6048 #email-check,
5994 #fake-check, 6049 #fake-check,
  6050 +#password-rate,
5995 #password-check { 6051 #password-check {
5996 margin: -2px 16px -5px 13px; 6052 margin: -2px 16px -5px 13px;
5997 text-align: right; 6053 text-align: right;
@@ -6000,10 +6056,20 @@ li.profile-activity-item.upload_image .activity-gallery-images-count-1 img { @@ -6000,10 +6056,20 @@ li.profile-activity-item.upload_image .activity-gallery-images-count-1 img {
6000 6056
6001 #email-check p, 6057 #email-check p,
6002 #fake-check p, 6058 #fake-check p,
  6059 +#password-rate p,
6003 #password-check p { 6060 #password-check p {
6004 margin: 0; 6061 margin: 0;
6005 } 6062 }
6006 6063
  6064 +#password-rate {
  6065 + font-weight:bold;
  6066 +}
  6067 +
  6068 +.hidden {
  6069 + visibility: hidden;
  6070 + display: none;
  6071 +}
  6072 +
6007 .available { 6073 .available {
6008 color: #88BD00; 6074 color: #88BD00;
6009 } 6075 }
@@ -6017,6 +6083,7 @@ li.profile-activity-item.upload_image .activity-gallery-images-count-1 img { @@ -6017,6 +6083,7 @@ li.profile-activity-item.upload_image .activity-gallery-images-count-1 img {
6017 } 6083 }
6018 6084
6019 #email-check p, 6085 #email-check p,
  6086 +#password-rate p,
6020 #password-check p, 6087 #password-check p,
6021 #url-check p { 6088 #url-check p {
6022 margin: 0; 6089 margin: 0;
@@ -6526,3 +6593,19 @@ ul.article-versions li { @@ -6526,3 +6593,19 @@ ul.article-versions li {
6526 .controller-features .manage-fields-batch-actions td { 6593 .controller-features .manage-fields-batch-actions td {
6527 font-style: italic; 6594 font-style: italic;
6528 } 6595 }
  6596 +
  6597 +#signup-form #result-short {
  6598 + color: red;
  6599 +}
  6600 +
  6601 +#signup-form #result-bad {
  6602 + color: #825A2C;
  6603 +}
  6604 +
  6605 +#signup-form #result-good {
  6606 + color: #32CD32;
  6607 +}
  6608 +
  6609 +#signup-form #result-strong {
  6610 + color: green;
  6611 +}
test/functional/account_controller_test.rb
@@ -8,7 +8,6 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -8,7 +8,6 @@ class AccountControllerTest &lt; ActionController::TestCase
8 # Be sure to include AuthenticatedTestHelper in test/test_helper.rb instead 8 # Be sure to include AuthenticatedTestHelper in test/test_helper.rb instead
9 # Then, you can remove it from this and the units test. 9 # Then, you can remove it from this and the units test.
10 include AuthenticatedTestHelper 10 include AuthenticatedTestHelper
11 -  
12 all_fixtures 11 all_fixtures
13 12
14 def teardown 13 def teardown
@@ -17,8 +16,8 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -17,8 +16,8 @@ class AccountControllerTest &lt; ActionController::TestCase
17 16
18 def setup 17 def setup
19 @controller = AccountController.new 18 @controller = AccountController.new
20 - @request = ActionController::TestRequest.new  
21 - @response = ActionController::TestResponse.new 19 + @request = ActionController::TestRequest.new
  20 + @response = ActionController::TestResponse.new
22 disable_signup_bot_check 21 disable_signup_bot_check
23 end 22 end
24 23
@@ -646,21 +645,28 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -646,21 +645,28 @@ class AccountControllerTest &lt; ActionController::TestCase
646 assert_redirected_to :controller => 'home', :action => 'index' 645 assert_redirected_to :controller => 'home', :action => 'index'
647 end 646 end
648 647
649 - should 'check_url is available on environment' do 648 + should 'check_valid_name is available on environment' do
650 env = fast_create(Environment, :name => 'Environment test') 649 env = fast_create(Environment, :name => 'Environment test')
651 @controller.expects(:environment).returns(env).at_least_once 650 @controller.expects(:environment).returns(env).at_least_once
652 profile = create_user('mylogin').person 651 profile = create_user('mylogin').person
653 - get :check_url, :identifier => 'mylogin' 652 + get :check_valid_name, :identifier => 'mylogin'
654 assert_equal 'validated', assigns(:status_class) 653 assert_equal 'validated', assigns(:status_class)
655 end 654 end
656 655
657 should 'check if url is not available on environment' do 656 should 'check if url is not available on environment' do
658 @controller.expects(:environment).returns(Environment.default).at_least_once 657 @controller.expects(:environment).returns(Environment.default).at_least_once
659 profile = create_user('mylogin').person 658 profile = create_user('mylogin').person
660 - get :check_url, :identifier => 'mylogin' 659 + get :check_valid_name, :identifier => 'mylogin'
661 assert_equal 'invalid', assigns(:status_class) 660 assert_equal 'invalid', assigns(:status_class)
662 end 661 end
663 662
  663 + should 'suggest a list with three possible usernames' do
  664 + profile = create_user('mylogin').person
  665 + get :check_valid_name, :identifier => 'mylogin'
  666 +
  667 + assert_equal 3, assigns(:suggested_usernames).uniq.size
  668 + end
  669 +
664 should 'check if e-mail is available on environment' do 670 should 'check if e-mail is available on environment' do
665 env = fast_create(Environment, :name => 'Environment test') 671 env = fast_create(Environment, :name => 'Environment test')
666 @controller.expects(:environment).returns(env).at_least_once 672 @controller.expects(:environment).returns(env).at_least_once
@@ -689,6 +695,7 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -689,6 +695,7 @@ class AccountControllerTest &lt; ActionController::TestCase
689 {:test => 5} 695 {:test => 5}
690 end 696 end
691 end 697 end
  698 + Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name])
692 699
693 e = User.find_by_login('ze').environment 700 e = User.find_by_login('ze').environment
694 e.enable_plugin(Plugin1.name) 701 e.enable_plugin(Plugin1.name)
@@ -779,6 +786,7 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -779,6 +786,7 @@ class AccountControllerTest &lt; ActionController::TestCase
779 lambda {"<strong>Plugin2 text</strong>"} 786 lambda {"<strong>Plugin2 text</strong>"}
780 end 787 end
781 end 788 end
  789 + Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name])
782 790
783 Environment.default.enable_plugin(Plugin1.name) 791 Environment.default.enable_plugin(Plugin1.name)
784 Environment.default.enable_plugin(Plugin2.name) 792 Environment.default.enable_plugin(Plugin2.name)
@@ -795,6 +803,7 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -795,6 +803,7 @@ class AccountControllerTest &lt; ActionController::TestCase
795 User.new(:login => 'testuser') 803 User.new(:login => 'testuser')
796 end 804 end
797 end 805 end
  806 + Noosfero::Plugin.stubs(:all).returns([Plugin1.name])
798 Environment.default.enable_plugin(Plugin1.name) 807 Environment.default.enable_plugin(Plugin1.name)
799 808
800 post :login, :user => {:login => "testuser"} 809 post :login, :user => {:login => "testuser"}
@@ -809,6 +818,7 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -809,6 +818,7 @@ class AccountControllerTest &lt; ActionController::TestCase
809 nil 818 nil
810 end 819 end
811 end 820 end
  821 + Noosfero::Plugin.stubs(:all).returns([Plugin1.name])
812 Environment.default.enable_plugin(Plugin1.name) 822 Environment.default.enable_plugin(Plugin1.name)
813 post :login, :user => {:login => 'johndoe', :password => 'test'} 823 post :login, :user => {:login => 'johndoe', :password => 'test'}
814 assert session[:user] 824 assert session[:user]
@@ -822,6 +832,7 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -822,6 +832,7 @@ class AccountControllerTest &lt; ActionController::TestCase
822 false 832 false
823 end 833 end
824 end 834 end
  835 + Noosfero::Plugin.stubs(:all).returns([TestRegistrationPlugin.name])
825 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestRegistrationPlugin.new]) 836 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestRegistrationPlugin.new])
826 837
827 post :signup, :user => { :login => 'testuser', :password => '123456', :password_confirmation => '123456', :email => 'testuser@example.com' } 838 post :signup, :user => { :login => 'testuser', :password => '123456', :password_confirmation => '123456', :email => 'testuser@example.com' }
@@ -840,6 +851,7 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -840,6 +851,7 @@ class AccountControllerTest &lt; ActionController::TestCase
840 true 851 true
841 end 852 end
842 end 853 end
  854 + Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name])
843 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([Plugin1.new, Plugin2.new]) 855 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([Plugin1.new, Plugin2.new])
844 856
845 get :login 857 get :login
@@ -853,6 +865,7 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -853,6 +865,7 @@ class AccountControllerTest &lt; ActionController::TestCase
853 false 865 false
854 end 866 end
855 end 867 end
  868 + Noosfero::Plugin.stubs(:all).returns([TestRegistrationPlugin.name])
856 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestRegistrationPlugin.new]) 869 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestRegistrationPlugin.new])
857 870
858 #Redirect on get action 871 #Redirect on get action
@@ -876,6 +889,7 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -876,6 +889,7 @@ class AccountControllerTest &lt; ActionController::TestCase
876 true 889 true
877 end 890 end
878 end 891 end
  892 + Noosfero::Plugin.stubs(:all).returns([Plugin1.new, Plugin2.new])
879 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([Plugin1.new, Plugin2.new]) 893 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([Plugin1.new, Plugin2.new])
880 894
881 get :login 895 get :login
@@ -894,6 +908,7 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -894,6 +908,7 @@ class AccountControllerTest &lt; ActionController::TestCase
894 lambda {"<strong>Plugin2 text</strong>"} 908 lambda {"<strong>Plugin2 text</strong>"}
895 end 909 end
896 end 910 end
  911 + Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name])
897 912
898 Environment.default.enable_plugin(Plugin1.name) 913 Environment.default.enable_plugin(Plugin1.name)
899 Environment.default.enable_plugin(Plugin2.name) 914 Environment.default.enable_plugin(Plugin2.name)
@@ -917,6 +932,30 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -917,6 +932,30 @@ class AccountControllerTest &lt; ActionController::TestCase
917 assert @response.body.blank? 932 assert @response.body.blank?
918 end 933 end
919 934
  935 + should "Search for state" do
  936 + create_state_and_city
  937 +
  938 + xhr :get, :search_state, :state_name=>"Rio Grande"
  939 +
  940 + json_response = ActiveSupport::JSON.decode(@response.body)
  941 + label = json_response[0]['label']
  942 +
  943 + assert_equal label, "Rio Grande do Sul"
  944 + end
  945 +
  946 + should "Search for city" do
  947 + create_state_and_city
  948 +
  949 + xhr :get, :search_cities, :state_name=>"Rio Grande do Sul", :city_name=>"Lavras"
  950 +
  951 + json_response = ActiveSupport::JSON.decode(@response.body)
  952 + label = json_response[0]['label']
  953 + category = json_response[0]['category']
  954 +
  955 + assert_equal category, "Rio Grande do Sul"
  956 + assert_equal label, "Lavras do Sul"
  957 + end
  958 +
920 protected 959 protected
921 def new_user(options = {}, extra_options ={}) 960 def new_user(options = {}, extra_options ={})
922 data = {:profile_data => person_data} 961 data = {:profile_data => person_data}
@@ -945,4 +984,18 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -945,4 +984,18 @@ class AccountControllerTest &lt; ActionController::TestCase
945 environment.min_signup_delay = 0 984 environment.min_signup_delay = 0
946 environment.save! 985 environment.save!
947 end 986 end
  987 +
  988 + def create_state_and_city
  989 + city = 'Lavras do Sul'
  990 + state = 'Rio Grande do Sul'
  991 +
  992 + parent_region = fast_create(NationalRegion, :name => state,
  993 + :national_region_code => '43',
  994 + :national_region_type_id => NationalRegionType::STATE)
  995 +
  996 + fast_create(NationalRegion, :name => city,
  997 + :national_region_code => '431150',
  998 + :national_region_type_id => NationalRegionType::CITY,
  999 + :parent_national_region_code => parent_region.national_region_code)
  1000 + end
948 end 1001 end
test/functional/application_controller_test.rb
@@ -374,6 +374,8 @@ class ApplicationControllerTest &lt; ActionController::TestCase @@ -374,6 +374,8 @@ class ApplicationControllerTest &lt; ActionController::TestCase
374 end 374 end
375 plugin2_path = '/plugin2/style.css' 375 plugin2_path = '/plugin2/style.css'
376 376
  377 + Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name])
  378 +
377 environment = Environment.default 379 environment = Environment.default
378 environment.enable_plugin(Plugin1.name) 380 environment.enable_plugin(Plugin1.name)
379 environment.enable_plugin(Plugin2.name) 381 environment.enable_plugin(Plugin2.name)
@@ -405,6 +407,8 @@ class ApplicationControllerTest &lt; ActionController::TestCase @@ -405,6 +407,8 @@ class ApplicationControllerTest &lt; ActionController::TestCase
405 plugin2_path2 = '/plugin2/'+js2 407 plugin2_path2 = '/plugin2/'+js2
406 plugin2_path3 = '/plugin2/'+js3 408 plugin2_path3 = '/plugin2/'+js3
407 409
  410 + Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name])
  411 +
408 environment = Environment.default 412 environment = Environment.default
409 environment.enable_plugin(Plugin1.name) 413 environment.enable_plugin(Plugin1.name)
410 environment.enable_plugin(Plugin2.name) 414 environment.enable_plugin(Plugin2.name)
@@ -431,6 +435,8 @@ class ApplicationControllerTest &lt; ActionController::TestCase @@ -431,6 +435,8 @@ class ApplicationControllerTest &lt; ActionController::TestCase
431 end 435 end
432 end 436 end
433 437
  438 + Noosfero::Plugin.stubs(:all).returns([TestBodyBeginning1Plugin.name, TestBodyBeginning2Plugin.name])
  439 +
434 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBodyBeginning1Plugin.new, TestBodyBeginning2Plugin.new]) 440 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBodyBeginning1Plugin.new, TestBodyBeginning2Plugin.new])
435 441
436 get :index 442 get :index
@@ -455,6 +461,8 @@ class ApplicationControllerTest &lt; ActionController::TestCase @@ -455,6 +461,8 @@ class ApplicationControllerTest &lt; ActionController::TestCase
455 end 461 end
456 end 462 end
457 463
  464 + Noosfero::Plugin.stubs(:all).returns([TestHeadEnding1Plugin.name, TestHeadEnding2Plugin.name])
  465 +
458 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestHeadEnding1Plugin.new, TestHeadEnding2Plugin.new]) 466 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestHeadEnding1Plugin.new, TestHeadEnding2Plugin.new])
459 467
460 get :index 468 get :index
@@ -519,6 +527,7 @@ class ApplicationControllerTest &lt; ActionController::TestCase @@ -519,6 +527,7 @@ class ApplicationControllerTest &lt; ActionController::TestCase
519 :block => lambda {} } 527 :block => lambda {} }
520 end 528 end
521 end 529 end
  530 + Noosfero::Plugin.stubs(:all).returns([FilterPlugin.name])
522 531
523 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([FilterPlugin.new]) 532 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([FilterPlugin.new])
524 533
@@ -537,6 +546,7 @@ class ApplicationControllerTest &lt; ActionController::TestCase @@ -537,6 +546,7 @@ class ApplicationControllerTest &lt; ActionController::TestCase
537 :block => lambda {'plugin block called'} } 546 :block => lambda {'plugin block called'} }
538 end 547 end
539 end 548 end
  549 + Noosfero::Plugin.stubs(:all).returns([OtherFilterPlugin.name])
540 550
541 environment1 = fast_create(Environment, :name => 'test environment') 551 environment1 = fast_create(Environment, :name => 'test environment')
542 environment1.enable_plugin(OtherFilterPlugin.name) 552 environment1.enable_plugin(OtherFilterPlugin.name)
test/functional/catalog_controller_test.rb
@@ -91,6 +91,7 @@ class CatalogControllerTest &lt; ActionController::TestCase @@ -91,6 +91,7 @@ class CatalogControllerTest &lt; ActionController::TestCase
91 lambda {"<span id='plugin2'>This is Plugin2 speaking!</span>"} 91 lambda {"<span id='plugin2'>This is Plugin2 speaking!</span>"}
92 end 92 end
93 end 93 end
  94 + Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name])
94 95
95 product = fast_create(Product, :profile_id => @enterprise.id) 96 product = fast_create(Product, :profile_id => @enterprise.id)
96 environment = Environment.default 97 environment = Environment.default
test/functional/content_viewer_controller_test.rb
@@ -72,9 +72,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -72,9 +72,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
72 get :view_page, :profile => 'someone', :page => [ '500.html' ] 72 get :view_page, :profile => 'someone', :page => [ '500.html' ]
73 73
74 assert_response :success 74 assert_response :success
75 - assert_match /^text\/html/, @response.headers['Content-Type']  
76 - assert @response.headers['Content-Disposition'].present?  
77 - assert_match /attachment/, @response.headers['Content-Disposition'] 75 + assert_match /#{html.public_filename}/, @response.body
78 end 76 end
79 77
80 should 'produce a download-link when article is not text/html' do 78 should 'produce a download-link when article is not text/html' do
@@ -577,14 +575,6 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -577,14 +575,6 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
577 assert_template 'view_page' 575 assert_template 'view_page'
578 end 576 end
579 577
580 - should 'download data for image when not view' do  
581 - file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => profile)  
582 - get :view_page, :profile => profile.identifier, :page => file.explode_path  
583 -  
584 - assert_response :success  
585 - assert_template nil  
586 - end  
587 -  
588 should "display 'Upload files' when create children of image gallery" do 578 should "display 'Upload files' when create children of image gallery" do
589 login_as(profile.identifier) 579 login_as(profile.identifier)
590 f = Gallery.create!(:name => 'gallery', :profile => profile) 580 f = Gallery.create!(:name => 'gallery', :profile => profile)
@@ -1199,6 +1189,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -1199,6 +1189,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
1199 class Plugin2 < Noosfero::Plugin 1189 class Plugin2 < Noosfero::Plugin
1200 def content_remove_edit(content); false; end 1190 def content_remove_edit(content); false; end
1201 end 1191 end
  1192 + Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name])
1202 1193
1203 environment.enable_plugin(Plugin1.name) 1194 environment.enable_plugin(Plugin1.name)
1204 environment.enable_plugin(Plugin2.name) 1195 environment.enable_plugin(Plugin2.name)
@@ -1215,6 +1206,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -1215,6 +1206,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
1215 class Plugin2 < Noosfero::Plugin 1206 class Plugin2 < Noosfero::Plugin
1216 def content_expire_edit(content); nil; end 1207 def content_expire_edit(content); nil; end
1217 end 1208 end
  1209 + Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name])
1218 1210
1219 environment.enable_plugin(Plugin1.name) 1211 environment.enable_plugin(Plugin1.name)
1220 environment.enable_plugin(Plugin2.name) 1212 environment.enable_plugin(Plugin2.name)
@@ -1260,6 +1252,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -1260,6 +1252,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
1260 } 1252 }
1261 end 1253 end
1262 end 1254 end
  1255 + Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name])
1263 1256
1264 Environment.default.enable_plugin(Plugin1.name) 1257 Environment.default.enable_plugin(Plugin1.name)
1265 Environment.default.enable_plugin(Plugin2.name) 1258 Environment.default.enable_plugin(Plugin2.name)
@@ -1284,6 +1277,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -1284,6 +1277,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
1284 scope.where(:referrer => 'kernel.org') 1277 scope.where(:referrer => 'kernel.org')
1285 end 1278 end
1286 end 1279 end
  1280 + Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name])
1287 1281
1288 Environment.default.enable_plugin(Plugin1) 1282 Environment.default.enable_plugin(Plugin1)
1289 Environment.default.enable_plugin(Plugin2) 1283 Environment.default.enable_plugin(Plugin2)
@@ -1341,6 +1335,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -1341,6 +1335,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
1341 } 1335 }
1342 end 1336 end
1343 end 1337 end
  1338 + Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name])
1344 1339
1345 Environment.default.enable_plugin(Plugin1.name) 1340 Environment.default.enable_plugin(Plugin1.name)
1346 Environment.default.enable_plugin(Plugin2.name) 1341 Environment.default.enable_plugin(Plugin2.name)
@@ -1355,8 +1350,23 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -1355,8 +1350,23 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
1355 1350
1356 should 'display link to download of non-recognized file types on its page' do 1351 should 'display link to download of non-recognized file types on its page' do
1357 file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'bin/unknown'), :profile => profile) 1352 file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'bin/unknown'), :profile => profile)
1358 - get :view_page, file.url.merge(:view=>:true)  
1359 - assert_match /this is a sample text file/, @response.body 1353 + get :view_page, file.url
  1354 + assert_match /#{file.public_filename}/, @response.body
  1355 + end
  1356 +
  1357 + should 'not count hit from bots' do
  1358 + article = fast_create(Article, :profile_id => profile.id)
  1359 + assert_no_difference article, :hits do
  1360 + @request.env['HTTP_USER_AGENT'] = 'bot'
  1361 + get 'view_page', :profile => profile.identifier, :page => article.path.split('/')
  1362 + @request.env['HTTP_USER_AGENT'] = 'spider'
  1363 + get 'view_page', :profile => profile.identifier, :page => article.path.split('/')
  1364 + @request.env['HTTP_USER_AGENT'] = 'crawler'
  1365 + get 'view_page', :profile => profile.identifier, :page => article.path.split('/')
  1366 + @request.env['HTTP_USER_AGENT'] = '(http://some-crawler.com)'
  1367 + get 'view_page', :profile => profile.identifier, :page => article.path.split('/')
  1368 + article.reload
  1369 + end
1360 end 1370 end
1361 1371
1362 should 'add meta tags with article info' do 1372 should 'add meta tags with article info' do
test/functional/embed_controller_test.rb 0 → 100644
@@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class EmbedControllerTest < ActionController::TestCase
  4 +
  5 + def setup
  6 + login_as(create_admin_user(Environment.default))
  7 + @block = LoginBlock.create!
  8 + @block.class.any_instance.stubs(:embedable?).returns(true)
  9 + @environment = Environment.default
  10 + @environment.boxes.create!
  11 + @environment.boxes.first.blocks << @block
  12 + end
  13 +
  14 + should 'be able to get embed block' do
  15 + get :block, :id => @block.id
  16 + assert_tag :tag => 'div', :attributes => { :id => "block-#{@block.id}" }
  17 + end
  18 +
  19 + should 'display error message when not found block' do
  20 + Block.delete_all
  21 + get :block, :id => 1
  22 + assert_tag :tag => 'div', :attributes => { :id => "not-found" }
  23 + end
  24 +
  25 + should 'display error message when block is not visible/public' do
  26 + @block.display = 'never'
  27 + assert @block.save
  28 + get :block, :id => @block.id
  29 + assert_tag :tag => 'div', :attributes => { :id => "unavailable" }
  30 + end
  31 +
  32 + should 'display error message when block is not embedable' do
  33 + @block.class.any_instance.stubs(:embedable?).returns(false)
  34 + get :block, :id => @block.id
  35 + assert_tag :tag => 'div', :attributes => { :id => "unavailable" }
  36 + end
  37 +
  38 +
  39 +end
test/functional/enterprise_registration_controller_test.rb
@@ -193,6 +193,7 @@ class EnterpriseRegistrationControllerTest &lt; ActionController::TestCase @@ -193,6 +193,7 @@ class EnterpriseRegistrationControllerTest &lt; ActionController::TestCase
193 {'plugin2' => 'Plugin 2'} 193 {'plugin2' => 'Plugin 2'}
194 end 194 end
195 end 195 end
  196 + Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name])
196 197
197 environment = Environment.default 198 environment = Environment.default
198 environment.enable_plugin(Plugin1.name) 199 environment.enable_plugin(Plugin1.name)
test/functional/environment_design_controller_test.rb
@@ -379,4 +379,38 @@ class EnvironmentDesignControllerTest &lt; ActionController::TestCase @@ -379,4 +379,38 @@ class EnvironmentDesignControllerTest &lt; ActionController::TestCase
379 end 379 end
380 end 380 end
381 381
  382 + should 'return a list of paths from portal related to the words used in the query search' do
  383 + env = Environment.default
  384 + login_as(create_admin_user(env))
  385 + community = fast_create(Community, :environment_id => env)
  386 + env.portal_community = community
  387 + env.enable('use_portal_community')
  388 + env.save
  389 + @controller.stubs(:boxes_holder).returns(env)
  390 + article1 = fast_create(Article, :profile_id => community.id, :name => "Some thing")
  391 + article2 = fast_create(Article, :profile_id => community.id, :name => "Some article")
  392 + article3 = fast_create(Article, :profile_id => community.id, :name => "Not an article")
  393 +
  394 + xhr :get, :search_autocomplete, :query => 'Some'
  395 +
  396 + json_response = ActiveSupport::JSON.decode(@response.body)
  397 +
  398 + assert_response :success
  399 + assert_equal json_response.include?("/{portal}/"+article1.path), true
  400 + assert_equal json_response.include?("/{portal}/"+article2.path), true
  401 + assert_equal json_response.include?("/{portal}/"+article3.path), false
  402 + end
  403 +
  404 + should 'return empty if portal not configured' do
  405 + env = Environment.default
  406 + login_as(create_admin_user(env))
  407 +
  408 + xhr :get, :search_autocomplete, :query => 'Some'
  409 +
  410 + json_response = ActiveSupport::JSON.decode(@response.body)
  411 +
  412 + assert_response :success
  413 + assert_equal json_response, []
  414 + end
  415 +
382 end 416 end
test/functional/events_controller_test.rb
@@ -46,4 +46,12 @@ class EventsControllerTest &lt; ActionController::TestCase @@ -46,4 +46,12 @@ class EventsControllerTest &lt; ActionController::TestCase
46 assert_equal 20, assigns(:events).count 46 assert_equal 20, assigns(:events).count
47 end 47 end
48 48
  49 + should 'show events of specific day' do
  50 + profile.events << Event.new(:name => 'Joao Birthday', :start_date => Date.new(2009, 10, 28))
  51 +
  52 + get :events_by_day, :profile => profile.identifier, :year => 2009, :month => 10, :day => 28
  53 +
  54 + assert_tag :tag => 'a', :content => /Joao Birthday/
  55 + end
  56 +
49 end 57 end
test/functional/friends_controller_test.rb
@@ -68,6 +68,7 @@ class FriendsControllerTest &lt; ActionController::TestCase @@ -68,6 +68,7 @@ class FriendsControllerTest &lt; ActionController::TestCase
68 false 68 false
69 end 69 end
70 end 70 end
  71 + Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name])
71 72
72 e = profile.environment 73 e = profile.environment
73 e.enable_plugin(Plugin1.name) 74 e.enable_plugin(Plugin1.name)
test/functional/home_controller_test.rb
@@ -107,6 +107,7 @@ class HomeControllerTest &lt; ActionController::TestCase @@ -107,6 +107,7 @@ class HomeControllerTest &lt; ActionController::TestCase
107 lambda {"<a href='plugin2'>Plugin2 link</a>"} 107 lambda {"<a href='plugin2'>Plugin2 link</a>"}
108 end 108 end
109 end 109 end
  110 + Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name])
110 111
111 Environment.default.enable_plugin(Plugin1) 112 Environment.default.enable_plugin(Plugin1)
112 Environment.default.enable_plugin(Plugin2) 113 Environment.default.enable_plugin(Plugin2)
@@ -129,6 +130,7 @@ class HomeControllerTest &lt; ActionController::TestCase @@ -129,6 +130,7 @@ class HomeControllerTest &lt; ActionController::TestCase
129 true 130 true
130 end 131 end
131 end 132 end
  133 + Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name])
132 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([Plugin1.new, Plugin2.new]) 134 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([Plugin1.new, Plugin2.new])
133 135
134 get :index 136 get :index
test/functional/memberships_controller_test.rb
@@ -234,6 +234,7 @@ class MembershipsControllerTest &lt; ActionController::TestCase @@ -234,6 +234,7 @@ class MembershipsControllerTest &lt; ActionController::TestCase
234 {'plugin2' => 'Plugin 2'} 234 {'plugin2' => 'Plugin 2'}
235 end 235 end
236 end 236 end
  237 + Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name])
237 238
238 environment = Environment.default 239 environment = Environment.default
239 environment.enable_plugin(Plugin1.name) 240 environment.enable_plugin(Plugin1.name)
test/functional/plugins_controller_test.rb
@@ -47,7 +47,7 @@ class PluginsControllerTest &lt; ActionController::TestCase @@ -47,7 +47,7 @@ class PluginsControllerTest &lt; ActionController::TestCase
47 end 47 end
48 end 48 end
49 49
50 - Noosfero::Plugin.stubs(:all).returns([Plugin1.to_s,Plugin2.to_s]) 50 + Noosfero::Plugin.stubs(:all).returns([Plugin1.to_s, Plugin2.to_s])
51 51
52 get :index 52 get :index
53 53
test/functional/profile_controller_test.rb
@@ -1255,6 +1255,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1255,6 +1255,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1255 {:title => 'Plugin2 tab', :id => 'plugin2_tab', :content => lambda { 'Content from plugin2.' }} 1255 {:title => 'Plugin2 tab', :id => 'plugin2_tab', :content => lambda { 'Content from plugin2.' }}
1256 end 1256 end
1257 end 1257 end
  1258 + Noosfero::Plugin.stubs(:all).returns([Plugin1.to_s, Plugin2.to_s])
1258 1259
1259 e = profile.environment 1260 e = profile.environment
1260 e.enable_plugin(Plugin1.name) 1261 e.enable_plugin(Plugin1.name)
test/functional/profile_design_controller_test.rb
@@ -173,7 +173,8 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase @@ -173,7 +173,8 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
173 should 'have options to display blocks' do 173 should 'have options to display blocks' do
174 get :edit, :profile => 'designtestuser', :id => @b1.id 174 get :edit, :profile => 'designtestuser', :id => @b1.id
175 %w[always home_page_only except_home_page never].each do |option| 175 %w[always home_page_only except_home_page never].each do |option|
176 - assert_tag :input, :attributes => { :type => 'radio', :value => option} 176 + assert_tag :select, :attributes => {:name => 'block[display]'},
  177 + :descendant => {:tag => 'option', :attributes => {:value => option}}
177 end 178 end
178 end 179 end
179 180
@@ -302,24 +303,42 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase @@ -302,24 +303,42 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
302 303
303 should 'not edit main block with never option' do 304 should 'not edit main block with never option' do
304 get :edit, :profile => 'designtestuser', :id => @b4.id 305 get :edit, :profile => 'designtestuser', :id => @b4.id
305 - assert_no_tag :input, :attributes => { :type => 'radio', :value => 'never'} 306 + assert_no_tag :select, :attributes => {:name => 'block[display]'},
  307 + :descendant => {:tag => 'option', :attributes => {:value => 'never'}}
306 end 308 end
307 309
308 should 'not edit main block with home_page_only option' do 310 should 'not edit main block with home_page_only option' do
309 get :edit, :profile => 'designtestuser', :id => @b4.id 311 get :edit, :profile => 'designtestuser', :id => @b4.id
310 - assert_no_tag :input, :attributes => { :type => 'radio', :value => 'home_page_only'} 312 + assert_no_tag :select, :attributes => {:name => 'block[display]'},
  313 + :descendant => {:tag => 'option', :attributes => {:value => 'home_page_only'}}
311 end 314 end
312 315
313 should 'edit main block with always option' do 316 should 'edit main block with always option' do
314 get :edit, :profile => 'designtestuser', :id => @b4.id 317 get :edit, :profile => 'designtestuser', :id => @b4.id
315 - assert_tag :input, :attributes => { :type => 'radio', :value => 'always'} 318 + assert_tag :select, :attributes => {:name => 'block[display]'},
  319 + :descendant => {:tag => 'option', :attributes => {:value => 'always'}}
316 end 320 end
317 321
318 should 'edit main block with except_home_page option' do 322 should 'edit main block with except_home_page option' do
319 get :edit, :profile => 'designtestuser', :id => @b4.id 323 get :edit, :profile => 'designtestuser', :id => @b4.id
320 - assert_tag :input, :attributes => { :type => 'radio', :value => 'except_home_page'} 324 + assert_tag :select, :attributes => {:name=> 'block[display]'},
  325 + :descendant => {:tag => 'option', :attributes => {:value => 'except_home_page'}}
321 end 326 end
322 327
  328 + should 'return a list of paths related to the words used in the query search' do
  329 + article1 = fast_create(Article, :profile_id => @profile.id, :name => "Some thing")
  330 + article2 = fast_create(Article, :profile_id => @profile.id, :name => "Some article")
  331 + article3 = fast_create(Article, :profile_id => @profile.id, :name => "Not an article")
  332 +
  333 + xhr :get, :search_autocomplete, :profile => 'designtestuser' , :query => 'Some'
  334 +
  335 + json_response = ActiveSupport::JSON.decode(@response.body)
  336 +
  337 + assert_response :success
  338 + assert_equal json_response.include?("/{profile}/"+article1.path), true
  339 + assert_equal json_response.include?("/{profile}/"+article2.path), true
  340 + assert_equal json_response.include?("/{profile}/"+article3.path), false
  341 + end
323 342
324 ###################################################### 343 ######################################################
325 # END - tests for BoxOrganizerController features 344 # END - tests for BoxOrganizerController features
test/functional/profile_editor_controller_test.rb
@@ -868,6 +868,7 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase @@ -868,6 +868,7 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
868 {:title => "Plugin2 button", :icon => 'plugin2_icon', :url => 'plugin2_url'} 868 {:title => "Plugin2 button", :icon => 'plugin2_icon', :url => 'plugin2_url'}
869 end 869 end
870 end 870 end
  871 + Noosfero::Plugin.stubs(:all).returns([TestControlPanelButtons1.to_s, TestControlPanelButtons2.to_s])
871 872
872 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestControlPanelButtons1.new, TestControlPanelButtons2.new]) 873 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestControlPanelButtons1.new, TestControlPanelButtons2.new])
873 874
@@ -883,6 +884,7 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase @@ -883,6 +884,7 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
883 "<input id='field_added_by_plugin' value='value_of_field_added_by_plugin'/>" 884 "<input id='field_added_by_plugin' value='value_of_field_added_by_plugin'/>"
884 end 885 end
885 end 886 end
  887 + Noosfero::Plugin.stubs(:all).returns([TestProfileEditPlugin.to_s])
886 888
887 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestProfileEditPlugin.new]) 889 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestProfileEditPlugin.new])
888 890
@@ -911,6 +913,7 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase @@ -911,6 +913,7 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
911 lambda {"<strong>Plugin2 text</strong>"} 913 lambda {"<strong>Plugin2 text</strong>"}
912 end 914 end
913 end 915 end
  916 + Noosfero::Plugin.stubs(:all).returns([Plugin1.to_s, Plugin2.to_s])
914 917
915 Environment.default.enable_plugin(Plugin1) 918 Environment.default.enable_plugin(Plugin1)
916 Environment.default.enable_plugin(Plugin2) 919 Environment.default.enable_plugin(Plugin2)
@@ -932,6 +935,7 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase @@ -932,6 +935,7 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
932 lambda {"<strong>Plugin2 text</strong>"} 935 lambda {"<strong>Plugin2 text</strong>"}
933 end 936 end
934 end 937 end
  938 + Noosfero::Plugin.stubs(:all).returns([Plugin1.to_s, Plugin2.to_s])
935 939
936 Environment.default.enable_plugin(Plugin1) 940 Environment.default.enable_plugin(Plugin1)
937 Environment.default.enable_plugin(Plugin2) 941 Environment.default.enable_plugin(Plugin2)
test/functional/search_controller_test.rb
@@ -74,14 +74,14 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -74,14 +74,14 @@ class SearchControllerTest &lt; ActionController::TestCase
74 assert_includes assigns(:searches)[:articles][:results], art 74 assert_includes assigns(:searches)[:articles][:results], art
75 end 75 end
76 76
77 - should 'redirect contents to articles' do 77 + should 'redirect contents to articles' do
78 person = fast_create(Person) 78 person = fast_create(Person)
79 art = create_article_with_optional_category('an article to be found', person) 79 art = create_article_with_optional_category('an article to be found', person)
80 80
81 get 'contents', :query => 'article found' 81 get 'contents', :query => 'article found'
82 - # full description to avoid deprecation warning 82 + # full description to avoid deprecation warning
83 assert_redirected_to :controller => :search, :action => :articles, :query => 'article found' 83 assert_redirected_to :controller => :search, :action => :articles, :query => 'article found'
84 - end 84 + end
85 85
86 # 'assets' outside any category 86 # 'assets' outside any category
87 should 'list articles in general' do 87 should 'list articles in general' do
@@ -163,6 +163,7 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -163,6 +163,7 @@ class SearchControllerTest &lt; ActionController::TestCase
163 lambda {"<span id='plugin2'>This is Plugin2 speaking!</span>"} 163 lambda {"<span id='plugin2'>This is Plugin2 speaking!</span>"}
164 end 164 end
165 end 165 end
  166 + Noosfero::Plugin.stubs(:all).returns([Plugin1.to_s, Plugin2.to_s])
166 167
167 enterprise = fast_create(Enterprise) 168 enterprise = fast_create(Enterprise)
168 prod_cat = fast_create(ProductCategory) 169 prod_cat = fast_create(ProductCategory)
@@ -189,6 +190,7 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -189,6 +190,7 @@ class SearchControllerTest &lt; ActionController::TestCase
189 return { :name => _('Property2'), :content => lambda { link_to(product.name, '/plugin2') } } 190 return { :name => _('Property2'), :content => lambda { link_to(product.name, '/plugin2') } }
190 end 191 end
191 end 192 end
  193 + Noosfero::Plugin.stubs(:all).returns([Plugin1.to_s, Plugin2.to_s])
192 enterprise = fast_create(Enterprise) 194 enterprise = fast_create(Enterprise)
193 prod_cat = fast_create(ProductCategory) 195 prod_cat = fast_create(ProductCategory)
194 product = fast_create(Product, {:profile_id => enterprise.id, :name => "produto1", :product_category_id => prod_cat.id}, :search => true) 196 product = fast_create(Product, {:profile_id => enterprise.id, :name => "produto1", :product_category_id => prod_cat.id}, :search => true)
@@ -257,10 +259,10 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -257,10 +259,10 @@ class SearchControllerTest &lt; ActionController::TestCase
257 259
258 should 'render specific action when only one asset is enabled' do 260 should 'render specific action when only one asset is enabled' do
259 environment = Environment.default 261 environment = Environment.default
260 - # article is not disabled 262 + # article is not disabled
261 [:enterprises, :people, :communities, :products, :events].select do |key, name| 263 [:enterprises, :people, :communities, :products, :events].select do |key, name|
262 - environment.enable('disable_asset_' + key.to_s)  
263 - end 264 + environment.enable('disable_asset_' + key.to_s)
  265 + end
264 environment.save! 266 environment.save!
265 @controller.stubs(:environment).returns(environment) 267 @controller.stubs(:environment).returns(environment)
266 268
@@ -272,25 +274,25 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -272,25 +274,25 @@ class SearchControllerTest &lt; ActionController::TestCase
272 assert !assigns(:searches).has_key?(:communities) 274 assert !assigns(:searches).has_key?(:communities)
273 assert !assigns(:searches).has_key?(:products) 275 assert !assigns(:searches).has_key?(:products)
274 assert !assigns(:searches).has_key?(:events) 276 assert !assigns(:searches).has_key?(:events)
275 - end 277 + end
276 278
277 should 'search all enabled assets in general search' do 279 should 'search all enabled assets in general search' do
278 ent1 = create_profile_with_optional_category(Enterprise, 'test enterprise') 280 ent1 = create_profile_with_optional_category(Enterprise, 'test enterprise')
279 prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default) 281 prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default)
280 prod = ent1.products.create!(:name => 'test product', :product_category => prod_cat) 282 prod = ent1.products.create!(:name => 'test product', :product_category => prod_cat)
281 - art = Article.create!(:name => 'test article', :profile_id => fast_create(Person).id)  
282 - per = Person.create!(:name => 'test person', :identifier => 'test-person', :user_id => fast_create(User).id)  
283 - com = Community.create!(:name => 'test community')  
284 - eve = Event.create!(:name => 'test event', :profile_id => fast_create(Person).id) 283 + art = Article.create!(:name => 'test article', :profile_id => fast_create(Person).id)
  284 + per = Person.create!(:name => 'test person', :identifier => 'test-person', :user_id => fast_create(User).id)
  285 + com = Community.create!(:name => 'test community')
  286 + eve = Event.create!(:name => 'test event', :profile_id => fast_create(Person).id)
285 287
286 get :index, :query => 'test' 288 get :index, :query => 'test'
287 289
288 [:articles, :enterprises, :people, :communities, :products, :events].select do |key, name| 290 [:articles, :enterprises, :people, :communities, :products, :events].select do |key, name|
289 - !assigns(:environment).enabled?('disable_asset_' + key.to_s)  
290 - end.each do |asset|  
291 - assert !assigns(:searches)[asset][:results].empty?  
292 - end  
293 - end 291 + !assigns(:environment).enabled?('disable_asset_' + key.to_s)
  292 + end.each do |asset|
  293 + assert !assigns(:searches)[asset][:results].empty?
  294 + end
  295 + end
294 296
295 should 'display category image while in directory' do 297 should 'display category image while in directory' do
296 parent = Category.create!(:name => 'category1', :environment => Environment.default) 298 parent = Category.create!(:name => 'category1', :environment => Environment.default)
@@ -316,8 +318,8 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -316,8 +318,8 @@ class SearchControllerTest &lt; ActionController::TestCase
316 person = create_user('someone').person 318 person = create_user('someone').person
317 ten_days_ago = Date.today - 10.day 319 ten_days_ago = Date.today - 10.day
318 320
319 - ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], :start_date => ten_days_ago)  
320 - ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], :start_date => Date.today - 2.month) 321 + ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], :start_date => ten_days_ago)
  322 + ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], :start_date => Date.today - 2.month)
321 323
322 get :events, :day => ten_days_ago.day, :month => ten_days_ago.month, :year => ten_days_ago.year 324 get :events, :day => ten_days_ago.day, :month => ten_days_ago.month, :year => ten_days_ago.year
323 assert_equal [ev1], assigns(:events) 325 assert_equal [ev1], assigns(:events)
@@ -327,7 +329,7 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -327,7 +329,7 @@ class SearchControllerTest &lt; ActionController::TestCase
327 person = create_user('someone').person 329 person = create_user('someone').person
328 ten_days_ago = Date.today - 10.day 330 ten_days_ago = Date.today - 10.day
329 331
330 - ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], :start_date => ten_days_ago) 332 + ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], :start_date => ten_days_ago)
331 ev2 = create_event(person, :name => 'event 2', :start_date => ten_days_ago) 333 ev2 = create_event(person, :name => 'event 2', :start_date => ten_days_ago)
332 334
333 get :events, :day => ten_days_ago.day, :month => ten_days_ago.month, :year => ten_days_ago.year, :category_path => @category.path.split('/') 335 get :events, :day => ten_days_ago.day, :month => ten_days_ago.month, :year => ten_days_ago.year, :category_path => @category.path.split('/')
@@ -337,8 +339,8 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -337,8 +339,8 @@ class SearchControllerTest &lt; ActionController::TestCase
337 339
338 should 'return events of today when no date specified' do 340 should 'return events of today when no date specified' do
339 person = create_user('someone').person 341 person = create_user('someone').person
340 - ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], :start_date => Date.today)  
341 - ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], :start_date => Date.today - 2.month) 342 + ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], :start_date => Date.today)
  343 + ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], :start_date => Date.today - 2.month)
342 344
343 get :events 345 get :events
344 346
@@ -349,9 +351,9 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -349,9 +351,9 @@ class SearchControllerTest &lt; ActionController::TestCase
349 person = create_user('someone').person 351 person = create_user('someone').person
350 352
351 ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], 353 ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id],
352 - :start_date => Date.today + 2.month) 354 + :start_date => Date.today + 2.month)
353 ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], 355 ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id],
354 - :start_date => Date.today + 2.day) 356 + :start_date => Date.today + 2.day)
355 357
356 get :events 358 get :events
357 359
@@ -371,8 +373,9 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -371,8 +373,9 @@ class SearchControllerTest &lt; ActionController::TestCase
371 end 373 end
372 374
373 should 'see the events paginated' do 375 should 'see the events paginated' do
  376 + person = create_user('testuser').person
374 30.times do |i| 377 30.times do |i|
375 - create_event(person, :name => "Event #{i}", :start_date => Date.today) 378 + create_event(person, :name => "Event #{i}", :start_date => Date.today)
376 end 379 end
377 get :events 380 get :events
378 assert_equal 20, assigns(:events).count 381 assert_equal 20, assigns(:events).count
@@ -431,8 +434,8 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -431,8 +434,8 @@ class SearchControllerTest &lt; ActionController::TestCase
431 end 434 end
432 435
433 should 'show link to article asset in the see all foot link of the articles block in the category page' do 436 should 'show link to article asset in the see all foot link of the articles block in the category page' do
434 - (1..SearchController::MULTIPLE_SEARCH_LIMIT+1).each do |i|  
435 - a = create_user("test#{i}").person.articles.create!(:name => "article #{i} to be found") 437 + (1..SearchController::MULTIPLE_SEARCH_LIMIT+1).each do |i|
  438 + a = create_user("test#{i}").person.articles.create!(:name => "article #{i} to be found")
436 ArticleCategorization.add_category_to_article(@category, a) 439 ArticleCategorization.add_category_to_article(@category, a)
437 end 440 end
438 441
@@ -578,55 +581,55 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -578,55 +581,55 @@ class SearchControllerTest &lt; ActionController::TestCase
578 assert_not_includes assigns(:searches)[:communities][:results], p1 581 assert_not_includes assigns(:searches)[:communities][:results], p1
579 end 582 end
580 583
581 - should 'keep old urls working' do  
582 - get :assets, :asset => 'articles' 584 + should 'keep old urls working' do
  585 + get :assets, :asset => 'articles'
583 assert_redirected_to :controller => :search, :action => :articles 586 assert_redirected_to :controller => :search, :action => :articles
584 - get :assets, :asset => 'people' 587 + get :assets, :asset => 'people'
585 assert_redirected_to :controller => :search, :action => :people 588 assert_redirected_to :controller => :search, :action => :people
586 - get :assets, :asset => 'communities' 589 + get :assets, :asset => 'communities'
587 assert_redirected_to :controller => :search, :action => :communities 590 assert_redirected_to :controller => :search, :action => :communities
588 - get :assets, :asset => 'products' 591 + get :assets, :asset => 'products'
589 assert_redirected_to :controller => :search, :action => :products 592 assert_redirected_to :controller => :search, :action => :products
590 - get :assets, :asset => 'enterprises' 593 + get :assets, :asset => 'enterprises'
591 assert_redirected_to :controller => :search, :action => :enterprises 594 assert_redirected_to :controller => :search, :action => :enterprises
592 - get :assets, :asset => 'events' 595 + get :assets, :asset => 'events'
593 assert_redirected_to :controller => :search, :action => :events 596 assert_redirected_to :controller => :search, :action => :events
594 - end 597 + end
595 598
596 - should 'show tag cloud' do  
597 - @controller.stubs(:is_cache_expired?).returns(true) 599 + should 'show tag cloud' do
  600 + @controller.stubs(:is_cache_expired?).returns(true)
598 a = Article.create!(:name => 'my article', :profile_id => fast_create(Person).id) 601 a = Article.create!(:name => 'my article', :profile_id => fast_create(Person).id)
599 a.tag_list = ['one', 'two'] 602 a.tag_list = ['one', 'two']
600 - a.save_tags 603 + a.save_tags
601 604
602 - get :tags 605 + get :tags
603 606
604 - assert assigns(:tags)["two"] = 1  
605 - assert assigns(:tags)["one"] = 1  
606 - end 607 + assert assigns(:tags)["two"] = 1
  608 + assert assigns(:tags)["one"] = 1
  609 + end
607 610
608 should 'show tagged content' do 611 should 'show tagged content' do
609 - @controller.stubs(:is_cache_expired?).returns(true) 612 + @controller.stubs(:is_cache_expired?).returns(true)
610 a = Article.create!(:name => 'my article', :profile_id => fast_create(Person).id) 613 a = Article.create!(:name => 'my article', :profile_id => fast_create(Person).id)
611 a2 = Article.create!(:name => 'my article 2', :profile_id => fast_create(Person).id) 614 a2 = Article.create!(:name => 'my article 2', :profile_id => fast_create(Person).id)
612 a.tag_list = ['one', 'two'] 615 a.tag_list = ['one', 'two']
613 a2.tag_list = ['two', 'three'] 616 a2.tag_list = ['two', 'three']
614 - a.save_tags 617 + a.save_tags
615 a2.save_tags 618 a2.save_tags
616 619
617 - get :tag, :tag => 'two' 620 + get :tag, :tag => 'two'
618 621
619 assert_equivalent [a, a2], assigns(:searches)[:tag][:results] 622 assert_equivalent [a, a2], assigns(:searches)[:tag][:results]
620 623
621 - get :tag, :tag => 'one' 624 + get :tag, :tag => 'one'
622 625
623 assert_equivalent [a], assigns(:searches)[:tag][:results] 626 assert_equivalent [a], assigns(:searches)[:tag][:results]
624 end 627 end
625 628
626 should 'not show assets from other environments' do 629 should 'not show assets from other environments' do
627 other_env = Environment.create!(:name => 'Another environment') 630 other_env = Environment.create!(:name => 'Another environment')
628 - p1 = Person.create!(:name => 'Hildebrando', :identifier => 'hild', :user_id => fast_create(User).id, :environment_id => other_env.id)  
629 - p2 = Person.create!(:name => 'Adamastor', :identifier => 'adam', :user_id => fast_create(User).id) 631 + p1 = Person.create!(:name => 'Hildebrando', :identifier => 'hild', :user_id => fast_create(User).id, :environment_id => other_env.id)
  632 + p2 = Person.create!(:name => 'Adamastor', :identifier => 'adam', :user_id => fast_create(User).id)
630 art1 = Article.create!(:name => 'my article', :profile_id => p1.id) 633 art1 = Article.create!(:name => 'my article', :profile_id => p1.id)
631 art2 = Article.create!(:name => 'my article', :profile_id => p2.id) 634 art2 = Article.create!(:name => 'my article', :profile_id => p2.id)
632 635
@@ -637,9 +640,9 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -637,9 +640,9 @@ class SearchControllerTest &lt; ActionController::TestCase
637 640
638 should 'order articles by more recent' do 641 should 'order articles by more recent' do
639 Article.destroy_all 642 Article.destroy_all
640 - art1 = Article.create!(:name => 'review C', :profile_id => fast_create(Person).id, :created_at => Time.now-1.days)  
641 - art2 = Article.create!(:name => 'review A', :profile_id => fast_create(Person).id, :created_at => Time.now)  
642 - art3 = Article.create!(:name => 'review B', :profile_id => fast_create(Person).id, :created_at => Time.now-2.days) 643 + art1 = Article.create!(:name => 'review C', :profile_id => fast_create(Person).id, :created_at => Time.now-1.days)
  644 + art2 = Article.create!(:name => 'review A', :profile_id => fast_create(Person).id, :created_at => Time.now)
  645 + art3 = Article.create!(:name => 'review B', :profile_id => fast_create(Person).id, :created_at => Time.now-2.days)
643 646
644 get :articles, :filter => :more_recent 647 get :articles, :filter => :more_recent
645 648
test/integration/routing_test.rb
@@ -270,5 +270,8 @@ class RoutingTest &lt; ActionController::IntegrationTest @@ -270,5 +270,8 @@ class RoutingTest &lt; ActionController::IntegrationTest
270 assert_routing('/work/free-software/versions', :controller => 'content_viewer', :action => 'article_versions', :page => [ 'work', 'free-software'] ) 270 assert_routing('/work/free-software/versions', :controller => 'content_viewer', :action => 'article_versions', :page => [ 'work', 'free-software'] )
271 end 271 end
272 272
  273 + should 'have route to get HTML code of Blocks to embed' do
  274 + assert_routing('/embed/block/12345', :controller => 'embed', :action => 'block', :id => '12345')
  275 + end
273 276
274 end 277 end
test/unit/account_helper_test.rb 0 → 100644
@@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class AccountHelperTest < ActiveSupport::TestCase
  4 +
  5 + include AccountHelper
  6 + include ActionView::Helpers::TagHelper
  7 +
  8 + should 'not suggest usernames if username is empty' do
  9 + assert_equal '', suggestion_based_on_username
  10 + end
  11 +
  12 + should 'suggest valid usernames' do
  13 + ze = create_user('ze').person
  14 + stubs(:environment).returns(ze.environment)
  15 + suggestions = suggestion_based_on_username('ze')
  16 + suggestions.each do |suggestion|
  17 + assert_equal true, Person.is_available?(suggestion, ze.environment)
  18 + end
  19 + end
  20 +
  21 +end
test/unit/application_helper_test.rb
@@ -676,6 +676,7 @@ class ApplicationHelperTest &lt; ActiveSupport::TestCase @@ -676,6 +676,7 @@ class ApplicationHelperTest &lt; ActiveSupport::TestCase
676 should 'parse macros' do 676 should 'parse macros' do
677 class Plugin1 < Noosfero::Plugin 677 class Plugin1 < Noosfero::Plugin
678 end 678 end
  679 + Noosfero::Plugin.stubs(:all).returns(['ApplicationHelperTest::Plugin1'])
679 680
680 class Plugin1::Macro1 < Noosfero::Plugin::Macro 681 class Plugin1::Macro1 < Noosfero::Plugin::Macro
681 def parse(params, inner_html, source) 682 def parse(params, inner_html, source)
test/unit/block_test.rb
@@ -223,6 +223,61 @@ class BlockTest &lt; ActiveSupport::TestCase @@ -223,6 +223,61 @@ class BlockTest &lt; ActiveSupport::TestCase
223 assert !block.visible?(3) 223 assert !block.visible?(3)
224 end 224 end
225 225
  226 + should 'not be embedable by default' do
  227 + assert !Block.new.embedable?
  228 + end
  229 +
  230 + should 'generate embed code' do
  231 + b = Block.new
  232 + b.stubs(:url_for).returns('http://myblogtest.com/embed/block/1')
  233 + assert_equal "<iframe class=\"embed block block\" frameborder=\"0\" height=\"768\" src=\"http://myblogtest.com/embed/block/1\" width=\"1024\"></iframe>", b.embed_code.call
  234 + end
  235 +
  236 + should 'default value for display_user is all' do
  237 + block = Block.new
  238 + assert_equal 'all', block.display_user
  239 + end
  240 +
  241 + should 'display block to not logged users for display_user = all' do
  242 + block = Block.new
  243 + assert block.display_to_user?(nil)
  244 + end
  245 +
  246 + should 'display block to logged users for display_user = all' do
  247 + block = Block.new
  248 + assert block.display_to_user?(User.new)
  249 + end
  250 +
  251 + should 'display block to logged users for display_user = logged' do
  252 + block = Block.new
  253 + block.display_user = 'logged'
  254 + assert block.display_to_user?(User.new)
  255 + end
  256 +
  257 + should 'do not display block to logged users for display_user = not_logged' do
  258 + block = Block.new
  259 + block.display_user = 'not_logged'
  260 + assert !block.display_to_user?(User.new)
  261 + end
  262 +
  263 + should 'do not display block to not logged users for display_user = logged' do
  264 + block = Block.new
  265 + block.display_user = 'logged'
  266 + assert !block.display_to_user?(nil)
  267 + end
  268 +
  269 + should 'display block to not logged users for display_user = not_logged' do
  270 + block = Block.new
  271 + block.display_user = 'not_logged'
  272 + assert block.display_to_user?(nil)
  273 + end
  274 +
  275 + should 'not be visible if display_to_user? is false' do
  276 + block = Block.new
  277 + block.expects(:display_to_user?).once.returns(false)
  278 + assert !block.visible?({})
  279 + end
  280 +
226 should 'accept user as parameter on cache_key without change its value' do 281 should 'accept user as parameter on cache_key without change its value' do
227 person = fast_create(Person) 282 person = fast_create(Person)
228 block = Block.new 283 block = Block.new
test/unit/boxes_helper_test.rb
@@ -54,6 +54,7 @@ class BoxesHelperTest &lt; ActiveSupport::TestCase @@ -54,6 +54,7 @@ class BoxesHelperTest &lt; ActiveSupport::TestCase
54 expects(:display_block).with(b, '') 54 expects(:display_block).with(b, '')
55 stubs(:request).returns(request) 55 stubs(:request).returns(request)
56 stubs(:block_target).returns('') 56 stubs(:block_target).returns('')
  57 + stubs(:user).returns(nil)
57 expects(:locale).returns('en') 58 expects(:locale).returns('en')
58 with_box_decorator self do 59 with_box_decorator self do
59 display_box_content(box, '') 60 display_box_content(box, '')
@@ -73,6 +74,7 @@ class BoxesHelperTest &lt; ActiveSupport::TestCase @@ -73,6 +74,7 @@ class BoxesHelperTest &lt; ActiveSupport::TestCase
73 box.save! 74 box.save!
74 expects(:display_block).with(b, '').never 75 expects(:display_block).with(b, '').never
75 stubs(:request).returns(request) 76 stubs(:request).returns(request)
  77 + stubs(:user).returns(nil)
76 stubs(:block_target).returns('') 78 stubs(:block_target).returns('')
77 expects(:locale).returns('en') 79 expects(:locale).returns('en')
78 display_box_content(box, '') 80 display_box_content(box, '')
@@ -111,8 +113,9 @@ class BoxesHelperTest &lt; ActiveSupport::TestCase @@ -111,8 +113,9 @@ class BoxesHelperTest &lt; ActiveSupport::TestCase
111 request.expects(:path).returns('/') 113 request.expects(:path).returns('/')
112 request.expects(:params).returns({}) 114 request.expects(:params).returns({})
113 stubs(:request).returns(request) 115 stubs(:request).returns(request)
  116 + stubs(:user).returns(nil)
114 expects(:locale).returns('en') 117 expects(:locale).returns('en')
115 - box_decorator.expects(:select_blocks).with([], {:article => nil, :request_path => '/', :locale => 'en', :params => {}}).returns([]) 118 + box_decorator.expects(:select_blocks).with([], {:article => nil, :request_path => '/', :locale => 'en', :params => {}, :user => nil}).returns([])
116 119
117 display_box_content(box, '') 120 display_box_content(box, '')
118 end 121 end
test/unit/comment_test.rb
@@ -468,8 +468,8 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -468,8 +468,8 @@ class CommentTest &lt; ActiveSupport::TestCase
468 end 468 end
469 end 469 end
470 470
471 -  
472 should 'delegate spam detection to plugins' do 471 should 'delegate spam detection to plugins' do
  472 + Noosfero::Plugin.stubs(:all).returns(['CommentTest::EverythingIsSpam'])
473 Environment.default.enable_plugin(EverythingIsSpam) 473 Environment.default.enable_plugin(EverythingIsSpam)
474 474
475 c1 = create_comment 475 c1 = create_comment
@@ -495,6 +495,7 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -495,6 +495,7 @@ class CommentTest &lt; ActiveSupport::TestCase
495 end 495 end
496 496
497 should 'notify plugins of comments being marked as spam' do 497 should 'notify plugins of comments being marked as spam' do
  498 + Noosfero::Plugin.stubs(:all).returns(['CommentTest::SpamNotification'])
498 Environment.default.enable_plugin(SpamNotification) 499 Environment.default.enable_plugin(SpamNotification)
499 500
500 c = create_comment 501 c = create_comment
@@ -506,6 +507,7 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -506,6 +507,7 @@ class CommentTest &lt; ActiveSupport::TestCase
506 end 507 end
507 508
508 should 'notify plugins of comments being marked as ham' do 509 should 'notify plugins of comments being marked as ham' do
  510 + Noosfero::Plugin.stubs(:all).returns(['CommentTest::SpamNotification'])
509 Environment.default.enable_plugin(SpamNotification) 511 Environment.default.enable_plugin(SpamNotification)
510 512
511 c = create_comment 513 c = create_comment
test/unit/forgot_password_helper_test.rb
@@ -22,6 +22,7 @@ class ForgotPasswordHelperTest &lt; ActionView::TestCase @@ -22,6 +22,7 @@ class ForgotPasswordHelperTest &lt; ActionView::TestCase
22 {:field => 'f3', :name => 'F3', :model => 'person'}] 22 {:field => 'f3', :name => 'F3', :model => 'person'}]
23 end 23 end
24 end 24 end
  25 + Noosfero::Plugin.stubs(:all).returns(['ForgotPasswordHelperTest::Plugin1', 'ForgotPasswordHelperTest::Plugin2'])
25 26
26 environment.enable_plugin(Plugin1) 27 environment.enable_plugin(Plugin1)
27 environment.enable_plugin(Plugin2) 28 environment.enable_plugin(Plugin2)
@@ -43,6 +44,7 @@ class ForgotPasswordHelperTest &lt; ActionView::TestCase @@ -43,6 +44,7 @@ class ForgotPasswordHelperTest &lt; ActionView::TestCase
43 {:field => 'f3', :name => 'F3', :model => 'person'}] 44 {:field => 'f3', :name => 'F3', :model => 'person'}]
44 end 45 end
45 end 46 end
  47 + Noosfero::Plugin.stubs(:all).returns(['ForgotPasswordHelperTest::Plugin1', 'ForgotPasswordHelperTest::Plugin2'])
46 48
47 environment.enable_plugin(Plugin1) 49 environment.enable_plugin(Plugin1)
48 environment.enable_plugin(Plugin2) 50 environment.enable_plugin(Plugin2)
@@ -64,6 +66,7 @@ class ForgotPasswordHelperTest &lt; ActionView::TestCase @@ -64,6 +66,7 @@ class ForgotPasswordHelperTest &lt; ActionView::TestCase
64 {:field => 'f3', :name => 'F3', :model => 'user'}] 66 {:field => 'f3', :name => 'F3', :model => 'user'}]
65 end 67 end
66 end 68 end
  69 + Noosfero::Plugin.stubs(:all).returns(['ForgotPasswordHelperTest::Plugin1', 'ForgotPasswordHelperTest::Plugin2'])
67 70
68 environment.enable_plugin(Plugin1) 71 environment.enable_plugin(Plugin1)
69 environment.enable_plugin(Plugin2) 72 environment.enable_plugin(Plugin2)
@@ -85,6 +88,7 @@ class ForgotPasswordHelperTest &lt; ActionView::TestCase @@ -85,6 +88,7 @@ class ForgotPasswordHelperTest &lt; ActionView::TestCase
85 {:field => 'f3', :name => 'F3', :model => 'user'}] 88 {:field => 'f3', :name => 'F3', :model => 'user'}]
86 end 89 end
87 end 90 end
  91 + Noosfero::Plugin.stubs(:all).returns(['ForgotPasswordHelperTest::Plugin1', 'ForgotPasswordHelperTest::Plugin2'])
88 92
89 environment.enable_plugin(Plugin1) 93 environment.enable_plugin(Plugin1)
90 environment.enable_plugin(Plugin2) 94 environment.enable_plugin(Plugin2)
test/unit/link_list_block_test.rb
@@ -39,6 +39,32 @@ class LinkListBlockTest &lt; ActiveSupport::TestCase @@ -39,6 +39,32 @@ class LinkListBlockTest &lt; ActiveSupport::TestCase
39 assert_tag_in_string l.content, :tag => 'a', :attributes => {:href => '/test_profile/address'} 39 assert_tag_in_string l.content, :tag => 'a', :attributes => {:href => '/test_profile/address'}
40 end 40 end
41 41
  42 + should 'replace {portal} with environment portal identifier' do
  43 + env = Environment.default
  44 + env.enable('use_portal_community')
  45 + portal = fast_create(Community, :identifier => 'portal-community', :environment_id => env.id)
  46 + env.portal_community = portal
  47 + env.save
  48 +
  49 + stubs(:environment).returns(env)
  50 + l = LinkListBlock.new(:links => [{:name => 'categ', :address => '/{portal}/address'}])
  51 + l.stubs(:owner).returns(env)
  52 + assert_tag_in_string l.content, :tag => 'a', :attributes => {:href => '/portal-community/address'}
  53 + end
  54 +
  55 + should 'not change address if no {portal} there' do
  56 + env = Environment.default
  57 + env.enable('use_portal_community')
  58 + portal = fast_create(Community, :identifier => 'portal-community', :environment_id => env.id)
  59 + env.portal_community = portal
  60 + env.save
  61 +
  62 + stubs(:environment).returns(env)
  63 + l = LinkListBlock.new(:links => [{:name => 'categ', :address => '/address'}])
  64 + l.stubs(:owner).returns(env)
  65 + assert_tag_in_string l.content, :tag => 'a', :attributes => {:href => '/address'}
  66 + end
  67 +
42 should 'display options for icons' do 68 should 'display options for icons' do
43 l = LinkListBlock.new 69 l = LinkListBlock.new
44 l.icons_options.each do |option| 70 l.icons_options.each do |option|
test/unit/macros_helper_test.rb
@@ -28,6 +28,7 @@ class MacrosHelperTest &lt; ActiveSupport::TestCase @@ -28,6 +28,7 @@ class MacrosHelperTest &lt; ActiveSupport::TestCase
28 end 28 end
29 29
30 def setup 30 def setup
  31 + Noosfero::Plugin.stubs(:all).returns(['MacrosHelperTest::Plugin1'])
31 @environment = Environment.default 32 @environment = Environment.default
32 @environment.enable_plugin(Plugin1) 33 @environment.enable_plugin(Plugin1)
33 @plugins = Noosfero::Plugin::Manager.new(@environment, self) 34 @plugins = Noosfero::Plugin::Manager.new(@environment, self)
test/unit/person_test.rb
@@ -1255,6 +1255,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -1255,6 +1255,7 @@ class PersonTest &lt; ActiveSupport::TestCase
1255 false 1255 false
1256 end 1256 end
1257 end 1257 end
  1258 + Noosfero::Plugin.stubs(:all).returns(['PersonTest::Plugin1', 'PersonTest::Plugin2'])
1258 1259
1259 e = Environment.default 1260 e = Environment.default
1260 e.enable_plugin(Plugin1.name) 1261 e.enable_plugin(Plugin1.name)
@@ -1424,6 +1425,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -1424,6 +1425,7 @@ class PersonTest &lt; ActiveSupport::TestCase
1424 Profile.memberships_of(Person.find_by_identifier('person2')) 1425 Profile.memberships_of(Person.find_by_identifier('person2'))
1425 end 1426 end
1426 end 1427 end
  1428 + Noosfero::Plugin.stubs(:all).returns(['PersonTest::Plugin1', 'PersonTest::Plugin2'])
1427 1429
1428 Environment.default.enable_plugin(Plugin1) 1430 Environment.default.enable_plugin(Plugin1)
1429 Environment.default.enable_plugin(Plugin2) 1431 Environment.default.enable_plugin(Plugin2)
test/unit/plugin_manager_test.rb
@@ -26,6 +26,7 @@ class PluginManagerTest &lt; ActiveSupport::TestCase @@ -26,6 +26,7 @@ class PluginManagerTest &lt; ActiveSupport::TestCase
26 class Plugin2 < Noosfero::Plugin; end; 26 class Plugin2 < Noosfero::Plugin; end;
27 class Plugin3 < Noosfero::Plugin; end; 27 class Plugin3 < Noosfero::Plugin; end;
28 class Plugin4 < Noosfero::Plugin; end; 28 class Plugin4 < Noosfero::Plugin; end;
  29 + Noosfero::Plugin.stubs(:all).returns(['PluginManagerTest::Plugin1', 'PluginManagerTest::Plugin2', 'PluginManagerTest::Plugin3', 'PluginManagerTest::Plugin4'])
29 environment.stubs(:enabled_plugins).returns([Plugin1.to_s, Plugin2.to_s, Plugin4.to_s]) 30 environment.stubs(:enabled_plugins).returns([Plugin1.to_s, Plugin2.to_s, Plugin4.to_s])
30 Noosfero::Plugin.stubs(:all).returns([Plugin1.to_s, Plugin3.to_s, Plugin4.to_s]) 31 Noosfero::Plugin.stubs(:all).returns([Plugin1.to_s, Plugin3.to_s, Plugin4.to_s])
31 results = plugins.enabled_plugins.map { |instance| instance.class.to_s } 32 results = plugins.enabled_plugins.map { |instance| instance.class.to_s }
@@ -51,6 +52,7 @@ class PluginManagerTest &lt; ActiveSupport::TestCase @@ -51,6 +52,7 @@ class PluginManagerTest &lt; ActiveSupport::TestCase
51 'Plugin 2 action.' 52 'Plugin 2 action.'
52 end 53 end
53 end 54 end
  55 + Noosfero::Plugin.stubs(:all).returns(['PluginManagerTest::Plugin1', 'PluginManagerTest::Plugin2'])
54 56
55 environment.stubs(:enabled_plugins).returns([Plugin1.to_s, Plugin2.to_s]) 57 environment.stubs(:enabled_plugins).returns([Plugin1.to_s, Plugin2.to_s])
56 58
@@ -83,6 +85,7 @@ class PluginManagerTest &lt; ActiveSupport::TestCase @@ -83,6 +85,7 @@ class PluginManagerTest &lt; ActiveSupport::TestCase
83 'Plugin 3 action.' 85 'Plugin 3 action.'
84 end 86 end
85 end 87 end
  88 + Noosfero::Plugin.stubs(:all).returns(['PluginManagerTest::Plugin1', 'PluginManagerTest::Plugin2', 'PluginManagerTest::Plugin3'])
86 89
87 environment.stubs(:enabled_plugins).returns([Plugin1.to_s, Plugin2.to_s, Plugin3.to_s]) 90 environment.stubs(:enabled_plugins).returns([Plugin1.to_s, Plugin2.to_s, Plugin3.to_s])
88 p1 = Plugin1.new 91 p1 = Plugin1.new
@@ -107,6 +110,7 @@ class PluginManagerTest &lt; ActiveSupport::TestCase @@ -107,6 +110,7 @@ class PluginManagerTest &lt; ActiveSupport::TestCase
107 'Plugin3' 110 'Plugin3'
108 end 111 end
109 end 112 end
  113 + Noosfero::Plugin.stubs(:all).returns(['PluginManagerTest::Plugin1', 'PluginManagerTest::Plugin2', 'PluginManagerTest::Plugin3'])
110 114
111 environment.enable_plugin(Plugin1.name) 115 environment.enable_plugin(Plugin1.name)
112 environment.enable_plugin(Plugin2.name) 116 environment.enable_plugin(Plugin2.name)
@@ -134,6 +138,7 @@ class PluginManagerTest &lt; ActiveSupport::TestCase @@ -134,6 +138,7 @@ class PluginManagerTest &lt; ActiveSupport::TestCase
134 true 138 true
135 end 139 end
136 end 140 end
  141 + Noosfero::Plugin.stubs(:all).returns(['PluginManagerTest::Plugin1', 'PluginManagerTest::Plugin2', 'PluginManagerTest::Plugin3'])
137 142
138 environment.enable_plugin(Plugin1.name) 143 environment.enable_plugin(Plugin1.name)
139 environment.enable_plugin(Plugin2.name) 144 environment.enable_plugin(Plugin2.name)
@@ -162,6 +167,7 @@ class PluginManagerTest &lt; ActiveSupport::TestCase @@ -162,6 +167,7 @@ class PluginManagerTest &lt; ActiveSupport::TestCase
162 true 167 true
163 end 168 end
164 end 169 end
  170 + Noosfero::Plugin.stubs(:all).returns(['PluginManagerTest::Plugin1', 'PluginManagerTest::Plugin2', 'PluginManagerTest::Plugin3'])
165 171
166 environment.enable_plugin(Plugin1.name) 172 environment.enable_plugin(Plugin1.name)
167 environment.enable_plugin(Plugin2.name) 173 environment.enable_plugin(Plugin2.name)
@@ -178,6 +184,7 @@ class PluginManagerTest &lt; ActiveSupport::TestCase @@ -178,6 +184,7 @@ class PluginManagerTest &lt; ActiveSupport::TestCase
178 [Macro1, Macro2] 184 [Macro1, Macro2]
179 end 185 end
180 end 186 end
  187 + Noosfero::Plugin.stubs(:all).returns(['PluginManagerTest::Plugin1'])
181 188
182 class Plugin1::Macro1 < Noosfero::Plugin::Macro 189 class Plugin1::Macro1 < Noosfero::Plugin::Macro
183 def convert(macro, source) 190 def convert(macro, source)
@@ -212,6 +219,7 @@ class PluginManagerTest &lt; ActiveSupport::TestCase @@ -212,6 +219,7 @@ class PluginManagerTest &lt; ActiveSupport::TestCase
212 [v1 * v, v2 * v] 219 [v1 * v, v2 * v]
213 end 220 end
214 end 221 end
  222 + Noosfero::Plugin.stubs(:all).returns(['PluginManagerTest::Plugin1', 'PluginManagerTest::Plugin2'])
215 223
216 environment.enable_plugin(Plugin1) 224 environment.enable_plugin(Plugin1)
217 environment.enable_plugin(Plugin2) 225 environment.enable_plugin(Plugin2)
@@ -231,6 +239,7 @@ class PluginManagerTest &lt; ActiveSupport::TestCase @@ -231,6 +239,7 @@ class PluginManagerTest &lt; ActiveSupport::TestCase
231 value * 5 239 value * 5
232 end 240 end
233 end 241 end
  242 + Noosfero::Plugin.stubs(:all).returns(['PluginManagerTest::Plugin1', 'PluginManagerTest::Plugin2'])
234 243
235 environment.enable_plugin(Plugin1) 244 environment.enable_plugin(Plugin1)
236 environment.enable_plugin(Plugin2) 245 environment.enable_plugin(Plugin2)
@@ -252,6 +261,7 @@ class PluginManagerTest &lt; ActiveSupport::TestCase @@ -252,6 +261,7 @@ class PluginManagerTest &lt; ActiveSupport::TestCase
252 [v1 * v, v2 * v, 666] 261 [v1 * v, v2 * v, 666]
253 end 262 end
254 end 263 end
  264 + Noosfero::Plugin.stubs(:all).returns(['PluginManagerTest::Plugin1', 'PluginManagerTest::Plugin2'])
255 265
256 environment.enable_plugin(Plugin1) 266 environment.enable_plugin(Plugin1)
257 environment.enable_plugin(Plugin2) 267 environment.enable_plugin(Plugin2)
@@ -273,6 +283,7 @@ class PluginManagerTest &lt; ActiveSupport::TestCase @@ -273,6 +283,7 @@ class PluginManagerTest &lt; ActiveSupport::TestCase
273 numbers.reject {|n| n<=5} 283 numbers.reject {|n| n<=5}
274 end 284 end
275 end 285 end
  286 + Noosfero::Plugin.stubs(:all).returns(['PluginManagerTest::Plugin1', 'PluginManagerTest::Plugin2'])
276 287
277 environment.enable_plugin(Plugin1) 288 environment.enable_plugin(Plugin1)
278 environment.enable_plugin(Plugin2) 289 environment.enable_plugin(Plugin2)
test/unit/plugin_test.rb
@@ -9,15 +9,9 @@ class PluginTest &lt; ActiveSupport::TestCase @@ -9,15 +9,9 @@ class PluginTest &lt; ActiveSupport::TestCase
9 9
10 include Noosfero::Plugin::HotSpot 10 include Noosfero::Plugin::HotSpot
11 11
12 - should 'keep the list of all loaded subclasses' do  
13 - class Plugin1 < Noosfero::Plugin  
14 - end  
15 -  
16 - class Plugin2 < Noosfero::Plugin  
17 - end  
18 -  
19 - assert_includes Noosfero::Plugin.all, Plugin1.to_s  
20 - assert_includes Noosfero::Plugin.all, Plugin2.to_s 12 + should 'keep the list of all available plugins' do
  13 + assert File.directory?(File.join(Rails.root, 'plugins', 'foo'))
  14 + assert_includes Noosfero::Plugin.all, 'FooPlugin'
21 end 15 end
22 16
23 should 'returns url to plugin management if plugin has admin_controller' do 17 should 'returns url to plugin management if plugin has admin_controller' do
test/unit/profile_test.rb
@@ -363,7 +363,7 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -363,7 +363,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
363 t2 = c.tasks.build; t2.save!; t2.finish 363 t2 = c.tasks.build; t2.save!; t2.finish
364 t3 = c.tasks.build; t3.save!; t3.finish 364 t3 = c.tasks.build; t3.save!; t3.finish
365 365
366 - assert_equal [t2, t3], c.tasks.finished 366 + assert_equivalent [t2, t3], c.tasks.finished
367 end 367 end
368 368
369 should 'responds to categories' do 369 should 'responds to categories' do
@@ -1812,6 +1812,7 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -1812,6 +1812,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
1812 Person.members_of(Community.find_by_identifier('community2')) 1812 Person.members_of(Community.find_by_identifier('community2'))
1813 end 1813 end
1814 end 1814 end
  1815 + Noosfero::Plugin.stubs(:all).returns(['ProfileTest::Plugin1', 'ProfileTest::Plugin2'])
1815 Environment.default.enable_plugin(Plugin1) 1816 Environment.default.enable_plugin(Plugin1)
1816 Environment.default.enable_plugin(Plugin2) 1817 Environment.default.enable_plugin(Plugin2)
1817 1818
@@ -1969,6 +1970,7 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -1969,6 +1970,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
1969 end 1970 end
1970 1971
1971 environment = Environment.default 1972 environment = Environment.default
  1973 + Noosfero::Plugin.stubs(:all).returns(['ProfileTest::Plugin1'])
1972 environment.enable_plugin(Plugin1) 1974 environment.enable_plugin(Plugin1)
1973 plugins = Noosfero::Plugin::Manager.new(environment, self) 1975 plugins = Noosfero::Plugin::Manager.new(environment, self)
1974 p = fast_create(Profile) 1976 p = fast_create(Profile)
test/unit/suggest_article_test.rb
@@ -7,6 +7,7 @@ class SuggestArticleTest &lt; ActiveSupport::TestCase @@ -7,6 +7,7 @@ class SuggestArticleTest &lt; ActiveSupport::TestCase
7 ActionMailer::Base.perform_deliveries = true 7 ActionMailer::Base.perform_deliveries = true
8 ActionMailer::Base.deliveries = [] 8 ActionMailer::Base.deliveries = []
9 @profile = create_user('test_user').person 9 @profile = create_user('test_user').person
  10 + Noosfero::Plugin.stubs(:all).returns(['SuggestArticleTest::EverythingIsSpam', 'SuggestArticleTest::SpamNotification'])
10 end 11 end
11 attr_reader :profile 12 attr_reader :profile
12 13
test/unit/tags_helper_test.rb
@@ -20,12 +20,14 @@ class TagsHelperTest &lt; ActiveSupport::TestCase @@ -20,12 +20,14 @@ class TagsHelperTest &lt; ActiveSupport::TestCase
20 20
21 should 'order tags alphabetically with special characters' do 21 should 'order tags alphabetically with special characters' do
22 result = tag_cloud( 22 result = tag_cloud(
23 - { 'aula'=>9, 'área'=>2, 'area'=>2, 'avião'=>2, 'armário'=>2,  
24 - 'A'=>1, 'Á'=>1, 'AB'=>1, 'ÁA'=>1 }, 23 + { 'area'=>9, 'área'=>2, 'base'=>2, 'báse' => 3,
  24 + 'A'=>1, 'Á'=>1, 'zebra'=>1, 'zebrá'=>1 },
25 :id, 25 :id,
26 { :host=>'noosfero.org', :controller=>'test', :action=>'tag' } 26 { :host=>'noosfero.org', :controller=>'test', :action=>'tag' }
27 ) 27 )
28 - assert_equal %w(A Á ÁA AB area área armário aula avião).join("\n"), result 28 + result = result.split("\n")
  29 + assert_order ['Á', 'área', 'báse', 'zebrá'], result
  30 + assert_order ['A', 'area', 'base', 'zebra'], result
29 end 31 end
30 32
31 end 33 end
test/unit/text_article_test.rb
@@ -37,4 +37,51 @@ class TextArticleTest &lt; ActiveSupport::TestCase @@ -37,4 +37,51 @@ class TextArticleTest &lt; ActiveSupport::TestCase
37 assert_equal Blog.icon_name, TextArticle.icon_name(article) 37 assert_equal Blog.icon_name, TextArticle.icon_name(article)
38 end 38 end
39 39
  40 + should 'change image path to relative' do
  41 + person = create_user('testuser').person
  42 + article = TextArticle.new(:profile => person, :name => 'test')
  43 + env = Environment.default
  44 + article.body = "<img src=\"http://#{env.default_hostname}/test.png\" />"
  45 + article.save!
  46 + assert_equal "<img src=\"/test.png\" />", article.body
  47 + end
  48 +
  49 + should 'change link to relative path' do
  50 + person = create_user('testuser').person
  51 + article = TextArticle.new(:profile => person, :name => 'test')
  52 + env = Environment.default
  53 + article.body = "<a href=\"http://#{env.default_hostname}/test\">test</a>"
  54 + article.save!
  55 + assert_equal "<a href=\"/test\">test</a>", article.body
  56 + end
  57 +
  58 + should 'change image path to relative for domain with https' do
  59 + person = create_user('testuser').person
  60 + article = TextArticle.new(:profile => person, :name => 'test')
  61 + env = Environment.default
  62 + article.body = "<img src=\"https://#{env.default_hostname}/test.png\" />"
  63 + article.save!
  64 + assert_equal "<img src=\"/test.png\" />", article.body
  65 + end
  66 +
  67 + should 'change image path to relative for domain with port' do
  68 + person = create_user('testuser').person
  69 + article = TextArticle.new(:profile => person, :name => 'test')
  70 + env = Environment.default
  71 + article.body = "<img src=\"http://#{env.default_hostname}:3000/test.png\" />"
  72 + article.save!
  73 + assert_equal "<img src=\"/test.png\" />", article.body
  74 + end
  75 +
  76 + should 'change image path to relative for domain with www' do
  77 + person = create_user('testuser').person
  78 + article = TextArticle.new(:profile => person, :name => 'test')
  79 + env = Environment.default
  80 + env.force_www = true
  81 + env.save!
  82 + article.body = "<img src=\"http://#{env.default_hostname}:3000/test.png\" />"
  83 + article.save!
  84 + assert_equal "<img src=\"/test.png\" />", article.body
  85 + end
  86 +
40 end 87 end
test/unit/uploaded_file_test.rb
@@ -324,13 +324,11 @@ class UploadedFileTest &lt; ActiveSupport::TestCase @@ -324,13 +324,11 @@ class UploadedFileTest &lt; ActiveSupport::TestCase
324 should 'group trackers activity of image\'s upload' do 324 should 'group trackers activity of image\'s upload' do
325 ActionTracker::Record.delete_all 325 ActionTracker::Record.delete_all
326 gallery = fast_create(Gallery, :profile_id => profile.id) 326 gallery = fast_create(Gallery, :profile_id => profile.id)
327 - count = ActionTracker::Record.find_all_by_verb('upload_image').count  
328 image1 = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => gallery, :profile => profile) 327 image1 = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => gallery, :profile => profile)
329 - count += 1  
330 - assert_equal count, ActionTracker::Record.find_all_by_verb('upload_image').count 328 + assert_equal 1, ActionTracker::Record.find_all_by_verb('upload_image').count
331 329
332 image2 = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/other-pic.jpg', 'image/jpg'), :parent => gallery, :profile => profile) 330 image2 = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/other-pic.jpg', 'image/jpg'), :parent => gallery, :profile => profile)
333 - assert_equal count, ActionTracker::Record.find_all_by_verb('upload_image').count 331 + assert_equal 1, ActionTracker::Record.find_all_by_verb('upload_image').count
334 end 332 end
335 333
336 { 334 {