Skip to content

Commit

Permalink
Add rails app for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
lardawge committed Aug 7, 2023
1 parent 23e3982 commit e769d4d
Show file tree
Hide file tree
Showing 56 changed files with 821 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source "http://rubygems.org"

# Specify your gem's dependencies in carrierwave_backgrounder.gemspec
gemspec
gemspec
7 changes: 6 additions & 1 deletion carrierwave_backgrounder.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_dependency "carrierwave", [">= 0.5", "< 2.3"]
s.add_dependency "carrierwave", [">= 0.5", "< 4.0"]

s.add_development_dependency "rspec", ["~> 3.12"]
s.add_development_dependency "rake"
s.add_development_dependency "rails"
s.add_development_dependency "rspec-rails"
s.add_development_dependency "sqlite3"
s.add_development_dependency "sidekiq"
s.add_development_dependency "pry"
end
15 changes: 15 additions & 0 deletions spec/integrations/store_in_background_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'rails_helper'

RSpec.describe '::store_in_background', images: true do
let(:user) { User.new }

it 'creates a temp file and stores the path' do
expect {
user.update(avatar: File.open('spec/support/fixtures/images/test-1.jpg'))
}.to change { Dir.entries('spec/support/dummy_app/tmp/images').size }.by(1)

expect(user.avatar_tmp).to include('test-1.jpg')
end

it 'creates a background job in queue'
end
25 changes: 25 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'

require_relative 'support/dummy_app/config/environment'
require 'rspec/rails'
require 'backgrounder/railtie'

begin
ActiveRecord::Migration.maintain_test_schema!
rescue ActiveRecord::PendingMigrationError => e
abort e.to_s.strip
end

RSpec.configure do |config|
config.before do
CarrierWave::Backgrounder::Railtie.initializers.each(&:run)
end

config.after(:example, images: true) do
FileUtils.rm_rf Dir.glob("spec/support/dummy_app/tmp/images/*")
end
end

ActiveRecord::Schema.verbose = false
load 'support/dummy_app/db/schema.rb' # use db agnostic schema by default
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'rubygems'
require 'bundler/setup'
require 'logger'
require 'pry'
require 'carrierwave_backgrounder'

module WarningSuppression
Expand Down
20 changes: 0 additions & 20 deletions spec/support/backend_constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,6 @@ module Resque
module Qu
end

module Sidekiq
module Client
end

module Worker
def self.included(base)
base.extend(ClassMethods)
end

module ClassMethods
def sidekiq_options(opts = {})
opts
end

def client_push(item)
end
end
end
end

module QC
end

Expand Down
48 changes: 48 additions & 0 deletions spec/support/dummy_app/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby "3.0.0"

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.6"

# Use sqlite3 as the database for Active Record
gem "sqlite3", "~> 1.4"

# Use the Puma web server [https://github.com/puma/puma]
# gem "puma", "~> 5.0"

gem 'carrierwave'
gem 'carrierwave_backgrounder', path: "../../../"

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
# gem "jbuilder"

# Use Redis adapter to run Action Cable in production
# gem "redis", "~> 4.0"

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"

# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
# gem "rack-cors"

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri mingw x64_mingw ]
end

group :development do
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"
end

24 changes: 24 additions & 0 deletions spec/support/dummy_app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# README

This README would normally document whatever steps are necessary to get the
application up and running.

Things you may want to cover:

* Ruby version

* System dependencies

* Configuration

* Database creation

* Database initialization

* How to run the test suite

* Services (job queues, cache servers, search engines, etc.)

* Deployment instructions

* ...
6 changes: 6 additions & 0 deletions spec/support/dummy_app/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative "config/application"

Rails.application.load_tasks
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ApplicationController < ActionController::API
end
Empty file.
7 changes: 7 additions & 0 deletions spec/support/dummy_app/app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ApplicationJob < ActiveJob::Base
# Automatically retry jobs that encountered a deadlock
# retry_on ActiveRecord::Deadlocked

