Commit 70662537aaa3b5e53b12458bd88aefa48abfa56a
Exists in
staging
and in
42 other branches
Merge commit 'refs/merge-requests/284' of git://gitorious.org/noosfero/noosfero …
…into merge-requests/284
Showing
5 changed files
with
31 additions
and
4 deletions
Show diff stats
app/controllers/public/catalog_controller.rb
@@ -7,7 +7,7 @@ class CatalogController < PublicController | @@ -7,7 +7,7 @@ class CatalogController < PublicController | ||
7 | def index | 7 | def index |
8 | @category = params[:level] ? ProductCategory.find(params[:level]) : nil | 8 | @category = params[:level] ? ProductCategory.find(params[:level]) : nil |
9 | @products = @profile.products.from_category(@category).paginate(:order => 'available desc, highlighted desc, name asc', :per_page => 9, :page => params[:page]) | 9 | @products = @profile.products.from_category(@category).paginate(:order => 'available desc, highlighted desc, name asc', :per_page => 9, :page => params[:page]) |
10 | - @categories = ProductCategory.on_level(params[:level]) | 10 | + @categories = ProductCategory.on_level(params[:level]).order(:name) |
11 | end | 11 | end |
12 | 12 | ||
13 | protected | 13 | protected |
app/helpers/catalog_helper.rb
@@ -21,7 +21,7 @@ module CatalogHelper | @@ -21,7 +21,7 @@ module CatalogHelper | ||
21 | 21 | ||
22 | def category_sub_links(category) | 22 | def category_sub_links(category) |
23 | sub_categories = [] | 23 | sub_categories = [] |
24 | - category.children.each do |sub_category| | 24 | + category.children.order(:name).each do |sub_category| |
25 | sub_categories << category_link(sub_category, true) | 25 | sub_categories << category_link(sub_category, true) |
26 | end | 26 | end |
27 | content_tag('ul', sub_categories) if sub_categories.size > 1 | 27 | content_tag('ul', sub_categories) if sub_categories.size > 1 |
db/migrate/20130304200849_add_default_value_to_product_highlighted.rb
0 → 100644
@@ -0,0 +1,10 @@ | @@ -0,0 +1,10 @@ | ||
1 | +class AddDefaultValueToProductHighlighted < ActiveRecord::Migration | ||
2 | + def self.up | ||
3 | + change_column :products, :highlighted, :boolean, :default => false | ||
4 | + execute('UPDATE products SET highlighted=(0>1) WHERE highlighted IS NULL;') | ||
5 | + end | ||
6 | + | ||
7 | + def self.down | ||
8 | + say 'This migraiton is not reversible!' | ||
9 | + end | ||
10 | +end |
db/schema.rb
@@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
9 | # | 9 | # |
10 | # It's strongly recommended to check this file into your version control system. | 10 | # It's strongly recommended to check this file into your version control system. |
11 | 11 | ||
12 | -ActiveRecord::Schema.define(:version => 20130111232201) do | 12 | +ActiveRecord::Schema.define(:version => 20130304200849) do |
13 | 13 | ||
14 | create_table "abuse_reports", :force => true do |t| | 14 | create_table "abuse_reports", :force => true do |t| |
15 | t.integer "reporter_id" | 15 | t.integer "reporter_id" |
@@ -415,7 +415,7 @@ ActiveRecord::Schema.define(:version => 20130111232201) do | @@ -415,7 +415,7 @@ ActiveRecord::Schema.define(:version => 20130111232201) do | ||
415 | t.datetime "updated_at" | 415 | t.datetime "updated_at" |
416 | t.decimal "discount" | 416 | t.decimal "discount" |
417 | t.boolean "available", :default => true | 417 | t.boolean "available", :default => true |
418 | - t.boolean "highlighted" | 418 | + t.boolean "highlighted", :default => false |
419 | t.integer "unit_id" | 419 | t.integer "unit_id" |
420 | t.integer "image_id" | 420 | t.integer "image_id" |
421 | end | 421 | end |
test/functional/catalog_controller_test.rb
@@ -224,4 +224,21 @@ class CatalogControllerTest < ActionController::TestCase | @@ -224,4 +224,21 @@ class CatalogControllerTest < ActionController::TestCase | ||
224 | assert_tag :tag => 'li', :attributes => {:id => "product-#{p2.id}", :class => /not-available/} | 224 | assert_tag :tag => 'li', :attributes => {:id => "product-#{p2.id}", :class => /not-available/} |
225 | end | 225 | end |
226 | 226 | ||
227 | + should 'sort categories by name' do | ||
228 | + environment = @enterprise.environment | ||
229 | + environment.categories.destroy_all | ||
230 | + pc1 = ProductCategory.create!(:name => "Drinks", :environment => environment) | ||
231 | + pc2 = ProductCategory.create!(:name => "Bananas", :environment => environment) | ||
232 | + pc3 = ProductCategory.create!(:name => "Sodas", :environment => environment) | ||
233 | + pc4 = ProductCategory.create!(:name => "Pies", :environment => environment) | ||
234 | + p1 = fast_create(Product, :product_category_id => pc1.id, :enterprise_id => @enterprise.id) | ||
235 | + p2 = fast_create(Product, :product_category_id => pc2.id, :enterprise_id => @enterprise.id) | ||
236 | + p3 = fast_create(Product, :product_category_id => pc3.id, :enterprise_id => @enterprise.id) | ||
237 | + p4 = fast_create(Product, :product_category_id => pc4.id, :enterprise_id => @enterprise.id) | ||
238 | + | ||
239 | + get :index, :profile => @enterprise.identifier | ||
240 | + | ||
241 | + assert_equal [pc2, pc1, pc4, pc3], assigns(:categories) | ||
242 | + end | ||
243 | + | ||
227 | end | 244 | end |