Finalize suggest-a-tweet functionality (#2310)
This commit is contained in:
parent
1552df98d2
commit
d7e2a07064
4 changed files with 37 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -129,8 +129,9 @@
|
|||
<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? %>
|
||||
{ author: @<%= article.user.twitter_username %> } #DEVCommunity
|
||||
<% if !article.user.twitter_username.blank? %>
|
||||
|
||||
{ author: @<%= article.user.twitter_username %> } #DEVCommunity
|
||||
<% end %>
|
||||
</textarea>
|
||||
<button class="btn btn-info" style="font-size:1em;">🦅 Tweet to @ThePracticalDev</button>
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@
|
|||
<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>
|
||||
<textarea name="body_text" style="height: 100px"><%= buffer_update.body_text %></textarea>
|
||||
<br />
|
||||
<button value="confirmed" name="status" class="btn btn-success">confirm</button>
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue