diff --git a/app/controllers/ajax/inbox_controller.rb b/app/controllers/ajax/inbox_controller.rb index 64bee3e1..66ed1766 100644 --- a/app/controllers/ajax/inbox_controller.rb +++ b/app/controllers/ajax/inbox_controller.rb @@ -1,25 +1,4 @@ class Ajax::InboxController < AjaxController - def create - unless user_signed_in? - @response[:status] = :noauth - @response[:message] = t(".noauth") - return - end - - question = Question.create!(content: QuestionGenerator.generate, - author_is_anonymous: true, - author_identifier: "justask", - user: current_user) - - inbox = Inbox.create!(user: current_user, question_id: question.id, new: true) - - @response[:status] = :okay - @response[:message] = t(".success") - @response[:success] = true - @response[:render] = render_to_string(partial: 'inbox/entry', locals: { i: inbox }) - inbox.update(new: false) - end - def remove params.require :id diff --git a/app/javascript/retrospring/features/inbox/generate.ts b/app/javascript/retrospring/features/inbox/generate.ts deleted file mode 100644 index abbc4d83..00000000 --- a/app/javascript/retrospring/features/inbox/generate.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { post } from '@rails/request.js'; - -import I18n from 'retrospring/i18n'; -import { updateDeleteButton } from './delete'; -import { showErrorNotification } from 'utilities/notifications'; - -export function generateQuestionHandler(): void { - post('/ajax/generate_question') - .then(async response => { - const data = await response.json; - - if (!data.success) return false; - - document.querySelector('#entries').insertAdjacentHTML('afterbegin', data.render); - updateDeleteButton(); - }) - .catch(err => { - console.log(err); - showErrorNotification(I18n.translate('frontend.error.message')); - }); -} \ No newline at end of file diff --git a/app/javascript/retrospring/features/inbox/index.ts b/app/javascript/retrospring/features/inbox/index.ts index 8e6ff29d..4235dc15 100644 --- a/app/javascript/retrospring/features/inbox/index.ts +++ b/app/javascript/retrospring/features/inbox/index.ts @@ -2,11 +2,9 @@ import registerEvents from 'utilities/registerEvents'; import registerInboxEntryEvents from './entry'; import { authorSearchHandler } from './author'; import { deleteAllAuthorQuestionsHandler, deleteAllQuestionsHandler } from './delete'; -import { generateQuestionHandler } from './generate'; export default (): void => { registerEvents([ - { type: 'click', target: '#ib-generate-question', handler: generateQuestionHandler, global: true }, { type: 'click', target: '#ib-delete-all', handler: deleteAllQuestionsHandler, global: true }, { type: 'click', target: '#ib-delete-all-author', handler: deleteAllAuthorQuestionsHandler, global: true }, { type: 'submit', target: '#author-form', handler: authorSearchHandler, global: true } diff --git a/config/routes.rb b/config/routes.rb index a733f6fe..eae3f063 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -110,7 +110,6 @@ Rails.application.routes.draw do namespace :ajax do post "/ask", to: "question#create", as: :ask post "/destroy_question", to: "question#destroy", as: :destroy_question - post "/generate_question", to: "inbox#create", as: :generate_question post "/delete_inbox", to: "inbox#remove", as: :delete_inbox post "/delete_all_inbox", to: "inbox#remove_all", as: :delete_all_inbox post "/delete_all_inbox/:author", to: "inbox#remove_all_author", as: :delete_all_author diff --git a/spec/controllers/ajax/inbox_controller_spec.rb b/spec/controllers/ajax/inbox_controller_spec.rb index 35515b86..3b50c43d 100644 --- a/spec/controllers/ajax/inbox_controller_spec.rb +++ b/spec/controllers/ajax/inbox_controller_spec.rb @@ -4,46 +4,6 @@ require "rails_helper" describe Ajax::InboxController, :ajax_controller, type: :controller do - describe "#create" do - subject { post(:create) } - - context "when user is signed in" do - before(:each) { sign_in(user) } - - let(:expected_response) do - { - "success" => true, - "status" => "okay", - "message" => anything, - "render" => anything - } - end - - it "creates a generated question to the user's inbox" do - allow(QuestionGenerator).to receive(:generate).and_return("Is Mayonnaise an instrument?") - expect { subject }.to(change { user.inboxes.count }.by(1)) - expect(user.inboxes.last.question.author_is_anonymous).to eq(true) - expect(user.inboxes.last.question.author_identifier).to eq("justask") - expect(user.inboxes.last.question.user).to eq(user) - expect(user.inboxes.last.question.content).to eq("Is Mayonnaise an instrument?") - end - - include_examples "returns the expected response" - end - - context "when user is not signed in" do - let(:expected_response) do - { - "success" => false, - "status" => "noauth", - "message" => anything - } - end - - include_examples "returns the expected response" - end - end - describe "#remove" do let(:params) do {