Commit 1180328fed28ea050c691211fc9081f85a46099d
1 parent
28011292
Exists in
staging
and in
42 other branches
ActionItem490: implementing products block
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2149 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
4 changed files
with
65 additions
and
0 deletions
Show diff stats
app/models/product.rb
| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | +class ProductsBlock < Block | |
| 2 | + | |
| 3 | + include ActionView::Helpers::TagHelper | |
| 4 | + include ActionView::Helpers::UrlHelper | |
| 5 | + include ActionController::UrlWriter | |
| 6 | + | |
| 7 | + def content | |
| 8 | + block_title(_('Products')) + | |
| 9 | + content_tag( | |
| 10 | + 'ul', | |
| 11 | + owner.products.map {|product| content_tag('li', link_to(product.name, product.url), :class => 'product', :style => 'background-image:url(%s)' % ( product.image ? product.image.public_filename(:minor) : '/images/icons-app/product-default-pic-minor.png' ) )} | |
| 12 | + ) | |
| 13 | + end | |
| 14 | + | |
| 15 | +end | ... | ... |
test/unit/product_test.rb
| ... | ... | @@ -108,4 +108,18 @@ class ProductTest < Test::Unit::TestCase |
| 108 | 108 | assert_not_includes prods, prod2 |
| 109 | 109 | end |
| 110 | 110 | |
| 111 | + should 'provide url' do | |
| 112 | + product = Product.new | |
| 113 | + | |
| 114 | + result = mock | |
| 115 | + | |
| 116 | + enterprise = Enterprise.new | |
| 117 | + enterprise.expects(:generate_url).with(:controller => 'catalog', :action => 'show', :id => 999).returns(result) | |
| 118 | + | |
| 119 | + product.expects(:id).returns(999) | |
| 120 | + product.expects(:enterprise).returns(enterprise) | |
| 121 | + | |
| 122 | + assert_same result, product.url | |
| 123 | + end | |
| 124 | + | |
| 111 | 125 | end | ... | ... |
| ... | ... | @@ -0,0 +1,32 @@ |
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | + | |
| 3 | +class ProductsBlockTest < ActiveSupport::TestCase | |
| 4 | + | |
| 5 | + def setup | |
| 6 | + @block = ProductsBlock.new | |
| 7 | + end | |
| 8 | + attr_reader :block | |
| 9 | + | |
| 10 | + should 'be inherit from block' do | |
| 11 | + assert_kind_of Block, block | |
| 12 | + end | |
| 13 | + | |
| 14 | + should "list owner's products" do | |
| 15 | + | |
| 16 | + enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise') | |
| 17 | + enterprise.products.create!(:name => 'product one') | |
| 18 | + enterprise.products.create!(:name => 'product two') | |
| 19 | + | |
| 20 | + block.stubs(:owner).returns(enterprise) | |
| 21 | + | |
| 22 | + | |
| 23 | + content = block.content | |
| 24 | + | |
| 25 | + assert_tag_in_string content, :content => 'Products' | |
| 26 | + | |
| 27 | + assert_tag_in_string content, :tag => 'li', :attributes => { :class => 'product' }, :descendant => { :tag => 'a', :content => /product one/ } | |
| 28 | + assert_tag_in_string content, :tag => 'li', :attributes => { :class => 'product' }, :descendant => { :tag => 'a', :content => /product two/ } | |
| 29 | + | |
| 30 | + end | |
| 31 | + | |
| 32 | +end | ... | ... |