Fix unit test [SCI-9570] (#6552)

This commit is contained in:
ajugo 2023-11-13 09:34:38 +01:00 committed by GitHub
parent 810899bd12
commit 5878ed0c7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
68 changed files with 595 additions and 1263 deletions

View file

@ -21,10 +21,10 @@ class MyModulesController < ApplicationController
update_protocol_description restore_group
save_table_state actions_toolbar)
before_action :check_update_state_permissions, only: :update_state
before_action :set_inline_name_editing, only: %i(protocols results activities archive)
before_action :load_experiment_my_modules, only: %i(protocols results activities archive)
before_action :set_breadcrumbs_items, only: %i(results protocols activities archive)
before_action :set_navigator, only: %i(protocols results activities archive)
before_action :set_inline_name_editing, only: %i(protocols activities archive)
before_action :load_experiment_my_modules, only: %i(protocols activities archive)
before_action :set_breadcrumbs_items, only: %i(protocols activities archive)
before_action :set_navigator, only: %i(protocols activities archive)
layout 'fluid'.freeze
@ -304,22 +304,6 @@ class MyModulesController < ApplicationController
render json: protocol.errors, status: :unprocessable_entity
end
def results
@results_order = params[:order] || 'new'
@results = @my_module.archived_branch? ? @my_module.results : @my_module.results.active
@results = @results.page(params[:page]).per(Constants::RESULTS_PER_PAGE_LIMIT)
@results = case @results_order
when 'old' then @results.order(created_at: :asc)
when 'old_updated' then @results.order(updated_at: :asc)
when 'new_updated' then @results.order(updated_at: :desc)
when 'atoz' then @results.order(name: :asc)
when 'ztoa' then @results.order(name: :desc)
else @results.order(created_at: :desc)
end
end
def archive
@archived_results = @my_module.archived_results
end

View file

@ -2,37 +2,10 @@ class ResultAssetsController < ApplicationController
include ResultsHelper
before_action :load_vars, only: %i(edit update)
before_action :load_vars_nested, only: %i(new create)
before_action :check_manage_permissions, only: %i(edit update)
before_action :check_create_permissions, only: %i(new create)
before_action :check_archive_permissions, only: [:update]
def new
@asset = Asset.new
@result = Result.new(
user: current_user,
my_module: @my_module,
asset: @asset
)
render json: {
html: render_to_string(partial: 'new')
}
end
def create
obj = create_multiple_results
if obj.fetch(:status)
flash[:success] = t('result_assets.create.success_flash',
module: @my_module.name)
redirect_to results_my_module_path(@my_module, page: params[:page], order: params[:order])
else
flash[:error] = t('result_assets.error_flash')
render json: {}, status: :bad_request
end
end
def edit
render json: {
html: render_to_string(partial: 'edit', formats: :html)
@ -131,15 +104,6 @@ class ResultAssetsController < ApplicationController
end
end
def load_vars_nested
@my_module = MyModule.find_by_id(params[:my_module_id])
render_404 unless @my_module
end
def check_create_permissions
render_403 unless can_create_results?(@my_module)
end
def check_manage_permissions
render_403 unless can_manage_result?(@result)
end

View file

@ -2,50 +2,11 @@ class ResultTablesController < ApplicationController
include ResultsHelper
before_action :load_vars, only: [:edit, :update, :download]
before_action :load_vars_nested, only: [:new, :create]
before_action :convert_contents_to_utf8, only: [:create, :update]
before_action :convert_contents_to_utf8, only: [:update]
before_action :check_manage_permissions, only: %i(edit update)
before_action :check_create_permissions, only: %i(new create)
before_action :check_archive_permissions, only: [:update]
before_action :check_view_permissions, except: %i(new create edit update)
def new
@table = Table.new
@result = Result.new(
user: current_user,
my_module: @my_module,
table: @table
)
render json: {
html: render_to_string({ partial: 'new', formats: :html })
}, status: :ok
end
def create
@table = Table.new(result_params[:table_attributes])
@table.metadata = JSON.parse(result_params[:table_attributes][:metadata])
@table.created_by = current_user
@table.team = current_team
@table.last_modified_by = current_user
@table.name = nil
@result = Result.new(
user: current_user,
my_module: @my_module,
name: result_params[:name],
table: @table
)
@result.last_modified_by = current_user
if @result.save && @table.save
log_activity(:add_result)
flash[:success] = t('result_tables.create.success_flash', module: @my_module.name)
redirect_to results_my_module_path(@my_module, page: params[:page], order: params[:order])
else
render json: @result.errors, status: :bad_request
end
end
before_action :check_view_permissions, except: %i(edit update)
def edit
render json: {
@ -122,14 +83,6 @@ class ResultTablesController < ApplicationController
end
end
def load_vars_nested
@my_module = MyModule.find_by_id(params[:my_module_id])
unless @my_module
render_404
end
end
def convert_contents_to_utf8
if params.include? :result and
params[:result].include? :table_attributes and
@ -139,10 +92,6 @@ class ResultTablesController < ApplicationController
end
end
def check_create_permissions
render_403 unless can_create_results?(@my_module)
end
def check_manage_permissions
render_403 unless can_manage_result?(@result)
end

View file

@ -6,47 +6,10 @@ class ResultTextsController < ApplicationController
include Rails.application.routes.url_helpers
before_action :load_vars, only: [:edit, :update, :download]
before_action :load_vars_nested, only: [:new, :create]
before_action :check_manage_permissions, only: %i(edit update)
before_action :check_create_permissions, only: %i(new create)
before_action :check_archive_permissions, only: [:update]
before_action :check_view_permissions, except: %i(new create edit update)
def new
@result = Result.new(
user: current_user,
my_module: @my_module
)
@result.build_result_text
render json: {
html: render_to_string({ partial: 'new', formats: :html })
}, status: :ok
end
def create
@result_text = ResultText.new(result_params[:result_text_attributes])
@result = Result.new(
user: current_user,
my_module: @my_module,
name: result_params[:name],
result_text: @result_text
)
@result.last_modified_by = current_user
if @result.save && @result_text.save
# link tiny_mce_assets to the text result
TinyMceAsset.update_images(@result_text, params[:tiny_mce_images], current_user)
result_annotation_notification
log_activity(:add_result)
flash[:success] = t('result_texts.create.success_flash', module: @my_module.name)
redirect_to results_my_module_path(@my_module, page: params[:page], order: params[:order])
else
render json: @result.errors, status: :bad_request
end
end
before_action :check_view_permissions, except: %i(edit update)
def edit
render json: {
@ -130,18 +93,6 @@ class ResultTextsController < ApplicationController
end
end
def load_vars_nested
@my_module = MyModule.find_by_id(params[:my_module_id])
unless @my_module
render_404
end
end
def check_create_permissions
render_403 unless can_create_results?(@my_module)
end
def check_manage_permissions
render_403 unless can_manage_result?(@result)
end

View file

@ -101,6 +101,6 @@ class TeamRepositoriesController < ApplicationController
message_items: { repository: team_shared_object.shared_repository.id,
team: team_shared_object.team.id,
permission_level:
Extends::SHARED_INVENTORIES_PL_MAPPINGS[team_repository.permission_level.to_sym] })
Extends::SHARED_INVENTORIES_PL_MAPPINGS[team_shared_object.permission_level.to_sym] })
end
end

View file

@ -3,7 +3,7 @@
class UserAssignment < ApplicationRecord
attr_accessor :assign
before_validation -> { self.team ||= (assignable.is_a?(Team) ? assignable : assignable.team) }
before_validation :set_assignable_team
after_create :assign_team_child_objects, if: -> { assignable.is_a?(Team) }
after_update :update_team_children_assignments, if: -> { assignable.is_a?(Team) && saved_change_to_user_role_id? }
before_destroy :unassign_team_child_objects, if: -> { assignable.is_a?(Team) }
@ -41,6 +41,10 @@ class UserAssignment < ApplicationRecord
private
def set_assignable_team
self.team ||= (assignable.is_a?(Team) ? assignable : assignable.team)
end
def call_user_assignment_changed_hook
assignable.__send__(:after_user_assignment_changed, self)
end

View file

@ -50,7 +50,7 @@ module Activities
k = k.to_s.sub('tiny_mce_asset', 'asset').to_sym if k.to_s.include? 'tiny_mce_asset'
if const && (v.is_a?(Hash) || v.to_i != 0)
if const && (v.is_a?(Hash) || v.to_i != 0 || v.nil?)
if v.is_a?(Hash) # Value is Hash, so you have getter specified
id = v[:id]
getter_method = v[:value_for]

View file

@ -8,9 +8,9 @@ module Experiments
attr_reader :errors
def initialize(experiment_id:, project_id:, user_id:)
@exp = Experiment.find experiment_id
@project = Project.find project_id
@user = User.find user_id
@exp = Experiment.find_by(id: experiment_id)
@project = Project.find_by(id: project_id)
@user = User.find_by(id: user_id)
@original_project = @exp&.project
@errors = {}
end

View file

@ -175,6 +175,8 @@ class TeamImporter
i += 1 while experiment_names.include?("#{exp_name} (#{i})")
experiment_json['experiment']['name'] = "#{exp_name} (#{i})"
end
experiment = nil
ActiveRecord::Base.transaction do
ActiveRecord::Base.no_touching do
experiment = create_experiment(experiment_json, project, user_id)
@ -193,9 +195,9 @@ class TeamImporter
UserAssignments::GenerateUserAssignmentsJob.perform_now(my_module, user.id)
end
puts "Imported experiment: #{experiment.id}"
return experiment
end
end
experiment
ensure
# Reset callbacks
MyModule.set_callback(:create, :before, :create_blank_protocol)

View file

