Commit 50eb406534cde2753f91d00801657b06d34ef42c

Authored by Rafael Manzo
1 parent 69d53e9a

Fixed Project image renderization

Signed off by: Diego Araújo <diegoamc90@gmail.com>
app/helpers/projects_helper.rb
... ... @@ -2,4 +2,15 @@ module ProjectsHelper
2 2 def project_owner? project_id
3 3 user_signed_in? && !current_user.project_attributes.find_by_project_id(project_id).nil?
4 4 end
  5 +
  6 + def project_image_html(project)
  7 + url = project.attributes.image_url
  8 +
  9 + if url && !url.empty?
  10 + image_tag url, size:"128x128"
  11 + else
  12 + "<center><i class='fa fa-file-image-o fa-5x'></i></center><br />
  13 + #{t('no_image_available')}"
  14 + end
  15 + end
5 16 end
6 17 \ No newline at end of file
... ...
app/views/projects/show.html.erb
1 1 <div class="page-header">
2 2 <div class="row">
3 3 <div class="col-md-2">
4   - <% if @project_image && !@project_image.url.empty? %>
5   - <%= image_tag "#{@project_image.url}", size:"128x128" %>
6   - <% else %>
7   - <center><i class="fa fa-file-image-o fa-5x"></i></center><br />
8   - <%= t("no_image_available") %>
9   - <% end %>
  4 + <%= project_image_html(@project) %>
10 5 </div>
11 6 <div class="col-md-10">
12 7 <h1><%= @project.name %></h1>
... ...
config/locales/views/projects/en.yml
... ... @@ -17,3 +17,4 @@ en:
17 17 image_url: "Image URL"
18 18 all_projects: "All Projects"
19 19 no_repositories: "There are no Repositories yet!"
  20 + no_image_available: "No Image Available"
... ...
config/locales/views/projects/pt.yml
... ... @@ -17,3 +17,4 @@ pt:
17 17 image_url: "URL da imagem"
18 18 all_projects: "Todos os Projetos"
19 19 no_repositories: "Não há repositórios ainda!"
  20 + no_image_available: "Imagem indisponível"
... ...
spec/helpers/projects_helper_spec.rb
... ... @@ -43,4 +43,32 @@ describe ProjectsHelper, :type =&gt; :helper do
43 43 end
44 44 end
45 45  
  46 + describe 'project_image_html' do
  47 + let(:project) { FactoryGirl.build(:project) }
  48 + let(:project_attributes) { FactoryGirl.build(:project_attributes) }
  49 +
  50 + context 'when the project has an image' do
  51 + before :each do
  52 + project.expects(:attributes).twice.returns(project_attributes)
  53 + end
  54 +
  55 + it 'is expect to return an image tag with the project attribute URL' do
  56 + expect(helper.project_image_html(project)).to include("<img")
  57 + expect(helper.project_image_html(project)).to include(project_attributes.image_url)
  58 + end
  59 + end
  60 +
  61 + context 'when the project does not has an image' do
  62 + before :each do
  63 + project_attributes.image_url = ""
  64 + project.expects(:attributes).twice.returns(project_attributes)
  65 + end
  66 +
  67 + it 'is expect to return a default image icon with a message' do
  68 + expect(helper.project_image_html(project)).to include("<i class")
  69 + expect(helper.project_image_html(project)).to include(I18n.t('no_image_available'))
  70 + end
  71 + end
  72 + end
  73 +
46 74 end
47 75 \ No newline at end of file
... ...