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.
Provide a rating between 1 and 10 based on which audience would find this post most valuable.
+
1: for brand new developers, 3: for junior developers, 10: for very advanced developers, etc.
+
This will provide
+ approximate and gentle algorithmic adjustments to help deliver relevant content.
+
It will be used as one of many indicators. No one rating will have an overly dramatic affect.
+
+
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index 7881b9093..62e59fdb0 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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"
diff --git a/db/migrate/20190402224426_add_user_info_to_buffer_updates.rb b/db/migrate/20190402224426_add_user_info_to_buffer_updates.rb
new file mode 100644
index 000000000..d022ac038
--- /dev/null
+++ b/db/migrate/20190402224426_add_user_info_to_buffer_updates.rb
@@ -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
diff --git a/db/schema.rb b/db/schema.rb
index a391323c8..125158b58 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -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
diff --git a/spec/policies/buffer_update_policy_spec.rb b/spec/policies/buffer_update_policy_spec.rb
new file mode 100644
index 000000000..3da642bbd
--- /dev/null
+++ b/spec/policies/buffer_update_policy_spec.rb
@@ -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
diff --git a/spec/requests/buffer_updates_spec.rb b/spec/requests/buffer_updates_spec.rb
new file mode 100644
index 000000000..17d5cd079
--- /dev/null
+++ b/spec/requests/buffer_updates_spec.rb
@@ -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
diff --git a/spec/requests/internal_buffer_updates_spec.rb b/spec/requests/internal_buffer_updates_spec.rb
index e6bf2edc2..444a38fb8 100644
--- a/spec/requests/internal_buffer_updates_spec.rb
+++ b/spec/requests/internal_buffer_updates_spec.rb
@@ -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