Commit e453a360890f55ad5af4ab3a1e6e9a8aa5ad8fed
Exists in
master
and in
29 other branches
Merge commit 'refs/merge-requests/227' of git://gitorious.org/noosfero/noosfero …
…into merge-requests/227
Showing
6 changed files
with
25 additions
and
8 deletions
Show diff stats
app/helpers/search_helper.rb
| ... | ... | @@ -50,7 +50,7 @@ module SearchHelper |
| 50 | 50 | end |
| 51 | 51 | |
| 52 | 52 | def map_search? |
| 53 | - !@query.blank? and !multiple_search? and params[:display] == 'map' | |
| 53 | + !@empty_query and !multiple_search? and params[:display] == 'map' | |
| 54 | 54 | end |
| 55 | 55 | |
| 56 | 56 | def search_page_title(title, category = nil) |
| ... | ... | @@ -107,7 +107,7 @@ module SearchHelper |
| 107 | 107 | @asset_class = asset_class(asset) |
| 108 | 108 | render(:partial => 'facets_unselect_menu') |
| 109 | 109 | end |
| 110 | - | |
| 110 | + | |
| 111 | 111 | def facet_javascript(input_id, facet, array) |
| 112 | 112 | array = [] if array.nil? |
| 113 | 113 | hintText = _('Type in an option') |
| ... | ... | @@ -156,6 +156,7 @@ module SearchHelper |
| 156 | 156 | params = params.dup |
| 157 | 157 | params[:facet].each do |id, value| |
| 158 | 158 | facet = klass.facet_by_id(id.to_sym) |
| 159 | + next unless facet | |
| 159 | 160 | if value.kind_of?(Hash) |
| 160 | 161 | label_hash = facet[:label].call(environment) |
| 161 | 162 | value.each do |label_id, value| | ... | ... |
app/models/product.rb
| 1 | 1 | class Product < ActiveRecord::Base |
| 2 | + | |
| 2 | 3 | belongs_to :enterprise |
| 3 | 4 | has_one :region, :through => :enterprise |
| 4 | 5 | validates_presence_of :enterprise |
| ... | ... | @@ -163,7 +164,7 @@ class Product < ActiveRecord::Base |
| 163 | 164 | |
| 164 | 165 | def total_production_cost |
| 165 | 166 | return inputs_cost if price_details.empty? |
| 166 | - inputs_cost + price_details.map(&:price).inject { |sum,price| sum + price } | |
| 167 | + inputs_cost + price_details.map(&:price).inject(0){ |sum,price| sum + price } | |
| 167 | 168 | end |
| 168 | 169 | |
| 169 | 170 | def price_described? | ... | ... |
app/models/uploaded_file.rb
| ... | ... | @@ -67,7 +67,7 @@ class UploadedFile < Article |
| 67 | 67 | 'upload-file' |
| 68 | 68 | end |
| 69 | 69 | end |
| 70 | - | |
| 70 | + | |
| 71 | 71 | def mime_type |
| 72 | 72 | content_type |
| 73 | 73 | end |
| ... | ... | @@ -129,6 +129,12 @@ class UploadedFile < Article |
| 129 | 129 | end |
| 130 | 130 | end |
| 131 | 131 | |
| 132 | + def extension | |
| 133 | + dotindex = self.filename.rindex('.') | |
| 134 | + return nil unless dotindex | |
| 135 | + self.filename[(dotindex+1)..-1].downcase | |
| 136 | + end | |
| 137 | + | |
| 132 | 138 | def allow_children? |
| 133 | 139 | false |
| 134 | 140 | end |
| ... | ... | @@ -144,4 +150,5 @@ class UploadedFile < Article |
| 144 | 150 | def uploaded_file? |
| 145 | 151 | true |
| 146 | 152 | end |
| 153 | + | |
| 147 | 154 | end | ... | ... |
app/views/search/_image.rhtml
| 1 | 1 | <div class="search-image-container"> |
| 2 | 2 | |
| 3 | 3 | <% if image.is_a? UploadedFile and image.filename %> |
| 4 | - <% extension = image.filename[(image.filename.rindex('.')+1)..-1].downcase %> | |
| 4 | + <% extension = image.extension %> | |
| 5 | 5 | <% if ['jpg', 'jpeg', 'gif', 'png', 'tiff', 'svg'].include? extension %> |
| 6 | 6 | <%= link_to '', image.view_url, :class => "search-image-pic", :style => 'background-image: url(%s)'% image.public_filename(:thumb) %> |
| 7 | 7 | <% if image.width && image.height %> | ... | ... |
lib/acts_as_faceted.rb
| ... | ... | @@ -8,7 +8,7 @@ module ActsAsFaceted |
| 8 | 8 | # |
| 9 | 9 | #acts_as_faceted :fields => { |
| 10 | 10 | # :f_type => {:label => _('Type'), :proc => proc{|klass| f_type_proc(klass)}}, |
| 11 | - # :f_published_at => {:type => :date, :label => _('Published date'), :queries => {'[* TO NOW-1YEARS/DAY]' => _("Older than one year"), | |
| 11 | + # :f_published_at => {:type => :date, :label => _('Published date'), :queries => {'[* TO NOW-1YEARS/DAY]' => _("Older than one year"), | |
| 12 | 12 | # '[NOW-1YEARS TO NOW/DAY]' => _("Last year"), '[NOW-1MONTHS TO NOW/DAY]' => _("Last month"), '[NOW-7DAYS TO NOW/DAY]' => _("Last week"), '[NOW-1DAYS TO NOW/DAY]' => _("Last day")}}, |
| 13 | 13 | # :f_profile_type => {:label => _('Author'), :proc => proc{|klass| f_profile_type_proc(klass)}}, |
| 14 | 14 | # :f_category => {:label => _('Categories')}}, |
| ... | ... | @@ -36,7 +36,7 @@ module ActsAsFaceted |
| 36 | 36 | self.facets_order = options[:order] || self.facets.keys |
| 37 | 37 | self.facets_results_containers = {:fields => 'facet_fields', :queries => 'facet_queries', :ranges => 'facet_ranges'} |
| 38 | 38 | self.facets_option_for_solr = Hash[facets.select{ |id,data| ! data.has_key?(:queries) }].keys |
| 39 | - self.facets_fields_for_solr = facets.map{ |id,data| {id => data[:type] || :facet} } | |
| 39 | + self.facets_fields_for_solr = facets.map{ |id,data| {id => data[:type] || :facet} } | |
| 40 | 40 | self.solr_fields_names = facets.map{ |id,data| id.to_s + '_' + get_solr_field_type(data[:type] || :facet) } |
| 41 | 41 | self.facet_category_query = options[:category_query] |
| 42 | 42 | |
| ... | ... | @@ -67,6 +67,7 @@ module ActsAsFaceted |
| 67 | 67 | raise 'Use map_facets_for before this method' if facet[:solr_field].nil? |
| 68 | 68 | facets_data = {} if facets_data.blank? # could be empty array |
| 69 | 69 | solr_facet = to_solr_fields_names[facet[:solr_field]] |
| 70 | + unfiltered_facets_data ||= {} | |
| 70 | 71 | |
| 71 | 72 | if facet[:queries] |
| 72 | 73 | container = facets_data[facets_results_containers[:queries]] |
| ... | ... | @@ -158,13 +159,15 @@ module ActsAsFaceted |
| 158 | 159 | end |
| 159 | 160 | |
| 160 | 161 | def facet_label(facet) |
| 161 | - _ facet[:label] | |
| 162 | + return nil unless facet | |
| 163 | + _(facet[:label]) | |
| 162 | 164 | end |
| 163 | 165 | |
| 164 | 166 | def facets_find_options(facets_selected = {}, options = {}) |
| 165 | 167 | browses = [] |
| 166 | 168 | facets_selected ||= {} |
| 167 | 169 | facets_selected.map do |id, value| |
| 170 | + next unless facets[id.to_sym] | |
| 168 | 171 | if value.kind_of?(Hash) |
| 169 | 172 | value.map do |label_id, value| |
| 170 | 173 | value.to_a.each do |value| | ... | ... |
test/unit/uploaded_file_test.rb
| ... | ... | @@ -306,6 +306,11 @@ class UploadedFileTest < ActiveSupport::TestCase |
| 306 | 306 | uses_sqlite |
| 307 | 307 | end |
| 308 | 308 | |
| 309 | + should 'return extension' do | |
| 310 | + file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => @profile) | |
| 311 | + assert_equal 'png', file.extension | |
| 312 | + end | |
| 313 | + | |
| 309 | 314 | should 'upload to path prefix folder if database is not postgresql' do |
| 310 | 315 | uses_sqlite |
| 311 | 316 | file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :profile => @profile) | ... | ... |