[deploy] Update design and functionality of internal/articles (#7517)

* Update design and functionality of internal/articles

* Fix spec

* Update specs

* Fiddle with test

* Fix request spec
This commit is contained in:
Ben Halpern 2020-04-26 18:27:09 -04:00 committed by GitHub
parent 6c3bd047a3
commit d447d0cadf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 215 additions and 256 deletions

View file

@ -7,6 +7,7 @@ class Internal::ArticlesController < Internal::ApplicationController
def index
@pending_buffer_updates = BufferUpdate.where(status: "pending").includes(:article)
@user_buffer_updates = BufferUpdate.where(status: "sent_direct", approver_user_id: current_user.id).where("created_at > ?", 24.hours.ago)
case params[:state]
when /not\-buffered/
@ -17,6 +18,8 @@ class Internal::ArticlesController < Internal::ApplicationController
@articles = articles_top(months_ago)
when "satellite"
@articles = articles_satellite
when "satellite-not-bufffered"
@articles = articles_satellite.where(last_buffered: nil)
when "boosted-additional-articles"
@articles = articles_boosted_additional
when "chronological"

View file

@ -6,18 +6,19 @@ class Internal::BufferUpdatesController < Internal::ApplicationController
tweet = params[:tweet]
listing_id = params[:listing_id]
listing = ClassifiedListing.find(params[:listing_id]) if listing_id.present?
article&.update(featured: true)
case params[:social_channel]
when "main_twitter"
Bufferizer.new("article", article, tweet).main_tweet!
Bufferizer.new("article", article, tweet, current_user.id).main_tweet!
render body: nil
when "satellite_twitter"
Bufferizer.new("article", article, tweet).satellite_tweet!
Bufferizer.new("article", article, tweet, current_user.id).satellite_tweet!
render body: nil
when "facebook"
Bufferizer.new("article", article, fb_post).facebook_post!
Bufferizer.new("article", article, fb_post, current_user.id).facebook_post!
render body: nil
when "listings_twitter"
Bufferizer.new("listing", listing, tweet).listings_tweet!
Bufferizer.new("listing", listing, tweet, current_user.id).listings_tweet!
render body: nil
end
end

View file

@ -6,7 +6,7 @@ export default class ArticleController extends Controller {
increaseFeaturedNumber() {
// Increases the article's chances of being seen
const seconds = new Date().getTime() / 1000;
this.featuredNumberTarget.value = Math.round(seconds);
this.featuredNumberTarget.value = (Math.round(seconds) + 300);
}
decreaseFeaturedNumber() {

View file

@ -2,30 +2,35 @@ class Bufferizer
attr_accessor :post_type, :post, :text
include ApplicationHelper
def initialize(post_type, post, text)
def initialize(post_type, post, text, admin_id = nil)
if post_type == "article"
@article = post
else
@listing = post
end
@text = text
@admin_id = admin_id
end
def satellite_tweet!
@article.tags.find_each do |tag|
BufferUpdate.buff!(@article.id, twitter_buffer_text, tag.buffer_profile_id_code, "twitter", tag.id) if tag.buffer_profile_id_code.present?
next if tag.buffer_profile_id_code.blank?
text = twitter_buffer_text
text = text.gsub(" #DEVCommunity", " #DEVCommunity ##{tag.name}") if text.length < 250
BufferUpdate.buff!(@article.id, text, tag.buffer_profile_id_code, "twitter", tag.id, @admin_id)
end
@article.update(last_buffered: Time.current)
end
def main_tweet!
BufferUpdate.buff!(@article.id, twitter_buffer_text, ApplicationConfig["BUFFER_TWITTER_ID"], "twitter", nil)
BufferUpdate.buff!(@article.id, twitter_buffer_text, ApplicationConfig["BUFFER_TWITTER_ID"], "twitter", nil, @admin_id)
@article.update(last_buffered: Time.current)
end
def facebook_post!
BufferUpdate.buff!(@article.id, fb_buffer_text, ApplicationConfig["BUFFER_FACEBOOK_ID"], "facebook")
BufferUpdate.buff!(@article.id, fb_buffer_text + social_tags, ApplicationConfig["BUFFER_LINKEDIN_ID"], "linkedin")
BufferUpdate.buff!(@article.id, fb_buffer_text, ApplicationConfig["BUFFER_FACEBOOK_ID"], "facebook", @admin_id)
BufferUpdate.buff!(@article.id, fb_buffer_text + social_tags, ApplicationConfig["BUFFER_LINKEDIN_ID"], "linkedin", @admin_id)
@article.update(facebook_last_buffered: Time.current)
end

View file

@ -5,12 +5,13 @@ class BufferUpdate < ApplicationRecord
validate :validate_body_text_recent_uniqueness
validates :status, inclusion: { in: %w[pending sent_direct confirmed dismissed] }
def self.buff!(article_id, text, buffer_profile_id_code, social_service_name = "twitter", tag_id = nil)
def self.buff!(article_id, text, buffer_profile_id_code, social_service_name = "twitter", tag_id = nil, admin_id = nil)
buffer_response = send_to_buffer(text, buffer_profile_id_code)
create(
article_id: article_id,
tag_id: tag_id,
body_text: text,
approver_user_id: admin_id,
buffer_profile_id_code: buffer_profile_id_code,
social_service_name: social_service_name,
buffer_response: buffer_response,
@ -41,6 +42,10 @@ class BufferUpdate < ApplicationRecord
)
end
def self.twitter_default_text(article)
"#{article.title}\n\n#{"{ author: @#{article.user.twitter_username} } #DEVCommunity" if article.user.twitter_username?}".strip
end
private
def validate_body_text_recent_uniqueness

View file

@ -1,37 +1,5 @@
<script>
window.addEventListener('load', function() {
imageUploadButt = document.getElementById('image-upload-button')
imageUpload = document.getElementById('image-upload')
imageUploadSubmit = document.getElementById('image-upload-submit')
if (imageUploadButt && imageUpload && imageUploadSubmit) {
imageUploadButt.onclick = function (e) {
e.preventDefault();
document.getElementById('image-upload').click();
}
imageUpload.onchange = function (e) {
var image = document.getElementById('image-upload').files;
if (image.length > 0) {
document.getElementById('uploaded-image').style = 'display:none';
document.getElementById('image-upload-submit').value = "uploading";
setTimeout(function () {
document.getElementById('image-upload-submit').click(function () {
});
}, 50)
}
}
imageUploadSubmit.onclick = function (e) {
e.preventDefault();
var image = document.getElementById('image-upload').files;
if (image.length > 0) {
var ajaxReq = createAjaxReq();
ajaxReq.onreadystatechange = uploadImageCb.bind(this, ajaxReq);
ajaxReq.open('POST', '/image_uploads', true);
ajaxReq.send(generateUploadFormdata(image));
}
}
}
function generateUploadFormdata(image) {
var token = document.getElementsByName('authenticity_token')[0].value;
var formData = new FormData();

View file

@ -1,7 +1,38 @@
<style>
.article-body-html img {
max-width: 100%;
}
</style>
<div class="card my-3" data-controller="article" data-article-id="<%= article.id %>">
<div class="card-header">
<a href="<%= article.path %>" target="_blank" rel="noopener"><%= article.title %></a>
<a class="ml-2" href="<%= article.path %>/edit" target="_blank" rel="noopener"><span class="badge badge-success">EDIT</span></a>
<h2>
<a href="<%= article.path %>" target="_blank" rel="noopener">
<%= article.title %>
</a>
</h2>
<div>
<a href="<%= article.path %>/edit" target="_blank" rel="noopener"><span class="btn btn-sm btn-primary">Edit</span></a>
<button class="btn btn-sm btn-success" data-action="article#increaseFeaturedNumber">Boost</button>
<a class="btn btn-sm btn-secondary" href="/internal/users/<%= article.user_id %>" target="_blank" rel="noopener">Manage User</a>
<a href="/internal/users/<%= article.user_id %>" class="badge badge-light">@<%= article.user&.username %></a>
<span class="badge badge-light">❤️ <%= article.positive_reactions_count %> 💬 <%= article.comments_count %></span>
<span class="badge badge-light">
<% if article.published_from_feed? && !article.published? %>
RSS Import <%= article.created_at.strftime("%b %d, %Y") %>
Originally Published <%= article.published_at&.strftime("%b %d, %Y") %>
<% elsif article.crossposted_at? %>
Crossposted <%= article.crossposted_at.strftime("%b %d, %Y") %> & Published
<%= article.published_at&.strftime("%b %d, %Y") %>
<% else %>
<%= article.published_at&.strftime("%b %d, %Y") %>
<% end %>
</span>
<% article.decorate.cached_tag_list_array.each do |tag| %>
<a class="badge badge-secondary" href='/t/<%= tag %>'>#<%= tag %></a>
<% end %>
</div>
</div>
<% featured = article.featured ? "bg-featured" : "" %>
@ -10,7 +41,6 @@
<div
class="card-body <%= background_color %> <%= "bg-danger" if !article.published? && article.published_from_feed? && !article.user&.feed_admin_publish_permission? %>">
<button class="btn btn-primary float-right" href="/internal/users/<%= article.user_id %>">Manage User</button>
<% if article.video %>
<h2>Contains Video</h2>
@ -33,114 +63,53 @@
<p><a href="/internal/users/<%= article.user_id %>">View All</a></p>
<% end %>
<% end %>
<% if article.published_from_feed? && !article.published? %>
<p>
RSS Import <%= article.created_at.strftime("%b %d, %Y") %>
</p>
<p>
Originally Published <%= article.published_at&.strftime("%b %d, %Y") %>
</p>
<% elsif article.crossposted_at? %>
<p>
Crossposted <%= article.crossposted_at.strftime("%b %d, %Y") %> & Published
<%= article.published_at&.strftime("%b %d, %Y") %>
</p>
<% else %>
<p>
Published <%= article.published_at&.strftime("%b %d, %Y") %>
</p>
<% end %>
<% if article.main_image.present? %>
<div style="max-height:450px;overflow:hidden;">
<img src="<%= cloud_cover_url(article.main_image) %>" style="width:100%;" alt="cover image" /><br />
<img src="<%= cloud_cover_url(article.main_image) %>" style="width:100%;max-width:380px;border-radius:8px;background:<%= article.main_image_background_hex_color %>;" alt="cover image" /><br />
</div>
<% end %>
<div class="d-flex justify-content-between">
<h3>
<a href="/internal/users/<%= article.user_id %>">@<%= article.user&.username %></a>
</h3>
<h3>
❤️ <%= article.positive_reactions_count %> | 💬 <%= article.comments_count %>
</h3>
</div>
<ul class="nav">
<% article.decorate.cached_tag_list_array.each do |tag| %>
<li class="nav-item">
<a class="nav-link" href='/t/<%= tag %>'>#<%= tag %></a>
</li>
<% end %>
</ul>
<button class="btn btn-success" data-action="article#increaseFeaturedNumber">☝️ Boost!</button>
<button class="btn btn-danger" data-action="article#decreaseFeaturedNumber">👇 SPAM!</button>
<%= form_with url: internal_article_path(article.id), html: { data: { action: "submit->article#highlightElement" } } do |f| %>
<div class="form-group">
<input name="utf8" type="hidden" value="✓">
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>" />
<input type="hidden" name="_method" value="patch" />
</div>
<div class="form-group">
<label for="featured_number_<%= article.id %>">Featured Number:</label>
<input id="featured_number_<%= article.id %>" class="form-control" name="article[featured_number]"
value="<%= article.featured_number %>" data-target="article.featuredNumber">
<div class="row">
<div class="form-group col">
<label for="featured_number_<%= article.id %>">Featured Number:</label>
<input id="featured_number_<%= article.id %>" class="form-control" name="article[featured_number]"
value="<%= article.featured_number %>" data-target="article.featuredNumber">
</div>
<div class="form-group col">
<label for="author_id_<%= article.id %>">Author ID:</label>
<input id="author_id_<%= article.id %>" class="form-control" size="6" name="article[user_id]"
value="<%= article.user_id %>">
</div>
</div>
<div class="form-group">
<label for="author_id_<%= article.id %>">Author ID:</label>
<input id="author_id_<%= article.id %>" class="form-control" size="6" name="article[user_id]"
value="<%= article.user_id %>">
<div class="row">
<div class="form-check col">
<input name="article[featured]" type="checkbox" <%= "checked" if article.featured %> id="featured-<%= article.id %>">
<label for="featured-<%= article.id %>">Featured</label>
</div>
<div class="form-check col">
<input name="article[approved]" type="checkbox" <%= "checked" if article.approved %> id="approved-<%= article.id %>">
<label for="approved-<%= article.id %>">Approved</label>
</div>
<div class="form-check col">
<input name="article[boosted_additional_articles]" type="checkbox"
<%= "checked" if article.boosted_additional_articles %> id="boosted_additional_articles-<%= article.id %>">
<label for="boosted_additional_articles-<%= article.id %>">Boosted</label>
</div>
<% unless article.last_buffered %>
<div class="form-check col">
<input name="article[last_buffered]" value="<%= Time.current %>" type="checkbox" id="last_buffered-<%= article.id %>">
<label for="last_buffered-<%= article.id %>">Mark as buffered</label>
</div>
<% end %>
<div class="col">
<button class="btn btn-primary float-right">Submit</button>
</div>
</div>
<div class="form-group">
<label for="image_bg_color_<%= article.id %>">Image BG color:</label>
<input name="article[main_image_background_hex_color]" class="form-control"
value="<%= article.main_image_background_hex_color %>" id="image_bg_color_<%= article.id %>">
</div>
<div class="form-group">
<label for="social_image_<%= article.id %>">Social Image:</label>
<input name="article[social_image]" class="form-control" value="<%= article.social_image %>"
id="social_image_<%= article.id %>">
</div>
<div class="form-check">
<input name="article[featured]" type="checkbox" <%= "checked" if article.featured %>>
<label>Featured</label>
</div>
<div class="form-check">
<input name="article[approved]" type="checkbox" <%= "checked" if article.approved %>>
<label>Approved</label>
</div>
<div class="form-check">
<input name="article[live_now]" type="checkbox" <%= "checked" if article.live_now %>>
<label>Live Now</label>
</div>
<div class="form-check">
<input name="article[email_digest_eligible]" type="checkbox" <%= "checked" if article.email_digest_eligible %>>
<label>Email Digest Eligible</label>
</div>
<div class="form-check">
<input name="article[boosted_additional_articles]" type="checkbox"
<%= "checked" if article.boosted_additional_articles %>>
<label>Boosted (Additional articles)</label>
</div>
<div class="form-check">
<input name="article[boosted_dev_digest_email]" type="checkbox"
<%= "checked" if article.boosted_dev_digest_email %>>
<label>Boosted (<%= community_name %> Digest)</label>
</div>
<% unless article.last_buffered %>
<div class="form-check">
<input name="article[last_buffered]" value="<%= Time.current %>" type="checkbox">
<label>Buffered</label>
</div>
<% end %>
<% if params[:state]&.include?("classic") %>
<textarea cols="70" rows="6" wrap="hard" name="article[body_markdown]"><%= article.body_markdown %></textarea>
<% end %>
<button class="btn btn-primary float-right">Submit</button>
<% end %>
<% if article.last_buffered %>
@ -179,68 +148,52 @@
OPENED EMAILS IN THE PAST WEEK</b>
<% end %>
<div>
<button class="btn btn-secondary" data-toggle="collapse" data-target="#article-<%= article.id %>-buffer-area"
<div class="d-flex justify-content-between" style="padding-top:15px;">
<button class="btn btn-dark btn-lg btn-block" data-toggle="collapse" data-target="#article-<%= article.id %>-buffer-area"
area-expanded="false" area-controls="article-<%= article.id %>-buffer-area">
Share to Buffer
Social Distribution
</button>
<% if (article.decorate.cached_tag_list_array & Tag.bufferized_tags).any? %>
(Satellites Available)
<% end %>
</div>
<div id="article-<%= article.id %>-buffer-area" class="buffering-area-for-single-article collapse">
<% unless params[:state]&.include?("classic") %>
<div class="blockquote my-2">
<%= article.processed_html&.html_safe %>
</div>
<div>
<%= form_with url: internal_buffer_updates_path, html: { data: { action: "submit->article#highlightElement" } } do %>
<input type="hidden" name="social_channel" value="main_twitter" />
<input type="hidden" name="article_id" value="<%= article.id %>" />
<h5>Twitter MAIN</h5>
<div class="form-group">
<textarea cols="37" rows="6" wrap="hard" name="tweet" maxlength="255">
<% concat article.title
concat "\n\n"
if article.user.twitter_username?
concat "{ author: @#{article.user.twitter_username} } #DEVCommunity"
end %>
</textarea>
<div id="article-<%= article.id %>-buffer-area" class="buffering-area-for-single-article collapse" style="padding-top:25px;">
<div class="row">
<div class="article-body-html col col-7" style="background:white;max-height: 800px;padding-top:8px;overflow:auto;border-radius: 3px;">
<%= article.processed_html&.html_safe %>
</div>
<button class="btn btn-primary mb-2">🦅 Tweet to @<%= SiteConfig.social_media_handles["twitter"] %></button>
<% end %>
<% if (article.decorate.cached_tag_list_array & Tag.bufferized_tags).any? %>
<%= form_with url: internal_buffer_updates_path, html: { data: { action: "submit->article#highlightElement" } } do %>
<input type="hidden" name="social_channel" value="satellite_twitter" />
<input type="hidden" name="article_id" value="<%= article.id %>" />
<h5>Twitter Satellite</h5>
<div class="form-group">
<textarea cols="37" rows="6" wrap="hard" name="tweet" maxlength="255">
<% concat article.title
concat "\n\n"
if article.user.twitter_username?
concat "{ author: @#{article.user.twitter_username} }"
end %>
</textarea>
<div class="col col-5">
<%= form_with url: internal_buffer_updates_path, html: { data: { action: "submit->article#highlightElement" } } do %>
<input type="hidden" name="social_channel" value="main_twitter" />
<input type="hidden" name="article_id" value="<%= article.id %>" />
<h5>Twitter MAIN</h5>
<div class="form-group">
<textarea rows="5" wrap="hard" name="tweet" maxlength="255" class="form-control"><%= BufferUpdate.twitter_default_text(article) %></textarea>
</div>
<button class="btn btn-primary mb-2">🦅 Tweet to @<%= SiteConfig.social_media_handles["twitter"] %></button>
<% end %>
<% if (article.decorate.cached_tag_list_array & Tag.bufferized_tags).any? %>
<%= form_with url: internal_buffer_updates_path, html: { data: { action: "submit->article#highlightElement" } } do %>
<input type="hidden" name="social_channel" value="satellite_twitter" />
<input type="hidden" name="article_id" value="<%= article.id %>" />
<h5>Twitter Satellite</h5>
<div class="form-group">
<textarea rows="5" wrap="hard" name="tweet" maxlength="255" class="form-control"><%= BufferUpdate.twitter_default_text(article) %></textarea>
</div>
<button class="btn btn-primary mb-2">🐦 Tweet to satellites</button>
<% end %>
<% end %>
<%= form_with url: internal_buffer_updates_path, html: { data: { action: "submit->article#highlightElement" } } do %>
<input type="hidden" name="social_channel" value="facebook" />
<input type="hidden" name="article_id" value="<%= article.id %>" />
<h5>Facebook & LinkedIn</h5>
<div class="form-group">
<textarea rows="5" wrap="hard" name="fb_post" class="form-control" required></textarea>
</div>
<button class="btn btn-primary mb-2">📘 Post to Facebook</button>
<% end %>
</div>
<button class="btn btn-primary mb-2">🐦 Tweet to satellites</button>
<% end %>
<% end %>
</div>
<%= form_with url: internal_buffer_updates_path, html: { data: { action: "submit->article#highlightElement" } } do %>
<input type="hidden" name="social_channel" value="facebook" />
<input type="hidden" name="article_id" value="<%= article.id %>" />
<h5>Facebook & LinkedIn</h5>
<div class="form-group">
<textarea cols="37" rows="6" wrap="hard" name="fb_post" required></textarea>
</div>
<button class="btn btn-primary mb-2">📘 Post to Facebook</button>
<% end %>
<% end %>
</div>
</div>
</div>

View file

@ -1,20 +1,28 @@
<div class="row">
<div class="col-12 py-2 sticky-top bg-white d-flex justify-content-center editor-image-upload" data-controller="image-upload">
<input type="file" id="image-upload" name="file" accept="image/*" style="display:none">
<input type="submit" id='image-upload-submit' value="Upload" style="display:none">
<button class="btn btn-primary mr-2" id="image-upload-button">Upload Image</button>
<input id="uploaded-image" class="form-control w-50" style="" placeholder="(or paste URL directly into Social Image input)" type="text" readonly>
<% if @user_buffer_updates.any? %>
<div class="alert alert-primary">
You have sent <strong><%= @user_buffer_updates.size %></strong> buffers so far in the past 24 hours. Keep it up!
</div>
<% else %>
<div class="alert alert-warning" role="alert">
You haven't sent any buffers in the past 24 hours, let's get to work!
</div>
<% end %>
<div class="row">
<div class="col-12">
<hr>
<ul class="nav nav-pills nav-fill">
<ul class="nav nav-tabs nav-fill">
<li class="nav-item">
<a href="/internal/articles" class="nav-link <%= "active" if params[:state].blank? %>">Hot</a>
</li>
<li class="nav-item">
<a href="/internal/articles?state=chronological" class="nav-link <%= "active" if params[:state] == "chronological" %>">Chronological</a>
</li>
<h3 class="mx-2">Not Buffered:</h3>
<li class="nav-item">
<a href="/internal/articles?state=satellite" class="nav-link <%= "active" if params[:state] == "satellite" %>">Satellite</a>
</li>
<li class="nav-item">
<span class="nav-link disabled">Not Buffered:</span>
</li>
<li class="nav-item">
<a href="/internal/articles?state=not-buffered-0.25" class="nav-link <%= "active" if params[:state] == "not-buffered-0.25" %>">6hr</a>
</li>
@ -25,66 +33,61 @@
<a href="/internal/articles?state=not-buffered-7" class="nav-link <%= "active" if params[:state] == "not-buffered-7" %>">7d</a>
</li>
<li class="nav-item">
<a href="/internal/articles?state=satellite" class="nav-link <%= "active" if params[:state] == "satellite" %>">🛰</a>
</li>
<h3 class="mx-2">Top:</h3>
<li class="nav-item">
<a href="/internal/articles?state=top-3" class="nav-link <%= "active" if params[:state] == "top-3" %>">3mo</a>
</li>
<li class="nav-item">
<a href="/internal/articles?state=boosted-additional-articles" class="nav-link <%= "active" if params[:state] == "boosted-additional-articles" %>">Boosted</a>
<a href="/internal/articles?state=satellite-not-buffered" class="nav-link <%= "active" if params[:state] == "satellite-not-buffered" %>">Satellite</a>
</li>
</ul>
<% if params[:state] && params[:state].include?("top-") && params[:state] != "top-3" && params[:state] != "top-6" %>
<h1 style="color:red">
<%= params[:state] %>-months
</h1>
<% end %>
<hr>
</div>
<div class="col-12 mb-2">
<details>
<summary style="font-size: 1.3em; cursor: pointer;">Suggested Tweets (<%= @pending_buffer_updates.size %>)</summary>
<% @pending_buffer_updates.each do |buffer_update| %>
<% next unless buffer_update.article %>
<div class="card my-3" id="suggested-tweet-<%= buffer_update.id %>" data-controller="buffer" data-action="load@window->buffer#autosizeBodyText">
<div class="card-header">
<h2 class="my-0" data-target="buffer.header"><%= buffer_update.article.title %></h2>
</div>
<div class="card-body">
<h4>Score: <%= buffer_update.article.score %></h4>
<div class="blockquote">
<%= HTML_Truncator.truncate(buffer_update.article.processed_html, 50, ellipsis: '<a class="comment-read-more" href="' + buffer_update.article.path + '">... Read Entire Post</a>').html_safe %>
<% if @pending_buffer_updates.any? %>
<div class="col-12 mb-2">
<details>
<summary style="font-size: 1.3em; cursor: pointer;">Suggested Tweets (<%= @pending_buffer_updates.size %>)</summary>
<% @pending_buffer_updates.each do |buffer_update| %>
<% next unless buffer_update.article %>
<div class="card my-3" id="suggested-tweet-<%= buffer_update.id %>" data-controller="buffer" data-action="load@window->buffer#autosizeBodyText">
<div class="card-header">
<h2 class="my-0" data-target="buffer.header"><%= buffer_update.article.title %></h2>
</div>
<hr />
<code><b><%= Tag.find_by(id: buffer_update.tag_id)&.name || buffer_update.social_service_name %>:</b></code>
<%= form_with url: internal_buffer_update_path(buffer_update.id), class: "buffer-form buffer-confirm", html: { data: { action: "submit->buffer#highlightElement" } } do |f| %>
<div class="form-group">
<input name="utf8" type="hidden" value="✓">
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>" />
<input type="hidden" name="_method" value="patch" />
<input type="hidden" name="status" value="confirmed" />
<textarea class="w-100 suggested-tweet-body-text" name="body_text" class="form-control" data-target="buffer.bodyText"><%= buffer_update.body_text %></textarea>
<div class="card-body">
<h4>Score: <%= buffer_update.article.score %></h4>
<div class="blockquote">
<%= HTML_Truncator.truncate(buffer_update.article.processed_html, 50, ellipsis: '<a class="comment-read-more" href="' + buffer_update.article.path + '">... Read Entire Post</a>').html_safe %>
</div>
<button value="confirmed" name="status" class="btn btn-success" data-action="buffer#tagBufferUpdateConfirmed">Confirm</button>
<% end %>
<hr />
<%= form_with url: internal_buffer_update_path(buffer_update.id), class: "buffer-form buffer-dismiss", html: { data: { action: "submit->buffer#highlightElement" } } do |f| %>
<div class="form-group">
<input name="utf8" type="hidden" value="✓">
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>" />
<input type="hidden" name="_method" value="patch" />
<input type="hidden" name="status" value="dismissed" />
</div>
<button value="dismissed" name="status" class="btn btn-danger" data-action="buffer#tagBufferUpdateDismissed">Dismiss</button>
<% end %>
<code><b><%= Tag.find_by(id: buffer_update.tag_id)&.name || buffer_update.social_service_name %>:</b></code>
<%= form_with url: internal_buffer_update_path(buffer_update.id), class: "buffer-form buffer-confirm", html: { data: { action: "submit->buffer#highlightElement" } } do |f| %>
<div class="form-group">
<input name="utf8" type="hidden" value="✓">
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>" />
<input type="hidden" name="_method" value="patch" />
<input type="hidden" name="status" value="confirmed" />
<textarea class="w-100 suggested-tweet-body-text" name="body_text" class="form-control" data-target="buffer.bodyText"><%= buffer_update.body_text %></textarea>
</div>
<button value="confirmed" name="status" class="btn btn-success" data-action="buffer#tagBufferUpdateConfirmed">Confirm</button>
<% end %>
<%= form_with url: internal_buffer_update_path(buffer_update.id), class: "buffer-form buffer-dismiss", html: { data: { action: "submit->buffer#highlightElement" } } do |f| %>
<div class="form-group">
<input name="utf8" type="hidden" value="✓">
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>" />
<input type="hidden" name="_method" value="patch" />
<input type="hidden" name="status" value="dismissed" />
</div>
<button value="dismissed" name="status" class="btn btn-danger" data-action="buffer#tagBufferUpdateDismissed">Dismiss</button>
<% end %>
</div>
</div>
</div>
<% end %>
</details>
</div>
<% end %>
</details>
</div>
<% end %>
<div class="col-12">
<% if @featured_articles.present? %>
<h2>Manually Featured Articles</h2>
@ -94,7 +97,6 @@
<% end %>
</div>
<div class="col-12">
<h1>All Articles</h1>
<%= paginate @articles %>
<% @articles.each do |article| %>

View file

@ -3,7 +3,8 @@ require "rails_helper"
RSpec.describe Bufferizer, type: :labor do
let(:user) { create(:user) }
let(:listing) { create(:classified_listing, user_id: user.id) }
let(:article) { create(:article, user_id: user.id) }
let(:tag) { create(:tag, buffer_profile_id_code: "test")}
let(:article) { create(:article, user_id: user.id, tags: tag.name) }
it "sends to buffer twitter" do
tweet = "test tweet"
@ -11,9 +12,23 @@ RSpec.describe Bufferizer, type: :labor do
expect(article.last_buffered.utc.to_i).to be > 2.minutes.ago.to_i
end
it "includes admin approver" do
tweet = "test tweet"
described_class.new("article", article, tweet, user.id).main_tweet!
expect(BufferUpdate.last.approver_user_id).to be user.id
end
it "sends to buffer sattelite twitter" do
tweet = "test tweet #DEVCommunity"
described_class.new("article", article, tweet).satellite_tweet!
expect(article.last_buffered.utc.to_i).to be > 2.minutes.ago.to_i
expect(BufferUpdate.last.body_text).to include(" #DEVCommunity ##{tag.name} http")
end
it "sends to buffer facebook" do
post = "test facebook post"
described_class.new("article", article, post).facebook_post!
described_class.new("article", article, post, user.id).facebook_post!
expect(article.facebook_last_buffered.utc.to_i).to be > 2.minutes.ago.to_i
end

View file

@ -34,6 +34,13 @@ RSpec.describe "/internal/buffer_updates", type: :request do
expect(article.reload.last_buffered).not_to eq(nil)
end
it "marks article as featured" do
post "/internal/buffer_updates",
params:
{ social_channel: "main_twitter", article_id: article.id, tweet: "Hello this is a test" }
expect(article.reload.featured).to be true
end
it "updates last buffered at with satellite buffer" do
post "/internal/buffer_updates",
params: