scinote-web/spec/controllers/result_texts_controller_spec.rb

58 lines
1.6 KiB
Ruby
Raw Normal View History

2019-03-14 02:05:29 +08:00
# frozen_string_literal: true
require 'rails_helper'
describe ResultTextsController, type: :controller do
login_user
include_context 'reference_project_structure', {
result_text: true
}
2021-09-09 21:41:42 +08:00
describe 'POST create' do
let(:action) { post :create, params: params, format: :json }
2019-03-14 02:05:29 +08:00
let(:params) do
{ my_module_id: my_module.id,
2019-03-14 02:05:29 +08:00
result: { name: 'result name created',
result_text_attributes: { text: 'result text created' } } }
end
it 'calls create activity service' do
expect(Activities::CreateActivityService).to receive(:call)
.with(hash_including(activity_type: :add_result))
action
end
2019-03-14 02:05:29 +08:00
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
2019-03-14 02:05:29 +08:00
end
end
describe '#update' do
let(:action) { put :update, params: params, format: :json }
2019-03-14 02:05:29 +08:00
let(:params) do
{ id: result_text.id,
result: { name: result_text.result.name } }
2019-03-14 02:05:29 +08:00
end
it 'calls create activity service (edit_result)' do
params[:result][:name] = 'test result changed'
expect(Activities::CreateActivityService).to receive(:call)
.with(hash_including(activity_type: :edit_result))
action
2019-03-14 02:05:29 +08:00
end
it 'calls create activity service (archive_result)' do
params[:result][:archived] = 'true'
expect(Activities::CreateActivityService).to receive(:call)
.with(hash_including(activity_type: :archive_result))
action
end
2019-03-14 02:05:29 +08:00
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
2019-03-14 02:05:29 +08:00
end
end
end