# Most jobs are safe to ignore if the underlying records are no longer available
# discard_on ActiveJob::DeserializationError
end
3 changes: 3 additions & 0 deletions spec/support/dummy_app/app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
primary_abstract_class
end
Empty file.
4 changes: 4 additions & 0 deletions spec/support/dummy_app/app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class User < ApplicationRecord
mount_uploader :avatar, AvatarUploader
store_in_background :avatar
end
67 changes: 67 additions & 0 deletions spec/support/dummy_app/app/uploaders/avatar_uploader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
require 'carrierwave'

class AvatarUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
include CarrierWave::MiniMagick
include ::CarrierWave::Backgrounder::Delay

# Choose what kind of storage to use for this uploader:
# storage :aws
storage :file
# storage :fog

# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

def cache_dir
"../tmp/images"
end

# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url(*args)
# # For Rails 3.1+ asset pipeline compatibility:
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
#
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end

# Process files as they are uploaded:
# process scale: [200, 300]
#
# def scale(width, height)
# # do something
# end

# Create different versions of your uploaded files:
version :thumb do
process resize_to_fit: [50, 50]
end

version :large_1920 do
process resize_to_limit: [1920, 1920]
end

version :medium_1024 do
process resize_to_limit: [1024, 1024]
end

version :small_640 do
process resize_to_limit: [640, 640]
end

# Add an allowlist of extensions which are allowed to be uploaded.
# For images you might use something like this:
# def extension_allowlist
# %w(jpg jpeg gif png)
# end

# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "something.jpg" if original_filename
# end
end
114 changes: 114 additions & 0 deletions spec/support/dummy_app/bin/bundle
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'bundle' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "rubygems"

m = Module.new do
module_function

def invoked_as_script?
File.expand_path($0) == File.expand_path(__FILE__)
end

def env_var_version
ENV["BUNDLER_VERSION"]
end

def cli_arg_version
return unless invoked_as_script? # don't want to hijack other binstubs
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
bundler_version = nil
update_index = nil
ARGV.each_with_index do |a, i|
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
bundler_version = a
end
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
bundler_version = $1
update_index = i
end
bundler_version
end

def gemfile
gemfile = ENV["BUNDLE_GEMFILE"]
return gemfile if gemfile && !gemfile.empty?

File.expand_path("../../Gemfile", __FILE__)
end

def lockfile
lockfile =
case File.basename(gemfile)
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
else "#{gemfile}.lock"
end
File.expand_path(lockfile)
end

def lockfile_version
return unless File.file?(lockfile)
lockfile_contents = File.read(lockfile)
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
Regexp.last_match(1)
end

def bundler_version
@bundler_version ||=
env_var_version || cli_arg_version ||
lockfile_version
end

def bundler_requirement
return "#{Gem::Requirement.default}.a" unless bundler_version

bundler_gem_version = Gem::Version.new(bundler_version)

requirement = bundler_gem_version.approximate_recommendation

return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")

requirement += ".a" if bundler_gem_version.prerelease?

requirement
end

def load_bundler!
ENV["BUNDLE_GEMFILE"] ||= gemfile

activate_bundler
end

def activate_bundler
gem_error = activation_error_handling do
gem "bundler", bundler_requirement
end
return if gem_error.nil?
require_error = activation_error_handling do
require "bundler/version"
end
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
exit 42
end

def activation_error_handling
yield
nil
rescue StandardError, LoadError => e
e
end
end

m.load_bundler!

if m.invoked_as_script?
load Gem.bin_path("bundler", "bundle")
end
4 changes: 4 additions & 0 deletions spec/support/dummy_app/bin/rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path("../config/application", __dir__)
require_relative "../config/boot"
require "rails/commands"
4 changes: 4 additions & 0 deletions spec/support/dummy_app/bin/rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
require_relative "../config/boot"
require "rake"
Rake.application.run
Loading

0 comments on commit e769d4d

Please sign in to comment.