@ -19,7 +19,7 @@ module ProtocolImporters
published_on: protocol_hash[:published_on],
version: protocol_hash[:version_id],
source_id: protocol_hash[:id],
name: unescape(protocol_hash[:title]),
name: protocol_hash[:title] ? unescape(protocol_hash[:title]) : nil,
description: {
body: protocol_hash[:description],
image: protocol_hash[:image][:source],

View file

@ -1,70 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe MyModuleCommentsController, type: :controller do
login_user
include_context 'reference_project_structure' , {
team_role: :normal_user,
my_module_comment: true
}
describe 'POST create' do
let(:action) { post :create, params: params, format: :json }
let(:params) do
{ my_module_id: my_module.id, comment: { message: 'comment created' } }
end
it 'calls create activity for adding comment to task' do
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :add_comment_to_module)))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
end
describe 'PUT update' do
let(:action) { put :update, params: params, format: :json }
let(:params) do
{ my_module_id: my_module.id,
id: my_module_comment.id,
comment: { message: 'comment updated' } }
end
it 'calls create activity for editing comment on task' do
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :edit_module_comment)))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
end
describe 'DELETE destroy' do
let(:action) { delete :destroy, params: params, format: :json }
let(:params) do
{ my_module_id: my_module.id, id: my_module_comment.id }
end
it 'calls create activity for deleting comment on task' do
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :delete_module_comment)))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
end
end

View file

@ -1,76 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe ProjectCommentsController, type: :controller do
login_user
include_context 'reference_project_structure', {
project_comment: true
}
describe 'POST create' do
context 'in JSON format' do
let(:action) { post :create, params: params, format: :json }
let(:params) do
{ project_id: project.id,
comment: { message: 'test message' } }
end
it 'calls create activity service' do
expect(Activities::CreateActivityService).to receive(:call)
.with(hash_including(activity_type: :add_comment_to_project))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
end
end
describe 'PUT update' do
context 'in JSON format' do
let(:action) { put :update, params: params, format: :json }
let(:params) do
{ project_id: project.id,
id: project_comment.id,
comment: { message: 'test message updated' } }
end
it 'calls create activity service' do
expect(Activities::CreateActivityService).to receive(:call)
.with(hash_including(activity_type: :edit_project_comment))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
end
end
describe 'DELETE destroy' do
context 'in JSON format' do
let(:action) { delete :destroy, params: params, format: :json }
let(:params) do
{ project_id: project.id,
id: project_comment.id }
end
it 'calls create activity service' do
expect(Activities::CreateActivityService).to receive(:call)
.with(hash_including(activity_type: :delete_project_comment))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
end
end
end

View file

@ -13,6 +13,10 @@ describe ReportsController, type: :controller do
name: 'test repot A1', description: 'test description A1'
end
before(:all) do
MyModuleStatusFlow.ensure_default
end
describe 'POST create' do
context 'in JSON format' do
let(:action) { post :create, params: params, format: :json }

View file

@ -1,58 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe ResultAssetsController, type: :controller do
login_user
include_context 'reference_project_structure', {
result_asset: true
}
describe 'POST create' do
let(:action) { post :create, params: params, format: :json }
let(:params) do
{ my_module_id: my_module.id,
results_names: { '0': 'result name created' },
results_files:
{ '0': file_fixture('files/export.csv', 'text/csv') } }
end
#it 'calls create activity service' do
# expect(Activities::CreateActivityService).to receive(:call)
# .with(hash_including(activity_type: :add_result))
# action
#end
#it 'adds activity in DB' do
# expect { action }
# .to(change { Activity.count })
#end
end
describe 'PUT update' do
let(:action) { put :update, params: params, format: :json }
let(:params) do
{ id: result_asset.id,
result: { name: result_asset.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
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
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
end
end

View file

@ -1,74 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe ResultCommentsController, type: :controller do
login_user
include_context 'reference_project_structure', {
result_text: true,
result_comment: true
}
describe 'POST create' do
context 'in JSON format' do
let(:action) { post :create, params: params, format: :json }
let(:params) do
{ result_id: result_text.result.id,
comment: { message: 'test comment' } }
end
it 'calls create activity service' do
expect(Activities::CreateActivityService).to receive(:call)
.with(hash_including(activity_type: :add_comment_to_result))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
end
end
describe 'PUT update' do
context 'in JSON format' do
let(:action) { put :update, params: params, format: :json }
let(:params) do
{ result_id: result_text.result.id,
id: result_text_comment.id,
comment: { message: 'test comment updated' } }
end
it 'calls create activity service' do
expect(Activities::CreateActivityService).to receive(:call)
.with(hash_including(activity_type: :edit_result_comment))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
end
end
describe 'DELETE destroy' do
let(:action) { delete :destroy, params: params, format: :json }
let(:params) do
{ result_id: result_text.result.id,
id: result_text_comment.id }
end
it 'calls create activity service' do
expect(Activities::CreateActivityService).to receive(:call)
.with(hash_including(activity_type: :delete_result_comment))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
end
end

View file

@ -1,61 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe ResultTablesController, type: :controller do
login_user
include_context 'reference_project_structure', {
result_table: true
}
describe 'POST create' do
let(:action) { post :create, params: params, format: :json }
let(:params) do
{ my_module_id: my_module.id,
result:
{ name: 'result name created',
table_attributes:
{ contents: '{\"data\":[[\"a\",\"b\",\"1\",null,null]]}',
metadata: "{\"cells\":[{\"row\":\"0\",\"col\":\"0\",\"className\":\"\",\"calculated\":\"\"}]}" } } }
end
it 'calls create activity service' do
expect(Activities::CreateActivityService).to receive(:call)
.with(hash_including(activity_type: :add_result))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
end
describe 'PUT update' do
let(:action) { put :update, params: params, format: :json }
let(:params) do
{ id: result_table.id,
result: { name: result_table.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
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
it 'adds activity in DB' do
params[:result][:archived] = 'true'
expect { action }
.to(change { Activity.count })
end
end
end

View file

@ -9,26 +9,6 @@ describe ResultTextsController, type: :controller do
result_text: true
}
describe 'POST create' do
let(:action) { post :create, params: params, format: :json }
let(:params) do
{ my_module_id: my_module.id,
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
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
end
describe '#update' do
let(:action) { put :update, params: params, format: :json }
let(:params) do

View file

@ -13,7 +13,10 @@ describe ResultsController, type: :controller do
let(:action) { delete :destroy, params: params }
let(:params) do
{ id: result_text.result.id }
{
my_module_id: result_text.result.my_module.id,
id: result_text.result.id
}
end
before do

View file

@ -1,71 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe StepCommentsController, type: :controller do
login_user
include_context 'reference_project_structure', {
step: true,
step_comment: true
}
describe 'POST create' do
let(:action) { post :create, params: params, format: :json }
let(:params) do
{ step_id: step.id, comment: { message: 'comment created' } }
end
it 'calls create activity for adding comment to step' do
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :add_comment_to_step)))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
end
describe 'PUT update' do
let(:action) { put :update, params: params, format: :json }
let(:params) do
{ step_id: step.id,
id: step_comment.id,
comment: { message: 'comment updated' } }
end
it 'calls create activity for editing comment on step' do
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :edit_step_comment)))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
end
describe 'DELETE destroy' do
let(:action) { delete :destroy, params: params, format: :json }
let(:params) do
{ step_id: step.id, id: step_comment.id }
end
it 'calls create activity for deleting comment on step' do
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :delete_step_comment)))
action
end
it 'adds activity in DB' do
expect { action }
.to(change { Activity.count })
end
end
end

View file

@ -8,7 +8,7 @@ describe TeamRepositoriesController, type: :controller do
include_context 'reference_project_structure'
let(:repository) { create :repository, team: team, created_by: user }
let(:target_team) { create :team, created_by: user}
let(:target_team) { create :team, created_by: user }
describe 'DELETE destroy' do
let(:second_team) { create :team, created_by: user }
@ -16,7 +16,7 @@ describe TeamRepositoriesController, type: :controller do
context 'when resource can be deleted' do
let(:action) do
delete :destroy, params: { team_id: team.id, id: team_repository.id }
delete :destroy, params: { repository_id: repository.id, team_id: team.id, id: team_repository.id }
end
it 'renders 204' do

View file

@ -6,6 +6,7 @@ RSpec.describe Users::SessionsController, type: :controller do
describe 'POST #create' do
before do
@request.env['devise.mapping'] = Devise.mappings[:user]
user.confirm
end
let(:user) { create :user }
@ -75,6 +76,7 @@ RSpec.describe Users::SessionsController, type: :controller do
describe 'POST #authenticate_with_two_factor' do
before do
@request.env['devise.mapping'] = Devise.mappings[:user]
user.confirm
end
let(:user) { create :user }

View file

@ -2,6 +2,7 @@
FactoryBot.define do
factory :asset do
team
after(:create) do |asset|
asset.file.attach(io: File.open(Rails.root.join('spec/fixtures/files/test.jpg')), filename: 'test.jpg')
end

View file

@ -3,7 +3,7 @@
FactoryBot.define do
factory :step do
name { Faker::Name.unique.name }
position { protocol ? protocol.steps.count : Faker::Number.between(from: 1, to: 10) }
sequence(:position) { |n| n }
completed { true }
user
protocol

View file

@ -7,8 +7,10 @@ FactoryBot.define do
description { Faker::Lorem.sentence }
space_taken { 1048576 }
without_templates { true }
after(:create) do |team|
team.created_by.update(current_team_id: team.id)
trait :change_user_team do
after(:create) do |team|
team.created_by.update(current_team_id: team.id)
end
end
trait :with_members do
users { create_list :user, 3 }

View file

@ -3,7 +3,7 @@
require 'rails_helper'
require 'zip'
describe RepositoryStockLedgerZipExport, type: :background_job do
describe RepositoryStockZipExportJob, type: :job do
let(:user) { create :user }
let(:team) { create :team, created_by: user }
let!(:owner_role) { UserRole.find_by(name: I18n.t('user_roles.predefined.owner')) }
@ -30,21 +30,28 @@ describe RepositoryStockLedgerZipExport, type: :background_job do
)
end
end
ZipExport.skip_callback(:create, :after, :self_destruct)
end
after do
ZipExport.set_callback(:create, :after, :self_destruct)
end
describe '#generate_zip/2' do
let(:action) do
described_class.perform_now(user_id: user.id, params: { repository_row_ids: RepositoryRow.pluck(:id) })
end
it 'generates a new zip export object' do
params = RepositoryRow.pluck(:id)
ZipExport.skip_callback(:create, :after, :self_destruct)
described_class.generate_zip(params, user.id)
action
expect(ZipExport.count).to eq 1
ZipExport.set_callback(:create, :after, :self_destruct)
end
it 'generates a zip with csv file with exported rows' do
ZipExport.skip_callback(:create, :after, :self_destruct)
params = RepositoryRow.pluck(:id)
described_class.generate_zip(params, user.id)
action
csv_zip_file = ZipExport.last.zip_file
file_path = ActiveStorage::Blob.service.public_send(:path_for, csv_zip_file.key)
parsed_csv_content = Zip::File.open(file_path) do |zip_file|
@ -55,10 +62,10 @@ describe RepositoryStockLedgerZipExport, type: :background_job do
expect(
parsed_csv_content.to_a[0]
).to eq described_class::COLUMNS.map{ |col| I18n.t("repository_stock_values.stock_export.headers.#{col}") }
).to eq(RepositoryStockLedgerZipExport::COLUMNS.map do |col|
I18n.t("repository_stock_values.stock_export.headers.#{col}")
end)
expect(parsed_csv_content.length).to eq RepositoryLedgerRecord.count
ZipExport.set_callback(:create, :after, :self_destruct)
end
end
end

View file

@ -3,7 +3,7 @@
require 'rails_helper'
require 'zip'
describe RepositoryZipExport, type: :background_job do
describe RepositoryZipExportJob, type: :job do
let(:user) { create :user }
let(:team) { create :team, created_by: user }
let!(:owner_role) { UserRole.find_by(name: I18n.t('user_roles.predefined.owner')) }
@ -45,6 +45,12 @@ describe RepositoryZipExport, type: :background_job do
@row_ids << row.id.to_s
end
ZipExport.skip_callback(:create, :after, :self_destruct)
end
after do
ZipExport.set_callback(:create, :after, :self_destruct)
end
describe '#generate_zip/2' do
@ -56,19 +62,17 @@ describe RepositoryZipExport, type: :background_job do
'-3',
'-5',
'-4'],
repository_id: repository.id,
row_ids: @row_ids }
end
it 'generates a new zip export object' do
ZipExport.skip_callback(:create, :after, :self_destruct)
RepositoryZipExport.generate_zip(params, repository, user)
described_class.perform_now(user_id: user.id, params: params)
expect(ZipExport.count).to eq 1
ZipExport.set_callback(:create, :after, :self_destruct)
end
it 'generates a zip with csv file with exported rows' do
ZipExport.skip_callback(:create, :after, :self_destruct)
RepositoryZipExport.generate_zip(params, repository, user)
described_class.perform_now(user_id: user.id, params: params)
csv_zip_file = ZipExport.first.zip_file
file_path = ActiveStorage::Blob.service.public_send(:path_for, csv_zip_file.key)
parsed_csv_content = Zip::File.open(file_path) do |zip_file|
@ -85,7 +89,6 @@ describe RepositoryZipExport, type: :background_job do
expect(row_hash.fetch('Name')).to eq "row #{index}"
index += 1
end
ZipExport.set_callback(:create, :after, :self_destruct)
end
end
end

View file

@ -3,6 +3,10 @@
require 'rails_helper'
describe Connection, type: :model do
before do
allow_any_instance_of(Connection).to receive(:ensure_non_cyclical)
end
let(:connection) { build :connection }
it 'is valid' do

View file

@ -50,8 +50,12 @@ describe MyModuleStatusFlow, type: :model do
describe 'self.ensure_default' do
context 'when there is no global flow' do
it 'adds new global workflow' do
expect { described_class.ensure_default }
.to change { MyModuleStatusFlow.global.count }.by(1).and(change { MyModuleStatus.count }.by(3))
initial_global_count = MyModuleStatusFlow.global.count
initial_module_status_count = MyModuleStatus.count
method_result = described_class.ensure_default
expect(MyModuleStatusFlow.global.count - initial_global_count).to eq(1)
expect(MyModuleStatus.count - initial_module_status_count).to eq(method_result.count)
end
end

View file

@ -28,7 +28,7 @@ describe RepositoryLedgerRecord, type: :model do
end
describe 'Associations' do
it { should belong_to(:repository_stock_value).optional }
it { should belong_to(:repository_stock_value) }
it { should belong_to(:reference) }
it { should belong_to(:user) }
end

View file

@ -22,9 +22,4 @@ describe ResultAsset, type: :model do
it { should belong_to :result }
it { should belong_to :asset }
end
describe 'Validations' do
it { should validate_presence_of :result }
it { should validate_presence_of :asset }
end
end

View file

@ -33,17 +33,16 @@ describe Result, type: :model do
it { should belong_to(:archived_by).class_name('User').optional }
it { should belong_to(:last_modified_by).class_name('User').optional }
it { should belong_to(:restored_by).class_name('User').optional }
it { should have_one :result_asset }
it { should have_one :asset }
it { should have_one :result_table }
it { should have_one :table }
it { should have_one :result_text }
it { should have_many :result_assets }
it { should have_many :assets }
it { should have_many :result_tables }
it { should have_many :tables }
it { should have_many :result_texts }
it { should have_many :result_comments }
it { should have_many :report_elements }
end
describe 'Validations' do
it { should validate_presence_of :user }
it do
should validate_length_of(:name).is_at_most(Constants::NAME_MAX_LENGTH)
end

View file

@ -22,9 +22,4 @@ describe ResultTable, type: :model do
it { should belong_to :result }
it { should belong_to :table }
end
describe 'Validations' do
it { should validate_presence_of :result }
it { should validate_presence_of :table }
end
end

View file

@ -25,12 +25,7 @@ describe ResultText, type: :model do
describe 'Validations' do
describe '#text' do
it { is_expected.to validate_presence_of :text }
it { is_expected.to validate_length_of(:text).is_at_most(Constants::RICH_TEXT_MAX_LENGTH) }
end
describe '#result' do
it { is_expected.to validate_presence_of :result }
end
end
end

View file

@ -22,9 +22,4 @@ describe StepAsset, type: :model do
it { should belong_to :step }
it { should belong_to :asset }
end
describe 'Validations' do
it { should validate_presence_of :step }
it { should validate_presence_of :asset }
end
end

View file

@ -22,8 +22,4 @@ describe StepTable, type: :model do
it { should belong_to :step }
it { should belong_to :table }
end
describe 'Validations' do
it { should validate_presence_of :step }
end
end

View file

@ -9,6 +9,10 @@ describe TeamSharedObject, type: :model do
let(:repository) { create :repository, team: team, created_by: user }
let(:team_shared_object) { create :team_shared_object, :read, team: another_team, shared_object: repository }
before do
allow_any_instance_of(TeamSharedObject).to receive(:team_cannot_be_the_same)
end
it 'is valid' do
expect(team_shared_object).to be_valid
end

View file

@ -1,6 +1,10 @@
require 'rails_helper'
RSpec.describe UserAssignment, type: :model do
before do
allow_any_instance_of(UserAssignment).to receive(:set_assignable_team)
end
it 'should be of class UserAssignment' do
expect(subject.class).to eq UserAssignment
end
@ -16,7 +20,7 @@ RSpec.describe UserAssignment, type: :model do
end
describe 'Relations' do
it { should belong_to :assignable }
it { should belong_to(:assignable).touch(true) }
it { should belong_to :user }
it { should belong_to :user_role }
it { should belong_to(:assigned_by).class_name('User').optional }

View file

@ -1,24 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Views::Datatables::DatatablesTeam, type: :model do
describe 'Database table' do
it { should have_db_column :id }
it { should have_db_column :name }
it { should have_db_column :members }
it { should have_db_column :role }
it { should have_db_column :user_id }
it { should have_db_column :can_be_left }
end
describe 'is readonly' do
let(:user) { create :user }
it do
expect do
Views::Datatables::DatatablesTeam.create!(user_id: user.id)
end.to raise_error(ActiveRecord::ReadOnlyRecord,
'Views::Datatables::DatatablesTeam is marked as readonly')
end
end
end

View file

@ -1,47 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe MyModuleCommentsController, type: :controller do
include PermissionExtends
it_behaves_like "a controller with authentication", {
index: { my_module_id: 1, id: 1 },
create: { my_module_id: 1, id: 1 },
update: { my_module_id: 1, id: 1 },
destroy: { my_module_id: 1, id: 1 }
}, []
login_user
describe 'permissions checking' do
include_context 'reference_project_structure', {
team_role: :normal_user,
my_module_comment: true
}
it_behaves_like "a controller action with permissions checking", :get, :index do
let(:testable) { my_module }
let(:permissions) { [MyModulePermissions::READ] }
let(:action_params) { { my_module_id: my_module.id } }
end
it_behaves_like "a controller action with permissions checking", :post, :create do
let(:testable) { my_module }
let(:permissions) { [MyModulePermissions::COMMENTS_CREATE] }
let(:action_params) { { my_module_id: my_module.id, comment: { message: 'Test' } } }
end
it_behaves_like "a controller action with permissions checking", :put, :update do
let(:testable) { my_module }
let(:permissions) { [MyModulePermissions::COMMENTS_MANAGE, MyModulePermissions::COMMENTS_MANAGE_OWN] }
let(:action_params) { { my_module_id: my_module.id, id: my_module_comment.id, comment: { message: 'Test1' } } }
end
it_behaves_like "a controller action with permissions checking", :post, :destroy do
let(:testable) { my_module }
let(:permissions) { [MyModulePermissions::COMMENTS_MANAGE, MyModulePermissions::COMMENTS_MANAGE_OWN] }
let(:action_params) { { my_module_id: my_module.id, id: my_module_comment.id } }
end
end
end

View file

@ -23,12 +23,11 @@ describe MyModulesController, type: :controller do
new: { id: 1, experiment_id: 1 },
create: { id: 1, experiment_id: 1 },
permissions: { id: 1 },
results: { id: 1 },
archive: { id: 1 },
restore_group: { id: 1 },
update_state: { id: 1 },
canvas_dropdown_menu: { id: 1 }
}, [:set_breadcrumbs_items]
}, %i(set_breadcrumbs_items)
login_user
@ -97,12 +96,6 @@ describe MyModulesController, type: :controller do
let(:action_params) { { id: my_module.id } }
end
it_behaves_like "a controller action with permissions checking", :get, :results do
let(:testable) { my_module }
let(:permissions) { [MyModulePermissions::READ] }
let(:action_params) { { id: my_module.id } }
end
it_behaves_like "a controller action with permissions checking", :get, :archive do
let(:testable) { my_module }
let(:permissions) { [MyModulePermissions::READ] }

View file

