Commit eaaf3e5e2abb0ae79db449d63c4e4bbd8536f456
Committed by
Victor Costa
1 parent
d50ac31c
Exists in
master
and in
26 other branches
Option to filter by template in search
Showing
13 changed files
with
407 additions
and
8 deletions
Show diff stats
app/controllers/public/search_controller.rb
| @@ -9,6 +9,7 @@ class SearchController < PublicController | @@ -9,6 +9,7 @@ class SearchController < PublicController | ||
| 9 | before_filter :load_search_assets, :except => :suggestions | 9 | before_filter :load_search_assets, :except => :suggestions |
| 10 | before_filter :load_query, :except => :suggestions | 10 | before_filter :load_query, :except => :suggestions |
| 11 | before_filter :load_order, :except => :suggestions | 11 | before_filter :load_order, :except => :suggestions |
| 12 | + before_filter :load_templates, :except => :suggestions | ||
| 12 | 13 | ||
| 13 | # Backwards compatibility with old URLs | 14 | # Backwards compatibility with old URLs |
| 14 | def redirect_asset_param | 15 | def redirect_asset_param |
| @@ -210,6 +211,11 @@ class SearchController < PublicController | @@ -210,6 +211,11 @@ class SearchController < PublicController | ||
| 210 | end | 211 | end |
| 211 | end | 212 | end |
| 212 | 213 | ||
| 214 | + def load_templates | ||
| 215 | + @templates = {} | ||
| 216 | + @templates[@asset] = environment.send(@asset.to_s).templates if [:people, :enterprises, :communities].include?(@asset) | ||
| 217 | + end | ||
| 218 | + | ||
| 213 | def limit | 219 | def limit |
| 214 | if map_search?(@searches) | 220 | if map_search?(@searches) |
| 215 | MAP_SEARCH_LIMIT | 221 | MAP_SEARCH_LIMIT |
| @@ -230,7 +236,7 @@ class SearchController < PublicController | @@ -230,7 +236,7 @@ class SearchController < PublicController | ||
| 230 | end | 236 | end |
| 231 | 237 | ||
| 232 | def full_text_search | 238 | def full_text_search |
| 233 | - @searches[@asset] = find_by_contents(@asset, environment, @scope, @query, paginate_options, {:category => @category, :filter => @order}) | 239 | + @searches[@asset] = find_by_contents(@asset, environment, @scope, @query, paginate_options, {:category => @category, :filter => @order, :template_id => params[:template_id]}) |
| 234 | end | 240 | end |
| 235 | 241 | ||
| 236 | private | 242 | private |
app/helpers/layout_helper.rb
| @@ -49,6 +49,7 @@ module LayoutHelper | @@ -49,6 +49,7 @@ module LayoutHelper | ||
| 49 | 'selectordie', | 49 | 'selectordie', |
| 50 | 'inputosaurus', | 50 | 'inputosaurus', |
| 51 | 'chat', | 51 | 'chat', |
| 52 | + 'selectordie-theme', | ||
| 52 | pngfix_stylesheet_path, | 53 | pngfix_stylesheet_path, |
| 53 | ] + tokeninput_stylesheets | 54 | ] + tokeninput_stylesheets |
| 54 | plugins_stylesheets = @plugins.select(&:stylesheet?).map { |plugin| plugin.class.public_path('style.css') } | 55 | plugins_stylesheets = @plugins.select(&:stylesheet?).map { |plugin| plugin.class.public_path('style.css') } |
app/helpers/search_helper.rb
| @@ -148,4 +148,11 @@ module SearchHelper | @@ -148,4 +148,11 @@ module SearchHelper | ||
| 148 | link_to(@enabled_searches[asset], "/search/#{asset}") | 148 | link_to(@enabled_searches[asset], "/search/#{asset}") |
| 149 | end | 149 | end |
| 150 | 150 | ||
| 151 | + def assets_submenu(asset) | ||
| 152 | + return '' if @templates[asset].blank? || @templates[asset].length == 1 | ||
| 153 | + options = @templates[asset].map {|template| [template.name, template.id]} | ||
| 154 | + options = options_for_select([[_('Choose a template'), nil]] + options, selected: (params[:template_id])) | ||
| 155 | + select_tag('template_id', options, :id => 'submenu') | ||
| 156 | + end | ||
| 157 | + | ||
| 151 | end | 158 | end |
app/models/profile.rb
| @@ -85,7 +85,15 @@ class Profile < ActiveRecord::Base | @@ -85,7 +85,15 @@ class Profile < ActiveRecord::Base | ||
| 85 | #FIXME: these will work only if the subclass is already loaded | 85 | #FIXME: these will work only if the subclass is already loaded |
| 86 | scope :enterprises, lambda { {:conditions => (Enterprise.send(:subclasses).map(&:name) << 'Enterprise').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } | 86 | scope :enterprises, lambda { {:conditions => (Enterprise.send(:subclasses).map(&:name) << 'Enterprise').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } |
| 87 | scope :communities, lambda { {:conditions => (Community.send(:subclasses).map(&:name) << 'Community').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } | 87 | scope :communities, lambda { {:conditions => (Community.send(:subclasses).map(&:name) << 'Community').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } |
| 88 | - scope :templates, {:conditions => {:is_template => true}} | 88 | + scope :templates, lambda { |template_id = nil| |
| 89 | + conditions = {:conditions => {:is_template => true}} | ||
| 90 | + conditions[:conditions].merge!({:id => template_id}) unless template_id.nil? | ||
| 91 | + conditions | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + scope :with_templates, lambda { |templates| | ||
| 95 | + {:conditions => {:template_id => templates}} | ||
| 96 | + } | ||
| 89 | scope :no_templates, {:conditions => {:is_template => false}} | 97 | scope :no_templates, {:conditions => {:is_template => false}} |
| 90 | 98 | ||
| 91 | def members | 99 | def members |
app/views/search/_search_content.html.erb
| 1 | <div id='search-content'> | 1 | <div id='search-content'> |
| 2 | + <div class='total'> | ||
| 3 | + <%= _('Total of %s results ') % @searches[@asset][:results].total_entries.inspect %> | ||
| 4 | + </div> | ||
| 5 | + | ||
| 2 | <%= display_results(@searches, @asset) %> | 6 | <%= display_results(@searches, @asset) %> |
| 3 | <% if params[:display] != 'map' %> | 7 | <% if params[:display] != 'map' %> |
| 4 | <%= pagination_links @searches[@asset][:results] %> | 8 | <%= pagination_links @searches[@asset][:results] %> |
app/views/search/_search_form.html.erb
| @@ -5,8 +5,12 @@ | @@ -5,8 +5,12 @@ | ||
| 5 | <div id='search-header'> | 5 | <div id='search-header'> |
| 6 | <%= assets_menu(@asset) %> | 6 | <%= assets_menu(@asset) %> |
| 7 | <%= filters(@asset) %> | 7 | <%= filters(@asset) %> |
| 8 | + <div class="clear"></div> | ||
| 8 | </div> | 9 | </div> |
| 9 | 10 | ||
| 11 | + <div id='search-subheader'> | ||
| 12 | + <%= assets_submenu(@asset) %> | ||
| 13 | + </div> | ||
| 10 | <div class="search-field"> | 14 | <div class="search-field"> |
| 11 | <span class="formfield"> | 15 | <span class="formfield"> |
| 12 | <%= search_input_with_suggestions('query', @asset, @query, {:id => 'search-input', :size => 50, :placeholder => hint}) %> | 16 | <%= search_input_with_suggestions('query', @asset, @query, {:id => 'search-input', :size => 50, :placeholder => hint}) %> |
lib/noosfero/plugin.rb
| @@ -556,6 +556,7 @@ class Noosfero::Plugin | @@ -556,6 +556,7 @@ class Noosfero::Plugin | ||
| 556 | # own use in specific views | 556 | # own use in specific views |
| 557 | def find_by_contents(asset, scope, query, paginate_options={}, options={}) | 557 | def find_by_contents(asset, scope, query, paginate_options={}, options={}) |
| 558 | scope = scope.like_search(query, options) unless query.blank? | 558 | scope = scope.like_search(query, options) unless query.blank? |
| 559 | + scope = scope.with_templates(options[:template_id]) unless options[:template_id].blank? | ||
| 559 | scope = scope.send(options[:filter]) unless options[:filter].blank? | 560 | scope = scope.send(options[:filter]) unless options[:filter].blank? |
| 560 | {:results => scope.paginate(paginate_options)} | 561 | {:results => scope.paginate(paginate_options)} |
| 561 | end | 562 | end |
public/javascripts/search.js
| @@ -15,9 +15,17 @@ | @@ -15,9 +15,17 @@ | ||
| 15 | $('form.search_form').submit(); | 15 | $('form.search_form').submit(); |
| 16 | }); | 16 | }); |
| 17 | 17 | ||
| 18 | + // Filter submenu | ||
| 19 | + $('#search-subheader select').change(function(){ | ||
| 20 | + $('form.search_form').submit(); | ||
| 21 | + }); | ||
| 22 | + | ||
| 18 | // Custom styled select | 23 | // Custom styled select |
| 19 | $('#search-filters select').selectOrDie(); | 24 | $('#search-filters select').selectOrDie(); |
| 20 | 25 | ||
| 26 | + // Custom styled select | ||
| 27 | + $('#search-subheader select').selectOrDie(); | ||
| 28 | + | ||
| 21 | // Form Ajax submission | 29 | // Form Ajax submission |
| 22 | $('form.search_form').submit(function () { | 30 | $('form.search_form').submit(function () { |
| 23 | $.ajax({ | 31 | $.ajax({ |
public/stylesheets/search.css
| @@ -953,7 +953,7 @@ ul#assets-menu { | @@ -953,7 +953,7 @@ ul#assets-menu { | ||
| 953 | text-align: justify; | 953 | text-align: justify; |
| 954 | text-justify: distribute-all-lines; /* distribute items in IE */ | 954 | text-justify: distribute-all-lines; /* distribute items in IE */ |
| 955 | list-style-type: none; | 955 | list-style-type: none; |
| 956 | - margin: 5px 0 13px; | 956 | + margin: 5px 0px 10px 0px; |
| 957 | padding: 0; | 957 | padding: 0; |
| 958 | width: 500px; | 958 | width: 500px; |
| 959 | float: left; | 959 | float: left; |
| @@ -984,6 +984,15 @@ ul#assets-menu li.selected a { | @@ -984,6 +984,15 @@ ul#assets-menu li.selected a { | ||
| 984 | color: #EF2929; | 984 | color: #EF2929; |
| 985 | font-weight: bold; | 985 | font-weight: bold; |
| 986 | } | 986 | } |
| 987 | +ul#assets-links li.selected a { | ||
| 988 | + border-bottom: 4px solid #dd4b39; | ||
| 989 | + padding-bottom: 6px; | ||
| 990 | +} | ||
| 991 | + | ||
| 992 | +ul#assets-links li.selected a { | ||
| 993 | + color: #dd4b39; | ||
| 994 | + font-weight: bold; | ||
| 995 | +} | ||
| 987 | 996 | ||
| 988 | #search-filters { | 997 | #search-filters { |
| 989 | float: right; | 998 | float: right; |
| @@ -1037,3 +1046,13 @@ ul#assets-menu li.selected a { | @@ -1037,3 +1046,13 @@ ul#assets-menu li.selected a { | ||
| 1037 | border-bottom:1px solid #ccc; | 1046 | border-bottom:1px solid #ccc; |
| 1038 | margin-bottom: 10px; | 1047 | margin-bottom: 10px; |
| 1039 | } | 1048 | } |
| 1049 | + | ||
| 1050 | +#search-header{ | ||
| 1051 | + border-bottom: 1px solid #ebebeb; | ||
| 1052 | +} | ||
| 1053 | + | ||
| 1054 | +#search-content .total{ | ||
| 1055 | + color: #808080; | ||
| 1056 | + line-height: 20px; | ||
| 1057 | + font-style: oblique; | ||
| 1058 | +} |
| @@ -0,0 +1,75 @@ | @@ -0,0 +1,75 @@ | ||
| 1 | +/* Default custom select styles */ | ||
| 2 | + | ||
| 3 | +#search-subheader div.sod_select { | ||
| 4 | + display: inline-block; | ||
| 5 | + vertical-align: middle; | ||
| 6 | + position: relative; | ||
| 7 | + text-align: left; | ||
| 8 | + background: #fff; | ||
| 9 | + z-index: 100; | ||
| 10 | + -webkit-touch-callout: none; | ||
| 11 | + -webkit-user-select: none; | ||
| 12 | + -khtml-user-select: none; | ||
| 13 | + -moz-user-select: none; | ||
| 14 | + -ms-user-select: none; | ||
| 15 | + user-select: none; | ||
| 16 | + background: transparent; | ||
| 17 | + max-width: 400px; | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +#search-subheader div.sod_select:focus { | ||
| 21 | + outline: none; /* For better accessibility add a style for this in your skin */ | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +#search-subheader .sod_select select { | ||
| 25 | + display: none; | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +#search-subheader .sod_label::after { | ||
| 29 | + font-family: Arial, 'Liberation Sans', sans-serif; | ||
| 30 | + font-weight: bold; | ||
| 31 | + content: '+'; | ||
| 32 | + left: 0px; | ||
| 33 | + -webkit-transform: translate3d(0,-50%,0) rotate3d(0,0,1,0deg);; | ||
| 34 | + transform: translate3d(0,-50%,0) rotate3d(0,0,1,0deg);; | ||
| 35 | + -webkit-transition: -webkit-transform 0.5s; | ||
| 36 | + transition: transform 0.5s; | ||
| 37 | + position: absolute; | ||
| 38 | + top: 50%; | ||
| 39 | + font-size: 2.1em; | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +#search-subheader .sod_select.open .sod_label::after { | ||
| 43 | + -webkit-transform: translate3d(0,-50%,0) rotate3d(0,0,1,225deg); | ||
| 44 | + transform: translate3d(0,-50%,0) rotate3d(0,0,1,225deg); | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +/* Changes on select or die*/ | ||
| 48 | +#search-subheader .sod_select{ | ||
| 49 | + border: none; | ||
| 50 | + padding-top: 10px; | ||
| 51 | + padding-left: 20px; | ||
| 52 | + padding-bottom: 10px; | ||
| 53 | + width: auto; | ||
| 54 | + font-weight: normal; | ||
| 55 | + text-transform: none; | ||
| 56 | + font-size: 12px; | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +#search-subheader .sod_select.open{ | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +#search-subheader .sod_select .sod_list{ | ||
| 63 | + border: 1px solid #ebebeb; | ||
| 64 | + margin-left: -1px; | ||
| 65 | + width: auto; | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +#search-subheader .sod_select:before, | ||
| 69 | +#search-subheader .sod_select:after { | ||
| 70 | + content: ""; | ||
| 71 | +} | ||
| 72 | + | ||
| 73 | +#search-subheader .sod_select.focus { | ||
| 74 | + box-shadow: none; | ||
| 75 | +} |
test/functional/search_controller_test.rb
| @@ -13,14 +13,14 @@ class SearchControllerTest < ActionController::TestCase | @@ -13,14 +13,14 @@ class SearchControllerTest < ActionController::TestCase | ||
| 13 | @request.stubs(:ssl?).returns(false) | 13 | @request.stubs(:ssl?).returns(false) |
| 14 | @response = ActionController::TestResponse.new | 14 | @response = ActionController::TestResponse.new |
| 15 | 15 | ||
| 16 | - @category = Category.create!(:name => 'my-category', :environment => Environment.default) | 16 | + @environment = Environment.default |
| 17 | + @category = Category.create!(:name => 'my-category', :environment => @environment) | ||
| 17 | 18 | ||
| 18 | - env = Environment.default | ||
| 19 | - domain = env.domains.first | 19 | + domain = @environment.domains.first |
| 20 | if !domain | 20 | if !domain |
| 21 | domain = Domain.create!(:name => "127.0.0.1") | 21 | domain = Domain.create!(:name => "127.0.0.1") |
| 22 | - env.domains = [domain] | ||
| 23 | - env.save! | 22 | + @environment.domains = [domain] |
| 23 | + @environment.save! | ||
| 24 | end | 24 | end |
| 25 | domain.google_maps_key = 'ENVIRONMENT_KEY' | 25 | domain.google_maps_key = 'ENVIRONMENT_KEY' |
| 26 | domain.save! | 26 | domain.save! |
| @@ -37,6 +37,8 @@ class SearchControllerTest < ActionController::TestCase | @@ -37,6 +37,8 @@ class SearchControllerTest < ActionController::TestCase | ||
| 37 | Person.any_instance.stubs(:user).returns(user) | 37 | Person.any_instance.stubs(:user).returns(user) |
| 38 | end | 38 | end |
| 39 | 39 | ||
| 40 | + attr_reader :environment | ||
| 41 | + | ||
| 40 | def create_article_with_optional_category(name, profile, category = nil) | 42 | def create_article_with_optional_category(name, profile, category = nil) |
| 41 | fast_create(Article, {:name => name, :profile_id => profile.id }, :search => true, :category => category) | 43 | fast_create(Article, {:name => name, :profile_id => profile.id }, :search => true, :category => category) |
| 42 | end | 44 | end |
| @@ -651,6 +653,122 @@ class SearchControllerTest < ActionController::TestCase | @@ -651,6 +653,122 @@ class SearchControllerTest < ActionController::TestCase | ||
| 651 | assert_equal [st1,st2].to_json, response.body | 653 | assert_equal [st1,st2].to_json, response.body |
| 652 | end | 654 | end |
| 653 | 655 | ||
| 656 | + should 'templates variable be an hash in articles asset' do | ||
| 657 | + get :articles | ||
| 658 | + assert assigns(:templates).kind_of?(Hash) | ||
| 659 | + end | ||
| 660 | + | ||
| 661 | + should 'not load people templates in articles asset' do | ||
| 662 | + t1 = fast_create(Person, :is_template => true, :environment_id => environment.id) | ||
| 663 | + t2 = fast_create(Person, :is_template => true, :environment_id => environment.id) | ||
| 664 | + get :articles | ||
| 665 | + assert_nil assigns(:templates)[:people] | ||
| 666 | + end | ||
| 667 | + | ||
| 668 | + should 'not load communities templates in articles asset' do | ||
| 669 | + t1 = fast_create(Community, :is_template => true, :environment_id => environment.id) | ||
| 670 | + t2 = fast_create(Community, :is_template => true, :environment_id => environment.id) | ||
| 671 | + get :articles | ||
| 672 | + assert_nil assigns(:templates)[:communities] | ||
| 673 | + end | ||
| 674 | + | ||
| 675 | + should 'not load enterprises templates in articles asset' do | ||
| 676 | + t1 = fast_create(Enterprise, :is_template => true, :environment_id => environment.id) | ||
| 677 | + t2 = fast_create(Enterprise, :is_template => true, :environment_id => environment.id) | ||
| 678 | + get :articles | ||
| 679 | + assert_nil assigns(:templates)[:enterprises] | ||
| 680 | + end | ||
| 681 | + | ||
| 682 | + should 'templates variable be equals to people templates in people assert' do | ||
| 683 | + t1 = fast_create(Person, :is_template => true, :environment_id => environment.id) | ||
| 684 | + t2 = fast_create(Person, :is_template => true, :environment_id => environment.id) | ||
| 685 | + get :people | ||
| 686 | + | ||
| 687 | + assert_equivalent [t1,t2], assigns(:templates)[:people] | ||
| 688 | + end | ||
| 689 | + | ||
| 690 | + should 'not load communities templates in people asset' do | ||
| 691 | + t1 = fast_create(Community, :is_template => true, :environment_id => environment.id) | ||
| 692 | + t2 = fast_create(Community, :is_template => true, :environment_id => environment.id) | ||
| 693 | + get :people | ||
| 694 | + assert_nil assigns(:templates)[:communities] | ||
| 695 | + end | ||
| 696 | + | ||
| 697 | + should 'not load enterprises templates in people asset' do | ||
| 698 | + t1 = fast_create(Enterprise, :is_template => true, :environment_id => environment.id) | ||
| 699 | + t2 = fast_create(Enterprise, :is_template => true, :environment_id => environment.id) | ||
| 700 | + get :people | ||
| 701 | + assert_nil assigns(:templates)[:enterprises] | ||
| 702 | + end | ||
| 703 | + | ||
| 704 | + should 'templates variable be equals to communities templates in communities assert' do | ||
| 705 | + t1 = fast_create(Community, :is_template => true, :environment_id => environment.id) | ||
| 706 | + t2 = fast_create(Community, :is_template => true, :environment_id => environment.id) | ||
| 707 | + get :communities | ||
| 708 | + | ||
| 709 | + assert_equivalent [t1,t2], assigns(:templates)[:communities] | ||
| 710 | + end | ||
| 711 | + | ||
| 712 | + should 'not load people templates in communities asset' do | ||
| 713 | + t1 = fast_create(Person, :is_template => true, :environment_id => environment.id) | ||
| 714 | + t2 = fast_create(Person, :is_template => true, :environment_id => environment.id) | ||
| 715 | + get :communities | ||
| 716 | + assert_nil assigns(:templates)[:people] | ||
| 717 | + end | ||
| 718 | + | ||
| 719 | + should 'not load enterprises templates in communities asset' do | ||
| 720 | + t1 = fast_create(Enterprise, :is_template => true, :environment_id => environment.id) | ||
| 721 | + t2 = fast_create(Enterprise, :is_template => true, :environment_id => environment.id) | ||
| 722 | + get :communities | ||
| 723 | + assert_nil assigns(:templates)[:enterprises] | ||
| 724 | + end | ||
| 725 | + | ||
| 726 | + should 'templates variable be equals to enterprises templates in enterprises assert' do | ||
| 727 | + t1 = fast_create(Enterprise, :is_template => true, :environment_id => environment.id) | ||
| 728 | + t2 = fast_create(Enterprise, :is_template => true, :environment_id => environment.id) | ||
| 729 | + get :enterprises | ||
| 730 | + | ||
| 731 | + assert_equivalent [t1,t2], assigns(:templates)[:enterprises] | ||
| 732 | + end | ||
| 733 | + | ||
| 734 | + should 'not load communities templates in enterprises asset' do | ||
| 735 | + t1 = fast_create(Community, :is_template => true, :environment_id => environment.id) | ||
| 736 | + t2 = fast_create(Community, :is_template => true, :environment_id => environment.id) | ||
| 737 | + get :enterprises | ||
| 738 | + assert_nil assigns(:templates)[:communities] | ||
| 739 | + end | ||
| 740 | + | ||
| 741 | + should 'not load people templates in enterprises asset' do | ||
| 742 | + t1 = fast_create(Person, :is_template => true, :environment_id => environment.id) | ||
| 743 | + t2 = fast_create(Person, :is_template => true, :environment_id => environment.id) | ||
| 744 | + get :enterprises | ||
| 745 | + assert_nil assigns(:templates)[:people] | ||
| 746 | + end | ||
| 747 | + | ||
| 748 | + should 'list all community of on specific template' do | ||
| 749 | + t1 = fast_create(Community, :is_template => true, :environment_id => environment.id) | ||
| 750 | + t2 = fast_create(Community, :is_template => true, :environment_id => environment.id) | ||
| 751 | + c1 = fast_create(Community, :template_id => t1.id, :name => 'Testing community 1', :created_at => DateTime.now - 2) | ||
| 752 | + c2 = fast_create(Community, :template_id => t2.id, :name => 'Testing community 2', :created_at => DateTime.now - 1) | ||
| 753 | + c3 = fast_create(Community, :template_id => t1.id, :name => 'Testing community 3') | ||
| 754 | + c4 = fast_create(Community, :name => 'Testing community 3') | ||
| 755 | + | ||
| 756 | + get :communities, :template_id => t1.id | ||
| 757 | + assert_equivalent [c1,c3] , assigns(:searches)[:communities][:results] | ||
| 758 | + end | ||
| 759 | + | ||
| 760 | + should 'list all communities of no template is passed' do | ||
| 761 | + t1 = fast_create(Community, :is_template => true, :environment_id => environment.id) | ||
| 762 | + t2 = fast_create(Community, :is_template => true, :environment_id => environment.id) | ||
| 763 | + c1 = create(Community, :template_id => t1.id, :name => 'Testing community 1', :created_at => DateTime.now - 2) | ||
| 764 | + c2 = create(Community, :template_id => t2.id, :name => 'Testing community 2', :created_at => DateTime.now - 1) | ||
| 765 | + c3 = create(Community, :template_id => t1.id, :name => 'Testing community 3') | ||
| 766 | + c4 = create(Community, :name => 'Testing community 3') | ||
| 767 | + | ||
| 768 | + get :communities, :template_id => nil | ||
| 769 | + assert_equivalent [t1,t2,c1,c2,c3,c4] , assigns(:searches)[:communities][:results] | ||
| 770 | + end | ||
| 771 | + | ||
| 654 | protected | 772 | protected |
| 655 | 773 | ||
| 656 | def create_event(profile, options) | 774 | def create_event(profile, options) |
test/unit/profile_test.rb
| @@ -1406,6 +1406,71 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1406,6 +1406,71 @@ class ProfileTest < ActiveSupport::TestCase | ||
| 1406 | assert_not_includes environment.profiles.templates, profile | 1406 | assert_not_includes environment.profiles.templates, profile |
| 1407 | end | 1407 | end |
| 1408 | 1408 | ||
| 1409 | + should 'return an specific template when specified' do | ||
| 1410 | + environment = Environment.default | ||
| 1411 | + t1 = fast_create(Profile, :is_template => true) | ||
| 1412 | + t2 = fast_create(Profile, :is_template => true) | ||
| 1413 | + profile = fast_create(Profile) | ||
| 1414 | + | ||
| 1415 | + assert_equal [t1], environment.profiles.templates(t1) | ||
| 1416 | + assert_equal [t2], environment.profiles.templates(t2) | ||
| 1417 | + end | ||
| 1418 | + | ||
| 1419 | + should 'not return a template when and invalid template is specified' do | ||
| 1420 | + environment = Environment.default | ||
| 1421 | + t1 = fast_create(Profile, :is_template => true) | ||
| 1422 | + t2 = fast_create(Profile, :is_template => true) | ||
| 1423 | + t3 = fast_create(Profile) | ||
| 1424 | + | ||
| 1425 | + assert_equal [], environment.profiles.templates(t3) | ||
| 1426 | + end | ||
| 1427 | + | ||
| 1428 | + should 'return profiles of specified template passing object' do | ||
| 1429 | + environment = Environment.default | ||
| 1430 | + t1 = fast_create(Profile, :is_template => true) | ||
| 1431 | + t2 = fast_create(Profile, :is_template => true) | ||
| 1432 | + p1 = fast_create(Profile, :template_id => t1.id) | ||
| 1433 | + p2 = fast_create(Profile, :template_id => t2.id) | ||
| 1434 | + p3 = fast_create(Profile, :template_id => t1.id) | ||
| 1435 | + | ||
| 1436 | + assert_equivalent [p1,p3], environment.profiles.with_templates(t1) | ||
| 1437 | + end | ||
| 1438 | + | ||
| 1439 | + should 'return profiles of specified template passing id' do | ||
| 1440 | + environment = Environment.default | ||
| 1441 | + t1 = fast_create(Profile, :is_template => true) | ||
| 1442 | + t2 = fast_create(Profile, :is_template => true) | ||
| 1443 | + p1 = fast_create(Profile, :template_id => t1.id) | ||
| 1444 | + p2 = fast_create(Profile, :template_id => t2.id) | ||
| 1445 | + p3 = fast_create(Profile, :template_id => t1.id) | ||
| 1446 | + | ||
| 1447 | + assert_equivalent [p1,p3], environment.profiles.with_templates(t1.id) | ||
| 1448 | + end | ||
| 1449 | + | ||
| 1450 | + should 'return profiles of a list of specified templates' do | ||
| 1451 | + environment = Environment.default | ||
| 1452 | + t1 = fast_create(Profile, :is_template => true) | ||
| 1453 | + t2 = fast_create(Profile, :is_template => true) | ||
| 1454 | + t3 = fast_create(Profile, :is_template => true) | ||
| 1455 | + p1 = fast_create(Profile, :template_id => t1.id) | ||
| 1456 | + p2 = fast_create(Profile, :template_id => t2.id) | ||
| 1457 | + p3 = fast_create(Profile, :template_id => t3.id) | ||
| 1458 | + | ||
| 1459 | + assert_equivalent [p1,p2], environment.profiles.with_templates([t1,t2]) | ||
| 1460 | + end | ||
| 1461 | + | ||
| 1462 | + should 'return all profiles without any template if nil is passed as parameter' do | ||
| 1463 | + environment = Environment.default | ||
| 1464 | + Profile.delete_all | ||
| 1465 | + t1 = fast_create(Profile, :is_template => true) | ||
| 1466 | + t2 = fast_create(Profile, :is_template => true) | ||
| 1467 | + p1 = fast_create(Profile, :template_id => t1.id) | ||
| 1468 | + p2 = fast_create(Profile, :template_id => t2.id) | ||
| 1469 | + p3 = fast_create(Profile) | ||
| 1470 | + | ||
| 1471 | + assert_equivalent [t1,t2,p3], environment.profiles.with_templates(nil) | ||
| 1472 | + end | ||
| 1473 | + | ||
| 1409 | should 'return a list of profiles that are not templates' do | 1474 | should 'return a list of profiles that are not templates' do |
| 1410 | environment = Environment.default | 1475 | environment = Environment.default |
| 1411 | p1 = fast_create(Profile, :is_template => false) | 1476 | p1 = fast_create(Profile, :is_template => false) |
test/unit/search_helper_test.rb
| @@ -3,6 +3,9 @@ require_relative "../test_helper" | @@ -3,6 +3,9 @@ require_relative "../test_helper" | ||
| 3 | class SearchHelperTest < ActiveSupport::TestCase | 3 | class SearchHelperTest < ActiveSupport::TestCase |
| 4 | 4 | ||
| 5 | include SearchHelper | 5 | include SearchHelper |
| 6 | + include ActionView::Helpers::FormOptionsHelper | ||
| 7 | + include ActionView::Helpers::FormTagHelper | ||
| 8 | + | ||
| 6 | 9 | ||
| 7 | should 'return whether on a multiple search' do | 10 | should 'return whether on a multiple search' do |
| 8 | stubs(:params).returns({:action => 'index', :display => 'map'}) | 11 | stubs(:params).returns({:action => 'index', :display => 'map'}) |
| @@ -122,4 +125,84 @@ class SearchHelperTest < ActiveSupport::TestCase | @@ -122,4 +125,84 @@ class SearchHelperTest < ActiveSupport::TestCase | ||
| 122 | end | 125 | end |
| 123 | end | 126 | end |
| 124 | 127 | ||
| 128 | + should 'return an empty string in assets_submenu for articles assets' do | ||
| 129 | + @templates = {} | ||
| 130 | + assert_equal '', assets_submenu(:articles) | ||
| 131 | + @templates = {:articles => nil} | ||
| 132 | + assert_equal '', assets_submenu(:articles) | ||
| 133 | + end | ||
| 134 | + | ||
| 135 | + should 'return an empty string in assets_submenu for people asset without template' do | ||
| 136 | + @templates = {:people => nil} | ||
| 137 | + assert_equal '', assets_submenu(:people) | ||
| 138 | + | ||
| 139 | + @templates = {:people => []} | ||
| 140 | + assert_equal '', assets_submenu(:people) | ||
| 141 | + end | ||
| 142 | + | ||
| 143 | + should 'return an empty string in assets_submenu for people asset with only one template' do | ||
| 144 | + t = fast_create(Person, :is_template => true) | ||
| 145 | + @templates = {:people => [t]} | ||
| 146 | + assert_equal '', assets_submenu(:people) | ||
| 147 | + end | ||
| 148 | + | ||
| 149 | + should 'return a select of templates for people asset with more then one template' do | ||
| 150 | + t1 = fast_create(Person, :is_template => true) | ||
| 151 | + t2 = fast_create(Person, :is_template => true) | ||
| 152 | + @templates = {:people => [t1,t2]} | ||
| 153 | + SearchHelperTest.any_instance.stubs(:params).returns({}) | ||
| 154 | + assert_match /select/, assets_submenu(:people) | ||
| 155 | + assert_match /#{t1.name}/, assets_submenu(:people) | ||
| 156 | + assert_match /#{t2.name}/, assets_submenu(:people) | ||
| 157 | + end | ||
| 158 | + | ||
| 159 | + should 'return an empty string in assets_submenu for communities asset without template' do | ||
| 160 | + @templates = {:communities => nil} | ||
| 161 | + assert_equal '', assets_submenu(:communities) | ||
| 162 | + | ||
| 163 | + @templates = {:communities => []} | ||
| 164 | + assert_equal '', assets_submenu(:communities) | ||
| 165 | + end | ||
| 166 | + | ||
| 167 | + should 'return an empty string in assets_submenu for communities asset with only one template' do | ||
| 168 | + t = fast_create(Community, :is_template => true) | ||
| 169 | + @templates = {:communities => [t]} | ||
| 170 | + assert_equal '', assets_submenu(:communities) | ||
| 171 | + end | ||
| 172 | + | ||
| 173 | + should 'return a select of templates for communities asset with more then one template' do | ||
| 174 | + t1 = fast_create(Community, :is_template => true) | ||
| 175 | + t2 = fast_create(Community, :is_template => true) | ||
| 176 | + @templates = {:communities => [t1,t2]} | ||
| 177 | + SearchHelperTest.any_instance.stubs(:params).returns({}) | ||
| 178 | + assert_match /select/, assets_submenu(:communities) | ||
| 179 | + assert_match /#{t1.name}/, assets_submenu(:communities) | ||
| 180 | + assert_match /#{t2.name}/, assets_submenu(:communities) | ||
| 181 | + end | ||
| 182 | + | ||
| 183 | + should 'return an empty string in assets_submenu for enterprises asset without template' do | ||
| 184 | + @templates = {:enterprises => nil} | ||
| 185 | + assert_equal '', assets_submenu(:enterprises) | ||
| 186 | + | ||
| 187 | + @templates = {:enterprises => []} | ||
| 188 | + assert_equal '', assets_submenu(:enterprises) | ||
| 189 | + end | ||
| 190 | + | ||
| 191 | + should 'return an empty string in assets_submenu for enterprises asset with only one template' do | ||
| 192 | + t = fast_create(Enterprise, :is_template => true) | ||
| 193 | + @templates = {:enterprises => [t]} | ||
| 194 | + assert_equal '', assets_submenu(:enterprises) | ||
| 195 | + end | ||
| 196 | + | ||
| 197 | + should 'return a select of templates for enterprises asset with more then one template' do | ||
| 198 | + t1 = fast_create(Enterprise, :is_template => true) | ||
| 199 | + t2 = fast_create(Enterprise, :is_template => true) | ||
| 200 | + @templates = {:enterprises => [t1,t2]} | ||
| 201 | + SearchHelperTest.any_instance.stubs(:params).returns({}) | ||
| 202 | + assert_match /select/, assets_submenu(:enterprises) | ||
| 203 | + assert_match /#{t1.name}/, assets_submenu(:enterprises) | ||
| 204 | + assert_match /#{t2.name}/, assets_submenu(:enterprises) | ||
| 205 | + end | ||
| 206 | + | ||
| 207 | + | ||
| 125 | end | 208 | end |