Merge pull request #1958 from aignatov-bio/ai-sci-3728-fix-active-storage-tests

Fix tests for active storage [SCI-3728]
This commit is contained in:
aignatov-bio 2019-08-06 11:12:33 +02:00 committed by GitHub
commit 988cb68d10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
95 changed files with 460 additions and 653 deletions

View file

@ -4,9 +4,7 @@ source 'http://rubygems.org'
ruby '2.6.3'
gem 'bootsnap', require: false
gem 'webpacker', '~> 3.5'
gem 'bootstrap-sass', '~> 3.3.7'
gem 'bootstrap_form', '~> 2.7.0'
gem 'devise', '~> 4.6.2'
@ -19,6 +17,7 @@ gem 'recaptcha', require: 'recaptcha/rails'
gem 'sanitize', '~> 4.4'
gem 'sassc-rails'
gem 'simple_token_authentication', '~> 1.15.1' # Token authentication for Devise
gem 'webpacker', '~> 3.5'
gem 'yomu'
# Gems for OAuth2 subsystem
@ -29,6 +28,7 @@ gem 'omniauth-linkedin-oauth2'
# Gems for API implementation
gem 'active_model_serializers', '~> 0.10.7'
gem 'json-jwt'
gem 'jsonapi-renderer', '= 0.2.0'
gem 'jwt', '~> 1.5'
gem 'kaminari'
gem 'rack-attack'
@ -82,12 +82,12 @@ gem 'wkhtmltopdf-heroku', '2.12.4'
gem 'aws-sdk-rails'
gem 'aws-sdk-s3'
gem 'mini_magick'
gem 'paperclip', '~> 6.1' # File attachment, image attachment library
gem 'delayed_job_active_record'
gem 'devise-async',
git: 'https://github.com/mhfs/devise-async.git',
branch: 'devise-4.x'
gem 'mini_magick'
gem 'paperclip', '~> 6.1' # File attachment, image attachment library
gem 'rufus-scheduler', '~> 3.5'
gem 'discard', '~> 1.0'

View file

@ -283,7 +283,7 @@ GEM
json_matchers (0.11.0)
json_schema
json_schema (0.20.6)
jsonapi-renderer (0.2.1)
jsonapi-renderer (0.2.0)
jwt (1.5.6)
kaminari (1.1.1)
activesupport (>= 4.1.0)
@ -616,6 +616,7 @@ DEPENDENCIES
js_cookie_rails
json-jwt
json_matchers
jsonapi-renderer (= 0.2.0)
jwt (~> 1.5)
kaminari
listen (~> 3.0)

View file

@ -5,7 +5,7 @@ class AssetTextDatum < ApplicationRecord
validates :data, presence: true
validates :asset, presence: true, uniqueness: true
belongs_to :asset, inverse_of: :asset_text_datum, optional: true
belongs_to :asset, inverse_of: :asset_text_datum
after_save :update_ts_index

View file

@ -7,7 +7,7 @@ class Checklist < ApplicationRecord
length: { maximum: Constants::TEXT_MAX_LENGTH }
validates :step, presence: true
belongs_to :step, inverse_of: :checklists, touch: true, optional: true
belongs_to :step, inverse_of: :checklists, touch: true
belongs_to :created_by,
foreign_key: 'created_by_id',
class_name: 'User',

View file

@ -7,8 +7,7 @@ class ChecklistItem < ApplicationRecord
validates :checked, inclusion: { in: [true, false] }
belongs_to :checklist,
inverse_of: :checklist_items,
optional: true
inverse_of: :checklist_items
belongs_to :created_by,
foreign_key: 'created_by_id',
class_name: 'User',

View file

@ -3,15 +3,13 @@ class Experiment < ApplicationRecord
include SearchableModel
include SearchableByNameModel
belongs_to :project, inverse_of: :experiments, touch: true, optional: true
belongs_to :project, inverse_of: :experiments, touch: true
belongs_to :created_by,
foreign_key: :created_by_id,
class_name: 'User',
optional: true
class_name: 'User'
belongs_to :last_modified_by,
foreign_key: :last_modified_by_id,
class_name: 'User',
optional: true
class_name: 'User'
belongs_to :archived_by,
foreign_key: :archived_by_id, class_name: 'User', optional: true
belongs_to :restored_by,
@ -225,6 +223,12 @@ class Experiment < ApplicationRecord
workflowimg.service.exist?(workflowimg.blob.key)
end
def workflowimg_file_name
return '' unless workflowimg.attached?
workflowimg.blob&.filename&.sanitized
end
# Get projects where user is either owner or user in the same team
# as this experiment
def projects_with_role_above_user(current_user)

View file

@ -34,7 +34,7 @@ class MyModule < ApplicationRecord
foreign_key: 'restored_by_id',
class_name: 'User',
optional: true
belongs_to :experiment, inverse_of: :my_modules, touch: true, optional: true
belongs_to :experiment, inverse_of: :my_modules, touch: true
belongs_to :my_module_group, inverse_of: :my_modules, optional: true
has_many :results, inverse_of: :my_module, dependent: :destroy
has_many :my_module_tags, inverse_of: :my_module, dependent: :destroy

View file

@ -3,7 +3,7 @@ class MyModuleGroup < ApplicationRecord
validates :experiment, presence: true
belongs_to :experiment, inverse_of: :my_module_groups, optional: true
belongs_to :experiment, inverse_of: :my_module_groups
belongs_to :created_by,
foreign_key: 'created_by_id',
class_name: 'User',

View file

@ -4,10 +4,8 @@ class MyModuleRepositoryRow < ApplicationRecord
class_name: 'User',
optional: true
belongs_to :repository_row,
optional: true,
inverse_of: :my_module_repository_rows
belongs_to :my_module,
optional: true,
touch: true,
inverse_of: :my_module_repository_rows

View file

@ -2,10 +2,10 @@ class MyModuleTag < ApplicationRecord
validates :my_module, :tag, presence: true
validates :tag_id, uniqueness: { scope: :my_module_id }
belongs_to :my_module, inverse_of: :my_module_tags, optional: true
belongs_to :my_module, inverse_of: :my_module_tags
belongs_to :created_by,
foreign_key: 'created_by_id',
class_name: 'User',
optional: true
belongs_to :tag, inverse_of: :my_module_tags, optional: true
belongs_to :tag, inverse_of: :my_module_tags
end

View file

@ -29,7 +29,7 @@ class Project < ApplicationRecord
foreign_key: 'restored_by_id',
class_name: 'User',
optional: true
belongs_to :team, inverse_of: :projects, touch: true, optional: true
belongs_to :team, inverse_of: :projects, touch: true
has_many :user_projects, inverse_of: :project
has_many :users, through: :user_projects
has_many :experiments, inverse_of: :project

View file

@ -100,7 +100,7 @@ class Protocol < ApplicationRecord
belongs_to :my_module,
inverse_of: :protocols,
optional: true
belongs_to :team, inverse_of: :protocols, optional: true
belongs_to :team, inverse_of: :protocols
belongs_to :parent,
foreign_key: 'parent_id',
class_name: 'Protocol',

View file

@ -11,8 +11,8 @@ class Report < ApplicationRecord
validates :project, presence: true
validates :user, presence: true
belongs_to :project, inverse_of: :reports, optional: true
belongs_to :user, inverse_of: :reports, optional: true
belongs_to :project, inverse_of: :reports
belongs_to :user, inverse_of: :reports
belongs_to :team, inverse_of: :reports
belongs_to :last_modified_by,
foreign_key: 'last_modified_by_id',

View file

@ -6,7 +6,7 @@ class Repository < ApplicationRecord
attribute :discarded_by_id, :integer
belongs_to :team, optional: true
belongs_to :team
belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User'
has_many :repository_columns, dependent: :destroy
has_many :repository_rows, dependent: :destroy

View file

@ -33,8 +33,8 @@ class RepositoryAssetValue < ApplicationRecord
end
def update_data!(new_data, user)
file.original_filename = new_data[:file_name]
asset.file.attach(io: new_data[:file_data], filename: new_data[:file_name])
asset.file.attach(io: StringIO.new(Base64.decode64(new_data[:file_data].split(',')[1])),
filename: new_data[:file_name])
asset.last_modified_by = user
self.last_modified_by = user
asset.save! && save!
@ -43,15 +43,15 @@ class RepositoryAssetValue < ApplicationRecord
def self.new_with_payload(payload, attributes)
value = new(attributes)
team = value.repository_cell.repository_column.repository.team
file = Paperclip.io_adapters.for(payload[:file_data])
file.original_filename = payload[:file_name]
value.asset = Asset.create!(
file: file,
created_by: value.created_by,
last_modified_by: value.created_by,
team: team
)
value.asset.post_process_file(team)
value.asset.file.attach(
io: StringIO.new(Base64.decode64(payload[:file_data].split(',')[1])),
filename: payload[:file_name]
)
value
end
end

View file

@ -35,7 +35,7 @@ class RepositoryCell < ActiveRecord::Base
validates_inclusion_of :repository_column,
in: (lambda do |cell|
cell.repository_row.repository.repository_columns
cell.repository_row&.repository&.repository_columns || []
end)
validates :repository_column, presence: true
validate :repository_column_data_type

View file

@ -14,9 +14,7 @@ class RepositoryListValue < ApplicationRecord
validates :repository_cell, presence: true
validates_inclusion_of :repository_list_item,
in: (lambda do |list_value|
list_value.repository_cell
.repository_column
.repository_list_items
list_value.repository_cell&.repository_column&.repository_list_items || []
end)
SORTABLE_COLUMN_NAME = 'repository_list_items.data'

View file

@ -8,6 +8,7 @@ class User < ApplicationRecord
include User::ProjectRoles
include TeamBySubjectModel
include InputSanitizeHelper
include ActiveStorage::Downloading
acts_as_token_authenticatable
devise :invitable, :confirmable, :database_authenticatable, :registerable,
@ -248,6 +249,8 @@ class User < ApplicationRecord
end
def avatar_variant(style)
return Constants::DEFAULT_AVATAR_URL.gsub(':style', style) unless avatar.attached?
format = case style.to_sym
when :medium
Constants::MEDIUM_PIC_FORMAT
@ -563,6 +566,12 @@ class User < ApplicationRecord
.map { |i| { name: escape_input(i[:full_name]), id: i[:id] } }
end
def file_name
return '' unless avatar.attached?
avatar.blob&.filename&.sanitized
end
def avatar_base64(style)
unless avatar.present?
missing_link = File.open("#{Rails.root}/app/assets/images/#{style}/missing.png").to_a.join

View file

@ -49,7 +49,7 @@ class ZipExport < ApplicationRecord
end
def zip_file_name
return '' unless file.attached?
return '' unless zip_file.attached?
zip_file.blob&.filename&.to_s
end

View file

@ -18,10 +18,10 @@ module Api
end
def url
if !object.asset&.file&.exists?
if !object.asset&.file&.attached?
nil
else
rails_blob_path(object.asset.file, disposition: 'attachment')
Rails.application.routes.url_helpers.rails_blob_path(object.asset.file, disposition: 'attachment')
end
end
end

View file

@ -19,10 +19,10 @@ module Api
end
def url
if !object.asset&.file&.exists?
if !object.asset&.file&.attached?
nil
else
rails_blob_path(object.asset.file, disposition: 'attachment')
Rails.application.routes.url_helpers.rails_blob_path(object.asset.file, disposition: 'attachment')
end
end
end

View file

@ -5,20 +5,20 @@ module Api
class UserSerializer < ActiveModel::Serializer
type :users
attributes :full_name, :initials, :email
attribute :avatar_file_name, if: -> { object.avatar.present? }
attribute :avatar_file_size, if: -> { object.avatar.present? }
attribute :avatar_url, if: -> { object.avatar.present? }
attribute :avatar_file_name, if: -> { object.avatar.attached? }
attribute :avatar_file_size, if: -> { object.avatar.attached? }
attribute :avatar_url, if: -> { object.avatar.attached? }
def avatar_file_name
object.avatar_file_name
object.avatar.blob.filename
end
def avatar_file_size
object.avatar.size
object.avatar.blob.byte_size
end
def avatar_url
object.avatar.url(:icon)
object.avatar_url(:icon)
end
end
end

View file

@ -67,10 +67,19 @@ module ModelExporters
{
result: result,
result_comments: result.result_comments,
asset: result.asset,
asset: result_assets_data(result.asset),
table: table(result.table),
result_text: result.result_text
}
end
def result_assets_data(asset)
return unless asset&.file&.attached?
{
asset: asset,
asset_blob: asset.file.blob
}
end
end
end

View file

@ -14,27 +14,21 @@ module ModelExporters
def copy_files(assets, attachment_name, dir_name)
assets.flatten.each do |a|
next unless a.public_send(attachment_name).present?
next unless a.public_send(attachment_name).attached?
unless a.public_send(attachment_name).exists?
raise StandardError,
"File id:#{a.id} of type #{attachment_name} is missing"
end
yield if block_given?
dir = FileUtils.mkdir_p(File.join(dir_name, a.id.to_s)).first
if defined?(S3_BUCKET)
s3_asset =
S3_BUCKET.object(a.public_send(attachment_name).path.remove(%r{^/}))
file_name = a.public_send(attachment_name).original_filename
File.open(File.join(dir, file_name), 'wb') do |f|
s3_asset.get(response_target: f)
end
else
FileUtils.cp(
a.public_send(attachment_name).path,
File.join(dir, a.public_send(attachment_name).original_filename)
)
end
tempfile = Tempfile.new
tempfile.binmode
a.public_send(attachment_name).blob.download { |chunk| tempfile.write(chunk) }
tempfile.flush
tempfile.rewind
FileUtils.cp(
tempfile.path,
File.join(dir, a.file_name)
)
tempfile.close!
end
end
@ -57,12 +51,21 @@ module ModelExporters
checklists: step.checklists.map { |c| checklist(c) },
step_comments: step.step_comments,
step_assets: step.step_assets,
assets: step.assets,
assets: step.assets.map { |a| assets_data(a) },
step_tables: step.step_tables,
tables: step.tables.map { |t| table(t) }
}
end
def assets_data(asset)
return unless asset.file.attached?
{
asset: asset,
asset_blob: asset.file.blob
}
end
def checklist(checklist)
{
checklist: checklist,

View file

@ -39,9 +39,7 @@ module ModelExporters
private
def team(team)
if team.tiny_mce_assets.present?
@tiny_mce_assets_to_copy.push(team.tiny_mce_assets)
end
@tiny_mce_assets_to_copy.push(team.tiny_mce_assets) if team.tiny_mce_assets.present?
{
team: team,
default_admin_id: team.user_teams.where(role: 2).first.user.id,
@ -53,7 +51,7 @@ module ModelExporters
.map { |n| notification(n) },
custom_fields: team.custom_fields,
repositories: team.repositories.map { |r| repository(r) },
tiny_mce_assets: team.tiny_mce_assets,
tiny_mce_assets: team.tiny_mce_assets.map { |tma| tiny_mce_asset_data(tma) },
protocols: team.protocols.where(my_module: nil).map do |pr|
protocol(pr)
end,
@ -80,6 +78,7 @@ module ModelExporters
user_json['sign_in_count'] = user.sign_in_count
user_json['last_sign_in_at'] = user.last_sign_in_at
user_json['last_sign_in_ip'] = user.last_sign_in_ip
user_json['avatar'] = user.avatar.blob if user.avatar.attached?
copy_files([user], :avatar, File.join(@dir_to_export, 'avatars'))
{
user: user_json,
@ -152,11 +151,21 @@ module ModelExporters
}
end
def tiny_mce_asset_data(asset)
{
tiny_mce_asset: asset,
tiny_mce_asset_blob: asset.image.blob
}
end
def get_cell_value_asset(cell)
return unless cell.value_type == 'RepositoryAssetValue'
@assets_to_copy.push(cell.value.asset)
cell.value.asset
{
asset: cell.value.asset,
asset_blob: cell.value.asset.blob
}
end
end
end

View file

@ -84,7 +84,9 @@ class ProjectsOverviewService
).joins(
"LEFT OUTER JOIN (#{due_modules.to_sql}) due_modules "\
"ON due_modules.experiment_id = experiments.id"
).left_outer_joins(:user_projects, :project_comments)
).joins(
'LEFT OUTER JOIN user_projects ON user_projects.project_id = projects.id'
).left_outer_joins(:project_comments)
# Only admins see all projects of the team
unless @user.is_admin_of_team?(@team)

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class RepositoryTableStateColumnUpdateService
# We're using Constants::REPOSITORY_TABLE_DEFAULT_STATE as a reference for
# default table state; this Ruby Hash makes heavy use of Ruby symbols
@ -56,9 +58,7 @@ class RepositoryTableStateColumnUpdateService
state['order'].reject! { |_, v| v[0] == old_column_index }
state['order'].each do |k, v|
if v[0].to_i > old_column_index.to_i
state['order'][k] = [(v[0].to_i - 1).to_s, v[1]]
end
state['order'][k] = [(v[0].to_i - 1).to_s, v[1]] if v[0].to_i > old_column_index.to_i
end
if state['order'].empty?
# Fallback to default order if user had table ordered by
@ -73,4 +73,4 @@ class RepositoryTableStateColumnUpdateService
table_state.save
end
end
end
end

View file

