diff --git a/app/assets/images/widget_logos/OH_Partner_frame.png b/app/assets/images/widget_logos/OH_Partner_frame.png index 56d0a14cc..9386b2f6f 100644 Binary files a/app/assets/images/widget_logos/OH_Partner_frame.png and b/app/assets/images/widget_logos/OH_Partner_frame.png differ diff --git a/app/controllers/account_widgets_controller.rb b/app/controllers/account_widgets_controller.rb index 8917df367..a928e7476 100644 --- a/app/controllers/account_widgets_controller.rb +++ b/app/controllers/account_widgets_controller.rb @@ -2,7 +2,7 @@ class AccountWidgetsController < WidgetsController before_action :set_account - before_action :render_image_for_gif_format + before_action :render_image_for_image_format before_action :account_context, only: :index def index diff --git a/app/controllers/organization_widgets_controller.rb b/app/controllers/organization_widgets_controller.rb index 7821efa6f..ab1145cc8 100644 --- a/app/controllers/organization_widgets_controller.rb +++ b/app/controllers/organization_widgets_controller.rb @@ -2,7 +2,7 @@ class OrganizationWidgetsController < WidgetsController before_action :set_organization - before_action :render_not_supported_for_gif_format + before_action :render_not_supported_for_image_format before_action :render_iframe_for_js_format before_action :organization_context, only: :index diff --git a/app/controllers/project_widgets_controller.rb b/app/controllers/project_widgets_controller.rb index 534f1cdd4..a74f1cae4 100644 --- a/app/controllers/project_widgets_controller.rb +++ b/app/controllers/project_widgets_controller.rb @@ -3,8 +3,8 @@ class ProjectWidgetsController < WidgetsController helper :Projects, :Analyses before_action :set_project - before_action :render_image_for_gif_format, only: %i[partner_badge thin_badge] - before_action :render_not_supported_for_gif_format, except: %i[partner_badge thin_badge index] + before_action :render_image_for_image_format, only: %i[partner_badge thin_badge] + before_action :render_not_supported_for_image_format, except: %i[partner_badge thin_badge index] before_action :render_iframe_for_js_format before_action :project_context, only: :index diff --git a/app/controllers/stack_widgets_controller.rb b/app/controllers/stack_widgets_controller.rb index 0cb3a6d3b..8de3d66b4 100644 --- a/app/controllers/stack_widgets_controller.rb +++ b/app/controllers/stack_widgets_controller.rb @@ -3,7 +3,7 @@ class StackWidgetsController < WidgetsController before_action :set_widget before_action :set_stack_and_account - before_action :render_not_supported_for_gif_format + before_action :render_not_supported_for_image_format before_action :render_iframe_for_js_format before_action :account_context, only: :index diff --git a/app/controllers/widgets_controller.rb b/app/controllers/widgets_controller.rb index 1000d0d43..cd43fff4c 100644 --- a/app/controllers/widgets_controller.rb +++ b/app/controllers/widgets_controller.rb @@ -22,19 +22,30 @@ def set_widget .new(permitted_params) end - def render_image_for_gif_format - return unless request.format.gif? + def render_image_for_image_format + return unless request.format.gif? || request.format.png? + send_data(cached_widget_image, disposition: 'inline', type: image_mime_type, filename: image_filename, status: 200) + end + + def cached_widget_image cache_key = "#{@widget.parent.class.name}/#{@widget.parent.id}/#{@widget.name}" - image = Rails.cache.fetch(cache_key, expires_in: 4.hours) { @widget.image } - send_data(image, disposition: 'inline', type: 'image/gif', filename: 'widget.gif', status: 200) + Rails.cache.fetch(cache_key, expires_in: 4.hours) { @widget.image } end - def render_not_supported_for_gif_format - return unless request.format.gif? + def render_not_supported_for_image_format + return unless request.format.gif? || request.format.png? image = Rails.cache.fetch('not_supported_widget') { WidgetBadge::Thin.create([text: 'Not supported']) } - send_data(image, disposition: 'inline', type: 'image/gif', filename: 'widget.gif', status: 406) + send_data(image, disposition: 'inline', type: image_mime_type, filename: image_filename, status: 406) + end + + def image_mime_type + request.format.png? ? 'image/png' : 'image/gif' + end + + def image_filename + request.format.png? ? 'widget.png' : 'widget.gif' end def render_iframe_for_js_format diff --git a/app/models/widget/account_widget/detailed.rb b/app/models/widget/account_widget/detailed.rb index 414db3a3e..729308b9c 100644 --- a/app/models/widget/account_widget/detailed.rb +++ b/app/models/widget/account_widget/detailed.rb @@ -2,7 +2,7 @@ class Widget::AccountWidget::Detailed < Widget::AccountWidget def width - 230 + 232 end def height diff --git a/app/models/widget/account_widget/tiny.rb b/app/models/widget/account_widget/tiny.rb index a7b59c801..c22c19ced 100644 --- a/app/models/widget/account_widget/tiny.rb +++ b/app/models/widget/account_widget/tiny.rb @@ -2,7 +2,7 @@ class Widget::AccountWidget::Tiny < Widget::AccountWidget def height - 15 + 16 end def width diff --git a/lib/widget_badge/badge_helper.rb b/lib/widget_badge/badge_helper.rb index a0a5c60d0..78db97a24 100644 --- a/lib/widget_badge/badge_helper.rb +++ b/lib/widget_badge/badge_helper.rb @@ -15,6 +15,7 @@ module ClassMethods def setup_blank image = MiniMagick::Image.open(IMAGE_DIR.join('OH_Partner_frame.png')) image.background('white') + image.flatten image end diff --git a/test/controllers/positions_controller_test.rb b/test/controllers/positions_controller_test.rb index 6fbba2232..636dc0005 100755 --- a/test/controllers/positions_controller_test.rb +++ b/test/controllers/positions_controller_test.rb @@ -332,7 +332,7 @@ class PositionsControllerTest < ActionController::TestCase assert_response :success language = position.name_fact.primary_language.nice_name _(unescaped_response_body).must_match "1\nCommit\nin mostly\n#{language}" - _(unescaped_response_body).must_match position.name_fact.analysis.project.organization.name + _(unescaped_response_body).must_include position.name_fact.analysis.project.organization.name assert_select 'div#all_projects.chart-with-data[data-value]', 1 end diff --git a/test/data/widget_badge/account/badge.png b/test/data/widget_badge/account/badge.png index fbe3bdeac..44feb965f 100644 Binary files a/test/data/widget_badge/account/badge.png and b/test/data/widget_badge/account/badge.png differ diff --git a/test/data/widget_badge/account/new_text_image.png b/test/data/widget_badge/account/new_text_image.png index 31abd9397..00d15d68f 100644 Binary files a/test/data/widget_badge/account/new_text_image.png and b/test/data/widget_badge/account/new_text_image.png differ diff --git a/test/data/widget_badge/account/text_without_commits_and_kudos.png b/test/data/widget_badge/account/text_without_commits_and_kudos.png index 2d078b683..beef8262c 100644 Binary files a/test/data/widget_badge/account/text_without_commits_and_kudos.png and b/test/data/widget_badge/account/text_without_commits_and_kudos.png differ diff --git a/test/data/widget_badge/account/text_without_name.png b/test/data/widget_badge/account/text_without_name.png index 981ee180f..1c1cb836f 100644 Binary files a/test/data/widget_badge/account/text_without_name.png and b/test/data/widget_badge/account/text_without_name.png differ diff --git a/test/data/widget_badge/partner/add_text.png b/test/data/widget_badge/partner/add_text.png index 32fb7ece5..442aeb0b5 100644 Binary files a/test/data/widget_badge/partner/add_text.png and b/test/data/widget_badge/partner/add_text.png differ diff --git a/test/data/widget_badge/partner/badge.gif b/test/data/widget_badge/partner/badge.gif index 869591207..f207ea020 100644 Binary files a/test/data/widget_badge/partner/badge.gif and b/test/data/widget_badge/partner/badge.gif differ diff --git a/test/data/widget_badge/partner/text_without_name.png b/test/data/widget_badge/partner/text_without_name.png index 44930439f..d5a2d7ce0 100644 Binary files a/test/data/widget_badge/partner/text_without_name.png and b/test/data/widget_badge/partner/text_without_name.png differ diff --git a/test/data/widget_badge/thin/openhub_and_text.png b/test/data/widget_badge/thin/openhub_and_text.png index cb28212c0..6ae9560fe 100644 Binary files a/test/data/widget_badge/thin/openhub_and_text.png and b/test/data/widget_badge/thin/openhub_and_text.png differ diff --git a/test/helpers/widgets_helper_test.rb b/test/helpers/widgets_helper_test.rb index 37ab13871..716a08dce 100644 --- a/test/helpers/widgets_helper_test.rb +++ b/test/helpers/widgets_helper_test.rb @@ -73,7 +73,7 @@ class WidgetsHelperTest < ActionView::TestCase describe 'widget_iframe_style' do it 'should return css' do - _(widget_iframe_style(widget)).must_equal 'height: 35px; width: 230px; border: none' + _(widget_iframe_style(widget)).must_equal 'height: 35px; width: 232px; border: none' end end diff --git a/test/lib/widget_badge/account_test.rb b/test/lib/widget_badge/account_test.rb index bcc8f39cd..35835ff2b 100644 --- a/test/lib/widget_badge/account_test.rb +++ b/test/lib/widget_badge/account_test.rb @@ -12,7 +12,7 @@ result_blob = WidgetBadge::Account.create(options) result_file = write_to_file(result_blob) - compare_images(result_file.path, expected_image_path, 0.1) + compare_images(result_file.path, expected_image_path, 0.15) end it 'must handle spaces and utf-8 characters in account names' do diff --git a/test/models/widget/account_widget/detailed_test.rb b/test/models/widget/account_widget/detailed_test.rb index 09d64baa1..6610ca75b 100644 --- a/test/models/widget/account_widget/detailed_test.rb +++ b/test/models/widget/account_widget/detailed_test.rb @@ -7,8 +7,8 @@ class DetailedTest < ActiveSupport::TestCase let(:widget) { Widget::AccountWidget::Detailed.new(account_id: account.id) } describe 'width' do - it 'should return 230' do - _(widget.width).must_equal 230 + it 'should return 232' do + _(widget.width).must_equal 232 end end diff --git a/test/models/widget/account_widget/tiny_test.rb b/test/models/widget/account_widget/tiny_test.rb index a97021f62..7db5d745f 100644 --- a/test/models/widget/account_widget/tiny_test.rb +++ b/test/models/widget/account_widget/tiny_test.rb @@ -13,8 +13,8 @@ class TinyTest < ActiveSupport::TestCase end describe 'height' do - it 'should return 15' do - _(widget.height).must_equal 15 + it 'should return 16' do + _(widget.height).must_equal 16 end end