* Add SiteConfig.feed_pinned_article and validation * Display pinned article at the top of feed * Add (basic) functionality to pin/unpin post * Admins can pin other users posts as well * Hide the button if looking at the non pinned post * Add pinned/unpinned snackbar message * Rename SiteConfig usage to Settings::General * Add pinned article to the Admin articles index * Show the pin post button when there's no pinned article * Move pinning to a separate controller * Fix SiteConfig reference * Hide PinController actions to unauthorized users * PinnedArticlesController#show action and refactor some of the code * Add Modal interaction * Fix modal-pinned checkbox interaction * Fixed pin/unpin post * Add ArticleDecorator#pinned? specs * Add PinnedArticlePolicy and PinnedArticlesController specs * Add ability to actually pin an article from the admin after submit * Add partial Cypress pin/unpin spec * Fix pinned article and add basic Cypress interaction tests * Add Crayons styling to modal * Only render the pinned article on the default Feed page * Use persisted? * Add some comments * Update app/javascript/articles/Article.jsx Co-authored-by: Suzanne Aitchison <suzanne@forem.com> * Update app/javascript/packs/homePageFeed.jsx Co-authored-by: Suzanne Aitchison <suzanne@forem.com> * Fix Cypress tests * Update app/javascript/admin/controllers/article_controller.js Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com> * Fix pinning in article show page * Used PinnedArticle domain model * Fix spec * Update cypress/integration/adminFlows/articles/pinArticle.spec.js Co-authored-by: Suzanne Aitchison <suzanne@forem.com> * Update cypress/integration/adminFlows/articles/pinArticle.spec.js Co-authored-by: Suzanne Aitchison <suzanne@forem.com> * Update cypress/integration/adminFlows/articles/pinArticle.spec.js Co-authored-by: Suzanne Aitchison <suzanne@forem.com> * Update cypress/integration/adminFlows/articles/pinArticle.spec.js Co-authored-by: Suzanne Aitchison <suzanne@forem.com> * Update cypress/integration/adminFlows/articles/pinArticle.spec.js Co-authored-by: Suzanne Aitchison <suzanne@forem.com> * Update cypress/integration/articleFlows/pinArticle.spec.js Co-authored-by: Suzanne Aitchison <suzanne@forem.com> * Update cypress/integration/articleFlows/pinArticle.spec.js Co-authored-by: Suzanne Aitchison <suzanne@forem.com> * Update app/views/admin/articles/index.html.erb Co-authored-by: Suzanne Aitchison <suzanne@forem.com> * Fix merge woes * Add missing article pin post flows * Add missing admin article flows * Add Unpin to Admin as well * Add Audit::Log entries for pin/unpin actions * Update app/controllers/stories/feeds_controller.rb Co-authored-by: Michael Kohl <citizen428@dev.to> * Do not rate limit in E2E tests * Use .find instead of .filter * Rename ArticleIdValidator to ExistingArticleIdValidator * Treat draft and deleted articles the same * Make sure posts can be pinned after the pinned article is unpublished or deleted * Use .get directly * Fix spec and fix PinnedArticlesController#show * Strengthen pinArticle Cypress tests * Add Cypress test heading guard * Add another Cypress test heading guard * Remove duplicate validator * Try using the Tools: header instead of the article title Co-authored-by: Suzanne Aitchison <suzanne@forem.com> Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com> Co-authored-by: Michael Kohl <citizen428@dev.to>
132 lines
3.4 KiB
Ruby
132 lines
3.4 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe PinnedArticle, type: :model do
|
|
let(:article) { create(:article) }
|
|
|
|
describe ".exists?" do
|
|
it "returns false if there is no pinned article" do
|
|
Settings::General.feed_pinned_article_id = nil
|
|
|
|
expect(described_class.exists?).to be(false)
|
|
end
|
|
|
|
it "returns false if the pinned article has been unpublished" do
|
|
Settings::General.feed_pinned_article_id = article.id
|
|
|
|
article.update_columns(published: false)
|
|
|
|
expect(described_class.exists?).to be(false)
|
|
end
|
|
|
|
it "returns false if the pinned article has been deleted" do
|
|
Settings::General.feed_pinned_article_id = article.id
|
|
|
|
article.destroy
|
|
|
|
expect(described_class.exists?).to be(false)
|
|
end
|
|
|
|
it "returns true if there is a pinned article" do
|
|
Settings::General.feed_pinned_article_id = article.id
|
|
|
|
expect(described_class.exists?).to be(true)
|
|
end
|
|
end
|
|
|
|
describe ".id" do
|
|
it "returns nil if there is no pinned article" do
|
|
Settings::General.feed_pinned_article_id = nil
|
|
|
|
expect(described_class.id).to be_nil
|
|
end
|
|
|
|
it "returns nil if the pinned article has been unpublished" do
|
|
Settings::General.feed_pinned_article_id = article.id
|
|
|
|
article.update_columns(published: false)
|
|
|
|
expect(described_class.id).to be_nil
|
|
end
|
|
|
|
it "returns nil if the pinned article has been deleted" do
|
|
Settings::General.feed_pinned_article_id = article.id
|
|
|
|
article.destroy
|
|
|
|
expect(described_class.id).to be_nil
|
|
end
|
|
|
|
it "returns the id of the pinned article" do
|
|
Settings::General.feed_pinned_article_id = article.id
|
|
|
|
expect(described_class.id).to eq(article.id)
|
|
end
|
|
end
|
|
|
|
describe ".get" do
|
|
it "returns nil if there is no pinned article" do
|
|
Settings::General.feed_pinned_article_id = nil
|
|
|
|
expect(described_class.get).to be_nil
|
|
end
|
|
|
|
it "returns nil if the pinned article has been unpublished" do
|
|
Settings::General.feed_pinned_article_id = article.id
|
|
|
|
article.update_columns(published: false)
|
|
|
|
expect(described_class.get).to be_nil
|
|
end
|
|
|
|
it "returns nil if the pinned article has been deleted" do
|
|
Settings::General.feed_pinned_article_id = article.id
|
|
|
|
article.destroy
|
|
|
|
expect(described_class.get).to be_nil
|
|
end
|
|
|
|
it "returns the pinned article" do
|
|
Settings::General.feed_pinned_article_id = article.id
|
|
|
|
expect(described_class.get.id).to eq(article.id)
|
|
end
|
|
end
|
|
|
|
describe ".set" do
|
|
it "sets the pinned article" do
|
|
expect(Settings::General.feed_pinned_article_id).to be_nil
|
|
|
|
described_class.set(article)
|
|
|
|
expect(Settings::General.feed_pinned_article_id).to eq(article.id)
|
|
end
|
|
|
|
it "overwrites the current pinned article" do
|
|
Settings::General.feed_pinned_article_id = article.id
|
|
|
|
another_article = create(:article)
|
|
described_class.set(another_article)
|
|
|
|
expect(Settings::General.feed_pinned_article_id).to eq(another_article.id)
|
|
end
|
|
end
|
|
|
|
describe ".remove" do
|
|
it "works even if there is no pinned article" do
|
|
Settings::General.feed_pinned_article_id = nil
|
|
|
|
described_class.remove
|
|
|
|
expect(Settings::General.feed_pinned_article_id).to be_nil
|
|
end
|
|
|
|
it "removes the currently pinned article" do
|
|
Settings::General.feed_pinned_article_id = article.id
|
|
|
|
described_class.remove
|
|
|
|
expect(Settings::General.feed_pinned_article_id).to be_nil
|
|
end
|
|
end
|
|
end
|