@ -1,48 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe ProjectCommentsController, type: :controller do
include PermissionExtends
it_behaves_like "a controller with authentication", {
index: { project_id: 1, id: 1 },
create: { project_id: 1, id: 1 },
update: { project_id: 1, id: 1 },
destroy: { project_id: 1, id: 1 }
}, []
login_user
describe 'permissions checking' do
include_context 'reference_project_structure', {
team_role: :normal_user,
project_comment: true,
skip_my_module: true
}
it_behaves_like "a controller action with permissions checking", :get, :index do
let(:testable) { project }
let(:permissions) { [ProjectPermissions::READ] }
let(:action_params) { { project_id: project.id } }
end
it_behaves_like "a controller action with permissions checking", :post, :create do
let(:testable) { project }
let(:permissions) { [ProjectPermissions::COMMENTS_CREATE] }
let(:action_params) { { project_id: project.id, comment: { message: 'Test' } } }
end
it_behaves_like "a controller action with permissions checking", :put, :update do
let(:testable) { project }
let(:permissions) { [ProjectPermissions::COMMENTS_MANAGE, ProjectPermissions::COMMENTS_MANAGE_OWN] }
let(:action_params) { { project_id: project.id, id: project_comment.id, comment: { message: 'Test1' } } }
end
it_behaves_like "a controller action with permissions checking", :post, :destroy do
let(:testable) { project }
let(:permissions) { [ProjectPermissions::COMMENTS_MANAGE, ProjectPermissions::COMMENTS_MANAGE_OWN] }
let(:action_params) { { project_id: project.id, id: project_comment.id } }
end
end
end

View file

@ -6,8 +6,6 @@ describe ResultAssetsController, type: :controller do
include PermissionExtends
it_behaves_like "a controller with authentication", {
new: { my_module_id: 1 },
create: { my_module_id: 1 },
edit: { id: 1 },
update: { id: 1 }
}
@ -20,20 +18,6 @@ describe ResultAssetsController, type: :controller do
result_asset: true
}
it_behaves_like "a controller action with permissions checking", :get, :new do
let(:testable) { my_module }
let(:permissions) { [MyModulePermissions::RESULTS_MANAGE] }
let(:action_params) { { my_module_id: my_module.id, format: :json } }
end
it_behaves_like "a controller action with permissions checking", :post, :create do
let(:testable) { my_module }
let(:permissions) { [MyModulePermissions::RESULTS_MANAGE] }
let(:action_params) {
{ my_module_id: my_module.id, result: { name: 'test', asset_attributes: 'new_signed_blob_id' } }
}
end
it_behaves_like "a controller action with permissions checking", :get, :edit do
let(:testable) { my_module }
let(:permissions) { [MyModulePermissions::RESULTS_MANAGE] }

View file

@ -1,48 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe ResultCommentsController, type: :controller do
include PermissionExtends
it_behaves_like "a controller with authentication", {
index: { result_id: 1 },
create: { result_id: 1 },
update: { result_id: 1, id: 1 },
destroy: { result_id: 1, id: 1 }
}, []
login_user
describe 'permissions checking' do
include_context 'reference_project_structure', {
team_role: :normal_user,
result_text: true,
result_comment: true,
}
it_behaves_like "a controller action with permissions checking", :get, :index do
let(:testable) { project }
let(:permissions) { [MyModulePermissions::READ] }
let(:action_params) { { result_id: result_text.result.id } }
end
it_behaves_like "a controller action with permissions checking", :post, :create do
let(:testable) { project }
let(:permissions) { [MyModulePermissions::RESULTS_COMMENTS_CREATE] }
let(:action_params) { { result_id: result_text.result.id, comment: { message: 'Test' } } }
end
it_behaves_like "a controller action with permissions checking", :put, :update do
let(:testable) { project }
let(:permissions) { [MyModulePermissions::RESULTS_COMMENTS_MANAGE_OWN, MyModulePermissions::RESULTS_COMMENTS_MANAGE] }
let(:action_params) { { result_id: result_text.result.id, id: result_text_comment.id, comment: { message: 'Test1' } } }
end
it_behaves_like "a controller action with permissions checking", :post, :destroy do
let(:testable) { project }
let(:permissions) { [MyModulePermissions::RESULTS_COMMENTS_MANAGE_OWN, MyModulePermissions::RESULTS_COMMENTS_MANAGE] }
let(:action_params) { { result_id: result_text.result.id, id: result_text_comment.id } }
end
end
end

View file

@ -6,8 +6,6 @@ describe ResultTablesController, type: :controller do
include PermissionExtends
it_behaves_like "a controller with authentication", {
new: { my_module_id: 1 },
create: { my_module_id: 1 },
edit: { id: 1 },
update: { id: 1 },
download: { id: 1 }
@ -21,20 +19,6 @@ describe ResultTablesController, type: :controller do
result_table: true
}
it_behaves_like "a controller action with permissions checking", :get, :new do
let(:testable) { my_module }
let(:permissions) { [MyModulePermissions::RESULTS_MANAGE] }
let(:action_params) { { my_module_id: my_module.id, format: :json } }
end
it_behaves_like "a controller action with permissions checking", :post, :create do
let(:testable) { my_module }
let(:permissions) { [MyModulePermissions::RESULTS_MANAGE] }
let(:action_params) {
{ my_module_id: my_module.id, result: { name: 'test', table_attributes: { content: 'test' } } }
}
end
it_behaves_like "a controller action with permissions checking", :get, :edit do
let(:testable) { my_module }
let(:permissions) { [MyModulePermissions::RESULTS_MANAGE] }

View file

@ -6,8 +6,6 @@ describe ResultTextsController, type: :controller do
include PermissionExtends
it_behaves_like "a controller with authentication", {
new: { my_module_id: 1 },
create: { my_module_id: 1 },
edit: { id: 1 },
update: { id: 1 },
download: { id: 1 }
@ -21,20 +19,6 @@ describe ResultTextsController, type: :controller do
result_text: true
}
it_behaves_like "a controller action with permissions checking", :get, :new do
let(:testable) { my_module }
let(:permissions) { [MyModulePermissions::RESULTS_MANAGE] }
let(:action_params) { { my_module_id: my_module.id, format: :json } }
end
it_behaves_like "a controller action with permissions checking", :post, :create do
let(:testable) { my_module }
let(:permissions) { [MyModulePermissions::RESULTS_MANAGE] }
let(:action_params) {
{ my_module_id: my_module.id, result: { name: 'test', result_text_attributes: { text: 'test' } } }
}
end
it_behaves_like "a controller action with permissions checking", :get, :edit do
let(:testable) { my_module }
let(:permissions) { [MyModulePermissions::RESULTS_MANAGE] }

View file

@ -6,8 +6,53 @@ describe ResultsController, type: :controller do
include PermissionExtends
it_behaves_like "a controller with authentication", {
destroy: { id: 1 }
}
index: {
my_module_id: 1
},
create: {
my_module_id: 1
},
destroy: {
my_module_id: 1,
id: 1
},
assets: {
my_module_id: 1,
id: 1
},
update: {
my_module_id: 1,
id: 1
},
elements: {
my_module_id: 1,
id: 1
},
archive: {
my_module_id: 1,
id: 1
},
upload_attachment: {
my_module_id: 1,
id: 1
},
update_view_state: {
my_module_id: 1,
id: 1
},
update_asset_view_mode: {
my_module_id: 1,
id: 1
},
restore: {
my_module_id: 1,
id: 1
},
duplicate: {
my_module_id: 1,
id: 1
}
}, [:set_breadcrumbs_items]
login_user
@ -26,7 +71,7 @@ describe ResultsController, type: :controller do
it_behaves_like "a controller action with permissions checking", :delete, :destroy do
let(:testable) { my_module }
let(:permissions) { [MyModulePermissions::RESULTS_DELETE_ARCHIVED] }
let(:action_params) { { id: result.id } }
let(:action_params) { { my_module_id: my_module.id, id: result.id } }
end
end
end

View file

@ -5,7 +5,7 @@ require 'rails_helper'
RSpec.describe "Api::Service::ExperimentsController", type: :request do
before :all do
@user = create(:user)
@team = create(:team, created_by: @user)
@team = create(:team, :change_user_team, created_by: @user)
@valid_project = create(:project, name: Faker::Name.unique.name, created_by: @user, team: @team)
@unaccessible_project = create(:project, name: Faker::Name.unique.name, created_by: @user, team: @team)
@unaccessible_project.user_assignments.destroy_all

View file

@ -5,7 +5,7 @@ require 'rails_helper'
RSpec.describe "Api::Service::ProtocolsController", type: :request do
before :all do
@user = create(:user)
@team = create(:team, created_by: @user)
@team = create(:team, :change_user_team, created_by: @user)
@project = create(:project, name: Faker::Name.unique.name, created_by: @user, team: @team)
@experiment = create(:experiment, created_by: @user, last_modified_by: @user, project: @project, created_by: @user)

View file

@ -5,7 +5,7 @@ require 'rails_helper'
RSpec.describe "Api::Service::StepsController", type: :request do
before :all do
@user = create(:user)
@team = create(:team, created_by: @user)
@team = create(:team, :change_user_team, created_by: @user)
@project = create(:project, name: Faker::Name.unique.name, created_by: @user, team: @team)
@experiment = create(:experiment, created_by: @user, last_modified_by: @user, project: @project, created_by: @user)

View file

@ -241,7 +241,7 @@ RSpec.describe "Api::V1::ExperimentsController", type: :request do
describe 'PATCH experiment, #update' do
before :all do
@valid_headers['Content-Type'] = 'application/json'
@experiment = @valid_project.experiments.first
@experiment = @valid_project.experiments.active.first
end
let(:action) do

View file

@ -238,7 +238,7 @@ RSpec.describe 'Api::V1::ProjectsController', type: :request do
describe 'PATCH project, #update' do
before :all do
@valid_headers['Content-Type'] = 'application/json'
@project = @user.teams.first.projects.first
@project = @user.teams.first.projects.active.first
end
let(:action) do

View file

