Sha256: 0cc2fdd4374396e8810384def4e93850599ea25a16ea21da6ad0ba62395ec8c1

Contents?: true

Size: 1.81 KB

Versions: 31

Compression:

Stored size: 1.81 KB

Contents

require 'bundler/inline'

gemfile(true) do
  source 'https://rubygems.org'

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  gem 'rails', '6.0.3'
  gem 'sqlite3'
  gem 'format_parser', path: './'
end

require 'active_record/railtie'
require 'active_storage/engine'
require 'tmpdir'

class TestApp < Rails::Application
  config.root = __dir__
  config.hosts << 'example.org'
  config.eager_load = false
  config.session_store :cookie_store, key: 'cookie_store_key'
  secrets.secret_key_base = 'secret_key_base'

  config.logger = Logger.new('/dev/null')

  config.active_storage.service = :local
  config.active_storage.service_configurations = {
    local: {
      root: Dir.tmpdir,
      service: 'Disk'
    }
  }

  config.active_storage.analyzers.prepend FormatParser::ActiveStorage::BlobAnalyzer
end

ENV['DATABASE_URL'] = 'sqlite3::memory:'

Rails.application.initialize!

require ActiveStorage::Engine.root.join('db/migrate/20170806125915_create_active_storage_tables.rb').to_s

ActiveRecord::Schema.define do
  CreateActiveStorageTables.new.change

  create_table :users, force: true
end

class User < ActiveRecord::Base
  has_one_attached :profile_picture
end

require 'minitest/autorun'
require 'open-uri'

fixtures_dir = File.join(File.dirname(__FILE__), '../../fixtures')

describe User do
  describe "profile_picture's metadatas" do
    it 'parse metadatas with format_parser' do
      fixture_path = fixtures_dir + '/PNG/cat.png'
      user = User.create
      user.profile_picture.attach(
        filename: 'cat.png',
        io: File.open(fixture_path, 'rb')
      )

      user.profile_picture.analyze

      _(user.profile_picture.metadata[:width_px]).must_equal 600
      _(user.profile_picture.metadata[:height_px]).must_equal 600
      _(user.profile_picture.metadata[:color_mode]).must_equal 'rgba'
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
format_parser-1.7.0 spec/integration/active_storage/rails_app.rb
format_parser-1.6.0 spec/integration/active_storage/rails_app.rb
format_parser-1.5.0 spec/integration/active_storage/rails_app.rb
format_parser-1.4.2 spec/integration/active_storage/rails_app.rb
format_parser-1.4.1 spec/integration/active_storage/rails_app.rb
format_parser-1.4.0 spec/integration/active_storage/rails_app.rb
format_parser-1.3.0 spec/integration/active_storage/rails_app.rb
format_parser-1.2.1 spec/integration/active_storage/rails_app.rb
format_parser-1.2.0 spec/integration/active_storage/rails_app.rb
format_parser-1.1.0 spec/integration/active_storage/rails_app.rb
format_parser-1.0.0 spec/integration/active_storage/rails_app.rb