2019-03-07 00:18:35 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe ExperimentsController, type: :controller do
|
|
|
|
login_user
|
|
|
|
|
2019-03-05 18:39:57 +08:00
|
|
|
let!(:user) { controller.current_user }
|
|
|
|
let!(:team) { create :team, created_by: user, users: [user] }
|
|
|
|
let!(:project) { create :project, team: team }
|
|
|
|
let!(:user_project) do
|
|
|
|
create :user_project, :owner, user: user, project: project
|
|
|
|
end
|
|
|
|
let(:experiment) { create :experiment, project: project }
|
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
describe 'POST create' do
|
|
|
|
let(:action) { post :create, params: params, format: :json }
|
2019-03-05 18:39:57 +08:00
|
|
|
let(:params) do
|
|
|
|
{ project_id: project.id,
|
|
|
|
experiment: { name: 'test experiment A1',
|
|
|
|
description: 'test description one' } }
|
2019-03-07 00:18:35 +08:00
|
|
|
end
|
2019-03-05 18:39:57 +08:00
|
|
|
|
|
|
|
it 'calls create activity service' do
|
|
|
|
expect(Activities::CreateActivityService).to receive(:call)
|
|
|
|
.with(hash_including(activity_type: :create_experiment))
|
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
action
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
2019-03-05 18:39:57 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT update' do
|
2019-03-13 16:06:48 +08:00
|
|
|
let(:action) { put :update, params: params }
|
2019-03-07 00:18:35 +08:00
|
|
|
|
|
|
|
context 'when editing experiment' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
id: experiment.id,
|
|
|
|
experiment: { title: 'new_title' }
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls create activity for editing experiment' do
|
|
|
|
expect(Activities::CreateActivityService)
|
|
|
|
.to(receive(:call)
|
|
|
|
.with(hash_including(activity_type: :edit_experiment)))
|
|
|
|
|
2019-03-13 16:06:48 +08:00
|
|
|
action
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
2019-03-07 00:18:35 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when archiving experiment' do
|
|
|
|
let(:archived_experiment) do
|
|
|
|
create :experiment,
|
|
|
|
archived: true,
|
|
|
|
archived_by: (create :user),
|
|
|
|
archived_on: Time.now,
|
|
|
|
project: project
|
|
|
|
end
|
|
|
|
|
2019-03-13 16:06:48 +08:00
|
|
|
let(:params) do
|
2019-03-07 00:18:35 +08:00
|
|
|
{
|
|
|
|
id: archived_experiment.id,
|
|
|
|
experiment: { archived: false }
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls create activity for unarchiving experiment' do
|
|
|
|
expect(Activities::CreateActivityService)
|
|
|
|
.to(receive(:call)
|
|
|
|
.with(hash_including(activity_type: :restore_experiment)))
|
|
|
|
|
2019-03-13 16:06:48 +08:00
|
|
|
action
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
2019-03-07 00:18:35 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-03-05 18:39:57 +08:00
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
describe 'GET archive' do
|
|
|
|
let(:action) { get :archive, params: params, format: :json }
|
2019-03-05 18:39:57 +08:00
|
|
|
let(:params) do
|
|
|
|
{ id: experiment.id,
|
2019-03-21 04:34:47 +08:00
|
|
|
experiment: { archived: false } }
|
2019-03-05 18:39:57 +08:00
|
|
|
end
|
|
|
|
it 'calls create activity service' do
|
|
|
|
expect(Activities::CreateActivityService).to receive(:call)
|
|
|
|
.with(hash_including(activity_type: :archive_experiment))
|
|
|
|
|
2019-03-27 18:24:44 +08:00
|
|
|
action
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds activity in DB' do
|
|
|
|
expect { action }
|
|
|
|
.to(change { Activity.count })
|
2019-03-05 18:39:57 +08:00
|
|
|
end
|
|
|
|
end
|
2019-03-07 00:18:35 +08:00
|
|
|
end
|