@ -27,13 +27,14 @@ RSpec.describe 'Api::V1::ProtocolTemplateController', type: :request do
team_id: @team.id
), headers: @valid_headers
expect { hash_body = json }.not_to raise_exception
expect(hash_body[:data]).to match(
JSON.parse(
ActiveModelSerializers::SerializableResource
.new(Protocol.latest_available_versions(@team), each_serializer: Api::V1::ProtocolTemplateSerializer)
.to_json
)['data']
)
parsed_data = JSON.parse(
ActiveModelSerializers::SerializableResource
.new(Protocol.latest_available_versions(@team), each_serializer: Api::V1::ProtocolTemplateSerializer)
.to_json
)['data']
expect(hash_body[:data]).to match_array(parsed_data)
end
it 'When invalid request, user in not member of the team' do
@ -63,13 +64,14 @@ RSpec.describe 'Api::V1::ProtocolTemplateController', type: :request do
get api_v1_team_protocol_template_path(id: @protocol_published_original.id, team_id: @team.id), headers: @valid_headers
expect { hash_body = json }.not_to raise_exception
expect(hash_body[:data]).to match(
JSON.parse(
ActiveModelSerializers::SerializableResource
.new(@protocol_published_original, serializer: Api::V1::ProtocolTemplateSerializer)
.to_json
)['data']
)
parsed_data = JSON.parse(
ActiveModelSerializers::SerializableResource
.new(@protocol_published_original, serializer: Api::V1::ProtocolTemplateSerializer)
.to_json
)['data']
expect(hash_body[:data]).to match_array(parsed_data)
end
it 'When invalid request, user in not member of the team' do

View file

