Commit 50eb406534cde2753f91d00801657b06d34ef42c
1 parent
69d53e9a
Exists in
colab
and in
4 other branches
Fixed Project image renderization
Signed off by: Diego Araújo <diegoamc90@gmail.com>
Showing
5 changed files
with
42 additions
and
6 deletions
Show diff stats
app/helpers/projects_helper.rb
| @@ -2,4 +2,15 @@ module ProjectsHelper | @@ -2,4 +2,15 @@ module ProjectsHelper | ||
| 2 | def project_owner? project_id | 2 | def project_owner? project_id |
| 3 | user_signed_in? && !current_user.project_attributes.find_by_project_id(project_id).nil? | 3 | user_signed_in? && !current_user.project_attributes.find_by_project_id(project_id).nil? |
| 4 | end | 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 | end | 16 | end |
| 6 | \ No newline at end of file | 17 | \ No newline at end of file |
app/views/projects/show.html.erb
| 1 | <div class="page-header"> | 1 | <div class="page-header"> |
| 2 | <div class="row"> | 2 | <div class="row"> |
| 3 | <div class="col-md-2"> | 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 | </div> | 5 | </div> |
| 11 | <div class="col-md-10"> | 6 | <div class="col-md-10"> |
| 12 | <h1><%= @project.name %></h1> | 7 | <h1><%= @project.name %></h1> |
config/locales/views/projects/en.yml
| @@ -17,3 +17,4 @@ en: | @@ -17,3 +17,4 @@ en: | ||
| 17 | image_url: "Image URL" | 17 | image_url: "Image URL" |
| 18 | all_projects: "All Projects" | 18 | all_projects: "All Projects" |
| 19 | no_repositories: "There are no Repositories yet!" | 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,3 +17,4 @@ pt: | ||
| 17 | image_url: "URL da imagem" | 17 | image_url: "URL da imagem" |
| 18 | all_projects: "Todos os Projetos" | 18 | all_projects: "Todos os Projetos" |
| 19 | no_repositories: "Não há repositórios ainda!" | 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 => :helper do | @@ -43,4 +43,32 @@ describe ProjectsHelper, :type => :helper do | ||
| 43 | end | 43 | end |
| 44 | end | 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 | end | 74 | end |
| 47 | \ No newline at end of file | 75 | \ No newline at end of file |