Add ability for trusted users to suggest social copy for posts (#2306)

* Add ability for trusted users to suggest social copy for posts

* Fix schema

* Fix tests

* Fix test
This commit is contained in:
Ben Halpern 2019-04-04 17:01:58 -04:00 committed by GitHub
parent 5e9867ec56
commit 1552df98d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 389 additions and 74 deletions

View file

@ -0,0 +1,50 @@
class BufferUpdatesController < ApplicationController
after_action :verify_authorized
def create
authorize BufferUpdate
@article = Article.find(params[:buffer_update][:article_id])
create_main_tweet
create_satellite_tweets
@article.update(last_buffered: Time.current)
redirect_back(fallback_location: "/mod")
end
def create_main_tweet
BufferUpdate.create(
article_id: @article.id,
composer_user_id: current_user.id,
body_text: params[:buffer_update][:body_text],
social_service_name: "twitter",
buffer_profile_id_code: ApplicationConfig["BUFFER_TWITTER_ID"],
status: "pending",
)
end
def create_satellite_tweets
tags_names = @article.decorate.cached_tag_list_array
tags_names.each do |name|
tag = Tag.find_by(name: name)
if tag&.buffer_profile_id_code.present?
BufferUpdate.create(
article_id: @article.id,
composer_user_id: current_user.id,
body_text: params[:buffer_update][:body_text],
social_service_name: "twitter",
buffer_profile_id_code: tag.buffer_profile_id_code,
tag_id: params[:buffer_update][:tag_id],
status: "pending",
)
end
end
end
def modified_body_text
@user = @article.user
if @user.twitter_username.present?
params[:buffer_update][:body_text] + "\n{ author: @#{@user.twitter_username} } #DEVCommunity"
else
params[:buffer_update][:body_text]
end
end
end

View file

@ -2,6 +2,7 @@ class Internal::ArticlesController < Internal::ApplicationController
layout "internal"
def index
@pending_buffer_updates = BufferUpdate.where(status: "pending").includes(:article)
case params[:state]
when /not\-buffered/

View file

@ -14,4 +14,9 @@ class Internal::BufferUpdatesController < Internal::ApplicationController
render body: nil
end
end
def update
BufferUpdate.upbuff!(params[:id], current_user.id, params[:body_text], params[:status])
render body: nil
end
end

View file

@ -9,7 +9,7 @@ class ModerationsController < ApplicationController
includes(:rating_votes).
where("rating_votes_count < 3").
where("score > -5").
order("hotness_score DESC").limit(50)
order("hotness_score DESC").limit(100)
if params[:tag].present?
@articles = @articles.
cached_tagged_with(params[:tag])

View file

@ -2,6 +2,7 @@ class BufferUpdate < ApplicationRecord
belongs_to :article
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)
buffer_response = send_to_buffer(text, buffer_profile_id_code)
@ -12,9 +13,20 @@ class BufferUpdate < ApplicationRecord
buffer_profile_id_code: buffer_profile_id_code,
social_service_name: social_service_name,
buffer_response: buffer_response,
status: "sent_direct",
)
end
def self.upbuff!(buffer_update_id, admin_id, body_text, status)
buffer_update = BufferUpdate.find(buffer_update_id)
if status == "confirmed"
buffer_response = send_to_buffer(buffer_update.body_text, buffer_update.buffer_profile_id_code)
buffer_update.update!(buffer_response: buffer_response, status: status, approver_user_id: admin_id, body_text: body_text)
else
buffer_update.update!(status: status, approver_user_id: admin_id)
end
end
def self.send_to_buffer(text, buffer_profile_id_code)
client = Buffer::Client.new(ApplicationConfig["BUFFER_ACCESS_TOKEN"])
client.create_update(
@ -31,6 +43,8 @@ class BufferUpdate < ApplicationRecord
private
def validate_body_text_recent_uniqueness
return if persisted?
if BufferUpdate.where(body_text: body_text, article_id: article_id, tag_id: tag_id, social_service_name: social_service_name).
where("created_at > ?", 2.minutes.ago).any?
errors.add(:body_text, "\"#{body_text}\" has already been submitted very recently")

View file

@ -66,4 +66,8 @@ class ApplicationPolicy
def user_is_banned?
user.banned
end
def user_is_trusted?
user.has_role?(:trusted)
end
end

View file

@ -0,0 +1,5 @@
class BufferUpdatePolicy < ApplicationPolicy
def create?
user_is_trusted?
end
end

View file

@ -129,7 +129,10 @@
<input type="hidden" name="article_id" value="<%= article.id %>" />
<p> Twitter MAIN</p>
<textarea cols="37" rows="6" wrap="hard" name="tweet" maxlength="255"><%= article.title %>
<% if !article.user.twitter_username.blank? %>&#013{ author: @<%= article.user.twitter_username %> }<% end %></textarea>
<% if !article.user.twitter_username.blank? %>&#013
{ author: @<%= article.user.twitter_username %> } #DEVCommunity
<% end %>
</textarea>
<button class="btn btn-info" style="font-size:1em;">🦅 Tweet to @ThePracticalDev</button>
<% end %>
<% if (article.decorate.cached_tag_list_array & Tag.bufferized_tags).any? %>

View file

@ -44,6 +44,34 @@
</h1>
<% end %>
<% @pending_buffer_updates.each do |buffer_update| %>
<div class="row">
<h2><%= buffer_update.article.title %></h2>
<h4>Score: <%= buffer_update.article.score %></h4>
<hr />
<%= 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 %>
<hr />
<code><b><%= Tag.find_by(id: buffer_update.tag_id)&.name || "@ThePracticalDev (main)" %>:</b></code>
<form action="/internal/buffer_updates/<%= buffer_update.id %>" accept-charset="UTF-8" method="post">
<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 name="body_text"><%= buffer_update.body_text %></textarea>
<br />
<button value="confirmed" name="status" class="btn btn-success">confirm</button>
</form>
<form action="/internal/buffer_updates/<%= buffer_update.id %>" accept-charset="UTF-8" method="post">
<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" />
<button value="dismissed" name="status" class="btn btn-danger">dismiss</button>
</form>
</div>
<% end %>
<% if @featured_articles && @featured_articles.any? %>
<h1>Manually Featured Articles</h1>
<% @featured_articles.each do |article| %>

View file

@ -12,6 +12,46 @@
.level-rating-button.selected {
background: #9bebff;
}
.tag-mod-form {
border-top: 1px solid rgba(255, 255, 255, 0.5);
margin: 40px auto;
}
.tag-mod-form ul {
text-align: left;
font-size: 15px;
}
.tag-mod-form form {
width: 500px;
margin: auto;
max-width: 90%;
}
.tag-mod-form form input {
width: 100%;
padding: 5px;
font-size: 20px;
margin-bottom: 5px;
border: 1px solid #888;
}
.tag-mod-form form input[type="submit"] {
background: #0045ff;
color: white;
font-weight: bold;
padding: 10px;
margin: auto;
display: block;
}
.tag-mod-form form textarea {
width: 100%;
padding: 5px;
font-size: 17px;
height: 100px;
border: 1px solid #888;
}
</style>
<br /><br /><br /><br />
@ -23,8 +63,8 @@
<div class="container">
<% @articles.each do |article| %>
<% @rating_vote = article.rating_votes.where(user_id: current_user.id).first %>
<% unless @rating_vote %>
<div style="border-bottom: 2px solid black; margin-bottom: 15px;">
<% if !@rating_vote || article.last_buffered.nil? %>
<div style="border-bottom: 20px solid black; margin-bottom: 15px;">
<center>
<h1><%= article.title %></h1>
<% cache("main-article-tags-#{article.cached_tag_list}", expires_in: 30.hours) do %>
@ -40,23 +80,33 @@
200, ellipsis: '<a class="comment-read-more" href="' + article.path + '">... Read Entire Post</a>').html_safe %>
</div>
<center>
<h2><a href="<%= article.path %>/mod">Moderate</a></h2>
<h2>Experience Level Target:</h2>
<%= form_for(RatingVote.new) do |f| %>
<%= f.hidden_field :article_id, value: article.id %>
<%= f.hidden_field :group, value: "experience_level" %>
<button value="1" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 1.0 %>">1</button>
<button value="2" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 2.0 %>">2</button>
<button value="3" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 3.0 %>">3</button>
<button value="4" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 4.0 %>">4</button>
<button value="5" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 5.0 %>">5</button>
<button value="6" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 6.0 %>">6</button>
<button value="7" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 7.0 %>">7</button>
<button value="8" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 8.0 %>">8</button>
<button value="9" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 9.0 %>">9</button>
<button value="10" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 10.0 %>">10</button>
<% if article.last_buffered.nil? %>
<div class="tag-mod-form" style="padding: 10px 0px 20px">
<%= form_for(BufferUpdate.new) do |f| %>
<h2>Suggest a Tweet</h2>
<%= f.hidden_field :article_id, value: article.id %>
<%= f.text_area :body_text, maxlength: 220 %>
<%= f.submit %>
<% end %>
</div>
<p style="width: 90%;margin:50px auto;text-align:left">
<br /><br />Text will be used in the body of a tweet linking to this post.
<br /><br />Tweet suggestion can be a TLDR of the post, an interesting quote from the post, or bullet points from topics covered in the post.
</p>
<% end %>
<br /><br />
<div style="padding: 10px 0px 20px">
<h2>Experience Level Target:</h2>
<% 10.times do |i| %>
<%= form_for(RatingVote.new, html: { style: "display: inline-block" }) do |f| %>
<%= f.hidden_field :article_id, value: article.id %>
<%= f.hidden_field :group, value: "experience_level" %>
<%= f.hidden_field :rating, value: i + 1 %>
<button value="<%= i + 1 %>" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == i + 1 %>"><%= i + 1 %></button>
<% end %>
<% end %>
</div>
<h2><a href="<%= article.path %>/mod">Full Moderation</a></h2>
<br /><br /> <br /><br />
</center>
</div>
<% end %>
@ -75,3 +125,30 @@
</div>
</div>
<% end %>
<script>
var forms = document.getElementsByTagName("form");
for (i=0; i < forms.length; i++){
var form = forms[i];
form.onsubmit = function(e) {
e.preventDefault();
var thisForm = this;
thisForm.parentNode.style.background = "#b7ffe7"
var data = new URLSearchParams();
for (var pair of new FormData(thisForm)) {
console.log(pair[0])
data.append(pair[0], pair[1]);
}
fetch(thisForm.action, {
method: 'post',
body: data,
})
.then(function() {
thisForm.parentNode.style.background = "#00ffa9"
console.log("form submitted")
});
}
}
</script>