@ -90,6 +90,7 @@ class TeamImporter
user_notification.notification_id =
@notification_mappings[user_notification.notification_id]
next if user_notification.notification_id.blank?
user_notification.save!
end
@ -241,6 +242,7 @@ class TeamImporter
comment.save! if update_annotation(comment.message)
end
next unless res.result_text
res.save! if update_annotation(res.result_text.text)
end
end
@ -250,6 +252,7 @@ class TeamImporter
# Returns true if text was updated
def update_annotation(text)
return false if text.nil?
updated = false
%w(prj exp tsk rep_item).each do |name|
text.scan(/~#{name}~\w+\]/).each do |text_match|
@ -267,6 +270,7 @@ class TeamImporter
@repository_row_mappings[orig_id]
end
next unless new_id
new_id_encoded = new_id.base62_encode
text.sub!("~#{name}~#{orig_id_encoded}]", "~#{name}~#{new_id_encoded}]")
updated = true
@ -276,6 +280,7 @@ class TeamImporter
orig_id_encoded = user_match.match(/\[@[\w+-@?! ]+~(\w+)\]/)[1]
orig_id = orig_id_encoded.base62_decode
next unless @user_mappings[orig_id]
new_id_encoded = @user_mappings[orig_id].base62_encode
text.sub!("~#{orig_id_encoded}]", "~#{new_id_encoded}]")
updated = true
@ -327,11 +332,12 @@ class TeamImporter
def create_tiny_mce_assets(tmce_assets_json, team)
tmce_assets_json.each do |tiny_mce_asset_json|
tiny_mce_asset = TinyMceAsset.new(tiny_mce_asset_json)
tiny_mce_asset = TinyMceAsset.new(tiny_mce_asset_json['tiny_mce_asset'])
tiny_mce_asset_blob = tiny_mce_asset_json['tiny_mce_asset_blob']
# Try to find and load file
File.open(
File.join(@import_dir, 'tiny_mce_assets', tiny_mce_asset.id.to_s,
tiny_mce_asset.image_file_name)
tiny_mce_asset_blob['filename'])
) do |tiny_mce_file|
orig_tmce_id = tiny_mce_asset.id
tiny_mce_asset.id = nil
@ -341,7 +347,7 @@ class TeamImporter
end
tiny_mce_asset.team = team
tiny_mce_asset.save!
tiny_mce_asset.image.attach(io: tiny_mce_file, filename: tiny_mce_file.basename)
tiny_mce_asset.image.attach(io: tiny_mce_file, filename: File.basename(tiny_mce_file))
@mce_asset_counter += 1
if tiny_mce_asset.object_id.present?
object = tiny_mce_asset.object
@ -368,12 +374,10 @@ class TeamImporter
user.password = user_json['user']['encrypted_password']
user.current_team_id = team.id
user.invited_by_id = @user_mappings[user.invited_by_id]
if user.avatar.present?
if user_json['user']['avatar']
avatar_path = File.join(@import_dir, 'avatars', orig_user_id.to_s,
user.avatar_file_name)
if File.exist?(avatar_path)
File.open(avatar_path) { |f| user.avatar = f }
end
user_json['user']['avatar']['filename'])
File.open(avatar_path) { |f| user.avatar = f } if File.exist?(avatar_path)
end
user.save!
@user_counter += 1
@ -394,6 +398,7 @@ class TeamImporter
notifications_json.each do |notification_json|
notification = Notification.new(notification_json)
next if notification.type_of.blank?
orig_notification_id = notification.id
notification.id = nil
notification.generator_user_id = find_user(notification.generator_user_id)
@ -415,7 +420,6 @@ class TeamImporter
@repository_mappings[orig_repository_id] = repository.id
@repository_counter += 1
repository_json['repository_columns'].each do |repository_column_json|
repository_column = RepositoryColumn.new(
repository_column_json['repository_column']
)
@ -427,6 +431,7 @@ class TeamImporter
repository_column.save!
@repository_column_mappings[orig_rep_col_id] = repository_column.id
next unless repository_column.data_type == 'RepositoryListValue'
repository_column_json['repository_list_items'].each do |list_item|
created_by_id = find_user(repository_column.created_by_id)
repository_list_item = RepositoryListItem.new(data: list_item['data'])
@ -662,9 +667,7 @@ class TeamImporter
protocol.archived_by_id = find_user(protocol.archived_by_id)
protocol.restored_by_id = find_user(protocol.restored_by_id)
protocol.my_module = my_module unless protocol.my_module_id.nil?
unless protocol.parent_id.nil?
protocol.parent_id = @protocol_mappings[protocol.parent_id]
end
protocol.parent_id = @protocol_mappings[protocol.parent_id] unless protocol.parent_id.nil?
protocol.save!
@protocol_counter += 1
@protocol_mappings[orig_protocol_id] = protocol.id
@ -792,9 +795,10 @@ class TeamImporter
# returns asset object
def create_asset(asset_json, team, user_id = nil)
asset = Asset.new(asset_json)
asset = Asset.new(asset_json['asset'])
asset_blob = asset_json['asset_blob']
File.open(
"#{@import_dir}/assets/#{asset.id}/#{asset.file_name}"
"#{@import_dir}/assets/#{asset.id}/#{asset_blob['filename']}"
) do |file|
orig_asset_id = asset.id
asset.id = nil
@ -804,7 +808,7 @@ class TeamImporter
asset.team = team
asset.in_template = true if @is_template
asset.save!
asset.file.attach(io: file, filename: file.basename)
asset.file.attach(io: file, filename: File.basename(file))
asset.post_process_file(team)
@asset_mappings[orig_asset_id] = asset.id
@asset_counter += 1
@ -864,22 +868,14 @@ class TeamImporter
report_element.my_module_id =
@my_module_mappings[report_element.my_module_id]
end
if report_element.step_id
report_element.step_id = @step_mappings[report_element.step_id]
end
if report_element.result_id
report_element.result_id = @result_mappings[report_element.result_id]
end
report_element.step_id = @step_mappings[report_element.step_id] if report_element.step_id
report_element.result_id = @result_mappings[report_element.result_id] if report_element.result_id
if report_element.checklist_id
report_element.checklist_id =
@checklist_mappings[report_element.checklist_id]
end
if report_element.asset_id
report_element.asset_id = @asset_mappings[report_element.asset_id]
end
if report_element.table_id
report_element.table_id = @table_mappings[report_element.table_id]
end
report_element.asset_id = @asset_mappings[report_element.asset_id] if report_element.asset_id
report_element.table_id = @table_mappings[report_element.table_id] if report_element.table_id
if report_element.experiment_id
report_element.experiment_id =
@experiment_mappings[report_element.experiment_id]
@ -902,7 +898,8 @@ class TeamImporter
def find_user(user_id)
return nil if user_id.nil?
@user_mappings[user_id] ? @user_mappings[user_id] : @admin_id
@user_mappings[user_id] || @admin_id
end
def find_list_item_id(list_item_id)

View file

@ -1,14 +1,15 @@
# frozen_string_literal: true
module DelayedUploaderDemo
# Get asset from demo_files folder
def self.get_asset(user, team, file_name)
Asset.new(
file: File.open(
"#{Rails.root}/app/assets/demo_files/#{file_name}", 'r'
),
asset = Asset.create(
created_by: user,
team: team,
last_modified_by: user
)
asset.file.attach(io: File.open("#{Rails.root}/app/assets/demo_files/#{file_name}", 'r'), filename: file_name)
asset
end
# Generates results asset for given module, file_name assumes file is located
@ -32,7 +33,6 @@ module DelayedUploaderDemo
)
temp_result.save
temp_asset.save
# Generate comment if it exists
generate_result_comment(temp_result, current_user, comment) if comment

View file

