2019-03-14 02:05:29 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe ResultTablesController, type: :controller do
|
|
|
|
login_user
|
|
|
|
|
2021-09-16 17:52:18 +08:00
|
|
|
include_context 'reference_project_structure', {
|
|
|
|
result_table: true
|
|
|
|
}
|
2021-09-09 21:41:42 +08:00
|
|
|
|
2019-03-27 18:24:44 +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
|
2021-09-16 17:52:18 +08:00
|
|
|
{ my_module_id: my_module.id,
|
2019-03-14 02:05:29 +08:00
|
|
|
result:
|
|
|
|
{ name: 'result name created',
|
|
|
|
table_attributes:
|
2023-10-12 22:16:43 +08:00
|
|
|
{ contents: '{\"data\":[[\"a\",\"b\",\"1\",null,null]]}',
|
|
|
|
metadata: "{\"cells\":[{\"row\":\"0\",\"col\":\"0\",\"className\":\"\",\"calculated\":\"\"}]}" } } }
|
2019-03-14 02:05:29 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls create activity service' do
|
|
|
|
expect(Activities::CreateActivityService).to receive(:call)
|
|
|
|
.with(hash_including(activity_type: :add_result))
|
2019-03-27 18:24:44 +08:00
|
|
|
action
|
|
|
|
end
|
2019-03-14 02:05:29 +08:00
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
2019-03-14 02:05:29 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
describe 'PUT update' do
|
|
|
|
let(:action) { put :update, params: params, format: :json }
|
2019-03-14 02:05:29 +08:00
|
|
|
let(:params) do
|
|
|
|
{ id: result_table.id,
|
2021-09-16 17:52:18 +08:00
|
|
|
result: { name: result_table.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))
|
2019-03-27 18:24:44 +08:00
|
|
|
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))
|
2019-03-27 18:24:44 +08:00
|
|
|
action
|
|
|
|
end
|
2019-03-14 02:05:29 +08:00
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
it 'adds activity in DB' do
|
|
|
|
params[:result][:archived] = 'true'
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
2019-03-14 02:05:29 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|