From 1e805cfd3e3dc1e52557c1fbca7f5c404c3b2261 Mon Sep 17 00:00:00 2001 From: OsamaSayegh Date: Thu, 7 Jun 2018 08:51:52 +0300 Subject: [PATCH] REFACTOR: composer messages controller specs to requests (#5940) --- .../composer_messages_controller_spec.rb | 29 ---------------- .../composer_messages_controller_spec.rb | 33 +++++++++++++++++++ 2 files changed, 33 insertions(+), 29 deletions(-) delete mode 100644 spec/controllers/composer_messages_controller_spec.rb create mode 100644 spec/requests/composer_messages_controller_spec.rb diff --git a/spec/controllers/composer_messages_controller_spec.rb b/spec/controllers/composer_messages_controller_spec.rb deleted file mode 100644 index 27338ed8906..00000000000 --- a/spec/controllers/composer_messages_controller_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require 'rails_helper' - -describe ComposerMessagesController do - - context '.index' do - - it 'requires you to be logged in' do - get :index, format: :json - expect(response.status).to eq(403) - end - - context 'when logged in' do - let!(:user) { log_in } - let(:args) { { 'topic_id' => '123', 'post_id' => '333', 'composer_action' => 'reply' } } - - it 'redirects to your user preferences' do - get :index, format: :json - expect(response).to be_successful - end - - it 'delegates args to the finder' do - finder = mock - ComposerMessagesFinder.expects(:new).with(instance_of(User), has_entries(args)).returns(finder) - finder.expects(:find) - get :index, params: args, format: :json - end - end - end -end diff --git a/spec/requests/composer_messages_controller_spec.rb b/spec/requests/composer_messages_controller_spec.rb new file mode 100644 index 00000000000..ea3163ccfad --- /dev/null +++ b/spec/requests/composer_messages_controller_spec.rb @@ -0,0 +1,33 @@ +require 'rails_helper' + +describe ComposerMessagesController do + let(:topic) { Fabricate(:topic, created_at: 10.years.ago, last_posted_at: 10.years.ago) } + let(:post) { Fabricate(:post, topic: topic, post_number: 1, created_at: 10.years.ago) } + + context '#index' do + it 'requires you to be logged in' do + get "/composer_messages.json" + expect(response.status).to eq(403) + end + + context 'when logged in' do + let!(:user) { sign_in(Fabricate(:user)) } + let(:args) { { 'topic_id' => post.topic.id, 'post_id' => '333', 'composer_action' => 'reply' } } + + it 'redirects to your user preferences' do + get "/composer_messages.json" + expect(response.status).to eq(200) + end + + it 'delegates args to the finder' do + user.user_stat.update!(post_count: 10) + SiteSetting.disable_avatar_education_message = true + + get "/composer_messages.json", params: args + expect(response.status).to eq(200) + json = JSON.parse(response.body) + expect(json["composer_messages"].first["id"]).to eq("reviving_old") + end + end + end +end