@ -23,7 +23,7 @@
</div>
<div class="panel-body">
<% if experiment.workflowimg? %>
<% if experiment.workflowimg.attached? %>
<div class="workflowimg-container">
<%= image_tag(
experiment.workflowimg.expiring_url(

View file

@ -2,11 +2,8 @@
FactoryBot.define do
factory :asset do
file_file_name { 'sample_file.txt' }
file_content_type { 'text/plain' }
file_file_size { 69 }
version { 1 }
estimated_size { 232 }
file_processing { false }
file do
fixture_file_upload(Rails.root.join('spec', 'fixtures', 'files', 'test.jpg'), 'image/jpg')
end
end
end

View file

@ -2,8 +2,10 @@
FactoryBot.define do
factory :notification do
title { '<i>Admin</i> was added as Owner to project ' \
'<strong>Demo project - qPCR</strong> by <i>User</i>.' }
title do
'<i>Admin</i> was added as Owner to project ' \
'<strong>Demo project - qPCR</strong> by <i>User</i>.'
end
message { 'Project: <a href=\"/projects/3\"> Demo project - qPCR</a>' }
type_of { 'assignment' }
end

View file

@ -7,7 +7,7 @@ FactoryBot.define do
trait :text_value do
repository_column { create :repository_column, :text_type, repository: repository_row.repository }
after(:build) do |repository_cell|
repository_cell.value ||= build(:repository_text_value, repository_cell: repository_cell)
repository_cell.value ||= create(:repository_text_value, repository_cell: repository_cell)
end
end

View file

@ -3,8 +3,8 @@
FactoryBot.define do
factory :tiny_mce_asset do
association :team, factory: :team
image_file_name { 'sample_file.jpg' }
image_content_type { 'image/jpeg' }
image_file_size { 69 }
image do
fixture_file_upload(Rails.root.join('spec', 'fixtures', 'files', 'test.jpg'), 'image/jpg')
end
end
end

BIN
spec/fixtures/files/test.jpg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

View file

@ -31,11 +31,11 @@ describe Activity, type: :model do
end
describe 'Relations' do
it { should belong_to :project }
it { should belong_to :experiment }
it { should belong_to :my_module }
it { should belong_to(:project).optional }
it { should belong_to(:experiment).optional }
it { should belong_to(:my_module).optional }
it { should belong_to :owner }
it { should belong_to :subject }
it { should belong_to(:subject).optional }
end
describe 'Validations' do

View file

@ -33,9 +33,9 @@ describe Asset, type: :model do
end
describe 'Relations' do
it { should belong_to(:created_by).class_name('User') }
it { should belong_to(:last_modified_by).class_name('User') }
it { should belong_to :team }
it { should belong_to(:created_by).class_name('User').optional }
it { should belong_to(:last_modified_by).class_name('User').optional }
it { should belong_to(:team).optional }
it { should have_many :report_elements }
it { should have_one :step_asset }
it { should have_one :step }
@ -45,14 +45,4 @@ describe Asset, type: :model do
it { should have_one :repository_asset_value }
it { should have_one :repository_cell }
end
describe 'Validations' do
describe '#file' do
it { is_expected.to validate_presence_of(:file) }
end
describe '#estimated_size' do
it { expect(asset).to validate_presence_of(:estimated_size) }
end
end
end

View file

@ -26,9 +26,9 @@ describe ChecklistItem, type: :model do
end
describe 'Relations' do
it { should belong_to :checklist }
it { should belong_to(:created_by).class_name('User') }
it { should belong_to(:last_modified_by).class_name('User') }
it { should belong_to(:checklist) }
it { should belong_to(:created_by).class_name('User').optional }
it { should belong_to(:last_modified_by).class_name('User').optional }
end
describe 'Validations' do

View file

@ -24,9 +24,9 @@ describe Checklist, type: :model do
end
describe 'Relations' do
it { should belong_to :step }
it { should belong_to(:created_by).class_name('User') }
it { should belong_to(:last_modified_by).class_name('User') }
it { should belong_to(:step) }
it { should belong_to(:created_by).class_name('User').optional }
it { should belong_to(:last_modified_by).class_name('User').optional }
it { should have_many :report_elements }
it { should have_many :checklist_items }
end

View file

@ -26,7 +26,7 @@ describe Comment, type: :model do
describe 'Relations' do
it { should belong_to :user }
it { should belong_to(:last_modified_by).class_name('User') }
it { should belong_to(:last_modified_by).class_name('User').optional }
end
describe 'Validations' do

View file

@ -26,7 +26,7 @@ describe CustomField, type: :model do
describe 'Relations' do
it { should belong_to :user }
it { should belong_to :team }
it { should belong_to(:last_modified_by).class_name('User') }
it { should belong_to(:last_modified_by).class_name('User').optional }
it { should have_many :sample_custom_fields }
end
@ -44,7 +44,6 @@ describe CustomField, type: :model do
expect(custom_field).to validate_uniqueness_of(:name).scoped_to(:team_id)
end
end
describe '#user' do

View file

@ -35,11 +35,11 @@ describe Experiment, type: :model do
end
describe 'Relations' do
it { should belong_to :project }
it { should belong_to(:project) }
it { should belong_to(:created_by).class_name('User') }
it { should belong_to(:last_modified_by).class_name('User') }
it { should belong_to(:archived_by).class_name('User') }
it { should belong_to(:restored_by).class_name('User') }
it { should belong_to(:archived_by).class_name('User').optional }
it { should belong_to(:restored_by).class_name('User').optional }
it { should have_many :my_modules }
it { should have_many :my_module_groups }
it { should have_many :report_elements }

View file

@ -22,8 +22,8 @@ describe MyModuleGroup, type: :model do
end
describe 'Relations' do
it { should belong_to :experiment }
it { should belong_to(:created_by).class_name('User') }
it { should belong_to(:experiment) }
it { should belong_to(:created_by).class_name('User').optional }
it { should have_many(:my_modules) }
end

View file

@ -23,9 +23,9 @@ describe MyModuleRepositoryRow, type: :model do
end
describe 'Relations' do
it { should belong_to :my_module }
it { should belong_to(:assigned_by).class_name('User') }
it { should belong_to :repository_row }
it { should belong_to(:my_module) }
it { should belong_to(:assigned_by).class_name('User').optional }
it { should belong_to(:repository_row) }
end
describe 'Validations' do

View file

@ -38,12 +38,12 @@ describe MyModule, type: :model do
end
describe 'Relations' do
it { should belong_to :experiment }
it { should belong_to :my_module_group }
it { should belong_to(:created_by).class_name('User') }
it { should belong_to(:last_modified_by).class_name('User') }
it { should belong_to(:archived_by).class_name('User') }
it { should belong_to(:restored_by).class_name('User') }
it { should belong_to(:experiment) }
it { should belong_to(:my_module_group).optional }
it { should belong_to(:created_by).class_name('User').optional }
it { should belong_to(:last_modified_by).class_name('User').optional }
it { should belong_to(:archived_by).class_name('User').optional }
it { should belong_to(:restored_by).class_name('User').optional }
it { should have_many :results }
it { should have_many :my_module_tags }
it { should have_many :tags }

View file

@ -20,9 +20,9 @@ describe MyModuleTag, type: :model do
end
describe 'Relations' do
it { should belong_to :my_module }
it { should belong_to(:created_by).class_name('User') }
it { should belong_to :tag }
it { should belong_to(:my_module) }
it { should belong_to(:created_by).class_name('User').optional }
it { should belong_to(:tag) }
end
describe 'Validations' do

View file

@ -24,7 +24,7 @@ describe Notification, type: :model do
end
describe 'Relations' do
it { should belong_to(:generator_user).class_name('User') }
it { should belong_to(:generator_user).class_name('User').optional }
it { should have_many :users }
it { should have_many :user_notifications }
end

View file

@ -33,11 +33,11 @@ describe Project, type: :model do
end
describe 'Relations' do
it { should belong_to :team }
it { should belong_to(:created_by).class_name('User') }
it { should belong_to(:last_modified_by).class_name('User') }
it { should belong_to(:archived_by).class_name('User') }
it { should belong_to(:restored_by).class_name('User') }
it { should belong_to(:team) }
it { should belong_to(:created_by).class_name('User').optional }
it { should belong_to(:last_modified_by).class_name('User').optional }
it { should belong_to(:archived_by).class_name('User').optional }
it { should belong_to(:restored_by).class_name('User').optional }
it { should have_many :user_projects }
it { should have_many :users }
it { should have_many :experiments }

View file

@ -31,8 +31,8 @@ describe ProtocolKeyword, type: :model do
it { should validate_presence_of :team }
it do
should validate_length_of(:name)
.is_at_least(Constants::NAME_MIN_LENGTH)
.is_at_most(Constants::NAME_MAX_LENGTH)
.is_at_least(Constants::NAME_MIN_LENGTH)
.is_at_most(Constants::NAME_MAX_LENGTH)
end
end
end

View file

@ -34,12 +34,11 @@ describe Protocol, type: :model do
end
describe 'Relations' do
it { should belong_to :my_module }
it { should belong_to :team }
it { should belong_to(:added_by).class_name('User') }
it { should belong_to(:parent).class_name('Protocol') }
it { should belong_to(:archived_by).class_name('User') }
it { should belong_to(:restored_by).class_name('User') }
it { should belong_to(:team) }
it { should belong_to(:added_by).class_name('User').optional }
it { should belong_to(:parent).class_name('Protocol').optional }
it { should belong_to(:archived_by).class_name('User').optional }
it { should belong_to(:restored_by).class_name('User').optional }
it { should have_many(:linked_children).class_name('Protocol') }
it { should have_many :protocol_protocol_keywords }
it { should have_many :protocol_keywords }

View file

@ -38,16 +38,15 @@ describe ReportElement, type: :model do
end
describe 'Relations' do
it { should belong_to :report }
it { should belong_to :project }
it { should belong_to :experiment }
it { should belong_to :my_module }
it { should belong_to :step }
it { should belong_to :result }
it { should belong_to :checklist }
it { should belong_to :asset }
it { should belong_to :table }
it { should belong_to :repository }
it { should belong_to(:project).optional }
it { should belong_to(:experiment).optional }
it { should belong_to(:my_module).optional }
it { should belong_to(:step).optional }
it { should belong_to(:result).optional }
it { should belong_to(:checklist).optional }
it { should belong_to(:asset).optional }
it { should belong_to(:table).optional }
it { should belong_to(:repository).optional }
it { should belong_to(:report) }
it { should have_many(:children).class_name('ReportElement') }
end

View file

@ -27,9 +27,8 @@ describe Report, type: :model do
describe 'Relations' do
it { should belong_to :project }
it { should belong_to :user }
it { should belong_to :project }
it { should belong_to :team }
it { should belong_to(:last_modified_by).class_name('User') }
it { should belong_to(:last_modified_by).class_name('User').optional }
it { should have_many :report_elements }
end

View file

@ -22,8 +22,8 @@ describe RepositoryAssetValue, type: :model do
end
describe 'Relations' do
it { should belong_to(:created_by).class_name('User') }
it { should belong_to(:last_modified_by).class_name('User') }
it { should belong_to(:created_by).class_name('User').optional }
it { should belong_to(:last_modified_by).class_name('User').optional }
it { should belong_to(:asset).dependent(:destroy) }
it { should have_one :repository_cell }
it { should accept_nested_attributes_for(:repository_cell) }
@ -36,10 +36,10 @@ describe RepositoryAssetValue, type: :model do
describe '#data' do
it 'returns the asset' do
asset = create :asset, file_file_name: 'my file'
asset = create :asset
repository_asset_value = create :repository_asset_value, asset: asset
expect(repository_asset_value.reload.formatted).to eq 'my file'
expect(repository_asset_value.reload.formatted).to eq 'test.jpg'
end
end
end

View file

@ -23,7 +23,7 @@ describe RepositoryRow, type: :model do
end
describe 'Relations' do
it { should belong_to :repository }
it { should belong_to(:repository).optional }
it { should belong_to(:created_by).class_name('User') }
it { should belong_to(:last_modified_by).class_name('User') }
it { should have_many :repository_cells }

View file

@ -30,9 +30,9 @@ describe Result, type: :model do
describe 'Relations' do
it { should belong_to :user }
it { should belong_to :my_module }
it { should belong_to(:archived_by).class_name('User') }
it { should belong_to(:last_modified_by).class_name('User') }
it { should belong_to(:restored_by).class_name('User') }
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 }

View file

@ -1,47 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe SampleCustomField, type: :model do
it 'is valid' do
# Need this records because of after_create callback
sample = create :sample
create :samples_table, user: sample.user, team: sample.team
custom_field = create :custom_field, user: sample.user, team: sample.team
sample_custom_filed = create :sample_custom_field, sample: sample, custom_field: custom_field
expect(sample_custom_filed).to be_valid
end
it 'should be of class SampleCustomField' do
expect(subject.class).to eq SampleCustomField
end
describe 'Database table' do
it { should have_db_column :value }
it { should have_db_column :custom_field_id }
it { should have_db_column :sample_id }
it { should have_db_column :created_at }
it { should have_db_column :updated_at }
end
describe 'Relations' do
it { should belong_to :custom_field }
it { should belong_to :sample }
end
describe 'Validations' do
describe '#value' do
it { is_expected.to validate_presence_of :value }
it { is_expected.to validate_length_of(:value).is_at_most(Constants::NAME_MAX_LENGTH) }
end
describe '#custom_field' do
it { is_expected.to validate_presence_of :custom_field }
end
describe '#sample' do
it { is_expected.to validate_presence_of :sample }
end
end
end

View file

@ -1,53 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe SampleGroup, type: :model do
let(:sample_group) { build :sample_group }
it 'is valid' do
expect(sample_group).to be_valid
end
it 'should be of class SampleGroup' do
expect(subject.class).to eq SampleGroup
end
describe 'Database table' do
it { should have_db_column :name }
it { should have_db_column :color }
it { should have_db_column :team_id }
it { should have_db_column :created_at }
it { should have_db_column :updated_at }
it { should have_db_column :created_by_id }
it { should have_db_column :last_modified_by_id }
end
describe 'Relations' do
it { should belong_to :team }
it { should belong_to(:created_by).class_name('User') }
it { should belong_to(:last_modified_by).class_name('User') }
it 'have many samples' do
table = SampleGroup.reflect_on_association(:samples)
expect(table.macro).to eq(:has_many)
end
end
describe 'Validations' do
describe '#name' do
it { is_expected.to validate_presence_of :name }
it { is_expected.to validate_length_of(:name).is_at_most(Constants::NAME_MAX_LENGTH) }
it { expect(sample_group).to validate_uniqueness_of(:name).scoped_to(:team_id).case_insensitive }
end
describe '#color' do
it { is_expected.to validate_presence_of :color }
it { is_expected.to validate_length_of(:color).is_at_most(Constants::COLOR_MAX_LENGTH) }
end
describe '#team' do
it { is_expected.to validate_presence_of :team }
end
end
end

View file

@ -1,39 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe SampleMyModule, type: :model do
let(:sample_my_module) { build :sample_my_module }
it 'is valid' do
expect(sample_my_module).to be_valid
end
it 'should be of class SampleMyModule' do
expect(subject.class).to eq SampleMyModule
end
describe 'Database table' do
it { should have_db_column :sample_id }
it { should have_db_column :my_module_id }
it { should have_db_column :assigned_by_id }
it { should have_db_column :assigned_on }
end
describe 'Relations' do
it { should belong_to(:assigned_by).class_name('User') }
it { should belong_to :sample }
it { should belong_to :my_module }
end
describe 'Validations' do
describe '#sample' do
it { should validate_presence_of :sample }
it { expect(sample_my_module).to validate_uniqueness_of(:sample_id).scoped_to(:my_module_id) }
end
describe '#my_module' do
it { should validate_presence_of :my_module }
end
end
end

View file

@ -1,54 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe Sample, type: :model do
let(:sample) { build :sample }
it 'is valid' do
expect(sample).to be_valid
end
it 'should be of class Sample' do
expect(subject.class).to eq Sample
end
describe 'Database table' do
it { should have_db_column :name }
it { should have_db_column :user_id }
it { should have_db_column :team_id }
it { should have_db_column :created_at }
it { should have_db_column :updated_at }
it { should have_db_column :sample_group_id }
it { should have_db_column :sample_type_id }
it { should have_db_column :last_modified_by_id }
it { should have_db_column :nr_of_modules_assigned_to }
end
describe 'Relations' do
it { should belong_to :user }
it { should belong_to :team }
it { should belong_to :sample_group }
it { should belong_to :sample_type }
it { should belong_to(:last_modified_by).class_name('User') }
it { should have_many :sample_my_modules }
it { should have_many :my_modules }
it { should have_many :sample_custom_fields }
it { should have_many :custom_fields }
end
describe 'Validations' do
describe '#name' do
it { is_expected.to validate_presence_of :name }
it { is_expected.to validate_length_of(:name).is_at_most(Constants::NAME_MAX_LENGTH) }
end
describe '#user' do
it { is_expected.to validate_presence_of :user }
end
describe '#team' do
it { is_expected.to validate_presence_of :team }
end
end
end

View file

@ -1,46 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe SampleType, type: :model do
let(:sample_type) { build :sample_type }
it 'is valid' do
expect(sample_type).to be_valid
end
it 'should be of class SampleType' do
expect(subject.class).to eq SampleType
end
describe 'Database table' do
it { should have_db_column :name }
it { should have_db_column :team_id }
it { should have_db_column :created_at }
it { should have_db_column :updated_at }
it { should have_db_column :created_by_id }
it { should have_db_column :last_modified_by_id }
end
describe 'Relations' do
it { should belong_to :team }
it { should belong_to(:created_by).class_name('User') }
it { should belong_to(:last_modified_by).class_name('User') }
it 'have many samples' do
table = SampleType.reflect_on_association(:samples)
expect(table.macro).to eq(:has_many)
end
end
describe 'Validations' do
describe '#name' do
it { is_expected.to validate_presence_of :name }
it { is_expected.to validate_length_of(:name).is_at_most(Constants::NAME_MAX_LENGTH) }
it { expect(sample_type).to validate_uniqueness_of(:name).scoped_to(:team_id).case_insensitive }
end
describe '#team' do
it { is_expected.to validate_presence_of :team }
end
end
end

View file

@ -1,33 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe SamplesTable, type: :model do
let(:samples_table) { build :samples_table }
it 'is valid' do
expect(samples_table).to be_valid
end
it 'should be of class SamplesTable' do
expect(subject.class).to eq SamplesTable
end
describe 'Database table' do
it { should have_db_column :status }
it { should have_db_column :user_id }
it { should have_db_column :team_id }
it { should have_db_column :created_at }
it { should have_db_column :updated_at }
end
describe 'Relations' do
it { should belong_to :user }
it { should belong_to :team }
end
describe 'Validations' do
it { should validate_presence_of :team }
it { should validate_presence_of :user }
end
end

View file

@ -29,7 +29,7 @@ describe Step, type: :model do
describe 'Relations' do
it { should belong_to :user }
it { should belong_to :protocol }
it { should belong_to(:last_modified_by).class_name('User') }
it { should belong_to(:last_modified_by).class_name('User').optional }
it { should have_many :checklists }
it { should have_many :step_comments }
it { should have_many :step_assets }
@ -50,7 +50,7 @@ describe Step, type: :model do
end
it do
should validate_length_of(:description)
.is_at_most(Constants::RICH_TEXT_MAX_LENGTH)
.is_at_most(Constants::RICH_TEXT_MAX_LENGTH)
end
it { should validate_inclusion_of(:completed).in_array([true, false]) }
end

View file

@ -25,9 +25,9 @@ describe Table, type: :model do
end
describe 'Relations' do
it { should belong_to :team }
it { should belong_to(:created_by).class_name('User') }
it { should belong_to(:last_modified_by).class_name('User') }
it { should belong_to(:team).optional }
it { should belong_to(:created_by).class_name('User').optional }
it { should belong_to(:last_modified_by).class_name('User').optional }
it { should have_one :step_table }
it { should have_one :step }
it { should have_one :result_table }

View file

@ -25,8 +25,8 @@ describe Tag, type: :model do
describe 'Relations' do
it { should belong_to :project }
it { should belong_to(:created_by).class_name('User') }
it { should belong_to(:last_modified_by).class_name('User') }
it { should belong_to(:created_by).class_name('User').optional }
it { should belong_to(:last_modified_by).class_name('User').optional }
it { should have_many :my_module_tags }
it { should have_many :my_modules }
end

View file

@ -24,8 +24,8 @@ describe Team, type: :model do
end
describe 'Relations' do
it { should belong_to(:created_by).class_name('User') }
it { should belong_to(:last_modified_by).class_name('User') }
it { should belong_to(:created_by).class_name('User').optional }
it { should belong_to(:last_modified_by).class_name('User').optional }
it { should have_many :user_teams }
it { should have_many :users }
it { should have_many :samples }
@ -45,12 +45,12 @@ describe Team, type: :model do
it { should validate_presence_of :space_taken }
it do
should validate_length_of(:name)
.is_at_least(Constants::NAME_MIN_LENGTH)
.is_at_most(Constants::NAME_MAX_LENGTH)
.is_at_least(Constants::NAME_MIN_LENGTH)
.is_at_most(Constants::NAME_MAX_LENGTH)
end
it do
should validate_length_of(:description)
.is_at_most(Constants::TEXT_MAX_LENGTH)
.is_at_most(Constants::TEXT_MAX_LENGTH)
end
end
end

View file

@ -21,8 +21,8 @@ describe TinyMceAsset, type: :model do
end
describe 'Relations' do
it { should belong_to :team }
it { should belong_to :object }
it { should belong_to(:team).optional }
it { should belong_to(:object).optional }
end
describe 'Should be a valid object' do
@ -49,8 +49,8 @@ describe TinyMceAsset, type: :model do
describe '#generate_url' do
it 'create new url' do
image
expect(TinyMceAsset.generate_url(result_text.text)).to include 'sample_file.jpg'
image.update(object: result_text)
expect(TinyMceAsset.generate_url(result_text.text, result_text)).to include 'test.jpg'
end
end

View file

@ -24,7 +24,7 @@ describe UserMyModule, type: :model do
describe 'Relations' do
it { should belong_to :user }
it { should belong_to :my_module }
it { should belong_to(:assigned_by).class_name('User') }
it { should belong_to(:assigned_by).class_name('User').optional }
end
describe 'Validations' do

View file

@ -23,8 +23,8 @@ describe UserNotification, type: :model do
end
describe 'Relations' do
it { should belong_to :user }
it { should belong_to :notification }
it { should belong_to(:user).optional }
it { should belong_to(:notification).optional }
end
describe '#unseen_notification_count ' do
@ -54,9 +54,9 @@ describe UserNotification, type: :model do
end
it 'set the check status to false' do
expect {
expect do
UserNotification.seen_by_user(user)
}.to change { user_notification_one.reload.checked }.from(false).to(true)
end.to change { user_notification_one.reload.checked }.from(false).to(true)
end
end
end

View file

@ -30,7 +30,7 @@ describe UserProject, type: :model do
describe 'Relations' do
it { should belong_to :user }
it { should belong_to :project }
it { should belong_to(:assigned_by).class_name('User') }
it { should belong_to(:assigned_by).class_name('User').optional }
end
describe 'Should be a valid object' do

View file

@ -10,8 +10,8 @@ describe UserSystemNotification do
end
describe 'Associations' do
it { is_expected.to belong_to(:user) }
it { is_expected.to belong_to(:system_notification) }
it { should belong_to :user }
it { should belong_to :system_notification }
end
describe 'Methods' do

View file

@ -25,7 +25,7 @@ describe UserTeam, type: :model do
describe 'Relations' do
it { should belong_to :user }
it { should belong_to :team }
it { should belong_to(:assigned_by).class_name('User') }
it { should belong_to(:assigned_by).class_name('User').optional }
end
describe 'Validations' do

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Views::Datatables::DatatablesTeam, type: :model do
@ -14,10 +16,10 @@ RSpec.describe Views::Datatables::DatatablesTeam, type: :model do
describe 'is readonly' do
let(:user) { create :user }
it do
expect {
expect do
Views::Datatables::DatatablesTeam.create!(user_id: user.id)
}.to raise_error(ActiveRecord::ReadOnlyRecord,
'Views::Datatables::DatatablesTeam is marked as readonly')
end.to raise_error(ActiveRecord::ReadOnlyRecord,
'Views::Datatables::DatatablesTeam is marked as readonly')
end
end
end

View file

@ -24,6 +24,6 @@ describe ZipExport, type: :model do
end
describe 'Relations' do
it { should belong_to :user }
it { should belong_to(:user).optional }
end
end

View file

@ -103,6 +103,9 @@ RSpec.configure do |config|
# includes FactoryBot in rspec
config.include FactoryBot::Syntax::Methods
FactoryBot::SyntaxRunner.class_eval do
include ActionDispatch::TestProcess
end
# Devise
config.include Devise::Test::ControllerHelpers, type: :controller
config.include ApiHelper, type: :controller

View file

@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe "Api::V1::InventoriesController", type: :request do
RSpec.describe 'Api::V1::InventoriesController', type: :request do
before :all do
@user = create(:user)
@teams = create_list(:team, 2, created_by: @user)
@ -55,6 +55,7 @@ RSpec.describe "Api::V1::InventoriesController", type: :request do
id: @teams.first.repositories.first.id),
headers: @valid_headers
expect { hash_body = json }.not_to raise_exception
expect(hash_body[:data]).to match(
ActiveModelSerializers::SerializableResource
.new(@teams.first.repositories.first,

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe ClientApi::InvitationsService do
@ -7,40 +9,40 @@ describe ClientApi::InvitationsService do
it 'raises an ClientApi::CustomInvitationsError if ' \
'role is not assigned' do
expect {
expect do
ClientApi::InvitationsService.new(user: user_one,
team: team_one,
emails: emails_one)
}.to raise_error(ClientApi::CustomInvitationsError)
end.to raise_error(ClientApi::CustomInvitationsError)
end
it 'raises an ClientApi::CustomInvitationsError if ' \
'emails are not assigned' do
expect {
expect do
ClientApi::InvitationsService.new(user: user_one,
team: team_one,
role: 'normal_user')
}.to raise_error(ClientApi::CustomInvitationsError)
end.to raise_error(ClientApi::CustomInvitationsError)
end
it 'raises an ClientApi::CustomInvitationsError if ' \
'emails are not present' do
expect {
expect do
ClientApi::InvitationsService.new(user: user_one,
team: team_one,
role: 'normal_user',
emails: [])
}.to raise_error(ClientApi::CustomInvitationsError)
end.to raise_error(ClientApi::CustomInvitationsError)
end
it 'raises an ClientApi::CustomInvitationsError if ' \
'role is not included in UserTeam.roles' do
expect {
expect do
ClientApi::InvitationsService.new(user: user_one,
team: team_one,
role: 'abnormal_user',
emails: emails_one)
}.to raise_error(ClientApi::CustomInvitationsError)
end.to raise_error(ClientApi::CustomInvitationsError)
end
describe '#invitation' do

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
include ClientApi::Teams

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe ClientApi::TeamsService do
@ -5,21 +7,21 @@ describe ClientApi::TeamsService do
let(:user_one) { create :user }
it 'should raise an ClientApi::CustomTeamError if user is not assigned' do
expect {
expect do
ClientApi::TeamsService.new(team_id: team_one.id)
}.to raise_error(ClientApi::CustomTeamError)
end.to raise_error(ClientApi::CustomTeamError)
end
it 'should raise an ClientApi::CustomTeamError if team is not assigned' do
expect {
expect do
ClientApi::TeamsService.new(current_user: user_one)
}.to raise_error(ClientApi::CustomTeamError)
end.to raise_error(ClientApi::CustomTeamError)
end
it 'should raise an ClientApi::CustomTeamError if team is not user team' do
expect {
expect do
ClientApi::TeamsService.new(current_user: user_one, team_id: team_one.id)
}.to raise_error(ClientApi::CustomTeamError)
end.to raise_error(ClientApi::CustomTeamError)
end
describe '#change_current_team!' do
@ -75,9 +77,9 @@ describe ClientApi::TeamsService do
description: "super long: #{'a' * Constants::TEXT_MAX_LENGTH}"
}
)
expect {
expect do
team_service.update_team!
}.to raise_error(ClientApi::CustomTeamError)
end.to raise_error(ClientApi::CustomTeamError)
end
it 'should update the team description if the input is valid' do

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe ClientApi::UserTeamService do
@ -7,25 +9,25 @@ describe ClientApi::UserTeamService do
let(:user_team) { create :user_team, :admin, user: user_one, team: team_one }
it 'should raise ClientApi::CustomUserTeamError if user is not assigned' do
expect {
expect do
ClientApi::UserTeamService.new(
team_id: team_one.id,
user_team_id: user_team.id
)
}.to raise_error(ClientApi::CustomUserTeamError)
end.to raise_error(ClientApi::CustomUserTeamError)
end
it 'should raise ClientApi::CustomUserTeamError if team is not assigned' do
expect {
expect do
ClientApi::UserTeamService.new(user: user_one, user_team_id: user_team.id)
}.to raise_error(ClientApi::CustomUserTeamError)
end.to raise_error(ClientApi::CustomUserTeamError)
end
it 'should raise ClientApi::CustomUserTeamError if ' \
'user_team is not assigned' do
expect {
expect do
ClientApi::UserTeamService.new(user: user_one, team_id: team_one.id)
}.to raise_error(ClientApi::CustomUserTeamError)
end.to raise_error(ClientApi::CustomUserTeamError)
end
describe '#destroy_user_team_and_assign_new_team_owner!' do
@ -36,9 +38,9 @@ describe ClientApi::UserTeamService do
user_team_id: user_team.id,
user: user_one
)
expect {
expect do
ut_service.destroy_user_team_and_assign_new_team_owner!
}.to raise_error(ClientApi::CustomUserTeamError)
end.to raise_error(ClientApi::CustomUserTeamError)
end
it 'should destroy the user_team relation' do
@ -73,9 +75,9 @@ describe ClientApi::UserTeamService do
team_id: team_one.id,
user_team_id: user_team.id
)
expect {
expect do
ut_service.update_role!
}.to raise_error(ClientApi::CustomUserTeamError)
end.to raise_error(ClientApi::CustomUserTeamError)
end
it 'should update user role' do
@ -101,9 +103,9 @@ describe ClientApi::UserTeamService do
user_team_id: user_team.id,
role: 1
)
expect {
expect do
ut_service.update_role!
}.to raise_error(ClientApi::CustomUserTeamError)
end.to raise_error(ClientApi::CustomUserTeamError)
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
include ClientApi::Users

