mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 14:45:56 +08:00
Fix tests for active storage
This commit is contained in:
parent
618f0cc334
commit
a4b2825258
1
Gemfile
1
Gemfile
|
@ -32,6 +32,7 @@ gem 'json-jwt'
|
|||
gem 'jwt', '~> 1.5'
|
||||
gem 'kaminari'
|
||||
gem 'rack-attack'
|
||||
gem 'jsonapi-renderer', '= 0.2.0'
|
||||
|
||||
# JS datetime library, requirement of datetime picker
|
||||
gem 'momentjs-rails', '~> 2.17.1'
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RepositoryAssetValue < ApplicationRecord
|
||||
belongs_to :created_by,
|
||||
foreign_key: :created_by_id,
|
||||
|
@ -28,8 +30,7 @@ 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!
|
||||
|
@ -38,15 +39,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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue