Commit ed6f20bb506691b63fefab297614180ca8815024
Exists in
staging
and in
1 other branch
fix merge with master conflit
Showing
209 changed files
with
2548 additions
and
1973 deletions
Show diff stats
.gitlab-ci.yml
... | ... | @@ -6,12 +6,13 @@ before_script: |
6 | 6 | - ./script/silent-quick-start |
7 | 7 | |
8 | 8 | stages: |
9 | - - smoke-tests | |
9 | + #FIXME Selenium tests are randomly failing and this avoid other tests to run. | |
10 | + #- smoke-tests | |
10 | 11 | - all-tests |
11 | 12 | |
12 | -smoke: | |
13 | - script: bundle exec rake ci:smoke | |
14 | - stage: smoke-tests | |
13 | +#smoke: | |
14 | +# script: bundle exec rake ci:smoke | |
15 | +# stage: smoke-tests | |
15 | 16 | |
16 | 17 | units: |
17 | 18 | script: bundle exec rake test:units | ... | ... |
.travis.yml
... | ... | @@ -55,7 +55,10 @@ env: |
55 | 55 | - TASK=test:integration |
56 | 56 | - TASK=cucumber LANG=en |
57 | 57 | - TASK=selenium |
58 | - - TASK=test:noosfero_plugins BUNDLE_OPTS=install | |
58 | + - SLICE=1/4 TASK=test:noosfero_plugins BUNDLE_OPTS=install | |
59 | + - SLICE=2/4 TASK=test:noosfero_plugins BUNDLE_OPTS=install | |
60 | + - SLICE=3/4 TASK=test:noosfero_plugins BUNDLE_OPTS=install | |
61 | + - SLICE=4/4 TASK=test:noosfero_plugins BUNDLE_OPTS=install | |
59 | 62 | |
60 | 63 | script: |
61 | 64 | - ./script/ci | ... | ... |
... | ... | @@ -0,0 +1,12 @@ |
1 | +If you made any significant change to the code that you consider worth being | |
2 | +reminded on the Release Notes, also include a correspondent entry here. If you | |
3 | +are not sure in which release your code will be released, include it on the | |
4 | +latest release and leave it to the commiter or RM responsible for it. | |
5 | + | |
6 | +v 1.5.0 (unreleased) | |
7 | + - Allow groups to disable admin email notificationo | |
8 | + - Add option to HighlightsBlock to open link in a new tab | |
9 | + - Move blocks html generation from models to helpers | |
10 | + | |
11 | +v 1.4.0 | |
12 | + - Migration from Rails 3 to Rails 4! | ... | ... |
Gemfile
... | ... | @@ -34,7 +34,7 @@ gem 'slim' |
34 | 34 | |
35 | 35 | # API dependencies |
36 | 36 | gem 'grape', '~> 0.12' |
37 | -gem 'grape-entity', '= 0.4.8' | |
37 | +gem 'grape-entity', '0.4.8' | |
38 | 38 | gem 'grape_logging' |
39 | 39 | gem 'grape-swagger' |
40 | 40 | gem 'swagger-ui_rails' |
... | ... | @@ -43,7 +43,7 @@ gem 'rack-cors' |
43 | 43 | gem 'rack-contrib' |
44 | 44 | gem 'liquid', '~> 3.0.3' |
45 | 45 | |
46 | -gem 'api-pagination', '~> 4.1.1' | |
46 | +gem 'api-pagination', '>= 4.1.1' | |
47 | 47 | |
48 | 48 | # asset pipeline |
49 | 49 | gem 'uglifier', '>= 1.0.3' | ... | ... |
Gemfile.lock
... | ... | @@ -21,14 +21,14 @@ PATH |
21 | 21 | access_control (0.0.0) |
22 | 22 | |
23 | 23 | PATH |
24 | - remote: vendor/plugins/action_tracker | |
24 | + remote: vendor/plugins/action_tracker_has_comments | |
25 | 25 | specs: |
26 | - action_tracker (0.0.1) | |
26 | + action_tracker_has_comments (0.0.0) | |
27 | 27 | |
28 | 28 | PATH |
29 | - remote: vendor/plugins/action_tracker_has_comments | |
29 | + remote: vendor/plugins/action_tracker | |
30 | 30 | specs: |
31 | - action_tracker_has_comments (0.0.0) | |
31 | + action_tracker (0.0.1) | |
32 | 32 | |
33 | 33 | PATH |
34 | 34 | remote: vendor/plugins/acts_as_list |
... | ... | @@ -425,7 +425,7 @@ DEPENDENCIES |
425 | 425 | acts_as_tree (= 0.0.0)! |
426 | 426 | acts_as_versioned (> 0.0.0)! |
427 | 427 | airbrake (~> 4) |
428 | - api-pagination (~> 4.1.1) | |
428 | + api-pagination (>= 4.1.1) | |
429 | 429 | capybara (~> 2.2) |
430 | 430 | contacts (> 0.0.0)! |
431 | 431 | cucumber |
... | ... | @@ -491,3 +491,6 @@ DEPENDENCIES |
491 | 491 | whenever |
492 | 492 | will_paginate (~> 3.0.7) |
493 | 493 | xss_terminate (= 0.0.0)! |
494 | + | |
495 | +BUNDLED WITH | |
496 | + 1.11.2 | ... | ... |
app/controllers/my_profile/tasks_controller.rb
... | ... | @@ -2,6 +2,8 @@ class TasksController < MyProfileController |
2 | 2 | |
3 | 3 | protect [:perform_task, :view_tasks], :profile, :only => [:index, :save_tags, :search_tags] |
4 | 4 | protect :perform_task, :profile, :only => [:processed, :change_responsible, :close, :new, :list_requested, :ticket_details, :search_tags] |
5 | + include TasksHelper | |
6 | + | |
5 | 7 | |
6 | 8 | def index |
7 | 9 | @rejection_email_templates = profile.email_templates.find_all_by_template_type(:task_rejection) |
... | ... | @@ -84,12 +86,12 @@ class TasksController < MyProfileController |
84 | 86 | end |
85 | 87 | end |
86 | 88 | |
87 | - url = { :action => 'index' } | |
89 | + url = tasks_url(:action => 'index') | |
88 | 90 | if failed.blank? |
89 | 91 | session[:notice] = _("All decisions were applied successfully.") |
90 | 92 | else |
91 | 93 | session[:notice] = _("Some decisions couldn't be applied.") |
92 | - url[:failed] = failed | |
94 | + url = tasks_url(:action => 'index', :failed => failed) | |
93 | 95 | end |
94 | 96 | redirect_to url |
95 | 97 | end | ... | ... |
app/helpers/application_helper.rb
... | ... | @@ -50,6 +50,12 @@ module ApplicationHelper |
50 | 50 | |
51 | 51 | include TaskHelper |
52 | 52 | |
53 | + include ButtonsHelper | |
54 | + | |
55 | + include ProfileImageHelper | |
56 | + | |
57 | + include ThemeLoaderHelper | |
58 | + | |
53 | 59 | def locale |
54 | 60 | (@page && !@page.language.blank?) ? @page.language : FastGettext.locale |
55 | 61 | end |
... | ... | @@ -211,52 +217,6 @@ module ApplicationHelper |
211 | 217 | result |
212 | 218 | end |
213 | 219 | |
214 | - def button(type, label, url, html_options = {}) | |
215 | - html_options ||= {} | |
216 | - the_class = 'with-text' | |
217 | - if html_options.has_key?(:class) | |
218 | - the_class << ' ' << html_options[:class] | |
219 | - end | |
220 | - button_without_text type, label, url, html_options.merge(:class => the_class) | |
221 | - end | |
222 | - | |
223 | - def button_without_text(type, label, url, html_options = {}) | |
224 | - the_class = "button icon-#{type}" | |
225 | - if html_options.has_key?(:class) | |
226 | - the_class << ' ' << html_options[:class] | |
227 | - end | |
228 | - the_title = html_options[:title] || label | |
229 | - if html_options[:disabled] | |
230 | - content_tag('a', ' '+content_tag('span', label), html_options.merge(:class => the_class, :title => the_title)) | |
231 | - else | |
232 | - link_to(' '+content_tag('span', label), url, html_options.merge(:class => the_class, :title => the_title)) | |
233 | - end | |
234 | - end | |
235 | - | |
236 | - def button_to_function(type, label, js_code, html_options = {}, &block) | |
237 | - html_options[:class] = "button with-text" unless html_options[:class] | |
238 | - html_options[:class] << " icon-#{type}" | |
239 | - link_to_function(label, js_code, html_options, &block) | |
240 | - end | |
241 | - | |
242 | - def button_to_function_without_text(type, label, js_code, html_options = {}, &block) | |
243 | - html_options[:class] = "" unless html_options[:class] | |
244 | - html_options[:class] << " button icon-#{type}" | |
245 | - link_to_function(content_tag('span', label), js_code, html_options, &block) | |
246 | - end | |
247 | - | |
248 | - def button_to_remote(type, label, options, html_options = {}) | |
249 | - html_options[:class] = "button with-text" unless html_options[:class] | |
250 | - html_options[:class] << " icon-#{type}" | |
251 | - link_to_remote(label, options, html_options) | |
252 | - end | |
253 | - | |
254 | - def button_to_remote_without_text(type, label, options, html_options = {}) | |
255 | - html_options[:class] = "" unless html_options[:class] | |
256 | - html_options[:class] << " button icon-#{type}" | |
257 | - link_to_remote(content_tag('span', label), options, html_options.merge(:title => label)) | |
258 | - end | |
259 | - | |
260 | 220 | def icon(icon_name, html_options = {}) |
261 | 221 | the_class = "button #{icon_name}" |
262 | 222 | if html_options.has_key?(:class) |
... | ... | @@ -327,48 +287,6 @@ module ApplicationHelper |
327 | 287 | end |
328 | 288 | end |
329 | 289 | |
330 | - def theme_path | |
331 | - if session[:theme] | |
332 | - '/user_themes/' + current_theme | |
333 | - else | |
334 | - '/designs/themes/' + current_theme | |
335 | - end | |
336 | - end | |
337 | - | |
338 | - def current_theme | |
339 | - @current_theme ||= | |
340 | - begin | |
341 | - if session[:theme] | |
342 | - session[:theme] | |
343 | - else | |
344 | - # utility for developers: set the theme to 'random' in development mode and | |
345 | - # you will get a different theme every request. This is interesting for | |
346 | - # testing | |
347 | - if Rails.env.development? && environment.theme == 'random' | |
348 | - @random_theme ||= Dir.glob('public/designs/themes/*').map { |f| File.basename(f) }.rand | |
349 | - @random_theme | |
350 | - elsif Rails.env.development? && respond_to?(:params) && params[:theme] && File.exists?(Rails.root.join('public/designs/themes', params[:theme])) | |
351 | - params[:theme] | |
352 | - else | |
353 | - if profile && !profile.theme.nil? | |
354 | - profile.theme | |
355 | - elsif environment | |
356 | - environment.theme | |
357 | - else | |
358 | - if logger | |
359 | - logger.warn("No environment found. This is weird.") | |
360 | - logger.warn("Request environment: %s" % request.env.inspect) | |
361 | - logger.warn("Request parameters: %s" % params.inspect) | |
362 | - end | |
363 | - | |
364 | - # could not determine the theme, so return the default one | |
365 | - 'default' | |
366 | - end | |
367 | - end | |
368 | - end | |
369 | - end | |
370 | - end | |
371 | - | |
372 | 290 | def theme_view_file(template, theme=nil) |
373 | 291 | # Since we cannot control what people are doing in external themes, we |
374 | 292 | # will keep looking for the deprecated .rhtml extension here. |
... | ... | @@ -441,141 +359,6 @@ module ApplicationHelper |
441 | 359 | Theme.find(current_theme).owner.identifier |
442 | 360 | end |
443 | 361 | |
444 | - # generates a image tag for the profile. | |
445 | - # | |
446 | - # If the profile has no image set yet, then a default image is used. | |
447 | - def profile_image(profile, size=:portrait, opt={}) | |
448 | - return '' if profile.nil? | |
449 | - opt[:alt] ||= profile.name() | |
450 | - opt[:title] ||= '' | |
451 | - opt[:class] ||= '' | |
452 | - opt[:class] += ( profile.class == Person ? ' photo' : ' logo' ) | |
453 | - image_tag(profile_icon(profile, size), opt ) | |
454 | - end | |
455 | - | |
456 | - def profile_icon( profile, size=:portrait, return_mimetype=false ) | |
457 | - filename, mimetype = '', 'image/png' | |
458 | - if profile.image | |
459 | - filename = profile.image.public_filename( size ) | |
460 | - mimetype = profile.image.content_type | |
461 | - else | |
462 | - icon = | |
463 | - if profile.organization? | |
464 | - if profile.kind_of?(Community) | |
465 | - '/images/icons-app/community-'+ size.to_s() +'.png' | |
466 | - else | |
467 | - '/images/icons-app/enterprise-'+ size.to_s() +'.png' | |
468 | - end | |
469 | - else | |
470 | - pixels = Image.attachment_options[:thumbnails][size].split('x').first | |
471 | - gravatar_profile_image_url( | |
472 | - profile.email, | |
473 | - :size => pixels, | |
474 | - :d => gravatar_default | |
475 | - ) | |
476 | - end | |
477 | - filename = default_or_themed_icon(icon) | |
478 | - end | |
479 | - return_mimetype ? [filename, mimetype] : filename | |
480 | - end | |
481 | - | |
482 | - def default_or_themed_icon(icon) | |
483 | - if File.exists?(Rails.root.join('public', theme_path, icon)) | |
484 | - theme_path + icon | |
485 | - else | |
486 | - icon | |
487 | - end | |
488 | - end | |
489 | - | |
490 | - def profile_sex_icon( profile ) | |
491 | - return '' unless profile.is_a?(Person) | |
492 | - return '' unless !environment.enabled?('disable_gender_icon') | |
493 | - sex = ( profile.sex ? profile.sex.to_s() : 'undef' ) | |
494 | - title = ( sex == 'undef' ? _('non registered gender') : ( sex == 'male' ? _('Male') : _('Female') ) ) | |
495 | - sex = content_tag 'span', | |
496 | - content_tag( 'span', sex ), | |
497 | - :class => 'sex-'+sex, | |
498 | - :title => title | |
499 | - sex | |
500 | - end | |
501 | - | |
502 | - def links_for_balloon(profile) | |
503 | - if environment.enabled?(:show_balloon_with_profile_links_when_clicked) | |
504 | - if profile.kind_of?(Person) | |
505 | - [ | |
506 | - {_('Wall') => {:href => url_for(profile.public_profile_url)}}, | |
507 | - {_('Friends') => {:href => url_for(:controller => :profile, :action => :friends, :profile => profile.identifier)}}, | |
508 | - {_('Communities') => {:href => url_for(:controller => :profile, :action => :communities, :profile => profile.identifier)}}, | |
509 | - {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email', :style => 'display: none'}}, | |
510 | - {_('Add') => {:href => url_for(profile.add_url), :class => 'add-friend', :style => 'display: none'}} | |
511 | - ] | |
512 | - elsif profile.kind_of?(Community) | |
513 | - [ | |
514 | - {_('Wall') => {:href => url_for(profile.public_profile_url)}}, | |
515 | - {_('Members') => {:href => url_for(:controller => :profile, :action => :members, :profile => profile.identifier)}}, | |
516 | - {_('Agenda') => {:href => url_for(:controller => :profile, :action => :events, :profile => profile.identifier)}}, | |
517 | - {_('Join') => {:href => url_for(profile.join_url), :class => 'join-community', :style => 'display: none'}}, | |
518 | - {_('Leave community') => {:href => url_for(profile.leave_url), :class => 'leave-community', :style => 'display: none'}}, | |
519 | - {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email', :style => 'display: none'}} | |
520 | - ] | |
521 | - elsif profile.kind_of?(Enterprise) | |
522 | - [ | |
523 | - {_('Products') => {:href => catalog_path(profile.identifier)}}, | |
524 | - {_('Members') => {:href => url_for(:controller => :profile, :action => :members, :profile => profile.identifier)}}, | |
525 | - {_('Agenda') => {:href => url_for(:controller => :profile, :action => :events, :profile => profile.identifier)}}, | |
526 | - {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email', :style => 'display: none'}}, | |
527 | - ] | |
528 | - else | |
529 | - [] | |
530 | - end | |
531 | - end | |
532 | - end | |
533 | - | |
534 | - # displays a link to the profile homepage with its image (as generated by | |
535 | - # #profile_image) and its name below it. | |
536 | - def profile_image_link( profile, size=:portrait, tag='li', extra_info = nil ) | |
537 | - if content = @plugins.dispatch_first(:profile_image_link, profile, size, tag, extra_info) | |
538 | - return instance_exec(&content) | |
539 | - end | |
540 | - name = profile.short_name | |
541 | - if profile.person? | |
542 | - url = url_for(profile.check_friendship_url) | |
543 | - trigger_class = 'person-trigger' | |
544 | - else | |
545 | - city = '' | |
546 | - url = url_for(profile.check_membership_url) | |
547 | - if profile.community? | |
548 | - trigger_class = 'community-trigger' | |
549 | - elsif profile.enterprise? | |
550 | - trigger_class = 'enterprise-trigger' | |
551 | - end | |
552 | - end | |
553 | - | |
554 | - extra_info_tag = '' | |
555 | - img_class = 'profile-image' | |
556 | - | |
557 | - if extra_info.is_a? Hash | |
558 | - extra_info_tag = content_tag( 'span', extra_info[:value], :class => 'extra_info '+extra_info[:class]) | |
559 | - img_class +=' '+extra_info[:class] | |
560 | - else | |
561 | - extra_info_tag = content_tag( 'span', extra_info, :class => 'extra_info' ) | |
562 | - end | |
563 | - | |
564 | - links = links_for_balloon(profile) | |
565 | - content_tag('div', content_tag(tag, | |
566 | - (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? | |
567 | - popover_menu(_('Profile links'),profile.short_name,links,{:class => trigger_class, :url => url}) : "") + | |
568 | - link_to( | |
569 | - content_tag( 'span', profile_image( profile, size ), :class => img_class ) + | |
570 | - content_tag( 'span', h(name), :class => ( profile.class == Person ? 'fn' : 'org' ) ) + | |
571 | - extra_info_tag + profile_sex_icon( profile ), | |
572 | - profile.url, | |
573 | - :class => 'profile_link url', | |
574 | - :help => _('Click on this icon to go to the <b>%s</b>\'s home page') % profile.name, | |
575 | - :title => profile.name ), | |
576 | - :class => 'vcard'), :class => 'common-profile-list-block') | |
577 | - end | |
578 | - | |
579 | 362 | def popover_menu(title,menu_title,links,html_options={}) |
580 | 363 | html_options[:class] = "" unless html_options[:class] |
581 | 364 | html_options[:class] << " menu-submenu-trigger" |
... | ... | @@ -584,10 +367,6 @@ module ApplicationHelper |
584 | 367 | link_to(content_tag(:span, title), '#', html_options) |
585 | 368 | end |
586 | 369 | |
587 | - def gravatar_default | |
588 | - (respond_to?(:theme_option) && theme_option.present? && theme_option['gravatar']) || NOOSFERO_CONF['gravatar'] || 'mm' | |
589 | - end | |
590 | - | |
591 | 370 | attr_reader :environment |
592 | 371 | |
593 | 372 | def select_categories(object_name, title=nil, title_size=4) |
... | ... | @@ -936,13 +715,6 @@ module ApplicationHelper |
936 | 715 | content_for(:head) { stylesheet_link_tag(*args) } |
937 | 716 | end |
938 | 717 | |
939 | - def article_to_html(article, options = {}) | |
940 | - options.merge!(:page => params[:npage]) | |
941 | - content = article.to_html(options) | |
942 | - content = content.kind_of?(Proc) ? self.instance_exec(&content).html_safe : content.html_safe | |
943 | - filter_html(content, article) | |
944 | - end | |
945 | - | |
946 | 718 | # Please, use link_to by default! |
947 | 719 | # This method was created to work around to inexplicable |
948 | 720 | # chain of problems when display_short_format was called |
... | ... | @@ -1379,16 +1151,6 @@ module ApplicationHelper |
1379 | 1151 | @no_design_blocks = true |
1380 | 1152 | end |
1381 | 1153 | |
1382 | - def filter_html(html, source) | |
1383 | - if @plugins && source && source.has_macro? | |
1384 | - html = convert_macro(html, source) unless @plugins.enabled_macros.blank? | |
1385 | - #TODO This parse should be done through the macro infra, but since there | |
1386 | - # are old things that do not support it we are keeping this hot spot. | |
1387 | - html = @plugins.pipeline(:parse_content, html, source).first | |
1388 | - end | |
1389 | - html && html.html_safe | |
1390 | - end | |
1391 | - | |
1392 | 1154 | def convert_macro(html, source) |
1393 | 1155 | doc = Nokogiri::HTML.fragment html |
1394 | 1156 | #TODO This way is more efficient but do not support macro inside of | ... | ... |
app/helpers/article_helper.rb
... | ... | @@ -195,4 +195,21 @@ module ArticleHelper |
195 | 195 | end |
196 | 196 | end |
197 | 197 | |
198 | + def filter_html(html, source) | |
199 | + if @plugins && source && source.has_macro? | |
200 | + html = convert_macro(html, source) unless @plugins.enabled_macros.blank? | |
201 | + #TODO This parse should be done through the macro infra, but since there | |
202 | + # are old things that do not support it we are keeping this hot spot. | |
203 | + html = @plugins.pipeline(:parse_content, html, source).first | |
204 | + end | |
205 | + html && html.html_safe | |
206 | + end | |
207 | + | |
208 | + def article_to_html(article, options = {}) | |
209 | + options.merge!(:page => params[:npage]) | |
210 | + content = article.to_html(options) | |
211 | + content = content.kind_of?(Proc) ? self.instance_exec(&content).html_safe : content.html_safe | |
212 | + filter_html(content, article) | |
213 | + end | |
214 | + | |
198 | 215 | end | ... | ... |
app/helpers/boxes_helper.rb
... | ... | @@ -87,10 +87,38 @@ module BoxesHelper |
87 | 87 | box_decorator == DontMoveBlocks |
88 | 88 | end |
89 | 89 | |
90 | - def display_block_content(block, person, main_content = nil) | |
91 | - content = block.main? ? wrap_main_content(main_content) : block.content({:person => person}) | |
90 | + def render_block block, prefix = nil, klass = block.class | |
91 | + template_name = klass.name.underscore.sub '_block', '' | |
92 | + begin | |
93 | + render template: "blocks/#{prefix}#{template_name}", locals: { block: block } | |
94 | + rescue ActionView::MissingTemplate | |
95 | + return if klass.superclass === Block | |
96 | + render_block block, prefix, klass.superclass | |
97 | + end | |
98 | + end | |
99 | + | |
100 | + def render_block_content block | |
101 | + # FIXME: this conditional should be removed after all | |
102 | + # block footer from plugins methods get refactored into helpers and views. | |
103 | + # They are a failsafe until all of them are done. | |
104 | + return block.content if block.method(:content).owner != Block | |
105 | + render_block block | |
106 | + end | |
107 | + | |
108 | + def render_block_footer block | |
109 | + return block.footer if block.method(:footer).owner != Block | |
110 | + render_block block, 'footers/' | |
111 | + end | |
112 | + | |
113 | + def display_block_content(block, main_content = nil) | |
114 | + content = nil | |
115 | + if block.main? | |
116 | + content = wrap_main_content(main_content) | |
117 | + else | |
118 | + content = render_block_content block | |
119 | + end | |
92 | 120 | result = extract_block_content(content) |
93 | - footer_content = extract_block_content(block.footer) | |
121 | + footer_content = extract_block_content(render_block_footer block) | |
94 | 122 | unless footer_content.blank? |
95 | 123 | footer_content = content_tag('div', footer_content, :class => 'block-footer-content' ) |
96 | 124 | end | ... | ... |
... | ... | @@ -0,0 +1,47 @@ |
1 | +module ButtonsHelper | |
2 | + def button(type, label, url, html_options = {}) | |
3 | + html_options ||= {} | |
4 | + the_class = 'with-text' | |
5 | + if html_options.has_key?(:class) | |
6 | + the_class << ' ' << html_options[:class] | |
7 | + end | |
8 | + button_without_text type, label, url, html_options.merge(:class => the_class) | |
9 | + end | |
10 | + | |
11 | + def button_without_text(type, label, url, html_options = {}) | |
12 | + the_class = "button icon-#{type}" | |
13 | + if html_options.has_key?(:class) | |
14 | + the_class << ' ' << html_options[:class] | |
15 | + end | |
16 | + the_title = html_options[:title] || label | |
17 | + if html_options[:disabled] | |
18 | + content_tag('a', ' '+content_tag('span', label), html_options.merge(:class => the_class, :title => the_title)) | |
19 | + else | |
20 | + link_to(' '+content_tag('span', label), url, html_options.merge(:class => the_class, :title => the_title)) | |
21 | + end | |
22 | + end | |
23 | + | |
24 | + def button_to_function(type, label, js_code, html_options = {}, &block) | |
25 | + html_options[:class] = "button with-text" unless html_options[:class] | |
26 | + html_options[:class] << " icon-#{type}" | |
27 | + link_to_function(label, js_code, html_options, &block) | |
28 | + end | |
29 | + | |
30 | + def button_to_function_without_text(type, label, js_code, html_options = {}, &block) | |
31 | + html_options[:class] = "" unless html_options[:class] | |
32 | + html_options[:class] << " button icon-#{type}" | |
33 | + link_to_function(content_tag('span', label), js_code, html_options, &block) | |
34 | + end | |
35 | + | |
36 | + def button_to_remote(type, label, options, html_options = {}) | |
37 | + html_options[:class] = "button with-text" unless html_options[:class] | |
38 | + html_options[:class] << " icon-#{type}" | |
39 | + link_to_remote(label, options, html_options) | |
40 | + end | |
41 | + | |
42 | + def button_to_remote_without_text(type, label, options, html_options = {}) | |
43 | + html_options[:class] = "" unless html_options[:class] | |
44 | + html_options[:class] << " button icon-#{type}" | |
45 | + link_to_remote(content_tag('span', label), options, html_options.merge(:title => label)) | |
46 | + end | |
47 | +end | ... | ... |
app/helpers/forms_helper.rb
... | ... | @@ -137,7 +137,7 @@ module FormsHelper |
137 | 137 | content_tag('table',rows.join("\n")) |
138 | 138 | end |
139 | 139 | |
140 | - def date_field(name, value, format = '%Y-%m-%d', datepicker_options = {}, html_options = {}) | |
140 | + def date_field(name, value, datepicker_options = {}, html_options = {}) | |
141 | 141 | datepicker_options[:disabled] ||= false |
142 | 142 | datepicker_options[:alt_field] ||= '' |
143 | 143 | datepicker_options[:alt_format] ||= '' |
... | ... | @@ -152,7 +152,7 @@ module FormsHelper |
152 | 152 | datepicker_options[:close_text] ||= _('Done') |
153 | 153 | datepicker_options[:constrain_input] ||= true |
154 | 154 | datepicker_options[:current_text] ||= _('Today') |
155 | - datepicker_options[:date_format] ||= 'yy/mm/dd' | |
155 | + datepicker_options[:date_format] ||= 'yy-mm-dd' | |
156 | 156 | datepicker_options[:day_names] ||= [_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday')] |
157 | 157 | datepicker_options[:day_names_min] ||= [_('Su'), _('Mo'), _('Tu'), _('We'), _('Th'), _('Fr'), _('Sa')] |
158 | 158 | datepicker_options[:day_names_short] ||= [_('Sun'), _('Mon'), _('Tue'), _('Wed'), _('Thu'), _('Fri'), _('Sat')] |
... | ... | @@ -184,10 +184,11 @@ module FormsHelper |
184 | 184 | datepicker_options[:year_range] ||= 'c-10:c+10' |
185 | 185 | datepicker_options[:year_suffix] ||= '' |
186 | 186 | |
187 | + date_format = datepicker_options[:time] ? "%Y-%m-%d %H:%M" : "%Y-%m-%d" | |
188 | + value = value.strftime(date_format) if value.present? | |
189 | + | |
187 | 190 | element_id = html_options[:id] || 'datepicker-date' |
188 | - value = value.strftime(format) if value.present? | |
189 | 191 | method = datepicker_options[:time] ? 'datetimepicker' : 'datepicker' |
190 | - current_date_or_nil = value.present? ? "new Date('#{value}')" : "null" | |
191 | 192 | result = text_field_tag(name, value, html_options) |
192 | 193 | result += |
193 | 194 | " |
... | ... | @@ -238,17 +239,17 @@ module FormsHelper |
238 | 239 | weekHeader: #{datepicker_options[:week_header].to_json}, |
239 | 240 | yearRange: #{datepicker_options[:year_range].to_json}, |
240 | 241 | yearSuffix: #{datepicker_options[:year_suffix].to_json} |
241 | - }).datepicker('setDate', current_date_or_nil) | |
242 | + }).datepicker() | |
242 | 243 | </script> |
243 | 244 | ".html_safe |
244 | 245 | result |
245 | 246 | end |
246 | 247 | |
247 | - def date_range_field(from_name, to_name, from_value, to_value, format = '%Y-%m-%d', datepicker_options = {}, html_options = {}) | |
248 | + def date_range_field(from_name, to_name, from_value, to_value, datepicker_options = {}, html_options = {}) | |
248 | 249 | from_id = html_options[:from_id] || 'datepicker-from-date' |
249 | 250 | to_id = html_options[:to_id] || 'datepicker-to-date' |
250 | - return _('From') +' '+ date_field(from_name, from_value, format, datepicker_options, html_options.merge({:id => from_id})) + | |
251 | - ' ' + _('until') +' '+ date_field(to_name, to_value, format, datepicker_options, html_options.merge({:id => to_id})) | |
251 | + return _('From') +' '+ date_field(from_name, from_value, datepicker_options, html_options.merge({:id => from_id})) + | |
252 | + ' ' + _('until') +' '+ date_field(to_name, to_value, datepicker_options, html_options.merge({:id => to_id})) | |
252 | 253 | end |
253 | 254 | |
254 | 255 | def select_folder(label_text, field_id, collection, default_value=nil, html_options = {}, js_options = {}) | ... | ... |
... | ... | @@ -0,0 +1,140 @@ |
1 | +module ProfileImageHelper | |
2 | + def default_or_themed_icon(icon) | |
3 | + if File.exists?(Rails.root.join('public', theme_path, icon)) | |
4 | + theme_path + icon | |
5 | + else | |
6 | + icon | |
7 | + end | |
8 | + end | |
9 | + | |
10 | + def gravatar_default | |
11 | + (respond_to?(:theme_option) && theme_option.present? && theme_option['gravatar']) || NOOSFERO_CONF['gravatar'] || 'mm' | |
12 | + end | |
13 | + | |
14 | + def profile_sex_icon( profile ) | |
15 | + return '' unless profile.is_a?(Person) | |
16 | + return '' unless !environment.enabled?('disable_gender_icon') | |
17 | + sex = ( profile.sex ? profile.sex.to_s() : 'undef' ) | |
18 | + title = ( sex == 'undef' ? _('non registered gender') : ( sex == 'male' ? _('Male') : _('Female') ) ) | |
19 | + sex = content_tag 'span', | |
20 | + content_tag( 'span', sex ), | |
21 | + :class => 'sex-'+sex, | |
22 | + :title => title | |
23 | + sex | |
24 | + end | |
25 | + | |
26 | + def profile_icon( profile, size=:portrait, return_mimetype=false ) | |
27 | + filename, mimetype = '', 'image/png' | |
28 | + if profile.image | |
29 | + filename = profile.image.public_filename( size ) | |
30 | + mimetype = profile.image.content_type | |
31 | + else | |
32 | + icon = | |
33 | + if profile.organization? | |
34 | + if profile.kind_of?(Community) | |
35 | + '/images/icons-app/community-'+ size.to_s() +'.png' | |
36 | + else | |
37 | + '/images/icons-app/enterprise-'+ size.to_s() +'.png' | |
38 | + end | |
39 | + else | |
40 | + pixels = Image.attachment_options[:thumbnails][size].split('x').first | |
41 | + gravatar_profile_image_url( | |
42 | + profile.email, | |
43 | + :size => pixels, | |
44 | + :d => gravatar_default | |
45 | + ) | |
46 | + end | |
47 | + filename = default_or_themed_icon(icon) | |
48 | + end | |
49 | + return_mimetype ? [filename, mimetype] : filename | |
50 | + end | |
51 | + | |
52 | + # generates a image tag for the profile. | |
53 | + # | |
54 | + # If the profile has no image set yet, then a default image is used. | |
55 | + def profile_image(profile, size=:portrait, opt={}) | |
56 | + return '' if profile.nil? | |
57 | + opt[:alt] ||= profile.name() | |
58 | + opt[:title] ||= '' | |
59 | + opt[:class] ||= '' | |
60 | + opt[:class] += ( profile.class == Person ? ' photo' : ' logo' ) | |
61 | + image_tag(profile_icon(profile, size), opt ) | |
62 | + end | |
63 | + | |
64 | + def links_for_balloon(profile) | |
65 | + if environment.enabled?(:show_balloon_with_profile_links_when_clicked) | |
66 | + if profile.kind_of?(Person) | |
67 | + [ | |
68 | + {_('Wall') => {:href => url_for(profile.public_profile_url)}}, | |
69 | + {_('Friends') => {:href => url_for(:controller => :profile, :action => :friends, :profile => profile.identifier)}}, | |
70 | + {_('Communities') => {:href => url_for(:controller => :profile, :action => :communities, :profile => profile.identifier)}}, | |
71 | + {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email', :style => 'display: none'}}, | |
72 | + {_('Add') => {:href => url_for(profile.add_url), :class => 'add-friend', :style => 'display: none'}} | |
73 | + ] | |
74 | + elsif profile.kind_of?(Community) | |
75 | + [ | |
76 | + {_('Wall') => {:href => url_for(profile.public_profile_url)}}, | |
77 | + {_('Members') => {:href => url_for(:controller => :profile, :action => :members, :profile => profile.identifier)}}, | |
78 | + {_('Agenda') => {:href => url_for(:controller => :profile, :action => :events, :profile => profile.identifier)}}, | |
79 | + {_('Join') => {:href => url_for(profile.join_url), :class => 'join-community', :style => 'display: none'}}, | |
80 | + {_('Leave community') => {:href => url_for(profile.leave_url), :class => 'leave-community', :style => 'display: none'}}, | |
81 | + {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email', :style => 'display: none'}} | |
82 | + ] | |
83 | + elsif profile.kind_of?(Enterprise) | |
84 | + [ | |
85 | + {_('Products') => {:href => catalog_path(profile.identifier)}}, | |
86 | + {_('Members') => {:href => url_for(:controller => :profile, :action => :members, :profile => profile.identifier)}}, | |
87 | + {_('Agenda') => {:href => url_for(:controller => :profile, :action => :events, :profile => profile.identifier)}}, | |
88 | + {_('Send an e-mail') => {:href => url_for(:profile => profile.identifier, :controller => 'contact', :action => 'new'), :class => 'send-an-email', :style => 'display: none'}}, | |
89 | + ] | |
90 | + else | |
91 | + [] | |
92 | + end | |
93 | + end | |
94 | + end | |
95 | + | |
96 | + # displays a link to the profile homepage with its image (as generated by | |
97 | + # #profile_image) and its name below it. | |
98 | + def profile_image_link( profile, size=:portrait, tag='li', extra_info = nil ) | |
99 | + if content = @plugins.dispatch_first(:profile_image_link, profile, size, tag, extra_info) | |
100 | + return instance_exec(&content) | |
101 | + end | |
102 | + name = profile.short_name | |
103 | + if profile.person? | |
104 | + url = url_for(profile.check_friendship_url) | |
105 | + trigger_class = 'person-trigger' | |
106 | + else | |
107 | + city = '' | |
108 | + url = url_for(profile.check_membership_url) | |
109 | + if profile.community? | |
110 | + trigger_class = 'community-trigger' | |
111 | + elsif profile.enterprise? | |
112 | + trigger_class = 'enterprise-trigger' | |
113 | + end | |
114 | + end | |
115 | + | |
116 | + extra_info_tag = '' | |
117 | + img_class = 'profile-image' | |
118 | + | |
119 | + if extra_info.is_a? Hash | |
120 | + extra_info_tag = content_tag( 'span', extra_info[:value], :class => 'extra_info '+extra_info[:class]) | |
121 | + img_class +=' '+extra_info[:class] | |
122 | + else | |
123 | + extra_info_tag = content_tag( 'span', extra_info, :class => 'extra_info' ) | |
124 | + end | |
125 | + | |
126 | + links = links_for_balloon(profile) | |
127 | + content_tag('div', content_tag(tag, | |
128 | + (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? | |
129 | + popover_menu(_('Profile links'),profile.short_name,links,{:class => trigger_class, :url => url}) : "") + | |
130 | + link_to( | |
131 | + content_tag( 'span', profile_image( profile, size ), :class => img_class ) + | |
132 | + content_tag( 'span', h(name), :class => ( profile.class == Person ? 'fn' : 'org' ) ) + | |
133 | + extra_info_tag + profile_sex_icon( profile ), | |
134 | + profile.url, | |
135 | + :class => 'profile_link url', | |
136 | + :help => _('Click on this icon to go to the <b>%s</b>\'s home page') % profile.name, | |
137 | + :title => profile.name ), | |
138 | + :class => 'vcard'), :class => 'common-profile-list-block') | |
139 | + end | |
140 | +end | |
0 | 141 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,12 @@ |
1 | +module TasksHelper | |
2 | + | |
3 | + def tasks_url options = {} | |
4 | + url_for(options.merge(filter_params)) | |
5 | + end | |
6 | + | |
7 | + def filter_params | |
8 | + filter_fields = ['filter_type', 'filter_text', 'filter_responsible', 'filter_tags'] | |
9 | + params.select {|filter| filter if filter_fields.include? filter } | |
10 | + end | |
11 | + | |
12 | +end | ... | ... |
... | ... | @@ -0,0 +1,43 @@ |
1 | +module ThemeLoaderHelper | |
2 | + def current_theme | |
3 | + @current_theme ||= | |
4 | + begin | |
5 | + if session[:theme] | |
6 | + session[:theme] | |
7 | + else | |
8 | + # utility for developers: set the theme to 'random' in development mode and | |
9 | + # you will get a different theme every request. This is interesting for | |
10 | + # testing | |
11 | + if Rails.env.development? && environment.theme == 'random' | |
12 | + @random_theme ||= Dir.glob('public/designs/themes/*').map { |f| File.basename(f) }.rand | |
13 | + @random_theme | |
14 | + elsif Rails.env.development? && respond_to?(:params) && params[:theme] && File.exists?(Rails.root.join('public/designs/themes', params[:theme])) | |
15 | + params[:theme] | |
16 | + else | |
17 | + if profile && !profile.theme.nil? | |
18 | + profile.theme | |
19 | + elsif environment | |
20 | + environment.theme | |
21 | + else | |
22 | + if logger | |
23 | + logger.warn("No environment found. This is weird.") | |
24 | + logger.warn("Request environment: %s" % request.env.inspect) | |
25 | + logger.warn("Request parameters: %s" % params.inspect) | |
26 | + end | |
27 | + | |
28 | + # could not determine the theme, so return the default one | |
29 | + 'default' | |
30 | + end | |
31 | + end | |
32 | + end | |
33 | + end | |
34 | + end | |
35 | + | |
36 | + def theme_path | |
37 | + if session[:theme] | |
38 | + '/user_themes/' + current_theme | |
39 | + else | |
40 | + '/designs/themes/' + current_theme | |
41 | + end | |
42 | + end | |
43 | +end | ... | ... |
app/models/article_block.rb
... | ... | @@ -18,18 +18,6 @@ class ArticleBlock < Block |
18 | 18 | _('This block displays one of your articles. You can edit the block to select which one of your articles is going to be displayed in the block.') |
19 | 19 | end |
20 | 20 | |
21 | - def content(args={}) | |
22 | - block = self | |
23 | - proc do | |
24 | - block_title(block.title) + | |
25 | - (block.article ? article_to_html(FilePresenter.for(block.article), | |
26 | - :gallery_view => false, | |
27 | - :inside_block => block, # For Blogs and folders | |
28 | - :format => block.visualization_format # For Articles and contents | |
29 | - ).html_safe : _('Article not selected yet.')) | |
30 | - end | |
31 | - end | |
32 | - | |
33 | 21 | def article_id |
34 | 22 | self.settings[:article_id] |
35 | 23 | end | ... | ... |
app/models/blog.rb
... | ... | @@ -93,4 +93,20 @@ class Blog < Folder |
93 | 93 | posts.where("type != 'RssFeed'").order(:updated_at).limit(limit) |
94 | 94 | end |
95 | 95 | |
96 | + def total_number_of_posts(group_by, year = nil) | |
97 | + case group_by | |
98 | + when :by_year | |
99 | + posts.published.native_translations | |
100 | + .except(:order) | |
101 | + .count(:all, :group => 'EXTRACT(YEAR FROM published_at)') | |
102 | + .sort_by {|year, count| -year.to_i} | |
103 | + when :by_month | |
104 | + posts.published.native_translations | |
105 | + .except(:order) | |
106 | + .where('EXTRACT(YEAR FROM published_at)=?', year.to_i) | |
107 | + .group('EXTRACT(MONTH FROM published_at)') | |
108 | + .count | |
109 | + .sort_by {|month, count| -month.to_i} | |
110 | + end | |
111 | + end | |
96 | 112 | end | ... | ... |
app/models/blog_archives_block.rb
... | ... | @@ -21,30 +21,6 @@ class BlogArchivesBlock < Block |
21 | 21 | blog_id && owner.blogs.exists?(blog_id) ? owner.blogs.find(blog_id) : owner.blog |
22 | 22 | end |
23 | 23 | |
24 | - def visible_posts(person) | |
25 | - #FIXME Performance issues with display_to. Must convert it to a scope. | |
26 | - # Checkout this page for further information: http://noosfero.org/Development/ActionItem2705 | |
27 | - blog.posts.published.native_translations #.select {|post| post.display_to?(person)} | |
28 | - end | |
29 | - | |
30 | - def content(args={}) | |
31 | - owner_blog = self.blog | |
32 | - return nil unless owner_blog | |
33 | - results = '' | |
34 | - posts = visible_posts(args[:person]) | |
35 | - posts.except(:order).count(:all, :group => 'EXTRACT(YEAR FROM published_at)').sort_by {|year, count| -year.to_i}.each do |year, count| | |
36 | - results << content_tag('li', content_tag('strong', "#{year.to_i} (#{count})")) | |
37 | - results << "<ul class='#{year.to_i}-archive'>" | |
38 | - posts.except(:order).where('EXTRACT(YEAR FROM published_at)=?', year.to_i).group('EXTRACT(MONTH FROM published_at)').count.sort_by {|month, count| -month.to_i}.each do |month, count| | |
39 | - results << content_tag('li', link_to("#{month_name(month.to_i)} (#{count})", owner_blog.url.merge(year: year.to_i, month: month.to_i))) | |
40 | - end | |
41 | - results << "</ul>" | |
42 | - end | |
43 | - block_title(title) + | |
44 | - content_tag('ul', results, :class => 'blog-archives') + | |
45 | - content_tag('div', link_to(_('Subscribe RSS Feed'), owner_blog.feed.url), :class => 'subscribe-feed') | |
46 | - end | |
47 | - | |
48 | 24 | def self.expire_on |
49 | 25 | { :profile => [:article], :environment => [:article] } |
50 | 26 | end | ... | ... |
app/models/categories_block.rb
... | ... | @@ -30,13 +30,6 @@ class CategoriesBlock < Block |
30 | 30 | Category.top_level_for(self.owner).from_types(self.category_types) |
31 | 31 | end |
32 | 32 | |
33 | - def content(args={}) | |
34 | - block = self | |
35 | - proc do | |
36 | - render :file => 'blocks/categories', :locals => { :block => block } | |
37 | - end | |
38 | - end | |
39 | - | |
40 | 33 | def self.expire_on |
41 | 34 | { :profile => [], :environment => [:category] } |
42 | 35 | end | ... | ... |
app/models/comment.rb
... | ... | @@ -117,7 +117,15 @@ class Comment < ActiveRecord::Base |
117 | 117 | end |
118 | 118 | |
119 | 119 | delegate :environment, :to => :profile |
120 | - delegate :profile, :to => :source, :allow_nil => true | |
120 | + | |
121 | + def environment | |
122 | + profile && profile.respond_to?(:environment) ? profile.environment : nil | |
123 | + end | |
124 | + | |
125 | + def profile | |
126 | + return unless source | |
127 | + source.kind_of?(Profile) ? source : source.profile | |
128 | + end | |
121 | 129 | |
122 | 130 | include Noosfero::Plugin::HotSpot |
123 | 131 | ... | ... |
app/models/communities_block.rb
... | ... | @@ -27,15 +27,6 @@ class CommunitiesBlock < ProfileListBlock |
27 | 27 | owner.profile_suggestions.of_community.enabled.limit(3).includes(:suggestion) |
28 | 28 | end |
29 | 29 | |
30 | - def footer | |
31 | - owner = self.owner | |
32 | - suggestions = self.suggestions | |
33 | - return '' unless owner.kind_of?(Profile) || owner.kind_of?(Environment) | |
34 | - proc do | |
35 | - render :file => 'blocks/communities', :locals => { :owner => owner, :suggestions => suggestions } | |
36 | - end | |
37 | - end | |
38 | - | |
39 | 30 | def profiles |
40 | 31 | owner.communities |
41 | 32 | end | ... | ... |
app/models/disabled_enterprise_message_block.rb
... | ... | @@ -12,13 +12,6 @@ class DisabledEnterpriseMessageBlock < Block |
12 | 12 | _('Message') |
13 | 13 | end |
14 | 14 | |
15 | - def content(args={}) | |
16 | - message = self.owner.environment.message_for_disabled_enterprise || '' | |
17 | - lambda do |_| | |
18 | - render :file => 'blocks/disabled_enterprise_message', :locals => {:message => message} | |
19 | - end | |
20 | - end | |
21 | - | |
22 | 15 | def editable?(user=nil) |
23 | 16 | false |
24 | 17 | end | ... | ... |
app/models/enterprises_block.rb
... | ... | @@ -12,22 +12,6 @@ class EnterprisesBlock < ProfileListBlock |
12 | 12 | _('Enterprises') |
13 | 13 | end |
14 | 14 | |
15 | - def footer | |
16 | - owner = self.owner | |
17 | - case owner | |
18 | - when Profile | |
19 | - proc do | |
20 | - link_to s_('enterprises|View all'), :profile => owner.identifier, :controller => 'profile', :action => 'enterprises' | |
21 | - end | |
22 | - when Environment | |
23 | - proc do | |
24 | - link_to s_('enterprises|View all'), :controller => 'search', :action => 'assets', :asset => 'enterprises' | |
25 | - end | |
26 | - else | |
27 | - '' | |
28 | - end | |
29 | - end | |
30 | - | |
31 | 15 | def profiles |
32 | 16 | owner.enterprises |
33 | 17 | end | ... | ... |
app/models/fans_block.rb
... | ... | @@ -12,14 +12,6 @@ class FansBlock < ProfileListBlock |
12 | 12 | _('This block presents the fans of an enterprise.') |
13 | 13 | end |
14 | 14 | |
15 | - def footer | |
16 | - profile = self.owner | |
17 | - proc do | |
18 | - link_to _('View all'), :profile => profile.identifier, :controller => | |
19 | - 'profile', :action => 'fans' | |
20 | - end | |
21 | - end | |
22 | - | |
23 | 15 | def profiles |
24 | 16 | owner.fans |
25 | 17 | end | ... | ... |
app/models/favorite_enterprises_block.rb
... | ... | @@ -12,14 +12,6 @@ class FavoriteEnterprisesBlock < ProfileListBlock |
12 | 12 | _('Favorite Enterprises') |
13 | 13 | end |
14 | 14 | |
15 | - def footer | |
16 | - owner = self.owner | |
17 | - return '' unless owner.kind_of?(Person) | |
18 | - proc do | |
19 | - link_to _('enterprises|View all'), {:profile => owner.identifier, :controller => 'profile', :action => 'favorite_enterprises'}, :class => 'view-all' | |
20 | - end | |
21 | - end | |
22 | - | |
23 | 15 | def profiles |
24 | 16 | owner.favorite_enterprises |
25 | 17 | end | ... | ... |
app/models/featured_products_block.rb
... | ... | @@ -32,11 +32,4 @@ class FeaturedProductsBlock < Block |
32 | 32 | self.owner.highlighted_products_with_image |
33 | 33 | end |
34 | 34 | |
35 | - def content(args={}) | |
36 | - block = self | |
37 | - proc do | |
38 | - render :file => 'blocks/featured_products', :locals => { :block => block } | |
39 | - end | |
40 | - end | |
41 | - | |
42 | 35 | end | ... | ... |
app/models/feed_reader_block.rb
... | ... | @@ -52,24 +52,6 @@ class FeedReaderBlock < Block |
52 | 52 | self.feed_title.nil? ? _('Feed Reader') : self.feed_title |
53 | 53 | end |
54 | 54 | |
55 | - def formatted_feed_content | |
56 | - if error_message.blank? | |
57 | - "<ul>\n".html_safe + | |
58 | - self.feed_items[0..(limit-1)].map{ |item| "<li><a href='#{item[:link]}'>#{item[:title]}</a></li>" }.join("\n").html_safe + | |
59 | - "</ul>".html_safe | |
60 | - else | |
61 | - "<p>#{error_message}</p>".html_safe | |
62 | - end | |
63 | - end | |
64 | - | |
65 | - def footer | |
66 | - if self.fetched_at.nil? or self.feed_items.empty? | |
67 | - _('Feed content was not loaded yet') | |
68 | - else | |
69 | - _("Updated: %s") % show_date(self.fetched_at) | |
70 | - end | |
71 | - end | |
72 | - | |
73 | 55 | def add_item(title, link, date, content) |
74 | 56 | self.feed_items.unshift( {:title => title, :link => link}) |
75 | 57 | end |
... | ... | @@ -85,8 +67,4 @@ class FeedReaderBlock < Block |
85 | 67 | self.save! |
86 | 68 | end |
87 | 69 | |
88 | - def content(args={}) | |
89 | - block_title(title) + formatted_feed_content | |
90 | - end | |
91 | - | |
92 | 70 | end | ... | ... |
app/models/highlights_block.rb
... | ... | @@ -43,13 +43,6 @@ class HighlightsBlock < Block |
43 | 43 | end |
44 | 44 | end |
45 | 45 | |
46 | - def content(args={}) | |
47 | - block = self | |
48 | - proc do | |
49 | - render :file => 'blocks/highlights', :locals => { :block => block } | |
50 | - end | |
51 | - end | |
52 | - | |
53 | 46 | def folder_choices |
54 | 47 | owner.image_galleries |
55 | 48 | end | ... | ... |
app/models/link_list_block.rb
... | ... | @@ -59,20 +59,6 @@ class LinkListBlock < Block |
59 | 59 | _('Link list') |
60 | 60 | end |
61 | 61 | |
62 | - def content(args={}) | |
63 | - block_title(title) + | |
64 | - content_tag('ul', | |
65 | - links.select{|i| !i[:name].blank? and !i[:address].blank?}.map{|i| content_tag('li', link_html(i))}.join | |
66 | - ) | |
67 | - end | |
68 | - | |
69 | - def link_html(link) | |
70 | - klass = 'icon-' + link[:icon] if link[:icon] | |
71 | - sanitize_link( | |
72 | - link_to(link[:name], expand_address(link[:address]), :target => link[:target], :class => klass, :title => link[:title]) | |
73 | - ) | |
74 | - end | |
75 | - | |
76 | 62 | def expand_address(address) |
77 | 63 | add = if owner.respond_to?(:identifier) |
78 | 64 | address.gsub('{profile}', owner.identifier) |
... | ... | @@ -99,8 +85,6 @@ class LinkListBlock < Block |
99 | 85 | end |
100 | 86 | end |
101 | 87 | |
102 | - private | |
103 | - | |
104 | 88 | def sanitize_link(text) |
105 | 89 | sanitizer = HTML::WhiteListSanitizer.new |
106 | 90 | sanitizer.sanitize(text) | ... | ... |
app/models/location_block.rb
... | ... | @@ -13,12 +13,4 @@ class LocationBlock < Block |
13 | 13 | _('Shows where the profile is on the material world.') |
14 | 14 | end |
15 | 15 | |
16 | - def content(args={}) | |
17 | - block = self | |
18 | - profile = self.owner | |
19 | - proc do | |
20 | - render :file => 'blocks/location', :locals => {:block => block, :profile => profile} | |
21 | - end | |
22 | - end | |
23 | - | |
24 | 16 | end | ... | ... |
app/models/login_block.rb
app/models/main_block.rb
app/models/my_network_block.rb
... | ... | @@ -14,16 +14,6 @@ class MyNetworkBlock < Block |
14 | 14 | _('This block displays some info about your networking.') |
15 | 15 | end |
16 | 16 | |
17 | - def content(args={}) | |
18 | - block = self | |
19 | - proc do | |
20 | - render :file => 'blocks/my_network', :locals => { | |
21 | - :title => block.title, | |
22 | - :owner => block.owner | |
23 | - } | |
24 | - end | |
25 | - end | |
26 | - | |
27 | 17 | def cacheable? |
28 | 18 | false |
29 | 19 | end | ... | ... |
app/models/product_categories_block.rb
... | ... | @@ -13,26 +13,6 @@ class ProductCategoriesBlock < Block |
13 | 13 | _('Helps to filter the products catalog.') |
14 | 14 | end |
15 | 15 | |
16 | - def content(args={}) | |
17 | - profile = owner | |
18 | - proc do | |
19 | - if @categories.nil? or @categories.length == 0 | |
20 | - categories = ProductCategory.on_level(nil).order(:name) | |
21 | - if @categories and @categories.length == 0 | |
22 | - notice = _('There are no sub-categories for %s') % @category.name | |
23 | - end | |
24 | - else | |
25 | - categories = @categories | |
26 | - end | |
27 | - render :file => 'blocks/product_categories', | |
28 | - :locals => { | |
29 | - :profile => profile, | |
30 | - :categories => categories, | |
31 | - :notice => notice | |
32 | - } | |
33 | - end | |
34 | - end | |
35 | - | |
36 | 16 | DISPLAY_OPTIONS = DISPLAY_OPTIONS.merge('catalog_only' => _('Only on the catalog')) |
37 | 17 | |
38 | 18 | def display | ... | ... |
app/models/products_block.rb
... | ... | @@ -19,26 +19,6 @@ class ProductsBlock < Block |
19 | 19 | _('This block presents a list of your products.') |
20 | 20 | end |
21 | 21 | |
22 | - def content(args={}) | |
23 | - block_title(title) + | |
24 | - content_tag( | |
25 | - 'ul', | |
26 | - products.map {|product| | |
27 | - content_tag('li', | |
28 | - link_to( product.name, | |
29 | - product.url, | |
30 | - :style => 'background-image:url(%s)' % product.default_image('minor') | |
31 | - ), | |
32 | - :class => 'product' | |
33 | - ) | |
34 | - }.join | |
35 | - ) | |
36 | - end | |
37 | - | |
38 | - def footer | |
39 | - link_to(_('View all products'), owner.public_profile_url.merge(:controller => 'catalog', :action => 'index')) | |
40 | - end | |
41 | - | |
42 | 22 | settings_items :product_ids, type: Array |
43 | 23 | def product_ids=(array) |
44 | 24 | self.settings[:product_ids] = array | ... | ... |
app/models/profile.rb
... | ... | @@ -5,8 +5,8 @@ class Profile < ActiveRecord::Base |
5 | 5 | |
6 | 6 | attr_accessible :name, :identifier, :public_profile, :nickname, :custom_footer, :custom_header, :address, :zip_code, :contact_phone, :image_builder, :description, :closed, :template_id, :environment, :lat, :lng, :is_template, :fields_privacy, :preferred_domain_id, :category_ids, :country, :city, :state, :national_region_code, :email, :contact_email, :redirect_l10n, :notification_time, |
7 | 7 | :redirection_after_login, :custom_url_redirection, |
8 | - :email_suggestions, :allow_members_to_invite, :invite_friends_only, :secret, | |
9 | - :custom_fields, :administrator_mail_notification, :region, :region_id | |
8 | + :email_suggestions, :allow_members_to_invite, :invite_friends_only, :secret, :profile_admin_mail_notification, | |
9 | + :custom_fields, :region, :region_id | |
10 | 10 | |
11 | 11 | # use for internationalizable human type names in search facets |
12 | 12 | # reimplement on subclasses |
... | ... | @@ -277,7 +277,7 @@ class Profile < ActiveRecord::Base |
277 | 277 | settings_items :description |
278 | 278 | settings_items :fields_privacy, :type => :hash, :default => {} |
279 | 279 | settings_items :email_suggestions, :type => :boolean, :default => false |
280 | - settings_items :administrator_mail_notification, :type => :boolean, :default => true | |
280 | + settings_items :profile_admin_mail_notification, :type => :boolean, :default => true | |
281 | 281 | |
282 | 282 | validates_length_of :description, :maximum => 550, :allow_nil => true |
283 | 283 | ... | ... |
app/models/profile_image_block.rb
... | ... | @@ -12,17 +12,6 @@ class ProfileImageBlock < Block |
12 | 12 | _('This block presents the profile image') |
13 | 13 | end |
14 | 14 | |
15 | - def content(args={}) | |
16 | - block = self | |
17 | - s = show_name | |
18 | - lambda do |object| | |
19 | - render( | |
20 | - :file => 'blocks/profile_image', | |
21 | - :locals => { :block => block, :show_name => s } | |
22 | - ) | |
23 | - end | |
24 | - end | |
25 | - | |
26 | 15 | def cacheable? |
27 | 16 | false |
28 | 17 | end | ... | ... |
app/models/profile_info_block.rb
... | ... | @@ -16,13 +16,6 @@ class ProfileInfoBlock < Block |
16 | 16 | _('Basic information about <i>%{user}</i>: how long <i>%{user}</i> is part of <i>%{env}</i> and useful links.') % { :user => self.owner.name(), :env => self.owner.environment.name() } |
17 | 17 | end |
18 | 18 | |
19 | - def content(args={}) | |
20 | - block = self | |
21 | - lambda do |_| | |
22 | - render :file => 'blocks/profile_info', :locals => { :block => block } | |
23 | - end | |
24 | - end | |
25 | - | |
26 | 19 | def cacheable? |
27 | 20 | false |
28 | 21 | end | ... | ... |
app/models/profile_list_block.rb
... | ... | @@ -40,26 +40,6 @@ result = public_profiles.all(:limit => get_limit, :order => 'profiles.updated_at |
40 | 40 | _('Clicking on the people or groups will take you to their home page.') |
41 | 41 | end |
42 | 42 | |
43 | - def content(args={}) | |
44 | - profiles = self.profile_list | |
45 | - title = self.view_title | |
46 | - nl = "\n" | |
47 | - proc do |context| | |
48 | - count=0 | |
49 | - list = profiles.map {|item| | |
50 | - count+=1 | |
51 | - send(:profile_image_link, item, :minor ) | |
52 | - }.join("\n ") | |
53 | - if list.empty? | |
54 | - list = content_tag 'div', _('None'), :class => 'common-profile-list-block-none' | |
55 | - else | |
56 | - list = content_tag 'ul', nl +' '+ list + nl | |
57 | - end | |
58 | - block_title(title) + nl + | |
59 | - content_tag('div', nl + list + nl + tag('br', :style => 'clear:both')) | |
60 | - end | |
61 | - end | |
62 | - | |
63 | 43 | def view_title |
64 | 44 | title.gsub('{#}', profile_count.to_s) |
65 | 45 | end | ... | ... |
app/models/profile_search_block.rb
... | ... | @@ -4,11 +4,4 @@ class ProfileSearchBlock < Block |
4 | 4 | _('Display a form to search the profile') |
5 | 5 | end |
6 | 6 | |
7 | - def content(args={}) | |
8 | - title = self.title | |
9 | - lambda do |_| | |
10 | - render :file => 'blocks/profile_search', :locals => { :title => title } | |
11 | - end | |
12 | - end | |
13 | - | |
14 | 7 | end | ... | ... |
app/models/raw_html_block.rb
app/models/recent_documents_block.rb
... | ... | @@ -22,24 +22,6 @@ class RecentDocumentsBlock < Block |
22 | 22 | |
23 | 23 | settings_items :limit, :type => :integer, :default => 5 |
24 | 24 | |
25 | - def content(args={}) | |
26 | - docs = self.docs | |
27 | - title = self.title | |
28 | - proc do | |
29 | - block_title(title) + | |
30 | - content_tag('ul', docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) | |
31 | - end | |
32 | - end | |
33 | - | |
34 | - def footer | |
35 | - return nil unless self.owner.is_a?(Profile) | |
36 | - | |
37 | - profile = self.owner | |
38 | - proc do | |
39 | - link_to _('All content'), :profile => profile.identifier, :controller => 'profile', :action => 'sitemap' | |
40 | - end | |
41 | - end | |
42 | - | |
43 | 25 | def docs |
44 | 26 | self.limit.nil? ? owner.recent_documents(nil, {}, false) : owner.recent_documents(self.get_limit, {}, false) |
45 | 27 | end | ... | ... |
app/models/sellers_search_block.rb
... | ... | @@ -22,10 +22,4 @@ class SellersSearchBlock < Block |
22 | 22 | _('This block presents a search engine for products.') |
23 | 23 | end |
24 | 24 | |
25 | - def content(args={}) | |
26 | - title = self.title | |
27 | - lambda do |object| | |
28 | - render :file => 'search/_sellers_form', :locals => { :title => title } | |
29 | - end | |
30 | - end | |
31 | 25 | end | ... | ... |
app/models/slideshow_block.rb
... | ... | @@ -33,23 +33,6 @@ class SlideshowBlock < Block |
33 | 33 | gallery.images.reject {|item| item.folder?} |
34 | 34 | end |
35 | 35 | |
36 | - def content(args={}) | |
37 | - block = self | |
38 | - if gallery | |
39 | - images = block_images | |
40 | - if shuffle | |
41 | - images = images.shuffle | |
42 | - end | |
43 | - proc do | |
44 | - render :file => 'blocks/slideshow', :locals => { :block => block, :images => images } | |
45 | - end | |
46 | - else | |
47 | - proc do | |
48 | - render :file => 'blocks/slideshow', :locals => { :block => block, :images => nil } | |
49 | - end | |
50 | - end | |
51 | - end | |
52 | - | |
53 | 36 | def folder_choices |
54 | 37 | owner.image_galleries |
55 | 38 | end | ... | ... |
app/models/tags_block.rb
... | ... | @@ -28,42 +28,6 @@ class TagsBlock < Block |
28 | 28 | Try to add some tags to some articles and you'l see your tag cloud growing.") |
29 | 29 | end |
30 | 30 | |
31 | - def content(args={}) | |
32 | - is_env = owner.class == Environment | |
33 | - tags = is_env ? owner.tag_counts : owner.article_tags | |
34 | - return '' if tags.empty? | |
35 | - | |
36 | - if limit | |
37 | - tags_tmp = tags.sort_by{ |k,v| -v }[0..(limit-1)] | |
38 | - tags = {} | |
39 | - tags_tmp.map{ |k,v| tags[k] = v } | |
40 | - end | |
41 | - | |
42 | - url = is_env ? {:host=>owner.default_hostname, :controller=>'search', :action => 'tag'} : | |
43 | - owner.public_profile_url.merge(:controller => 'profile', :action => 'content_tagged') | |
44 | - tagname_option = is_env ? :tag : :id | |
45 | - | |
46 | - block_title(title) + | |
47 | - "\n<div class='tag_cloud'>\n".html_safe+ | |
48 | - tag_cloud( tags, tagname_option, url, :max_size => 16, :min_size => 9 ) + | |
49 | - "\n</div><!-- end class='tag_cloud' -->\n".html_safe | |
50 | - end | |
51 | - | |
52 | - def footer | |
53 | - if owner.class == Environment | |
54 | - proc do | |
55 | - link_to s_('tags|View all'), | |
56 | - :controller => 'search', :action => 'tags' | |
57 | - end | |
58 | - else | |
59 | - owner_id = owner.identifier | |
60 | - proc do | |
61 | - link_to s_('tags|View all'), | |
62 | - :profile => owner_id, :controller => 'profile', :action => 'tags' | |
63 | - end | |
64 | - end | |
65 | - end | |
66 | - | |
67 | 31 | def timeout |
68 | 32 | 15.minutes |
69 | 33 | end | ... | ... |
app/models/task.rb
... | ... | @@ -81,17 +81,13 @@ class Task < ActiveRecord::Base |
81 | 81 | end |
82 | 82 | |
83 | 83 | def target_profile_accepts_notification?(task) |
84 | - if target_is_profile?(task) | |
85 | - return task.target.administrator_mail_notification | |
84 | + if task.target.kind_of? Organization | |
85 | + return task.target.profile_admin_mail_notification | |
86 | 86 | else |
87 | 87 | true |
88 | 88 | end |
89 | 89 | end |
90 | 90 | |
91 | - def target_is_profile?(task) | |
92 | - task.target.kind_of? Profile | |
93 | - end | |
94 | - | |
95 | 91 | # this method finished the task. It calls #perform, which must be overriden |
96 | 92 | # by subclasses. At the end a message (as returned by #finish_message) is |
97 | 93 | # sent to the requestor with #notify_requestor. | ... | ... |
... | ... | @@ -0,0 +1,12 @@ |
1 | +<%= block_title(block.title) %> | |
2 | +<% if block.article %> | |
3 | + <%= | |
4 | + h(article_to_html(FilePresenter.for(block.article), | |
5 | + :gallery_view => false, | |
6 | + :inside_block => block, # For Blogs and folders | |
7 | + :format => block.visualization_format # For Articles and contents | |
8 | + )) | |
9 | + %> | |
10 | +<% else %> | |
11 | + <%= _('Article not selected yet.') %> | |
12 | +<% end %> | ... | ... |
... | ... | @@ -0,0 +1,16 @@ |
1 | +<% if block.blog %> | |
2 | + <%= block_title(block.title) %> | |
3 | + | |
4 | + <ul class='blog-archives'> | |
5 | + <% block.blog.total_number_of_posts(:by_year).each do |year, count| %> | |
6 | + <%= content_tag('li', content_tag('strong', "#{year.to_i} (#{count})")) %> | |
7 | + <ul class='<%= year.to_i %>-archive'> | |
8 | + <% block.blog.total_number_of_posts(:by_month, year).each do |month, count| %> | |
9 | + <%= content_tag('li', link_to("#{month_name(month.to_i)} (#{count})", block.blog.url.merge(year: year.to_i, month: month.to_i))) %> | |
10 | + <% end %> | |
11 | + </ul> | |
12 | + <% end %> | |
13 | + </ul> | |
14 | + | |
15 | + <%= content_tag('div', link_to(_('Subscribe RSS Feed'), block.blog.feed.url), :class => 'subscribe-feed') %> | |
16 | +<% end %> | ... | ... |
app/views/blocks/communities.html.erb
... | ... | @@ -1,17 +0,0 @@ |
1 | -<% if owner.kind_of?(Profile) %> | |
2 | - <%= link_to s_('communities|View all'), {:profile => owner.identifier, :controller => 'profile', :action => 'communities'}, :class => 'view-all' %> | |
3 | -<% elsif owner.kind_of?(Environment) %> | |
4 | - <%= link_to s_('communities|View all'), {:controller => 'search', :action => 'communities'}, :class => 'view-all' %> | |
5 | -<% end %> | |
6 | - | |
7 | -<% if user && user == profile && suggestions && !suggestions.empty? %> | |
8 | - <div class='suggestions-block common-profile-list-block'> | |
9 | - <h4 class='block-subtitle'><%= _('Some suggestions for you') %></h4> | |
10 | - <div class='profiles-suggestions'> | |
11 | - <%= render :partial => 'shared/profile_suggestions_list', :locals => { :suggestions => suggestions, :collection => :communities_suggestions, :per_page => 3 } %> | |
12 | - </div> | |
13 | - <div class='more-suggestions'> | |
14 | - <%= link_to _('See all suggestions'), profile.communities_suggestions_url %> | |
15 | - </div> | |
16 | - </div> | |
17 | -<% end %> |
app/views/blocks/disabled_enterprise_message.html.erb
... | ... | @@ -0,0 +1,11 @@ |
1 | +<%= block_title(block.title) %> | |
2 | + | |
3 | +<%= | |
4 | + if block.error_message.blank? | |
5 | + "<ul>\n".html_safe + | |
6 | + block.feed_items[0..(block.limit-1)].map{ |item| "<li><a href='#{item[:link]}'>#{item[:title]}</a></li>" }.join("\n").html_safe + | |
7 | + "</ul>".html_safe | |
8 | + else | |
9 | + "<p>#{block.error_message}</p>".html_safe | |
10 | + end | |
11 | +%> | ... | ... |
... | ... | @@ -0,0 +1,19 @@ |
1 | +<% if block.owner.kind_of?(Profile) || block.owner.kind_of?(Environment) %> | |
2 | + <% if block.owner.kind_of?(Profile) %> | |
3 | + <%= link_to s_('communities|View all'), {:profile => block.owner.identifier, :controller => 'profile', :action => 'communities'}, :class => 'view-all' %> | |
4 | + <% elsif block.owner.kind_of?(Environment) %> | |
5 | + <%= link_to s_('communities|View all'), {:controller => 'search', :action => 'communities'}, :class => 'view-all' %> | |
6 | + <% end %> | |
7 | + | |
8 | + <% if user && user == profile && block.suggestions && !block.suggestions.empty? %> | |
9 | + <div class='suggestions-block common-profile-list-block'> | |
10 | + <h4 class='block-subtitle'><%= _('Some suggestions for you') %></h4> | |
11 | + <div class='profiles-suggestions'> | |
12 | + <%= render :partial => 'shared/profile_suggestions_list', :locals => { :suggestions => block.suggestions, :collection => :communities_suggestions, :per_page => 3 } %> | |
13 | + </div> | |
14 | + <div class='more-suggestions'> | |
15 | + <%= link_to _('See all suggestions'), profile.communities_suggestions_url %> | |
16 | + </div> | |
17 | + </div> | |
18 | + <% end %> | |
19 | +<% end %> | ... | ... |
... | ... | @@ -0,0 +1,5 @@ |
1 | +<% if block.owner.is_a?(Profile) %> | |
2 | + <%= link_to s_('enterprises|View all'), :profile => block.owner.identifier, :controller => 'profile', :action => 'enterprises' %> | |
3 | +<% elsif block.owner.is_a?(Environment) %> | |
4 | + <%= link_to s_('enterprises|View all'), :controller => 'search', :action => 'assets', :asset => 'enterprises' %> | |
5 | +<% end %> | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +<%= link_to _('View all'), :profile => block.owner.identifier, :controller => 'profile', :action => 'fans' %> | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +<%= link_to(_('View all products'), block.owner.public_profile_url.merge(:controller => 'catalog', :action => 'index')) %> | ... | ... |
... | ... | @@ -0,0 +1,5 @@ |
1 | +<% if block.owner.is_a?(Environment) %> | |
2 | + <%= link_to s_('tags|View all'), :controller => 'search', :action => 'tags' %> | |
3 | +<% else %> | |
4 | + <%= link_to s_('tags|View all'), :profile => block.owner.identifier, :controller => 'profile', :action => 'tags' %> | |
5 | +<% end %> | ... | ... |
... | ... | @@ -0,0 +1,14 @@ |
1 | +<%= block_title(block.title) %> | |
2 | + | |
3 | +<%= block.links.empty? && block.title.empty? ? content_tag('em', _('Please, edit this block to add links')) : '' %> | |
4 | + | |
5 | +<ul> | |
6 | + <% block.links.select{|i| !i[:name].blank? and !i[:address].blank?}.each do |link| %> | |
7 | + <li> | |
8 | + <%= block.sanitize_link(link_to(link[:name], block.expand_address(link[:address]), | |
9 | + :target => link[:target], | |
10 | + :class => (link[:icon] ? "icon-#{link[:icon]}" : ''), | |
11 | + :title => link[:title])) %> | |
12 | + </li> | |
13 | + <% end %> | |
14 | +</ul> | ... | ... |
app/views/blocks/location.html.erb
1 | -<% if profile.lat %> | |
1 | +<% if block.owner.lat %> | |
2 | 2 | <%= block_title block.title %> |
3 | 3 | <div class='the-localization-map'> |
4 | - <img src="https://maps.google.com/maps/api/staticmap?center=<%=profile.lat%>,<%=profile.lng%>&zoom=<%=block.zoom%>&size=190x250&maptype=<%=block.map_type%>&markers=<%=profile.lat%>,<%=profile.lng%>&sensor=false"/> | |
4 | + <img src="https://maps.google.com/maps/api/staticmap?center=<%=block.owner.lat%>,<%=block.owner.lng%>&zoom=<%=block.zoom%>&size=190x250&maptype=<%=block.map_type%>&markers=<%=block.owner.lat%>,<%=block.owner.lng%>&sensor=false"/> | |
5 | 5 | </div> |
6 | 6 | <% else %> |
7 | 7 | <i><%= _('This profile has no geographical position registered.') %></i> | ... | ... |
... | ... | @@ -0,0 +1,16 @@ |
1 | +<% if user.present? %> | |
2 | + <div class="logged-user-info"> | |
3 | + <h2><%= _('Logged in as %s') % user.identifier %></h2> | |
4 | + <ul> | |
5 | + <li><%= _('User since %s/%s') % [user.created_at.month, user.created_at.year] %></li> | |
6 | + <li><%= link_to _('Homepage'), user.public_profile_url %></li> | |
7 | + </ul> | |
8 | + <div class="user-actions"> | |
9 | + <%= button(:'menu-logout', _('Logout'), :controller => 'account', :action => 'logout') %> | |
10 | + </div> | |
11 | + </div> | |
12 | +<% else %> | |
13 | + <div class='not-logged-user'> | |
14 | + <%= render :file => 'account/login_block' %> | |
15 | + </div> | |
16 | +<% end%> | ... | ... |
app/views/blocks/login_block.html.erb
... | ... | @@ -1,16 +0,0 @@ |
1 | -<% if user.present? %> | |
2 | - <div class="logged-user-info"> | |
3 | - <h2><%= _('Logged in as %s') % user.identifier %></h2> | |
4 | - <ul> | |
5 | - <li><%= _('User since %s/%s') % [user.created_at.month, user.created_at.year] %></li> | |
6 | - <li><%= link_to _('Homepage'), user.public_profile_url %></li> | |
7 | - </ul> | |
8 | - <div class="user-actions"> | |
9 | - <%= button(:'menu-logout', _('Logout'), :controller => 'account', :action => 'logout') %> | |
10 | - </div> | |
11 | - </div> | |
12 | -<% else %> | |
13 | - <div class='not-logged-user'> | |
14 | - <%= render :file => 'account/login_block' %> | |
15 | - </div> | |
16 | -<% end%> |
app/views/blocks/my_network.html.erb
1 | -<%= block_title(title) %> | |
1 | +<%= block_title(block.title) %> | |
2 | 2 | |
3 | 3 | <ul> |
4 | - <li><%= link_to(_('Homepage'), owner.url, :class => 'url') %></li> | |
5 | - <li><%= link_to(_('View profile'), owner.public_profile_url) %></li> | |
6 | - <% if !user.nil? and owner.organization? and user.has_permission?('edit_profile', profile) %> | |
4 | + <li><%= link_to(_('Homepage'), block.owner.url, :class => 'url') %></li> | |
5 | + <li><%= link_to(_('View profile'), block.owner.public_profile_url) %></li> | |
6 | + <% if !user.nil? and block.owner.organization? and user.has_permission?('edit_profile', profile) %> | |
7 | 7 | <li><%= link_to _('Control panel'), :controller => 'profile_editor', :profile => profile.identifier %></li> |
8 | 8 | <% end %> |
9 | 9 | </ul> |
10 | 10 | |
11 | 11 | <div class="my-network-actions"> |
12 | - <%= render_profile_actions owner.class %> | |
12 | + <%= render_profile_actions block.owner.class %> | |
13 | 13 | </div> | ... | ... |
app/views/blocks/product_categories.html.erb
1 | -<%= link_to _('Catalog start'), profile.catalog_url, :class=>'catalog-home-link' %> | |
1 | +<% | |
2 | + if @categories.nil? or @categories.length == 0 | |
3 | + categories = ProductCategory.on_level(nil).order(:name) | |
4 | + else | |
5 | + categories = @categories | |
6 | + end | |
7 | +%> | |
8 | + | |
9 | +<%= link_to _('Catalog start'), block.owner.catalog_url, :class=>'catalog-home-link' %> | |
2 | 10 | <ul class="catalog-categories-list"> |
3 | 11 | <% categories.each do |category| %> |
4 | 12 | <%= category_with_sub_list(category) %> |
5 | 13 | <% end %> |
6 | 14 | </ul> |
7 | -<% if notice %> | |
8 | - <div class="catalog-categories-notice"><%= notice %></div> | |
15 | +<% if @categories and @categories.length == 0 %> | |
16 | + <div class="catalog-categories-notice"> | |
17 | + <%= _('There are no sub-categories for %s') % @category.name %> | |
18 | + </div> | |
9 | 19 | <% end %> | ... | ... |
app/views/blocks/profile_image.html.erb
... | ... | @@ -0,0 +1,17 @@ |
1 | +<%= block_title(block.view_title) %> | |
2 | + | |
3 | +<% | |
4 | + list = block.profile_list.map do |item| | |
5 | + profile_image_link(item, :minor) | |
6 | + end.join("\n ") | |
7 | +%> | |
8 | + | |
9 | +<div> | |
10 | + <% if list.empty? %> | |
11 | + <div class='common-profile-list-block-none'><%= _('None') %></div> | |
12 | + <% else %> | |
13 | + <ul><%= list %></ul> | |
14 | + <% end %> | |
15 | +</div> | |
16 | + | |
17 | +<br style='clear:both'/> | ... | ... |
app/views/blocks/profile_search.html.erb
... | ... | @@ -0,0 +1,24 @@ |
1 | +<h3><%= block.title %></h3> | |
2 | + | |
3 | +<%= form_tag({:controller => 'search', :action => 'assets'}, {:method => 'get'}) do %> | |
4 | + | |
5 | + <div class="search-in-opt"><%= _('Search in:') %> | |
6 | + <dir> | |
7 | + <%= labelled_radio_button _('Enterprises'), 'asset', 'enterprises', true %><br /> | |
8 | + <%= labelled_radio_button _('Products'), 'asset', 'products', false %> | |
9 | + </dir> | |
10 | + </div> | |
11 | + | |
12 | + <div class="formfield search-from-opt"> | |
13 | + <%= select_city(true) %> | |
14 | + </div> | |
15 | + | |
16 | + <div class="formfield search-distance-opt"> | |
17 | + <%= labelled_select(_('Distance:'), 'radius', :first, :last, nil, [15, 30, 50, 100, 150, 200, 300, 400, 500, 1000].map{|n|[n, n.to_s + 'km']}) %> | |
18 | + </div> | |
19 | + | |
20 | + <div class="button-bar"> | |
21 | + <%= submit_button :search, _('Search') %> | |
22 | + </div> | |
23 | + | |
24 | +<% end %> | ... | ... |
app/views/blocks/slideshow.html.erb
1 | +<% | |
2 | + if block.gallery | |
3 | + images = block.block_images | |
4 | + if block.shuffle | |
5 | + images = images.shuffle | |
6 | + end | |
7 | + end | |
8 | +%> | |
9 | + | |
1 | 10 | <%= block_title(block.title) %> |
11 | + | |
2 | 12 | <% if images %> |
3 | 13 | <% description = images.any? { |img| !img.abstract.blank? } %> |
4 | 14 | <div class='slideshow-border<%= (description ? ' with-descriptions' : '')%>'> | ... | ... |
... | ... | @@ -0,0 +1,25 @@ |
1 | +<%= block_title(block.title) %> | |
2 | + | |
3 | +<% | |
4 | + is_env = block.owner.class == Environment | |
5 | + tags = is_env ? block.owner.tag_counts : block.owner.article_tags | |
6 | + if block.limit | |
7 | + tags_tmp = tags.sort_by{ |k,v| -v }[0..(block.limit-1)] | |
8 | + tags = {} | |
9 | + tags_tmp.map{ |k,v| tags[k] = v } | |
10 | + end | |
11 | +%> | |
12 | + | |
13 | +<% unless tags.empty? %> | |
14 | + <div class='tag_cloud'> | |
15 | + <% if is_env %> | |
16 | + <%= tag_cloud(tags, :tag, | |
17 | + {:host => block.owner.default_hostname, :controller=>'search', :action => 'tag'}, | |
18 | + :max_size => 16, :min_size => 9) %> | |
19 | + <% else %> | |
20 | + <%= tag_cloud(tags, :id, | |
21 | + block.owner.public_profile_url.merge(:controller => 'profile', :action => 'content_tagged'), | |
22 | + :max_size => 16, :min_size => 9) %> | |
23 | + <% end %> | |
24 | + </div> | |
25 | +<% end %> | ... | ... |
app/views/cms/_event.html.erb
... | ... | @@ -8,7 +8,7 @@ |
8 | 8 | <%= render :partial => 'general_fields' %> |
9 | 9 | <%= render :partial => 'translatable' %> |
10 | 10 | |
11 | -<%= date_range_field('article[start_date]', 'article[end_date]', @article.start_date, @article.end_date, _('%Y-%m-%d %H:%M'), {:time => true}, {:id => 'article_start_date'} ) %> | |
11 | +<%= date_range_field('article[start_date]', 'article[end_date]', @article.start_date, @article.end_date, {:time => true}, {:id => 'article_start_date'} ) %> | |
12 | 12 | |
13 | 13 | <%= labelled_form_field(_('Presenter:'), text_field(:article, :presenter)) %> |
14 | 14 | ... | ... |
app/views/cms/_text_fields.html.erb
1 | -<%= labelled_form_field(_('Publish date'), date_field('article[published_at]', @article.published_at || DateTime.current, '%Y-%m-%d', {:max_date => '+0d', :date_format => 'yy-mm-dd'}, {:id => "article_published_at"})) %> | |
1 | +<%= labelled_form_field(_('Publish date'), date_field('article[published_at]', @article.published_at || DateTime.current, {:max_date => '+0d', :date_format => 'yy-mm-dd'}, {:id => "article_published_at"})) %> | ... | ... |
app/views/custom_fields/_date.html.erb
1 | -<%= labelled_form_field(field.name, date_field(name, profile.custom_value(field.name).to_date, '%Y-%m-%d', {:change_month => true, :change_year => true, :year_range => '-100:-5', :date_format => 'yy-mm-dd'}, {:id => field.name.parameterize.underscore}))%> | |
1 | +<%= labelled_form_field(field.name, date_field(name, profile.custom_value(field.name).to_date, {:change_month => true, :change_year => true, :year_range => '-100:-5', :date_format => 'yy-mm-dd'}, {:id => field.name.parameterize.underscore}))%> | ... | ... |
app/views/profile_editor/_moderation.html.erb
... | ... | @@ -4,9 +4,9 @@ |
4 | 4 | <h4><%= _('Email Configuration:')%></h4> |
5 | 5 | </div> |
6 | 6 | <div style='margin-bottom: 0.5em'> |
7 | - <%= check_box(:profile_data, :administrator_mail_notification, :style => 'float: left') %> | |
7 | + <%= check_box(:profile_data, :profile_admin_mail_notification, :style => 'float: left') %> | |
8 | 8 | <div style='margin-left: 30px'> |
9 | - <%= _('Send administrator Email for every task (Default: yes)') %> | |
9 | + <%= _('Send administrator Email for every task') %> | |
10 | 10 | </div> |
11 | 11 | </div> |
12 | 12 | ... | ... |
app/views/profile_editor/_person_form.html.erb
... | ... | @@ -16,7 +16,7 @@ |
16 | 16 | <%= optional_field(@person, 'jabber_id', f.text_field(:jabber_id, :rel => _('Jabber'))) %> |
17 | 17 | <%= optional_field(@person, 'personal_website', f.text_field(:personal_website, :rel => _('Personal website'))) %> |
18 | 18 | <%= optional_field(@person, 'sex', f.radio_group(:profile_data, :sex, [ ['male',_('Male')], ['female',_('Female')] ])) %> |
19 | -<%= optional_field(@person, 'birth_date', labelled_form_field(_('Birth date'), date_field('profile_data[birth_date]', @profile_data. birth_date, '%Y-%m-%d', {:change_month => true, :change_year => true, :year_range => '-100:-5', :date_format => 'yy-mm-dd'}, {:id => 'profile_data_birth_date'}))) %> | |
19 | +<%= optional_field(@person, 'birth_date', labelled_form_field(_('Birth date'), date_field('profile_data[birth_date]', @profile_data. birth_date, {:change_month => true, :change_year => true, :year_range => '-100:-5', :date_format => 'yy-mm-dd'}, {:id => 'profile_data_birth_date'}))) %> | |
20 | 20 | <%= optional_field(@person, 'nationality', f.text_field(:nationality, :rel => _('Nationality'))) %> |
21 | 21 | <%= optional_field(@person, 'country', select_country(_('Country'), 'profile_data', 'country', {:class => 'type-select'})) %> |
22 | 22 | <%= optional_field(@person, 'state', f.text_field(:state, :id => 'state_field', :rel => _('State'))) %> | ... | ... |
app/views/search/_sellers_form.html.erb
... | ... | @@ -1,24 +0,0 @@ |
1 | -<h3><%= title %></h3> | |
2 | - | |
3 | -<%= form_tag({:controller => 'search', :action => 'assets'}, {:method => 'get'}) do %> | |
4 | - | |
5 | - <div class="search-in-opt"><%= _('Search in:') %> | |
6 | - <dir> | |
7 | - <%= labelled_radio_button _('Enterprises'), 'asset', 'enterprises', true %><br /> | |
8 | - <%= labelled_radio_button _('Products'), 'asset', 'products', false %> | |
9 | - </dir> | |
10 | - </div> | |
11 | - | |
12 | - <div class="formfield search-from-opt"> | |
13 | - <%= select_city(true) %> | |
14 | - </div> | |
15 | - | |
16 | - <div class="formfield search-distance-opt"> | |
17 | - <%= labelled_select(_('Distance:'), 'radius', :first, :last, nil, [15, 30, 50, 100, 150, 200, 300, 400, 500, 1000].map{|n|[n, n.to_s + 'km']}) %> | |
18 | - </div> | |
19 | - | |
20 | - <div class="button-bar"> | |
21 | - <%= submit_button :search, _('Search') %> | |
22 | - </div> | |
23 | - | |
24 | -<% end %> |
app/views/shared/block.html.erb
1 | 1 | <% if block.cacheable? && use_cache %> |
2 | 2 | <% cache_timeout(block.cache_key(language, user), block.timeout) do %> |
3 | - <%= display_block_content(block, user, main_content) %> | |
3 | + <%= display_block_content(block, main_content) %> | |
4 | 4 | <% end %> |
5 | 5 | <% else %> |
6 | - <%= display_block_content(block, user, main_content) %> | |
6 | + <%= display_block_content(block, main_content) %> | |
7 | 7 | <% end %> | ... | ... |
app/views/tasks/index.html.erb
... | ... | @@ -50,7 +50,7 @@ |
50 | 50 | <em><%= _('No pending tasks for %s') % profile.name %></em> |
51 | 51 | </p> |
52 | 52 | <% else %> |
53 | - <%= form_tag task_action('close') do%> | |
53 | + <%= form_tag tasks_url(:action => 'close') do%> | |
54 | 54 | <% button_bar(:class => 'task-actions') do %> |
55 | 55 | <%# FiXME button(:edit, _('View my requests'), :action => 'list_requested') %> |
56 | 56 | <%# FIXME button('menu-mail', _('Send request'), :action => 'new') %> | ... | ... |
debian/control
... | ... | @@ -47,6 +47,7 @@ Depends: adduser, |
47 | 47 | ruby-activerecord-session-store, |
48 | 48 | ruby-activerecord-deprecated-finders, |
49 | 49 | ruby-acts-as-taggable-on (>= 3.5), |
50 | + ruby-api-pagination, | |
50 | 51 | ruby-daemons, |
51 | 52 | ruby-dalli, |
52 | 53 | ruby-delayed-job, |
... | ... | @@ -60,7 +61,7 @@ Depends: adduser, |
60 | 61 | ruby-feedparser (>= 0.7-3~), |
61 | 62 | ruby-gettext, |
62 | 63 | ruby-grape, |
63 | - ruby-grape-entity, | |
64 | + ruby-grape-entity (= 0.4.8), | |
64 | 65 | ruby-grape-logging, |
65 | 66 | ruby-minitest, |
66 | 67 | ruby-nokogiri, | ... | ... |
... | ... | @@ -0,0 +1,45 @@ |
1 | +Feature: manage tasks | |
2 | + As an community admin user | |
3 | + I want to manage pending tasks | |
4 | + In order to approve or disapprove them | |
5 | + | |
6 | + Background: | |
7 | + Given the following users | |
8 | + | login | name | email | | |
9 | + | bob | Bob Rezende | bob@invalid.br | | |
10 | + | maria | Maria Sousa | maria@invalid.br | | |
11 | + | marie | Marie Curie | marie@invalid.br | | |
12 | + | mario | Mario Souto | mario@invalid.br | | |
13 | + And the following community | |
14 | + | identifier | name | | |
15 | + | mycommunity | My Community | | |
16 | + And the community "My Community" is closed | |
17 | + And the articles of "My Community" are moderated | |
18 | + And "Bob Rezende" is admin of "My Community" | |
19 | + And "Mario Souto" is a member of "My Community" | |
20 | + | |
21 | + @selenium | |
22 | + Scenario: keep filters after close tasks | |
23 | + Given "Marie Curie" asked to join "My Community" | |
24 | + And "Maria Sousa" asked to join "My Community" | |
25 | + And someone suggested the following article to be published | |
26 | + |name | target | email | body | person | | |
27 | + |Sample Article | mycommunity | mario@invalid.br | Corpo | mario | | |
28 | + |Other Article | mycommunity | maria@invalid.br | Corpo | maria | | |
29 | + |Another Article | mycommunity | marie@invalid.br | Corpo | marie | | |
30 | + And I am logged in as "bob" | |
31 | + And I go to mycommunity's control panel | |
32 | + And I follow "Tasks" | |
33 | + And I should see "Marie Curie wants to be a member of 'My Community'" | |
34 | + And I should see "Maria Sousa wants to be a member of 'My Community'" | |
35 | + And I should see "Mario Souto suggested the publication of the article: Sample Article" | |
36 | + And I should see "Maria Sousa suggested the publication of the article: Other Article" | |
37 | + And I should see "Marie Curie suggested the publication of the article: Another Article" | |
38 | + When I select "New member" from "Type of task" | |
39 | + And I press "Search" | |
40 | + And I should see "wants to be a member of 'My Community'" | |
41 | + And I should not see "suggested the publication of the article:" | |
42 | + And I choose "Accept" | |
43 | + And I press "Apply" | |
44 | + And I should see "wants to be a member of 'My Community'" | |
45 | + Then I should not see "suggested the publication of the article:" | ... | ... |
features/step_definitions/noosfero_steps.rb
... | ... | @@ -497,7 +497,9 @@ end |
497 | 497 | Given /^someone suggested the following article to be published$/ do |table| |
498 | 498 | table.hashes.map{|item| item.dup}.each do |item| |
499 | 499 | target = Community[item.delete('target')] |
500 | - task = SuggestArticle.create!(:target => target, :data => item) | |
500 | + article = {:name => item.delete('name'), :body => item.delete('body')} | |
501 | + person = Profile[item.delete('person')] | |
502 | + task = SuggestArticle.create!(:target => target, :article => article, :requestor => person) | |
501 | 503 | end |
502 | 504 | end |
503 | 505 | ... | ... |
lib/noosfero/api/entities.rb
... | ... | @@ -132,7 +132,6 @@ module Noosfero |
132 | 132 | expose :articles_count do |person, options| |
133 | 133 | person.articles.count |
134 | 134 | end |
135 | - | |
136 | 135 | end |
137 | 136 | |
138 | 137 | class Enterprise < Profile |
... | ... | @@ -246,7 +245,6 @@ module Noosfero |
246 | 245 | type_map.first.represent(activity.target) unless type_map.nil? |
247 | 246 | end |
248 | 247 | end |
249 | - | |
250 | 248 | end |
251 | 249 | end |
252 | 250 | end | ... | ... |
lib/noosfero/api/helpers.rb
... | ... | @@ -5,7 +5,7 @@ require_relative '../../find_by_contents' |
5 | 5 | module API |
6 | 6 | module APIHelpers |
7 | 7 | PRIVATE_TOKEN_PARAM = :private_token |
8 | - DEFAULT_ALLOWED_PARAMETERS = [:parent_id, :from, :until, :content_type, :author_id, :archived, :identifier] | |
8 | + DEFAULT_ALLOWED_PARAMETERS = [:parent_id, :from, :until, :content_type, :author_id, :identifier, :archived] | |
9 | 9 | |
10 | 10 | include SanitizeParams |
11 | 11 | include Noosfero::Plugin::HotSpot |
... | ... | @@ -116,6 +116,7 @@ require_relative '../../find_by_contents' |
116 | 116 | end |
117 | 117 | end |
118 | 118 | |
119 | + ARTICLE_TYPES = ['Article'] + Article.descendants.map{|a| a.to_s} | |
119 | 120 | TASK_TYPES = ['Task'] + Task.descendants.map{|a| a.to_s} |
120 | 121 | |
121 | 122 | def find_article(articles, id) |
... | ... | @@ -127,8 +128,7 @@ require_relative '../../find_by_contents' |
127 | 128 | return forbidden! unless current_person.can_post_content?(asset) |
128 | 129 | |
129 | 130 | klass_type= params[:content_type].nil? ? TinyMceArticle.name : params[:content_type] |
130 | - article_types = ['Article'] + Article.descendants.map{|a| a.to_s} | |
131 | - return forbidden! unless article_types.include?(klass_type) | |
131 | + return forbidden! unless ARTICLE_TYPES.include?(klass_type) | |
132 | 132 | |
133 | 133 | article = klass_type.constantize.new(params[:article]) |
134 | 134 | article.last_changed_by = current_person |
... | ... | @@ -152,12 +152,7 @@ require_relative '../../find_by_contents' |
152 | 152 | end |
153 | 153 | |
154 | 154 | def present_articles(articles) |
155 | - present_partial articles, :with => Entities::Article | |
156 | - end | |
157 | - | |
158 | - def present_articles_paginated(articles, per_page=nil) | |
159 | - articles = paginate(articles) | |
160 | - present_partial articles, :with => Entities::Article | |
155 | + present_partial paginate(articles), :with => Entities::Article | |
161 | 156 | end |
162 | 157 | |
163 | 158 | def find_articles(asset, method = 'articles') |
... | ... | @@ -239,15 +234,6 @@ require_relative '../../find_by_contents' |
239 | 234 | return order |
240 | 235 | end |
241 | 236 | |
242 | - def make_page_number_with_parameters(params) | |
243 | - params[:page] || 1 | |
244 | - end | |
245 | - | |
246 | - def make_per_page_with_parameters(params) | |
247 | - params[:per_page] ||= limit | |
248 | - params[:per_page].to_i | |
249 | - end | |
250 | - | |
251 | 237 | def make_timestamp_with_parameters_and_method(params, method) |
252 | 238 | timestamp = nil |
253 | 239 | if params[:timestamp] |
... | ... | @@ -281,17 +267,17 @@ require_relative '../../find_by_contents' |
281 | 267 | def select_filtered_collection_of(object, method, params) |
282 | 268 | conditions = make_conditions_with_parameter(params) |
283 | 269 | order = make_order_with_parameters(object,method,params) |
284 | - page_number = make_page_number_with_parameters(params) | |
285 | - per_page = make_per_page_with_parameters(params) | |
286 | 270 | timestamp = make_timestamp_with_parameters_and_method(params, method) |
287 | 271 | |
288 | 272 | objects = object.send(method) |
289 | 273 | objects = by_reference(objects, params) |
290 | 274 | objects = by_categories(objects, params) |
291 | 275 | |
292 | - objects = objects.where(conditions).where(timestamp).page(page_number).per_page(per_page).reorder(order) | |
276 | + objects = objects.where(conditions).where(timestamp).reorder(order) | |
293 | 277 | |
294 | - objects | |
278 | + params[:page] ||= 1 | |
279 | + params[:per_page] ||= limit | |
280 | + paginate(objects) | |
295 | 281 | end |
296 | 282 | |
297 | 283 | def authenticate! | ... | ... |
lib/noosfero/api/v1/activities.rb
lib/noosfero/api/v1/articles.rb
... | ... | @@ -9,8 +9,7 @@ module Noosfero |
9 | 9 | |
10 | 10 | resource :articles do |
11 | 11 | |
12 | - paginate per_page: MAX_PER_PAGE, max_per_page: MAX_PER_PAGE | |
13 | - | |
12 | + paginate max_per_page: MAX_PER_PAGE | |
14 | 13 | # Collect articles |
15 | 14 | # |
16 | 15 | # Parameters: |
... | ... | @@ -132,8 +131,7 @@ module Noosfero |
132 | 131 | named 'ArticleFollowers' |
133 | 132 | end |
134 | 133 | get 'voted_by_me' do |
135 | - #FIXME refactor this method | |
136 | - present_articles_paginated(current_person.votes.where(:voteable_type => 'Article').collect(&:voteable)) | |
134 | + present_articles(current_person.votes.where(:voteable_type => 'Article').collect(&:voteable)) | |
137 | 135 | end |
138 | 136 | |
139 | 137 | desc 'Perform a vote on a article by id' do |
... | ... | @@ -176,6 +174,11 @@ module Noosfero |
176 | 174 | {:total_followers => total} |
177 | 175 | end |
178 | 176 | |
177 | + desc "Return the articles followed by me" | |
178 | + get 'followed_by_me' do | |
179 | + present_articles_for_asset(current_person, 'following_articles') | |
180 | + end | |
181 | + | |
179 | 182 | desc "Add a follower for the article" do |
180 | 183 | detail 'Add the current user identified by private token, like a follower of a article' |
181 | 184 | params Noosfero::API::Entities::UserLogin.documentation | ... | ... |
lib/noosfero/api/v1/boxes.rb
... | ... | @@ -17,10 +17,29 @@ module Noosfero |
17 | 17 | end |
18 | 18 | end |
19 | 19 | end |
20 | - | |
21 | 20 | end |
22 | 21 | |
23 | 22 | end |
23 | + | |
24 | + resource :environments do | |
25 | + [ '/default', '/context', ':environment_id' ].each do |route| | |
26 | + segment route do | |
27 | + resource :boxes do | |
28 | + get do | |
29 | + if (route.match(/default/)) | |
30 | + env = Environment.default | |
31 | + elsif (route.match(/context/)) | |
32 | + env = environment | |
33 | + else | |
34 | + env = Environment.find(params[:environment_id]) | |
35 | + end | |
36 | + present env.boxes, :with => Entities::Box | |
37 | + end | |
38 | + end | |
39 | + end | |
40 | + end | |
41 | + end | |
42 | + | |
24 | 43 | end |
25 | 44 | |
26 | 45 | end | ... | ... |
lib/noosfero/api/v1/comments.rb
... | ... | @@ -32,8 +32,7 @@ module Noosfero |
32 | 32 | article = find_article(environment.articles, params[:id]) |
33 | 33 | options = params.select { |key,v| !['id','private_token'].include?(key) }.merge(:author => current_person, :source => article) |
34 | 34 | begin |
35 | - comment = Comment.create(options) | |
36 | - comment.save! | |
35 | + comment = Comment.create!(options) | |
37 | 36 | rescue ActiveRecord::RecordInvalid => e |
38 | 37 | render_api_error!(e.message, 400) |
39 | 38 | end | ... | ... |
lib/noosfero/api/v1/environments.rb
... | ... | @@ -9,7 +9,17 @@ module Noosfero |
9 | 9 | get '/signup_person_fields' do |
10 | 10 | present environment.signup_person_fields |
11 | 11 | end |
12 | - | |
12 | + | |
13 | + get ':id' do | |
14 | + if (params[:id] == "default") | |
15 | + present Environment.default | |
16 | + elsif (params[:id] == "context") | |
17 | + present environment | |
18 | + else | |
19 | + present Environment.find(params[:id]) | |
20 | + end | |
21 | + end | |
22 | + | |
13 | 23 | end |
14 | 24 | |
15 | 25 | end | ... | ... |
lib/noosfero/api/v1/people.rb
... | ... | @@ -9,6 +9,7 @@ module Noosfero |
9 | 9 | desc 'API Root' |
10 | 10 | |
11 | 11 | resource :people do |
12 | + paginate max_per_page: MAX_PER_PAGE | |
12 | 13 | |
13 | 14 | # -- A note about privacy -- |
14 | 15 | # We wold find people by location, but we must test if the related |
... | ... | @@ -111,7 +112,7 @@ module Noosfero |
111 | 112 | resource :profiles do |
112 | 113 | segment '/:profile_id' do |
113 | 114 | resource :members do |
114 | - paginate per_page: MAX_PER_PAGE, max_per_page: MAX_PER_PAGE | |
115 | + paginate max_per_page: MAX_PER_PAGE | |
115 | 116 | get do |
116 | 117 | profile = environment.profiles.find_by_id(params[:profile_id]) |
117 | 118 | members = select_filtered_collection_of(profile, 'members', params) |
... | ... | @@ -120,7 +121,6 @@ module Noosfero |
120 | 121 | end |
121 | 122 | end |
122 | 123 | end |
123 | - | |
124 | 124 | end |
125 | 125 | end |
126 | 126 | end | ... | ... |
lib/noosfero/api/v1/search.rb
... | ... | @@ -5,7 +5,7 @@ module Noosfero |
5 | 5 | |
6 | 6 | resource :search do |
7 | 7 | resource :article do |
8 | - paginate per_page: 20, max_per_page: 200 | |
8 | + paginate max_per_page: 200 | |
9 | 9 | get do |
10 | 10 | # Security checks |
11 | 11 | sanitize_params_hash(params) |
... | ... | @@ -24,17 +24,11 @@ module Noosfero |
24 | 24 | |
25 | 25 | options = {:filter => order, :template_id => params[:template_id]} |
26 | 26 | |
27 | - paginate_options = params.select{|k,v| [:page, :per_page].include?(k.to_sym)}.symbolize_keys | |
28 | - paginate_options.each_pair{|k,v| v=v.to_i} | |
29 | - paginate_options[:page]=1 if !paginate_options.keys.include?(:page) | |
30 | - | |
31 | - search_result = find_by_contents(asset, context, scope, query, paginate_options, options) | |
27 | + search_result = find_by_contents(asset, context, scope, query, {:page => 1}, options) | |
32 | 28 | |
33 | 29 | articles = search_result[:results] |
34 | 30 | |
35 | - result = present_articles_paginated(articles) | |
36 | - | |
37 | - result | |
31 | + present_articles(articles) | |
38 | 32 | end |
39 | 33 | end |
40 | 34 | end | ... | ... |
lib/noosfero/plugin.rb
... | ... | @@ -762,6 +762,10 @@ class Noosfero::Plugin |
762 | 762 | # returns = string with reason of expiration |
763 | 763 | elsif method.to_s =~ /^content_expire_(#{content_actions.join('|')})$/ |
764 | 764 | nil |
765 | + # -> Generic hotspots for models callbacks | |
766 | + # Example: article_after_create_callback | |
767 | + elsif method.to_s =~ /^(.+)_#{Noosfero::Plugin::HotSpot::CALLBACK_HOTSPOTS.join('|')}_callback$/ | |
768 | + nil | |
765 | 769 | elsif context.respond_to?(method) |
766 | 770 | context.send(method, *args) |
767 | 771 | else | ... | ... |
lib/noosfero/plugin/hot_spot.rb
... | ... | @@ -6,6 +6,7 @@ |
6 | 6 | # Environment will be used to determine which plugins are enabled and therefore |
7 | 7 | # which plugins should be instantiated. |
8 | 8 | module Noosfero::Plugin::HotSpot |
9 | + CALLBACK_HOTSPOTS =[:after_save, :after_destroy, :before_save, :before_destroy, :after_create, :before_create] | |
9 | 10 | |
10 | 11 | # Returns an instance of Noosfero::Plugin::Manager. |
11 | 12 | # |
... | ... | @@ -15,4 +16,26 @@ module Noosfero::Plugin::HotSpot |
15 | 16 | @plugins ||= Noosfero::Plugin::Manager.new(environment, self) |
16 | 17 | end |
17 | 18 | |
19 | + def self.included(klass) | |
20 | + klass.extend(ClassMethods) | |
21 | + end | |
22 | + | |
23 | + module ClassMethods | |
24 | + def self.extended base | |
25 | + CALLBACK_HOTSPOTS.each do |callback| | |
26 | + if base.respond_to?(callback) | |
27 | + base.class_eval do | |
28 | + self.send callback do |object| | |
29 | + current=self.class | |
30 | + while current.included_modules.include? Noosfero::Plugin::HotSpot do | |
31 | + callback_name = "#{current.name.underscore}_#{callback}_callback" | |
32 | + plugins.dispatch(callback_name, object) | |
33 | + current=current.superclass | |
34 | + end | |
35 | + end | |
36 | + end | |
37 | + end | |
38 | + end | |
39 | + end | |
40 | + end | |
18 | 41 | end | ... | ... |
lib/noosfero/plugin/manager.rb
... | ... | @@ -75,7 +75,8 @@ class Noosfero::Plugin::Manager |
75 | 75 | end |
76 | 76 | |
77 | 77 | def enabled_plugins |
78 | - @enabled_plugins ||= (Noosfero::Plugin.all & environment.enabled_plugins).map do |plugin| | |
78 | + environment_enabled_plugins = environment.present? ? environment.enabled_plugins : [] | |
79 | + @enabled_plugins ||= (Noosfero::Plugin.all & environment_enabled_plugins).map do |plugin| | |
79 | 80 | Noosfero::Plugin.load_plugin_identifier(plugin).new context |
80 | 81 | end |
81 | 82 | end | ... | ... |
lib/tasks/plugins_tests.rake
... | ... | @@ -215,7 +215,15 @@ namespace :test do |
215 | 215 | |
216 | 216 | desc "Run all tests for all plugins" |
217 | 217 | task :noosfero_plugins do |
218 | - test_sequence(@all_plugins - $broken_plugins, @all_tasks) do |failed| | |
218 | + plugins = @all_plugins - $broken_plugins | |
219 | + if slice = ENV['SLICE'] | |
220 | + slice = slice.split('/').map &:to_i | |
221 | + selected = slice[0]-1 | |
222 | + size = (plugins.size / slice[1].to_f).ceil | |
223 | + plugins = plugins.each_slice(size).to_a[selected] | |
224 | + end | |
225 | + | |
226 | + test_sequence plugins, @all_tasks do |failed| | |
219 | 227 | plugins_status_report(failed) |
220 | 228 | end |
221 | 229 | end |
... | ... | @@ -233,8 +241,10 @@ def plugins_status_report(failed) |
233 | 241 | |
234 | 242 | @all_plugins.each do |plugin| |
235 | 243 | if $broken_plugins.include?(plugin) |
244 | + status = "BROKEN" | |
245 | + elsif failed[plugin].nil? | |
236 | 246 | status = "SKIP" |
237 | - elsif !failed[plugin] || failed[plugin].empty? | |
247 | + elsif failed[plugin].empty? | |
238 | 248 | status = "PASS" |
239 | 249 | else |
240 | 250 | status = "FAIL: #{failed[plugin].join(', ')}" | ... | ... |
plugins/community_track/views/cms/community_track_plugin/_step.html.erb
... | ... | @@ -6,7 +6,6 @@ |
6 | 6 | <%= required f.text_field('name', :size => '64', :maxlength => 150) %> |
7 | 7 | <%= labelled_form_field(_('Period'), ( |
8 | 8 | date_range_field('article[start_date]', 'article[end_date]', @article.start_date, @article.end_date, |
9 | - '%Y-%m-%d', | |
10 | 9 | { :change_month => true, :change_year => true, |
11 | 10 | :date_format => 'yy-mm-dd' }, |
12 | 11 | { :size => 14 }) | ... | ... |
plugins/custom_forms/db/migrate/20151008130948_create_text_field_type_in_custom_forms_plugin.rb
0 → 100644
... | ... | @@ -0,0 +1,13 @@ |
1 | +class CreateTextFieldTypeInCustomFormsPlugin < ActiveRecord::Migration | |
2 | + def up | |
3 | + rename_column :custom_forms_plugin_fields, :select_field_type, :show_as | |
4 | + change_column :custom_forms_plugin_fields, :show_as, :string, :null => true, :default => nil | |
5 | + update("UPDATE custom_forms_plugin_fields SET show_as='text' WHERE type = 'CustomFormsPlugin::TextField'") | |
6 | + end | |
7 | + | |
8 | + def down | |
9 | + rename_column :custom_forms_plugin_fields, :show_as, :select_field_type | |
10 | + change_column :custom_forms_plugin_fields, :select_field_type, :string, :null => false, :default => 'radio' | |
11 | + update("UPDATE custom_forms_plugin_fields SET select_field_type='radio' WHERE type = 'CustomFormsPlugin::TextField'") | |
12 | + end | |
13 | +end | ... | ... |
plugins/custom_forms/lib/custom_forms_plugin/field.rb
... | ... | @@ -2,8 +2,9 @@ class CustomFormsPlugin::Field < ActiveRecord::Base |
2 | 2 | self.table_name = :custom_forms_plugin_fields |
3 | 3 | |
4 | 4 | validates_presence_of :name |
5 | + validates_length_of :default_value, :maximum => 255 | |
5 | 6 | |
6 | - attr_accessible :name, :form, :mandatory, :type, :position, :default_value, :select_field_type, :alternatives_attributes | |
7 | + attr_accessible :name, :form, :mandatory, :type, :position, :default_value, :show_as, :alternatives_attributes | |
7 | 8 | |
8 | 9 | belongs_to :form, :class_name => 'CustomFormsPlugin::Form' |
9 | 10 | has_many :answers, :class_name => 'CustomFormsPlugin::Answer', :dependent => :destroy | ... | ... |
plugins/custom_forms/lib/custom_forms_plugin/helper.rb
... | ... | @@ -85,7 +85,11 @@ module CustomFormsPlugin::Helper |
85 | 85 | |
86 | 86 | def display_text_field(field, answer, form) |
87 | 87 | value = answer.present? ? answer.value : field.default_value |
88 | - text_field(form, "#{field.id}", :value => value, :disabled => display_disabled?(field, answer)) | |
88 | + if field.show_as == 'textarea' | |
89 | + text_area(form, "#{field.id}", :value => value, :disabled => display_disabled?(field, answer)) | |
90 | + else | |
91 | + text_field(form, "#{field.id}", :value => value, :disabled => display_disabled?(field, answer)) | |
92 | + end | |
89 | 93 | end |
90 | 94 | |
91 | 95 | def default_selected(field, answer) |
... | ... | @@ -93,7 +97,7 @@ module CustomFormsPlugin::Helper |
93 | 97 | end |
94 | 98 | |
95 | 99 | def display_select_field(field, answer, form) |
96 | - case field.select_field_type | |
100 | + case field.show_as | |
97 | 101 | when 'select' |
98 | 102 | selected = default_selected(field, answer) |
99 | 103 | select_tag form.to_s + "[#{field.id}]", options_for_select([['','']] + field.alternatives.map {|a| [a.label, a.id.to_s]}, selected), :disabled => display_disabled?(field, answer) |
... | ... | @@ -114,11 +118,11 @@ module CustomFormsPlugin::Helper |
114 | 118 | end |
115 | 119 | |
116 | 120 | def radio_button?(field) |
117 | - type_for_options(field.class) == 'select_field' && field.select_field_type == 'radio' | |
121 | + type_for_options(field.class) == 'select_field' && field.show_as == 'radio' | |
118 | 122 | end |
119 | 123 | |
120 | 124 | def check_box?(field) |
121 | - type_for_options(field.class) == 'select_field' && field.select_field_type == 'check_box' | |
125 | + type_for_options(field.class) == 'select_field' && field.show_as == 'check_box' | |
122 | 126 | end |
123 | 127 | |
124 | 128 | end | ... | ... |
plugins/custom_forms/lib/custom_forms_plugin/select_field.rb
1 | 1 | class CustomFormsPlugin::SelectField < CustomFormsPlugin::Field |
2 | 2 | self.table_name = :custom_forms_plugin_fields |
3 | - validates_inclusion_of :select_field_type, :in => %w(radio check_box select multiple_select) | |
3 | + validates_inclusion_of :show_as, :in => %w(radio check_box select multiple_select) | |
4 | 4 | validates_length_of :alternatives, :minimum => 1, :message => 'can\'t be empty' |
5 | + | |
6 | + after_initialize do | |
7 | + self.show_as ||= 'radio' | |
8 | + end | |
5 | 9 | end | ... | ... |
plugins/custom_forms/lib/custom_forms_plugin/text_field.rb
plugins/custom_forms/po/pt/custom_forms.po
... | ... | @@ -13,16 +13,16 @@ msgid "" |
13 | 13 | msgstr "" |
14 | 14 | "Project-Id-Version: 1.3~rc2-1-ga15645d\n" |
15 | 15 | "POT-Creation-Date: 2015-10-30 16:35-0300\n" |
16 | -"PO-Revision-Date: 2015-08-07 16:48+0200\n" | |
17 | -"Last-Translator: Antonio Terceiro <terceiro@softwarelivre.org>\n" | |
18 | -"Language-Team: Portuguese <https://hosted.weblate.org/projects/noosfero/" | |
19 | -"plugin-custom-forms/pt/>\n" | |
16 | +"PO-Revision-Date: 2016-03-14 15:58+0000\n" | |
17 | +"Last-Translator: Eduardo Vital <vitaldu@gmail.com>\n" | |
18 | +"Language-Team: Portuguese <https://hosted.weblate.org/projects/noosfero" | |
19 | +"/plugin-custom-forms/pt/>\n" | |
20 | 20 | "Language: pt\n" |
21 | 21 | "MIME-Version: 1.0\n" |
22 | 22 | "Content-Type: text/plain; charset=UTF-8\n" |
23 | 23 | "Content-Transfer-Encoding: 8bit\n" |
24 | 24 | "Plural-Forms: nplurals=2; plural=n != 1;\n" |
25 | -"X-Generator: Weblate 2.4-dev\n" | |
25 | +"X-Generator: Weblate 2.5\n" | |
26 | 26 | |
27 | 27 | #: plugins/custom_forms/lib/custom_forms_plugin/form.rb:67 |
28 | 28 | msgid "Invalid string format of access." |
... | ... | @@ -184,7 +184,7 @@ msgstr "E-mail" |
184 | 184 | |
185 | 185 | #: plugins/custom_forms/views/custom_forms_plugin_profile/show.html.erb:31 |
186 | 186 | msgid "Your e-mail will be visible to this form's owners." |
187 | -msgstr "" | |
187 | +msgstr "Seu e-mail ficará visível para o dono deste formulário." | |
188 | 188 | |
189 | 189 | #: plugins/custom_forms/views/custom_forms_plugin_myprofile/new.html.erb:1 |
190 | 190 | msgid "New form" |
... | ... | @@ -220,11 +220,11 @@ msgstr "Radio" |
220 | 220 | |
221 | 221 | #: plugins/custom_forms/views/custom_forms_plugin_myprofile/custom_forms_plugin/_select_field.html.erb:7 |
222 | 222 | msgid "Checkbox" |
223 | -msgstr "Checkbox" | |
223 | +msgstr "Caixa de seleção" | |
224 | 224 | |
225 | 225 | #: plugins/custom_forms/views/custom_forms_plugin_myprofile/custom_forms_plugin/_select_field.html.erb:9 |
226 | 226 | msgid "Drop down" |
227 | -msgstr "Drop down" | |
227 | +msgstr "Lista suspensa" | |
228 | 228 | |
229 | 229 | #: plugins/custom_forms/views/custom_forms_plugin_myprofile/custom_forms_plugin/_select_field.html.erb:11 |
230 | 230 | msgid "Multiple Select" |
... | ... | @@ -262,7 +262,7 @@ msgstr "Disparado depois da aprovação de um novo integrante" |
262 | 262 | #: plugins/custom_forms/views/custom_forms_plugin_myprofile/_form.html.erb:29 |
263 | 263 | #: plugins/custom_forms/views/custom_forms_plugin_myprofile/_form.html.erb:38 |
264 | 264 | msgid "This field will be added automatically to your form" |
265 | -msgstr "" | |
265 | +msgstr "Esse campo será adicionado automaticamente no seu formulário" | |
266 | 266 | |
267 | 267 | #: plugins/custom_forms/views/custom_forms_plugin_myprofile/_form.html.erb:55 |
268 | 268 | msgid "Add a new text field" |
... | ... | @@ -315,18 +315,16 @@ msgid "Back to forms" |
315 | 315 | msgstr "Voltar para os formulários" |
316 | 316 | |
317 | 317 | #: plugins/custom_forms/views/custom_forms_plugin_myprofile/show_submission.html.erb:10 |
318 | -#, fuzzy | |
319 | 318 | msgid "Submission date" |
320 | -msgstr "Submissão salva" | |
319 | +msgstr "Data da submissão" | |
321 | 320 | |
322 | 321 | #: plugins/custom_forms/views/custom_forms_plugin_myprofile/show_submission.html.erb:14 |
323 | -#, fuzzy | |
324 | 322 | msgid "Author" |
325 | -msgstr "Nome do autor" | |
323 | +msgstr "Autor" | |
326 | 324 | |
327 | 325 | #: plugins/custom_forms/views/custom_forms_plugin_myprofile/show_submission.html.erb:26 |
328 | 326 | msgid "Unauthenticated" |
329 | -msgstr "" | |
327 | +msgstr "Não autenticado" | |
330 | 328 | |
331 | 329 | #: plugins/custom_forms/views/custom_forms_plugin_myprofile/show_submission.html.erb:48 |
332 | 330 | msgid "Back to submissions" | ... | ... |
plugins/custom_forms/public/style.css
plugins/custom_forms/test/functional/custom_forms_plugin_myprofile_controller_test.rb
... | ... | @@ -54,7 +54,7 @@ class CustomFormsPluginMyprofileControllerTest < ActionController::TestCase |
54 | 54 | }, |
55 | 55 | 2 => { |
56 | 56 | :name => 'Color', |
57 | - :select_field_type => 'radio', | |
57 | + :show_as => 'radio', | |
58 | 58 | :type => 'CustomFormsPlugin::SelectField', |
59 | 59 | :alternatives_attributes => { |
60 | 60 | 1 => {:label => 'Red'}, |
... | ... | @@ -82,7 +82,7 @@ class CustomFormsPluginMyprofileControllerTest < ActionController::TestCase |
82 | 82 | |
83 | 83 | assert_equal 'Color', f2.name |
84 | 84 | assert_equal f2.alternatives.map(&:label).sort, ['Red', 'Blue', 'Black'].sort |
85 | - assert_equal f2.select_field_type, 'radio' | |
85 | + assert_equal f2.show_as, 'radio' | |
86 | 86 | assert f2.kind_of?(CustomFormsPlugin::SelectField) |
87 | 87 | end |
88 | 88 | ... | ... |
plugins/custom_forms/test/unit/custom_forms_plugin/select_field_test.rb
... | ... | @@ -13,16 +13,16 @@ class CustomFormsPlugin::SelectFieldTest < ActiveSupport::TestCase |
13 | 13 | select = CustomFormsPlugin::SelectField.new(:name => 'select_field001' ) |
14 | 14 | select.alternatives << CustomFormsPlugin::Alternative.new(:label => 'option') |
15 | 15 | |
16 | - select.update_attribute(:select_field_type, 'random') | |
16 | + select.update_attribute(:show_as, 'random') | |
17 | 17 | assert select.invalid? |
18 | 18 | |
19 | - select.update_attribute(:select_field_type, 'radio') | |
19 | + select.update_attribute(:show_as, 'radio') | |
20 | 20 | assert select.valid? |
21 | - select.update_attribute(:select_field_type, 'check_box') | |
21 | + select.update_attribute(:show_as, 'check_box') | |
22 | 22 | assert select.valid? |
23 | - select.update_attribute(:select_field_type, 'select') | |
23 | + select.update_attribute(:show_as, 'select') | |
24 | 24 | assert select.valid? |
25 | - select.update_attribute(:select_field_type, 'multiple_select') | |
25 | + select.update_attribute(:show_as, 'multiple_select') | |
26 | 26 | assert select.valid? |
27 | 27 | end |
28 | 28 | end | ... | ... |
plugins/custom_forms/test/unit/custom_forms_plugin/text_field_test.rb
0 → 100644
... | ... | @@ -0,0 +1,22 @@ |
1 | +require File.dirname(__FILE__) + '/../../../../../test/test_helper' | |
2 | + | |
3 | +class CustomFormsPlugin::TextFieldTest < ActiveSupport::TestCase | |
4 | + should 'validate type' do | |
5 | + text = CustomFormsPlugin::TextField.new(:name => 'text-field-010' ) | |
6 | + | |
7 | + text.update_attribute(:show_as, 'random') | |
8 | + assert text.invalid? | |
9 | + text.update_attribute(:show_as, 'radio') | |
10 | + assert text.invalid? | |
11 | + | |
12 | + text.update_attribute(:show_as, 'text') | |
13 | + assert text.valid? | |
14 | + text.update_attribute(:show_as, 'textarea') | |
15 | + assert text.valid? | |
16 | + end | |
17 | + | |
18 | + should 'field type defaults to text when initialized' do | |
19 | + text = CustomFormsPlugin::TextField.new(:name => 'text_field001' ) | |
20 | + assert_equal 'text', text.show_as | |
21 | + end | |
22 | +end | ... | ... |
plugins/custom_forms/views/custom_forms_plugin_myprofile/_edit_select.html.erb
... | ... | @@ -1,32 +0,0 @@ |
1 | -<div class='edit-information edit-select'> | |
2 | - <h2><%= c_('Options') %></h2> | |
3 | - <table class='action-table' style='width: 420px'> | |
4 | - <tr> | |
5 | - <th style='width: 40%'><%= _('Name') %></th> | |
6 | - <th style='width: 40%'><%= _('Value') %></th> | |
7 | - <th style='width: 20%'><%= c_('Delete') %></th> | |
8 | - </tr> | |
9 | - <% option_counter = 1 %> | |
10 | - <% (field.choices || {}).each do |name, value| %> | |
11 | - <%= render :partial => 'option', :locals => {:name => name, :value => value, :counter => counter, :option_counter => option_counter} %> | |
12 | - <% option_counter += 1 %> | |
13 | - <% end %> | |
14 | - <%= render :partial => 'empty_option', :locals => {:counter => counter, :option_counter => option_counter} %> | |
15 | - <tr class='new-item'> | |
16 | - <td colspan='3'> | |
17 | - <%= button(:add, _('Add a new option'), '#', :class => 'new-option', :field_id => counter)%> | |
18 | - </td> | |
19 | - </tr> | |
20 | - </table> | |
21 | - | |
22 | - <h3><%= c_('Type') %></h3> | |
23 | - <%= labelled_radio_button 'Radio', "fields[#{counter}][kind]", 'radio', !field.multiple && !field.list %><br /> | |
24 | - <%= labelled_radio_button 'Checkbox', "fields[#{counter}][kind]", 'check_box', field.multiple && !field.list %><br /> | |
25 | - <%= labelled_radio_button 'Select', "fields[#{counter}][kind]", 'select', !field.multiple && field.list %><br /> | |
26 | - <%= labelled_radio_button 'Multiple Select', "fields[#{counter}][kind]", 'multiple_select', field.multiple && field.list %><br /> | |
27 | - | |
28 | - <% button_bar do %> | |
29 | - <%= button :ok, _('Ok'), '#', :div_id => elem_id %> | |
30 | - <% end %> | |
31 | -</div> | |
32 | - |
plugins/custom_forms/views/custom_forms_plugin_myprofile/_empty_field.html.erb
... | ... | @@ -1,10 +0,0 @@ |
1 | -<tr id="empty-field" style='display: none' last_id=<%= counter %>> | |
2 | - <td style="text-align: left"><%= text_field "fields[#{counter}]", :name, :size => 25 %></td> | |
3 | - <td><%= select "fields[#{counter}]", :type, type_options, :selected => type_for_options(field.class) %></td> | |
4 | - <td><%= check_box "fields[#{counter}]", :mandatory %></td> | |
5 | - <%= hidden_field "fields[#{counter}]", :form_id, :value => @form.id %> | |
6 | - <td class='actions'> | |
7 | - <%= button_without_text :edit, c_('Edit'), '', :field_id => counter %> | |
8 | - <%= button_without_text :remove, c_('Remove'), '#', class: 'remove-field', field_id: counter, data: {confirm: _('Are you sure you want to remove this field?')} %> | |
9 | - </td> | |
10 | -</tr> |
plugins/custom_forms/views/custom_forms_plugin_myprofile/_empty_option.html.erb
... | ... | @@ -1,8 +0,0 @@ |
1 | -<tr id=<%= "empty-option-#{counter}" %> option_id=<%= option_counter %> style="display: none;"> | |
2 | - <td><%= text_field_tag("fields[#{counter}][choices][#{option_counter}][name]") %></td> | |
3 | - <td><%= text_field_tag("fields[#{counter}][choices][#{option_counter}][value]") %></td> | |
4 | - <td class='actions'> | |
5 | - <%= button_without_text :remove, c_('Remove'), '#', class: 'remove-option', field_id: counter, option_id: option_counter, data: {confirm: _('Are you sure you want to remove this option?')} %> | |
6 | - </td> | |
7 | -</tr> | |
8 | - |
plugins/custom_forms/views/custom_forms_plugin_myprofile/_form.html.erb
... | ... | @@ -5,7 +5,6 @@ |
5 | 5 | <%= required labelled_form_field _('Name'), f.text_field(:name) %> |
6 | 6 | <%= labelled_form_field(_('What is the time limit for this form to be filled?'), ( |
7 | 7 | date_range_field('form[begining]', 'form[ending]', @form.begining, @form.ending, |
8 | - '%Y/%m/%d %H:%M', | |
9 | 8 | { :time => true, :change_month => true, :change_year => true, |
10 | 9 | :date_format => 'yy-mm-dd', :time_format => 'hh:mm' }, |
11 | 10 | { :size => 14 }) | ... | ... |
plugins/custom_forms/views/custom_forms_plugin_myprofile/custom_forms_plugin/_select_field.html.erb
1 | 1 | <%= render :layout => 'field', :locals => { :f => f } do %> |
2 | 2 | <div class="field-select-type"> |
3 | 3 | <%= _('Type:') %> |
4 | - <%= f.radio_button(:select_field_type, 'radio') %> | |
5 | - <%= f.label(:select_field_type, _('Radio'), :value => 'radio') %> | |
6 | - <%= f.radio_button(:select_field_type, 'check_box') %> | |
7 | - <%= f.label(:select_field_type, _('Checkbox'), :value => 'check_box') %> | |
8 | - <%= f.radio_button(:select_field_type, 'select') %> | |
9 | - <%= f.label(:select_field_type, _('Drop down'), :value => 'select') %> | |
10 | - <%= f.radio_button(:select_field_type, 'multiple_select') %> | |
11 | - <%= f.label(:select_field_type, _('Multiple Select'), :value => 'multiple_select') %> | |
4 | + <%= f.radio_button(:show_as, 'radio') %> | |
5 | + <%= f.label(:show_as, _('Radio'), :value => 'radio') %> | |
6 | + <%= f.radio_button(:show_as, 'check_box') %> | |
7 | + <%= f.label(:show_as, _('Checkbox'), :value => 'check_box') %> | |
8 | + <%= f.radio_button(:show_as, 'select') %> | |
9 | + <%= f.label(:show_as, _('Drop down'), :value => 'select') %> | |
10 | + <%= f.radio_button(:show_as, 'multiple_select') %> | |
11 | + <%= f.label(:show_as, _('Multiple Select'), :value => 'multiple_select') %> | |
12 | 12 | </div> |
13 | 13 | |
14 | 14 | <table> | ... | ... |
plugins/custom_forms/views/custom_forms_plugin_myprofile/custom_forms_plugin/_text_field.html.erb
1 | 1 | <%= render :layout => 'field', :locals => { :f => f } do %> |
2 | + <div class="field-select-type"> | |
3 | + <%= _('Type:') %> | |
4 | + <%= f.radio_button(:show_as, 'text') %> | |
5 | + <%= f.label(:show_as, _('One-line text'), :value => 'text') %> | |
6 | + <%= f.radio_button(:show_as, 'textarea') %> | |
7 | + <%= f.label(:show_as, _('Multiline text'), :value => 'textarea') %> | |
8 | + </div> | |
9 | + | |
2 | 10 | <div class="field-text-default"> |
3 | 11 | <%= f.label(:default_value, _('Default text:')) %> |
4 | 12 | <%= f.text_field(:default_value) %> |
13 | + <small><%= _('Maximum of 255 characters') %></small> | |
5 | 14 | </div> |
6 | 15 | <% end %> | ... | ... |
plugins/ldap/po/pt/ldap.po
... | ... | @@ -13,16 +13,16 @@ msgid "" |
13 | 13 | msgstr "" |
14 | 14 | "Project-Id-Version: 1.3~rc2-1-ga15645d\n" |
15 | 15 | "POT-Creation-Date: 2015-10-30 16:35-0300\n" |
16 | -"PO-Revision-Date: 2014-12-18 18:40-0200\n" | |
17 | -"Last-Translator: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com>\n" | |
18 | -"Language-Team: Portuguese <https://hosted.weblate.org/projects/noosfero/" | |
19 | -"noosfero/pt/>\n" | |
16 | +"PO-Revision-Date: 2016-03-14 16:09+0000\n" | |
17 | +"Last-Translator: Eduardo Vital <vitaldu@gmail.com>\n" | |
18 | +"Language-Team: Portuguese <https://hosted.weblate.org/projects/noosfero" | |
19 | +"/plugin-ldap/pt/>\n" | |
20 | 20 | "Language: pt\n" |
21 | 21 | "MIME-Version: 1.0\n" |
22 | 22 | "Content-Type: text/plain; charset=UTF-8\n" |
23 | 23 | "Content-Transfer-Encoding: 8bit\n" |
24 | 24 | "Plural-Forms: nplurals=2; plural=n != 1;\n" |
25 | -"X-Generator: Weblate 2.0\n" | |
25 | +"X-Generator: Weblate 2.5\n" | |
26 | 26 | |
27 | 27 | #: plugins/ldap/lib/ldap_plugin.rb:11 |
28 | 28 | msgid "A plugin that add ldap support." |
... | ... | @@ -42,7 +42,7 @@ msgstr "Gerenciamento do Ldap" |
42 | 42 | |
43 | 43 | #: plugins/ldap/views/ldap_plugin_admin/index.html.erb:7 |
44 | 44 | msgid "LDAP Configuration" |
45 | -msgstr "" | |
45 | +msgstr "Configuração do LDAP" | |
46 | 46 | |
47 | 47 | #: plugins/ldap/views/ldap_plugin_admin/index.html.erb:8 |
48 | 48 | msgid "Value" |
... | ... | @@ -85,9 +85,8 @@ msgid "Attributes" |
85 | 85 | msgstr "Atributos" |
86 | 86 | |
87 | 87 | #: plugins/ldap/views/ldap_plugin_admin/index.html.erb:47 |
88 | -#, fuzzy | |
89 | 88 | msgid "LDAP Field" |
90 | -msgstr "Filtro LDAP" | |
89 | +msgstr "Campo do LDAP" | |
91 | 90 | |
92 | 91 | #: plugins/ldap/views/ldap_plugin_admin/index.html.erb:54 |
93 | 92 | msgid "Fullname" |
... | ... | @@ -98,12 +97,13 @@ msgid "Mail" |
98 | 97 | msgstr "Mail" |
99 | 98 | |
100 | 99 | #: plugins/ldap/views/ldap_plugin_admin/index.html.erb:65 |
100 | +#, fuzzy | |
101 | 101 | msgid "Behaviour Configuration" |
102 | -msgstr "" | |
102 | +msgstr "Configuração de comportamento" | |
103 | 103 | |
104 | 104 | #: plugins/ldap/views/ldap_plugin_admin/index.html.erb:70 |
105 | 105 | msgid "Allow password recovery" |
106 | -msgstr "" | |
106 | +msgstr "Permitir recuperação de senha" | |
107 | 107 | |
108 | 108 | #: plugins/ldap/views/ldap_plugin_admin/index.html.erb:78 |
109 | 109 | msgid "Back to plugins administration panel" | ... | ... |
plugins/newsletter/controllers/newsletter_plugin_admin_controller.rb
... | ... | @@ -30,14 +30,14 @@ class NewsletterPluginAdminController < PluginAdminController |
30 | 30 | end |
31 | 31 | |
32 | 32 | #TODO: Make this query faster |
33 | - def search_communities | |
34 | - communities = environment.communities | |
33 | + def search_profiles | |
34 | + profiles = environment.profiles | |
35 | 35 | blogs = Blog.joins(:profile).where(profiles: {environment_id: environment.id}) |
36 | 36 | |
37 | - found_communities = find_by_contents(:communities, environment, communities, params['q'], {:page => 1})[:results] | |
37 | + found_profiles = find_by_contents(:profiles, environment, profiles, params['q'], {:page => 1})[:results] | |
38 | 38 | found_blogs = find_by_contents(:blogs, environment, blogs, params['q'], {:page => 1})[:results] |
39 | 39 | |
40 | - results = (found_blogs + found_communities.map(&:blogs).flatten).uniq | |
40 | + results = (found_blogs + found_profiles.map(&:blogs).flatten).uniq | |
41 | 41 | render :text => results.map { |blog| {:id => blog.id, :name => _("%s in %s") % [blog.name, blog.profile.name]} }.to_json |
42 | 42 | end |
43 | 43 | ... | ... |
plugins/newsletter/features/newsletter_plugin.feature
1 | 1 | Feature: newsletter plugin |
2 | 2 | |
3 | 3 | Background: |
4 | - Given the following users | |
5 | - | login | name | | |
6 | - | joaosilva | Joao Silva | | |
7 | - And I am logged in as "joaosilva" | |
4 | + Given I am logged in as admin | |
8 | 5 | |
9 | 6 | Scenario: as admin I can configure plugin |
10 | - Given I am logged in as admin | |
11 | 7 | When I go to the environment control panel |
12 | 8 | And I follow "Plugins" |
13 | 9 | Then I should see "Configuration" linking to "/admin/plugin/newsletter" |
14 | 10 | |
15 | 11 | Scenario: in the newsletter settings I can see the field to enable/disable |
16 | - Given I am logged in as admin | |
17 | 12 | When I go to the environment control panel |
18 | 13 | And I follow "Plugins" |
19 | 14 | And I follow "Configuration" |
20 | 15 | Then I should see "Enable send of newsletter to members on this environment" |
21 | 16 | |
22 | 17 | Scenario: redirect to newsletter visualization after save and visualize |
23 | - Given I am logged in as admin | |
24 | - And "NewsletterPlugin" plugin is enabled | |
18 | + Given "NewsletterPlugin" plugin is enabled | |
25 | 19 | When I go to the environment control panel |
26 | 20 | And I follow "Plugins" |
27 | 21 | And I follow "Configuration" |
... | ... | @@ -30,11 +24,58 @@ Feature: newsletter plugin |
30 | 24 | And I should not see "Newsletter settings" |
31 | 25 | |
32 | 26 | Scenario: stay on newsletter settings page after save |
33 | - Given I am logged in as admin | |
34 | - And "NewsletterPlugin" plugin is enabled | |
27 | + Given "NewsletterPlugin" plugin is enabled | |
35 | 28 | When I go to the environment control panel |
36 | 29 | And I follow "Plugins" |
37 | 30 | And I follow "Configuration" |
38 | 31 | And I press "Save" |
39 | 32 | Then I should see "Newsletter settings" |
40 | 33 | And I should not see "If you can't view this email, click here" |
34 | + | |
35 | + @selenium | |
36 | + Scenario: search community and select blog for newsletter | |
37 | + Given the following communities | |
38 | + | identifier | name | | |
39 | + | sample-community | Sample Community | | |
40 | + And the following blogs | |
41 | + | owner | name | | |
42 | + | sample-community | Sample Blog | | |
43 | + And "NewsletterPlugin" plugin is enabled | |
44 | + When I go to the environment control panel | |
45 | + And I follow "Plugins" | |
46 | + And I follow "Configuration" | |
47 | + And I type in "Sample Community" into autocomplete list "search-profiles" and I choose "Sample Blog in Sample Community" | |
48 | + And I press "Save" | |
49 | + Then I should see "Sample Blog in Sample Community" | |
50 | + | |
51 | + @selenium | |
52 | + Scenario: search profile and select blog for newsletter | |
53 | + Given the following users | |
54 | + | login | name | | |
55 | + | joaosilva | Joao Silva | | |
56 | + And the following blogs | |
57 | + | owner | name | | |
58 | + | joaosilva | Joao Blog | | |
59 | + And "NewsletterPlugin" plugin is enabled | |
60 | + When I go to the environment control panel | |
61 | + And I follow "Plugins" | |
62 | + And I follow "Configuration" | |
63 | + And I type in "Silva" into autocomplete list "search-profiles" and I choose "Joao Blog in Joao Silva" | |
64 | + And I press "Save" | |
65 | + Then I should see "Joao Blog in Joao Silva" | |
66 | + | |
67 | + @selenium | |
68 | + Scenario: search blog and select it for newsletter | |
69 | + Given the following communities | |
70 | + | identifier | name | | |
71 | + | sample-community | Sample Community | | |
72 | + And the following blogs | |
73 | + | owner | name | | |
74 | + | sample-community | Sample Blog | | |
75 | + And "NewsletterPlugin" plugin is enabled | |
76 | + When I go to the environment control panel | |
77 | + And I follow "Plugins" | |
78 | + And I follow "Configuration" | |
79 | + And I type in "Sample Blog" into autocomplete list "search-profiles" and I choose "Sample Blog in Sample Community" | |
80 | + And I press "Save" | |
81 | + Then I should see "Sample Blog in Sample Community" | ... | ... |
plugins/newsletter/po/newsletter.pot
... | ... | @@ -158,7 +158,7 @@ msgid "Blogs from which news will be compiled" |
158 | 158 | msgstr "" |
159 | 159 | |
160 | 160 | #: plugins/newsletter/views/newsletter_plugin_admin/index.html.erb:36 |
161 | -msgid "Type in the communities' or blogs' names" | |
161 | +msgid "Type in the profiles' or blogs' names" | |
162 | 162 | msgstr "" |
163 | 163 | |
164 | 164 | #: plugins/newsletter/views/newsletter_plugin_admin/index.html.erb:42 | ... | ... |
plugins/newsletter/po/pt/newsletter.po
... | ... | @@ -164,8 +164,8 @@ msgid "Blogs from which news will be compiled" |
164 | 164 | msgstr "Blogs utilizados como fonte do boletim informativo" |
165 | 165 | |
166 | 166 | #: plugins/newsletter/views/newsletter_plugin_admin/index.html.erb:36 |
167 | -msgid "Type in the communities' or blogs' names" | |
168 | -msgstr "Digite nomes de comunidades ou blogs" | |
167 | +msgid "Type in the profiles' or blogs' names" | |
168 | +msgstr "Digite nomes de perfis ou blogs" | |
169 | 169 | |
170 | 170 | #: plugins/newsletter/views/newsletter_plugin_admin/index.html.erb:42 |
171 | 171 | msgid "Recipients" | ... | ... |
plugins/newsletter/views/newsletter_plugin_admin/index.html.erb
... | ... | @@ -29,11 +29,11 @@ |
29 | 29 | %> |
30 | 30 | |
31 | 31 | <p><%= _('Blogs from which news will be compiled') %></p> |
32 | - <% search_action = url_for(:action => 'search_communities') %> | |
32 | + <% search_action = url_for(:action => 'search_profiles') %> | |
33 | 33 | <% selected_blogs = @blogs.map { |blog| {:id => blog.id, :name => _("%s in %s") % [blog.name, blog.profile.name]} } %> |
34 | 34 | <%= token_input_field_tag( |
35 | - 'newsletter[blog_ids]', 'search-communities', search_action, | |
36 | - { hint_text: _('Type in the communities\' or blogs\' names'), | |
35 | + 'newsletter[blog_ids]', 'search-profiles', search_action, | |
36 | + { hint_text: _('Type in the profiles\' or blogs\' names'), | |
37 | 37 | focus: false, pre_populate: selected_blogs }) %> |
38 | 38 | |
39 | 39 | <br/> | ... | ... |
plugins/people_block/lib/friends_block.rb
... | ... | @@ -20,14 +20,6 @@ class FriendsBlock < PeopleBlockBase |
20 | 20 | owner.suggested_profiles.of_person.enabled.limit(3).includes(:suggestion) |
21 | 21 | end |
22 | 22 | |
23 | - def footer | |
24 | - profile = self.owner | |
25 | - suggestions = self.suggestions | |
26 | - proc do | |
27 | - render :file => 'blocks/friends', :locals => { :profile => profile, :suggestions => suggestions } | |
28 | - end | |
29 | - end | |
30 | - | |
31 | 23 | def self.expire_on |
32 | 24 | { :profile => [:profile] } |
33 | 25 | end | ... | ... |
plugins/people_block/lib/members_block.rb
... | ... | @@ -20,15 +20,6 @@ class MembersBlock < PeopleBlockBase |
20 | 20 | role ? owner.members.with_role(role.id) : owner.members |
21 | 21 | end |
22 | 22 | |
23 | - def footer | |
24 | - profile = self.owner | |
25 | - role_key = visible_role | |
26 | - s = show_join_leave_button | |
27 | - proc do | |
28 | - render :file => 'blocks/members', :locals => { :profile => profile, :show_join_leave_button => s, :role_key => role_key} | |
29 | - end | |
30 | - end | |
31 | - | |
32 | 23 | def role |
33 | 24 | visible_role && !visible_role.empty? ? Role.find_by_key_and_environment_id(visible_role, owner.environment) : nil |
34 | 25 | end | ... | ... |
plugins/people_block/lib/people_block.rb
plugins/people_block/lib/people_block_base.rb
... | ... | @@ -42,57 +42,6 @@ class PeopleBlockBase < Block |
42 | 42 | profiles.visible.count |
43 | 43 | end |
44 | 44 | |
45 | - def content(args={}) | |
46 | - profiles = self.profile_list | |
47 | - title = self.view_title | |
48 | - | |
49 | - if !self.name.blank? && !self.address.blank? | |
50 | - name = self.name | |
51 | - expanded_address = expand_address(self.address) | |
52 | - end | |
53 | - | |
54 | - proc do | |
55 | - count = 0 | |
56 | - list = profiles.map {|item| | |
57 | - count += 1 | |
58 | - send(:profile_image_link, item, :minor ) | |
59 | - }.join("\n") | |
60 | - if list.empty? | |
61 | - list = content_tag 'div', c_('None'), :class => 'common-profile-list-block-none' | |
62 | - else | |
63 | - if !name.blank? && !expanded_address.blank? | |
64 | - list << content_tag( | |
65 | - 'div', | |
66 | - content_tag( | |
67 | - 'li', | |
68 | - content_tag( | |
69 | - 'div', | |
70 | - link_to( | |
71 | - content_tag('span', name, :class => 'banner-span' ), | |
72 | - expanded_address, | |
73 | - :title => name | |
74 | - ), | |
75 | - :class => 'banner-div' | |
76 | - ), | |
77 | - :class => 'vcard' | |
78 | - ), | |
79 | - :class => 'common-profile-list-block' | |
80 | - ) | |
81 | - end | |
82 | - list = content_tag 'ul', list | |
83 | - end | |
84 | - block_title(title) + content_tag('div', list + tag('br', :style => 'clear:both')) | |
85 | - end | |
86 | - end | |
87 | - | |
88 | - def expand_address(address) | |
89 | - if address !~ /^[a-z]+:\/\// && address !~ /^\// | |
90 | - 'http://' + address | |
91 | - else | |
92 | - address | |
93 | - end | |
94 | - end | |
95 | - | |
96 | 45 | def extra_option |
97 | 46 | { } |
98 | 47 | end | ... | ... |
... | ... | @@ -0,0 +1,9 @@ |
1 | +module PeopleBlockHelper | |
2 | + def profiles_images_list(profiles) | |
3 | + profiles.map { |profile| profile_image_link(profile, :minor) }.join("\n") | |
4 | + end | |
5 | + | |
6 | + def set_address_protocol(address) | |
7 | + !URI.parse(address).scheme ? 'http://'+address : address | |
8 | + end | |
9 | +end | ... | ... |
plugins/people_block/test/unit/friends_block_test.rb
... | ... | @@ -60,39 +60,6 @@ class FriendsBlockTest < ActionView::TestCase |
60 | 60 | assert_equal 20, block.limit |
61 | 61 | end |
62 | 62 | |
63 | - should 'list friends from person' do | |
64 | - owner = fast_create(Person) | |
65 | - friend1 = fast_create(Person) | |
66 | - friend2 = fast_create(Person) | |
67 | - owner.add_friend(friend1) | |
68 | - owner.add_friend(friend2) | |
69 | - | |
70 | - block = FriendsBlock.new | |
71 | - | |
72 | - block.expects(:owner).returns(owner).at_least_once | |
73 | - expects(:profile_image_link).with(friend1, :minor).returns(friend1.name) | |
74 | - expects(:profile_image_link).with(friend2, :minor).returns(friend2.name) | |
75 | - expects(:block_title).with(anything).returns('') | |
76 | - | |
77 | - content = instance_eval(&block.content) | |
78 | - | |
79 | - assert_match(/#{friend1.name}/, content) | |
80 | - assert_match(/#{friend2.name}/, content) | |
81 | - end | |
82 | - | |
83 | - should 'link to "all friends"' do | |
84 | - person1 = create_user('mytestperson').person | |
85 | - | |
86 | - block = FriendsBlock.new | |
87 | - block.stubs(:suggestions).returns([]) | |
88 | - block.expects(:owner).returns(person1).at_least_once | |
89 | - | |
90 | - instance_eval(&block.footer) | |
91 | - assert_select 'a.view-all' do |elements| | |
92 | - assert_select '[href=/profile/mytestperson/friends]' | |
93 | - end | |
94 | - end | |
95 | - | |
96 | 63 | should 'count number of owner friends' do |
97 | 64 | owner = fast_create(Person) |
98 | 65 | friend1 = fast_create(Person) |
... | ... | @@ -151,3 +118,39 @@ class FriendsBlockTest < ActionView::TestCase |
151 | 118 | include NoosferoTestHelper |
152 | 119 | |
153 | 120 | end |
121 | + | |
122 | +require 'boxes_helper' | |
123 | + | |
124 | +class FriendsBlockViewTest < ActionView::TestCase | |
125 | + include BoxesHelper | |
126 | + | |
127 | + should 'list friends from person' do | |
128 | + owner = fast_create(Person) | |
129 | + friend1 = fast_create(Person) | |
130 | + friend2 = fast_create(Person) | |
131 | + owner.add_friend(friend1) | |
132 | + owner.add_friend(friend2) | |
133 | + | |
134 | + block = FriendsBlock.new | |
135 | + | |
136 | + block.expects(:owner).returns(owner).at_least_once | |
137 | + ActionView::Base.any_instance.expects(:profile_image_link).with(friend1, :minor).returns(friend1.name) | |
138 | + ActionView::Base.any_instance.expects(:profile_image_link).with(friend2, :minor).returns(friend2.name) | |
139 | + ActionView::Base.any_instance.expects(:block_title).with(anything).returns('') | |
140 | + | |
141 | + content = render_block_content(block) | |
142 | + | |
143 | + assert_match(/#{friend1.name}/, content) | |
144 | + assert_match(/#{friend2.name}/, content) | |
145 | + end | |
146 | + | |
147 | + should 'link to "all friends"' do | |
148 | + person1 = create_user('mytestperson').person | |
149 | + | |
150 | + block = FriendsBlock.new | |
151 | + block.stubs(:suggestions).returns([]) | |
152 | + block.expects(:owner).returns(person1).at_least_once | |
153 | + | |
154 | + assert_tag_in_string render_block_footer(block), tag: 'a', attributes: {class: 'view-all', href: '/profile/mytestperson/friends' } | |
155 | + end | |
156 | +end | ... | ... |
plugins/people_block/test/unit/members_block_test.rb
... | ... | @@ -90,26 +90,6 @@ class MembersBlockTest < ActionView::TestCase |
90 | 90 | end |
91 | 91 | |
92 | 92 | |
93 | - should 'list members from community' do | |
94 | - owner = fast_create(Community) | |
95 | - person1 = fast_create(Person) | |
96 | - person2 = fast_create(Person) | |
97 | - owner.add_member(person1) | |
98 | - owner.add_member(person2) | |
99 | - | |
100 | - block = MembersBlock.new | |
101 | - | |
102 | - block.expects(:owner).returns(owner).at_least_once | |
103 | - expects(:profile_image_link).with(person1, :minor).returns(person1.name) | |
104 | - expects(:profile_image_link).with(person2, :minor).returns(person2.name) | |
105 | - expects(:block_title).with(anything).returns('') | |
106 | - | |
107 | - content = instance_eval(&block.content) | |
108 | - | |
109 | - assert_match(/#{person1.name}/, content) | |
110 | - assert_match(/#{person2.name}/, content) | |
111 | - end | |
112 | - | |
113 | 93 | should 'count number of public and private members' do |
114 | 94 | owner = fast_create(Community) |
115 | 95 | private_p = fast_create(Person, {:public_profile => false}) |
... | ... | @@ -139,57 +119,6 @@ class MembersBlockTest < ActionView::TestCase |
139 | 119 | assert_equal 1, block.profile_count |
140 | 120 | end |
141 | 121 | |
142 | - should 'provide link to members page without a visible_role selected' do | |
143 | - profile = create_user('mytestuser').person | |
144 | - block = MembersBlock.new | |
145 | - block.box = profile.boxes.first | |
146 | - block.save! | |
147 | - | |
148 | - instance_eval(&block.footer) | |
149 | - assert_select 'a.view-all' do |elements| | |
150 | - assert_select "[href=/profile/mytestuser/members#members-tab]" | |
151 | - end | |
152 | - end | |
153 | - | |
154 | - should 'provide link to members page when visible_role is profile_member' do | |
155 | - profile = create_user('mytestuser').person | |
156 | - block = MembersBlock.new | |
157 | - block.box = profile.boxes.first | |
158 | - block.visible_role = 'profile_member' | |
159 | - block.save! | |
160 | - | |
161 | - instance_eval(&block.footer) | |
162 | - assert_select 'a.view-all' do |elements| | |
163 | - assert_select '[href=/profile/mytestuser/members#members-tab]' | |
164 | - end | |
165 | - end | |
166 | - | |
167 | - should 'provide link to members page when visible_role is profile_moderator' do | |
168 | - profile = create_user('mytestuser').person | |
169 | - block = MembersBlock.new | |
170 | - block.box = profile.boxes.first | |
171 | - block.visible_role = 'profile_moderator' | |
172 | - block.save! | |
173 | - | |
174 | - instance_eval(&block.footer) | |
175 | - assert_select 'a.view-all' do |elements| | |
176 | - assert_select '[href=/profile/mytestuser/members#members-tab]' | |
177 | - end | |
178 | - end | |
179 | - | |
180 | - should 'provide link to admins page when visible_role is profile_admin' do | |
181 | - profile = create_user('mytestuser').person | |
182 | - block = MembersBlock.new | |
183 | - block.box = profile.boxes.first | |
184 | - block.visible_role = 'profile_admin' | |
185 | - block.save! | |
186 | - | |
187 | - instance_eval(&block.footer) | |
188 | - assert_select 'a.view-all' do |elements| | |
189 | - assert_select '[href=/profile/mytestuser/members#admins-tab]' | |
190 | - end | |
191 | - end | |
192 | - | |
193 | 122 | should 'provide a role to be displayed (and default to nil)' do |
194 | 123 | env = fast_create(Environment) |
195 | 124 | env.boxes << Box.new |
... | ... | @@ -299,3 +228,82 @@ class MembersBlockTest < ActionView::TestCase |
299 | 228 | include NoosferoTestHelper |
300 | 229 | |
301 | 230 | end |
231 | + | |
232 | +require 'boxes_helper' | |
233 | + | |
234 | +class MembersBlockViewTest < ActionView::TestCase | |
235 | + include BoxesHelper | |
236 | + | |
237 | + should 'list members from community' do | |
238 | + owner = fast_create(Community) | |
239 | + person1 = fast_create(Person) | |
240 | + person2 = fast_create(Person) | |
241 | + owner.add_member(person1) | |
242 | + owner.add_member(person2) | |
243 | + profile = Profile.new | |
244 | + profile.identifier = 42 | |
245 | + | |
246 | + block = MembersBlock.new | |
247 | + | |
248 | + block.expects(:owner).returns(owner).at_least_once | |
249 | + ActionView::Base.any_instance.expects(:profile_image_link).with(person1, :minor).returns(person1.name) | |
250 | + ActionView::Base.any_instance.expects(:profile_image_link).with(person2, :minor).returns(person2.name) | |
251 | + ActionView::Base.any_instance.expects(:block_title).with(anything).returns('') | |
252 | + | |
253 | + content = render_block_content(block) | |
254 | + | |
255 | + assert_match(/#{person1.name}/, content) | |
256 | + assert_match(/#{person2.name}/, content) | |
257 | + end | |
258 | + | |
259 | + should 'provide link to members page without a visible_role selected' do | |
260 | + profile = create_user('mytestuser').person | |
261 | + block = MembersBlock.new | |
262 | + block.box = profile.boxes.first | |
263 | + block.save! | |
264 | + | |
265 | + render_block_footer(block) | |
266 | + assert_select 'a.view-all' do |elements| | |
267 | + assert_select "[href=/profile/mytestuser/members#members-tab]" | |
268 | + end | |
269 | + end | |
270 | + | |
271 | + should 'provide link to members page when visible_role is profile_member' do | |
272 | + profile = create_user('mytestuser').person | |
273 | + block = MembersBlock.new | |
274 | + block.box = profile.boxes.first | |
275 | + block.visible_role = 'profile_member' | |
276 | + block.save! | |
277 | + | |
278 | + render_block_footer(block) | |
279 | + assert_select 'a.view-all' do |elements| | |
280 | + assert_select '[href=/profile/mytestuser/members#members-tab]' | |
281 | + end | |
282 | + end | |
283 | + | |
284 | + should 'provide link to members page when visible_role is profile_moderator' do | |
285 | + profile = create_user('mytestuser').person | |
286 | + block = MembersBlock.new | |
287 | + block.box = profile.boxes.first | |
288 | + block.visible_role = 'profile_moderator' | |
289 | + block.save! | |
290 | + | |
291 | + render_block_footer(block) | |
292 | + assert_select 'a.view-all' do |elements| | |
293 | + assert_select '[href=/profile/mytestuser/members#members-tab]' | |
294 | + end | |
295 | + end | |
296 | + | |
297 | + should 'provide link to admins page when visible_role is profile_admin' do | |
298 | + profile = create_user('mytestuser').person | |
299 | + block = MembersBlock.new | |
300 | + block.box = profile.boxes.first | |
301 | + block.visible_role = 'profile_admin' | |
302 | + block.save! | |
303 | + | |
304 | + render_block_footer(block) | |
305 | + assert_select 'a.view-all' do |elements| | |
306 | + assert_select '[href=/profile/mytestuser/members#admins-tab]' | |
307 | + end | |
308 | + end | |
309 | +end | ... | ... |
plugins/people_block/test/unit/people_block_helper_test.rb
0 → 100644
... | ... | @@ -0,0 +1,37 @@ |
1 | +require 'test_helper' | |
2 | + | |
3 | +class PeopleBlockHelperTest < ActionView::TestCase | |
4 | + include PeopleBlockHelper | |
5 | + | |
6 | + should 'list profiles as images links' do | |
7 | + owner = fast_create(Environment) | |
8 | + profiles = [ | |
9 | + fast_create(Person, :environment_id => owner.id), | |
10 | + fast_create(Person, :environment_id => owner.id), | |
11 | + fast_create(Person, :environment_id => owner.id) | |
12 | + ] | |
13 | + link_html = "<a href=#><img src='' /></a>" | |
14 | + | |
15 | + profiles.each do |profile| | |
16 | + expects(:profile_image_link).with(profile, :minor).returns(link_html) | |
17 | + end | |
18 | + | |
19 | + list = profiles_images_list(profiles) | |
20 | + | |
21 | + assert_equal list, ([link_html]*profiles.count).join("\n") | |
22 | + end | |
23 | + | |
24 | + should 'prepend the protocol to urls missing it' do | |
25 | + address = 'noosfero.org' | |
26 | + | |
27 | + assert_equal set_address_protocol(address), 'http://'+address | |
28 | + end | |
29 | + | |
30 | + should 'leave urls already with protocol unchanged' do | |
31 | + address = 'http://noosfero.org' | |
32 | + ssl_address = 'https://noosfero.org' | |
33 | + | |
34 | + assert_equal set_address_protocol(address), address | |
35 | + assert_equal set_address_protocol(ssl_address), ssl_address | |
36 | + end | |
37 | +end | |
0 | 38 | \ No newline at end of file | ... | ... |
plugins/people_block/test/unit/people_block_test.rb
... | ... | @@ -85,36 +85,6 @@ class PeopleBlockTest < ActionView::TestCase |
85 | 85 | end |
86 | 86 | |
87 | 87 | |
88 | - should 'list people from environment' do | |
89 | - owner = fast_create(Environment) | |
90 | - person1 = fast_create(Person, :environment_id => owner.id) | |
91 | - person2 = fast_create(Person, :environment_id => owner.id) | |
92 | - | |
93 | - block = PeopleBlock.new | |
94 | - | |
95 | - block.expects(:owner).returns(owner).at_least_once | |
96 | - expects(:profile_image_link).with(person1, :minor).returns(person1.name) | |
97 | - expects(:profile_image_link).with(person2, :minor).returns(person2.name) | |
98 | - expects(:block_title).with(anything).returns('') | |
99 | - | |
100 | - content = instance_exec(&block.content) | |
101 | - | |
102 | - assert_match(/#{person1.name}/, content) | |
103 | - assert_match(/#{person2.name}/, content) | |
104 | - end | |
105 | - | |
106 | - | |
107 | - should 'link to "all people"' do | |
108 | - env = fast_create(Environment) | |
109 | - block = PeopleBlock.new | |
110 | - | |
111 | - instance_eval(&block.footer) | |
112 | - assert_select 'a.view-all' do |elements| | |
113 | - assert_select '[href=/search/people]' | |
114 | - end | |
115 | - end | |
116 | - | |
117 | - | |
118 | 88 | should 'count number of public and private people' do |
119 | 89 | owner = fast_create(Environment) |
120 | 90 | private_p = fast_create(Person, :public_profile => false, :environment_id => owner.id) |
... | ... | @@ -142,3 +112,37 @@ class PeopleBlockTest < ActionView::TestCase |
142 | 112 | include NoosferoTestHelper |
143 | 113 | |
144 | 114 | end |
115 | + | |
116 | +require 'boxes_helper' | |
117 | + | |
118 | +class PeopleBlockViewTest < ActionView::TestCase | |
119 | + include BoxesHelper | |
120 | + | |
121 | + should 'list people from environment' do | |
122 | + owner = fast_create(Environment) | |
123 | + person1 = fast_create(Person, :environment_id => owner.id) | |
124 | + person2 = fast_create(Person, :environment_id => owner.id) | |
125 | + | |
126 | + block = PeopleBlock.new | |
127 | + | |
128 | + block.expects(:owner).returns(owner).at_least_once | |
129 | + ActionView::Base.any_instance.expects(:profile_image_link).with(person1, :minor).returns(person1.name) | |
130 | + ActionView::Base.any_instance.expects(:profile_image_link).with(person2, :minor).returns(person2.name) | |
131 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
132 | + | |
133 | + content = render_block_content(block) | |
134 | + | |
135 | + assert_match(/#{person1.name}/, content) | |
136 | + assert_match(/#{person2.name}/, content) | |
137 | + end | |
138 | + | |
139 | + should 'link to "all people"' do | |
140 | + env = fast_create(Environment) | |
141 | + block = PeopleBlock.new | |
142 | + | |
143 | + render_block_footer(block) | |
144 | + assert_select 'a.view-all' do |elements| | |
145 | + assert_select '[href=/search/people]' | |
146 | + end | |
147 | + end | |
148 | +end | ... | ... |
plugins/people_block/views/blocks/footers/friends.html.erb
0 → 100644
... | ... | @@ -0,0 +1,13 @@ |
1 | +<%= link_to s_('friends|View all'), {:profile => block.owner.identifier, :controller => 'profile', :action => 'friends'}, :class => 'view-all' %> | |
2 | + | |
3 | +<% if !block.suggestions.empty? && user == block.owner %> | |
4 | + <div class='suggestions-block common-profile-list-block'> | |
5 | + <h4 class='block-subtitle'><%= _('Some suggestions for you') %></h4> | |
6 | + <div class='profiles-suggestions'> | |
7 | + <%= render :partial => 'shared/profile_suggestions_list', :locals => { :suggestions => block.suggestions, :collection => :friends_suggestions } %> | |
8 | + </div> | |
9 | + <div class='more-suggestions'> | |
10 | + <%= link_to _('See all suggestions'), block.owner.people_suggestions_url %> | |
11 | + </div> | |
12 | + </div> | |
13 | +<% end %> | ... | ... |
plugins/people_block/views/blocks/footers/members.html.erb
0 → 100644
... | ... | @@ -0,0 +1,6 @@ |
1 | +<% anchor = block.visible_role == "profile_admin" ? "admins-tab" : "members-tab" %> | |
2 | +<%= link_to c_('View all'), {:profile => block.owner.identifier, :controller => 'profile', :action => 'members', :anchor =>anchor }, :class => 'view-all' %> | |
3 | + | |
4 | +<% if block.show_join_leave_button %> | |
5 | + <%= render :partial => 'blocks/profile_info_actions/join_leave_community' %> | |
6 | +<% end %> | ... | ... |
plugins/people_block/views/blocks/footers/people.html.erb
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +<%= link_to c_('View all'), {:controller => 'search', :action => 'people'}, :class => 'view-all' %> | ... | ... |
plugins/people_block/views/blocks/friends.html.erb
... | ... | @@ -1,13 +0,0 @@ |
1 | -<%= link_to s_('friends|View all'), {:profile => profile.identifier, :controller => 'profile', :action => 'friends'}, :class => 'view-all' %> | |
2 | - | |
3 | -<% if !suggestions.empty? && user == profile %> | |
4 | - <div class='suggestions-block common-profile-list-block'> | |
5 | - <h4 class='block-subtitle'><%= _('Some suggestions for you') %></h4> | |
6 | - <div class='profiles-suggestions'> | |
7 | - <%= render :partial => 'shared/profile_suggestions_list', :locals => { :suggestions => suggestions, :collection => :friends_suggestions } %> | |
8 | - </div> | |
9 | - <div class='more-suggestions'> | |
10 | - <%= link_to _('See all suggestions'), profile.people_suggestions_url %> | |
11 | - </div> | |
12 | - </div> | |
13 | -<% end %> |
plugins/people_block/views/blocks/members.html.erb
... | ... | @@ -1,6 +0,0 @@ |
1 | -<% anchor = role_key == "profile_admin" ? "admins-tab" : "members-tab" %> | |
2 | -<%= link_to c_('View all'), {:profile => profile.identifier, :controller => 'profile', :action => 'members', :anchor =>anchor }, :class => 'view-all' %> | |
3 | - | |
4 | -<% if show_join_leave_button %> | |
5 | - <%= render :partial => 'blocks/profile_info_actions/join_leave_community' %> | |
6 | -<% end %> |
plugins/people_block/views/blocks/people.html.erb
... | ... | @@ -1 +0,0 @@ |
1 | -<%= link_to c_('View all'), {:controller => 'search', :action => 'people'}, :class => 'view-all' %> |
... | ... | @@ -0,0 +1,28 @@ |
1 | +<% extend PeopleBlockHelper %> | |
2 | + | |
3 | +<%= block_title(block.view_title) %> | |
4 | + | |
5 | +<div> | |
6 | + <% unless block.profiles.count == 0 %> | |
7 | + <ul> | |
8 | + <%= profiles_images_list(block.profiles) %> | |
9 | + | |
10 | + <% unless block.name.blank? || block.address.blank? %> | |
11 | + <div class="common-profile-list-block"> | |
12 | + <li class="vcard"> | |
13 | + <div class="banner-div"> | |
14 | + <%= link_to( | |
15 | + content_tag('span', block.name, :class => 'banner-span' ), | |
16 | + set_address_protocol(block.address), | |
17 | + title: block.name | |
18 | + ) %> | |
19 | + </div> | |
20 | + </li> | |
21 | + </div> | |
22 | + <% end %> | |
23 | + </ul> | |
24 | + <% else %> | |
25 | + <div class="common-profile-list-block-none"><%= c_('None') %></div> | |
26 | + <% end %> | |
27 | + <br style="clear:both" /> | |
28 | +</div> | ... | ... |
plugins/serpro_captcha
plugins/shopping_cart/po/pt/shopping_cart.po
... | ... | @@ -13,16 +13,16 @@ msgid "" |
13 | 13 | msgstr "" |
14 | 14 | "Project-Id-Version: 1.3~rc2-1-ga15645d\n" |
15 | 15 | "POT-Creation-Date: 2015-10-30 16:34-0300\n" |
16 | -"PO-Revision-Date: 2015-11-15 18:17-0300\n" | |
17 | -"Last-Translator: Michal Čihař <michal@cihar.com>\n" | |
18 | -"Language-Team: Portuguese <https://hosted.weblate.org/projects/noosfero/" | |
19 | -"plugin-shopping-cart/pt/>\n" | |
16 | +"PO-Revision-Date: 2016-03-14 15:52+0000\n" | |
17 | +"Last-Translator: Eduardo Vital <vitaldu@gmail.com>\n" | |
18 | +"Language-Team: Portuguese <https://hosted.weblate.org/projects/noosfero" | |
19 | +"/plugin-shopping-cart/pt/>\n" | |
20 | 20 | "Language: pt\n" |
21 | 21 | "MIME-Version: 1.0\n" |
22 | 22 | "Content-Type: text/plain; charset=UTF-8\n" |
23 | 23 | "Content-Transfer-Encoding: 8bit\n" |
24 | 24 | "Plural-Forms: nplurals=2; plural=n != 1;\n" |
25 | -"X-Generator: Weblate 2.3-dev\n" | |
25 | +"X-Generator: Weblate 2.5\n" | |
26 | 26 | |
27 | 27 | #: plugins/shopping_cart/lib/shopping_cart_plugin.rb:10 |
28 | 28 | msgid "A shopping basket feature for enterprises" |
... | ... | @@ -304,7 +304,7 @@ msgstr "Nome" |
304 | 304 | |
305 | 305 | #: plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb:16 |
306 | 306 | msgid "Email" |
307 | -msgstr "" | |
307 | +msgstr "E-mail" | |
308 | 308 | |
309 | 309 | #: plugins/shopping_cart/views/shopping_cart_plugin/buy.html.erb:17 |
310 | 310 | msgid "Contact phone" | ... | ... |
plugins/sniffer/controllers/sniffer_plugin_myprofile_controller.rb
1 | 1 | class SnifferPluginMyprofileController < MyProfileController |
2 | 2 | |
3 | - before_filter :fetch_sniffer_profile, :only => [:edit, :search] | |
4 | - | |
5 | 3 | include SnifferPlugin::Helper |
6 | 4 | helper SnifferPlugin::Helper |
7 | 5 | helper CmsHelper |
8 | 6 | |
9 | 7 | def edit |
10 | 8 | if request.post? |
11 | - begin | |
12 | - @sniffer_profile.update(params[:sniffer_plugin_profile]) | |
13 | - @sniffer_profile.enabled = true | |
14 | - @sniffer_profile.save! | |
9 | + if @profile.update params[:profile_data] | |
15 | 10 | session[:notice] = _('Consumer interests updated') |
16 | - rescue Exception => exception | |
17 | - flash[:error] = _('Could not save consumer interests') | |
18 | 11 | end |
19 | 12 | end |
20 | 13 | end |
... | ... | @@ -22,22 +15,21 @@ class SnifferPluginMyprofileController < MyProfileController |
22 | 15 | def product_category_search |
23 | 16 | query = params[:q] || params[:term] |
24 | 17 | |
25 | - scope = ProductCategory.by_environment(environment) | |
26 | - @categories = find_by_contents(:product_categories, @profile, scope, query, {:per_page => 10, :page => 1})[:results] | |
18 | + @categories = find_by_contents(:categories, @profile, environment.product_categories, query, {per_page: 10, page: 1})[:results] | |
27 | 19 | |
28 | 20 | autocomplete = params.has_key?(:term) |
29 | - render :json => @categories.map { |i| autocomplete ? {:value => i.id, :label => i.name} : {:id => i.id, :name => i.name} } | |
21 | + render json: @categories.map { |i| autocomplete ? {value: i.id, label: i.name} : {id: i.id, name: i.name} } | |
30 | 22 | end |
31 | 23 | |
32 | 24 | def product_category_add |
33 | 25 | product_category = environment.categories.find params[:id] |
34 | - response = { :productCategory => { | |
26 | + response = { productCategory: { | |
35 | 27 | :id => product_category.id |
36 | 28 | } |
37 | 29 | } |
38 | 30 | response[:enterprises] = product_category.sniffer_plugin_enterprises.enabled.visible.map do |enterprise| |
39 | 31 | profile_data = filter_visible_attr_profile(enterprise) |
40 | - profile_data[:balloonUrl] = url_for :controller => :sniffer_plugin_myprofile, :action => :map_balloon, :id => enterprise[:id], :escape => false | |
32 | + profile_data[:balloonUrl] = url_for controller: :sniffer_plugin_myprofile, action: :map_balloon, id: enterprise[:id], escape: false | |
41 | 33 | profile_data[:sniffer_plugin_distance] = Noosfero::GeoRef.dist(@profile.lat, @profile.lng, enterprise.lat, enterprise.lng) |
42 | 34 | profile_data[:suppliersProducts] = filter_visible_attr_suppliers_products( |
43 | 35 | enterprise.products.sniffer_plugin_products_from_category(product_category) |
... | ... | @@ -45,14 +37,14 @@ class SnifferPluginMyprofileController < MyProfileController |
45 | 37 | profile_data[:consumersProducts] = [] |
46 | 38 | profile_data |
47 | 39 | end |
48 | - render :text => response.to_json | |
40 | + render text: response.to_json | |
49 | 41 | end |
50 | 42 | |
51 | 43 | def search |
52 | 44 | @no_design_blocks = true |
53 | 45 | |
54 | - suppliers_products = @sniffer_profile.suppliers_products | |
55 | - consumers_products = @sniffer_profile.consumers_products | |
46 | + suppliers_products = @profile.sniffer_suppliers_products | |
47 | + consumers_products = @profile.sniffer_consumers_products | |
56 | 48 | |
57 | 49 | profiles_of_interest = fetch_profiles(suppliers_products + consumers_products) |
58 | 50 | |
... | ... | @@ -67,13 +59,13 @@ class SnifferPluginMyprofileController < MyProfileController |
67 | 59 | @profiles_data = {} |
68 | 60 | suppliers.each do |id, products| |
69 | 61 | @profiles_data[id] = { |
70 | - :profile => profiles_of_interest[id], | |
71 | - :suppliers_products => products, | |
72 | - :consumers_products => [] | |
62 | + profile: profiles_of_interest[id], | |
63 | + suppliers_products: products, | |
64 | + consumers_products: [] | |
73 | 65 | } |
74 | 66 | end |
75 | 67 | consumers.each do |id, products| |
76 | - @profiles_data[id] ||= { :profile => profiles_of_interest[id] } | |
68 | + @profiles_data[id] ||= { profile: profiles_of_interest[id] } | |
77 | 69 | @profiles_data[id][:suppliers_products] ||= [] |
78 | 70 | @profiles_data[id][:consumers_products] = products |
79 | 71 | end |
... | ... | @@ -91,22 +83,18 @@ class SnifferPluginMyprofileController < MyProfileController |
91 | 83 | @suppliers = build_products(suppliers_products).values.first |
92 | 84 | @consumers = build_products(consumers_products).values.first |
93 | 85 | |
94 | - render :layout => false | |
86 | + render layout: false | |
95 | 87 | end |
96 | 88 | |
97 | 89 | def my_map_balloon |
98 | 90 | @categories = @profile.categories |
99 | - render :layout => false | |
91 | + render layout: false | |
100 | 92 | end |
101 | 93 | |
102 | 94 | protected |
103 | 95 | |
104 | - def fetch_sniffer_profile | |
105 | - @sniffer_profile = SnifferPlugin::Profile.find_or_create profile | |
106 | - end | |
107 | - | |
108 | 96 | def fetch_profiles(products) |
109 | - profiles = Profile.all :conditions => {:id => products.map { |p| target_profile_id(p) }} | |
97 | + profiles = Profile.all conditions: {id: products.map { |p| target_profile_id(p) }} | |
110 | 98 | profiles_by_id = {} |
111 | 99 | profiles.each do |p| |
112 | 100 | p.sniffer_plugin_distance = Noosfero::GeoRef.dist(@profile.lat, @profile.lng, p.lat, p.lng) |
... | ... | @@ -125,9 +113,9 @@ class SnifferPluginMyprofileController < MyProfileController |
125 | 113 | |
126 | 114 | id_profiles = fetch_profiles(data) |
127 | 115 | |
128 | - products = Product.all :conditions => {:id => grab_id.call('id')}, :include => [:enterprise, :product_category] | |
116 | + products = Product.all conditions: {id: grab_id.call('id')}, include: [:enterprise, :product_category] | |
129 | 117 | products.each{ |p| id_products[p.id] ||= p } |
130 | - knowledges = Article.all :conditions => {:id => grab_id.call('knowledge_id')} | |
118 | + knowledges = Article.all conditions: {id: grab_id.call('knowledge_id')} | |
131 | 119 | knowledges.each{ |k| id_knowledges[k.id] ||= k} |
132 | 120 | |
133 | 121 | data.each do |attributes| |
... | ... | @@ -135,9 +123,9 @@ class SnifferPluginMyprofileController < MyProfileController |
135 | 123 | |
136 | 124 | results[profile.id] ||= [] |
137 | 125 | results[profile.id] << { |
138 | - :partial => attributes['view'], | |
139 | - :product => id_products[attributes['id'].to_i], | |
140 | - :knowledge => id_knowledges[attributes['knowledge_id'].to_i] | |
126 | + partial: attributes['view'], | |
127 | + product: id_products[attributes['id'].to_i], | |
128 | + knowledge: id_knowledges[attributes['knowledge_id'].to_i] | |
141 | 129 | } |
142 | 130 | end |
143 | 131 | results | ... | ... |
plugins/sniffer/db/migrate/20131212124106_drop_sniffer_profile_table.rb
0 → 100644
... | ... | @@ -0,0 +1,25 @@ |
1 | +SnifferPlugin.send :remove_const, :Opportunity if defined? SnifferPlugin::Opportunity | |
2 | + | |
3 | +class SnifferPlugin::Profile < ActiveRecord::Base | |
4 | + belongs_to :profile | |
5 | +end | |
6 | +class SnifferPlugin::Opportunity < ActiveRecord::Base | |
7 | + belongs_to :sniffer_profile, class_name: 'SnifferPlugin::Profile', foreign_key: :profile_id | |
8 | +end | |
9 | + | |
10 | +class DropSnifferProfileTable < ActiveRecord::Migration | |
11 | + def self.up | |
12 | + SnifferPlugin::Opportunity.find_each do |opportunity| | |
13 | + sniffer_profile = opportunity.sniffer_profile | |
14 | + next unless sniffer_profile.profile | |
15 | + | |
16 | + opportunity.profile_id = sniffer_profile.profile.id | |
17 | + opportunity.save! | |
18 | + end | |
19 | + | |
20 | + drop_table :sniffer_plugin_profiles | |
21 | + end | |
22 | + | |
23 | + def self.down | |
24 | + end | |
25 | +end | ... | ... |
plugins/sniffer/lib/ext/article.rb
... | ... | @@ -5,16 +5,16 @@ class Article |
5 | 5 | # search for interests of interested that matches the knowledges of wise |
6 | 6 | scope :sniffer_plugin_knowledges_interests, lambda { |wise, interested| |
7 | 7 | { |
8 | - :select => "op.opportunity_id AS interest_cat, | |
8 | + select: "op.opportunity_id AS interest_cat, | |
9 | 9 | articles.name AS knowledge_name, articles.id AS id, |
10 | 10 | article_resources.resource_id AS knowledge_cat", |
11 | - :joins => "INNER JOIN article_resources ON (articles.id = article_resources.article_id) | |
11 | + joins: "INNER JOIN article_resources ON (articles.id = article_resources.article_id) | |
12 | 12 | INNER JOIN sniffer_plugin_opportunities AS op ON (article_resources.resource_id = op.opportunity_id |
13 | 13 | AND article_resources.resource_type = 'ProductCategory' AND op.opportunity_type = 'ProductCategory') |
14 | - INNER JOIN sniffer_plugin_profiles sniffer ON (op.profile_id = sniffer.id AND sniffer.enabled = true)", | |
15 | - :conditions => "articles.type = 'CmsLearningPlugin::Learning' | |
14 | + INNER JOIN profiles sniffer ON op.profile_id = sniffer.id", | |
15 | + conditions: "articles.type = 'CmsLearningPlugin::Learning' | |
16 | 16 | AND articles.profile_id = #{wise.id} |
17 | - AND sniffer.profile_id = #{interested.id}" | |
17 | + AND sniffer.id = #{interested.id}" | |
18 | 18 | } |
19 | 19 | } |
20 | 20 | end | ... | ... |
plugins/sniffer/lib/ext/product.rb
... | ... | @@ -13,13 +13,13 @@ class Product |
13 | 13 | # -> Enterprise 1 as a parameter to this scope would return product B |
14 | 14 | scope :sniffer_plugin_suppliers_products, lambda { |enterprise| |
15 | 15 | { |
16 | - :select => "DISTINCT products_2.*, | |
16 | + select: "DISTINCT products_2.*, | |
17 | 17 | 'product' as view", |
18 | - :joins => "INNER JOIN inputs ON ( products.id = inputs.product_id ) | |
18 | + joins: "INNER JOIN inputs ON ( products.id = inputs.product_id ) | |
19 | 19 | INNER JOIN categories ON ( inputs.product_category_id = categories.id ) |
20 | 20 | INNER JOIN products products_2 ON ( categories.id = products_2.product_category_id ) |
21 | 21 | INNER JOIN profiles ON ( profiles.id = products_2.profile_id )", |
22 | - :conditions => "products.profile_id = #{enterprise.id} | |
22 | + conditions: "products.profile_id = #{enterprise.id} | |
23 | 23 | AND profiles.public_profile = true AND profiles.visible = true |
24 | 24 | AND profiles.enabled = true |
25 | 25 | AND profiles.id <> #{enterprise.id}" |
... | ... | @@ -36,14 +36,14 @@ class Product |
36 | 36 | # with an extra column `consumer_profile_id` equal to Enterprise 2 id |
37 | 37 | scope :sniffer_plugin_consumers_products, lambda { |enterprise| |
38 | 38 | { |
39 | - :select => "DISTINCT products_2.*, | |
39 | + select: "DISTINCT products_2.*, | |
40 | 40 | profiles.id as consumer_profile_id, |
41 | 41 | 'product' as view", |
42 | - :joins => "INNER JOIN inputs ON ( products.id = inputs.product_id ) | |
42 | + joins: "INNER JOIN inputs ON ( products.id = inputs.product_id ) | |
43 | 43 | INNER JOIN categories ON ( inputs.product_category_id = categories.id ) |
44 | 44 | INNER JOIN products products_2 ON ( categories.id = products_2.product_category_id ) |
45 | 45 | INNER JOIN profiles ON ( profiles.id = products.profile_id )", |
46 | - :conditions => "products_2.profile_id = #{enterprise.id} | |
46 | + conditions: "products_2.profile_id = #{enterprise.id} | |
47 | 47 | AND profiles.public_profile = true AND profiles.visible = true |
48 | 48 | AND profiles.enabled = true |
49 | 49 | AND profiles.id <> #{enterprise.id}" |
... | ... | @@ -59,14 +59,14 @@ class Product |
59 | 59 | # -> Enterprise 1 as a parameter to this scope would return product B |
60 | 60 | scope :sniffer_plugin_interests_suppliers_products, lambda { |profile| |
61 | 61 | { |
62 | - :from => "sniffer_plugin_profiles sniffer", | |
63 | - :select => "DISTINCT products.*, | |
62 | + from: "profiles sniffer", | |
63 | + select: "DISTINCT products.*, | |
64 | 64 | 'product' as view", |
65 | - :joins => "INNER JOIN sniffer_plugin_opportunities AS op ON ( sniffer.id = op.profile_id AND op.opportunity_type = 'ProductCategory' ) | |
65 | + joins: "INNER JOIN sniffer_plugin_opportunities AS op ON ( sniffer.id = op.profile_id AND op.opportunity_type = 'ProductCategory' ) | |
66 | 66 | INNER JOIN categories ON ( op.opportunity_id = categories.id ) |
67 | 67 | INNER JOIN products ON ( products.product_category_id = categories.id ) |
68 | 68 | INNER JOIN profiles ON ( products.profile_id = profiles.id )", |
69 | - :conditions => "sniffer.enabled = true AND sniffer.profile_id = #{profile.id} AND products.profile_id <> #{profile.id} | |
69 | + conditions: "sniffer.id = #{profile.id} AND products.profile_id <> #{profile.id} | |
70 | 70 | AND profiles.public_profile = true AND profiles.visible = true |
71 | 71 | AND profiles.enabled = true |
72 | 72 | AND profiles.id <> #{profile.id}" |
... | ... | @@ -83,14 +83,13 @@ class Product |
83 | 83 | # with an extra column `consumer_profile_id` equal to Enterprise 2 id |
84 | 84 | scope :sniffer_plugin_interests_consumers_products, lambda { |profile| |
85 | 85 | { |
86 | - :select => "DISTINCT products.*, | |
86 | + select: "DISTINCT products.*, | |
87 | 87 | profiles.id as consumer_profile_id, |
88 | 88 | 'product' as view", |
89 | - :joins => "INNER JOIN categories ON ( categories.id = products.product_category_id ) | |
89 | + joins: "INNER JOIN categories ON ( categories.id = products.product_category_id ) | |
90 | 90 | INNER JOIN sniffer_plugin_opportunities as op ON ( categories.id = op.opportunity_id AND op.opportunity_type = 'ProductCategory' ) |
91 | - INNER JOIN sniffer_plugin_profiles sniffer ON ( op.profile_id = sniffer.id AND sniffer.enabled = true ) | |
92 | - INNER JOIN profiles ON ( sniffer.profile_id = profiles.id )", | |
93 | - :conditions => "products.profile_id = #{profile.id} | |
91 | + INNER JOIN profiles ON ( op.profile_id = profiles.id )", | |
92 | + conditions: "products.profile_id = #{profile.id} | |
94 | 93 | AND profiles.public_profile = true AND profiles.visible = true |
95 | 94 | AND profiles.enabled = true |
96 | 95 | AND profiles.id <> #{profile.id}" |
... | ... | @@ -100,14 +99,14 @@ class Product |
100 | 99 | # knowledge x inputs |
101 | 100 | scope :sniffer_plugin_knowledge_consumers_inputs, lambda { |profile| |
102 | 101 | { |
103 | - :select => "DISTINCT products.*, | |
102 | + select: "DISTINCT products.*, | |
104 | 103 | articles.id AS knowledge_id, |
105 | 104 | 'knowledge' as view", |
106 | - :joins => "INNER JOIN inputs ON ( products.id = inputs.product_id ) | |
105 | + joins: "INNER JOIN inputs ON ( products.id = inputs.product_id ) | |
107 | 106 | INNER JOIN article_resources ON (article_resources.resource_id = inputs.product_category_id AND article_resources.resource_type = 'ProductCategory') |
108 | 107 | INNER JOIN articles ON (article_resources.article_id = articles.id) |
109 | 108 | INNER JOIN profiles ON ( products.profile_id = profiles.id )", |
110 | - :conditions => "articles.type = 'CmsLearningPlugin::Learning' | |
109 | + conditions: "articles.type = 'CmsLearningPlugin::Learning' | |
111 | 110 | AND articles.profile_id = #{profile.id} |
112 | 111 | AND products.profile_id <> #{profile.id}" |
113 | 112 | } |
... | ... | @@ -116,14 +115,14 @@ class Product |
116 | 115 | # inputs x knowledge |
117 | 116 | scope :sniffer_plugin_knowledge_suppliers_inputs, lambda { |profile| |
118 | 117 | { |
119 | - :select => "DISTINCT products.*, | |
118 | + select: "DISTINCT products.*, | |
120 | 119 | profiles.id as supplier_profile_id, articles.id AS knowledge_id, |
121 | 120 | 'knowledge' as view", |
122 | - :joins => "INNER JOIN inputs ON ( products.id = inputs.product_id ) | |
121 | + joins: "INNER JOIN inputs ON ( products.id = inputs.product_id ) | |
123 | 122 | INNER JOIN article_resources ON (article_resources.resource_id = inputs.product_category_id AND article_resources.resource_type = 'ProductCategory') |
124 | 123 | INNER JOIN articles ON (article_resources.article_id = articles.id) |
125 | 124 | INNER JOIN profiles ON ( articles.profile_id = profiles.id )", |
126 | - :conditions => "articles.type = 'CmsLearningPlugin::Learning' | |
125 | + conditions: "articles.type = 'CmsLearningPlugin::Learning' | |
127 | 126 | AND articles.profile_id <> #{profile.id} |
128 | 127 | AND products.profile_id = #{profile.id}" |
129 | 128 | } |
... | ... | @@ -132,16 +131,15 @@ class Product |
132 | 131 | # knowledge x interests |
133 | 132 | scope :sniffer_plugin_knowledge_consumers_interests, lambda { |profile| |
134 | 133 | { |
135 | - :select => "DISTINCT articles.id AS knowledge_id, | |
134 | + select: "DISTINCT articles.id AS knowledge_id, | |
136 | 135 | op.opportunity_id AS product_category_id, |
137 | 136 | profiles.id as profile_id, |
138 | 137 | 'knowledge' as view", |
139 | - :from => "articles", | |
140 | - :joins => "INNER JOIN article_resources ON (articles.id = article_resources.article_id) | |
138 | + from: "articles", | |
139 | + joins: "INNER JOIN article_resources ON (articles.id = article_resources.article_id) | |
141 | 140 | INNER JOIN sniffer_plugin_opportunities as op ON ( article_resources.resource_id = op.opportunity_id AND op.opportunity_type = 'ProductCategory' AND article_resources.resource_type = 'ProductCategory' ) |
142 | - INNER JOIN sniffer_plugin_profiles sniffer ON ( op.profile_id = sniffer.id AND sniffer.enabled = true ) | |
143 | - INNER JOIN profiles ON ( sniffer.profile_id = profiles.id )", | |
144 | - :conditions => "articles.profile_id = #{profile.id} | |
141 | + INNER JOIN profiles ON ( op.profile_id = profiles.id )", | |
142 | + conditions: "articles.profile_id = #{profile.id} | |
145 | 143 | AND profiles.public_profile = true |
146 | 144 | AND profiles.visible = true |
147 | 145 | AND profiles.enabled = true |
... | ... | @@ -152,28 +150,27 @@ class Product |
152 | 150 | # interests x knowledge |
153 | 151 | scope :sniffer_plugin_knowledge_suppliers_interests, lambda { |profile| |
154 | 152 | { |
155 | - :select => "DISTINCT articles.id AS knowledge_id, | |
153 | + select: "DISTINCT articles.id AS knowledge_id, | |
156 | 154 | op.opportunity_id AS product_category_id, |
157 | 155 | profiles.id as profile_id, |
158 | 156 | 'knowledge' as view", |
159 | - :from => "articles", | |
160 | - :joins => "INNER JOIN article_resources ON (articles.id = article_resources.article_id) | |
157 | + from: "articles", | |
158 | + joins: "INNER JOIN article_resources ON (articles.id = article_resources.article_id) | |
161 | 159 | INNER JOIN sniffer_plugin_opportunities as op ON ( article_resources.resource_id = op.opportunity_id AND op.opportunity_type = 'ProductCategory' AND article_resources.resource_type = 'ProductCategory' ) |
162 | - INNER JOIN sniffer_plugin_profiles sniffer ON ( op.profile_id = sniffer.id AND sniffer.enabled = true ) | |
163 | 160 | INNER JOIN profiles ON ( articles.profile_id = profiles.id )", |
164 | - :conditions => "articles.profile_id <> #{profile.id} | |
161 | + conditions: "articles.profile_id <> #{profile.id} | |
165 | 162 | AND profiles.public_profile = true |
166 | 163 | AND profiles.visible = true |
167 | 164 | AND profiles.enabled = true |
168 | - AND sniffer.profile_id = #{profile.id}" | |
165 | + AND profiles.id = #{profile.id}" | |
169 | 166 | } |
170 | 167 | } |
171 | 168 | |
172 | 169 | # searches for products as supplies for a given product category |
173 | 170 | scope :sniffer_plugin_products_from_category, lambda { |product_category| |
174 | 171 | { |
175 | - :conditions => { :product_category_id => product_category.id }, | |
176 | - :select => "*, 'product' as view" | |
172 | + conditions: { product_category_id: product_category.id }, | |
173 | + select: "*, 'product' as view" | |
177 | 174 | } |
178 | 175 | } |
179 | 176 | ... | ... |
plugins/sniffer/lib/ext/profile.rb
1 | 1 | require_dependency 'profile' |
2 | -# WORKAROUND: plugin class don't scope subclasses causing core classes conflict | |
3 | -require_dependency File.expand_path "#{File.dirname __FILE__}/../../lib/sniffer_plugin/profile" | |
4 | 2 | |
5 | 3 | class Profile |
6 | 4 | |
7 | - has_one :sniffer_plugin_profile, :class_name => 'SnifferPlugin::Profile' | |
8 | - has_many :sniffer_plugin_interests, :source => :product_categories, :through => :sniffer_plugin_profile | |
9 | - has_many :sniffer_plugin_opportunities, :source => :opportunities, :through => :sniffer_plugin_profile | |
10 | - | |
11 | 5 | attr_accessor :sniffer_plugin_distance |
12 | 6 | |
7 | + has_many :sniffer_opportunities, :class_name => 'SnifferPlugin::Opportunity', :dependent => :destroy | |
8 | + has_many :sniffer_interested_product_categories, :through => :sniffer_opportunities, :source => :product_category, :class_name => 'ProductCategory', | |
9 | + :conditions => ['sniffer_plugin_opportunities.opportunity_type = ?', 'ProductCategory'] | |
10 | + | |
11 | + attr_accessor :sniffer_interested_product_category_string_ids | |
12 | + descendants.each do |k| | |
13 | + k.attr_accessible :sniffer_interested_product_category_string_ids | |
14 | + end | |
15 | + | |
16 | + def sniffer_interested_product_category_string_ids | |
17 | + '' | |
18 | + end | |
19 | + def sniffer_interested_product_category_string_ids=(ids) | |
20 | + ids = ids.split(',') | |
21 | + self.sniffer_interested_product_categories = [] | |
22 | + r = environment.product_categories.find ids | |
23 | + self.sniffer_interested_product_categories = ids.collect{ |id| r.detect {|x| x.id == id.to_i} } | |
24 | + self.sniffer_opportunities.where(:opportunity_id => ids).each{|o| o.opportunity_type = 'ProductCategory'; o.save! } | |
25 | + end | |
26 | + | |
27 | + def sniffer_categories | |
28 | + (self.product_categories + self.input_categories + self.sniffer_interested_product_categories).uniq | |
29 | + end | |
30 | + | |
31 | + def sniffer_suppliers_products | |
32 | + products = [] | |
33 | + | |
34 | + products += Product.sniffer_plugin_suppliers_products self if self.enterprise? | |
35 | + products += Product.sniffer_plugin_interests_suppliers_products self | |
36 | + if defined?(CmsLearningPlugin) | |
37 | + products += Product.sniffer_plugin_knowledge_suppliers_inputs self | |
38 | + products += Product.sniffer_plugin_knowledge_suppliers_interests self | |
39 | + end | |
40 | + | |
41 | + products | |
42 | + end | |
43 | + | |
44 | + def sniffer_consumers_products | |
45 | + products = [] | |
46 | + | |
47 | + products += Product.sniffer_plugin_consumers_products self if self.enterprise? | |
48 | + products += Product.sniffer_plugin_interests_consumers_products self | |
49 | + if defined?(CmsLearningPlugin) | |
50 | + products += Product.sniffer_plugin_knowledge_consumers_inputs self | |
51 | + products += Product.sniffer_plugin_knowledge_consumers_interests self | |
52 | + end | |
53 | + | |
54 | + products | |
55 | + end | |
56 | + | |
13 | 57 | end | ... | ... |
plugins/sniffer/lib/sniffer_plugin/interests_block.rb
... | ... | @@ -18,11 +18,11 @@ class SnifferPlugin::InterestsBlock < Block |
18 | 18 | |
19 | 19 | def content(args = {}) |
20 | 20 | block = self |
21 | + profile = block.owner | |
21 | 22 | proc do |
22 | 23 | if block.owner.is_a?(Profile) |
23 | - sniffer = SnifferPlugin::Profile.find_or_create(block.owner) | |
24 | - interests = sniffer.opportunities | |
25 | - interests |= sniffer.profile.inputs if sniffer.profile.enterprise? | |
24 | + interests = profile.snnifer_opportunities | |
25 | + interests |= profile.inputs if sniffer.profile.enterprise? | |
26 | 26 | else # Environment |
27 | 27 | interests = SnifferPlugin::Opportunity.product_categories :limit => 5, :order => 'created_at DESC' |
28 | 28 | interests += Input.all :limit => 5, :order => 'created_at DESC' | ... | ... |
plugins/sniffer/lib/sniffer_plugin/opportunity.rb
... | ... | @@ -1,34 +0,0 @@ |
1 | -class SnifferPlugin::Opportunity < ActiveRecord::Base | |
2 | - | |
3 | - self.table_name = :sniffer_plugin_opportunities | |
4 | - | |
5 | - belongs_to :sniffer_profile, :class_name => 'SnifferPlugin::Profile', :foreign_key => :profile_id | |
6 | - has_one :profile, :through => :sniffer_profile | |
7 | - | |
8 | - belongs_to :opportunity, :polymorphic => true | |
9 | - | |
10 | - # for has_many :through | |
11 | - belongs_to :product_category, :class_name => 'ProductCategory', :foreign_key => :opportunity_id, | |
12 | - :conditions => ['sniffer_plugin_opportunities.opportunity_type = ?', 'ProductCategory'] | |
13 | - # getter | |
14 | - def product_category | |
15 | - opportunity_type == 'ProductCategory' ? opportunity : nil | |
16 | - end | |
17 | - | |
18 | - scope :product_categories, { | |
19 | - :conditions => ['sniffer_plugin_opportunities.opportunity_type = ?', 'ProductCategory'] | |
20 | - } | |
21 | - | |
22 | - if defined? SolrPlugin | |
23 | - acts_as_searchable :fields => [ | |
24 | - # searched fields | |
25 | - # filtered fields | |
26 | - # ordered/query-boosted fields | |
27 | - ], :include => [ | |
28 | - {:product_category => {:fields => [:name, :path, :slug, :lat, :lng, :acronym, :abbreviation]}}, | |
29 | - ] | |
30 | - | |
31 | - handle_asynchronously :solr_save | |
32 | - end | |
33 | - | |
34 | -end |
plugins/sniffer/lib/sniffer_plugin/profile.rb
... | ... | @@ -1,79 +0,0 @@ |
1 | -class SnifferPlugin::Profile < ActiveRecord::Base | |
2 | - | |
3 | - self.table_name = :sniffer_plugin_profiles | |
4 | - | |
5 | - belongs_to :profile, :class_name => '::Profile' | |
6 | - | |
7 | - has_many :opportunities, :class_name => 'SnifferPlugin::Opportunity', :foreign_key => :profile_id, :dependent => :destroy | |
8 | - has_many :product_categories, :through => :opportunities, :source => :product_category, :foreign_key => :profile_id, :class_name => 'ProductCategory', | |
9 | - :conditions => ['sniffer_plugin_opportunities.opportunity_type = ?', 'ProductCategory'] | |
10 | - | |
11 | - validates_presence_of :profile | |
12 | - | |
13 | - attr_accessible :product_category_string_ids, :enabled | |
14 | - | |
15 | - def self.find_or_create profile | |
16 | - sniffer = SnifferPlugin::Profile.find_by_profile_id profile.id | |
17 | - if sniffer.nil? | |
18 | - sniffer = SnifferPlugin::Profile.new | |
19 | - sniffer.profile = profile | |
20 | - sniffer.enabled = true | |
21 | - sniffer.save! | |
22 | - end | |
23 | - sniffer | |
24 | - end | |
25 | - | |
26 | - def product_category_string_ids | |
27 | - '' | |
28 | - end | |
29 | - | |
30 | - def product_category_string_ids=(ids) | |
31 | - ids = ids.split(',') | |
32 | - self.product_categories = [] | |
33 | - self.product_categories = ProductCategory.find(ids) | |
34 | - self.opportunities. | |
35 | - find(:all, :conditions => {:opportunity_id => ids}).each do |o| | |
36 | - o.opportunity_type = 'ProductCategory' | |
37 | - o.save! | |
38 | - end | |
39 | - end | |
40 | - | |
41 | - def profile_input_categories | |
42 | - profile.input_categories | |
43 | - end | |
44 | - | |
45 | - def profile_product_categories | |
46 | - profile.product_categories | |
47 | - end | |
48 | - | |
49 | - def all_categories | |
50 | - (profile_product_categories + profile_input_categories + product_categories).uniq | |
51 | - end | |
52 | - | |
53 | - def suppliers_products | |
54 | - products = [] | |
55 | - | |
56 | - products += Product.sniffer_plugin_suppliers_products profile if profile.enterprise? | |
57 | - products += Product.sniffer_plugin_interests_suppliers_products profile | |
58 | - if defined?(CmsLearningPlugin) | |
59 | - products += Product.sniffer_plugin_knowledge_suppliers_inputs profile | |
60 | - products += Product.sniffer_plugin_knowledge_suppliers_interests profile | |
61 | - end | |
62 | - | |
63 | - products | |
64 | - end | |
65 | - | |
66 | - def consumers_products | |
67 | - products = [] | |
68 | - | |
69 | - products += Product.sniffer_plugin_consumers_products profile if profile.enterprise? | |
70 | - products += Product.sniffer_plugin_interests_consumers_products profile | |
71 | - if defined?(CmsLearningPlugin) | |
72 | - products += Product.sniffer_plugin_knowledge_consumers_inputs profile | |
73 | - products += Product.sniffer_plugin_knowledge_consumers_interests profile | |
74 | - end | |
75 | - | |
76 | - products | |
77 | - end | |
78 | - | |
79 | -end |
... | ... | @@ -0,0 +1,48 @@ |
1 | +class SnifferPlugin::Opportunity < ActiveRecord::Base | |
2 | + | |
3 | + self.table_name = :sniffer_plugin_opportunities | |
4 | + | |
5 | + belongs_to :profile | |
6 | + | |
7 | + belongs_to :opportunity, polymorphic: true | |
8 | + | |
9 | + # for has_many :through | |
10 | + belongs_to :product_category, class_name: 'ProductCategory', foreign_key: :opportunity_id, | |
11 | + conditions: ['sniffer_plugin_opportunities.opportunity_type = ?', 'ProductCategory'] | |
12 | + # getter | |
13 | + def product_category | |
14 | + opportunity_type == 'ProductCategory' ? opportunity : nil | |
15 | + end | |
16 | + | |
17 | + scope :product_categories, { | |
18 | + conditions: ['sniffer_plugin_opportunities.opportunity_type = ?', 'ProductCategory'] | |
19 | + } | |
20 | + | |
21 | + if defined? SolrPlugin | |
22 | + acts_as_searchable fields: [ | |
23 | + # searched fields | |
24 | + # filtered fields | |
25 | + # ordered/query-boosted fields | |
26 | + ], include: [ | |
27 | + {product_category: {fields: [:name, :path, :slug, :lat, :lng, :acronym, :abbreviation]}}, | |
28 | + ] | |
29 | + | |
30 | + handle_asynchronously :solr_save | |
31 | + end | |
32 | + | |
33 | + delegate :lat, :lng, :to => :product_category, :allow_nil => true | |
34 | + | |
35 | + # delegate missing methods to opportunity | |
36 | + def method_missing method, *args, &block | |
37 | + if self.opportunity.respond_to? method | |
38 | + self.opportunity.send method, *args, &block | |
39 | + else | |
40 | + super method, *args, &block | |
41 | + end | |
42 | + end | |
43 | + def respond_to_with_opportunity? method, p2 = true | |
44 | + respond_to_without_opportunity? method, p2 or (self.opportunity and self.opportunity.respond_to? method) | |
45 | + end | |
46 | + alias_method_chain :respond_to?, :opportunity | |
47 | + | |
48 | +end | ... | ... |
plugins/sniffer/test/integration/sniffer_map_test.rb
... | ... | @@ -165,10 +165,9 @@ class SnifferMapTest < ActionDispatch::IntegrationTest |
165 | 165 | :identifier => 'acme', :name => 'ACME S.A.', :lat => 0, :lng => 0 |
166 | 166 | ) |
167 | 167 | # get the extended sniffer profile for the enterprise: |
168 | - sniffer_acme = SnifferPlugin::Profile.find_or_create acme | |
169 | - sniffer_acme.product_category_string_ids = "#{@c[1].id},#{@c[4].id}" | |
170 | - sniffer_acme.enabled = true | |
171 | - sniffer_acme.save! | |
168 | + acme.sniffer_interested_product_category_string_ids = "#{@c[1].id},#{@c[4].id}" | |
169 | + acme.enabled = true | |
170 | + acme.save! | |
172 | 171 | |
173 | 172 | # visit the map page: |
174 | 173 | get url_plugin_myprofile(acme, :search) | ... | ... |
... | ... | @@ -0,0 +1,96 @@ |
1 | +require 'test_helper' | |
2 | + | |
3 | +class ProfileTest < ActiveSupport::TestCase | |
4 | + | |
5 | + should 'register interest on a product category for a profile' do | |
6 | + # crate an entreprise | |
7 | + coop = create(Enterprise, | |
8 | + :identifier => 'coop', :name => 'A Cooperative', :lat => 0, :lng => 0 | |
9 | + ) | |
10 | + # create categories | |
11 | + c1 = create(ProductCategory, :name => 'Category 1') | |
12 | + c2 = create(ProductCategory, :name => 'Category 2') | |
13 | + # get the extended sniffer profile for the enterprise: | |
14 | + coop.sniffer_interested_product_category_string_ids = "#{c1.id},#{c2.id}" | |
15 | + coop.enabled = true | |
16 | + coop.save! | |
17 | + | |
18 | + categories = coop.sniffer_interested_product_categories | |
19 | + assert_equal 2, categories.length | |
20 | + assert_equal 'Category 1', categories[0].name | |
21 | + assert_equal 'Category 2', categories[1].name | |
22 | + end | |
23 | + | |
24 | + should 'find suppliers and consumers products' do | |
25 | + # Enterprises: | |
26 | + e1 = fast_create(Enterprise, :identifier => 'ent1' ) | |
27 | + e2 = fast_create(Enterprise, :identifier => 'ent2' ) | |
28 | + e3 = fast_create(Enterprise, :identifier => 'ent3' ) | |
29 | + # Categories: | |
30 | + c1 = fast_create(ProductCategory, :name => 'Category 1') | |
31 | + c2 = fast_create(ProductCategory, :name => 'Category 2') | |
32 | + c3 = fast_create(ProductCategory, :name => 'Category 3') | |
33 | + c4 = fast_create(ProductCategory, :name => 'Category 4') # not used by products | |
34 | + # Products (for enterprise 1): | |
35 | + p1 = fast_create(Product, :product_category_id => c1.id, :profile_id => e1.id ) | |
36 | + p2 = fast_create(Product, :product_category_id => c2.id, :profile_id => e1.id ) | |
37 | + # Products (for enterprise 2): | |
38 | + p3 = fast_create(Product, :product_category_id => c3.id, :profile_id => e2.id ) | |
39 | + p3.inputs.build.product_category = c1 # p3 uses p1 as input on its production | |
40 | + p3.save! | |
41 | + # Products (for enterprise 3): | |
42 | + p4 = fast_create(Product, :product_category_id => c3.id, :profile_id => e3.id ) | |
43 | + p5 = fast_create(Product, :product_category_id => c3.id, :profile_id => e3.id ) | |
44 | + p4.inputs.build.product_category = c1 # p4 uses p1 as input on its production | |
45 | + p5.inputs.build.product_category = c1 # as does p5 | |
46 | + p4.save! | |
47 | + p5.save! | |
48 | + | |
49 | + # register e2 interest for 'Category 2' use by p2 | |
50 | + e2.sniffer_interested_product_category_string_ids = "#{c2.id},#{c4.id}" | |
51 | + e2.enabled = true | |
52 | + e2.save! | |
53 | + | |
54 | + assert_equal [p1.id, p1.id, p2.id], | |
55 | + e1.sniffer_consumers_products.sort_by(&:id).map(&:id) | |
56 | + | |
57 | + # since they have interest in the same product, e2 and e3 position | |
58 | + # may vary here, but the last enterprise should be e2 | |
59 | + assert_equivalent [e2.id, e3.id], | |
60 | + e1.sniffer_consumers_products.sort_by(&:id).map{|p| p[:consumer_profile_id].to_i}.first(2) | |
61 | + assert_equal e2.id, | |
62 | + e1.sniffer_consumers_products.sort_by(&:id).map{|p| p[:consumer_profile_id].to_i}.last | |
63 | + | |
64 | + assert_equal [p1.id, p2.id], | |
65 | + e2.sniffer_suppliers_products.sort_by(&:id).map(&:id) | |
66 | + assert_equal [], e2.sniffer_consumers_products | |
67 | + end | |
68 | + | |
69 | + should 'not search for suppliers and consumers on disabled enterprises' do | |
70 | + # Enterprises: | |
71 | + e1 = fast_create(Enterprise, :identifier => 'ent1' ) | |
72 | + e2 = fast_create(Enterprise, :identifier => 'ent2' ) | |
73 | + # Categories: | |
74 | + c1 = fast_create(ProductCategory, :name => 'Category 1') | |
75 | + c2 = fast_create(ProductCategory, :name => 'Category 2') | |
76 | + # Products (for enterprise 1): | |
77 | + p1 = fast_create(Product, :product_category_id => c1.id, :profile_id => e1.id ) | |
78 | + | |
79 | + # Products (for enterprise 2): | |
80 | + p2 = fast_create(Product, :product_category_id => c2.id, :profile_id => e2.id ) | |
81 | + p2.inputs.build.product_category = c1 | |
82 | + p2.save! | |
83 | + | |
84 | + # register e2 interest for 'Category 1' used by p1 | |
85 | + e2.sniffer_interested_product_category_string_ids = "#{c1.id}" | |
86 | + e2.enabled = true | |
87 | + e2.save! | |
88 | + | |
89 | + # should not find anything for disabled enterprise | |
90 | + e1.enabled = false | |
91 | + e1.save! | |
92 | + assert_equal [], e2.sniffer_consumers_products | |
93 | + assert_equal [], e2.sniffer_suppliers_products | |
94 | + end | |
95 | + | |
96 | +end | ... | ... |
plugins/sniffer/test/unit/sniffer_plugin_profile_test.rb
... | ... | @@ -1,106 +0,0 @@ |
1 | -require 'test_helper' | |
2 | - | |
3 | -class SnifferPluginProfileTest < ActiveSupport::TestCase | |
4 | - | |
5 | - should 'register interest on a product category for a profile' do | |
6 | - # crate an entreprise | |
7 | - coop = fast_create(Enterprise, | |
8 | - :identifier => 'coop', :name => 'A Cooperative', :lat => 0, :lng => 0 | |
9 | - ) | |
10 | - # create categories | |
11 | - c1 = fast_create(ProductCategory, :name => 'Category 1') | |
12 | - c2 = fast_create(ProductCategory, :name => 'Category 2') | |
13 | - # get the extended sniffer profile for the enterprise: | |
14 | - sniffer_coop = SnifferPlugin::Profile.find_or_create coop | |
15 | - sniffer_coop.product_category_string_ids = "#{c1.id},#{c2.id}" | |
16 | - sniffer_coop.enabled = true | |
17 | - sniffer_coop.save! | |
18 | - | |
19 | - # search for and instance again the profile sniffer for coop | |
20 | - same_sniffer = SnifferPlugin::Profile.find_or_create coop | |
21 | - | |
22 | - categories = same_sniffer.product_categories | |
23 | - assert_equal 2, categories.length | |
24 | - assert_equal 'Category 1', categories[0].name | |
25 | - assert_equal 'Category 2', categories[1].name | |
26 | - end | |
27 | - | |
28 | - should 'find suppliers and consumers products' do | |
29 | - # Enterprises: | |
30 | - e1 = fast_create(Enterprise, :identifier => 'ent1' ) | |
31 | - e2 = fast_create(Enterprise, :identifier => 'ent2' ) | |
32 | - e3 = fast_create(Enterprise, :identifier => 'ent3' ) | |
33 | - # Categories: | |
34 | - c1 = fast_create(ProductCategory, :name => 'Category 1') | |
35 | - c2 = fast_create(ProductCategory, :name => 'Category 2') | |
36 | - c3 = fast_create(ProductCategory, :name => 'Category 3') | |
37 | - c4 = fast_create(ProductCategory, :name => 'Category 4') # not used by products | |
38 | - # Products (for enterprise 1): | |
39 | - p1 = fast_create(Product, :product_category_id => c1.id, :profile_id => e1.id ) | |
40 | - p2 = fast_create(Product, :product_category_id => c2.id, :profile_id => e1.id ) | |
41 | - # Products (for enterprise 2): | |
42 | - p3 = fast_create(Product, :product_category_id => c3.id, :profile_id => e2.id ) | |
43 | - p3.inputs.build.product_category = c1 # p3 uses p1 as input on its production | |
44 | - p3.save! | |
45 | - # Products (for enterprise 3): | |
46 | - p4 = fast_create(Product, :product_category_id => c3.id, :profile_id => e3.id ) | |
47 | - p5 = fast_create(Product, :product_category_id => c3.id, :profile_id => e3.id ) | |
48 | - p4.inputs.build.product_category = c1 # p4 uses p1 as input on its production | |
49 | - p5.inputs.build.product_category = c1 # as does p5 | |
50 | - p4.save! | |
51 | - p5.save! | |
52 | - | |
53 | - # get the extended sniffer profile for the enterprise: | |
54 | - e1_sniffer = SnifferPlugin::Profile.find_or_create e1 | |
55 | - e2_sniffer = SnifferPlugin::Profile.find_or_create e2 | |
56 | - # register e2 interest for 'Category 2' use by p2 | |
57 | - e2_sniffer.product_category_string_ids = "#{c2.id},#{c4.id}" | |
58 | - e2_sniffer.enabled = true | |
59 | - e2_sniffer.save! | |
60 | - | |
61 | - assert_equal [p1.id, p1.id, p2.id], | |
62 | - e1_sniffer.consumers_products.sort_by(&:id).map(&:id) | |
63 | - | |
64 | - # since they have interest in the same product, e2 and e3 position | |
65 | - # may vary here, but the last enterprise should be e2 | |
66 | - assert_equivalent [e2.id, e3.id], | |
67 | - e1_sniffer.consumers_products.sort_by(&:id).map{|p| p[:consumer_profile_id].to_i}.first(2) | |
68 | - assert_equal e2.id, | |
69 | - e1_sniffer.consumers_products.sort_by(&:id).map{|p| p[:consumer_profile_id].to_i}.last | |
70 | - | |
71 | - assert_equal [p1.id, p2.id], | |
72 | - e2_sniffer.suppliers_products.sort_by(&:id).map(&:id) | |
73 | - assert_equal [], e2_sniffer.consumers_products | |
74 | - end | |
75 | - | |
76 | - should 'not search for suppliers and consumers on disabled enterprises' do | |
77 | - # Enterprises: | |
78 | - e1 = fast_create(Enterprise, :identifier => 'ent1' ) | |
79 | - e2 = fast_create(Enterprise, :identifier => 'ent2' ) | |
80 | - # Categories: | |
81 | - c1 = fast_create(ProductCategory, :name => 'Category 1') | |
82 | - c2 = fast_create(ProductCategory, :name => 'Category 2') | |
83 | - # Products (for enterprise 1): | |
84 | - p1 = fast_create(Product, :product_category_id => c1.id, :profile_id => e1.id ) | |
85 | - | |
86 | - # Products (for enterprise 2): | |
87 | - p2 = fast_create(Product, :product_category_id => c2.id, :profile_id => e2.id ) | |
88 | - p2.inputs.build.product_category = c1 | |
89 | - p2.save! | |
90 | - | |
91 | - # get the extended sniffer profile for the enterprise: | |
92 | - e1_sniffer = SnifferPlugin::Profile.find_or_create e1 | |
93 | - e2_sniffer = SnifferPlugin::Profile.find_or_create e2 | |
94 | - # register e2 interest for 'Category 1' used by p1 | |
95 | - e2_sniffer.product_category_string_ids = "#{c1.id}" | |
96 | - e2_sniffer.enabled = true | |
97 | - e2_sniffer.save! | |
98 | - | |
99 | - # should not find anything for disabled enterprise | |
100 | - e1.enabled = false | |
101 | - e1.save! | |
102 | - assert_equal [], e2_sniffer.consumers_products | |
103 | - assert_equal [], e2_sniffer.suppliers_products | |
104 | - end | |
105 | - | |
106 | -end |
plugins/sniffer/views/sniffer_plugin_myprofile/edit.html.erb
... | ... | @@ -4,18 +4,21 @@ |
4 | 4 | <%= _('Select here products and services categories that you have an interest on buying. Then you can go to the Opportunity Sniffer and check out enterprises near you that offer such products. Type in some characters and choose your interests from our list.') %> |
5 | 5 | </p> |
6 | 6 | |
7 | -<%= form_for(@sniffer_profile, :url => {:action => 'edit'}, :method => 'post') do |f| %> | |
7 | +<%= form_for(@profile, as: :profile_data, url: {action: 'edit'}, method: 'post') do |f| %> | |
8 | 8 | |
9 | 9 | <div id='sniffer-plugin-product-select'> |
10 | - <% current_categories = @sniffer_profile.product_categories.collect{ |i| {:id => i.id, :name => i.name} } %> | |
10 | + <% current_categories = @profile.sniffer_interested_product_categories.map{ |i| {id: i.id, name: i.name} } %> | |
11 | 11 | |
12 | - <%= token_input_field_tag('sniffer_plugin_profile[product_category_string_ids]', 'sniffer_product_category_string_ids', { :action => 'product_category_search' }, {search_delay: 150, pre_populate: current_categories, prevent_duplicates: true, hint_text: _('Type in a keyword') }) %> | |
12 | + <%= token_input_field_tag('profile_data[sniffer_interested_product_category_string_ids]', | |
13 | + 'sniffer_interested_product_category_string_ids', | |
14 | + { action: 'product_category_search' }, | |
15 | + {search_delay: 150, pre_populate: current_categories, prevent_duplicates: true, hint_text: _('Type in a keyword') }) %> | |
13 | 16 | |
14 | 17 | </div> |
15 | 18 | |
16 | 19 | <% button_bar do %> |
17 | 20 | <%= submit_button(:save, _('Save')) %> |
18 | - <%= button :back, _('Back to control panel'), :controller => 'profile_editor' %> | |
21 | + <%= button :back, _('Back to control panel'), controller: 'profile_editor' %> | |
19 | 22 | <% end %> |
20 | 23 | <% end %> |
21 | 24 | ... | ... |
plugins/spaminator/test/unit/spaminator_plugin/spaminator_test.rb
... | ... | @@ -96,7 +96,8 @@ class SpaminatorPlugin::SpaminatorTest < ActiveSupport::TestCase |
96 | 96 | end |
97 | 97 | |
98 | 98 | should 'process person by network' do |
99 | - person = create_user('spammer').person | |
99 | + user = User.current = create_user 'spammer' | |
100 | + person = user.person | |
100 | 101 | person.created_at = Time.now - 2.months |
101 | 102 | person.save! |
102 | 103 | c1 = fast_create(Community) | ... | ... |
plugins/tolerance_time/po/pt/tolerance_time.po
... | ... | @@ -13,16 +13,16 @@ msgid "" |
13 | 13 | msgstr "" |
14 | 14 | "Project-Id-Version: 1.3~rc2-1-ga15645d\n" |
15 | 15 | "POT-Creation-Date: 2015-10-30 16:35-0300\n" |
16 | -"PO-Revision-Date: 2014-12-18 18:40-0200\n" | |
17 | -"Last-Translator: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com>\n" | |
18 | -"Language-Team: Portuguese <https://hosted.weblate.org/projects/noosfero/" | |
19 | -"noosfero/pt/>\n" | |
16 | +"PO-Revision-Date: 2016-03-14 16:06+0000\n" | |
17 | +"Last-Translator: Eduardo Vital <vitaldu@gmail.com>\n" | |
18 | +"Language-Team: Portuguese <https://hosted.weblate.org/projects/noosfero" | |
19 | +"/plugin-tolerance-time/pt/>\n" | |
20 | 20 | "Language: pt\n" |
21 | 21 | "MIME-Version: 1.0\n" |
22 | 22 | "Content-Type: text/plain; charset=UTF-8\n" |
23 | 23 | "Content-Transfer-Encoding: 8bit\n" |
24 | 24 | "Plural-Forms: nplurals=2; plural=n != 1;\n" |
25 | -"X-Generator: Weblate 2.0\n" | |
25 | +"X-Generator: Weblate 2.5\n" | |
26 | 26 | |
27 | 27 | #: plugins/tolerance_time/lib/tolerance_time_plugin.rb:8 |
28 | 28 | msgid "Adds a tolerance time for editing content after its publication" |
... | ... | @@ -43,24 +43,23 @@ msgstr "" |
43 | 43 | |
44 | 44 | #: plugins/tolerance_time/lib/tolerance_time_plugin.rb:59 |
45 | 45 | msgid "editing" |
46 | -msgstr "" | |
46 | +msgstr "edição" | |
47 | 47 | |
48 | 48 | #: plugins/tolerance_time/lib/tolerance_time_plugin.rb:63 |
49 | 49 | msgid "cloning" |
50 | -msgstr "" | |
50 | +msgstr "clonagem" | |
51 | 51 | |
52 | 52 | #: plugins/tolerance_time/lib/tolerance_time_plugin.rb:70 |
53 | -#, fuzzy | |
54 | 53 | msgid "The tolerance time for %s this content is over." |
55 | -msgstr "O tempo de tolerância para edição deste conteúdo acabou." | |
54 | +msgstr "O tempo de tolerância para %s deste conteúdo acabou." | |
56 | 55 | |
57 | 56 | #: plugins/tolerance_time/controllers/tolerance_time_plugin_myprofile_controller.rb:10 |
58 | 57 | msgid "Tolerance updated" |
59 | -msgstr "A tolerância foi atualizada" | |
58 | +msgstr "O tempo de tolerância foi atualizado" | |
60 | 59 | |
61 | 60 | #: plugins/tolerance_time/controllers/tolerance_time_plugin_myprofile_controller.rb:12 |
62 | 61 | msgid "Tolerance could not be updated" |
63 | -msgstr "A tolerância não pode ser atualizada" | |
62 | +msgstr "O tempo de tolerância não pode ser atualizado" | |
64 | 63 | |
65 | 64 | #: plugins/tolerance_time/views/tolerance_time_plugin_myprofile/index.html.erb:1 |
66 | 65 | msgid "Tolerance Adjustments" |
... | ... | @@ -79,6 +78,7 @@ msgid "Hours" |
79 | 78 | msgstr "Horas" |
80 | 79 | |
81 | 80 | #: plugins/tolerance_time/views/tolerance_time_plugin_myprofile/index.html.erb:10 |
81 | +#, fuzzy | |
82 | 82 | msgid "Content edition tolerance time" |
83 | 83 | msgstr "Tempo de tolerância para edição de conteúdo" |
84 | 84 | |
... | ... | @@ -87,5 +87,6 @@ msgid "Comment edition tolerance time" |
87 | 87 | msgstr "Tempo de tolerância para edição de comentários" |
88 | 88 | |
89 | 89 | #: plugins/tolerance_time/views/tolerance_time_plugin_myprofile/index.html.erb:18 |
90 | +#, fuzzy | |
90 | 91 | msgid "Empty means unlimited and zero means right away." |
91 | -msgstr "Vazio significa ilimitado e zero significa imediatamente." | |
92 | +msgstr "Campo vazio significa ilimitado e zero significa imediatamente." | ... | ... |
plugins/work_assignment/po/pt/work_assignment.po
... | ... | @@ -13,16 +13,16 @@ msgid "" |
13 | 13 | msgstr "" |
14 | 14 | "Project-Id-Version: 1.3~rc2-1-ga15645d\n" |
15 | 15 | "POT-Creation-Date: 2015-10-30 16:35-0300\n" |
16 | -"PO-Revision-Date: 2015-08-07 16:48+0200\n" | |
17 | -"Last-Translator: Antonio Terceiro <terceiro@softwarelivre.org>\n" | |
18 | -"Language-Team: Portuguese <https://hosted.weblate.org/projects/noosfero/" | |
19 | -"plugin-work-assignment/pt/>\n" | |
16 | +"PO-Revision-Date: 2016-03-14 15:58+0000\n" | |
17 | +"Last-Translator: Eduardo Vital <vitaldu@gmail.com>\n" | |
18 | +"Language-Team: Portuguese <https://hosted.weblate.org/projects/noosfero" | |
19 | +"/plugin-work-assignment/pt/>\n" | |
20 | 20 | "Language: pt\n" |
21 | 21 | "MIME-Version: 1.0\n" |
22 | 22 | "Content-Type: text/plain; charset=UTF-8\n" |
23 | 23 | "Content-Transfer-Encoding: 8bit\n" |
24 | 24 | "Plural-Forms: nplurals=2; plural=n != 1;\n" |
25 | -"X-Generator: Weblate 2.4-dev\n" | |
25 | +"X-Generator: Weblate 2.5\n" | |
26 | 26 | |
27 | 27 | #: plugins/work_assignment/lib/work_assignment_plugin.rb:8 |
28 | 28 | msgid "New kind of content for organizations." |
... | ... | @@ -66,7 +66,7 @@ msgstr "Nome" |
66 | 66 | |
67 | 67 | #: plugins/work_assignment/lib/work_assignment_plugin/helper.rb:9 |
68 | 68 | msgid "Submission date" |
69 | -msgstr "Data de submissão" | |
69 | +msgstr "Data da submissão" | |
70 | 70 | |
71 | 71 | #: plugins/work_assignment/lib/work_assignment_plugin/helper.rb:10 |
72 | 72 | msgid "Versions" | ... | ... |
po/pt/noosfero.po
... | ... | @@ -13,7 +13,7 @@ msgid "" |
13 | 13 | msgstr "" |
14 | 14 | "Project-Id-Version: 1.3~rc2-8-g01ea9f7\n" |
15 | 15 | "POT-Creation-Date: 2015-11-04 12:36-0300\n" |
16 | -"PO-Revision-Date: 2016-02-18 14:44+0000\n" | |
16 | +"PO-Revision-Date: 2016-03-14 15:58+0000\n" | |
17 | 17 | "Last-Translator: Eduardo Vital <vitaldu@gmail.com>\n" |
18 | 18 | "Language-Team: Portuguese " |
19 | 19 | "<https://hosted.weblate.org/projects/noosfero/noosfero/pt/>\n" |
... | ... | @@ -22,7 +22,7 @@ msgstr "" |
22 | 22 | "Content-Type: text/plain; charset=UTF-8\n" |
23 | 23 | "Content-Transfer-Encoding: 8bit\n" |
24 | 24 | "Plural-Forms: nplurals=2; plural=n != 1;\n" |
25 | -"X-Generator: Weblate 2.5-dev\n" | |
25 | +"X-Generator: Weblate 2.5\n" | |
26 | 26 | |
27 | 27 | #: app/models/approve_comment.rb:17 |
28 | 28 | msgid "Anonymous" | ... | ... |
public/stylesheets/cms.scss
... | ... | @@ -167,6 +167,12 @@ table.cms-articles .icon:hover { |
167 | 167 | white-space: nowrap; |
168 | 168 | } |
169 | 169 | |
170 | +.controller-cms td.article-name { | |
171 | + text-overflow: ellipsis; | |
172 | + white-space: nowrap; | |
173 | + overflow: hidden; | |
174 | +} | |
175 | + | |
170 | 176 | .controller-cms .article-controls { |
171 | 177 | white-space: nowrap; |
172 | 178 | } | ... | ... |
public/stylesheets/content/blog.scss
public/stylesheets/content/folder.scss
public/stylesheets/content/image-gallery.scss
script/install-dependencies/debian-jessie.sh
1 | -binary_packages='deb http://download.noosfero.org/debian/jessie ./' | |
1 | +binary_packages='deb http://download.noosfero.org/debian/jessie-test ./' | |
2 | 2 | |
3 | 3 | source_packages=$(echo "$binary_packages" | sed -e 's/^deb/deb-src/') |
4 | 4 | |
... | ... | @@ -10,7 +10,7 @@ EOF |
10 | 10 | |
11 | 11 | sudo apt-key add - <<EOF |
12 | 12 | -----BEGIN PGP PUBLIC KEY BLOCK----- |
13 | -Version: GnuPG v1.4.9 (GNU/Linux) | |
13 | +Version: GnuPG v1.4.12 (GNU/Linux) | |
14 | 14 | |
15 | 15 | mQGiBE1HCIURBADw6SnRbc1qCHdTV9wD0rxSMIWevzUX+bnDgvV455yudqtVFUhX |
16 | 16 | 2QYvtlwclllbLWKzRdiM7GsBi+2DyWli4B17xl86A5RBQNdc1v1vWZG3QwURxd4E | ... | ... |
script/quick-start
test/functional/profile_editor_controller_test.rb
... | ... | @@ -1224,4 +1224,11 @@ class ProfileEditorControllerTest < ActionController::TestCase |
1224 | 1224 | assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/default_user/profile_roles" } |
1225 | 1225 | end |
1226 | 1226 | |
1227 | + should 'save profile admin option to receive email for every task' do | |
1228 | + comm = fast_create(Community) | |
1229 | + assert comm.profile_admin_mail_notification | |
1230 | + post :edit, :profile => comm.identifier, :profile_data => { :profile_admin_mail_notification => '0' } | |
1231 | + refute comm.reload.profile_admin_mail_notification | |
1232 | + end | |
1233 | + | |
1227 | 1234 | end | ... | ... |
test/functional/tasks_controller_test.rb
... | ... | @@ -104,6 +104,17 @@ class TasksControllerTest < ActionController::TestCase |
104 | 104 | ok('task should be finished') { t.status == Task::Status::FINISHED } |
105 | 105 | end |
106 | 106 | |
107 | + should 'keep filters after close a task' do | |
108 | + t = profile.tasks.build; t.save! | |
109 | + | |
110 | + post :close, :tasks => {t.id => {:decision => 'finish', :task => {}}}, :filter_type => t.type | |
111 | + assert_redirected_to :action => 'index', :filter_type => t.type | |
112 | + assert_equal @controller.params[:filter_type], t.type | |
113 | + | |
114 | + t.reload | |
115 | + ok('task should be finished') { t.status == Task::Status::FINISHED } | |
116 | + end | |
117 | + | |
107 | 118 | should 'be able to cancel a task' do |
108 | 119 | t = profile.tasks.build; t.save! |
109 | 120 | ... | ... |
... | ... | @@ -0,0 +1,22 @@ |
1 | +require_relative 'test_helper' | |
2 | + | |
3 | +class ActivitiesTest < ActiveSupport::TestCase | |
4 | + | |
5 | + def setup | |
6 | + login_api | |
7 | + end | |
8 | + | |
9 | + should 'get activity from profile' do | |
10 | + person = fast_create(Person) | |
11 | + organization = fast_create(Organization) | |
12 | + assert_difference 'organization.activities_count' do | |
13 | + ActionTracker::Record.create! :verb => :leave_scrap, :user => person, :target => organization | |
14 | + organization.reload | |
15 | + end | |
16 | + get "/api/v1/profiles/#{organization.id}/activities?#{params.to_query}" | |
17 | + json = JSON.parse(last_response.body) | |
18 | + assert 1, json["activities"].count | |
19 | + assert_equal organization.activities.map(&:activity).first.id, json["activities"].first["id"] | |
20 | + end | |
21 | + | |
22 | +end | ... | ... |
test/unit/api/articles_test.rb
... | ... | @@ -13,6 +13,16 @@ class ArticlesTest < ActiveSupport::TestCase |
13 | 13 | assert_includes json["articles"].map { |a| a["id"] }, article.id |
14 | 14 | end |
15 | 15 | |
16 | + should 'get profile homepage' do | |
17 | + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") | |
18 | + person.home_page=article | |
19 | + person.save! | |
20 | + | |
21 | + get "/api/v1/profiles/#{person.id}/home_page?#{params.to_query}" | |
22 | + json = JSON.parse(last_response.body) | |
23 | + assert_equal article.id, json["article"]["id"] | |
24 | + end | |
25 | + | |
16 | 26 | should 'not list forbidden article when listing articles' do |
17 | 27 | person = fast_create(Person) |
18 | 28 | article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) |
... | ... | @@ -74,6 +84,16 @@ class ArticlesTest < ActiveSupport::TestCase |
74 | 84 | assert_equal 1, json['total_followers'] |
75 | 85 | end |
76 | 86 | |
87 | + should 'list articles followed by me' do | |
88 | + article1 = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") | |
89 | + fast_create(Article, :profile_id => user.person.id, :name => "Some other thing") | |
90 | + article1.person_followers << @person | |
91 | + get "/api/v1/articles/followed_by_me?#{params.to_query}" | |
92 | + json = JSON.parse(last_response.body) | |
93 | + assert_equal [article1.id], json['articles'].map { |a| a['id'] } | |
94 | + end | |
95 | + | |
96 | + | |
77 | 97 | should 'list article children' do |
78 | 98 | article = create(Article, :profile_id => user.person.id, :name => "Parent") |
79 | 99 | child1 = create(Article, :parent_id => article.id, :profile_id => user.person.id, :name => "Some Child") |
... | ... | @@ -190,6 +210,33 @@ class ArticlesTest < ActiveSupport::TestCase |
190 | 210 | end |
191 | 211 | end |
192 | 212 | |
213 | + should 'not perform a vote twice in same article' do | |
214 | + article = fast_create(Article, :profile_id => @person.id, :name => "Some thing") | |
215 | + @params[:value] = 1 | |
216 | + ## Perform a vote twice in API should compute only one vote | |
217 | + post "/api/v1/articles/#{article.id}/vote?#{params.to_query}" | |
218 | + post "/api/v1/articles/#{article.id}/vote?#{params.to_query}" | |
219 | + | |
220 | + total = article.votes_total | |
221 | + | |
222 | + assert_equal 1, total | |
223 | + end | |
224 | + | |
225 | + should 'not perform a vote in favor and against a proposal' do | |
226 | + article = fast_create(Article, :profile_id => @person.id, :name => "Some thing") | |
227 | + @params[:value] = 1 | |
228 | + ## Perform a vote in favor a proposal | |
229 | + post "/api/v1/articles/#{article.id}/vote?#{params.to_query}" | |
230 | + json = JSON.parse(last_response.body) | |
231 | + assert_equal 201, last_response.status | |
232 | + ## Perform a vote against a proposal | |
233 | + @params[:value] = -1 | |
234 | + post "/api/v1/articles/#{article.id}/vote?#{params.to_query}" | |
235 | + json = JSON.parse(last_response.body) | |
236 | + ## The api should not allow to save this vote | |
237 | + assert_equal 400, last_response.status | |
238 | + end | |
239 | + | |
193 | 240 | should "update body of article created by me" do |
194 | 241 | new_value = "Another body" |
195 | 242 | params[:article] = {:body => new_value} |
... | ... | @@ -685,7 +732,6 @@ class ArticlesTest < ActiveSupport::TestCase |
685 | 732 | json = JSON.parse(last_response.body) |
686 | 733 | assert_not_nil json['article'][attribute] |
687 | 734 | end |
688 | - | |
689 | 735 | end |
690 | 736 | |
691 | 737 | end | ... | ... |
... | ... | @@ -0,0 +1,42 @@ |
1 | +require_relative 'test_helper' | |
2 | + | |
3 | +class BoxesTest < ActiveSupport::TestCase | |
4 | + | |
5 | + def setup | |
6 | + @controller = AccountController.new | |
7 | + @request = ActionController::TestRequest.new | |
8 | + login_api | |
9 | +# @request = ActionController::TestRequest.new | |
10 | + end | |
11 | + | |
12 | + kinds= %w[Profile Community Person Enterprise Environment] | |
13 | + kinds.each do |kind| | |
14 | + should "get_boxes_from_#{kind.downcase.pluralize}" do | |
15 | + context_obj = fast_create(kind.constantize) | |
16 | + box = fast_create(Box, :owner_id => context_obj.id, :owner_type => (kind == 'Environment') ? 'Environment' : 'Profile') | |
17 | + get "/api/v1/#{kind.downcase.pluralize}/#{context_obj.id}/boxes?#{params.to_query}" | |
18 | + json = JSON.parse(last_response.body) | |
19 | + assert_equal box.id, json["boxes"].first["id"] | |
20 | + end | |
21 | + end | |
22 | + | |
23 | + should 'get boxes from default environment' do | |
24 | + Environment.delete_all | |
25 | + environment = fast_create(Environment, :is_default => true) | |
26 | + box = fast_create(Box, :owner_id => environment.id, :owner_type => 'Environment') | |
27 | + get "/api/v1/environments/default/boxes?#{params.to_query}" | |
28 | + json = JSON.parse(last_response.body) | |
29 | + assert_equal box.id, json["boxes"].first["id"] | |
30 | + end | |
31 | + | |
32 | + should 'get boxes from context environment' do | |
33 | + env = fast_create(Environment, :is_default => true) | |
34 | + env2 = fast_create(Environment).domains << Domain.new(:name => 'test.host') | |
35 | + box = fast_create(Box, :owner_id => environment.id, :owner_type => 'Environment') | |
36 | + get "/api/v1/environments/context/boxes?#{params.to_query}" | |
37 | + | |
38 | + json = JSON.parse(last_response.body) | |
39 | + assert_equal box.id, json["boxes"].first["id"] | |
40 | + end | |
41 | + | |
42 | +end | ... | ... |
... | ... | @@ -0,0 +1,38 @@ |
1 | +require_relative 'test_helper' | |
2 | + | |
3 | +class EnvironmentTest < ActiveSupport::TestCase | |
4 | + | |
5 | + def setup | |
6 | + @person = create_user('testing').person | |
7 | + end | |
8 | + attr_reader :person | |
9 | + | |
10 | + should 'return the default environment' do | |
11 | + environment = Environment.default | |
12 | + get "/api/v1/environment/default" | |
13 | + json = JSON.parse(last_response.body) | |
14 | + assert_equal environment.id, json['id'] | |
15 | + end | |
16 | + | |
17 | + should 'return created environment' do | |
18 | + environment = fast_create(Environment) | |
19 | + default_env = Environment.default | |
20 | + assert_not_equal environment.id, default_env.id | |
21 | + get "/api/v1/environment/#{environment.id}" | |
22 | + json = JSON.parse(last_response.body) | |
23 | + assert_equal environment.id, json['id'] | |
24 | + end | |
25 | + | |
26 | + should 'return context environment' do | |
27 | + context_env = fast_create(Environment) | |
28 | + context_env.name = "example org" | |
29 | + context_env.save | |
30 | + context_env.domains<< Domain.new(:name => 'example.org') | |
31 | + default_env = Environment.default | |
32 | + assert_not_equal context_env.id, default_env.id | |
33 | + get "/api/v1/environment/context" | |
34 | + json = JSON.parse(last_response.body) | |
35 | + assert_equal context_env.id, json['id'] | |
36 | + end | |
37 | + | |
38 | +end | ... | ... |
test/unit/api/helpers_test.rb
... | ... | @@ -205,6 +205,7 @@ class APIHelpersTest < ActiveSupport::TestCase |
205 | 205 | filter_disabled_plugins_endpoints |
206 | 206 | end |
207 | 207 | |
208 | +<<<<<<< HEAD | |
208 | 209 | should 'find all published articles on environment' do |
209 | 210 | #user = create_user('someuser') |
210 | 211 | #p = fast_create(Profile) |
... | ... | @@ -218,6 +219,8 @@ class APIHelpersTest < ActiveSupport::TestCase |
218 | 219 | #assert_equals [article1, article2], present_articles |
219 | 220 | end |
220 | 221 | |
222 | +======= | |
223 | +>>>>>>> master | |
221 | 224 | should 'not touch in options when no fields parameter is passed' do |
222 | 225 | model = mock |
223 | 226 | expects(:present).with(model, {}) | ... | ... |
test/unit/api/people_test.rb
... | ... | @@ -15,6 +15,19 @@ class PeopleTest < ActiveSupport::TestCase |
15 | 15 | assert_equivalent [person1.id, person2.id, person.id], json['people'].map {|c| c['id']} |
16 | 16 | end |
17 | 17 | |
18 | + should 'list all members of a community' do | |
19 | + person1 = fast_create(Person) | |
20 | + person2 = fast_create(Person) | |
21 | + community = fast_create(Community) | |
22 | + community.add_member(person1) | |
23 | + community.add_member(person2) | |
24 | + | |
25 | + get "/api/v1/profiles/#{community.id}/members?#{params.to_query}" | |
26 | + json = JSON.parse(last_response.body) | |
27 | + assert_equal 2, json["people"].count | |
28 | + assert_equivalent [person1.id,person2.id], json["people"].map{|p| p["id"]} | |
29 | + end | |
30 | + | |
18 | 31 | should 'not list invisible people' do |
19 | 32 | invisible_person = fast_create(Person, :visible => false) |
20 | 33 | |
... | ... | @@ -55,14 +68,13 @@ class PeopleTest < ActiveSupport::TestCase |
55 | 68 | end |
56 | 69 | |
57 | 70 | should 'people endpoint filter by fields parameter with hierarchy' do |
58 | - fields = {only: [:name, {user: [:login]}]}.to_json | |
71 | + fields = URI.encode({only: [:name, {user: [:login]}]}.to_json) | |
59 | 72 | get "/api/v1/people?#{params.to_query}&fields=#{fields}" |
60 | 73 | json = JSON.parse(last_response.body) |
61 | 74 | expected = {'people' => [{'name' => person.name, 'user' => {'login' => 'testapi'}}]} |
62 | 75 | assert_equal expected, json |
63 | 76 | end |
64 | 77 | |
65 | - | |
66 | 78 | should 'get logged person' do |
67 | 79 | get "/api/v1/people/me?#{params.to_query}" |
68 | 80 | json = JSON.parse(last_response.body) |
... | ... | @@ -228,7 +240,7 @@ class PeopleTest < ActiveSupport::TestCase |
228 | 240 | assert_equal "www.blog.org", json['person']['additional_data']['Custom Blog'] |
229 | 241 | end |
230 | 242 | |
231 | - PERSON_ATTRIBUTES = %w(vote_count comments_count following_articles_count articles_count) | |
243 | + PERSON_ATTRIBUTES = %w(vote_count comments_count articles_count following_articles_count) | |
232 | 244 | |
233 | 245 | PERSON_ATTRIBUTES.map do |attribute| |
234 | 246 | |
... | ... | @@ -243,7 +255,6 @@ class PeopleTest < ActiveSupport::TestCase |
243 | 255 | json = JSON.parse(last_response.body) |
244 | 256 | assert_not_nil json['person'][attribute] |
245 | 257 | end |
246 | - | |
247 | 258 | end |
248 | 259 | |
249 | 260 | end | ... | ... |
... | ... | @@ -0,0 +1,32 @@ |
1 | +require_relative 'test_helper' | |
2 | + | |
3 | +class ProfilesTest < ActiveSupport::TestCase | |
4 | + | |
5 | + def setup | |
6 | + Profile.delete_all | |
7 | + login_api | |
8 | + end | |
9 | + | |
10 | + should 'list all profiles' do | |
11 | + person1 = fast_create(Person) | |
12 | + person2 = fast_create(Person) | |
13 | + community = fast_create(Community) | |
14 | + get "/api/v1/profiles?#{params.to_query}" | |
15 | + json = JSON.parse(last_response.body) | |
16 | + assert_equivalent [person.id, person1.id, person2.id, community.id], json.map {|p| p['id']} | |
17 | + end | |
18 | + | |
19 | + should 'get person from profile id' do | |
20 | + some_person = fast_create(Person) | |
21 | + get "/api/v1/profiles/#{some_person.id}?#{params.to_query}" | |
22 | + json = JSON.parse(last_response.body) | |
23 | + assert_equal some_person.id, json['id'] | |
24 | + end | |
25 | + | |
26 | + should 'get community from profile id' do | |
27 | + community = fast_create(Community) | |
28 | + get "/api/v1/profiles/#{community.id}?#{params.to_query}" | |
29 | + json = JSON.parse(last_response.body) | |
30 | + assert_equal community.id, json['id'] | |
31 | + end | |
32 | +end | ... | ... |
test/unit/application_helper_test.rb
... | ... | @@ -80,12 +80,6 @@ class ApplicationHelperTest < ActionView::TestCase |
80 | 80 | assert_equal '', show_date(nil) |
81 | 81 | end |
82 | 82 | |
83 | - | |
84 | - should 'append with-text class and keep existing classes' do | |
85 | - expects(:button_without_text).with('type', 'label', 'url', { :class => 'with-text class1'}) | |
86 | - button('type', 'label', 'url', { :class => 'class1' }) | |
87 | - end | |
88 | - | |
89 | 83 | should 'generate correct link to category' do |
90 | 84 | cat = mock |
91 | 85 | cat.expects(:path).returns('my-category/my-subcatagory') |
... | ... | @@ -151,35 +145,6 @@ class ApplicationHelperTest < ActionView::TestCase |
151 | 145 | assert_tag_in_string rolename_for(member2, community), :tag => 'span', :content => 'Profile Administrator' |
152 | 146 | end |
153 | 147 | |
154 | - should 'get theme from environment by default' do | |
155 | - @environment = mock | |
156 | - @environment.stubs(:theme).returns('my-environment-theme') | |
157 | - stubs(:profile).returns(nil) | |
158 | - assert_equal 'my-environment-theme', current_theme | |
159 | - end | |
160 | - | |
161 | - should 'get theme from profile when profile is present' do | |
162 | - profile = mock | |
163 | - profile.stubs(:theme).returns('my-profile-theme') | |
164 | - stubs(:profile).returns(profile) | |
165 | - assert_equal 'my-profile-theme', current_theme | |
166 | - end | |
167 | - | |
168 | - should 'override theme with testing theme from session' do | |
169 | - stubs(:session).returns(:theme => 'theme-under-test') | |
170 | - assert_equal 'theme-under-test', current_theme | |
171 | - end | |
172 | - | |
173 | - should 'point to system theme path by default' do | |
174 | - expects(:current_theme).returns('my-system-theme') | |
175 | - assert_equal '/designs/themes/my-system-theme', theme_path | |
176 | - end | |
177 | - | |
178 | - should 'point to user theme path when testing theme' do | |
179 | - stubs(:session).returns({:theme => 'theme-under-test'}) | |
180 | - assert_equal '/user_themes/theme-under-test', theme_path | |
181 | - end | |
182 | - | |
183 | 148 | should 'render theme footer' do |
184 | 149 | stubs(:theme_path).returns('/user_themes/mytheme') |
185 | 150 | footer_path = Rails.root.join('public', 'user_themes', 'mytheme', 'footer.html.erb') |
... | ... | @@ -301,38 +266,6 @@ class ApplicationHelperTest < ActionView::TestCase |
301 | 266 | assert_nil select_categories(mock) |
302 | 267 | end |
303 | 268 | |
304 | - should 'provide sex icon for males' do | |
305 | - stubs(:environment).returns(Environment.default) | |
306 | - expects(:content_tag).with(anything, 'male').returns('MALE!!') | |
307 | - expects(:content_tag).with(anything, 'MALE!!', is_a(Hash)).returns("FINAL") | |
308 | - assert_equal "FINAL", profile_sex_icon(build(Person, :sex => 'male')) | |
309 | - end | |
310 | - | |
311 | - should 'provide sex icon for females' do | |
312 | - stubs(:environment).returns(Environment.default) | |
313 | - expects(:content_tag).with(anything, 'female').returns('FEMALE!!') | |
314 | - expects(:content_tag).with(anything, 'FEMALE!!', is_a(Hash)).returns("FINAL") | |
315 | - assert_equal "FINAL", profile_sex_icon(build(Person, :sex => 'female')) | |
316 | - end | |
317 | - | |
318 | - should 'provide undef sex icon' do | |
319 | - stubs(:environment).returns(Environment.default) | |
320 | - expects(:content_tag).with(anything, 'undef').returns('UNDEF!!') | |
321 | - expects(:content_tag).with(anything, 'UNDEF!!', is_a(Hash)).returns("FINAL") | |
322 | - assert_equal "FINAL", profile_sex_icon(build(Person, :sex => nil)) | |
323 | - end | |
324 | - | |
325 | - should 'not draw sex icon for non-person profiles' do | |
326 | - assert_equal '', profile_sex_icon(Community.new) | |
327 | - end | |
328 | - | |
329 | - should 'not draw sex icon when disabled in the environment' do | |
330 | - env = fast_create(Environment, :name => 'env test') | |
331 | - env.expects(:enabled?).with('disable_gender_icon').returns(true) | |
332 | - stubs(:environment).returns(env) | |
333 | - assert_equal '', profile_sex_icon(build(Person, :sex => 'male')) | |
334 | - end | |
335 | - | |
336 | 269 | should 'display field on person signup' do |
337 | 270 | env = create(Environment, :name => 'env test') |
338 | 271 | stubs(:environment).returns(env) |
... | ... | @@ -530,19 +463,6 @@ class ApplicationHelperTest < ActionView::TestCase |
530 | 463 | assert_equal Environment.default.name, page_title |
531 | 464 | end |
532 | 465 | |
533 | - should 'gravatar default parameter' do | |
534 | - profile = mock | |
535 | - profile.stubs(:theme).returns('some-theme') | |
536 | - stubs(:profile).returns(profile) | |
537 | - | |
538 | - NOOSFERO_CONF.stubs(:[]).with('gravatar').returns('crazyvatar') | |
539 | - assert_equal gravatar_default, 'crazyvatar' | |
540 | - | |
541 | - stubs(:theme_option).returns('gravatar' => 'nicevatar') | |
542 | - NOOSFERO_CONF.stubs(:[]).with('gravatar').returns('nicevatar') | |
543 | - assert_equal gravatar_default, 'nicevatar' | |
544 | - end | |
545 | - | |
546 | 466 | should 'use theme passed via param when in development mode' do |
547 | 467 | stubs(:environment).returns(build(Environment, :theme => 'environment-theme')) |
548 | 468 | Rails.env.stubs(:development?).returns(true) |
... | ... | @@ -564,48 +484,6 @@ class ApplicationHelperTest < ActionView::TestCase |
564 | 484 | assert_equal environment.theme, current_theme |
565 | 485 | end |
566 | 486 | |
567 | - should 'return nil when :show_balloon_with_profile_links_when_clicked is not enabled in environment' do | |
568 | - env = Environment.default | |
569 | - env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(false) | |
570 | - stubs(:environment).returns(env) | |
571 | - profile = Profile.new | |
572 | - assert_nil links_for_balloon(profile) | |
573 | - end | |
574 | - | |
575 | - should 'return ordered list of links to balloon to Person' do | |
576 | - env = Environment.default | |
577 | - env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(true) | |
578 | - stubs(:environment).returns(env) | |
579 | - person = Person.new identifier: 'person' | |
580 | - person.stubs(:url).returns('url for person') | |
581 | - person.stubs(:public_profile_url).returns('url for person') | |
582 | - links = links_for_balloon(person) | |
583 | - assert_equal ['Wall', 'Friends', 'Communities', 'Send an e-mail', 'Add'], links.map{|i| i.keys.first} | |
584 | - end | |
585 | - | |
586 | - should 'return ordered list of links to balloon to Community' do | |
587 | - env = Environment.default | |
588 | - env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(true) | |
589 | - stubs(:environment).returns(env) | |
590 | - community = Community.new identifier: 'comm' | |
591 | - community.stubs(:url).returns('url for community') | |
592 | - community.stubs(:public_profile_url).returns('url for community') | |
593 | - links = links_for_balloon(community) | |
594 | - assert_equal ['Wall', 'Members', 'Agenda', 'Join', 'Leave community', 'Send an e-mail'], links.map{|i| i.keys.first} | |
595 | - end | |
596 | - | |
597 | - should 'return ordered list of links to balloon to Enterprise' do | |
598 | - env = Environment.default | |
599 | - env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(true) | |
600 | - stubs(:environment).returns(env) | |
601 | - enterprise = Enterprise.new identifier: 'coop' | |
602 | - enterprise.stubs(:url).returns('url for enterprise') | |
603 | - enterprise.stubs(:public_profile_url).returns('url for enterprise') | |
604 | - stubs(:catalog_path) | |
605 | - links = links_for_balloon(enterprise) | |
606 | - assert_equal ['Products', 'Members', 'Agenda', 'Send an e-mail'], links.map{|i| i.keys.first} | |
607 | - end | |
608 | - | |
609 | 487 | should 'use favicon from environment theme if does not have profile' do |
610 | 488 | stubs(:environment).returns(fast_create(Environment, :theme => 'new-theme')) |
611 | 489 | stubs(:profile).returns(nil) |
... | ... | @@ -657,24 +535,6 @@ class ApplicationHelperTest < ActionView::TestCase |
657 | 535 | assert admin_link.present? |
658 | 536 | end |
659 | 537 | |
660 | - should 'not return mime type of profile icon if not requested' do | |
661 | - stubs(:profile).returns(Person.new) | |
662 | - stubs(:current_theme).returns('default') | |
663 | - | |
664 | - filename, mime = profile_icon(Person.new, :thumb) | |
665 | - assert_not_nil filename | |
666 | - assert_nil mime | |
667 | - end | |
668 | - | |
669 | - should 'return mime type of profile icon' do | |
670 | - stubs(:profile).returns(Person.new) | |
671 | - stubs(:current_theme).returns('default') | |
672 | - | |
673 | - filename, mime = profile_icon(Person.new, :thumb, true) | |
674 | - assert_not_nil filename | |
675 | - assert_not_nil mime | |
676 | - end | |
677 | - | |
678 | 538 | should 'pluralize without count' do |
679 | 539 | assert_equal "tests", pluralize_without_count(2, "test") |
680 | 540 | assert_equal "test", pluralize_without_count(1, "test") |
... | ... | @@ -1043,31 +903,6 @@ class ApplicationHelperTest < ActionView::TestCase |
1043 | 903 | assert_equal c.top_url, top_url |
1044 | 904 | end |
1045 | 905 | |
1046 | - should "Extra info with hash" do | |
1047 | - @plugins = mock | |
1048 | - @plugins.stubs(:dispatch_first).returns(false) | |
1049 | - env = Environment.default | |
1050 | - stubs(:environment).returns(env) | |
1051 | - stubs(:profile).returns(profile) | |
1052 | - profile = fast_create(Person, :environment_id => env.id) | |
1053 | - info = {:value =>_('New'), :class => 'new-profile'} | |
1054 | - html = profile_image_link(profile, size=:portrait, tag='li', extra_info = info) | |
1055 | - assert_tag_in_string html, :tag => 'span', :attributes => { :class => 'profile-image new-profile' } | |
1056 | - assert_tag_in_string html, :tag => 'span', :attributes => { :class => 'extra_info new-profile' }, :content => 'New' | |
1057 | - end | |
1058 | - | |
1059 | - should "Extra info without hash" do | |
1060 | - @plugins = mock | |
1061 | - @plugins.stubs(:dispatch_first).returns(false) | |
1062 | - env = Environment.default | |
1063 | - stubs(:environment).returns(env) | |
1064 | - stubs(:profile).returns(profile) | |
1065 | - profile = fast_create(Person, :environment_id => env.id) | |
1066 | - info = 'new' | |
1067 | - html = profile_image_link(profile, size=:portrait, tag='li', extra_info = info) | |
1068 | - assert_tag_in_string html, :tag => 'span', :attributes => { :class => 'extra_info' }, :content => 'new' | |
1069 | - end | |
1070 | - | |
1071 | 906 | protected |
1072 | 907 | include NoosferoTestHelper |
1073 | 908 | ... | ... |
test/unit/article_block_test.rb
... | ... | @@ -7,15 +7,6 @@ class ArticleBlockTest < ActiveSupport::TestCase |
7 | 7 | assert_not_equal Block.description, ArticleBlock.description |
8 | 8 | end |
9 | 9 | |
10 | - should "take article's content" do | |
11 | - block = ArticleBlock.new | |
12 | - article = mock | |
13 | - article.expects(:to_html).returns("Article content") | |
14 | - block.stubs(:article).returns(article) | |
15 | - | |
16 | - assert_match(/Article content/, instance_eval(&block.content)) | |
17 | - end | |
18 | - | |
19 | 10 | should 'refer to an article' do |
20 | 11 | profile = create_user('testuser').person |
21 | 12 | article = profile.articles.build(:name => 'test article') |
... | ... | @@ -85,6 +76,31 @@ class ArticleBlockTest < ActiveSupport::TestCase |
85 | 76 | assert_equal [a],block.available_articles |
86 | 77 | end |
87 | 78 | |
79 | + protected | |
80 | + include NoosferoTestHelper | |
81 | + | |
82 | +end | |
83 | + | |
84 | +require 'boxes_helper' | |
85 | +require 'block_helper' | |
86 | + | |
87 | +class ArticleBlockViewTest < ActionView::TestCase | |
88 | + include BoxesHelper | |
89 | + | |
90 | + ActionView::Base.send :include, ArticleHelper | |
91 | + ActionView::Base.send :include, ButtonsHelper | |
92 | + ActionView::Base.send :include, BlockHelper | |
93 | + | |
94 | + should "take article's content" do | |
95 | + block = ArticleBlock.new | |
96 | + article = mock | |
97 | + article.expects(:to_html).returns("Article content") | |
98 | + block.stubs(:article).returns(article) | |
99 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
100 | + | |
101 | + assert_match(/Article content/, render_block_content(block)) | |
102 | + end | |
103 | + | |
88 | 104 | should "display empty title if title is blank" do |
89 | 105 | block = ArticleBlock.new |
90 | 106 | article = mock |
... | ... | @@ -92,7 +108,7 @@ class ArticleBlockTest < ActiveSupport::TestCase |
92 | 108 | block.expects(:title).returns('') |
93 | 109 | block.stubs(:article).returns(article) |
94 | 110 | |
95 | - assert_equal "<h3 class=\"block-title empty\"><span></span></h3>Article content", instance_eval(&block.content) | |
111 | + assert_equal "<h3 class=\"block-title empty\"><span></span></h3>\n Article content\n", render_block_content(block) | |
96 | 112 | end |
97 | 113 | |
98 | 114 | should "display title if defined" do |
... | ... | @@ -102,7 +118,7 @@ class ArticleBlockTest < ActiveSupport::TestCase |
102 | 118 | block.expects(:title).returns('Article title') |
103 | 119 | block.stubs(:article).returns(article) |
104 | 120 | |
105 | - assert_equal "<h3 class=\"block-title\"><span>Article title</span></h3>Article content", instance_eval(&block.content) | |
121 | + assert_equal "<h3 class=\"block-title\"><span>Article title</span></h3>\n Article content\n", render_block_content(block) | |
106 | 122 | end |
107 | 123 | |
108 | 124 | should 'display image if article is an image' do |
... | ... | @@ -113,7 +129,7 @@ class ArticleBlockTest < ActiveSupport::TestCase |
113 | 129 | block.article = image |
114 | 130 | block.save! |
115 | 131 | |
116 | - assert_tag_in_string instance_eval(&block.content), | |
132 | + assert_tag_in_string render_block_content(block), | |
117 | 133 | :tag => 'img', |
118 | 134 | :attributes => { |
119 | 135 | :src => image.public_filename(:display), |
... | ... | @@ -129,7 +145,7 @@ class ArticleBlockTest < ActiveSupport::TestCase |
129 | 145 | block.article = image |
130 | 146 | block.save! |
131 | 147 | |
132 | - assert_no_match(/Previous/, instance_eval(&block.content)) | |
148 | + assert_no_match(/Previous/, render_block_content(block)) | |
133 | 149 | end |
134 | 150 | |
135 | 151 | should 'display link to archive if article is an archive' do |
... | ... | @@ -141,11 +157,6 @@ class ArticleBlockTest < ActiveSupport::TestCase |
141 | 157 | block.save! |
142 | 158 | |
143 | 159 | UploadedFile.any_instance.stubs(:url).returns('myhost.mydomain/path/to/file') |
144 | - | |
145 | - assert_tag_in_string instance_eval(&block.content), :tag => 'a', :content => _('Download') | |
160 | + assert_tag_in_string render_block_content(block), :tag => 'a', :content => _('Download') | |
146 | 161 | end |
147 | - | |
148 | - protected | |
149 | - include NoosferoTestHelper | |
150 | - | |
151 | 162 | end | ... | ... |
test/unit/blog_archives_block_test.rb
... | ... | @@ -17,6 +17,69 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase |
17 | 17 | assert l.editable? |
18 | 18 | end |
19 | 19 | |
20 | + should 'has field to configure blog' do | |
21 | + b = BlogArchivesBlock.new | |
22 | + assert b.respond_to?(:blog_id) | |
23 | + assert b.respond_to?(:blog_id=) | |
24 | + end | |
25 | + | |
26 | + should 'not try to load a removed blog' do | |
27 | + block = fast_create(BlogArchivesBlock) | |
28 | + block.blog_id = profile.blog.id | |
29 | + block.save! | |
30 | + block.stubs(:owner).returns(profile) | |
31 | + profile.blog.destroy | |
32 | + assert_nothing_raised do | |
33 | + assert_nil block.blog | |
34 | + end | |
35 | + end | |
36 | + | |
37 | + should 'load next blog if configured blog was removed' do | |
38 | + other_blog = fast_create(Blog, :profile_id => profile.id) | |
39 | + block = fast_create(BlogArchivesBlock) | |
40 | + block.blog_id = profile.blog.id | |
41 | + block.save! | |
42 | + block.stubs(:owner).returns(profile) | |
43 | + profile.blog.destroy | |
44 | + assert_nothing_raised do | |
45 | + assert_equal other_blog, block.blog | |
46 | + end | |
47 | + end | |
48 | + | |
49 | +#FIXME Performance issues with display_to. Must convert it to a scope. | |
50 | +# Checkout this page for further information: http://noosfero.org/Development/ActionItem2705 | |
51 | +# | |
52 | +# should 'not count articles if the user can\'t see them' do | |
53 | +# person = create_user('testuser').person | |
54 | +# blog = fast_create(Blog, :profile_id => profile.id, :path => 'blog_path') | |
55 | +# block = fast_create(BlogArchivesBlock) | |
56 | +# | |
57 | +# feed = mock() | |
58 | +# feed.stubs(:url).returns(blog.url) | |
59 | +# blog.stubs(:feed).returns(feed) | |
60 | +# block.stubs(:blog).returns(blog) | |
61 | +# block.stubs(:owner).returns(profile) | |
62 | +# | |
63 | +# public_post = fast_create(TextileArticle, :profile_id => profile.id, :parent_id => blog.id, :published => true, :published_at => Time.mktime(2012, 'jan')) | |
64 | +# private_post = fast_create(TextileArticle, :profile_id => profile.id, :parent_id => blog.id, :published => false, :published_at => Time.mktime(2012, 'jan')) | |
65 | +# | |
66 | +# assert_match /January \(1\)/, block.content({:person => person}) | |
67 | +# assert_match /January \(1\)/, block.content() | |
68 | +# assert_match /January \(2\)/, block.content({:person => profile}) | |
69 | +# end | |
70 | +end | |
71 | + | |
72 | +require 'boxes_helper' | |
73 | + | |
74 | +class BlogArchivesBlockViewTest < ActionView::TestCase | |
75 | + include BoxesHelper | |
76 | + | |
77 | + def setup | |
78 | + @profile = create_user('flatline').person | |
79 | + @profile.articles << Blog.new(:name => 'Blog One', :profile => @profile) | |
80 | + end | |
81 | + attr_reader :profile | |
82 | + | |
20 | 83 | should 'list amount posts by year' do |
21 | 84 | date = DateTime.parse('2008-01-10') |
22 | 85 | blog = profile.blog |
... | ... | @@ -26,7 +89,9 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase |
26 | 89 | end |
27 | 90 | block = BlogArchivesBlock.new |
28 | 91 | block.stubs(:owner).returns(profile) |
29 | - assert_tag_in_string block.content, :tag => 'li', :content => '2008 (10)' | |
92 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
93 | + ActionView::Base.any_instance.stubs(:month_name).returns("") | |
94 | + assert_tag_in_string render_block_content(block), :tag => 'li', :content => '2008 (10)' | |
30 | 95 | end |
31 | 96 | |
32 | 97 | should 'list amount posts by month' do |
... | ... | @@ -38,7 +103,18 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase |
38 | 103 | end |
39 | 104 | block = BlogArchivesBlock.new |
40 | 105 | block.stubs(:owner).returns(profile) |
41 | - assert_tag_in_string block.content, :tag => 'a', :content => 'January (10)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog-one\?month=1&year=2008$/ } | |
106 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
107 | + ActionView::Base.any_instance.stubs(:month_name).with(1).returns("January") | |
108 | + ActionView::Base.any_instance.stubs(:month_name).with(2).returns("February") | |
109 | + ActionView::Base.any_instance.stubs(:month_name).with(3).returns("March") | |
110 | + ActionView::Base.any_instance.stubs(:month_name).with(4).returns("April") | |
111 | + ActionView::Base.any_instance.stubs(:month_name).with(5).returns("May") | |
112 | + ActionView::Base.any_instance.stubs(:month_name).with(6).returns("June") | |
113 | + ActionView::Base.any_instance.stubs(:month_name).with(7).returns("July") | |
114 | + ActionView::Base.any_instance.stubs(:month_name).with(8).returns("August") | |
115 | + ActionView::Base.any_instance.stubs(:month_name).with(9).returns("September") | |
116 | + ActionView::Base.any_instance.stubs(:month_name).with(10).returns("Octuber") | |
117 | + assert_tag_in_string render_block_content(block), :tag => 'a', :content => 'January (10)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog-one\?month=1&year=2008$/ } | |
42 | 118 | end |
43 | 119 | |
44 | 120 | should 'order list of amount posts' do |
... | ... | @@ -49,7 +125,18 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase |
49 | 125 | end |
50 | 126 | block = BlogArchivesBlock.new |
51 | 127 | block.stubs(:owner).returns(profile) |
52 | - assert_tag_in_string block.content, :tag => 'li', :content => 'January (1)', | |
128 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
129 | + ActionView::Base.any_instance.stubs(:month_name).with(1).returns("January") | |
130 | + ActionView::Base.any_instance.stubs(:month_name).with(2).returns("February") | |
131 | + ActionView::Base.any_instance.stubs(:month_name).with(3).returns("March") | |
132 | + ActionView::Base.any_instance.stubs(:month_name).with(4).returns("April") | |
133 | + ActionView::Base.any_instance.stubs(:month_name).with(5).returns("May") | |
134 | + ActionView::Base.any_instance.stubs(:month_name).with(6).returns("June") | |
135 | + ActionView::Base.any_instance.stubs(:month_name).with(7).returns("July") | |
136 | + ActionView::Base.any_instance.stubs(:month_name).with(8).returns("August") | |
137 | + ActionView::Base.any_instance.stubs(:month_name).with(9).returns("September") | |
138 | + ActionView::Base.any_instance.stubs(:month_name).with(10).returns("Octuber") | |
139 | + assert_tag_in_string render_block_content(block), :tag => 'li', :content => 'January (1)', | |
53 | 140 | :sibling => {:tag => 'li', :content => 'February (1)', |
54 | 141 | :sibling => {:tag => 'li', :content => 'March (1)', |
55 | 142 | :sibling => {:tag => 'li', :content => 'April (1)', |
... | ... | @@ -63,7 +150,9 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase |
63 | 150 | end |
64 | 151 | block = BlogArchivesBlock.new |
65 | 152 | block.stubs(:owner).returns(profile) |
66 | - assert_match(/2009.*2008.*2007.*2006.*2005/m, block.content) | |
153 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
154 | + ActionView::Base.any_instance.stubs(:month_name).returns("") | |
155 | + assert_match(/2009.*2008.*2007.*2006.*2005/m, render_block_content(block)) | |
67 | 156 | end |
68 | 157 | |
69 | 158 | should 'order months from later to former' do |
... | ... | @@ -73,20 +162,20 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase |
73 | 162 | end |
74 | 163 | block = BlogArchivesBlock.new |
75 | 164 | block.stubs(:owner).returns(profile) |
76 | - assert_match(/.*March.*February.*January.*/m, block.content) | |
165 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
166 | + ActionView::Base.any_instance.stubs(:month_name).with(1).returns("January") | |
167 | + ActionView::Base.any_instance.stubs(:month_name).with(2).returns("February") | |
168 | + ActionView::Base.any_instance.stubs(:month_name).with(3).returns("March") | |
169 | + assert_match(/.*March.*February.*January.*/m, render_block_content(block)) | |
77 | 170 | end |
78 | 171 | |
79 | 172 | should 'not display any content if has no blog' do |
80 | 173 | profile.blogs.destroy_all |
81 | 174 | block = BlogArchivesBlock.new |
82 | 175 | block.stubs(:owner).returns(profile) |
83 | - assert_nil block.content | |
84 | - end | |
85 | - | |
86 | - should 'has field to configure blog' do | |
87 | - b = BlogArchivesBlock.new | |
88 | - assert b.respond_to?(:blog_id) | |
89 | - assert b.respond_to?(:blog_id=) | |
176 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
177 | + ActionView::Base.any_instance.stubs(:month_name).returns("") | |
178 | + assert_empty render_block_content(block) | |
90 | 179 | end |
91 | 180 | |
92 | 181 | should 'show posts from first blog' do |
... | ... | @@ -98,8 +187,10 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase |
98 | 187 | end |
99 | 188 | block = BlogArchivesBlock.new |
100 | 189 | block.stubs(:owner).returns(profile) |
101 | - assert_match(/blog-one/m, block.content) | |
102 | - assert_no_match(/blog-two/m, block.content) | |
190 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
191 | + ActionView::Base.any_instance.stubs(:month_name).returns("") | |
192 | + assert_match(/blog-one/m, render_block_content(block)) | |
193 | + assert_no_match(/blog-two/m, render_block_content(block)) | |
103 | 194 | end |
104 | 195 | |
105 | 196 | should 'list amount native posts by year' do |
... | ... | @@ -115,7 +206,9 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase |
115 | 206 | end |
116 | 207 | block = BlogArchivesBlock.new |
117 | 208 | block.stubs(:owner).returns(profile) |
118 | - assert_tag_in_string block.content, :tag => 'li', :content => '2008 (2)' | |
209 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
210 | + ActionView::Base.any_instance.stubs(:month_name).returns("") | |
211 | + assert_tag_in_string render_block_content(block), :tag => 'li', :content => '2008 (2)' | |
119 | 212 | end |
120 | 213 | |
121 | 214 | should 'list amount native posts by month' do |
... | ... | @@ -131,51 +224,8 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase |
131 | 224 | end |
132 | 225 | block = BlogArchivesBlock.new |
133 | 226 | block.stubs(:owner).returns(profile) |
134 | - assert_tag_in_string block.content, :tag => 'a', :content => 'January (2)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog-one\?month=1&year=2008$/ } | |
135 | - end | |
136 | - | |
137 | - should 'not try to load a removed blog' do | |
138 | - block = fast_create(BlogArchivesBlock) | |
139 | - block.blog_id = profile.blog.id | |
140 | - block.save! | |
141 | - block.stubs(:owner).returns(profile) | |
142 | - profile.blog.destroy | |
143 | - assert_nothing_raised do | |
144 | - assert_nil block.blog | |
145 | - end | |
227 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
228 | + ActionView::Base.any_instance.stubs(:month_name).with(1).returns("January") | |
229 | + assert_tag_in_string render_block_content(block), :tag => 'a', :content => 'January (2)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog-one\?month=1&year=2008$/ } | |
146 | 230 | end |
147 | - | |
148 | - should 'load next blog if configured blog was removed' do | |
149 | - other_blog = fast_create(Blog, :profile_id => profile.id) | |
150 | - block = fast_create(BlogArchivesBlock) | |
151 | - block.blog_id = profile.blog.id | |
152 | - block.save! | |
153 | - block.stubs(:owner).returns(profile) | |
154 | - profile.blog.destroy | |
155 | - assert_nothing_raised do | |
156 | - assert_equal other_blog, block.blog | |
157 | - end | |
158 | - end | |
159 | - | |
160 | -#FIXME Performance issues with display_to. Must convert it to a scope. | |
161 | -# Checkout this page for further information: http://noosfero.org/Development/ActionItem2705 | |
162 | -# | |
163 | -# should 'not count articles if the user can\'t see them' do | |
164 | -# person = create_user('testuser').person | |
165 | -# blog = fast_create(Blog, :profile_id => profile.id, :path => 'blog_path') | |
166 | -# block = fast_create(BlogArchivesBlock) | |
167 | -# | |
168 | -# feed = mock() | |
169 | -# feed.stubs(:url).returns(blog.url) | |
170 | -# blog.stubs(:feed).returns(feed) | |
171 | -# block.stubs(:blog).returns(blog) | |
172 | -# block.stubs(:owner).returns(profile) | |
173 | -# | |
174 | -# public_post = fast_create(TextileArticle, :profile_id => profile.id, :parent_id => blog.id, :published => true, :published_at => Time.mktime(2012, 'jan')) | |
175 | -# private_post = fast_create(TextileArticle, :profile_id => profile.id, :parent_id => blog.id, :published => false, :published_at => Time.mktime(2012, 'jan')) | |
176 | -# | |
177 | -# assert_match /January \(1\)/, block.content({:person => person}) | |
178 | -# assert_match /January \(1\)/, block.content() | |
179 | -# assert_match /January \(2\)/, block.content({:person => profile}) | |
180 | -# end | |
181 | 231 | end | ... | ... |
test/unit/blog_test.rb
... | ... | @@ -266,4 +266,23 @@ class BlogTest < ActiveSupport::TestCase |
266 | 266 | |
267 | 267 | assert_equal blog.image(true).filename, 'noosfero-network.png' |
268 | 268 | end |
269 | + | |
270 | + should 'count total number of posts by year' do | |
271 | + p = create_user('testuser').person | |
272 | + blog = fast_create(Blog, :profile_id => p.id, :name => 'Blog test') | |
273 | + create(TextileArticle, :name => 'Post 1', :parent => blog, :profile => p, :published_at => DateTime.parse('16-08-2010')) | |
274 | + create(TextileArticle, :name => 'Post 2', :parent => blog, :profile => p, :published_at => DateTime.parse('17-08-2010')) | |
275 | + create(TextileArticle, :name => 'Post 3', :parent => blog, :profile => p, :published_at => DateTime.parse('10-05-2012')) | |
276 | + assert_equal [[2012.0, 1], [2010.0, 2]], blog.total_number_of_posts(:by_year) | |
277 | + end | |
278 | + | |
279 | + should 'count total number of posts by month' do | |
280 | + p = create_user('testuser').person | |
281 | + blog = fast_create(Blog, :profile_id => p.id, :name => 'Blog test') | |
282 | + create(TextileArticle, :name => 'Post 1', :parent => blog, :profile => p, :published_at => DateTime.parse('16-08-2010')) | |
283 | + create(TextileArticle, :name => 'Post 2', :parent => blog, :profile => p, :published_at => DateTime.parse('17-08-2010')) | |
284 | + create(TextileArticle, :name => 'Post 3', :parent => blog, :profile => p, :published_at => DateTime.parse('11-10-2010')) | |
285 | + assert_equal [[10.0, 1], [8.0, 2]], blog.total_number_of_posts(:by_month, 2010) | |
286 | + end | |
287 | + | |
269 | 288 | end | ... | ... |
... | ... | @@ -0,0 +1,11 @@ |
1 | +# encoding: UTF-8 | |
2 | +require_relative "../test_helper" | |
3 | + | |
4 | +class ButtonsHelperTest < ActionView::TestCase | |
5 | + include ButtonsHelper | |
6 | + | |
7 | + should 'append with-text class and keep existing classes' do | |
8 | + expects(:button_without_text).with('type', 'label', 'url', { :class => 'with-text class1'}) | |
9 | + button('type', 'label', 'url', { :class => 'class1' }) | |
10 | + end | |
11 | +end | |
0 | 12 | \ No newline at end of file | ... | ... |
test/unit/categories_block_test.rb
... | ... | @@ -17,11 +17,13 @@ class CategoriesBlockTest < ActiveSupport::TestCase |
17 | 17 | assert_not_nil category_block.help |
18 | 18 | end |
19 | 19 | |
20 | + include BoxesHelper | |
21 | + | |
20 | 22 | should 'display category block' do |
21 | 23 | block = CategoriesBlock.new |
22 | 24 | |
23 | - self.expects(:render).with(:file => 'blocks/categories', :locals => { :block => block}) | |
24 | - instance_eval(& block.content) | |
25 | + self.expects(:render).with(template: 'blocks/categories', locals: {block: block}) | |
26 | + render_block_content(block) | |
25 | 27 | end |
26 | 28 | |
27 | 29 | should 'be editable' do | ... | ... |
test/unit/communities_block_test.rb
... | ... | @@ -36,14 +36,44 @@ class CommunitiesBlockTest < ActiveSupport::TestCase |
36 | 36 | assert_same list, block.profiles |
37 | 37 | end |
38 | 38 | |
39 | + should 'list non-public communities' do | |
40 | + user = create_user('testuser').person | |
41 | + | |
42 | + public_community = fast_create(Community, :environment_id => Environment.default.id) | |
43 | + public_community.add_member(user) | |
44 | + | |
45 | + private_community = fast_create(Community, :environment_id => Environment.default.id, :public_profile => false) | |
46 | + private_community.add_member(user) | |
47 | + | |
48 | + block = CommunitiesBlock.new | |
49 | + block.expects(:owner).at_least_once.returns(user) | |
50 | + | |
51 | + assert_equivalent [public_community, private_community], block.profiles | |
52 | + end | |
53 | + | |
54 | +end | |
55 | + | |
56 | +require 'boxes_helper' | |
57 | + | |
58 | +class CommunitiesBlockViewTest < ActionView::TestCase | |
59 | + include BoxesHelper | |
60 | + | |
39 | 61 | should 'support profile as block owner' do |
40 | 62 | profile = Profile.new |
63 | + profile.identifier = 42 | |
64 | + | |
65 | + ActionView::Base.any_instance.stubs(:user).with(anything).returns(profile) | |
66 | + ActionView::Base.any_instance.stubs(:profile).with(anything).returns(profile) | |
41 | 67 | |
42 | 68 | block = CommunitiesBlock.new |
43 | 69 | block.expects(:owner).returns(profile).at_least_once |
44 | 70 | |
45 | - self.expects(:render).with(:file => 'blocks/communities', :locals => { :owner => profile, :suggestions => block.suggestions }) | |
46 | - instance_eval(&block.footer) | |
71 | + footer = render_block_footer(block) | |
72 | + | |
73 | + assert_tag_in_string footer, tag: 'a', attributes: {href: '/profile/42/communities'} | |
74 | + | |
75 | + ActionView::Base.any_instance.unstub(:user) | |
76 | + ActionView::Base.any_instance.unstub(:profile) | |
47 | 77 | end |
48 | 78 | |
49 | 79 | should 'support environment as block owner' do |
... | ... | @@ -51,31 +81,24 @@ class CommunitiesBlockTest < ActiveSupport::TestCase |
51 | 81 | block = CommunitiesBlock.new |
52 | 82 | block.expects(:owner).returns(env).at_least_once |
53 | 83 | |
54 | - self.expects(:render).with(:file => 'blocks/communities', :locals => { :owner => env, :suggestions => block.suggestions }) | |
55 | - instance_eval(&block.footer) | |
56 | - end | |
57 | - | |
58 | - should 'give empty footer on unsupported owner type' do | |
59 | - block = CommunitiesBlock.new | |
60 | - block.expects(:owner).returns(1).at_least_once | |
84 | + profile = Profile.new | |
85 | + profile.identifier = 42 | |
61 | 86 | |
62 | - self.expects(:render).with(anything).never | |
63 | - assert_equal '', block.footer | |
64 | - end | |
87 | + ActionView::Base.any_instance.stubs(:user).with(anything).returns(profile) | |
88 | + ActionView::Base.any_instance.stubs(:profile).with(anything).returns(profile) | |
65 | 89 | |
66 | - should 'list non-public communities' do | |
67 | - user = create_user('testuser').person | |
90 | + footer = render_block_footer(block) | |
68 | 91 | |
69 | - public_community = fast_create(Community, :environment_id => Environment.default.id) | |
70 | - public_community.add_member(user) | |
92 | + assert_tag_in_string footer, tag: 'a', attributes: {href: '/search/communities'} | |
71 | 93 | |
72 | - private_community = fast_create(Community, :environment_id => Environment.default.id, :public_profile => false) | |
73 | - private_community.add_member(user) | |
94 | + ActionView::Base.any_instance.unstub(:user) | |
95 | + ActionView::Base.any_instance.unstub(:profile) | |
96 | + end | |
74 | 97 | |
98 | + should 'give empty footer on unsupported owner type' do | |
75 | 99 | block = CommunitiesBlock.new |
76 | - block.expects(:owner).at_least_once.returns(user) | |
100 | + block.expects(:owner).returns(1).at_least_once | |
77 | 101 | |
78 | - assert_equivalent [public_community, private_community], block.profiles | |
102 | + assert_equal '', render_block_footer(block) | |
79 | 103 | end |
80 | - | |
81 | 104 | end | ... | ... |
test/unit/community_test.rb
... | ... | @@ -3,7 +3,8 @@ require_relative "../test_helper" |
3 | 3 | class CommunityTest < ActiveSupport::TestCase |
4 | 4 | |
5 | 5 | def setup |
6 | - @person = fast_create(Person) | |
6 | + @user = User.current = create_user | |
7 | + @person = @user.person | |
7 | 8 | end |
8 | 9 | |
9 | 10 | attr_reader :person |
... | ... | @@ -287,8 +288,8 @@ class CommunityTest < ActiveSupport::TestCase |
287 | 288 | |
288 | 289 | should "update the action of article creation when an community's article is commented" do |
289 | 290 | ActionTrackerNotification.delete_all |
290 | - p1 = Person.first | |
291 | 291 | community = fast_create(Community) |
292 | + p1 = person | |
292 | 293 | p2 = create_user.person |
293 | 294 | p3 = create_user.person |
294 | 295 | community.add_member(p3) | ... | ... |
test/unit/disabled_enterprise_message_block_test.rb
... | ... | @@ -6,16 +6,30 @@ class DisabledEnterpriseMessageBlockTest < ActiveSupport::TestCase |
6 | 6 | assert_not_equal Block.description, DisabledEnterpriseMessageBlock.description |
7 | 7 | end |
8 | 8 | |
9 | + include BoxesHelper | |
10 | + | |
9 | 11 | should 'display message for disabled enterprise' do |
10 | - e = Environment.default | |
11 | - e.expects(:message_for_disabled_enterprise).returns('This message is for disabled enterprises') | |
12 | - block = DisabledEnterpriseMessageBlock.new | |
13 | - p = Profile.new | |
14 | - block.expects(:owner).returns(p) | |
15 | - p.expects(:environment).returns(e) | |
16 | - | |
17 | - expects(:render).with(:file => 'blocks/disabled_enterprise_message', :locals => { :message => 'This message is for disabled enterprises'}) | |
18 | - instance_eval(&block.content) | |
12 | + environment = Environment.default | |
13 | + environment.message_for_disabled_enterprise = 'This message is for disabled enterprises' | |
14 | + environment.save | |
15 | + | |
16 | + enterprise = fast_create(Enterprise, :identifier => 'disabled-enterprise', :environment_id => environment.id) | |
17 | + enterprise.boxes << Box.new | |
18 | + enterprise.boxes.first.blocks << DisabledEnterpriseMessageBlock.new | |
19 | + block = enterprise.boxes.first.blocks.first | |
20 | + | |
21 | + ApplicationHelper.class_eval do | |
22 | + alias_method :original_profile, :profile | |
23 | + def profile | |
24 | + return Enterprise['disabled-enterprise'] | |
25 | + end | |
26 | + end | |
27 | + | |
28 | + assert_match 'This message is for disabled enterprises', render_block_content(block) | |
29 | + | |
30 | + ApplicationHelper.class_eval do | |
31 | + alias_method :profile, :original_profile | |
32 | + end | |
19 | 33 | end |
20 | 34 | |
21 | 35 | should 'not be editable' do | ... | ... |
test/unit/enterprises_block_test.rb
... | ... | @@ -27,32 +27,6 @@ class EnterprisesBlockTest < ActiveSupport::TestCase |
27 | 27 | assert_same list, block.profiles |
28 | 28 | end |
29 | 29 | |
30 | - should 'link to all enterprises for profile' do | |
31 | - profile = Profile.new | |
32 | - profile.expects(:identifier).returns('theprofile') | |
33 | - block = EnterprisesBlock.new | |
34 | - block.expects(:owner).returns(profile) | |
35 | - | |
36 | - expects(:link_to).with('View all', :controller => 'profile', :profile => 'theprofile', :action => 'enterprises') | |
37 | - | |
38 | - instance_eval(&block.footer) | |
39 | - end | |
40 | - | |
41 | - should 'link to all enterprises for environment' do | |
42 | - env = Environment.default | |
43 | - block = EnterprisesBlock.new | |
44 | - block.expects(:owner).returns(env) | |
45 | - | |
46 | - expects(:link_to).with('View all', :controller => 'search', :action => 'assets', :asset => 'enterprises') | |
47 | - instance_eval(&block.footer) | |
48 | - end | |
49 | - | |
50 | - should 'give empty footer for unsupported owner type' do | |
51 | - block = EnterprisesBlock.new | |
52 | - block.expects(:owner).returns(1) | |
53 | - assert_equal '', block.footer | |
54 | - end | |
55 | - | |
56 | 30 | should 'count number of owner enterprises' do |
57 | 31 | user = create_user('testuser').person |
58 | 32 | |
... | ... | @@ -71,3 +45,35 @@ class EnterprisesBlockTest < ActiveSupport::TestCase |
71 | 45 | end |
72 | 46 | |
73 | 47 | end |
48 | + | |
49 | +require 'boxes_helper' | |
50 | + | |
51 | +class EnterprisesBlockViewTest < ActionView::TestCase | |
52 | + include BoxesHelper | |
53 | + | |
54 | + should 'link to all enterprises for profile' do | |
55 | + profile = Profile.new | |
56 | + profile.identifier = 'theprofile' | |
57 | + block = EnterprisesBlock.new | |
58 | + block.expects(:owner).twice.returns(profile) | |
59 | + | |
60 | + ActionView::Base.any_instance.expects(:link_to).with('View all', :controller => 'profile', :profile => 'theprofile', :action => 'enterprises') | |
61 | + | |
62 | + render_block_footer(block) | |
63 | + end | |
64 | + | |
65 | + should 'link to all enterprises for environment' do | |
66 | + env = Environment.default | |
67 | + block = EnterprisesBlock.new | |
68 | + block.expects(:owner).twice.returns(env) | |
69 | + | |
70 | + ActionView::Base.any_instance.expects(:link_to).with('View all', :controller => 'search', :action => 'assets', :asset => 'enterprises') | |
71 | + render_block_footer(block) | |
72 | + end | |
73 | + | |
74 | + should 'give empty footer for unsupported owner type' do | |
75 | + block = EnterprisesBlock.new | |
76 | + block.expects(:owner).twice.returns(1) | |
77 | + assert_equal '', render_block_footer(block) | |
78 | + end | |
79 | +end | ... | ... |
test/unit/featured_products_block_test.rb
1 | 1 | require_relative "../test_helper" |
2 | +require 'boxes_helper' | |
2 | 3 | |
3 | 4 | class FeaturedProductsBlockTest < ActiveSupport::TestCase |
5 | + include BoxesHelper | |
4 | 6 | |
5 | 7 | def setup |
6 | 8 | @profile = fast_create(Profile) |
... | ... | @@ -107,8 +109,8 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase |
107 | 109 | should 'display feature products block' do |
108 | 110 | block = FeaturedProductsBlock.new |
109 | 111 | |
110 | - self.expects(:render).with(:file => 'blocks/featured_products', :locals => { :block => block}) | |
111 | - instance_eval(& block.content) | |
112 | + self.expects(:render).with(template: 'blocks/featured_products', locals: {block: block}) | |
113 | + render_block_content(block) | |
112 | 114 | end |
113 | 115 | |
114 | 116 | should "return just highlighted products with image for selection" do | ... | ... |
test/unit/feed_reader_block_test.rb
... | ... | @@ -26,19 +26,6 @@ class FeedReaderBlockTest < ActiveSupport::TestCase |
26 | 26 | assert feed.editable? |
27 | 27 | end |
28 | 28 | |
29 | - should 'display feed posts from content' do | |
30 | - feed.feed_items = [] | |
31 | - %w[ last-post second-post first-post ].each do |i| | |
32 | - feed.feed_items << {:title => i, :link => "http://localhost/#{i}"} | |
33 | - end | |
34 | - feed.feed_title = 'Feed for unit tests' | |
35 | - feed_content = feed.content | |
36 | - assert_tag_in_string feed_content, :tag => 'h3', :content => 'Feed for unit tests' | |
37 | - assert_tag_in_string feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/last-post' }, :content => 'last-post' | |
38 | - assert_tag_in_string feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/second-post' }, :content => 'second-post' | |
39 | - assert_tag_in_string feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/first-post' }, :content => 'first-post' | |
40 | - end | |
41 | - | |
42 | 29 | should 'display channel title as title by default' do |
43 | 30 | feed.feed_title = 'Feed for unit tests' |
44 | 31 | assert_equal 'Feed for unit tests', feed.title |
... | ... | @@ -48,17 +35,6 @@ class FeedReaderBlockTest < ActiveSupport::TestCase |
48 | 35 | assert_equal 'Feed Reader', feed.title |
49 | 36 | end |
50 | 37 | |
51 | - should 'notice when content not fetched yet' do | |
52 | - assert_equal'Feed content was not loaded yet', feed.footer | |
53 | - end | |
54 | - | |
55 | - should 'display last fetched date' do | |
56 | - now = Time.new(2014,1,1) | |
57 | - feed.feed_items = ['one', 'two'] | |
58 | - feed.fetched_at = now | |
59 | - assert_equal "Updated: #{show_date(now)}", feed.footer | |
60 | - end | |
61 | - | |
62 | 38 | should 'clear feed title and items' do |
63 | 39 | feed.feed_items = %w[ last-post second-post first-post ] |
64 | 40 | feed.feed_title = 'Feed Test' |
... | ... | @@ -90,26 +66,10 @@ class FeedReaderBlockTest < ActiveSupport::TestCase |
90 | 66 | assert_equal %w[ last-post second-post first-post ], feed.feed_items.map{|i|i[:title]} |
91 | 67 | end |
92 | 68 | |
93 | - should 'display only limit posts' do | |
94 | - feed.limit = 1; feed.save! | |
95 | - %w[ first-post second-post ].each do |i| | |
96 | - feed.add_item(i, "http://localhost/#{i}", Date.today, "some contet for #{i}") | |
97 | - end | |
98 | - | |
99 | - assert_tag_in_string feed.formatted_feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/second-post' }, :content => 'second-post' | |
100 | - assert_no_tag_in_string feed.formatted_feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/first-post' }, :content => 'first-post' | |
101 | - end | |
102 | - | |
103 | 69 | should 'have empty error message by default' do |
104 | 70 | assert FeedReaderBlock.new.error_message.blank?, 'new feed reader block expected to have empty error message' |
105 | 71 | end |
106 | 72 | |
107 | - should "display error message as content when it's the case" do | |
108 | - msg = "there was a problem" | |
109 | - feed.error_message = msg | |
110 | - assert_match(msg, feed.content) | |
111 | - end | |
112 | - | |
113 | 73 | should 'expire after a period' do |
114 | 74 | # save current time |
115 | 75 | now = Time.now |
... | ... | @@ -195,3 +155,67 @@ class FeedReaderBlockTest < ActiveSupport::TestCase |
195 | 155 | end |
196 | 156 | |
197 | 157 | end |
158 | + | |
159 | +require 'boxes_helper' | |
160 | +require 'block_helper' | |
161 | +require 'dates_helper' | |
162 | + | |
163 | +class FeedReaderBlockViewTest < ActionView::TestCase | |
164 | + include BoxesHelper | |
165 | + include DatesHelper | |
166 | + | |
167 | + ActionView::Base.send :include, BlockHelper | |
168 | + ActionView::Base.send :include, DatesHelper | |
169 | + | |
170 | + def setup | |
171 | + @feed = create(:feed_reader_block) | |
172 | + end | |
173 | + attr_reader :feed | |
174 | + | |
175 | + should "display error message as content when it's the case" do | |
176 | + msg = "there was a problem" | |
177 | + feed.error_message = msg | |
178 | + | |
179 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
180 | + | |
181 | + assert_match(msg, render_block_content(feed)) | |
182 | + end | |
183 | + | |
184 | + should 'display feed posts from content' do | |
185 | + feed.feed_items = [] | |
186 | + %w[ last-post second-post first-post ].each do |i| | |
187 | + feed.feed_items << {:title => i, :link => "http://localhost/#{i}"} | |
188 | + end | |
189 | + feed.feed_title = 'Feed for unit tests' | |
190 | + | |
191 | + feed_content = render_block_content(feed) | |
192 | + | |
193 | + assert_tag_in_string feed_content, :tag => 'h3', :content => 'Feed for unit tests' | |
194 | + assert_tag_in_string feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/last-post' }, :content => 'last-post' | |
195 | + assert_tag_in_string feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/second-post' }, :content => 'second-post' | |
196 | + assert_tag_in_string feed_content, :tag => 'a', :attributes => { :href => 'http://localhost/first-post' }, :content => 'first-post' | |
197 | + end | |
198 | + | |
199 | + should 'display only limit posts' do | |
200 | + feed.limit = 1; feed.save! | |
201 | + %w[ first-post second-post ].each do |i| | |
202 | + feed.add_item(i, "http://localhost/#{i}", Date.today, "some contet for #{i}") | |
203 | + end | |
204 | + | |
205 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
206 | + | |
207 | + assert_tag_in_string render_block_content(feed), :tag => 'a', :attributes => { :href => 'http://localhost/second-post' }, :content => 'second-post' | |
208 | + assert_no_tag_in_string render_block_content(feed), :tag => 'a', :attributes => { :href => 'http://localhost/first-post' }, :content => 'first-post' | |
209 | + end | |
210 | + | |
211 | + should 'notice when content not fetched yet' do | |
212 | + assert_equal " Feed content was not loaded yet\n", render_block_footer(feed) | |
213 | + end | |
214 | + | |
215 | + should 'display last fetched date' do | |
216 | + now = Time.new(2014,1,1) | |
217 | + feed.feed_items = ['one', 'two'] | |
218 | + feed.fetched_at = now | |
219 | + assert_equal " Updated: #{show_date(now)}\n", render_block_footer(feed) | |
220 | + end | |
221 | +end | ... | ... |
test/unit/highlights_block_test.rb
... | ... | @@ -80,11 +80,13 @@ class HighlightsBlockTest < ActiveSupport::TestCase |
80 | 80 | assert_equal 'always', block.display |
81 | 81 | end |
82 | 82 | |
83 | + include BoxesHelper | |
84 | + | |
83 | 85 | should 'display highlights block' do |
84 | 86 | block = HighlightsBlock.new |
85 | - self.expects(:render).with(:file => 'blocks/highlights', :locals => { :block => block}) | |
87 | + self.expects(:render).with(template: 'blocks/highlights', locals: {block: block}) | |
86 | 88 | |
87 | - instance_eval(& block.content) | |
89 | + render_block_content(block) | |
88 | 90 | end |
89 | 91 | |
90 | 92 | should 'not list non existent image' do |
... | ... | @@ -167,7 +169,7 @@ class HighlightsBlockTest < ActiveSupport::TestCase |
167 | 169 | block.images = [i1] |
168 | 170 | block.save! |
169 | 171 | |
170 | - assert_tag_in_string instance_eval(& block.content), :tag => 'img', :attributes => { :src => "/social/img_address" } | |
172 | + assert_tag_in_string render_block_content(block), :tag => 'img', :attributes => { :src => "/social/img_address" } | |
171 | 173 | end |
172 | 174 | |
173 | 175 | [Environment, Profile].each do |klass| | ... | ... |
test/unit/link_list_block_test.rb
... | ... | @@ -2,6 +2,8 @@ require_relative "../test_helper" |
2 | 2 | |
3 | 3 | class LinkListBlockTest < ActiveSupport::TestCase |
4 | 4 | |
5 | + include BoxesHelper | |
6 | + | |
5 | 7 | should 'default describe' do |
6 | 8 | assert_not_equal Block.description, LinkListBlock.description |
7 | 9 | end |
... | ... | @@ -23,7 +25,7 @@ class LinkListBlockTest < ActiveSupport::TestCase |
23 | 25 | |
24 | 26 | should 'list links' do |
25 | 27 | l = LinkListBlock.new(:links => [{:name => 'products', :address => '/cat/products'}]) |
26 | - assert_match /products/, l.content | |
28 | + assert_match /products/, render_block_content(l) | |
27 | 29 | end |
28 | 30 | |
29 | 31 | should 'remove links with blank fields' do |
... | ... | @@ -36,7 +38,7 @@ class LinkListBlockTest < ActiveSupport::TestCase |
36 | 38 | profile = Profile.new(:identifier => 'test_profile') |
37 | 39 | l = LinkListBlock.new(:links => [{:name => 'categ', :address => '/{profile}/address'}]) |
38 | 40 | l.stubs(:owner).returns(profile) |
39 | - assert_tag_in_string l.content, :tag => 'a', :attributes => {:href => '/test_profile/address'} | |
41 | + assert_tag_in_string render_block_content(l), :tag => 'a', :attributes => {:href => '/test_profile/address'} | |
40 | 42 | end |
41 | 43 | |
42 | 44 | should 'replace {portal} with environment portal identifier' do |
... | ... | @@ -49,7 +51,7 @@ class LinkListBlockTest < ActiveSupport::TestCase |
49 | 51 | stubs(:environment).returns(env) |
50 | 52 | l = LinkListBlock.new(:links => [{:name => 'categ', :address => '/{portal}/address'}]) |
51 | 53 | l.stubs(:owner).returns(env) |
52 | - assert_tag_in_string l.content, :tag => 'a', :attributes => {:href => '/portal-community/address'} | |
54 | + assert_tag_in_string render_block_content(l), :tag => 'a', :attributes => {:href => '/portal-community/address'} | |
53 | 55 | end |
54 | 56 | |
55 | 57 | should 'not change address if no {portal} there' do |
... | ... | @@ -62,19 +64,19 @@ class LinkListBlockTest < ActiveSupport::TestCase |
62 | 64 | stubs(:environment).returns(env) |
63 | 65 | l = LinkListBlock.new(:links => [{:name => 'categ', :address => '/address'}]) |
64 | 66 | l.stubs(:owner).returns(env) |
65 | - assert_tag_in_string l.content, :tag => 'a', :attributes => {:href => '/address'} | |
67 | + assert_tag_in_string render_block_content(l), :tag => 'a', :attributes => {:href => '/address'} | |
66 | 68 | end |
67 | 69 | |
68 | 70 | should 'handle /prefix if not already added' do |
69 | 71 | Noosfero.stubs(:root).returns('/prefix') |
70 | 72 | l = LinkListBlock.new(:links => [{:name => "foo", :address => '/bar'}] ) |
71 | - assert_tag_in_string l.content, :tag => 'a', :attributes => { :href => '/prefix/bar' } | |
73 | + assert_tag_in_string render_block_content(l), :tag => 'a', :attributes => { :href => '/prefix/bar' } | |
72 | 74 | end |
73 | 75 | |
74 | 76 | should 'not add /prefix if already there' do |
75 | 77 | Noosfero.stubs(:root).returns('/prefix') |
76 | 78 | l = LinkListBlock.new(:links => [{:name => "foo", :address => '/prefix/bar'}] ) |
77 | - assert_tag_in_string l.content, :tag => 'a', :attributes => { :href => '/prefix/bar' } | |
79 | + assert_tag_in_string render_block_content(l), :tag => 'a', :attributes => { :href => '/prefix/bar' } | |
78 | 80 | end |
79 | 81 | |
80 | 82 | should 'display options for icons' do |
... | ... | @@ -85,29 +87,29 @@ class LinkListBlockTest < ActiveSupport::TestCase |
85 | 87 | end |
86 | 88 | |
87 | 89 | should 'link with icon' do |
88 | - l = LinkListBlock.new | |
89 | - assert_match /class="icon-save"/, l.link_html({:icon => 'save', :name => 'test', :address => 'test.com'}) | |
90 | + l = LinkListBlock.new(:links => [{:icon => 'save', :name => 'test', :address => 'test.com'}]) | |
91 | + assert_match /a class="icon-[^"]+"/, render_block_content(l) | |
90 | 92 | end |
91 | 93 | |
92 | 94 | should 'no class without icon' do |
93 | - l = LinkListBlock.new | |
94 | - assert_no_match /class="/, l.link_html({:icon => nil, :name => 'test', :address => 'test.com'}) | |
95 | + l = LinkListBlock.new(:links => [{:icon => nil, :name => 'test', :address => 'test.com'}]) | |
96 | + assert_no_match /a class="icon-[^"]+"/, render_block_content(l) | |
95 | 97 | end |
96 | 98 | |
97 | 99 | should 'not add link to javascript' do |
98 | 100 | l = LinkListBlock.new(:links => [{:name => 'link', :address => "javascript:alert('Message test')"}]) |
99 | - assert_no_match /href="javascript/, l.link_html(l.links.first) | |
101 | + assert_no_match /href="javascript/, render_block_content(l) | |
100 | 102 | end |
101 | 103 | |
102 | 104 | should 'not add link to onclick' do |
103 | 105 | l = LinkListBlock.new(:links => [{:name => 'link', :address => "#\" onclick=\"alert(123456)"}]) |
104 | - assert_no_tag_in_string l.link_html(l.links.first), :attributes => { :onclick => /.*/ } | |
106 | + assert_no_tag_in_string render_block_content(l), :attributes => { :onclick => /.*/ } | |
105 | 107 | end |
106 | 108 | |
107 | 109 | should 'add protocol in front of incomplete external links' do |
108 | 110 | {'/local/link' => '/local/link', 'http://example.org' => 'http://example.org', 'example.org' => '//example.org'}.each do |input, output| |
109 | 111 | l = LinkListBlock.new(:links => [{:name => 'categ', :address => input}]) |
110 | - assert_tag_in_string l.content, :tag => 'a', :attributes => {:href => output} | |
112 | + assert_tag_in_string render_block_content(l), :tag => 'a', :attributes => {:href => output} | |
111 | 113 | end |
112 | 114 | end |
113 | 115 | |
... | ... | @@ -128,7 +130,13 @@ class LinkListBlockTest < ActiveSupport::TestCase |
128 | 130 | |
129 | 131 | should 'link with title' do |
130 | 132 | l = LinkListBlock.new |
131 | - assert_match /title="mytitle"/, l.link_html({:name => 'mylink', :address => '/myaddress', :title => 'mytitle'}) | |
133 | + l = LinkListBlock.new(:links => [{:name => 'mylink', :address => '/myaddress', :title => 'mytitle'}]) | |
134 | + assert_match /title="mytitle"/, render_block_content(l) | |
135 | + end | |
136 | + | |
137 | + should 'display default message to brand new blocks with no links' do | |
138 | + l = LinkListBlock.new | |
139 | + assert_match /Please, edit this block to add links/, render_block_content(l) | |
132 | 140 | end |
133 | 141 | |
134 | 142 | end | ... | ... |
test/unit/location_block_test.rb
... | ... | @@ -18,7 +18,7 @@ class LocationBlockTest < ActiveSupport::TestCase |
18 | 18 | end |
19 | 19 | |
20 | 20 | should 'display no localization map without lat' do |
21 | - assert_tag_in_string extract_block_content(block.content), :tag => 'i' | |
21 | + assert_tag_in_string extract_block_content(render_block_content(block)), :tag => 'i' | |
22 | 22 | end |
23 | 23 | |
24 | 24 | should 'be editable' do |
... | ... | @@ -31,7 +31,7 @@ class LocationBlockTest < ActiveSupport::TestCase |
31 | 31 | |
32 | 32 | should 'use google maps api v3 with ssl' do |
33 | 33 | @block.owner.lat = '-12.34'; @block.owner.save! |
34 | - content = extract_block_content(@block.content) | |
34 | + content = extract_block_content(render_block_content(@block)) | |
35 | 35 | |
36 | 36 | assert_match 'https://maps.google.com/maps/api/staticmap', content |
37 | 37 | assert_no_match /key=/, content | ... | ... |
test/unit/manage_products_helper_test.rb
... | ... | @@ -5,6 +5,7 @@ class ManageProductsHelperTest < ActionView::TestCase |
5 | 5 | |
6 | 6 | include ManageProductsHelper |
7 | 7 | include ContentViewerHelper |
8 | + include ArticleHelper | |
8 | 9 | include ActionView::Helpers::AssetTagHelper |
9 | 10 | include ApplicationHelper |
10 | 11 | |
... | ... | @@ -43,7 +44,7 @@ class ManageProductsHelperTest < ActionView::TestCase |
43 | 44 | end |
44 | 45 | |
45 | 46 | should 'display link to edit product when user has permission' do |
46 | - user = mock | |
47 | + user = User.new(:email => 'display-link@email.invalid.com') | |
47 | 48 | user.expects(:has_permission?).with(anything, anything).returns(true) |
48 | 49 | @controller = mock |
49 | 50 | @controller.expects(:user).returns(user).at_least_once |
... | ... | @@ -57,7 +58,7 @@ class ManageProductsHelperTest < ActionView::TestCase |
57 | 58 | end |
58 | 59 | |
59 | 60 | should 'not display link to edit product category when user does not have permission' do |
60 | - user = mock | |
61 | + user = User.new(:email => 'not-display-link@email.invalid.com') | |
61 | 62 | user.expects(:has_permission?).with(anything, anything).returns(false) |
62 | 63 | @controller = mock |
63 | 64 | @controller.expects(:user).returns(user).at_least_once |
... | ... | @@ -68,7 +69,7 @@ class ManageProductsHelperTest < ActionView::TestCase |
68 | 69 | end |
69 | 70 | |
70 | 71 | should 'display link to edit product category when user has permission' do |
71 | - user = mock | |
72 | + user = User.new(:email => 'display-link@email.invalid.com') | |
72 | 73 | user.expects(:has_permission?).with(anything, anything).returns(true) |
73 | 74 | @controller = mock |
74 | 75 | @controller.expects(:user).returns(user).at_least_once |
... | ... | @@ -82,7 +83,7 @@ class ManageProductsHelperTest < ActionView::TestCase |
82 | 83 | end |
83 | 84 | |
84 | 85 | should 'not display ui_button to edit product when user does not have permission' do |
85 | - user = mock | |
86 | + user = User.new(:email => 'not-display-uibutton@email.invalid.com') | |
86 | 87 | user.expects(:has_permission?).with(anything, anything).returns(false) |
87 | 88 | @controller = mock |
88 | 89 | @controller.expects(:user).returns(user).at_least_once |
... | ... | @@ -93,7 +94,7 @@ class ManageProductsHelperTest < ActionView::TestCase |
93 | 94 | end |
94 | 95 | |
95 | 96 | should 'display ui_button_to_remote to edit product when user has permission' do |
96 | - user = mock | |
97 | + user = User.new(:email => 'display-uibuttontoremote@email.invalid.com') | |
97 | 98 | user.expects(:has_permission?).with(anything, anything).returns(true) |
98 | 99 | @controller = mock |
99 | 100 | @controller.expects(:user).returns(user).at_least_once |
... | ... | @@ -108,7 +109,7 @@ class ManageProductsHelperTest < ActionView::TestCase |
108 | 109 | |
109 | 110 | |
110 | 111 | should 'display ui_button to edit product when user has permission' do |
111 | - user = mock | |
112 | + user = User.new(:email => 'display-uibutton@email.invalid.com') | |
112 | 113 | user.expects(:has_permission?).with(anything, anything).returns(true) |
113 | 114 | @controller = mock |
114 | 115 | @controller.expects(:user).returns(user).at_least_once | ... | ... |
test/unit/my_network_block_test.rb
... | ... | @@ -19,14 +19,6 @@ class MyNetworkBlockTest < ActiveSupport::TestCase |
19 | 19 | assert_not_equal Block.new.default_title, MyNetworkBlock.new.default_title |
20 | 20 | end |
21 | 21 | |
22 | - should 'display my-profile' do | |
23 | - self.expects(:render).with(:file => 'blocks/my_network', :locals => { | |
24 | - :title => 'My network', | |
25 | - :owner => owner | |
26 | - }) | |
27 | - instance_eval(&block.content) | |
28 | - end | |
29 | - | |
30 | 22 | should 'be able to update display setting' do |
31 | 23 | user = create_user('testinguser').person |
32 | 24 | box = fast_create(Box, :owner_id => user.id) |
... | ... | @@ -37,3 +29,22 @@ class MyNetworkBlockTest < ActiveSupport::TestCase |
37 | 29 | end |
38 | 30 | |
39 | 31 | end |
32 | + | |
33 | +class MyNetworkBlockViewTest < ActionView::TestCase | |
34 | + include BoxesHelper | |
35 | + | |
36 | + def setup | |
37 | + @block = MyNetworkBlock.new | |
38 | + @owner = Person.new(:identifier => 'testuser') | |
39 | + @block.stubs(:owner).returns(@owner) | |
40 | + owner.stubs(:environment).returns(Environment.default) | |
41 | + end | |
42 | + attr_reader :owner, :block | |
43 | + | |
44 | + should 'display my-profile' do | |
45 | + ActionView::Base.any_instance.stubs(:block_title).with(anything).returns(true) | |
46 | + ActionView::Base.any_instance.stubs(:user).with(anything).returns(owner) | |
47 | + ActionView::Base.any_instance.stubs(:render_profile_actions) | |
48 | + assert_match "#{Environment.default.top_url}/profile/testuser", render_block_content(block) | |
49 | + end | |
50 | +end | ... | ... |
test/unit/person_test.rb
... | ... | @@ -1939,7 +1939,7 @@ class PersonTest < ActiveSupport::TestCase |
1939 | 1939 | community.add_member person |
1940 | 1940 | |
1941 | 1941 | assert !person.member_relation_of(community).empty?, "Person '#{person.identifier}' is not a member of Community '#{community.identifier}'" |
1942 | - assert person.member_since_date(community) == Date.today,"Person '#{person.identifier}' is not added like a member of Community '#{community.identifier}' today" | |
1942 | + assert_equal Date.current, person.member_since_date(community), "Person '#{person.identifier}' is not added like a member of Community '#{community.identifier}' today" | |
1943 | 1943 | end |
1944 | 1944 | |
1945 | 1945 | should 'a person follows many articles' do | ... | ... |
test/unit/plugin_hot_spot_test.rb
... | ... | @@ -15,4 +15,19 @@ class PluginHotSpotTest < ActiveSupport::TestCase |
15 | 15 | assert_same @client.plugins, @client.plugins |
16 | 16 | end |
17 | 17 | |
18 | + Noosfero::Plugin::HotSpot::CALLBACK_HOTSPOTS.each do |callback| | |
19 | + should "call #{callback} hotspot" do | |
20 | + class CoolPlugin < Noosfero::Plugin; end | |
21 | + | |
22 | + Noosfero::Plugin.stubs(:all).returns([CoolPlugin.name]) | |
23 | + Environment.default.enable_plugin(CoolPlugin) | |
24 | + CoolPlugin.any_instance.expects("comment_#{callback}_callback".to_sym) | |
25 | + | |
26 | + person = fast_create(Person) | |
27 | + article = fast_create(Article, :profile_id => person.id) | |
28 | + comment = Comment.create!(:author => person, :title => 'test comment', :body => 'body!', :source => article) | |
29 | + comment.destroy | |
30 | + end | |
31 | + end | |
32 | + | |
18 | 33 | end | ... | ... |
test/unit/products_block_test.rb
... | ... | @@ -20,33 +20,6 @@ class ProductsBlockTest < ActiveSupport::TestCase |
20 | 20 | assert_not_equal Block.description, ProductsBlock.description |
21 | 21 | end |
22 | 22 | |
23 | - should "list owner products" do | |
24 | - enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') | |
25 | - create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) | |
26 | - create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category) | |
27 | - | |
28 | - block.expects(:products).returns(enterprise.products) | |
29 | - | |
30 | - content = block.content | |
31 | - | |
32 | - assert_tag_in_string content, :content => 'Products' | |
33 | - | |
34 | - assert_tag_in_string content, :tag => 'li', :attributes => { :class => 'product' }, :descendant => { :tag => 'a', :content => /product one/ } | |
35 | - assert_tag_in_string content, :tag => 'li', :attributes => { :class => 'product' }, :descendant => { :tag => 'a', :content => /product two/ } | |
36 | - end | |
37 | - | |
38 | - should 'point to all products in footer' do | |
39 | - enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') | |
40 | - create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) | |
41 | - create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category) | |
42 | - | |
43 | - block.stubs(:owner).returns(enterprise) | |
44 | - | |
45 | - footer = block.footer | |
46 | - | |
47 | - assert_tag_in_string footer, :tag => 'a', :attributes => { :href => /\/catalog\/testenterprise$/ }, :content => 'View all products' | |
48 | - end | |
49 | - | |
50 | 23 | should 'list 4 random products by default' do |
51 | 24 | enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') |
52 | 25 | create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) |
... | ... | @@ -120,18 +93,35 @@ class ProductsBlockTest < ActiveSupport::TestCase |
120 | 93 | assert_equivalent [p1, p2, p3, p4], block.products |
121 | 94 | end |
122 | 95 | end |
96 | +end | |
123 | 97 | |
124 | - should 'generate footer when enterprise has own hostname' do | |
98 | +require 'boxes_helper' | |
99 | +require 'block_helper' | |
100 | + | |
101 | +class ProductsBlockViewTest < ActionView::TestCase | |
102 | + include BoxesHelper | |
103 | + | |
104 | + ActionView::Base.send :include, BlockHelper | |
105 | + | |
106 | + def setup | |
107 | + @block = ProductsBlock.new | |
108 | + @product_category = fast_create(ProductCategory, :name => 'Products') | |
109 | + end | |
110 | + attr_reader :block | |
111 | + | |
112 | + should "list owner products" do | |
125 | 113 | enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') |
126 | - enterprise.domains << Domain.new(:name => 'sometest.com'); enterprise.save! | |
127 | 114 | create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) |
128 | 115 | create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category) |
129 | 116 | |
130 | - block.stubs(:owner).returns(enterprise) | |
117 | + block.expects(:products).returns(enterprise.products) | |
131 | 118 | |
132 | - footer = block.footer | |
119 | + content = render_block_content(block) | |
133 | 120 | |
134 | - assert_tag_in_string footer, :tag => 'a', :attributes => { :href => /\/catalog\/testenterprise$/ }, :content => 'View all products' | |
121 | + assert_tag_in_string content, :content => 'Products' | |
122 | + | |
123 | + assert_tag_in_string content, :tag => 'li', :attributes => { :class => 'product' }, :descendant => { :tag => 'a', :content => /product one/ } | |
124 | + assert_tag_in_string content, :tag => 'li', :attributes => { :class => 'product' }, :descendant => { :tag => 'a', :content => /product two/ } | |
135 | 125 | end |
136 | 126 | |
137 | 127 | should 'display the default minor image if thumbnails were not processed' do |
... | ... | @@ -139,8 +129,9 @@ class ProductsBlockTest < ActiveSupport::TestCase |
139 | 129 | create(Product, :enterprise => enterprise, :name => 'product', :product_category => @product_category, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}) |
140 | 130 | |
141 | 131 | block.expects(:products).returns(enterprise.products) |
132 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
142 | 133 | |
143 | - content = block.content | |
134 | + content = render_block_content(block) | |
144 | 135 | |
145 | 136 | assert_tag_in_string content, :tag => 'a', :attributes => { :style => /image-loading-minor.png/ } |
146 | 137 | end |
... | ... | @@ -151,9 +142,34 @@ class ProductsBlockTest < ActiveSupport::TestCase |
151 | 142 | |
152 | 143 | process_delayed_job_queue |
153 | 144 | block.expects(:products).returns(enterprise.products.reload) |
145 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
154 | 146 | |
155 | - content = block.content | |
147 | + content = render_block_content(block) | |
156 | 148 | assert_tag_in_string content, :tag => 'a', :attributes => { :style => /rails_minor.png/ } |
157 | 149 | end |
158 | 150 | |
151 | + should 'point to all products in footer' do | |
152 | + enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') | |
153 | + create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) | |
154 | + create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category) | |
155 | + | |
156 | + block.stubs(:owner).returns(enterprise) | |
157 | + | |
158 | + footer = render_block_footer(block) | |
159 | + | |
160 | + assert_tag_in_string footer, :tag => 'a', :attributes => { :href => /\/catalog\/testenterprise$/ }, :content => 'View all products' | |
161 | + end | |
162 | + | |
163 | + should 'generate footer when enterprise has own hostname' do | |
164 | + enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') | |
165 | + enterprise.domains << Domain.new(:name => 'sometest.com'); enterprise.save! | |
166 | + create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) | |
167 | + create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category) | |
168 | + | |
169 | + block.stubs(:owner).returns(enterprise) | |
170 | + | |
171 | + footer = render_block_footer(block) | |
172 | + | |
173 | + assert_tag_in_string footer, :tag => 'a', :attributes => { :href => /\/catalog\/testenterprise$/ }, :content => 'View all products' | |
174 | + end | |
159 | 175 | end | ... | ... |
test/unit/profile_image_block_test.rb
1 | 1 | require_relative "../test_helper" |
2 | +require 'boxes_helper' | |
2 | 3 | |
3 | 4 | class ProfileImageBlockTest < ActiveSupport::TestCase |
5 | + include BoxesHelper | |
4 | 6 | |
5 | 7 | should 'provide description' do |
6 | 8 | assert_not_equal Block.description, ProfileImageBlock.description |
... | ... | @@ -9,8 +11,8 @@ class ProfileImageBlockTest < ActiveSupport::TestCase |
9 | 11 | should 'display profile image' do |
10 | 12 | block = ProfileImageBlock.new |
11 | 13 | |
12 | - self.expects(:render).with(:file => 'blocks/profile_image', :locals => { :block => block, :show_name => false}) | |
13 | - instance_eval(& block.content) | |
14 | + self.expects(:render).with(template: 'blocks/profile_image', locals: { block: block }) | |
15 | + render_block_content(block) | |
14 | 16 | end |
15 | 17 | |
16 | 18 | should 'be editable' do | ... | ... |
... | ... | @@ -0,0 +1,138 @@ |
1 | +# encoding: UTF-8 | |
2 | +require_relative "../test_helper" | |
3 | + | |
4 | +class ProfileImageHelperTest < ActionView::TestCase | |
5 | + include Noosfero::Gravatar | |
6 | + include ThemeLoaderHelper | |
7 | + include ProfileImageHelper | |
8 | + | |
9 | + should "Extra info with hash" do | |
10 | + @plugins = mock | |
11 | + @plugins.stubs(:dispatch_first).returns(false) | |
12 | + env = Environment.default | |
13 | + stubs(:environment).returns(env) | |
14 | + stubs(:profile).returns(profile) | |
15 | + profile = fast_create(Person, :environment_id => env.id) | |
16 | + info = {:value =>_('New'), :class => 'new-profile'} | |
17 | + html = profile_image_link(profile, size=:portrait, tag='li', extra_info = info) | |
18 | + assert_tag_in_string html, :tag => 'span', :attributes => { :class => 'profile-image new-profile' } | |
19 | + assert_tag_in_string html, :tag => 'span', :attributes => { :class => 'extra_info new-profile' }, :content => 'New' | |
20 | + end | |
21 | + | |
22 | + should "Extra info without hash" do | |
23 | + @plugins = mock | |
24 | + @plugins.stubs(:dispatch_first).returns(false) | |
25 | + env = Environment.default | |
26 | + stubs(:environment).returns(env) | |
27 | + stubs(:profile).returns(profile) | |
28 | + profile = fast_create(Person, :environment_id => env.id) | |
29 | + info = 'new' | |
30 | + html = profile_image_link(profile, size=:portrait, tag='li', extra_info = info) | |
31 | + assert_tag_in_string html, :tag => 'span', :attributes => { :class => 'extra_info' }, :content => 'new' | |
32 | + end | |
33 | + | |
34 | + should 'return nil when :show_balloon_with_profile_links_when_clicked is not enabled in environment' do | |
35 | + env = Environment.default | |
36 | + env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(false) | |
37 | + stubs(:environment).returns(env) | |
38 | + profile = Profile.new | |
39 | + assert_nil links_for_balloon(profile) | |
40 | + end | |
41 | + | |
42 | + should 'return ordered list of links to balloon to Person' do | |
43 | + env = Environment.default | |
44 | + env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(true) | |
45 | + stubs(:environment).returns(env) | |
46 | + person = Person.new identifier: 'person' | |
47 | + person.stubs(:url).returns('url for person') | |
48 | + person.stubs(:public_profile_url).returns('url for person') | |
49 | + links = links_for_balloon(person) | |
50 | + assert_equal ['Wall', 'Friends', 'Communities', 'Send an e-mail', 'Add'], links.map{|i| i.keys.first} | |
51 | + end | |
52 | + | |
53 | + should 'return ordered list of links to balloon to Community' do | |
54 | + env = Environment.default | |
55 | + env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(true) | |
56 | + stubs(:environment).returns(env) | |
57 | + community = Community.new identifier: 'comm' | |
58 | + community.stubs(:url).returns('url for community') | |
59 | + community.stubs(:public_profile_url).returns('url for community') | |
60 | + links = links_for_balloon(community) | |
61 | + assert_equal ['Wall', 'Members', 'Agenda', 'Join', 'Leave community', 'Send an e-mail'], links.map{|i| i.keys.first} | |
62 | + end | |
63 | + | |
64 | + should 'return ordered list of links to balloon to Enterprise' do | |
65 | + env = Environment.default | |
66 | + env.stubs(:enabled?).with(:show_balloon_with_profile_links_when_clicked).returns(true) | |
67 | + stubs(:environment).returns(env) | |
68 | + enterprise = Enterprise.new identifier: 'coop' | |
69 | + enterprise.stubs(:url).returns('url for enterprise') | |
70 | + enterprise.stubs(:public_profile_url).returns('url for enterprise') | |
71 | + stubs(:catalog_path) | |
72 | + links = links_for_balloon(enterprise) | |
73 | + assert_equal ['Products', 'Members', 'Agenda', 'Send an e-mail'], links.map{|i| i.keys.first} | |
74 | + end | |
75 | + | |
76 | + should 'not return mime type of profile icon if not requested' do | |
77 | + stubs(:profile).returns(Person.new) | |
78 | + stubs(:current_theme).returns('default') | |
79 | + | |
80 | + filename, mime = profile_icon(Person.new, :thumb) | |
81 | + assert_not_nil filename | |
82 | + assert_nil mime | |
83 | + end | |
84 | + | |
85 | + should 'return mime type of profile icon' do | |
86 | + stubs(:profile).returns(Person.new) | |
87 | + stubs(:current_theme).returns('default') | |
88 | + | |
89 | + filename, mime = profile_icon(Person.new, :thumb, true) | |
90 | + assert_not_nil filename | |
91 | + assert_not_nil mime | |
92 | + end | |
93 | + | |
94 | + should 'provide sex icon for males' do | |
95 | + stubs(:environment).returns(Environment.default) | |
96 | + expects(:content_tag).with(anything, 'male').returns('MALE!!') | |
97 | + expects(:content_tag).with(anything, 'MALE!!', is_a(Hash)).returns("FINAL") | |
98 | + assert_equal "FINAL", profile_sex_icon(build(Person, :sex => 'male')) | |
99 | + end | |
100 | + | |
101 | + should 'provide sex icon for females' do | |
102 | + stubs(:environment).returns(Environment.default) | |
103 | + expects(:content_tag).with(anything, 'female').returns('FEMALE!!') | |
104 | + expects(:content_tag).with(anything, 'FEMALE!!', is_a(Hash)).returns("FINAL") | |
105 | + assert_equal "FINAL", profile_sex_icon(build(Person, :sex => 'female')) | |
106 | + end | |
107 | + | |
108 | + should 'provide undef sex icon' do | |
109 | + stubs(:environment).returns(Environment.default) | |
110 | + expects(:content_tag).with(anything, 'undef').returns('UNDEF!!') | |
111 | + expects(:content_tag).with(anything, 'UNDEF!!', is_a(Hash)).returns("FINAL") | |
112 | + assert_equal "FINAL", profile_sex_icon(build(Person, :sex => nil)) | |
113 | + end | |
114 | + | |
115 | + should 'not draw sex icon for non-person profiles' do | |
116 | + assert_equal '', profile_sex_icon(Community.new) | |
117 | + end | |
118 | + | |
119 | + should 'not draw sex icon when disabled in the environment' do | |
120 | + env = fast_create(Environment, :name => 'env test') | |
121 | + env.expects(:enabled?).with('disable_gender_icon').returns(true) | |
122 | + stubs(:environment).returns(env) | |
123 | + assert_equal '', profile_sex_icon(build(Person, :sex => 'male')) | |
124 | + end | |
125 | + | |
126 | + should 'gravatar default parameter' do | |
127 | + profile = mock | |
128 | + profile.stubs(:theme).returns('some-theme') | |
129 | + stubs(:profile).returns(profile) | |
130 | + | |
131 | + NOOSFERO_CONF.stubs(:[]).with('gravatar').returns('crazyvatar') | |
132 | + assert_equal gravatar_default, 'crazyvatar' | |
133 | + | |
134 | + stubs(:theme_option).returns('gravatar' => 'nicevatar') | |
135 | + NOOSFERO_CONF.stubs(:[]).with('gravatar').returns('nicevatar') | |
136 | + assert_equal gravatar_default, 'nicevatar' | |
137 | + end | |
138 | +end | |
0 | 139 | \ No newline at end of file | ... | ... |
test/unit/profile_info_block_test.rb
... | ... | @@ -16,9 +16,11 @@ class ProfileInfoBlockTest < ActiveSupport::TestCase |
16 | 16 | assert_not_equal Block.description, ProfileInfoBlock.description |
17 | 17 | end |
18 | 18 | |
19 | + include BoxesHelper | |
20 | + | |
19 | 21 | should 'display profile information' do |
20 | - self.expects(:render).with(:file => 'blocks/profile_info', :locals => { :block => block}) | |
21 | - instance_eval(& block.content) | |
22 | + self.expects(:render).with(template: 'blocks/profile_info', locals: { block: block }) | |
23 | + render_block_content(block) | |
22 | 24 | end |
23 | 25 | |
24 | 26 | end | ... | ... |
test/unit/profile_list_block_test.rb
... | ... | @@ -20,6 +20,8 @@ class ProfileListBlockTest < ActiveSupport::TestCase |
20 | 20 | assert_equal 20, block.limit |
21 | 21 | end |
22 | 22 | |
23 | + include BoxesHelper | |
24 | + | |
23 | 25 | should 'list people' do |
24 | 26 | env = fast_create(Environment) |
25 | 27 | |
... | ... | @@ -30,15 +32,20 @@ class ProfileListBlockTest < ActiveSupport::TestCase |
30 | 32 | block = ProfileListBlock.new |
31 | 33 | block.stubs(:owner).returns(env) |
32 | 34 | |
33 | - self.expects(:profile_image_link).with(person1, :minor).once | |
34 | - self.expects(:profile_image_link).with(person2, :minor).once | |
35 | - self.expects(:profile_image_link).with(person3, :minor).once | |
36 | - | |
37 | - self.stubs(:tag).returns('<div></div>') | |
38 | - self.expects(:content_tag).returns('<div></div>').at_least_once | |
39 | - self.expects(:block_title).returns('block title').at_least_once | |
35 | + ApplicationHelper.class_eval do | |
36 | + alias_method :original_profile_image_link, :profile_image_link | |
37 | + def profile_image_link( profile, size=:portrait, tag='li', extra_info = nil ) | |
38 | + "<#{profile.name}>" | |
39 | + end | |
40 | + end | |
40 | 41 | |
41 | - assert_kind_of String, instance_eval(&block.content) | |
42 | + content = render_block_content(block) | |
43 | + assert_match '<testperson1>', content | |
44 | + assert_match '<testperson2>', content | |
45 | + assert_match '<testperson3>', content | |
46 | + ApplicationHelper.class_eval do | |
47 | + alias_method :profile_image_link, :original_profile_image_link | |
48 | + end | |
42 | 49 | end |
43 | 50 | |
44 | 51 | should 'list private profiles' do | ... | ... |
test/unit/profile_search_block_test.rb
... | ... | @@ -10,20 +10,22 @@ class ProfileSearchBlockTest < ActiveSupport::TestCase |
10 | 10 | assert_equal Block.new.default_title, ProfileSearchBlock.new.default_title |
11 | 11 | end |
12 | 12 | |
13 | + include BoxesHelper | |
14 | + | |
13 | 15 | should 'render profile search' do |
14 | 16 | person = fast_create(Person) |
15 | 17 | |
16 | 18 | block = ProfileSearchBlock.new |
17 | 19 | block.stubs(:owner).returns(person) |
18 | 20 | |
19 | - self.expects(:render).with(:file => 'blocks/profile_search', :locals => { :title => block.title}) | |
20 | - instance_eval(& block.content) | |
21 | + self.expects(:render).with(template: 'blocks/profile_search', locals: { block: block }) | |
22 | + render_block_content(block) | |
21 | 23 | end |
22 | 24 | |
23 | 25 | should 'provide view_title' do |
24 | 26 | person = fast_create(Person) |
25 | 27 | person.boxes << Box.new |
26 | - block = ProfileSearchBlock.new(:title => 'Title from block') | |
28 | + block = ProfileSearchBlock.new(title: 'Title from block') | |
27 | 29 | person.boxes.first.blocks << block |
28 | 30 | block.save! |
29 | 31 | assert_equal 'Title from block', block.view_title | ... | ... |
test/unit/raw_html_block_test.rb
... | ... | @@ -17,9 +17,11 @@ class RawHTMLBlockTest < ActiveSupport::TestCase |
17 | 17 | assert_equal html, block.html |
18 | 18 | end |
19 | 19 | |
20 | + include BoxesHelper | |
21 | + | |
20 | 22 | should 'return html as content' do |
21 | 23 | block = RawHTMLBlock.new(:html => "HTML") |
22 | - assert_match(/HTML$/, block.content) | |
24 | + assert_match /HTML$/, render_block_content(block) | |
23 | 25 | end |
24 | 26 | |
25 | 27 | should 'not be editable for users without permission' do | ... | ... |
test/unit/recent_documents_block_test.rb
... | ... | @@ -35,17 +35,6 @@ class RecentDocumentsBlockTest < ActiveSupport::TestCase |
35 | 35 | assert_equivalent block.docs, articles |
36 | 36 | end |
37 | 37 | |
38 | - should 'link to documents' do | |
39 | - articles.each do |a| | |
40 | - expects(:link_to).with(a.title, a.url) | |
41 | - end | |
42 | - stubs(:block_title).returns("") | |
43 | - stubs(:content_tag).returns("") | |
44 | - stubs(:li).returns("") | |
45 | - | |
46 | - instance_eval(&block.content) | |
47 | - end | |
48 | - | |
49 | 38 | should 'respect the maximum number of items as configured' do |
50 | 39 | block.limit = 3 |
51 | 40 | |
... | ... | @@ -68,21 +57,6 @@ class RecentDocumentsBlockTest < ActiveSupport::TestCase |
68 | 57 | assert block.limit > 0 |
69 | 58 | end |
70 | 59 | |
71 | - should 'display a link to sitemap with title "All content"' do | |
72 | - expects(:link_to).with('All content', :controller => 'profile', :action => 'sitemap', :profile => profile.identifier) | |
73 | - expects(:_).with('All content').returns('All content') | |
74 | - | |
75 | - instance_eval(&(block.footer)) | |
76 | - end | |
77 | - | |
78 | - should 'not display link to sitemap when owner is environment' do | |
79 | - block = RecentDocumentsBlock.new | |
80 | - box = mock | |
81 | - block.expects(:box).returns(box).at_least_once | |
82 | - box.expects(:owner).returns(Environment.new).at_least_once | |
83 | - assert_equal nil, block.footer | |
84 | - end | |
85 | - | |
86 | 60 | should 'be able to update display setting' do |
87 | 61 | assert @block.update!(:display => 'always') |
88 | 62 | @block.reload |
... | ... | @@ -100,3 +74,56 @@ class RecentDocumentsBlockTest < ActiveSupport::TestCase |
100 | 74 | assert_equal 0, block.get_limit |
101 | 75 | end |
102 | 76 | end |
77 | + | |
78 | +require 'boxes_helper' | |
79 | + | |
80 | +class RecentDocumentsBlockViewTest < ActionView::TestCase | |
81 | + include BoxesHelper | |
82 | + | |
83 | + def setup | |
84 | + @articles = [] | |
85 | + @profile = create_user('testinguser').person | |
86 | + @profile.articles.destroy_all | |
87 | + ['first', 'second', 'third', 'fourth', 'fifth'].each do |name| | |
88 | + article = @profile.articles.create!(:name => name) | |
89 | + @articles << article | |
90 | + end | |
91 | + | |
92 | + box = Box.new | |
93 | + box.owner = profile | |
94 | + box.save! | |
95 | + | |
96 | + | |
97 | + @block = RecentDocumentsBlock.new | |
98 | + @block.box_id = box.id | |
99 | + @block.save! | |
100 | + | |
101 | + end | |
102 | + attr_reader :block, :profile, :articles | |
103 | + | |
104 | + should 'link to documents' do | |
105 | + articles.each do |a| | |
106 | + ActionView::Base.any_instance.expects(:link_to).with(a.title, a.url) | |
107 | + end | |
108 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
109 | + ActionView::Base.any_instance.stubs(:content_tag).returns("") | |
110 | + ActionView::Base.any_instance.stubs(:li).returns("") | |
111 | + | |
112 | + render_block_content(block) | |
113 | + end | |
114 | + | |
115 | + should 'display a link to sitemap with title "All content"' do | |
116 | + ActionView::Base.any_instance.expects(:link_to).with('All content', :controller => 'profile', :action => 'sitemap', :profile => profile.identifier) | |
117 | + ActionView::Base.any_instance.expects(:_).with('All content').returns('All content') | |
118 | + | |
119 | + render_block_footer(block) | |
120 | + end | |
121 | + | |
122 | + should 'not display link to sitemap when owner is environment' do | |
123 | + block = RecentDocumentsBlock.new | |
124 | + box = mock | |
125 | + block.expects(:box).returns(box).at_least_once | |
126 | + box.expects(:owner).returns(Environment.new).at_least_once | |
127 | + assert_equal '', render_block_footer(block) | |
128 | + end | |
129 | +end | ... | ... |
test/unit/sellers_search_block_test.rb
... | ... | @@ -10,10 +10,4 @@ class SellersSearchBlockTest < ActiveSupport::TestCase |
10 | 10 | assert_not_equal Block.new.default_title, SellersSearchBlock.new.default_title |
11 | 11 | end |
12 | 12 | |
13 | - should 'not use a fixed title' do | |
14 | - block = SellersSearchBlock.new(:title => 'my custom title') | |
15 | - expects(:render).with(:file => 'search/_sellers_form', :locals => { :title => 'my custom title'}) | |
16 | - instance_eval(&block.content) | |
17 | - end | |
18 | - | |
19 | 13 | end | ... | ... |
test/unit/slideshow_block_test.rb
1 | 1 | require_relative "../test_helper" |
2 | +require 'boxes_helper' | |
2 | 3 | |
3 | 4 | class SlideshowBlockTest < ActiveSupport::TestCase |
5 | + include BoxesHelper | |
4 | 6 | |
5 | 7 | def setup |
6 | 8 | @profile = fast_create(Profile) |
... | ... | @@ -30,7 +32,7 @@ class SlideshowBlockTest < ActiveSupport::TestCase |
30 | 32 | |
31 | 33 | block = SlideshowBlock.new |
32 | 34 | block.stubs(:gallery).returns(gallery) |
33 | - block.content | |
35 | + render_block_content(block) | |
34 | 36 | end |
35 | 37 | |
36 | 38 | should 'list in random order' do |
... | ... | @@ -42,7 +44,7 @@ class SlideshowBlockTest < ActiveSupport::TestCase |
42 | 44 | block.stubs(:block_images).returns(images) |
43 | 45 | images.expects(:shuffle).once.returns(shuffled) |
44 | 46 | |
45 | - block.content | |
47 | + render_block_content(block) | |
46 | 48 | end |
47 | 49 | |
48 | 50 | should 'not shuffle by default' do | ... | ... |
test/unit/tags_block_test.rb
... | ... | @@ -25,47 +25,80 @@ class TagsBlockTest < ActiveSupport::TestCase |
25 | 25 | assert_not_equal Block.new.default_title, TagsBlock.new.default_title |
26 | 26 | end |
27 | 27 | |
28 | - should 'generate links to tags' do | |
29 | - assert_match /profile\/testinguser\/tags\/first-tag/, block.content | |
30 | - assert_match /profile\/testinguser\/tags\/second-tag/, block.content | |
31 | - assert_match /profile\/testinguser\/tags\/third-tag/, block.content | |
28 | + include BoxesHelper | |
29 | + | |
30 | + should 'return the max value in the range between zero and limit' do | |
31 | + block = TagsBlock.new | |
32 | + assert_equal 12, block.get_limit | |
32 | 33 | end |
33 | 34 | |
34 | - should 'generate links to tags on a environment page' do | |
35 | - @otheruser = create_user('othertestinguser').person | |
36 | - @otheruser.articles.build(:name => 'article A', :tag_list => 'other-tag').save! | |
37 | - @otheruser.articles.build(:name => 'article B', :tag_list => 'other-tag, second-tag').save! | |
38 | - box = create(Box, :owner => Environment.default) | |
39 | - @block = create(TagsBlock, :box => box) | |
35 | + should '' do | |
36 | + block = TagsBlock.new | |
37 | + block.limit = -5 | |
38 | + assert_equal 0, block.get_limit | |
39 | + end | |
40 | +end | |
41 | + | |
42 | +require 'tags_helper' | |
43 | + | |
44 | +class TagsBlockViewTest < ActionView::TestCase | |
45 | + include BoxesHelper | |
46 | + | |
47 | + ActionView::Base.send :include, TagsHelper | |
48 | + | |
49 | + def setup | |
50 | + @user = create_user('testinguser').person | |
51 | + @user.articles.build(:name => 'article 1', :tag_list => 'first-tag').save! | |
52 | + @user.articles.build(:name => 'article 2', :tag_list => 'first-tag, second-tag').save! | |
53 | + @user.articles.build(:name => 'article 3', :tag_list => 'first-tag, second-tag, third-tag').save! | |
40 | 54 | |
41 | - assert_match /3 items[^>]+\/tag\/first-tag/, block.content | |
42 | - assert_match /3 items[^>]+\/tag\/second-tag/, block.content | |
43 | - assert_match /one item[^>]+\/tag\/third-tag/, block.content | |
44 | - assert_match /2 item[^>]+\/tag\/other-tag"/, block.content | |
55 | + box = Box.new | |
56 | + box.owner = @user | |
57 | + box.save! | |
58 | + @block = TagsBlock.new | |
59 | + @block.box = box | |
60 | + @block.save | |
45 | 61 | end |
62 | + attr_reader :block | |
46 | 63 | |
47 | 64 | should 'return (none) when no tags to display' do |
65 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
48 | 66 | block.owner.expects(:article_tags).returns([]) |
49 | - assert_equal '', block.content | |
67 | + assert_equal "\n\n\n", render_block_content(block) | |
50 | 68 | end |
51 | 69 | |
52 | - should 'generate links when profile has own hostname' do | |
53 | - @user.domains << Domain.new(:name => 'testuser.net'); @user.save! | |
54 | - assert_match /profile\/testinguser\/tags\/first-tag/, block.content | |
70 | + should 'order tags alphabetically' do | |
71 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
72 | + assert /\/first-tag".*\/second-tag".*\/third-tag"/m =~ render_block_content(block) | |
55 | 73 | end |
56 | 74 | |
57 | - should 'order tags alphabetically' do | |
58 | - assert /\/first-tag".*\/second-tag".*\/third-tag"/m =~ block.content | |
75 | + should 'generate links to tags' do | |
76 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
77 | + content = render_block_content(block) | |
78 | + assert_match /profile\/testinguser\/tags\/first-tag/, content | |
79 | + assert_match /profile\/testinguser\/tags\/second-tag/, content | |
80 | + assert_match /profile\/testinguser\/tags\/third-tag/, content | |
59 | 81 | end |
60 | 82 | |
61 | - should 'return the max value in the range between zero and limit' do | |
62 | - block = TagsBlock.new | |
63 | - assert_equal 12, block.get_limit | |
83 | + should 'generate links to tags on a environment page' do | |
84 | + @otheruser = create_user('othertestinguser').person | |
85 | + @otheruser.articles.build(:name => 'article A', :tag_list => 'other-tag').save! | |
86 | + @otheruser.articles.build(:name => 'article B', :tag_list => 'other-tag, second-tag').save! | |
87 | + box = create(Box, :owner => Environment.default) | |
88 | + @block = create(TagsBlock, :box => box) | |
89 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
90 | + | |
91 | + content = render_block_content(block) | |
92 | + assert_match /3 items[^>]+\/tag\/first-tag/, content | |
93 | + assert_match /3 items[^>]+\/tag\/second-tag/, content | |
94 | + assert_match /one item[^>]+\/tag\/third-tag/, content | |
95 | + assert_match /2 item[^>]+\/tag\/other-tag"/, content | |
64 | 96 | end |
65 | 97 | |
66 | - should '' do | |
67 | - block = TagsBlock.new | |
68 | - block.limit = -5 | |
69 | - assert_equal 0, block.get_limit | |
98 | + | |
99 | + should 'generate links when profile has own hostname' do | |
100 | + @user.domains << Domain.new(:name => 'testuser.net'); @user.save! | |
101 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | |
102 | + assert_match /profile\/testinguser\/tags\/first-tag/, render_block_content(block) | |
70 | 103 | end |
71 | 104 | end | ... | ... |
test/unit/task_test.rb
... | ... | @@ -184,9 +184,9 @@ class TaskTest < ActiveSupport::TestCase |
184 | 184 | |
185 | 185 | should 'not send notification to target if notification is disabled in profile' do |
186 | 186 | task = Task.new |
187 | - target = fast_create(Profile) | |
187 | + target = fast_create(Organization) | |
188 | 188 | target.stubs(:notification_emails).returns(['adm@example.com']) |
189 | - target.stubs(:administrator_mail_notification).returns(false) | |
189 | + target.stubs(:profile_admin_mail_notification).returns(false) | |
190 | 190 | task.target = target |
191 | 191 | task.stubs(:target_notification_message).returns('some non nil message to be sent to target') |
192 | 192 | TaskMailer.expects(:target_notification).never |
... | ... | @@ -195,13 +195,12 @@ class TaskTest < ActiveSupport::TestCase |
195 | 195 | |
196 | 196 | should 'send notification to target if notification is enabled in profile' do |
197 | 197 | task = Task.new |
198 | - target = fast_create(Profile) | |
198 | + target = fast_create(Organization) | |
199 | 199 | target.stubs(:notification_emails).returns(['adm@example.com']) |
200 | - target.stubs(:administrator_mail_notification).returns(true) | |
200 | + target.stubs(:profile_admin_mail_notification).returns(true) | |
201 | 201 | task.target = target |
202 | 202 | task.stubs(:target_notification_message).returns('some non nil message to be sent to target') |
203 | 203 | |
204 | - | |
205 | 204 | mailer = mock |
206 | 205 | mailer.expects(:deliver).once |
207 | 206 | TaskMailer.expects(:target_notification).returns(mailer).once | ... | ... |
test/unit/textile_article_test.rb
... | ... | @@ -3,7 +3,8 @@ require_relative "../test_helper" |
3 | 3 | class TextileArticleTest < ActiveSupport::TestCase |
4 | 4 | |
5 | 5 | def setup |
6 | - @profile = create_user('testing').person | |
6 | + @user = User.current = create_user 'testing' | |
7 | + @profile = @user.person | |
7 | 8 | end |
8 | 9 | attr_reader :profile |
9 | 10 | |
... | ... | @@ -16,7 +17,7 @@ class TextileArticleTest < ActiveSupport::TestCase |
16 | 17 | end |
17 | 18 | |
18 | 19 | should 'convert Textile to HTML' do |
19 | - assert_equal '<p><strong>my text</strong></p>', build(TextileArticle, :body => '*my text*').to_html | |
20 | + assert_equal '<p><strong>my text</strong></p>', build(TextileArticle, body: '*my text*').to_html | |
20 | 21 | end |
21 | 22 | |
22 | 23 | should 'accept empty body' do |
... | ... | @@ -34,23 +35,21 @@ class TextileArticleTest < ActiveSupport::TestCase |
34 | 35 | |
35 | 36 | should 'notify activity on create' do |
36 | 37 | ActionTracker::Record.delete_all |
37 | - create TextileArticle, :name => 'test', :profile_id => fast_create(Profile).id, :published => true | |
38 | + create TextileArticle, name: 'test', profile_id: profile.id, published: true | |
38 | 39 | assert_equal 1, ActionTracker::Record.count |
39 | 40 | end |
40 | 41 | |
41 | 42 | should 'not group trackers activity of article\'s creation' do |
42 | - profile = fast_create(Profile) | |
43 | 43 | assert_difference 'ActionTracker::Record.count', 3 do |
44 | - create TextileArticle, :name => 'bar', :profile_id => profile.id, :published => true | |
45 | - create TextileArticle, :name => 'another bar', :profile_id => profile.id, :published => true | |
46 | - create TextileArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true | |
44 | + create TextileArticle, name: 'bar', profile_id: profile.id, published: true | |
45 | + create TextileArticle, name: 'another bar', profile_id: profile.id, published: true | |
46 | + create TextileArticle, name: 'another bar 2', profile_id: profile.id, published: true | |
47 | 47 | end |
48 | 48 | end |
49 | 49 | |
50 | 50 | should 'not update activity on update of an article' do |
51 | 51 | ActionTracker::Record.delete_all |
52 | - profile = fast_create(Profile) | |
53 | - article = create(TextileArticle, :profile_id => profile.id) | |
52 | + article = create(TextileArticle, profile_id: profile.id) | |
54 | 53 | time = article.activity.updated_at |
55 | 54 | Time.stubs(:now).returns(time + 1.day) |
56 | 55 | assert_no_difference 'ActionTracker::Record.count' do |
... | ... | @@ -62,8 +61,8 @@ class TextileArticleTest < ActiveSupport::TestCase |
62 | 61 | |
63 | 62 | should 'not create trackers activity when updating articles' do |
64 | 63 | ActionTracker::Record.delete_all |
65 | - a1 = create TextileArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | |
66 | - a2 = create TextileArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true | |
64 | + a1 = create TextileArticle, name: 'bar', profile_id: profile.id, published: true | |
65 | + a2 = create TextileArticle, name: 'another bar', profile_id: profile.id, published: true | |
67 | 66 | assert_no_difference 'ActionTracker::Record.count' do |
68 | 67 | a1.name = 'foo';a1.save! |
69 | 68 | a2.name = 'another foo';a2.save! |
... | ... | @@ -72,7 +71,7 @@ class TextileArticleTest < ActiveSupport::TestCase |
72 | 71 | |
73 | 72 | should 'remove activity after destroying article' do |
74 | 73 | ActionTracker::Record.delete_all |
75 | - a = create TextileArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | |
74 | + a = create TextileArticle, name: 'bar', profile_id: profile.id, published: true | |
76 | 75 | assert_difference 'ActionTracker::Record.count', -1 do |
77 | 76 | a.destroy |
78 | 77 | end |
... | ... | @@ -80,8 +79,8 @@ class TextileArticleTest < ActiveSupport::TestCase |
80 | 79 | |
81 | 80 | should 'remove activity after article is destroyed' do |
82 | 81 | ActionTracker::Record.delete_all |
83 | - a1 = create TextileArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | |
84 | - a2 = create TextileArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true | |
82 | + a1 = create TextileArticle, name: 'bar', profile_id: profile.id, published: true | |
83 | + a2 = create TextileArticle, name: 'another bar', profile_id: profile.id, published: true | |
85 | 84 | assert_equal 2, ActionTracker::Record.count |
86 | 85 | assert_difference 'ActionTracker::Record.count', -2 do |
87 | 86 | a1.destroy |
... | ... | @@ -95,20 +94,20 @@ class TextileArticleTest < ActiveSupport::TestCase |
95 | 94 | p1 = Person.first |
96 | 95 | community.add_member(p1) |
97 | 96 | assert p1.is_member_of?(community) |
98 | - article = create TextileArticle, :name => 'test', :profile_id => community.id | |
97 | + article = create TextileArticle, name: 'test', profile_id: community.id | |
99 | 98 | assert_equal article, ActionTracker::Record.last.target |
100 | 99 | end |
101 | 100 | |
102 | 101 | should "the tracker action target be defined as the article on articles'creation in profile" do |
103 | 102 | ActionTracker::Record.delete_all |
104 | 103 | person = Person.first |
105 | - article = create TextileArticle, :name => 'test', :profile_id => person.id | |
104 | + article = create TextileArticle, name: 'test', profile_id: person.id | |
106 | 105 | assert_equal article, ActionTracker::Record.last.target |
107 | 106 | end |
108 | 107 | |
109 | 108 | should 'not notify activity if the article is not advertise' do |
110 | 109 | ActionTracker::Record.delete_all |
111 | - a = create TextileArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true, :advertise => false | |
110 | + a = create TextileArticle, name: 'bar', profile_id: profile.id, published: true, advertise: false | |
112 | 111 | assert_equal true, a.published? |
113 | 112 | assert_equal true, a.notifiable? |
114 | 113 | assert_equal false, a.image? |
... | ... | @@ -121,7 +120,7 @@ class TextileArticleTest < ActiveSupport::TestCase |
121 | 120 | end |
122 | 121 | |
123 | 122 | should "the common trackable conditions return the correct value" do |
124 | - a = build(TextileArticle, :profile => profile) | |
123 | + a = build(TextileArticle, profile: profile) | |
125 | 124 | a.published = a.advertise = true |
126 | 125 | assert_equal true, a.published? |
127 | 126 | assert_equal true, a.notifiable? |
... | ... | @@ -139,7 +138,7 @@ class TextileArticleTest < ActiveSupport::TestCase |
139 | 138 | end |
140 | 139 | |
141 | 140 | should 'generate proper HTML for links' do |
142 | - assert_tag_in_string build_article('"Noosfero":http://noosfero.org/').to_html, :tag => 'a', :attributes => { :href => 'http://noosfero.org/' } | |
141 | + assert_tag_in_string build_article('"Noosfero":http://noosfero.org/').to_html, tag: 'a', attributes: { href: 'http://noosfero.org/' } | |
143 | 142 | end |
144 | 143 | |
145 | 144 | should 'not mess up with textile markup' do |
... | ... | @@ -153,7 +152,7 @@ class TextileArticleTest < ActiveSupport::TestCase |
153 | 152 | end |
154 | 153 | |
155 | 154 | should 'not allow Javascript on links' do |
156 | - assert_no_tag_in_string build_article('<a href="javascript: alert(\'BOOM\')" onclick="javascript: alert(\'BOOM\')"></a>').to_html, :tag => 'a', :attributes => { :href => /./, :onclick => /./ } | |
155 | + assert_no_tag_in_string build_article('<a href="javascript: alert(\'BOOM\')" onclick="javascript: alert(\'BOOM\')"></a>').to_html, tag: 'a', attributes: { href: /./, onclick: /./ } | |
157 | 156 | end |
158 | 157 | |
159 | 158 | should 'allow harmless HTML' do |
... | ... | @@ -163,11 +162,11 @@ class TextileArticleTest < ActiveSupport::TestCase |
163 | 162 | end |
164 | 163 | |
165 | 164 | should 'use Textile markup for lead as well' do |
166 | - assert_tag_in_string build_article(nil, :abstract => '"Noosfero":http://noosfero.org/').lead, :tag => 'a', :attributes => { :href => 'http://noosfero.org/' } | |
165 | + assert_tag_in_string build_article(nil, abstract: '"Noosfero":http://noosfero.org/').lead, tag: 'a', attributes: { href: 'http://noosfero.org/' } | |
167 | 166 | end |
168 | 167 | |
169 | 168 | should 'not allow arbitrary HTML in the lead' do |
170 | - assert_not_equal '<script>alert(1)</script>', build_article(nil, :abstract => '<script>alert(1)</script>').lead | |
169 | + assert_not_equal '<script>alert(1)</script>', build_article(nil, abstract: '<script>alert(1)</script>').lead | |
171 | 170 | end |
172 | 171 | |
173 | 172 | should 'not add hard breaks for single line breaks' do |
... | ... | @@ -182,7 +181,7 @@ class TextileArticleTest < ActiveSupport::TestCase |
182 | 181 | protected |
183 | 182 | |
184 | 183 | def build_article(input = nil, options = {}) |
185 | - article = build(TextileArticle, {:body => input}.merge(options)) | |
184 | + article = build(TextileArticle, {body: input}.merge(options)) | |
186 | 185 | article.valid? # trigger the xss terminate thingy |
187 | 186 | article |
188 | 187 | end | ... | ... |
... | ... | @@ -0,0 +1,36 @@ |
1 | +# encoding: UTF-8 | |
2 | +require_relative "../test_helper" | |
3 | + | |
4 | +class ThemeLoaderHelperTest < ActionView::TestCase | |
5 | + include ThemeLoaderHelper | |
6 | + | |
7 | + should 'get theme from environment by default' do | |
8 | + @environment = mock | |
9 | + @environment.stubs(:theme).returns('my-environment-theme') | |
10 | + stubs(:profile).returns(nil) | |
11 | + stubs(:environment).returns(@environment) | |
12 | + assert_equal 'my-environment-theme', current_theme | |
13 | + end | |
14 | + | |
15 | + should 'get theme from profile when profile is present' do | |
16 | + profile = mock | |
17 | + profile.stubs(:theme).returns('my-profile-theme') | |
18 | + stubs(:profile).returns(profile) | |
19 | + assert_equal 'my-profile-theme', current_theme | |
20 | + end | |
21 | + | |
22 | + should 'override theme with testing theme from session' do | |
23 | + stubs(:session).returns(:theme => 'theme-under-test') | |
24 | + assert_equal 'theme-under-test', current_theme | |
25 | + end | |
26 | + | |
27 | + should 'point to system theme path by default' do | |
28 | + expects(:current_theme).returns('my-system-theme') | |
29 | + assert_equal '/designs/themes/my-system-theme', theme_path | |
30 | + end | |
31 | + | |
32 | + should 'point to user theme path when testing theme' do | |
33 | + stubs(:session).returns({:theme => 'theme-under-test'}) | |
34 | + assert_equal '/user_themes/theme-under-test', theme_path | |
35 | + end | |
36 | +end | |
0 | 37 | \ No newline at end of file | ... | ... |
test/unit/tiny_mce_article_test.rb
... | ... | @@ -5,7 +5,8 @@ class TinyMceArticleTest < ActiveSupport::TestCase |
5 | 5 | |
6 | 6 | def setup |
7 | 7 | super |
8 | - @profile = create_user('zezinho').person | |
8 | + @user = User.current = create_user('zezinho') | |
9 | + @profile = @user.person | |
9 | 10 | end |
10 | 11 | attr_reader :profile |
11 | 12 | |
... | ... | @@ -114,24 +115,22 @@ class TinyMceArticleTest < ActiveSupport::TestCase |
114 | 115 | |
115 | 116 | should 'notify activity on create' do |
116 | 117 | ActionTracker::Record.delete_all |
117 | - create TinyMceArticle, :name => 'test', :profile_id => fast_create(Profile).id, :published => true | |
118 | + create TinyMceArticle, name: 'test', profile_id: profile.id, published: true | |
118 | 119 | assert_equal 1, ActionTracker::Record.count |
119 | 120 | end |
120 | 121 | |
121 | 122 | should 'not group trackers activity of article\'s creation' do |
122 | 123 | ActionTracker::Record.delete_all |
123 | - profile = fast_create(Profile) | |
124 | - create TinyMceArticle, :name => 'bar', :profile_id => profile.id, :published => true | |
125 | - create TinyMceArticle, :name => 'another bar', :profile_id => profile.id, :published => true | |
124 | + create TinyMceArticle, name: 'bar', profile_id: profile.id, published: true | |
125 | + create TinyMceArticle, name: 'another bar', profile_id: profile.id, published: true | |
126 | 126 | assert_equal 2, ActionTracker::Record.count |
127 | - create TinyMceArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true | |
127 | + create TinyMceArticle, name: 'another bar 2', profile_id: profile.id, published: true | |
128 | 128 | assert_equal 3, ActionTracker::Record.count |
129 | 129 | end |
130 | 130 | |
131 | 131 | should 'not update activity on update of an article' do |
132 | 132 | ActionTracker::Record.delete_all |
133 | - profile = fast_create(Profile) | |
134 | - article = create(TinyMceArticle, :profile_id => profile.id) | |
133 | + article = create TinyMceArticle, profile_id: profile.id | |
135 | 134 | time = article.activity.updated_at |
136 | 135 | Time.stubs(:now).returns(time + 1.day) |
137 | 136 | assert_no_difference 'ActionTracker::Record.count' do |
... | ... | @@ -143,8 +142,8 @@ class TinyMceArticleTest < ActiveSupport::TestCase |
143 | 142 | |
144 | 143 | should 'not create trackers activity when updating articles' do |
145 | 144 | ActionTracker::Record.delete_all |
146 | - a1 = create TinyMceArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | |
147 | - a2 = create TinyMceArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true | |
145 | + a1 = create TinyMceArticle, name: 'bar', profile_id: profile.id, published: true | |
146 | + a2 = create TinyMceArticle, name: 'another bar', profile_id: profile.id, published: true | |
148 | 147 | assert_no_difference 'ActionTracker::Record.count' do |
149 | 148 | a1.name = 'foo';a1.save! |
150 | 149 | a2.name = 'another foo';a2.save! |
... | ... | @@ -153,34 +152,32 @@ class TinyMceArticleTest < ActiveSupport::TestCase |
153 | 152 | |
154 | 153 | should 'remove activity when an article is destroyed' do |
155 | 154 | ActionTracker::Record.delete_all |
156 | - a1 = create TinyMceArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | |
157 | - a2 = create TinyMceArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true | |
155 | + a1 = create TinyMceArticle, name: 'bar', profile_id: profile.id, published: true | |
156 | + a2 = create TinyMceArticle, name: 'another bar', profile_id: profile.id, published: true | |
158 | 157 | assert_difference 'ActionTracker::Record.count', -2 do |
159 | 158 | a1.destroy |
160 | 159 | a2.destroy |
161 | -end | |
160 | + end | |
162 | 161 | end |
163 | 162 | |
164 | 163 | should "the tracker action target be defined as the article on articles'creation in communities" do |
165 | 164 | ActionTracker::Record.delete_all |
166 | 165 | community = fast_create(Community) |
167 | - p1 = Person.first | |
168 | - community.add_member(p1) | |
169 | - assert p1.is_member_of?(community) | |
170 | - article = create TinyMceArticle, :name => 'test', :profile_id => community.id | |
166 | + community.add_member profile | |
167 | + assert profile.is_member_of?(community) | |
168 | + article = create TinyMceArticle, name: 'test', profile_id: community.id | |
171 | 169 | assert_equal article, ActionTracker::Record.last.target |
172 | 170 | end |
173 | 171 | |
174 | 172 | should "the tracker action target be defined as the article on articles'creation in profile" do |
175 | 173 | ActionTracker::Record.delete_all |
176 | - person = Person.first | |
177 | - article = create TinyMceArticle, :name => 'test', :profile_id => person.id | |
174 | + article = create TinyMceArticle, name: 'test', profile_id: profile.id | |
178 | 175 | assert_equal article, ActionTracker::Record.last.target |
179 | 176 | end |
180 | 177 | |
181 | 178 | should 'not notify activity if the article is not advertise' do |
182 | 179 | ActionTracker::Record.delete_all |
183 | - a = create TinyMceArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true, :advertise => false | |
180 | + a = create TinyMceArticle, name: 'bar', profile_id: profile.id, published: true, advertise: false | |
184 | 181 | assert_equal true, a.published? |
185 | 182 | assert_equal true, a.notifiable? |
186 | 183 | assert_equal false, a.image? | ... | ... |
vendor/plugins/action_tracker/lib/action_tracker_model.rb