View file

@ -106,7 +106,7 @@
<br><br>The DEV team will be notified about vomits and take appropriate action, but leaving a level-headed comment addressing the behavior is welcome if you feel up for it.
</p>
<% end %>
<% is_mod = (@moderatable.tag_list.select { |t| current_user.has_role?(:tag_moderator, Tag.find_by_name(t)) }).any? if @moderatable.class.name == "Article" %>
<% is_mod = (@moderatable.tag_list.select { |t| current_user.has_role?(:tag_moderator, Tag.find_by(name: t)) }).any? if @moderatable.class.name == "Article" %>
<% if @moderatable.class.name == "Article" && (current_user.has_role?(:super_admin) || is_mod) %>
<div class="tag-mod-form">
<%= form_for(TagAdjustment.new) do |f| %>
@ -137,30 +137,46 @@
</div>
<% end %>
<% if @moderatable.class.name == "Article" %>
<% @rating_vote = RatingVote.where(article_id: @moderatable.id, user_id: current_user.id).first %>
<%= form_for(RatingVote.new) do |f| %>
<h2>Experience Level of Post</h2>
<%= f.hidden_field :article_id, value: @moderatable.id %>
<%= f.hidden_field :group, value: "experience_level" %>
<button value="1" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 1.0 %>">1</button>
<button value="2" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 2.0 %>">2</button>
<button value="3" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 3.0 %>">3</button>
<button value="4" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 4.0 %>">4</button>
<button value="5" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 5.0 %>">5</button>
<button value="6" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 6.0 %>">6</button>
<button value="7" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 7.0 %>">7</button>
<button value="8" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 8.0 %>">8</button>
<button value="9" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 9.0 %>">9</button>
<button value="10" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 10.0 %>">10</button>
<% if @moderatable.last_buffered.blank? %>
<div class="tag-mod-form">
<%= form_for(BufferUpdate.new) do |f| %>
<h2>Suggest a Tweet</h2>
<%= f.hidden_field :article_id, value: @moderatable.id %>
<%= f.text_area :body_text, maxlength: 220 %>
<%= f.submit %>
<% end %>
<p style="width: 90%;margin:50px auto;text-align:left">
<br /><br />Text will be used in the body of a tweet linking to this post.
<br /><br />Tweet suggestion can be a TLDR of the post, an interesting quote from the post, or bullet points from topics covered in the post.
</p>
</div>
<% end %>
<p style="width: 90%;margin:50px auto;text-align:left">
<b style="font-size:1.1em">All rating votes are private.</b>
<br><br>Provide a rating between 1 and 10 based on which audience would find this post most valuable.
<br><br>1: for brand new developers, 3: for junior developers, 10: for very advanced developers, etc.
<br><br>This will provide
<em>approximate and gentle</em> algorithmic adjustments to help deliver relevant content.
<br><br>It will be used as one of many indicators. No one rating will have an overly dramatic affect.
</p>
<div class="tag-mod-form">
<% @rating_vote = RatingVote.where(article_id: @moderatable.id, user_id: current_user.id).first %>
<%= form_for(RatingVote.new) do |f| %>
<h2>Experience Level of Post</h2>
<%= f.hidden_field :article_id, value: @moderatable.id %>
<%= f.hidden_field :group, value: "experience_level" %>
<button value="1" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 1.0 %>">1</button>
<button value="2" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 2.0 %>">2</button>
<button value="3" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 3.0 %>">3</button>
<button value="4" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 4.0 %>">4</button>
<button value="5" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 5.0 %>">5</button>
<button value="6" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 6.0 %>">6</button>
<button value="7" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 7.0 %>">7</button>
<button value="8" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 8.0 %>">8</button>
<button value="9" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 9.0 %>">9</button>
<button value="10" name="rating_vote[rating]" class="level-rating-button <%= "selected" if @rating_vote&.rating == 10.0 %>">10</button>
<% end %>
<p style="width: 90%;margin:50px auto;text-align:left">
<b style="font-size:1.1em">All rating votes are private.</b>
<br><br>Provide a rating between 1 and 10 based on which audience would find this post most valuable.
<br><br>1: for brand new developers, 3: for junior developers, 10: for very advanced developers, etc.
<br><br>This will provide
<em>approximate and gentle</em> algorithmic adjustments to help deliver relevant content.
<br><br>It will be used as one of many indicators. No one rating will have an overly dramatic affect.
</p>
</div>
<% end %>
</div>

View file

@ -42,7 +42,7 @@ Rails.application.routes.draw do
end
resources :events
resources :dogfood, only: [:index]
resources :buffer_updates, only: [:create]
resources :buffer_updates, only: %i[create update]
resources :articles, only: %i[index update] do
get "rss_articles", on: :collection
end
@ -137,6 +137,8 @@ Rails.application.routes.draw do
resources :tag_adjustments, only: [:create]
resources :rating_votes, only: [:create]
resources :page_views, only: %i[create update]
resources :buffer_updates, only: [:create]
get "/notifications/:filter" => "notifications#index"
get "/notifications/:filter/:org_id" => "notifications#index"

View file

@ -0,0 +1,7 @@
class AddUserInfoToBufferUpdates < ActiveRecord::Migration[5.1]
def change
add_column :buffer_updates, :composer_user_id, :integer
add_column :buffer_updates, :approver_user_id, :integer
add_column :buffer_updates, :status, :string, default: "pending"
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2019_04_01_213605) do
ActiveRecord::Schema.define(version: 2019_04_02_224426) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
enable_extension "plpgsql"
@ -192,13 +192,16 @@ ActiveRecord::Schema.define(version: 2019_04_01_213605) do
end
create_table "buffer_updates", force: :cascade do |t|
t.integer "approver_user_id"
t.integer "article_id", null: false
t.text "body_text"
t.string "buffer_id_code"
t.string "buffer_profile_id_code"
t.text "buffer_response", default: "--- {}\n"
t.integer "composer_user_id"
t.datetime "created_at", null: false
t.string "social_service_name"
t.string "status", default: "pending"
t.integer "tag_id"
t.datetime "updated_at", null: false
end
@ -484,7 +487,6 @@ ActiveRecord::Schema.define(version: 2019_04_01_213605) do
t.index ["json_data"], name: "index_notifications_on_json_data", using: :gin
t.index ["notifiable_id"], name: "index_notifications_on_notifiable_id"
t.index ["notifiable_type"], name: "index_notifications_on_notifiable_type"
t.index ["user_id", "organization_id", "notifiable_id", "notifiable_type", "action"], name: "index_notifications_on_user_organization_notifiable_and_action", unique: true
t.index ["user_id"], name: "index_notifications_on_user_id"
end

View file

@ -0,0 +1,19 @@
require "rails_helper"
RSpec.describe BufferUpdatePolicy do
subject { described_class.new(user, block) }
let(:block) { build(:block) }
context "when user is trusted" do
let(:user) { build(:user, :trusted) }
it { is_expected.to permit_actions(%i[create]) }
end
context "when user is not trusted" do
let(:user) { build(:user) }
it { is_expected.to forbid_actions(%i[create]) }
end
end

View file

@ -0,0 +1,60 @@
require "rails_helper"
RSpec.describe "BufferUpdates", type: :request do
let(:user) { create(:user) }
let(:mod_user) { create(:user) }
let(:article) { create(:article, user_id: user.id) }
let(:comment) { create(:comment, user_id: user.id, commentable_id: article.id) }
context "when trusted user is logged in" do
before do
sign_in mod_user
mod_user.add_role(:trusted)
end
it "creates buffer update for tweet if tweet params are passed" do
post "/buffer_updates",
params:
{ buffer_update: { body_text: "This is the text!!!!", tag_id: "javascript", article_id: article.id } }
expect(BufferUpdate.all.size).to eq(1)
expect(BufferUpdate.last.body_text).to eq("This is the text!!!!")
expect(BufferUpdate.last.status).to eq("pending")
end
end
context "when non-trusted user is logged in" do
before do
sign_in user
mod_user.add_role(:trusted)
end
it "rejects buffer update for non-trusted user" do
expect do
post "/buffer_updates",
params:
{ buffer_update: { body_text: "This is the text!!!!", tag_id: "javascript", article_id: article.id } }
end.to raise_error(Pundit::NotAuthorizedError)
end
end
# it "updates last buffered at" do
# post "/internal/buffer_updates",
# params:
# { social_channel: "main_twitter", article_id: article.id, tweet: "Hello this is a test" }
# expect(article.reload.last_buffered).not_to eq(nil)
# end
# it "updates last buffered at with satellite buffer" do
# post "/internal/buffer_updates",
# params:
# { social_channel: "satellite_twitter", article_id: article.id, tweet: "Hello this is a test" }
# expect(article.reload.last_buffered).not_to eq(nil)
# end
# it "updates last facebook buffered at" do
# post "/internal/buffer_updates",
# params:
# { social_channel: "facebook", article_id: article.id, tweet: "Hello this is a test" }
# expect(article.reload.facebook_last_buffered).not_to eq(nil)
# end
end

View file

@ -10,35 +10,57 @@ RSpec.describe "InternalBufferUpdates", type: :request do
user.add_role(:super_admin)
end
it "creates buffer update for tweet if tweet params are passed" do
post "/internal/buffer_updates",
params:
{ social_channel: "main_twitter", article_id: article.id, tweet: "Hello this is a test" }
expect(BufferUpdate.all.size).to eq(1)
post "/internal/buffer_updates",
params: { social_channel: "main_twitter", article_id: article.id, tweet: "Hello this is a test!" }
expect(BufferUpdate.all.size).to eq(2)
expect(BufferUpdate.last.article_id).to eq(article.id)
describe "POST /internal/buffer_updates" do
it "creates buffer update for tweet if tweet params are passed" do
post "/internal/buffer_updates",
params:
{ social_channel: "main_twitter", article_id: article.id, tweet: "Hello this is a test" }
expect(BufferUpdate.all.size).to eq(1)
post "/internal/buffer_updates",
params: { social_channel: "main_twitter", article_id: article.id, tweet: "Hello this is a test!" }
expect(BufferUpdate.all.size).to eq(2)
expect(BufferUpdate.last.article_id).to eq(article.id)
end
it "updates last buffered at" do
post "/internal/buffer_updates",
params:
{ social_channel: "main_twitter", article_id: article.id, tweet: "Hello this is a test" }
expect(article.reload.last_buffered).not_to eq(nil)
end
it "updates last buffered at with satellite buffer" do
post "/internal/buffer_updates",
params:
{ social_channel: "satellite_twitter", article_id: article.id, tweet: "Hello this is a test" }
expect(article.reload.last_buffered).not_to eq(nil)
end
it "updates last facebook buffered at" do
post "/internal/buffer_updates",
params:
{ social_channel: "facebook", article_id: article.id, tweet: "Hello this is a test" }
expect(article.reload.facebook_last_buffered).not_to eq(nil)
end
end
it "updates last buffered at" do
post "/internal/buffer_updates",
params:
{ social_channel: "main_twitter", article_id: article.id, tweet: "Hello this is a test" }
expect(article.reload.last_buffered).not_to eq(nil)
end
describe "PUT /internal/buffer_updates" do
let(:buffer_update) do
BufferUpdate.create(article_id: article.id,
composer_user_id: user.id,
body_text: "This is text - #{rand(100)}",
social_service_name: "twitter",
tag_id: "ruby",
status: "pending")
end
it "updates last buffered at with satellite buffer" do
post "/internal/buffer_updates",
params:
{ social_channel: "satellite_twitter", article_id: article.id, tweet: "Hello this is a test" }
expect(article.reload.last_buffered).not_to eq(nil)
end
it "updates last facebook buffered at" do
post "/internal/buffer_updates",
params:
{ social_channel: "facebook", article_id: article.id, tweet: "Hello this is a test" }
expect(article.reload.facebook_last_buffered).not_to eq(nil)
it "sends to buffer" do
put "/internal/buffer_updates/#{buffer_update.id}", params: {
status: "confirmed", body_text: "test"
}
expect(buffer_update.reload.buffer_response).not_to eq(nil)
expect(buffer_update.reload.status).to eq("confirmed")
expect(buffer_update.reload.approver_user_id).to eq(user.id)
end
end
end