docbrown/spec/requests/admin/articles_spec.rb
rhymes 99ddd31058
Pin posts to feed (#13807)
* 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>
2021-06-04 10:54:53 +02:00

114 lines
3.7 KiB
Ruby

require "rails_helper"
require "requests/shared_examples/internal_policy_dependant_request"
RSpec.describe "/admin/content_manager/articles", type: :request do
let(:super_admin) { create(:user, :super_admin) }
let(:article) { create(:article) }
it_behaves_like "an InternalPolicy dependant request", Article do
let(:request) { get admin_articles_path }
end
context "when updating an article via /admin/content_manager/articles" do
before do
sign_in super_admin
end
it "allows an Admin to add a co-author to an individual article" do
get request
expect do
article.update_columns(co_author_ids: [1])
end.to change(article, :co_author_ids).from([]).to([1])
end
it "allows an Admin to add co-authors to an individual article" do
get request
article.update_columns(co_author_ids: [2, 3])
expect(article.co_author_ids).to eq([2, 3])
end
it "allows an Admin to mark an article as approved" do
expect do
patch admin_article_path(article.id), params: { article: { approved: true } }
end.to change { article.reload.approved }.to(true)
end
it "allows an Admin to mark an article as featured" do
expect do
patch admin_article_path(article.id), params: { article: { featured: true } }
end.to change { article.reload.featured }.to(true)
end
it "allows an Admin to mark an article as pinned" do
decorated_article = article.decorate
expect do
patch admin_article_path(article.id), params: { article: { pinned: true } }
end.to change { decorated_article.pinned? }.to(true)
end
it "allows an Admin to update the published at datetime for an article" do
updated_published_at = article.published_at - 5.hours
expect do
patch admin_article_path(article.id), params: { article: {
"published_at(1i)": updated_published_at.year,
"published_at(2i)": updated_published_at.month,
"published_at(3i)": updated_published_at.day,
"published_at(4i)": updated_published_at.hour,
"published_at(5i)": updated_published_at.min,
"published_at(6i)": updated_published_at.sec
} }
end.to change { article.reload.published_at }.to(DateTime.parse(updated_published_at.to_s))
end
it "creates an audit log on update" do
Audit::Subscribe.listen(:moderator)
expect do
patch admin_article_path(article.id), params: { article: { approved: true } }
end.to change(AuditLog, :count).by(1)
Audit::Subscribe.forget(:moderator)
end
end
context "when unpinning an article" do
before do
sign_in super_admin
end
it "responds with :not_found with an invalid article id" do
expect { delete unpin_admin_article_path(9999) }.to raise_error(ActiveRecord::RecordNotFound)
end
it "allows an admin to unpin an article", :aggregate_failures do
PinnedArticle.set(article)
delete unpin_admin_article_path(article.id)
expect(PinnedArticle.exists?).to be(false)
expect(response).to redirect_to(admin_article_path(article.id))
end
it "allows an admin to unpin an article via Ajax", :aggregate_failures do
PinnedArticle.set(article)
delete unpin_admin_article_path(article.id), xhr: true
expect(PinnedArticle.exists?).to be(false)
expect(response).to have_http_status(:ok)
expect(response.media_type).to eq("text/html")
expect(response.body).to include('data-controller="article"')
end
it "creates an audit log" do
Audit::Subscribe.listen(:moderator)
expect do
delete unpin_admin_article_path(article.id)
end.to change(AuditLog, :count).by(1)
Audit::Subscribe.forget(:moderator)
end
end
end