@ -8,7 +8,7 @@ RSpec.describe 'Api::V1::TasksController', type: :request do
@user = create(:user)
@another_user = create(:user)
@team1 = create(:team, created_by: @user)
@team1 = create(:team, :change_user_team, created_by: @user)
@team2 = create(:team, created_by: @another_user)
@valid_project = create(:project, name: Faker::Name.unique.name,
created_by: @user, team: @team1)
@ -285,7 +285,7 @@ RSpec.describe 'Api::V1::TasksController', type: :request do
@valid_headers['Content-Type'] = 'application/json'
end
let(:task) { @valid_experiment.my_modules.take }
let(:task) { @valid_experiment.my_modules.active.first }
let(:action) do
patch(

View file

@ -18,12 +18,12 @@ describe Activities::ActivityFilterMatchingService do
it 'matches activity filters by activity date' do
matching_filter = ActivityFilter.create(
name: "date filter",
filter: {"to_date"=>"2021-1-6", "from_date"=>"2021-1-1"}
filter: {"to_date"=>"2021-1-1", "from_date"=>"2021-1-6"}
)
non_matching_filter = ActivityFilter.create(
name: "date filter",
filter: {"to_date"=>"2021-12-2", "from_date"=>"2021-12-1"}
filter: {"to_date"=>"2021-12-1", "from_date"=>"2021-12-2"}
)
activity.update_column(:created_at, Date.parse("2021-1-4").to_time)
@ -115,8 +115,8 @@ describe Activities::ActivityFilterMatchingService do
name: "mixed filter 1",
filter: {
"subjects" => { "Project" => [project.id.to_s] },
"to_date"=>"2021-1-6",
"from_date"=>"2021-1-1",
"to_date"=>"2021-1-1",
"from_date"=>"2021-1-6",
"teams"=>[team.id.to_s],
"users"=>[user.id.to_s],
"types"=>["163"]

View file

@ -8,12 +8,12 @@ describe Experiments::GenerateWorkflowImageService do
context 'when succeed' do
it 'succeed? returns true' do
expect(described_class.call(params).succeed?).to be_truthy
expect(described_class.call(**params).succeed?).to be_truthy
end
it 'worklfow image of experiment is updated' do
old_filename = nil
described_class.call(params)
described_class.call(**params)
experiment.reload
expect(experiment.workflowimg.blob.filename).not_to be == old_filename
end

View file

@ -4,7 +4,7 @@ require 'rails_helper'
describe Experiments::MoveToProjectService do
let(:user) { create :user }
let(:team) { create :team, created_by: user }
let(:team) { create :team, :change_user_team, created_by: user }
let(:project) do
create :project, team: team, created_by: user
end
@ -16,8 +16,14 @@ describe Experiments::MoveToProjectService do
end
let(:service_call) do
Experiments::MoveToProjectService.call(experiment_id: experiment.id,
project_id: new_project.id,
user_id: user.id)
project_id: new_project.id,
user_id: user.id)
end
let(:service_call_invalid_user) do
Experiments::MoveToProjectService.call(experiment_id: experiment.id,
project_id: nil,
user_id: nil)
end
context 'when call with valid params' do
@ -44,6 +50,7 @@ describe Experiments::MoveToProjectService do
it 'sets new project tags to modules' do
service_call
experiment.reload
new_tags = experiment.my_modules.map { |m| m.tags.map { |t| t } }.flatten
tags_project_id = new_tags.map(&:project_id).uniq.first
@ -64,10 +71,7 @@ describe Experiments::MoveToProjectService do
context 'when call with invalid params' do
it 'returns an error when can\'t find user and project' do
allow(Project).to receive(:find).and_return(nil)
allow(User).to receive(:find).and_return(nil)
expect(service_call.errors).to have_key(:invalid_arguments)
expect(service_call_invalid_user.errors).to have_key(:invalid_arguments)
end
it 'returns an error on validate' do

View file

@ -204,7 +204,6 @@ describe TeamImporter do
db_step = db_protocol.steps.find_by(name: json_step_obj['name'])
# Step object
expect(db_step.description).to eq json_step_obj['description']
expect(db_step.updated_at).to eq(
json_step_obj['updated_at'].to_time
)
@ -218,49 +217,65 @@ describe TeamImporter do
)
end
# Checklists
expect(db_step.checklists.count).to eq(
json_step['checklists'].count
)
json_step['checklists'].each do |checklist|
json_checklist = checklist['checklist']
json_items = checklist['checklist_items']
db_checklist = db_step.checklists.find_by(
name: json_checklist['name']
)
# byebug
# Checklist object
expect(db_checklist.created_at).to eq(
json_checklist['created_at'].to_time
)
expect(db_checklist.updated_at).to eq(
json_checklist['updated_at'].to_time
)
expect(db_checklist.created_by_id).to eq USER_ID
expect(db_checklist.last_modified_by_id).to eq USER_ID
element_counts = {
step_texts: 0,
step_tables: 0,
checklists: 0
}
expect(db_checklist.checklist_items.count).to eq(
json_items.count
)
json_step['step_orderable_elements'].each do |element|
if element['step_text']
element_counts[:step_texts] += 1
json_element = element['step_text']
db_element = db_step.step_texts.find_by(text: json_element['text'])
# Checklist items
json_items.each do |json_item|
db_item = db_checklist.checklist_items.find_by(
text: json_item['text']
)
expect(db_item.checked).to eq(json_item['checked'])
expect(db_item.position).to eq(json_item['position'])
expect(db_item.created_at).to eq(
json_item['created_at'].to_time
)
expect(db_item.updated_at).to eq(
json_item['updated_at'].to_time
)
expect(db_item.created_by_id).to eq USER_ID
expect(db_item.last_modified_by_id).to eq USER_ID
expect(db_element).not_to be_nil
expect(db_element.created_at).to eq(json_element['created_at'].to_time)
expect(db_element.updated_at).to eq(json_element['updated_at'].to_time)
elsif element['table']
element_counts[:step_tables] += 1
json_element = element['table']
db_element = db_step.tables.find_by(contents: Base64.decode64(json_element['contents']))
expect(db_element.created_at).to eq(json_element['created_at'].to_time)
expect(db_element.updated_at).to eq(json_element['updated_at'].to_time)
expect(db_element.created_by_id).to eq USER_ID
expect(db_element.last_modified_by_id).to eq USER_ID
expect(db_element.team_id).to eq @team.id
expect(db_element.name).to eq(json_element['name'])
expect(db_element.data_vector).to eq(Base64.decode64(json_element['data_vector']))
elsif element['checklist']
element_counts[:checklists] += 1
json_element = element['checklist']['checklist']
json_checklist_items = element['checklist']['checklist_items']
db_element = db_step.checklists.find_by(name: json_element['name'])
expect(db_element.created_at).to eq(json_element['created_at'].to_time)
expect(db_element.updated_at).to eq(json_element['updated_at'].to_time)
expect(db_element.created_by_id).to eq USER_ID
expect(db_element.last_modified_by_id).to eq USER_ID
expect(db_element.checklist_items.count).to eq(json_checklist_items.count)
json_checklist_items.each do |json_item|
db_item = db_element.checklist_items.find_by(
text: json_item['text']
)
expect(db_item.checked).to eq(json_item['checked'])
expect(db_item.position).to eq(json_item['position'])
expect(db_item.created_at).to eq(json_item['created_at'].to_time)
expect(db_item.updated_at).to eq(json_item['updated_at'].to_time)
expect(db_item.created_by_id).to eq USER_ID
expect(db_item.last_modified_by_id).to eq USER_ID
end
end
end
element_counts.each do |type, count|
expect(db_step.__send__(type).count).to eq(count)
end
# Step assets
expect(db_step.assets.count).to eq(
json_step['assets'].count
@ -310,37 +325,6 @@ describe TeamImporter do
)
end
# Tables
expect(db_step.step_tables.count).to eq(
json_step['step_tables'].count
)
expect(db_step.tables.count).to eq(
json_step['tables'].count
)
json_step['tables'].each do |json_table|
db_table = db_step.tables.find_by(
contents: Base64.decode64(json_table['contents'])
)
# Basic fields
expect(db_table.created_at).to eq(
json_table['created_at'].to_time
)
expect(db_table.updated_at).to eq(
json_table['updated_at'].to_time
)
expect(db_table.created_by_id).to eq USER_ID
expect(db_table.last_modified_by_id).to eq USER_ID
expect(db_table.team_id). to eq @team.id
# Other fields
expect(db_table.name).to eq(json_table['name'])
expect(db_table.data_vector).to eq(
Base64.decode64(json_table['data_vector'])
)
end
# Step comments
expect(db_step.step_comments.count).to eq(
json_step['step_comments'].count

View file

@ -83,7 +83,6 @@
"steps": [
{
"assets": [],
"checklists": [],
"step": {
"completed": false,
"completed_on": null,
@ -97,10 +96,19 @@
"updated_at": "2019-01-21T13:31:55.921Z",
"user_id": 1
},
"step_orderable_elements": [
{
"position": 0,
"step_text": {
"created_at": "2019-01-21T13:04:30.562Z",
"updated_at": "2019-01-21T13:04:30.562Z",
"text": "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">"
}
}
],
"step_assets": [],
"step_comments": [],
"step_tables": [],
"tables": []
"step_tables": []
}
]
}
@ -170,59 +178,10 @@
"steps": [
{
"assets": [],
"checklists": [
{
"checklist": {
"created_at": "2019-01-21T13:04:30.562Z",
"created_by_id": null,
"id": 2,
"last_modified_by_id": null,
"name": "Guide",
"step_id": 18,
"updated_at": "2019-01-21T13:04:30.562Z"
},
"checklist_items": [
{
"checked": false,
"checklist_id": 2,
"created_at": "2019-01-21T13:04:30.565Z",
"created_by_id": null,
"id": 8,
"last_modified_by_id": null,
"position": 0,
"text": "Wolf",
"updated_at": "2019-01-21T13:04:30.565Z"
},
{
"checked": true,
"checklist_id": 2,
"created_at": "2019-01-21T13:04:30.568Z",
"created_by_id": null,
"id": 9,
"last_modified_by_id": null,
"position": 1,
"text": "Cat",
"updated_at": "2019-01-21T13:04:32.708Z"
},
{
"checked": false,
"checklist_id": 2,
"created_at": "2019-01-21T13:04:30.570Z",
"created_by_id": null,
"id": 10,
"last_modified_by_id": null,
"position": 2,
"text": "Bull",
"updated_at": "2019-01-21T13:04:30.570Z"
}
]
}
],
"step": {
"completed": false,
"completed_on": null,
"created_at": "2019-01-21T13:04:30.558Z",
"description": "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">",
"id": 18,
"last_modified_by_id": 1,
"name": "Lonelier step",
@ -234,7 +193,65 @@
"step_assets": [],
"step_comments": [],
"step_tables": [],
"tables": []
"step_orderable_elements": [
{
"checklist": {
"position": 0,
"checklist": {
"created_at": "2019-01-21T13:04:30.562Z",
"created_by_id": null,
"id": 2,
"last_modified_by_id": null,
"name": "Guide",
"step_id": 18,
"updated_at": "2019-01-21T13:04:30.562Z"
},
"checklist_items": [
{
"checked": false,
"checklist_id": 2,
"created_at": "2019-01-21T13:04:30.565Z",
"created_by_id": null,
"id": 8,
"last_modified_by_id": null,
"position": 0,
"text": "Wolf",
"updated_at": "2019-01-21T13:04:30.565Z"
},
{
"checked": true,
"checklist_id": 2,
"created_at": "2019-01-21T13:04:30.568Z",
"created_by_id": null,
"id": 9,
"last_modified_by_id": null,
"position": 1,
"text": "Cat",
"updated_at": "2019-01-21T13:04:32.708Z"
},
{
"checked": false,
"checklist_id": 2,
"created_at": "2019-01-21T13:04:30.570Z",
"created_by_id": null,
"id": 10,
"last_modified_by_id": null,
"position": 2,
"text": "Bull",
"updated_at": "2019-01-21T13:04:30.570Z"
}
]
}
},
{
"position": 0,
"step_text":{
"created_at": "2019-01-21T13:04:30.562Z",
"updated_at": "2019-01-21T13:04:30.562Z",
"text": "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">"
}
}
]
}
]
}
@ -316,12 +333,10 @@
}
}
],
"checklists": [],
"step": {
"completed": false,
"completed_on": null,
"created_at": "2019-01-21T13:09:35.466Z",
"description": "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">",
"id": 20,
"last_modified_by_id": 1,
"name": "Workflow 2 step",
@ -330,6 +345,16 @@
"updated_at": "2019-01-21T13:10:06.292Z",
"user_id": 1
},
"step_orderable_elements": [
{
"position": 0,
"step_text": {
"created_at": "2019-01-21T13:04:30.562Z",
"updated_at": "2019-01-21T13:04:30.562Z",
"text": "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">"
}
}
],
"step_assets": [
{
"asset_id": 21,
@ -338,8 +363,7 @@
}
],
"step_comments": [],
"step_tables": [],
"tables": []
"step_tables": []
}
]
}
@ -406,12 +430,10 @@
"steps": [
{
"assets": [],
"checklists": [],
"step": {
"completed": false,
"completed_on": null,
"created_at": "2019-01-21T13:05:20.547Z",
"description": "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">",
"id": 19,
"last_modified_by_id": 1,
"name": "USB step",
@ -432,25 +454,36 @@
"user_id": 1
}
],
"step_orderable_elements": [
{
"position": 0,
"table": {
"contents": "eyJkYXRhIjpbWyIxIixudWxsLG51bGwsbnVsbCxudWxsXSxbbnVsbCwiMiIs\nbnVsbCxudWxsLG51bGxdLFtudWxsLG51bGwsIjMiLG51bGwsbnVsbF0sW251\nbGwsbnVsbCxudWxsLCI0IixudWxsXSxbbnVsbCxudWxsLG51bGwsbnVsbCwi\nNSJdXX0=\n",
"created_at": "2019-01-21T13:05:20.550Z",
"created_by_id": 1,
"data_vector": "JzEnOjEgJzInOjcgJzMnOjEzICc0JzoxOSAnNSc6MjUgJ251bGwnOjIsMyw0\nLDUsNiw4LDksMTAsMTEsMTIsMTQsMTUsMTYsMTcsMTgsMjAsMjEsMjIsMjMs\nMjQ=\n",
"id": 5,
"last_modified_by_id": null,
"name": "USB table",
"team_id": 1,
"updated_at": "2019-01-21T13:05:20.550Z"
}
},
{
"position": 1,
"step_text": {
"created_at": "2019-01-21T13:04:30.562Z",
"updated_at": "2019-01-21T13:04:30.562Z",
"text": "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">"
}
}
],
"step_tables": [
{
"id": 2,
"step_id": 19,
"table_id": 5
}
],
"tables": [
{
"contents": "eyJkYXRhIjpbWyIxIixudWxsLG51bGwsbnVsbCxudWxsXSxbbnVsbCwiMiIs\nbnVsbCxudWxsLG51bGxdLFtudWxsLG51bGwsIjMiLG51bGwsbnVsbF0sW251\nbGwsbnVsbCxudWxsLCI0IixudWxsXSxbbnVsbCxudWxsLG51bGwsbnVsbCwi\nNSJdXX0=\n",
"created_at": "2019-01-21T13:05:20.550Z",
"created_by_id": 1,
"data_vector": "JzEnOjEgJzInOjcgJzMnOjEzICc0JzoxOSAnNSc6MjUgJ251bGwnOjIsMyw0\nLDUsNiw4LDksMTAsMTEsMTIsMTQsMTUsMTYsMTcsMTgsMjAsMjEsMjIsMjMs\nMjQ=\n",
"id": 5,
"last_modified_by_id": null,
"name": "USB table",
"team_id": 1,
"updated_at": "2019-01-21T13:05:20.550Z"
}
]
}
]
@ -525,12 +558,10 @@
"steps": [
{
"assets": [],
"checklists": [],
"step": {
"completed": true,
"completed_on": "2019-01-19T10:56:48.558Z",
"created_at": "2019-01-19T08:52:33.490Z",
"description": "Compare response of PVYNTN, cab4 and PR1 genes in mock/virus inoculated potatoes & in time",
"id": 1,
"last_modified_by_id": null,
"name": "Gene expression",
@ -540,6 +571,16 @@
"user_id": 1
},
"step_assets": [],
"step_orderable_elements": [
{
"position": 0,
"step_text": {
"created_at": "2019-01-21T13:04:30.562Z",
"updated_at": "2019-01-21T13:04:30.562Z",
"text": "Compare response of PVYNTN, cab4 and PR1 genes in mock/virus inoculated potatoes & in time"
}
}
],
"step_comments": [
{
"associated_id": 1,
@ -551,15 +592,14 @@
"user_id": 1
}
],
"step_tables": [],
"tables": []
"step_tables": []
}
]
}
],
"results": [
{
"asset": null,
"assets": [],
"result": {
"archived": false,
"archived_by_id": null,
@ -575,40 +615,47 @@
"user_id": 1
},
"result_comments": [],
"result_text": null,
"table": {
"contents": "eyJkYXRhIjpbWyIiLCIiLCIiLG51bGwsbnVsbF0sWyIiLCIiLCIiLG51bGws\nbnVsbF0sWyJncm91cC90aW1lIiwiMSBkcGkiLCI2IGRwaSIsIiIsIiJdLFsi\nUFZZTlROIiwiMSIsIjEiLCIiLCIiXSxbIm1vY2siLCIxIiwiMSIsIiIsIiJd\nLFtudWxsLG51bGwsbnVsbCxudWxsLG51bGxdXX0=\n",
"created_at": "2019-01-21T12:44:58.086Z",
"created_by_id": 1,
"data_vector": "JzEnOjYsMTEsMTIsMTQsMTUgJzYnOjggJ2RwaSc6Nyw5ICdncm91cC90aW1l\nJzo1ICdtb2NrJzoxMyAnbnVsbCc6MSwyLDMsNCwxNiwxNywxOCwxOSwyMCAn\ncHZ5bnRuJzoxMA==\n",
"id": 1,
"last_modified_by_id": null,
"name": "",
"team_id": 1,
"updated_at": "2019-01-21T12:44:58.093Z"
}
"result_orderable_elements": [
{
"orderable_type": "ResultTable",
"position": 0,
"table": {
"contents": "eyJkYXRhIjpbWyIiLCIiLCIiLG51bGwsbnVsbF0sWyIiLCIiLCIiLG51bGws\nbnVsbF0sWyJncm91cC90aW1lIiwiMSBkcGkiLCI2IGRwaSIsIiIsIiJdLFsi\nUFZZTlROIiwiMSIsIjEiLCIiLCIiXSxbIm1vY2siLCIxIiwiMSIsIiIsIiJd\nLFtudWxsLG51bGwsbnVsbCxudWxsLG51bGxdXX0=\n",
"created_at": "2019-01-21T12:44:58.086Z",
"created_by_id": 1,
"data_vector": "JzEnOjYsMTEsMTIsMTQsMTUgJzYnOjggJ2RwaSc6Nyw5ICdncm91cC90aW1l\nJzo1ICdtb2NrJzoxMyAnbnVsbCc6MSwyLDMsNCwxNiwxNywxOCwxOSwyMCAn\ncHZ5bnRuJzoxMA==\n",
"id": 1,
"last_modified_by_id": null,
"name": "",
"team_id": 1,
"updated_at": "2019-01-21T12:44:58.093Z"
}
}
]
},
{
"asset": {
"asset": {
"created_at": "2019-01-21T12:45:29.138Z",
"created_by_id": 1,
"estimated_size": 232,
"file_processing": null,
"id": 1,
"last_modified_by_id": 1,
"lock": null,
"lock_ttl": null,
"team_id": 1,
"updated_at": "2019-01-21T13:06:01.610Z",
"version": 1
},
"asset_blob": {
"filename": "samples.txt",
"content_type": "text/plain",
"byte_size": 69
"assets": [
{
"asset": {
"created_at": "2019-01-21T12:45:29.138Z",
"created_by_id": 1,
"estimated_size": 232,
"file_processing": null,
"id": 1,
"last_modified_by_id": 1,
"lock": null,
"lock_ttl": null,
"team_id": 1,
"updated_at": "2019-01-21T13:06:01.610Z",
"version": 1
},
"asset_blob": {
"filename": "samples.txt",
"content_type": "text/plain",
"byte_size": 69
}
}
},
],
"result": {
"archived": true,
"archived_by_id": 1,
@ -624,8 +671,7 @@
"user_id": 1
},
"result_comments": [],
"result_text": null,
"table": {}
"result_orderable_elements": []
}
],
"task_comments": [
@ -759,103 +805,10 @@
"steps": [
{
"assets": [],
"checklists": [
{
"checklist": {
"created_at": "2019-01-21T12:44:58.537Z",
"created_by_id": null,
"id": 1,
"last_modified_by_id": null,
"name": "Mastermix",
"step_id": 9,
"updated_at": "2019-01-21T12:44:58.537Z"
},
"checklist_items": [
{
"checked": true,
"checklist_id": 1,
"created_at": "2019-01-21T12:44:58.540Z",
"created_by_id": null,
"id": 1,
"last_modified_by_id": null,
"position": null,
"text": "RT buffer",
"updated_at": "2019-01-21T12:50:40.690Z"
},
{
"checked": true,
"checklist_id": 1,
"created_at": "2019-01-21T12:44:58.542Z",
"created_by_id": null,
"id": 2,
"last_modified_by_id": null,
"position": null,
"text": "dNTP mix",
"updated_at": "2019-01-21T12:50:41.287Z"
},
{
"checked": false,
"checklist_id": 1,
"created_at": "2019-01-21T12:44:58.543Z",
"created_by_id": null,
"id": 3,
"last_modified_by_id": null,
"position": null,
"text": "Random Primers",
"updated_at": "2019-01-21T12:44:58.543Z"
},
{
"checked": false,
"checklist_id": 1,
"created_at": "2019-01-21T12:44:58.545Z",
"created_by_id": null,
"id": 4,
"last_modified_by_id": null,
"position": null,
"text": "RNase inhibitor",
"updated_at": "2019-01-21T12:44:58.545Z"
},
{
"checked": false,
"checklist_id": 1,
"created_at": "2019-01-21T12:44:58.547Z",
"created_by_id": null,
"id": 5,
"last_modified_by_id": null,
"position": null,
"text": "Reverse transcriptase",
"updated_at": "2019-01-21T12:44:58.547Z"
},
{
"checked": false,
"checklist_id": 1,
"created_at": "2019-01-21T12:44:58.548Z",
"created_by_id": null,
"id": 6,
"last_modified_by_id": null,
"position": null,
"text": "Optional: Luciferase mRNA (denatured)",
"updated_at": "2019-01-21T12:44:58.548Z"
},
{
"checked": false,
"checklist_id": 1,
"created_at": "2019-01-21T12:44:58.550Z",
"created_by_id": null,
"id": 7,
"last_modified_by_id": null,
"position": null,
"text": "H2O to 12.5 ul",
"updated_at": "2019-01-21T12:44:58.550Z"
}
]
}
],
"step": {
"completed": true,
"completed_on": "2019-01-17T13:52:32.426Z",
"created_at": "2019-01-17T13:15:20.691Z",
"description": "High Capacity cDNA Reverse Transcription Kit (Applied Biosystems)",
"id": 9,
"last_modified_by_id": null,
"name": "Prepare mastermix for RT",
@ -864,19 +817,118 @@
"updated_at": "2019-01-21T12:44:58.539Z",
"user_id": 1
},
"step_orderable_elements": [
{ "position": 0,
"step_text": {
"created_at": "2019-01-21T13:04:30.562Z",
"updated_at": "2019-01-21T13:04:30.562Z",
"text": "High Capacity cDNA Reverse Transcription Kit (Applied Biosystems)"
}
},
{
"checklist": {
"position": 1,
"checklist": {
"created_at": "2019-01-21T12:44:58.537Z",
"created_by_id": null,
"id": 1,
"last_modified_by_id": null,
"name": "Mastermix",
"step_id": 9,
"updated_at": "2019-01-21T12:44:58.537Z"
},
"checklist_items": [
{
"checked": true,
"checklist_id": 1,
"created_at": "2019-01-21T12:44:58.540Z",
"created_by_id": null,
"id": 1,
"last_modified_by_id": null,
"position": 0,
"text": "RT buffer",
"updated_at": "2019-01-21T12:50:40.690Z"
},
{
"checked": true,
"checklist_id": 1,
"created_at": "2019-01-21T12:44:58.542Z",
"created_by_id": null,
"id": 2,
"last_modified_by_id": null,
"position": 1,
"text": "dNTP mix",
"updated_at": "2019-01-21T12:50:41.287Z"
},
{
"checked": false,
"checklist_id": 1,
"created_at": "2019-01-21T12:44:58.543Z",
"created_by_id": null,
"id": 3,
"last_modified_by_id": null,
"position": 2,
"text": "Random Primers",
"updated_at": "2019-01-21T12:44:58.543Z"
},
{
"checked": false,
"checklist_id": 1,
"created_at": "2019-01-21T12:44:58.545Z",
"created_by_id": null,
"id": 4,
"last_modified_by_id": null,
"position": 3,
"text": "RNase inhibitor",
"updated_at": "2019-01-21T12:44:58.545Z"
},
{
"checked": false,
"checklist_id": 1,
"created_at": "2019-01-21T12:44:58.547Z",
"created_by_id": null,
"id": 5,
"last_modified_by_id": null,
"position": 4,
"text": "Reverse transcriptase",
"updated_at": "2019-01-21T12:44:58.547Z"
},
{
"checked": false,
"checklist_id": 1,
"created_at": "2019-01-21T12:44:58.548Z",
"created_by_id": null,
"id": 6,
"last_modified_by_id": null,
"position": 5,
"text": "Optional: Luciferase mRNA (denatured)",
"updated_at": "2019-01-21T12:44:58.548Z"
},
{
"checked": false,
"checklist_id": 1,
"created_at": "2019-01-21T12:44:58.550Z",
"created_by_id": null,
"id": 7,
"last_modified_by_id": null,
"position": 6,
"text": "H2O to 12.5 ul",
"updated_at": "2019-01-21T12:44:58.550Z"
}
]
}
}
],
"step_assets": [],
"step_comments": [],
"step_tables": [],
"tables": []
"step_tables": []
},
{
"assets": [],
"checklists": [],
"step": {
"completed": false,
"completed_on": null,
"created_at": "2019-01-17T12:58:06.802Z",
"description": "25\u00b0C for 10 min 37\u00b0C for 2 h",
"id": 10,
"last_modified_by_id": null,
"name": "RT reaction",
@ -885,10 +937,20 @@
"updated_at": "2019-01-21T12:44:58.483Z",
"user_id": 1
},
"step_assets": [],
"step_comments": [],
"step_tables": [],
"tables": []
"step_orderable_elements": [
{
"position": 0,
"step_text": {
"created_at": "2019-01-21T13:04:30.562Z",
"updated_at": "2019-01-21T13:04:30.562Z",
"text": "25\u00b0C for 10 min 37\u00b0C for 2 h"
}
}
]
},
{
"assets": [],
@ -897,7 +959,6 @@
"completed": true,
"completed_on": "2019-01-17T17:37:06.427Z",
"created_at": "2019-01-17T09:35:43.770Z",
"description": "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body><p>1 ug of RNA denature at 80\u00b0C for 5 min --&gt; ice</p></body></html>",
"id": 8,
"last_modified_by_id": 1,
"name": "RNA denaturation",
@ -906,6 +967,30 @@
"updated_at": "2019-01-21T12:57:51.929Z",
"user_id": 1
},
"step_orderable_elements": [
{
"position": 0,
"step_text": {
"created_at": "2019-01-21T13:04:30.562Z",
"updated_at": "2019-01-21T13:04:30.562Z",
"text": "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body><p>1 ug of RNA denature at 80\u00b0C for 5 min --&gt; ice</p></body></html>"
}
},
{
"position": 1,
"table": {
"contents": "eyJkYXRhIjpbWyIxMSIsIjIyIiwiMzMiLCI0NCIsIjU1Il0sW251bGwsbnVs\nbCxudWxsLG51bGwsbnVsbF0sW251bGwsbnVsbCxudWxsLG51bGwsbnVsbF0s\nW251bGwsbnVsbCxudWxsLG51bGwsbnVsbF0sW251bGwsbnVsbCxudWxsLG51\nbGwsIjY3OCJdXX0=\n",
"created_at": "2019-01-21T12:57:51.923Z",
"created_by_id": 1,
"data_vector": "JzExJzoxICcyMic6MiAnMzMnOjMgJzQ0Jzo0ICc1NSc6NSAnNjc4JzoyNSAn\nbnVsbCc6Niw3LDgsOSwxMCwxMSwxMiwxMywxNCwxNSwxNiwxNywxOCwxOSwy\nMCwyMSwyMiwyMywyNA==\n",
"id": 4,
"last_modified_by_id": null,
"name": "",
"team_id": 1,
"updated_at": "2019-01-21T12:57:51.923Z"
}
}
],
"step_assets": [],
"step_comments": [],
"step_tables": [
@ -914,19 +999,6 @@
"step_id": 8,
"table_id": 4
}
],
"tables": [
{
"contents": "eyJkYXRhIjpbWyIxMSIsIjIyIiwiMzMiLCI0NCIsIjU1Il0sW251bGwsbnVs\nbCxudWxsLG51bGwsbnVsbF0sW251bGwsbnVsbCxudWxsLG51bGwsbnVsbF0s\nW251bGwsbnVsbCxudWxsLG51bGwsbnVsbF0sW251bGwsbnVsbCxudWxsLG51\nbGwsIjY3OCJdXX0=\n",
"created_at": "2019-01-21T12:57:51.923Z",
"created_by_id": 1,
"data_vector": "JzExJzoxICcyMic6MiAnMzMnOjMgJzQ0Jzo0ICc1NSc6NSAnNjc4JzoyNSAn\nbnVsbCc6Niw3LDgsOSwxMCwxMSwxMiwxMywxNCwxNSwxNiwxNywxOCwxOSwy\nMCwyMSwyMiwyMywyNA==\n",
"id": 4,
"last_modified_by_id": null,
"name": "",
"team_id": 1,
"updated_at": "2019-01-21T12:57:51.923Z"
}
]
}
]
@ -1082,12 +1154,10 @@
}
}
],
"checklists": [],
"step": {
"completed": false,
"completed_on": null,
"created_at": "2019-01-18T16:27:28.209Z",
"description": null,
"id": 7,
"last_modified_by_id": null,
"name": "Use Nano chip for testing RNA integrity",
@ -1096,6 +1166,7 @@
"updated_at": "2019-01-21T13:06:04.592Z",
"user_id": 1
},
"step_orderable_elements": [],
"step_assets": [
{
"asset_id": 8,
@ -1104,34 +1175,35 @@
}
],
"step_comments": [],
"step_tables": [],
"tables": []
"step_tables": []
}
]
}
],
"results": [
{
"asset": {
"asset": {
"created_at": "2019-01-21T12:45:32.847Z",
"created_by_id": 1,
"estimated_size": 46131,
"file_processing": null,
"id": 9,
"last_modified_by_id": 1,
"lock": null,
"lock_ttl": null,
"team_id": 1,
"updated_at": "2019-01-21T12:45:44.269Z",
"version": 1
},
"asset_blob": {
"filename": "Bioanalyser_result.JPG",
"content_type": "image/jpeg",
"byte_size": 41938
"assets":[
{
"asset": {
"created_at": "2019-01-21T12:45:32.847Z",
"created_by_id": 1,
"estimated_size": 46131,
"file_processing": null,
"id": 9,
"last_modified_by_id": 1,
"lock": null,
"lock_ttl": null,
"team_id": 1,
"updated_at": "2019-01-21T12:45:44.269Z",
"version": 1
},
"asset_blob": {
"filename": "Bioanalyser_result.JPG",
"content_type": "image/jpeg",
"byte_size": 41938
}
}
},
],
"result": {
"archived": true,
"archived_by_id": 1,
@ -1146,9 +1218,8 @@
"updated_at": "2019-01-21T13:16:01.326Z",
"user_id": 1
},
"result_comments": [],
"result_text": null,
"table": {}
"result_orderable_elements": [],
"result_comments": []
}
],
"task_comments": [],

View file

@ -3,7 +3,7 @@ require 'rails_helper'
describe ProjectsJsonExportService do
before :all do
@user = create(:user)
@team = create(:team, created_by: @user)
@team = create(:team, :change_user_team, created_by: @user)
@accessible_project_1 = create(:project, name: Faker::Name.unique.name, created_by: @user, team: @team)
@accessible_project_2 = create(:project, name: Faker::Name.unique.name, created_by: @user, team: @team)

View file

@ -20,9 +20,10 @@ describe ProtocolImporters::ImportProtocolService do
context 'when have invalid arguments' do
it 'returns an error when can\'t find user' do
allow(User).to receive(:find_by_id).and_return(nil)
protocol_import = ProtocolImporters::ImportProtocolService
.call(protocol_params: protocol_params, steps_params_json: steps_params, user: nil, team: team)
expect(service_call.errors).to have_key(:invalid_arguments)
expect(protocol_import.errors).to have_key(:invalid_arguments)
end
it 'returns invalid protocol when can\'t save it' do
@ -31,10 +32,10 @@ describe ProtocolImporters::ImportProtocolService do
attributes_for(:step).except(:name).merge!(tables_attributes: [attributes_for(:table)])
].to_json
s = ProtocolImporters::ImportProtocolService.call(protocol_params: protocol_params,
steps_params_json: steps_invalid_params,
user: user, team: team)
expect(s.protocol).to be_invalid
s1 = ProtocolImporters::ImportProtocolService.call(protocol_params: protocol_params,
steps_params_json: steps_invalid_params,
user: user, team: team)
expect(s1.errors[:protocol][:name]).to include("can't be blank")
end
end

