# frozen_string_literal: true require 'rails_helper' require 'json' RSpec.describe <%= controller_class_name %>Controller do let(:params) { {} } let(:json_response) { JSON.parse(response.body, symbolize_names: true) } <% if doorkeeper_oauth? -%> let(:user) { create(:user) } let(:token) { instance_double('Doorkeeper::AccessToken', :accessible? => true, :acceptable? => true, resource_owner_id: user.id) } <% end -%> describe 'GET #index' do let!(:<%= controller_class_name.singularize.underscore %>) { create(:<%= controller_class_name.singularize.underscore %>) } before(:each) do <% if doorkeeper_oauth? -%> allow(subject).to receive(:doorkeeper_token) { token } <% end -%> get :index, params: params end context 'ok' do it { expect(json_response[0][:id]).to eq <%= controller_class_name.singularize.underscore %>.id } it { expect(response.status).to eq 200 } end end describe 'GET #show' do let(:<%= controller_class_name.singularize.underscore %>) { create(:<%= controller_class_name.singularize.underscore %>) } let(:params) { { id: <%= controller_class_name.singularize.underscore %>.id } } before(:each) do <% if doorkeeper_oauth? -%> allow(subject).to receive(:doorkeeper_token) { token } <% end -%> get :show, params: params end context 'ok' do it { expect(response.status).to eq 200 } end end describe 'POST #create' do let(:payload_params) { {text: 'OK'} } let(:params) { { payload: payload_params, binaries: [{identifier: 'record', mimetype: 'video/mp4'}] } } before(:each) do <% if doorkeeper_oauth? -%> allow(subject).to receive(:doorkeeper_token) { token } <% end -%> post :create, params: params end context 'ok' do it { expect(<%= controller_class_name.singularize %>.count).to eq 1 } it { expect(response.status).to eq 201 } <% if s3_storage? -%> it { expect(json_response[:binary_urls]).to_not be_nil } <% end %> end end end