Sha256: 9893c6e4cec5c92d6832502d6305ad82df6a797a86a6a5ab95359971a1ac43b6

Contents?: true

Size: 1.72 KB

Versions: 2

Compression:

Stored size: 1.72 KB

Contents

require 'spec_helper'

module Tasuku
  describe Taskables::Questions::AnswersController do
    routes { Tasuku::Engine.routes }

    describe "POST 'create'" do
      it 'routes' do
        expect(post: '/questions/1/answers').to route_to(
          action: 'create',
          controller: 'tasuku/taskables/questions/answers',
          question_id: '1'
        )
      end

      context 'with an answer' do
        let(:user)     { create :user }
        let(:question) { create :question }
        let(:option)   { create :question_option, question: question }
        let(:params)   { { question_id: question.id, taskables_question_answer: { option_ids: [option.id] } } }

        before { request.env['HTTP_REFERER'] = 'http://example.org' }
        before { expect(subject).to receive(:current_user).and_return(user) }

        it_behaves_like 'redirectable' do
          let(:action) { :create }
          let(:verb)   { :post }
        end

        it 'creates a new answer' do
          post :create, params

          expect(question.answers.count).to eq 1
        end
      end

      context 'no answers' do
        let(:user)     { create :user }
        let(:question) { create :question }
        let(:params)   { { question_id: question.id } }

        before { request.env['HTTP_REFERER'] = 'http://example.org' }
        before { post :create, params }

        it 'does not create a new answer' do
          expect(question.answers.count).to be_zero
        end

        it 'redirects back' do
          expect(response).to redirect_to 'http://example.org'
        end

        it 'renders an alert' do
          expect(flash[:alert]).to eq I18n.t('tasuku.taskables.questions.answers.no_answers')
        end
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tasuku-1.1.0 spec/controllers/tasuku/taskables/questions/answers_controller_spec.rb
tasuku-1.0.1 spec/controllers/tasuku/taskables/questions/answers_controller_spec.rb