diff --git a/app/controllers/budgets_controller.rb b/app/controllers/budgets_controller.rb index 298425174..70efd04e9 100644 --- a/app/controllers/budgets_controller.rb +++ b/app/controllers/budgets_controller.rb @@ -16,6 +16,7 @@ class BudgetsController < ApplicationController def index @finished_budgets = @budgets.finished.order(created_at: :desc) @budgets_coordinates = current_budget_map_locations + @banners = Banner.in_section('budgets').with_active end end diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index 826d90da9..f3aadc2f7 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -16,7 +16,7 @@ module CommentableActions index_customization if index_customization.present? @tag_cloud = tag_cloud - @banners = Banner.with_active + @banners = Banner.in_section(section(resource_model.name)).with_active set_resource_votes(@resources) @@ -114,4 +114,13 @@ module CommentableActions nil end + def section(resource_name) + case resource_name + when "Proposal" + 'proposals' + when "Debate" + 'debates' + end + end + end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 654fe2ff8..5ea596f9a 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -3,6 +3,7 @@ class PagesController < ApplicationController def show @custom_page = SiteCustomization::Page.published.find_by(slug: params[:id]) + @banners = Banner.in_section('help_page').with_active if @custom_page.present? render action: :custom_page diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 1ac4fd51a..8d19394d7 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -8,6 +8,7 @@ class WelcomeController < ApplicationController @header = Widget::Card.header.first @feeds = Widget::Feed.active @cards = Widget::Card.body + @banners = Banner.in_section('homepage').with_active end def welcome diff --git a/app/helpers/banners_helper.rb b/app/helpers/banners_helper.rb index b8b5864c9..3e78764a9 100644 --- a/app/helpers/banners_helper.rb +++ b/app/helpers/banners_helper.rb @@ -4,4 +4,4 @@ module BannersHelper @banners.present? && @banners.count > 0 end -end \ No newline at end of file +end diff --git a/app/models/banner.rb b/app/models/banner.rb index ad37fdc72..26d683e9c 100644 --- a/app/models/banner.rb +++ b/app/models/banner.rb @@ -16,4 +16,6 @@ class Banner < ActiveRecord::Base scope :with_active, -> { where("post_started_at <= ?", Time.current).where("post_ended_at >= ?", Time.current) } scope :with_inactive, -> { where("post_started_at > ? or post_ended_at < ?", Time.current, Time.current) } + + scope :in_section, ->(section_name) { joins(:web_sections, :sections).where("web_sections.name ilike ?", section_name) } end diff --git a/app/views/budgets/index.html.erb b/app/views/budgets/index.html.erb index a7f02440a..08efd5236 100644 --- a/app/views/budgets/index.html.erb +++ b/app/views/budgets/index.html.erb @@ -1,4 +1,9 @@ -<% provide :title do %><%= t("budgets.index.title") %><% end %> +<% if has_banners? %> + <%= render "shared/banner" %> +<% end %> + +<% provide :title do %><%= t('budgets.index.title') %><% end %> + <% content_for :canonical do %> <%= render "shared/canonical", href: budgets_url %> <% end %> diff --git a/app/views/pages/help/index.html.erb b/app/views/pages/help/index.html.erb index c4ec61d40..e0e268f7e 100644 --- a/app/views/pages/help/index.html.erb +++ b/app/views/pages/help/index.html.erb @@ -3,6 +3,10 @@ <%= render "shared/canonical", href: help_url %> <% end %> +<% if has_banners? %> + <%= render "shared/banner" %> +<% end %> +
diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index f670ff69c..e2ae116e1 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -4,6 +4,10 @@ <%= render "shared/canonical", href: root_url %> <% end %> +<% if has_banners? %> + <%= render "shared/banner" %> +<% end %> + <% provide :social_media_meta_tags do %> <%= render "shared/social_media_meta_tags", social_url: root_url %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index c999fcbc6..ec2f06277 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -39,7 +39,7 @@ en: debates: Debates proposals: Proposals budgets: Participatory budgeting - more_info: More info page + help_page: Help page background_color: Background colour font_color: Font colour edit: diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 68bdd2369..e5a4b125c 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -37,7 +37,7 @@ es: debates: Debates proposals: Propuestas budgets: Presupuestos participativos - more_info: Página de más información + help_page: Página de ayuda background_color: Color de fondo font_color: Color del texto edit: diff --git a/db/dev_seeds/banners.rb b/db/dev_seeds/banners.rb index e94b0e2d7..d7a60c64c 100644 --- a/db/dev_seeds/banners.rb +++ b/db/dev_seeds/banners.rb @@ -23,5 +23,5 @@ section "Creating web sections" do WebSection.create(name: 'debates') WebSection.create(name: 'proposals') WebSection.create(name: 'budgets') - WebSection.create(name: 'more_info') + WebSection.create(name: 'help_page') end diff --git a/lib/tasks/web_sections.rake b/lib/tasks/web_sections.rake index 8790bddd0..a3e5a4b25 100644 --- a/lib/tasks/web_sections.rake +++ b/lib/tasks/web_sections.rake @@ -5,6 +5,6 @@ namespace :web_sections do WebSection.create(name: 'debates') WebSection.create(name: 'proposals') WebSection.create(name: 'budgets') - WebSection.create(name: 'more_info') + WebSection.create(name: 'help_page') end end diff --git a/spec/factories.rb b/spec/factories.rb index 2b192813d..77deec79a 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -745,6 +745,15 @@ FactoryBot.define do font_color '#FFFFFF' end + factory :web_section do + name 'homepage' + end + + factory :banner_section, class: 'Banner::Section' do + association :banner_id, factory: :banner + association :web_section, factory: :web_section + end + factory :proposal_notification do sequence(:title) { |n| "Thank you for supporting my proposal #{n}" } sequence(:body) { |n| "Please let others know so we can make it happen #{n}" } diff --git a/spec/features/admin/banners_spec.rb b/spec/features/admin/banners_spec.rb index 6acaff300..9d001620d 100644 --- a/spec/features/admin/banners_spec.rb +++ b/spec/features/admin/banners_spec.rb @@ -74,6 +74,8 @@ feature 'Admin banners magement' do end scenario 'Publish a banner' do + section = create(:web_section, name: 'proposals') + visit admin_root_path within('#side_menu') do @@ -91,6 +93,7 @@ feature 'Admin banners magement' do fill_in 'post_ended_at', with: next_week.strftime("%d/%m/%Y") fill_in 'banner_background_color', with: '#850000' fill_in 'banner_font_color', with: '#ffb2b2' + check "banner_web_section_ids_#{section.id}" click_button 'Save changes' @@ -120,19 +123,6 @@ feature 'Admin banners magement' do expect(page.find_field("banner_font_color_picker").value).to eq('#ffb2b2') end - scenario "Created banner is correctly shown in the web" do - banner = create(:banner, title: 'My banner', description: 'My description of the banner', target_url: '/debates', background_color: '#00FF00') - - visit proposals_path - - expect(find('.banner')[:style]).to eq("background-color:#00FF00") - - within('.banner') do - expect(find('h2')[:style]).to eq("color:#{banner.font_color}") - expect(find('h3')[:style]).to eq("color:#{banner.font_color}") - end - end - scenario 'Edit banner with live refresh', :js do banner1 = create(:banner, title: 'Hello', description: 'Wrong text', diff --git a/spec/features/banners_spec.rb b/spec/features/banners_spec.rb new file mode 100644 index 000000000..0e5e5ea6a --- /dev/null +++ b/spec/features/banners_spec.rb @@ -0,0 +1,29 @@ +require 'rails_helper' + +feature 'Banner' do + + scenario "The banner is shown correctly" do + create(:web_section, name: 'homepage') + banner = create(:banner, title: 'Hello', + description: 'Banner description', + target_url: 'http://www.url.com', + post_started_at: (Time.current - 4.days), + post_ended_at: (Time.current + 10.days), + background_color: '#FF0000', + font_color: '#FFFFFF') + section = WebSection.where(name: 'homepage').last + create(:banner_section, web_section: section, banner_id: banner.id) + + visit root_path + + within('.banner') do + expect(page).to have_content('Banner description') + expect(find('h2')[:style]).to eq("color:#{banner.font_color}") + expect(find('h3')[:style]).to eq("color:#{banner.font_color}") + end + + visit debates_path + + expect(page).not_to have_content('Banner description') + end +end