On the product details page, the logo is shown in the header area. In
the product list page it is shown to the left of the product name.
Signed-off-by: Darryl L. Pierce <mcpierce(a)gmail.com>
---
app/models/product.rb | 9 +++++++++
app/views/products/index.html.erb | 1 +
app/views/products/show.html.erb | 4 ++++
doc/ChangeLog | 1 +
test/fixtures/products.yml | 1 +
test/unit/product_test.rb | 17 +++++++++++++++++
6 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/app/models/product.rb b/app/models/product.rb
index d01bda7..abc8d99 100644
--- a/app/models/product.rb
+++ b/app/models/product.rb
@@ -64,6 +64,15 @@ class Product < ActiveRecord::Base
return result
end
+ # Returns the product's logo url.
+ def logo_url
+ if logo_name
+
"#{ConfigProperty.fetch('image.product_logo_path')}/#{logo_name}"
+ else
+ project.logo_url
+ end
+ end
+
# Returns whether the user can modify this product.
def can_edit?(user)
user && (user.id == owner.id)
diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb
index 9ed1404..0d25bde 100644
--- a/app/views/products/index.html.erb
+++ b/app/views/products/index.html.erb
@@ -33,6 +33,7 @@
<td><%= "#{product.id}" %></td>
<td class="name">
+ <div class="small-icon"><%= image_tag product.logo_url
%></div>
<%= link_to "#{product.name}", product_path(product) %>
<%= RedCloth.new(get_first_sentence(product.description)).to_html %>
<%= link_to product.owner.display_name,user_path(product.owner) %>
diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb
index e539c9c..ef3274f 100644
--- a/app/views/products/show.html.erb
+++ b/app/views/products/show.html.erb
@@ -1,5 +1,9 @@
<div id="content">
<div id="page-details">
+ <div id="logo">
+ <%= image_tag @product.logo_url %>
+ </div>
+
<dl>
<dt>Owner</dt>
<dd><%= link_to "#{(a)product.owner.display_name}",
user_path((a)product.owner) %></dd>
diff --git a/doc/ChangeLog b/doc/ChangeLog
index 7afeb8b..ef42f89 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -15,6 +15,7 @@ Change Log (0.2.0):
* #117 - Projects have logos.
* #118 - Projects without a logo show the default logo.
* #120 - Products have logos.
+ * #121 - Products without logo show their project's logo.
* #125 - Added a system title to all pages.
* #131 - Admins can filter out unapproved projects.
* #132 - Team leads can start sprints.
diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml
index f9b8468..7c7ba03 100644
--- a/test/fixtures/products.yml
+++ b/test/fixtures/products.yml
@@ -3,6 +3,7 @@ projxp_web:
owner_id: <%= Fixtures.identify(:projxp_owner) %>
name: Cairo web application.
description: The Ruby on Rails application.
+ logo_name: projxp_web.png
projxp_web_services:
project_id: <%= Fixtures.identify(:projxp) %>
diff --git a/test/unit/product_test.rb b/test/unit/product_test.rb
index e016e5d..69b4e5c 100644
--- a/test/unit/product_test.rb
+++ b/test/unit/product_test.rb
@@ -35,6 +35,11 @@ class ProductTest < ActiveSupport::TestCase
@owner = @existing_product.owner
@nonowner = users(:mcpierce)
raise "Owner and nonowner cannot be the same user!" if @owner.id ==
@nonowner.id
+
+ @product_with_logo = products(:projxp_web)
+ raise "Product must have a logo!" unless @product_with_logo.logo_name
+ @product_without_logo = products(:projxp_web_services)
+ raise "Product must not have a logo!" if @product_without_logo.logo_name
end
# Ensures that a project is required.
@@ -79,4 +84,16 @@ class ProductTest < ActiveSupport::TestCase
def test_user_can_modify
flunk "Owners can modify products!" unless
@existing_product.can_edit?(@owner)
end
+
+ # Ensures that a product with no logo uses its parent project's logo.
+ def test_logo_url_for_product_with_no_logo
+ assert_equal @product_without_logo.project.logo_url, @product_without_logo.logo_url,
+ "Product should return the project's logo."
+ end
+
+ # Ensures that the logo url is returned.
+ def test_logo_url
+ assert_equal
"#{ConfigProperty.fetch('image.product_logo_path')}/#{(a)product_with_logo.logo_name}",
+ @product_with_logo.logo_url, "Did not return the correct logo url."
+ end
end
--
1.6.0.6