Commit e51a5224 authored by Tiago Botelho's avatar Tiago Botelho

Add specs

parent eefc967e
...@@ -52,10 +52,10 @@ class Admin::AppearancesController < Admin::ApplicationController ...@@ -52,10 +52,10 @@ class Admin::AppearancesController < Admin::ApplicationController
# Only allow a trusted parameter "white list" through. # Only allow a trusted parameter "white list" through.
def appearance_params def appearance_params
params.require(:appearance).permit(appearance_params_attributes) params.require(:appearance).permit(allowed_appearance_params)
end end
def appearance_params_attributes def allowed_appearance_params
%i[ %i[
title title
description description
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
.hint .hint
Maximum file size is 1MB. Pages are optimized for a 28px tall header logo Maximum file size is 1MB. Pages are optimized for a 28px tall header logo
= render partial: 'admin/appearances/ee/form', locals: { form: f } = render partial: 'admin/appearances/system_header_footer_form', locals: { form: f }
%fieldset.sign-in %fieldset.sign-in
%legend %legend
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
%body{ class: "#{user_application_theme} #{@body_class}", data: { page: body_data_page, project: "#{@project.path if @project}", group: "#{@group.path if @group}", find_file: find_file_path } } %body{ class: "#{user_application_theme} #{@body_class}", data: { page: body_data_page, project: "#{@project.path if @project}", group: "#{@group.path if @group}", find_file: find_file_path } }
= render "layouts/init_auto_complete" if @gfm_form = render "layouts/init_auto_complete" if @gfm_form
= render 'peek/bar' = render 'peek/bar'
= render "admin/appearances/ee/header_message" = header_message(@appearance)
= render "layouts/header/default" = render "layouts/header/default"
= render 'layouts/page', sidebar: sidebar, nav: nav = render 'layouts/page', sidebar: sidebar, nav: nav
= render "admin/appearances/ee/footer_message" = footer_message(@appearance)
= yield :scripts_body = yield :scripts_body
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
%html.devise-layout-html %html.devise-layout-html
= render "layouts/head" = render "layouts/head"
%body.ui_indigo.login-page.application.navless{ data: { page: body_data_page } } %body.ui_indigo.login-page.application.navless{ data: { page: body_data_page } }
= header_message(@appearance)
.page-wrap .page-wrap
= render "layouts/header/empty" = render "layouts/header/empty"
.login-page-broadcast .login-page-broadcast
...@@ -40,3 +41,4 @@ ...@@ -40,3 +41,4 @@
= link_to "Explore", explore_root_path = link_to "Explore", explore_root_path
= link_to "Help", help_path = link_to "Help", help_path
= link_to "About GitLab", "https://about.gitlab.com/" = link_to "About GitLab", "https://about.gitlab.com/"
= footer_message(@appearance)
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
%html{ lang: "en" } %html{ lang: "en" }
= render "layouts/head" = render "layouts/head"
%body.ui_indigo.login-page.application.navless %body.ui_indigo.login-page.application.navless
= header_message(@appearance)
= render "layouts/header/empty" = render "layouts/header/empty"
= render "layouts/broadcast" = render "layouts/broadcast"
.container.navless-container .container.navless-container
...@@ -15,3 +16,4 @@ ...@@ -15,3 +16,4 @@
= link_to "Explore", explore_root_path = link_to "Explore", explore_root_path
= link_to "Help", help_path = link_to "Help", help_path
= link_to "About GitLab", "https://about.gitlab.com/" = link_to "About GitLab", "https://about.gitlab.com/"
= footer_message(@appearance)
module EE module EE
module Admin module Admin
module AppearancesController module AppearancesController
def appearance_params_attributes def allowed_appearance_params
super + appearance_params_ee super + %i[
end
private
def appearance_params_ee
%i[
header_message header_message
footer_message footer_message
background_color background_color
......
module EE module EE
module AppearancesHelper module AppearancesHelper
def header_message(appearance) def header_message(appearance)
return unless appearance&.header_message.present? return unless appearance&.show_header?
class_names = [] class_names = []
class_names << 'with-performance-bar' if performance_bar_enabled? class_names << 'with-performance-bar' if performance_bar_enabled?
appearance_message(appearance, :header_message, class_names) render_message(appearance, :header_message, class_names)
end end
def footer_message(appearance) def footer_message(appearance)
return unless appearance&.footer_message.present? return unless appearance&.show_footer?
appearance_message(appearance, :footer_message) render_message(appearance, :footer_message)
end end
private private
def appearance_message(appearance, field_sym, class_names = []) def render_message(appearance, field_sym, class_names = [])
class_names << field_sym.to_s.dasherize class_names << field_sym.to_s.dasherize
content_tag :div, class: class_names, style: message_style(appearance) do content_tag :div, class: class_names, style: message_style(appearance) do
render_message(appearance, field_sym) ::Banzai.render_field(appearance, field_sym).html_safe
end end
end end
...@@ -31,9 +31,5 @@ module EE ...@@ -31,9 +31,5 @@ module EE
style << "color: #{appearance.font_color}" style << "color: #{appearance.font_color}"
style style
end end
def render_message(appearance, field)
::Banzai.render_field(appearance, field).html_safe
end
end end
end end
...@@ -12,5 +12,13 @@ module EE ...@@ -12,5 +12,13 @@ module EE
default_value_for :background_color, '#E75E40' default_value_for :background_color, '#E75E40'
default_value_for :font_color, '#FFFFFF' default_value_for :font_color, '#FFFFFF'
end end
def show_header?
self.header_message.present?
end
def show_footer?
self.footer_message.present?
end
end end
end end
require 'rails_helper'
describe 'Display system header and footer bar' do
let(:header_message) { "Foo" }
let(:footer_message) { "Bar" }
shared_examples 'system header is configured' do
it 'shows system header' do
expect(page).to have_css('.header-message')
end
it 'shows the correct content' do
page.within('.header-message') do
expect(page).to have_content(header_message)
end
end
end
shared_examples 'system footer is configured' do
it 'shows system footer' do
expect(page).to have_css('.footer-message')
end
it 'shows the correct content' do
page.within('.footer-message') do
expect(page).to have_content(footer_message)
end
end
end
shared_examples 'system header is not configured' do
it 'does not show system header' do
expect(page).not_to have_css('.header-message')
end
end
shared_examples 'system footer is not configured' do
it 'does not show system footer' do
expect(page).not_to have_css('.footer-message')
end
end
context 'when authenticated' do
context 'when system header and footer are not configured' do
before do
sign_in(create(:user))
visit root_path
end
it_behaves_like 'system header is not configured'
it_behaves_like 'system footer is not configured'
end
context 'when only system header is defined' do
before do
create(:appearance, header_message: header_message)
sign_in(create(:user))
visit root_path
end
it_behaves_like 'system header is configured'
it_behaves_like 'system footer is not configured'
end
context 'when only system footer is defined' do
before do
create(:appearance, footer_message: footer_message)
sign_in(create(:user))
visit root_path
end
it_behaves_like 'system header is not configured'
it_behaves_like 'system footer is configured'
end
context 'when system header and footer are defined' do
before do
create(:appearance, header_message: header_message, footer_message: footer_message)
sign_in(create(:user))
visit root_path
end
it_behaves_like 'system header is configured'
it_behaves_like 'system footer is configured'
end
end
context 'when not authenticated' do
context 'when system header and footer are not configured' do
before do
visit root_path
end
it_behaves_like 'system header is not configured'
it_behaves_like 'system footer is not configured'
end
context 'when only system header is defined' do
before do
create(:appearance, header_message: header_message)
visit root_path
end
it_behaves_like 'system header is configured'
it_behaves_like 'system footer is not configured'
end
context 'when only system footer is defined' do
before do
create(:appearance, footer_message: footer_message)
visit root_path
end
it_behaves_like 'system header is not configured'
it_behaves_like 'system footer is configured'
end
context 'when system header and footer are defined' do
before do
create(:appearance, header_message: header_message, footer_message: footer_message)
visit root_path
end
it_behaves_like 'system header is configured'
it_behaves_like 'system footer is configured'
end
end
end
require 'spec_helper'
describe AppearancesHelper do
describe '#header_message' do
it 'returns nil when header message field is not set' do
appearance = build(:appearance)
expect(helper.header_message(appearance)).to be_nil
end
context 'when header message is set' do
let(:appearance) { build(:appearance, header_message: message) }
it 'includes current message' do
message = "Foo bar"
appearance = build(:appearance, header_message: message)
expect(helper.header_message(appearance)).to include(message)
end
end
end
describe '#footer_message' do
it 'returns nil when footer message field is not set' do
appearance = build(:appearance)
expect(helper.footer_message(appearance)).to be_nil
end
context 'when footer message is set' do
let(:appearance) { build(:appearance, header_message: message) }
it 'includes current message' do
message = "Foo bar"
appearance = build(:appearance, footer_message: message)
expect(helper.footer_message(appearance)).to include(message)
end
end
end
end
require 'spec_helper'
describe Appearance do
subject { build(:appearance) }
describe 'validations' do
let(:triplet) { '#000' }
let(:hex) { '#AABBCC' }
it { is_expected.to allow_value(nil).for(:background_color) }
it { is_expected.to allow_value(triplet).for(:background_color) }
it { is_expected.to allow_value(hex).for(:background_color) }
it { is_expected.not_to allow_value('000').for(:background_color) }
it { is_expected.to allow_value(nil).for(:font_color) }
it { is_expected.to allow_value(triplet).for(:font_color) }
it { is_expected.to allow_value(hex).for(:font_color) }
it { is_expected.not_to allow_value('000').for(:font_color) }
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment