From d7e2a0706490f3d80ff20a46d344350d906ccb8e Mon Sep 17 00:00:00 2001 From: Ben Halpern Date: Thu, 4 Apr 2019 19:23:03 -0400 Subject: [PATCH] Finalize suggest-a-tweet functionality (#2310) --- app/controllers/buffer_updates_controller.rb | 12 +++++---- .../articles/_individual_article.html.erb | 5 ++-- app/views/internal/articles/index.html.erb | 2 +- spec/requests/buffer_updates_spec.rb | 27 ++++++++++++++++++- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/app/controllers/buffer_updates_controller.rb b/app/controllers/buffer_updates_controller.rb index fb1a7b94a..803ee121e 100644 --- a/app/controllers/buffer_updates_controller.rb +++ b/app/controllers/buffer_updates_controller.rb @@ -14,7 +14,7 @@ class BufferUpdatesController < ApplicationController BufferUpdate.create( article_id: @article.id, composer_user_id: current_user.id, - body_text: params[:buffer_update][:body_text], + body_text: modified_body_text, social_service_name: "twitter", buffer_profile_id_code: ApplicationConfig["BUFFER_TWITTER_ID"], status: "pending", @@ -29,10 +29,10 @@ class BufferUpdatesController < ApplicationController BufferUpdate.create( article_id: @article.id, composer_user_id: current_user.id, - body_text: params[:buffer_update][:body_text], + body_text: modified_body_text, social_service_name: "twitter", buffer_profile_id_code: tag.buffer_profile_id_code, - tag_id: params[:buffer_update][:tag_id], + tag_id: tag.id, status: "pending", ) end @@ -42,9 +42,11 @@ class BufferUpdatesController < ApplicationController def modified_body_text @user = @article.user if @user.twitter_username.present? - params[:buffer_update][:body_text] + "\n{ author: @#{@user.twitter_username} } #DEVCommunity" + params[:buffer_update][:body_text] + + "\n\n{ author: @#{@user.twitter_username} } #DEVCommunity\n#{ApplicationConfig['APP_PROTOCOL']}#{ApplicationConfig['APP_DOMAIN']}#{@article.path}" else - params[:buffer_update][:body_text] + params[:buffer_update][:body_text] + + " #DEVCommunity\n#{ApplicationConfig['APP_PROTOCOL']}#{ApplicationConfig['APP_DOMAIN']}#{@article.path}" end end end diff --git a/app/views/internal/articles/_individual_article.html.erb b/app/views/internal/articles/_individual_article.html.erb index 1262687bb..1c734f9a5 100644 --- a/app/views/internal/articles/_individual_article.html.erb +++ b/app/views/internal/articles/_individual_article.html.erb @@ -129,8 +129,9 @@

Twitter MAIN

diff --git a/app/views/internal/articles/index.html.erb b/app/views/internal/articles/index.html.erb index 76f13c74c..003e788bf 100644 --- a/app/views/internal/articles/index.html.erb +++ b/app/views/internal/articles/index.html.erb @@ -58,7 +58,7 @@ - +
diff --git a/spec/requests/buffer_updates_spec.rb b/spec/requests/buffer_updates_spec.rb index 17d5cd079..7e2e9c780 100644 --- a/spec/requests/buffer_updates_spec.rb +++ b/spec/requests/buffer_updates_spec.rb @@ -17,9 +17,34 @@ RSpec.describe "BufferUpdates", type: :request do 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.body_text).to start_with("This is the text!!!!") expect(BufferUpdate.last.status).to eq("pending") end + + it "creates buffer update with link" do + post "/buffer_updates", + params: + { buffer_update: { body_text: "This is the text!!!!", tag_id: "javascript", article_id: article.id } } + expect(BufferUpdate.last.body_text).to include(article.path) + end + + it "creates buffer hashtag" do + post "/buffer_updates", + params: + { buffer_update: { body_text: "This is the text!!!!", tag_id: "javascript", article_id: article.id } } + expect(BufferUpdate.last.body_text).to include("#DEVCommunity") + end + + it "creates satellite buffer" do + article.update_column(:cached_tag_list, "ruby, rails, meta") + create(:tag, name: "rails") + tag = create(:tag, buffer_profile_id_code: "placeholder", name: "ruby") + 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(2) + expect(BufferUpdate.last.tag_id).to eq(tag.id) + end end context "when non-trusted user is logged in" do