View file

@ -15,7 +15,6 @@ describe Experiments::GenerateWorkflowImageService do
old_filename = experiment.workflowimg_file_name
described_class.call(params)
experiment.reload
expect(experiment.workflowimg_file_name).not_to be == old_filename
end
end

View file

@ -53,7 +53,7 @@ describe TeamImporter do
it { expect(@exp.restored_by_id).to be_nil }
it { expect(@exp.restored_on).to be_nil }
it { expect(@exp.workflowimg.exists?).to eq(true) }
it { expect(@exp.workflowimg.attached?).to eq(true) }
end
describe 'Module groups' do
@ -155,9 +155,7 @@ describe TeamImporter do
)
# Check for lonely tasks
if json_module['my_module_group_id'].nil?
expect(db_module.my_module_group_id).to be_nil
end
expect(db_module.my_module_group_id).to be_nil if json_module['my_module_group_id'].nil?
expect(db_module.nr_of_assigned_samples).to be_zero
@ -281,13 +279,17 @@ describe TeamImporter do
)
json_step['assets'].each do |json_asset|
db_asset = db_step.assets.find_by(
file_file_name: json_asset['file_file_name']
blob_id = ActiveRecord::Base.connection.execute(\
"SELECT active_storage_blobs.id "\
"FROM active_storage_blobs "\
"WHERE active_storage_blobs.filename = '#{json_asset['asset_blob']['filename']}' LIMIT 1"
)
db_asset = db_step.assets.joins(:file_attachment)
.where('active_storage_attachments.blob_id' => blob_id.as_json[0]['id'].to_i).first
# Basic fields
expect(db_asset.created_at).to eq(
json_asset['created_at'].to_time
json_asset['asset']['created_at'].to_time
)
expect(db_asset.created_by_id).to eq USER_ID
expect(db_asset.last_modified_by_id).to eq USER_ID
@ -295,24 +297,24 @@ describe TeamImporter do
# Other fields
expect(db_asset.estimated_size).to eq(
json_asset['estimated_size']
json_asset['asset']['estimated_size']
)
expect(db_asset.file_content_type).to eq(
json_asset['file_content_type']
expect(db_asset.blob.content_type).to eq(
json_asset['asset_blob']['content_type']
)
expect(db_asset.file_file_size).to eq(
json_asset['file_file_size']
expect(db_asset.blob.byte_size).to eq(
json_asset['asset_blob']['byte_size']
)
expect(db_asset.file_updated_at).to be_within(10.seconds)
expect(db_asset.blob.created_at).to be_within(10.seconds)
.of(Time.now)
expect(db_asset.lock).to eq(
json_asset['lock']
json_asset['asset']['lock']
)
expect(db_asset.lock_ttl).to eq(
json_asset['lock_ttl']
json_asset['asset']['lock_ttl']
)
expect(db_asset.version).to eq(
json_asset['version']
json_asset['asset']['version']
)
end
@ -385,9 +387,7 @@ describe TeamImporter do
end
#
# User assigns to the the module
unless my_module['user_my_modules'].empty?
expect(db_module.user_my_modules.first.user_id).to eq USER_ID
end
expect(db_module.user_my_modules.first.user_id).to eq USER_ID unless my_module['user_my_modules'].empty?
end
end
end

View file

@ -303,22 +303,29 @@
{
"assets": [
{
"created_at": "2019-01-21T13:09:35.615Z",
"created_by_id": 1,
"estimated_size": 17799,
"file_content_type": "image/png",
"file_file_name": "100gen_line_bending.png",
"file_file_size": 16181,
"file_present": true,
"file_processing": false,
"file_updated_at": "2019-01-21T13:10:05.392Z",
"id": 21,
"last_modified_by_id": null,
"lock": null,
"lock_ttl": null,
"team_id": 1,
"updated_at": "2019-01-21T13:10:06.290Z",
"version": 1
"asset": {
"created_at": "2019-01-21T13:09:35.615Z",
"created_by_id": 1,
"estimated_size": 17799,
"file_content_type": null,
"file_file_name": null,
"file_file_size": null,
"file_present": true,
"file_processing": null,
"file_updated_at": "2019-01-21T13:10:05.392Z",
"id": 21,
"last_modified_by_id": null,
"lock": null,
"lock_ttl": null,
"team_id": 1,
"updated_at": "2019-01-21T13:10:06.290Z",
"version": 1
},
"asset_blob": {
"filename": "100gen_line_bending.png",
"content_type": "image/png",
"byte_size": 16181
}
}
],
"checklists": [],
@ -597,22 +604,29 @@
},
{
"asset": {
"created_at": "2019-01-21T12:45:29.138Z",
"created_by_id": 1,
"estimated_size": 232,
"file_content_type": "text/plain",
"file_file_name": "samples.txt",
"file_file_size": 69,
"file_present": true,
"file_processing": false,
"file_updated_at": "2019-01-21T12:45:28.889Z",
"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": {
"created_at": "2019-01-21T12:45:29.138Z",
"created_by_id": 1,
"estimated_size": 232,
"file_content_type": null,
"file_file_name": null,
"file_file_size": null,
"file_present": true,
"file_processing": null,
"file_updated_at": "2019-01-21T12:45:28.889Z",
"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,
@ -1069,22 +1083,29 @@
{
"assets": [
{
"created_at": "2019-01-21T12:45:32.296Z",
"created_by_id": 1,
"estimated_size": 1129370,
"file_content_type": "application/pdf",
"file_file_name": "G2938-90034_KitRNA6000Nano_ebook.pdf",
"file_file_size": 974068,
"file_present": true,
"file_processing": false,
"file_updated_at": "2019-01-21T12:45:32.237Z",
"id": 8,
"last_modified_by_id": 1,
"lock": null,
"lock_ttl": null,
"team_id": 1,
"updated_at": "2019-01-21T13:06:04.590Z",
"version": 1
"asset": {
"created_at": "2019-01-21T12:45:32.296Z",
"created_by_id": 1,
"estimated_size": 1129370,
"file_content_type": null,
"file_file_name": null,
"file_file_size": null,
"file_present": true,
"file_processing": null,
"file_updated_at": "2019-01-21T12:45:32.237Z",
"id": 8,
"last_modified_by_id": 1,
"lock": null,
"lock_ttl": null,
"team_id": 1,
"updated_at": "2019-01-21T13:06:04.590Z",
"version": 1
},
"asset_blob": {
"filename": "G2938-90034_KitRNA6000Nano_ebook.pdf",
"content_type": "application/pdf",
"byte_size": 974068
}
}
],
"checklists": [],
@ -1118,22 +1139,29 @@
"results": [
{
"asset": {
"created_at": "2019-01-21T12:45:32.847Z",
"created_by_id": 1,
"estimated_size": 46131,
"file_content_type": "image/jpeg",
"file_file_name": "Bioanalyser_result.JPG",
"file_file_size": 41938,
"file_present": true,
"file_processing": false,
"file_updated_at": "2019-01-21T12:45:43.655Z",
"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": {
"created_at": "2019-01-21T12:45:32.847Z",
"created_by_id": 1,
"estimated_size": 46131,
"file_content_type": null,
"file_file_name": null,
"file_file_size": null,
"file_present": true,
"file_processing": null,
"file_updated_at": "2019-01-21T12:45:43.655Z",
"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,

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe RepositoryActions::DuplicateRows do

View file

@ -65,7 +65,7 @@ describe RepositoryDatatableService do
contitions = subject.send(:build_conditions, params)
expect(contitions[:search_value]).to eq 'row'
expect(contitions[:order_by_column]).to eq(
{ column: 3, dir: 'asc' }
column: 3, dir: 'asc'
)
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe RepositoryTableStateColumnUpdateService do
@ -13,7 +15,7 @@ describe RepositoryTableStateColumnUpdateService do
create :repository_column, name: 'My column 1',
repository: repository,
data_type: :RepositoryTextValue
end
end
let!(:repository_column_2) do
create :repository_column, name: 'My column 2',
repository: repository,
@ -32,12 +34,12 @@ describe RepositoryTableStateColumnUpdateService do
last_modified_by: user_2
end
let!(:default_order) do
{ '0' => ['2', 'asc'] }
{ '0' => %w(2 asc) }
end
let!(:default_column_def) do
{ 'visible' => 'true',
'searchable' => 'true',
'search' => { 'search' => '',
'search' => { 'search' => '',
'smart' => 'true',
'regex' => 'false',
'caseInsensitive' => 'true' } }
@ -51,7 +53,7 @@ describe RepositoryTableStateColumnUpdateService do
RepositoryTableStateService.new(user_1, repository).create_default_state
end
let!(:initial_state_2) do
RepositoryTableStateService.new(user_2, repository).create_default_state
RepositoryTableStateService.new(user_2, repository).create_default_state
end
it 'should keep default repository states valid' do
@ -81,11 +83,11 @@ describe RepositoryTableStateColumnUpdateService do
end
it 'should keep order as it was' do
initial_state_1.state['order'] = { '0' => ['3', 'desc'] }
initial_state_1.state['order'] = { '0' => %w(3 desc) }
RepositoryTableStateService.new(user_1, repository).update_state(
initial_state_1.state
)
initial_state_2.state['order'] = { '0' => ['4', 'asc'] }
initial_state_2.state['order'] = { '0' => %w(4 asc) }
RepositoryTableStateService.new(user_2, repository).update_state(
initial_state_2.state
)
@ -94,9 +96,9 @@ describe RepositoryTableStateColumnUpdateService do
service.update_states_with_new_column(repository)
state_1 = RepositoryTableStateService.new(user_1, repository).load_state
expect(state_1.state['order']).to eq({ '0' => ['3', 'desc'] })
expect(state_1.state['order']).to eq('0' => %w(3 desc))
state_2 = RepositoryTableStateService.new(user_2, repository).load_state
expect(state_2.state['order']).to eq({ '0' => ['4', 'asc'] })
expect(state_2.state['order']).to eq('0' => %w(4 asc))
end
it 'should keep search as it was' do
@ -131,7 +133,7 @@ describe RepositoryTableStateColumnUpdateService do
state_1 = RepositoryTableStateService.new(user_1, repository).load_state
expect(state_1.state['columns']).to eq(
cols_1.merge({'8' => default_column_def, '9' => default_column_def})
cols_1.merge('8' => default_column_def, '9' => default_column_def)
)
state_2 = RepositoryTableStateService.new(user_2, repository).load_state
expect(state_2.state['columns']).to eq(
@ -141,12 +143,12 @@ describe RepositoryTableStateColumnUpdateService do
it 'should keep column order as it was' do
initial_state_1.state['ColReorder'] =
['5', '3', '2', '0', '1', '4', '6', '7']
%w(5 3 2 0 1 4 6 7)
RepositoryTableStateService.new(user_1, repository).update_state(
initial_state_1.state
)
initial_state_2.state['ColReorder'] =
['0', '6', '1', '4', '5', '7', '2', '3']
%w(0 6 1 4 5 7 2 3)
RepositoryTableStateService.new(user_2, repository).update_state(
initial_state_2.state
)
@ -156,11 +158,11 @@ describe RepositoryTableStateColumnUpdateService do
state_1 = RepositoryTableStateService.new(user_1, repository).load_state
expect(state_1.state['ColReorder']).to eq(
['5', '3', '2', '0', '1', '4', '6', '7', '8', '9']
%w(5 3 2 0 1 4 6 7 8 9)
)
state_2 = RepositoryTableStateService.new(user_2, repository).load_state
expect(state_2.state['ColReorder']).to eq(
['0', '6', '1', '4', '5', '7', '2', '3', '8', '9']
%w(0 6 1 4 5 7 2 3 8 9)
)
end
end
@ -170,7 +172,7 @@ describe RepositoryTableStateColumnUpdateService do
RepositoryTableStateService.new(user_1, repository).create_default_state
end
let!(:initial_state_2) do
RepositoryTableStateService.new(user_2, repository).create_default_state
RepositoryTableStateService.new(user_2, repository).create_default_state
end
# For column removal, we often use the index '6' twice - first, to
@ -204,11 +206,11 @@ describe RepositoryTableStateColumnUpdateService do
end
it 'should keep order as it was' do
initial_state_1.state['order'] = { '0' => ['3', 'desc'] }
initial_state_1.state['order'] = { '0' => %w(3 desc) }
RepositoryTableStateService.new(user_1, repository).update_state(
initial_state_1.state
)
initial_state_2.state['order'] = { '0' => ['7', 'asc'] }
initial_state_2.state['order'] = { '0' => %w(7 asc) }
RepositoryTableStateService.new(user_2, repository).update_state(
initial_state_2.state
)
@ -217,7 +219,7 @@ describe RepositoryTableStateColumnUpdateService do
service.update_states_with_removed_column(repository, '6')
state_1 = RepositoryTableStateService.new(user_1, repository).load_state
expect(state_1.state['order']).to eq({ '0' => ['3', 'desc'] })
expect(state_1.state['order']).to eq('0' => %w(3 desc))
state_2 = RepositoryTableStateService.new(user_2, repository).load_state
expect(state_2.state['order']).to eq(default_order)
end
@ -270,12 +272,12 @@ describe RepositoryTableStateColumnUpdateService do
it 'should keep column order as it was' do
initial_state_1.state['ColReorder'] =
['5', '3', '2', '0', '1', '4', '6', '7']
%w(5 3 2 0 1 4 6 7)
RepositoryTableStateService.new(user_1, repository).update_state(
initial_state_1.state
)
initial_state_2.state['ColReorder'] =
['0', '6', '1', '4', '5', '7', '2', '3']
%w(0 6 1 4 5 7 2 3)
RepositoryTableStateService.new(user_2, repository).update_state(
initial_state_2.state
)
@ -285,11 +287,11 @@ describe RepositoryTableStateColumnUpdateService do
state_1 = RepositoryTableStateService.new(user_1, repository).load_state
expect(state_1.state['ColReorder']).to eq(
['5', '3', '2', '0', '1', '4']
%w(5 3 2 0 1 4)
)
state_2 = RepositoryTableStateService.new(user_2, repository).load_state
expect(state_2.state['ColReorder']).to eq(
['0', '1', '4', '5', '2', '3']
%w(0 1 4 5 2 3)
)
end
end
@ -308,12 +310,12 @@ describe RepositoryTableStateColumnUpdateService do
let!(:initial_state) do
state = RepositoryTableStateService.new(user_1, repository)
.create_default_state
state.state['order'] = {'0' => ['8', 'desc']}
state.state['order'] = { '0' => %w(8 desc) }
(0..9).each do |idx|
state.state['columns'][idx.to_s]['search']['search'] = "search_#{idx}"
end
state.state['ColReorder'] =
['0', '1', '2', '9', '8', '4', '7', '3', '5', '6']
%w(0 1 2 9 8 4 7 3 5 6)
RepositoryTableStateService.new(user_1, repository).update_state(
state.state
)
@ -328,7 +330,7 @@ describe RepositoryTableStateColumnUpdateService do
state = RepositoryTableStateService.new(user_1, repository).load_state
expect(state).to be_valid_repository_table_state(5)
expect(state.state['ColReorder']).to eq(
['0', '1', '2', '9', '8', '4', '7', '3', '5', '6', '10']
%w(0 1 2 9 8 4 7 3 5 6 10)
)
service.update_states_with_removed_column(repository, '7')
@ -336,25 +338,25 @@ describe RepositoryTableStateColumnUpdateService do
state = RepositoryTableStateService.new(user_1, repository).load_state
expect(state).to be_valid_repository_table_state(4)
expect(state.state['ColReorder']).to eq(
['0', '1', '2', '8', '7', '4', '3', '5', '6', '9']
%w(0 1 2 8 7 4 3 5 6 9)
)
expect(state.state['order']).to eq ({'0' => ['7', 'desc']})
expect(state.state['order']).to eq('0' => %w(7 desc))
service.update_states_with_removed_column(repository, '7')
state = RepositoryTableStateService.new(user_1, repository).load_state
expect(state).to be_valid_repository_table_state(3)
expect(state.state['ColReorder']).to eq(
['0', '1', '2', '7', '4', '3', '5', '6', '8']
%w(0 1 2 7 4 3 5 6 8)
)
expect(state.state['order']).to eq ({'0' => ['2', 'asc']})
expect(state.state['order']).to eq('0' => %w(2 asc))
service.update_states_with_removed_column(repository, '7')
state = RepositoryTableStateService.new(user_1, repository).load_state
expect(state).to be_valid_repository_table_state(2)
expect(state.state['ColReorder']).to eq(
['0', '1', '2', '4', '3', '5', '6', '7']
%w(0 1 2 4 3 5 6 7)
)
service.update_states_with_new_column(repository)
@ -363,7 +365,7 @@ describe RepositoryTableStateColumnUpdateService do
state = RepositoryTableStateService.new(user_1, repository).load_state
expect(state).to be_valid_repository_table_state(4)
expect(state.state['ColReorder']).to eq(
['0', '1', '2', '4', '3', '5', '6', '7', '8', '9']
%w(0 1 2 4 3 5 6 7 8 9)
)
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe RepositoryTableStateService do
@ -12,7 +14,7 @@ describe RepositoryTableStateService do
create :repository_column, name: 'My column 1',
repository: repository,
data_type: :RepositoryTextValue
end
end
let!(:repository_column_2) do
create :repository_column, name: 'My column 2',
repository: repository,

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
require 'zip'
@ -69,7 +71,8 @@ describe RepositoryZipExport, type: :background_job do
ZipExport.skip_callback(:create, :after, :self_destruct)
RepositoryZipExport.generate_zip(params, repository, user)
csv_zip_file = ZipExport.first.zip_file
parsed_csv_content = Zip::File.open(csv_zip_file.path) do |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|
csv_file = zip_file.glob('*.csv').first
csv_content = csv_file.get_input_stream.read
CSV.parse(csv_content, headers: true)

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
require 'smart_annotations/html_preview'

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe SmartAnnotations::PermissionEval do

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe SmartAnnotations::TagToHtml do
@ -32,9 +34,9 @@ describe SmartAnnotations::TagToHtml do
describe '#fetch_object/2' do
it 'rises an error if type is not valid' do
expect {
expect do
subject.send(:fetch_object, 'banana', project.id)
}.to raise_error(ActiveRecord::RecordNotFound)
end.to raise_error(ActiveRecord::RecordNotFound)
end
it 'returns the required object' do

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe SmartAnnotations::TagToText do
@ -29,9 +31,9 @@ describe SmartAnnotations::TagToText do
describe '#fetch_object/2' do
it 'rises an error if type is not valid' do
expect {
expect do
subject.send(:fetch_object, 'banana', project.id)
}.to raise_error(ActiveRecord::RecordNotFound)
end.to raise_error(ActiveRecord::RecordNotFound)
end
it 'returns the required object' do
@ -52,7 +54,7 @@ describe SmartAnnotations::TagToText do
random_text = "Sec:[@#{user_two.full_name}~#{user_two.id.base62_encode}]"
expect(
subject.send(:parse_users_annotations, user, team, random_text)
).to eq "Sec:"
).to eq 'Sec:'
end
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
require 'smart_annotations/text_preview'

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Tasks::SamplesToRepositoryMigrationService do

View file

@ -50,7 +50,7 @@ describe TemplatesService do
tmpl_res = tmpl_task.results.find_by_name(demo_res.name)
expect(tmpl_res.name).to eq(demo_res.name)
if demo_res.asset
expect(tmpl_res.asset.file.exists?).to eq(true)
expect(tmpl_res.asset.file.attached?).to eq(true)
expect(demo_res.asset.file_file_name)
.to eq(tmpl_res.asset.file_file_name)
elsif demo_res.table
@ -65,6 +65,7 @@ describe TemplatesService do
demo_task.protocol.steps.size.positive?
next
end
demo_task.protocol.steps.each do |demo_step|
tmpl_step = tmpl_task.protocol.steps.find_by_name(demo_step.name)
expect(demo_step.name).to eq(tmpl_step.name)
@ -74,7 +75,7 @@ describe TemplatesService do
.to match_array(tmpl_step.assets.pluck(:file_file_name))
end
tmpl_step.assets.each do |asset|
expect(asset.file.exists?).to eq(true)
expect(asset.file.attached?).to eq(true)
end
if demo_step.tables.present?
expect(demo_step.tables.pluck(:contents))