Allow optional import_mode param for posts in api (#4952)

This commit is contained in:
Mudasir Raza 2017-08-17 16:53:04 +05:00 committed by Sam
parent 0e656ff213
commit 84c83afd35
2 changed files with 23 additions and 0 deletions

View File

@ -574,6 +574,9 @@ class PostsController < ApplicationController
params[:skip_validations] = params[:skip_validations].to_s == "true"
permitted << :skip_validations
params[:import_mode] = params[:import_mode].to_s == "true"
permitted << :import_mode
# We allow `embed_url` via the API
permitted << :embed_url

View File

@ -631,6 +631,26 @@ describe PostsController do
expect(response.body).to eq(original)
end
it 'allows to create posts in import_mode' do
NotificationEmailer.enable
post = Fabricate(:post)
user = Fabricate(:user)
master_key = ApiKey.create_master_key.key
xhr :post, :create, {api_username: user.username, api_key: master_key, raw: 'this is test reply 1', topic_id: post.topic.id, reply_to_post_number: 1}
expect(response).to be_success
expect(post.topic.user.notifications.count).to eq(1)
post.topic.user.notifications.destroy_all
xhr :post, :create, {api_username: user.username, api_key: master_key, raw: 'this is test reply 2', topic_id: post.topic.id, reply_to_post_number: 1, :import_mode => true}
expect(response).to be_success
expect(post.topic.user.notifications.count).to eq(0)
xhr :post, :create, {api_username: user.username, api_key: master_key, raw: 'this is test reply 3', topic_id: post.topic.id, reply_to_post_number: 1, :import_mode => false}
expect(response).to be_success
expect(post.topic.user.notifications.count).to eq(1)
end
end
describe 'when logged in' do