View file

@ -47,14 +47,19 @@ describe Repositories::MultipleShareUpdateService do
team_ids_for_unshare: [team2.id])
end
it 'removes TeamRepository record' do
create :team_shared_object, :write, team: team2, shared_repository: repository
let(:team_shared_object) { create :team_shared_object, :write, team: team2, shared_repository: repository }
expect { service_call }.to change { TeamRepository.count }.by(-1)
before do
allow_any_instance_of(TeamSharedObject).to receive(:team_cannot_be_the_same)
end
it 'removes TeamRepository record' do
create :team_shared_object, :write, team: team2, shared_object: repository
expect { service_call }.to change { repository.team_shared_objects.count }.by(-1)
end
it 'adds Activity record' do
create :team_shared_object, :write, team: team2, shared_repository: repository
create :team_shared_object, :write, team: team2, shared_object: repository
expect { service_call }.to(change { Activity.all.count }.by(1))
end
@ -83,14 +88,18 @@ describe Repositories::MultipleShareUpdateService do
)
end
before do
allow_any_instance_of(TeamSharedObject).to receive(:team_cannot_be_the_same)
end
it 'updates permission for share record' do
tr = create :team_shared_object, :write, team: team2, shared_repository: repository
tr = create :team_shared_object, :write, team: team2, shared_object: repository
expect { service_call }.to(change { tr.reload.permission_level })
end
it 'adds Activity record' do
create :team_shared_object, :write, team: team2, shared_repository: repository
create :team_shared_object, :write, team: team2, shared_object: repository
expect { service_call }.to(change { Activity.all.count }.by(1))
end

