scinote-web/spec/controllers/result_tables_controller_spec.rb

75 lines
2.1 KiB
Ruby
Raw Normal View History

2019-03-14 02:05:29 +08:00
# frozen_string_literal: true
require 'rails_helper'
describe ResultTablesController, type: :controller do
login_user
2019-03-21 04:34:47 +08:00
let(:user) { subject.current_user }
let!(:team) { create :team, created_by: user, users: [user] }
2019-03-14 02:05:29 +08:00
let(:project) do
2021-09-09 21:41:42 +08:00
create :project, team: team
end
2021-09-09 21:41:42 +08:00
let(:owner_role) { create :owner_role }
2019-03-14 02:05:29 +08:00
let(:experiment) { create :experiment, project: project }
let(:task) { create :my_module, name: 'test task', experiment: experiment }
let(:result) do
create :result, name: 'test result', my_module: task, user: user
end
let(:result_table) { create :result_table, result: result }
2021-09-09 21:41:42 +08:00
before do
create_user_assignment(task, owner_role, user)
end
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: task.id,
result:
{ name: 'result name created',
table_attributes:
{ contents: '{\"data\":[[\"a\",\"b\",\"1\",null,null]]}' } } }
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 '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,
result: { name: result.name } }
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
params[:result][:archived] = 'true'
expect { action }
.to(change { Activity.count })
2019-03-14 02:05:29 +08:00
end
end
end