[deploy] Mark Posts as Published in Admin Articles (#11142)

* Refactors #update in Admin::ArticlesController and articles_spec.rb
  - Adds article.update to #update in the controller
  - Shifts the update of co_author_ids further down in #update
  - Adds additional tests to articles_spec.rb
  - Refactors existing tests in articles_spec.rb

* Adds a gaurd clause to Admin::ArticlesController and refactors specs

* Removes ! from article creation in articles_spec.rb
This commit is contained in:
Julianna Tetreault 2020-10-30 08:39:31 -06:00 committed by GitHub
parent 24a4a421e1
commit 038385e4f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 5 deletions

View file

@ -44,8 +44,9 @@ module Admin
article.email_digest_eligible = article_params[:email_digest_eligible].to_s == "true"
article.boosted_additional_articles = article_params[:boosted_additional_articles].to_s == "true"
article.boosted_dev_digest_email = article_params[:boosted_dev_digest_email].to_s == "true"
article.user_id = article_params[:user_id].to_i
article.co_author_ids = article_params[:co_author_ids].split(",").map(&:strip)
article.user_id = article_params[:user_id].to_i if article_params[:user_id].present?
article.update(article_params)
article.co_author_ids = article_params[:co_author_ids]&.split(",")&.map(&:strip)
if article.save
flash[:success] = "Article saved!"
else

View file

@ -12,20 +12,33 @@ RSpec.describe "/admin/articles", type: :request do
let(:second_user) { create(:user) }
let(:third_user) { create(:user) }
before { sign_in super_admin }
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
article.update_columns(co_author_ids: [2, 3])
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/articles/#{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/articles/#{article.id}", params: { article: { featured: true } }
end.to change { article.reload.featured }.to(true)
end
end
end