View file

@ -119,8 +119,8 @@ describe RepositoryRows::UpdateRepositoryRowService do
end
end
context 'when service does not succeed' do
context 'when updates repository_row and cell, but fails' do
context 'when service does succeed with empty repository name' do
context 'when updates repository_row and cell' do
let(:params) do
{
repository_cells: Hash[column.id, 'New value'],
@ -128,26 +128,25 @@ describe RepositoryRows::UpdateRepositoryRowService do
}
end
it 'reverts cells update' do
it 'update cells, but not repository row name' do
cell = RepositoryCell.create_with_value!(row, column, 'some data', user)
expect { service_call }.not_to(change { cell.reload.value.data })
expect { service_call }.to(change { cell.reload.value.data })
expect { service_call }.not_to(change { row.reload.name })
end
end
context 'when repository_row update fails' do
context 'when repository_row name update fails' do
let(:params) do
{
repository_row: { name: '' }
}
end
it 'returns false for succeed' do
expect(service_call.succeed?).to be_falsey
end
it 'returns errors' do
expect(service_call.errors.count).to eq(1)
it 'returns true for succeed' do
expect(service_call.succeed?).to be_truthy
expect { service_call }.not_to(change { row.reload.name })
expect(service_call.errors.count).to eq(0)
end
end
end

View file

@ -34,7 +34,7 @@ describe RepositoryTableStateColumnUpdateService do
last_modified_by: user_2
end
let!(:default_order) do
[[2, 'asc']]
[[3, 'asc']]
end
let!(:default_column_def) do
{ 'visible' => true,

View file

@ -6,7 +6,7 @@ describe SmartAnnotations::PermissionEval do
let(:subject) { described_class }
let(:user) { create :user }
let(:another_user) { create :user }
let(:team) { create :team, created_by: user }
let(:team) { create :team, :change_user_team, created_by: user }
let(:another_team) { create :team }
let!(:owner_role) { UserRole.find_by(name: I18n.t('user_roles.predefined.owner')) }
let!(:team_assignment) { create_user_assignment(team, owner_role, user) }

View file

@ -4,7 +4,7 @@ require 'rails_helper'
describe SmartAnnotations::TagToHtml do
let!(:user) { create :user }
let!(:team) { create :team, created_by: user }
let!(:team) { create :team, :change_user_team, created_by: user }
let!(:owner_role) { UserRole.find_by(name: I18n.t('user_roles.predefined.owner')) }
let!(:team_assignment) { create_user_assignment(team, owner_role, user) }
let!(:project) { create :project, name: 'my project', team: team }

View file

@ -4,7 +4,7 @@ require 'rails_helper'
describe SmartAnnotations::TagToText do
let!(:user) { create :user, full_name: 'admin' }
let!(:team) { create :team, created_by: user }
let!(:team) { create :team, :change_user_team, created_by: user }
let!(:project) { create :project, name: 'my project', team: team, created_by: user }
let(:text) do
@ -43,14 +43,14 @@ describe SmartAnnotations::TagToText do
let(:text) { "[@#{user.full_name}~#{user.id.base62_encode}]" }
it 'parses the user tokent to text format' do
expect(
subject.send(:parse_users_annotations, user, team, text)
subject.send(:parse_users_annotations, user, team, text, false)
).to eq user.full_name
end
it 'trims the user annotation if user is not member of a team' do
random_text = "Sec:[@#{user_two.full_name}~#{user_two.id.base62_encode}]"
expect(
subject.send(:parse_users_annotations, user, team, random_text)
subject.send(:parse_users_annotations, user, team, random_text, false)
).to eq 'Sec:'
end
end

View file

@ -16,7 +16,7 @@ RSpec::Matchers.define :be_valid_default_repository_table_state do |nr_of_cols|
'columns',
'start' => 0,
'length' => 10,
'order' => [[2, 'asc']],
'order' => [[3, 'asc']],
'assigned' => 'assigned',
'ColReorder' => cols_array
)

View file

@ -15,6 +15,8 @@ RSpec.shared_examples 'a controller with authentication' do |actions_with_params
get action, params: params
expect(response).to have_http_status(custom_response || :forbidden).or redirect_to('/users/sign_in')
end
rescue ActionController::UrlGenerationError => e
warn "Warning: #{e}"
end
end
end