diff --git a/app/admin/news_article.rb b/app/admin/news_article.rb index 8e9d5d5cc..b2de584e7 100644 --- a/app/admin/news_article.rb +++ b/app/admin/news_article.rb @@ -6,7 +6,7 @@ decorate_with NewsArticleDecorator - permit_params :title, :content, :publication_date, + permit_params :title, :content, :publication_date, :is_insight, :created_by_id, :updated_by_id, :image, :keywords_string, tpi_sector_ids: [] @@ -30,6 +30,7 @@ row :image do |t| image_tag(url_for(t.image)) if t.image.present? end + row :is_insight row :updated_at row :updated_by row :created_at @@ -43,6 +44,7 @@ index do column 'Title', :title_link column :publication_date + column :is_insight actions end @@ -54,6 +56,7 @@ column(:sectors) { |l| l.tpi_sectors.map(&:name).join(Rails.application.config.csv_options[:entity_sep]) } column :keywords, &:keywords_csv column :publication_date + column :is_insight end form html: {'data-controller' => 'check-modified'} do |f| @@ -67,6 +70,7 @@ collection: TPISector.order(:name), input_html: {multiple: true} f.input :keywords_string, label: 'Keywords', hint: t('hint.tag'), as: :tags, collection: Keyword.pluck(:name) f.input :image, as: :file, input_html: {accept: 'image/*'} + f.input :is_insight end f.actions diff --git a/app/admin/publication.rb b/app/admin/publication.rb index 3b0587e54..2253d9819 100644 --- a/app/admin/publication.rb +++ b/app/admin/publication.rb @@ -7,7 +7,7 @@ decorate_with PublicationDecorator permit_params :title, :author, :author_image, :short_description, :publication_date, - :file, :image, :created_by_id, :updated_by_id, + :file, :image, :created_by_id, :updated_by_id, :summary, :keywords_string, tpi_sector_ids: [] filter :title @@ -20,6 +20,7 @@ attributes_table do row :title row :short_description + row :summary row :author row :author_image do |p| if p.author_image.present? @@ -63,6 +64,7 @@ f.input :author f.input :author_image, as: :file, hint: preview_file_tag(f.object.author_image), input_html: {accept: 'image/*'} f.input :short_description, as: :text + f.input :summary, as: :trix, embed_youtube: true f.input :publication_date, as: :date_time_picker f.input :tpi_sector_ids, label: 'Sectors', as: :select, collection: TPISector.order(:name), input_html: {multiple: true} diff --git a/app/assets/stylesheets/tpi/_pages.scss b/app/assets/stylesheets/tpi/_pages.scss index e55a2fe0b..3678e66f7 100644 --- a/app/assets/stylesheets/tpi/_pages.scss +++ b/app/assets/stylesheets/tpi/_pages.scss @@ -174,6 +174,12 @@ $margin-between-list-items: 20px; flex-direction: column; } } + + &__flex { + display: flex; + gap: 20px; + flex-wrap: wrap; + } } .pages__content-title { diff --git a/app/assets/stylesheets/tpi/_publications.scss b/app/assets/stylesheets/tpi/_publications.scss index d670ad829..f8f9fd804 100644 --- a/app/assets/stylesheets/tpi/_publications.scss +++ b/app/assets/stylesheets/tpi/_publications.scss @@ -257,6 +257,16 @@ $max-lines: 3; margin-bottom: 22px; } } + + &__content-type { + color: $grey-dark; + margin-top: 10px; + font-size: $size-7; + border: 1px solid rgba($grey-dark, 0.5); + padding-left: $size-7; + padding-right: $size-7; + display: inline-block; + } } .publications__grid { diff --git a/app/controllers/tpi/publications_controller.rb b/app/controllers/tpi/publications_controller.rb index 102a510ee..a50b00248 100644 --- a/app/controllers/tpi/publications_controller.rb +++ b/app/controllers/tpi/publications_controller.rb @@ -7,6 +7,7 @@ class PublicationsController < TPIController before_action :fetch_tags, only: [:index] before_action :fetch_sectors, only: [:index] before_action :fetch_publication, only: [:show] + before_action :fetch_news_article, only: [:show_news_article] def index results = Queries::TPI::NewsPublicationsQuery.new(filter_params).call @@ -36,14 +37,17 @@ def show respond_to do |format| format.html do admin_panel_path = polymorphic_path([:admin, @publication]) - fixed_navbar("#{@publication.class.name.underscore.humanize} #{@publication.title}", admin_panel_path) - - redirect_to '' unless @publication + fixed_navbar(@publication.title.to_s, admin_panel_path) end format.pdf { stream_publication_file } end end + def show_news_article + admin_panel_path = polymorphic_path([:admin, @news_article]) + fixed_navbar((@news_article[:title]).to_s, admin_panel_path) + end + def download_file @publication = Publication.published.find_by! slug: params[:slug] stream_publication_file @@ -70,15 +74,15 @@ def offset end def filter_params - params.permit(:tags, :sectors) + params.permit(:tags, :sectors, :types) end def fetch_publication - @publication = if params[:type].eql?('NewsArticle') - NewsArticle.published.find(params[:id]) - else - Publication.published.find_by(id: params[:id]) || Publication.published.find_by!(slug: params[:id]) - end + @publication = Publication.published.find_by(id: params[:id]) || Publication.published.find_by!(slug: params[:id]) + end + + def fetch_news_article + @news_article = NewsArticle.published.find params[:id] end def fetch_tags diff --git a/app/javascript/components/tpi/Filters.js b/app/javascript/components/tpi/Filters.js index 991a52050..a8922c03e 100644 --- a/app/javascript/components/tpi/Filters.js +++ b/app/javascript/components/tpi/Filters.js @@ -9,20 +9,25 @@ import { useQueryParam } from 'shared/hooks'; const ALL_OPTION_NAME = 'All'; const SHOW_ON_PAGE = 9; -const Filters = ({ tags, sectors, resultsSize }) => { +const Filters = ({ types, tags, sectors, resultsSize }) => { const [isFilterOpen, setIsFiltersOpen] = useState(false); const [resultsCount, setResultsCount] = useState(resultsSize); + const [queryTypesParam, setQueryTypes] = useQueryParam('types'); const [queryTagsParam, setQueryTags] = useQueryParam('tags'); const [querySectorsParam, setQuerySectors] = useQueryParam('sectors'); const [offset, setOffset] = useState(0); + const activeTypes = useMemo(() => { + const typesWithAllOption = [ALL_OPTION_NAME, ...types]; + const queryTypes = (queryTypesParam || '').split(',').filter(x => x); + return typesWithAllOption.map(type => ({ + name: type, + active: queryTypes.length > 0 ? queryTypes.includes(type) : type === ALL_OPTION_NAME + })); + }, [types, queryTypesParam]); const activeTags = useMemo(() => { const queryTags = (queryTagsParam || '').split(',').filter(x => x); - const tagsWithAllOption = [ - ALL_OPTION_NAME, - ...queryTags.filter(x => !tags.includes(x)), - ...tags - ]; + const tagsWithAllOption = [ALL_OPTION_NAME, ...tags]; return tagsWithAllOption.map(tag => ({ name: tag, active: queryTags.length > 0 ? queryTags.includes(tag) : tag === ALL_OPTION_NAME @@ -71,7 +76,11 @@ const Filters = ({ tags, sectors, resultsSize }) => { }; }, [handleLoadMore]); - const refreshPublicationsHtml = (_tags, _sectors, _offset) => { + const refreshPublicationsHtml = (_types, _tags, _sectors, _offset) => { + const activeTypesQueryParam = _types + .filter(t => t.active && t.name !== ALL_OPTION_NAME) + .map(t => encodeURIComponent(t.name)) + .join(', '); const activeTagsQueryParam = _tags .filter(t => t.active && t.name !== ALL_OPTION_NAME) .map(t => encodeURIComponent(t.name)) @@ -81,7 +90,7 @@ const Filters = ({ tags, sectors, resultsSize }) => { .map(s => encodeURIComponent(s.name)) .join(', '); - const query = `tags=${activeTagsQueryParam}§ors=${activeSectorsQueryParam}&offset=${_offset}`; + const query = `types=${activeTypesQueryParam}&tags=${activeTagsQueryParam}§ors=${activeSectorsQueryParam}&offset=${_offset}`; const url = `/publications/partial?${query}`; fetch(url) @@ -98,8 +107,31 @@ const Filters = ({ tags, sectors, resultsSize }) => { }; useEffect(() => { - refreshPublicationsHtml(activeTags, activeSectors, offset); - }, [activeTags, activeSectors, offset]); + refreshPublicationsHtml(activeTypes, activeTags, activeSectors, offset); + }, [activeTypes, activeTags, activeSectors, offset]); + + const handleTypeClick = (type) => { + const otherOptions = optionsWithoutALL(activeTypes); + + const shouldALLbeSelected = isAllClicked(type) && (isOtherOptionsActive(otherOptions) || isAllSelected(otherOptions)); + + if (shouldALLbeSelected) { + const typesWithALLSelected = activeTypes.map(s => ({ + name: s.name, + active: s.name === ALL_OPTION_NAME + })); + setOffset(0); + setQueryTypes(typesWithALLSelected.filter(s => s.active).map((s) => s.name).join(',')); + } else { + const updatedTypes = activeTypes.map(s => { + if (s.name === type.name) { return { name: s.name, active: !s.active }; } + if (s.name === ALL_OPTION_NAME) { return { name: s.name, active: false }; } + return { name: s.name, active: s.active }; + }); + setOffset(0); + setQueryTypes(updatedTypes.filter(s => s.active).map((s) => s.name).join(',')); + } + }; const handleTagClick = (tag) => { const otherOptions = optionsWithoutALL(activeTags); @@ -172,6 +204,18 @@ const Filters = ({ tags, sectors, resultsSize }) => { {isFilterOpen && (
+
Type
+
+ {activeTypes.length && activeTypes.map(type => ( + + ))} +
Tag
{activeTags.length && activeTags.map(tag => ( @@ -204,6 +248,7 @@ const Filters = ({ tags, sectors, resultsSize }) => { }; Filters.propTypes = { + types: PropTypes.array.isRequired, tags: PropTypes.array.isRequired, sectors: PropTypes.array.isRequired, resultsSize: PropTypes.number.isRequired diff --git a/app/models/bank_assessment_indicator.rb b/app/models/bank_assessment_indicator.rb index 5c15c29d0..60be9b66c 100644 --- a/app/models/bank_assessment_indicator.rb +++ b/app/models/bank_assessment_indicator.rb @@ -8,6 +8,8 @@ # text :text not null # created_at :datetime not null # updated_at :datetime not null +# comment :text +# is_placeholder :boolean default(FALSE) # class BankAssessmentIndicator < ApplicationRecord INDICATOR_TYPES = %w[area sub_area indicator sub_indicator].freeze diff --git a/app/models/news_article.rb b/app/models/news_article.rb index a9822a21e..0b2f51561 100644 --- a/app/models/news_article.rb +++ b/app/models/news_article.rb @@ -10,6 +10,7 @@ # updated_by_id :bigint # created_at :datetime not null # updated_at :datetime not null +# is_insight :boolean default(FALSE) # class NewsArticle < ApplicationRecord @@ -23,6 +24,8 @@ class NewsArticle < ApplicationRecord has_and_belongs_to_many :tpi_sectors scope :published, -> { where('publication_date <= ?', DateTime.now) } + scope :insights, -> { where(is_insight: true) } + scope :not_insights, -> { where(is_insight: false) } validates_presence_of :title, :content, :publication_date diff --git a/app/models/publication.rb b/app/models/publication.rb index ee3d815e6..931de762a 100644 --- a/app/models/publication.rb +++ b/app/models/publication.rb @@ -13,6 +13,8 @@ # created_at :datetime not null # updated_at :datetime not null # author :string +# slug :text not null +# summary :text # class Publication < ApplicationRecord diff --git a/app/services/queries/tpi/news_publications_query.rb b/app/services/queries/tpi/news_publications_query.rb index a90dd26e4..45b56bdf0 100644 --- a/app/services/queries/tpi/news_publications_query.rb +++ b/app/services/queries/tpi/news_publications_query.rb @@ -4,20 +4,30 @@ class NewsPublicationsQuery include ActiveModel::Model attr_reader :publications_scope, :news_scope - attr_accessor :tags, :sectors + attr_accessor :tags, :sectors, :types def call - (publications + news).uniq.sort_by(&:publication_date).reverse! + (publications + news + insights).uniq.sort_by(&:publication_date).reverse! end private def publications + return Publication.none if types.present? && !types.include?('Publications') + filter_scope(Publication.published) end def news - filter_scope(NewsArticle.published) + return NewsArticle.none if types.present? && !types.include?('News') + + filter_scope(NewsArticle.published.not_insights) + end + + def insights + return NewsArticle.none if types.present? && !types.include?('Insights') + + filter_scope(NewsArticle.published.insights) end def filter_scope(scope) diff --git a/app/views/tpi/publications/_list.html.erb b/app/views/tpi/publications/_list.html.erb index 9628166f1..d11cbf1c3 100644 --- a/app/views/tpi/publications/_list.html.erb +++ b/app/views/tpi/publications/_list.html.erb @@ -8,9 +8,13 @@
<% if publication.is_a?(Publication) %> - <%= link_to publication.title, tpi_publication_download_file_path(slug: publication.slug), target: '_blank', class: 'link is-strong' %> + <% if publication.summary.present? %> + <%= link_to publication.title, tpi_publication_path(id: publication.slug), class: 'link is-strong' %> + <% else %> + <%= link_to publication.title, tpi_publication_download_file_path(slug: publication.slug), target: '_blank', class: 'link is-strong' %> + <% end %> <% else %> - <%= link_to publication.title, tpi_publication_path(id: publication.id, type: publication.class.name), class: "link is-strong" %> + <%= link_to publication.title, show_news_article_tpi_publication_path(id: publication.id), class: "link is-strong" %> <% end %>
@@ -25,6 +29,13 @@ <% end %>

+
+ <% if publication.is_a?(NewsArticle) %> + <%= publication.is_insight? ? 'Insights' : 'News' %> + <% else %> + Publications + <% end %> +
<% if publication.keywords.any? || publication.tpi_sectors.any? %>
<% publication.tags_and_sectors.each do |tag| %> diff --git a/app/views/tpi/publications/index.html.erb b/app/views/tpi/publications/index.html.erb index 52c2257da..26cbe0864 100644 --- a/app/views/tpi/publications/index.html.erb +++ b/app/views/tpi/publications/index.html.erb @@ -7,7 +7,12 @@ filter icon
- <%= react_component("Filters", { tags: @tags, sectors: @sectors, resultsSize: @publications_and_articles_count }) %> + <%= react_component("Filters", { + types: %w[Publications News Insights], + tags: @tags, + sectors: @sectors, + resultsSize: @publications_and_articles_count + }) %>
<%= render 'promoted', publications_and_articles: @publications_and_articles, count: @publications_and_articles_count %>
diff --git a/app/views/tpi/publications/show.html.erb b/app/views/tpi/publications/show.html.erb index e6c4ea216..408a04200 100644 --- a/app/views/tpi/publications/show.html.erb +++ b/app/views/tpi/publications/show.html.erb @@ -1,24 +1,31 @@ <% content_for :page_title, "#{@publication.title} - Transition Pathway Initiative" %> -<% if @publication.class.name.eql?("NewsArticle") %> - <% content_for :page_description, strip_tags(@publication.content).first(160) if @publication.content.present? %> -<% else %> - <% content_for :page_description, @publication.short_description&.first(160) %> -<% end %> +<% content_for :page_description, @publication.short_description&.first(160) %>

<%= @publication.title %>

<%= @publication.publication_date.strftime('%d/%m/%Y') %>

- <% if @publication.class.name.eql?("NewsArticle") && @publication.image.present? %> -
<%= image_tag(@publication.image) %>
- <% end %> -
- <% if @publication.class.name.eql?("NewsArticle") %> - <%= @publication.content&.html_safe %> - <% else %> - <%= @publication.short_description %> + +
+ <% if @publication.image.present? %> +
<%= image_tag(@publication.image) %>
<% end %> +
+

<%= @publication.short_description %>

+ <% if @publication.keywords.any? || @publication.tpi_sectors.any? %> +
+ <% @publication.tags_and_sectors.each do |tag| %> + <%= tag %> + <% end %> +
+ <% end %> +
+ <%= @publication.summary&.html_safe %> +
+ + <%= link_to 'Download file', tpi_publication_download_file_path(slug: @publication.slug), target: '_blank', class: 'button is-primary' %> +
diff --git a/app/views/tpi/publications/show_news_article.erb b/app/views/tpi/publications/show_news_article.erb new file mode 100644 index 000000000..96496f89e --- /dev/null +++ b/app/views/tpi/publications/show_news_article.erb @@ -0,0 +1,17 @@ +<% content_for :page_title, "#{@news_article.title} - Transition Pathway Initiative" %> +<% content_for :page_description, strip_tags(@news_article.content).first(160) if @news_article.content.present? %> + +
+
+
+

<%= @news_article.title %>

+

<%= @news_article.publication_date.strftime('%d/%m/%Y') %>

+ <% if @news_article.image.present? %> +
<%= image_tag(@news_article.image) %>
+ <% end %> +
+ <%= @news_article.content&.html_safe %> +
+
+
+
diff --git a/app/views/tpi/sitemaps/index.xml.erb b/app/views/tpi/sitemaps/index.xml.erb index ce63b3e21..a1bbcea04 100644 --- a/app/views/tpi/sitemaps/index.xml.erb +++ b/app/views/tpi/sitemaps/index.xml.erb @@ -40,12 +40,12 @@ <% @publications.each do |publication| %> - <%= "#{@host}#{tpi_publication_download_file_path(slug: publication.slug)}" %> + <%= "#{@host}#{tpi_publication_path(id: publication.slug)}" %> <% end %> <% @news.each do |news| %> - <%= "#{@host}#{tpi_publication_path(news, type: 'NewsArticle')}" %> + <%= "#{@host}#{show_news_article_tpi_publication_path(id: news.id)}" %> <% end %> diff --git a/config/brakeman.ignore b/config/brakeman.ignore index d7821f3ca..4238fb329 100644 --- a/config/brakeman.ignore +++ b/config/brakeman.ignore @@ -26,7 +26,7 @@ "check_name": "CrossSiteScripting", "message": "Unescaped model attribute", "file": "app/views/tpi/companies/show.html.erb", - "line": 119, + "line": 138, "link": "https://brakemanscanner.org/docs/warning_types/cross_site_scripting", "code": "TPI::CompanyDecorator.decorate(Company.published.friendly.find(params[:id])).isin_array.join(\"
\")", "render_path": [ @@ -57,7 +57,7 @@ "check_name": "CrossSiteScripting", "message": "Unescaped model attribute", "file": "app/views/tpi/sectors/index.html.erb", - "line": 69, + "line": 88, "link": "https://brakemanscanner.org/docs/warning_types/cross_site_scripting", "code": "Content.find_by(:page => TPIPage.find_by(:slug => \"publicly-listed-equities-content\"), :code => \"methodology_description\").text", "render_path": [ @@ -65,7 +65,7 @@ "type": "controller", "class": "TPI::SectorsController", "method": "index", - "line": 27, + "line": 34, "file": "app/controllers/tpi/sectors_controller.rb", "rendered": { "name": "tpi/sectors/index", @@ -127,7 +127,7 @@ "type": "controller", "class": "TPI::BanksController", "method": "index", - "line": 26, + "line": 27, "file": "app/controllers/tpi/banks_controller.rb", "rendered": { "name": "tpi/banks/index", @@ -174,6 +174,37 @@ "confidence": "Weak", "note": "" }, + { + "warning_type": "Cross-Site Scripting", + "warning_code": 2, + "fingerprint": "7e53284632294fa27278fa7cd09aa0c3f4cd1d13c20c23b60a4a3f6df3f5a36a", + "check_name": "CrossSiteScripting", + "message": "Unescaped model attribute", + "file": "app/views/tpi/publications/show_news_article.erb", + "line": 13, + "link": "https://brakemanscanner.org/docs/warning_types/cross_site_scripting", + "code": "NewsArticle.published.find(params[:id]).content", + "render_path": [ + { + "type": "controller", + "class": "TPI::PublicationsController", + "method": "show_news_article", + "line": 49, + "file": "app/controllers/tpi/publications_controller.rb", + "rendered": { + "name": "tpi/publications/show_news_article", + "file": "app/views/tpi/publications/show_news_article.erb" + } + } + ], + "location": { + "type": "template", + "template": "tpi/publications/show_news_article" + }, + "user_input": null, + "confidence": "High", + "note": "" + }, { "warning_type": "Cross-Site Scripting", "warning_code": 2, @@ -308,6 +339,6 @@ "note": "" } ], - "updated": "2022-09-06 13:32:13 +0200", + "updated": "2023-10-19 11:42:02 +0200", "brakeman_version": "5.2.3" } diff --git a/config/routes.rb b/config/routes.rb index 78e0acd69..0eec8873d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -55,6 +55,9 @@ end resources :publications, only: [:index, :show] do + member do + get :show_news_article + end collection do get :partial end diff --git a/db/migrate/20231023101859_add_is_insight_to_news_articles.rb b/db/migrate/20231023101859_add_is_insight_to_news_articles.rb new file mode 100644 index 000000000..ba04d5af6 --- /dev/null +++ b/db/migrate/20231023101859_add_is_insight_to_news_articles.rb @@ -0,0 +1,5 @@ +class AddIsInsightToNewsArticles < ActiveRecord::Migration[6.1] + def change + add_column :news_articles, :is_insight, :boolean, default: false + end +end diff --git a/db/migrate/20231023120255_add_summary_to_publications.rb b/db/migrate/20231023120255_add_summary_to_publications.rb new file mode 100644 index 000000000..1a9545509 --- /dev/null +++ b/db/migrate/20231023120255_add_summary_to_publications.rb @@ -0,0 +1,5 @@ +class AddSummaryToPublications < ActiveRecord::Migration[6.1] + def change + add_column :publications, :summary, :text + end +end diff --git a/db/structure.sql b/db/structure.sql index 7ab6ee9dc..baf869227 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1325,7 +1325,8 @@ CREATE TABLE public.news_articles ( created_by_id bigint, updated_by_id bigint, created_at timestamp(6) without time zone NOT NULL, - updated_at timestamp(6) without time zone NOT NULL + updated_at timestamp(6) without time zone NOT NULL, + is_insight boolean DEFAULT false ); @@ -1410,7 +1411,8 @@ CREATE TABLE public.publications ( created_at timestamp(6) without time zone NOT NULL, updated_at timestamp(6) without time zone NOT NULL, author character varying, - slug text NOT NULL + slug text NOT NULL, + summary text ); @@ -3735,6 +3737,8 @@ INSERT INTO "schema_migrations" (version) VALUES ('20230712074753'), ('20230713121501'), ('20230926075145'), -('20230927112905'); +('20230927112905'), +('20231023101859'), +('20231023120255'); diff --git a/db/test-dump.psql b/db/test-dump.psql index eb6ba7d62..4ea096891 100644 Binary files a/db/test-dump.psql and b/db/test-dump.psql differ diff --git a/spec/controllers/admin/news_articles_controller_spec.rb b/spec/controllers/admin/news_articles_controller_spec.rb index 08c3279dc..c2993ed47 100644 --- a/spec/controllers/admin/news_articles_controller_spec.rb +++ b/spec/controllers/admin/news_articles_controller_spec.rb @@ -36,7 +36,8 @@ attributes_for( :news_article, title: 'My amazing title', - content: 'Test Content' + content: 'Test Content', + is_insight: true ) end @@ -48,6 +49,7 @@ last_news_article_created.tap do |g| expect(g.title).to eq(valid_params[:title]) expect(g.content).to eq(valid_params[:content]) + expect(g.is_insight).to be_truthy end end diff --git a/spec/controllers/admin/publications_controller_spec.rb b/spec/controllers/admin/publications_controller_spec.rb index 64b1270fd..4e571d3ce 100644 --- a/spec/controllers/admin/publications_controller_spec.rb +++ b/spec/controllers/admin/publications_controller_spec.rb @@ -36,7 +36,8 @@ attributes_for( :publication, title: 'My amazing title', - short_description: 'Test short_description' + short_description: 'Test short_description', + summary: 'Test summary' ) end @@ -48,6 +49,7 @@ last_publication_created.tap do |g| expect(g.title).to eq(valid_params[:title]) expect(g.short_description).to eq(valid_params[:short_description]) + expect(g.summary).to eq(valid_params[:summary]) end end diff --git a/spec/controllers/tpi/publications_controller_spec.rb b/spec/controllers/tpi/publications_controller_spec.rb index 3a8291dd4..80f5f7926 100644 --- a/spec/controllers/tpi/publications_controller_spec.rb +++ b/spec/controllers/tpi/publications_controller_spec.rb @@ -29,19 +29,19 @@ describe 'GET show' do context 'publication' do context 'published' do - subject { get :show, params: {id: publication1.id, type: 'Publication'} } + subject { get :show, params: {id: publication1.id} } it { is_expected.to be_successful } context 'when publication is searched by slug' do - subject { get :show, params: {id: publication1.slug, type: 'Publication'} } + subject { get :show, params: {id: publication1.slug} } it { is_expected.to be_successful } end end context 'unpublished' do - subject { get :show, params: {id: publication4.id, type: 'Publication'} } + subject { get :show, params: {id: publication4.slug} } it 'not found' do expect { subject }.to raise_exception(ActiveRecord::RecordNotFound) @@ -51,13 +51,13 @@ context 'news article' do context 'published' do - subject { get :show, params: {id: news_article1.id, type: 'NewsArticle'} } + subject { get :show_news_article, params: {id: news_article1.id} } it { is_expected.to be_successful } end context 'unpublished' do - subject { get :show, params: {id: news_article4.id, type: 'NewsArticle'} } + subject { get :show_news_article, params: {id: news_article4.id} } it 'not found' do expect { subject }.to raise_exception(ActiveRecord::RecordNotFound) diff --git a/spec/controllers/tpi/sitemaps_controller_spec.rb b/spec/controllers/tpi/sitemaps_controller_spec.rb index e888f44b0..3df09186a 100644 --- a/spec/controllers/tpi/sitemaps_controller_spec.rb +++ b/spec/controllers/tpi/sitemaps_controller_spec.rb @@ -1,6 +1,5 @@ require 'rails_helper' -# rubocop:disable Layout/LineLength RSpec.describe TPI::SitemapsController, type: :controller do let_it_be(:company1) { create(:company, :published) } let_it_be(:company2) { create(:company, :draft) } @@ -27,16 +26,15 @@ expect(response.body).to have_css('url loc', text: tpi_company_url(company1.slug, **host_params)) expect(response.body).to have_css('url loc', text: tpi_bank_url(bank.slug, **host_params)) expect(response.body).to have_css('url loc', text: "https://#{host_params[:host]}/#{page1.slug}") - expect(response.body).to have_css('url loc', text: tpi_publication_download_file_path(slug: publication1.slug, **host_params)) - expect(response.body).to have_css('url loc', text: tpi_publication_url(article1, type: 'NewsArticle', **host_params)) + expect(response.body).to have_css('url loc', text: tpi_publication_url(id: publication1.slug, **host_params)) + expect(response.body).to have_css('url loc', text: show_news_article_tpi_publication_path(article1, **host_params)) end it('should not return unpublished entities') do subject expect(response.body).not_to have_css('url loc', text: tpi_company_url(company2.slug, **host_params)) - expect(response.body).not_to have_css('url loc', text: tpi_publication_download_file_path(slug: publication2.slug, **host_params)) - expect(response.body).not_to have_css('url loc', text: tpi_publication_url(article2, type: 'NewsArticle', **host_params)) + expect(response.body).not_to have_css('url loc', text: tpi_publication_url(id: publication2.slug, **host_params)) + expect(response.body).not_to have_css('url loc', text: show_news_article_tpi_publication_path(article2, **host_params)) end end end -# rubocop:enable Layout/LineLength diff --git a/spec/factories/bank_assessment_indicators.rb b/spec/factories/bank_assessment_indicators.rb index 190675adf..5a2a3bc5f 100644 --- a/spec/factories/bank_assessment_indicators.rb +++ b/spec/factories/bank_assessment_indicators.rb @@ -8,6 +8,8 @@ # text :text not null # created_at :datetime not null # updated_at :datetime not null +# comment :text +# is_placeholder :boolean default(FALSE) # FactoryBot.define do factory :bank_assessment_indicator, class: BankAssessmentIndicator do diff --git a/spec/factories/news_articles.rb b/spec/factories/news_articles.rb index 8102b545b..9bef6a7a1 100644 --- a/spec/factories/news_articles.rb +++ b/spec/factories/news_articles.rb @@ -10,6 +10,7 @@ # updated_by_id :bigint # created_at :datetime not null # updated_at :datetime not null +# is_insight :boolean default(FALSE) # FactoryBot.define do @@ -19,6 +20,7 @@ tpi_sectors { |a| [a.association(:tpi_sector)] } publication_date { '2019-11-29' } image { fixture_file_upload(Rails.root.join('spec', 'support', 'fixtures', 'files', 'test.jpg'), 'jpg') } + is_insight { false } association :created_by, factory: :admin_user updated_by { created_by } diff --git a/spec/factories/publications.rb b/spec/factories/publications.rb index 1544037a0..e9a77f1d1 100644 --- a/spec/factories/publications.rb +++ b/spec/factories/publications.rb @@ -13,6 +13,8 @@ # created_at :datetime not null # updated_at :datetime not null # author :string +# slug :text not null +# summary :text # FactoryBot.define do @@ -22,6 +24,7 @@ title { 'MyString' } author { 'Author' } short_description { 'MyText' } + summary { 'MyText' } publication_date { '2019-12-02' } file { fixture_file_upload(Rails.root.join('spec', 'support', 'fixtures', 'files', 'test.pdf'), 'pdf') } diff --git a/spec/models/bank_assessment_indicator_spec.rb b/spec/models/bank_assessment_indicator_spec.rb index 4d90498b0..1f1a15046 100644 --- a/spec/models/bank_assessment_indicator_spec.rb +++ b/spec/models/bank_assessment_indicator_spec.rb @@ -8,6 +8,8 @@ # text :text not null # created_at :datetime not null # updated_at :datetime not null +# comment :text +# is_placeholder :boolean default(FALSE) # require 'rails_helper' diff --git a/spec/models/news_article_spec.rb b/spec/models/news_article_spec.rb index 5ee1f09fd..074ab6c30 100644 --- a/spec/models/news_article_spec.rb +++ b/spec/models/news_article_spec.rb @@ -10,6 +10,7 @@ # updated_by_id :bigint # created_at :datetime not null # updated_at :datetime not null +# is_insight :boolean default(FALSE) # require 'rails_helper' diff --git a/spec/models/publication_spec.rb b/spec/models/publication_spec.rb index ee560df96..6a8635388 100644 --- a/spec/models/publication_spec.rb +++ b/spec/models/publication_spec.rb @@ -13,6 +13,8 @@ # created_at :datetime not null # updated_at :datetime not null # author :string +# slug :text not null +# summary :text # require 'rails_helper'