diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..c99d2e7 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--require spec_helper diff --git a/.rubocop.yml b/.rubocop.yml index 76e6e9d..ab0e1ef 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,8 +4,20 @@ AllCops: Layout/LineLength: Max: 150 -Style/FrozenStringLiteralComment: +Style/Documentation: Enabled: false -Style/Documentation: - Enabled: false \ No newline at end of file +Metrics/BlockLength: + Exclude: + - 'test/dummy/db/seeds.rb' + - 'test/dummy/db/schema.rb' + - 'spec/requests/activejob_web/jobs_spec.rb' + +Metrics/MethodLength: + Exclude: + - 'db/migrate/20231024051840_create_jobs.rb' + - 'db/migrate/20231030145254_create_active_storage_tables.active_storage.rb' + +Metrics/AbcSize: + Exclude: + - 'db/migrate/20231030145254_create_active_storage_tables.active_storage.rb' diff --git a/Gemfile b/Gemfile index e7e5a00..37501de 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } @@ -8,6 +10,8 @@ gem 'puma' gem 'pg' +gem 'image_processing', '>= 1.2' + gem 'sprockets-rails' group :development do @@ -17,8 +21,8 @@ group :development do end group :development, :test do + gem 'rspec-rails' gem 'rubocop', require: false end -# Start debugger with binding.b [https://github.com/ruby/debug] -# gem "debug", ">= 1.0.0" +gem 'rails-controller-testing', '~> 1.0', '>= 1.0.5' diff --git a/Gemfile.lock b/Gemfile.lock index 555a3d7..61f491f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -37,6 +37,7 @@ GEM actionview (= 7.1.1) activesupport (= 7.1.1) nokogiri (>= 1.8.5) + racc rack (>= 2.2.4) rack-session (>= 1.0.1) rack-test (>= 0.6.3) @@ -83,7 +84,8 @@ GEM ast (2.4.2) base64 (0.1.1) bigdecimal (3.1.4) - brakeman (6.0.1) + brakeman (6.1.1) + racc builder (3.2.4) bundler-audit (0.9.1) bundler (>= 1.2.0, < 3) @@ -93,19 +95,24 @@ GEM connection_pool (2.4.1) crass (1.0.6) date (3.3.3) + diff-lcs (1.5.0) drb (2.1.1) ruby2_keywords erubi (1.12.0) + ffi (1.16.3) globalid (1.2.1) activesupport (>= 6.1) i18n (1.14.1) concurrent-ruby (~> 1.0) + image_processing (1.12.2) + mini_magick (>= 4.9.5, < 5) + ruby-vips (>= 2.0.17, < 3) iniparse (1.5.0) io-console (0.6.0) irb (1.8.3) rdoc reline (>= 0.3.8) - json (2.6.3) + json (2.7.1) language_server-protocol (3.17.0.3) loofah (2.21.4) crass (~> 1.0.2) @@ -116,6 +123,7 @@ GEM net-pop net-smtp marcel (1.0.2) + mini_magick (4.12.0) mini_mime (1.1.5) minitest (5.20.0) mutex_m (0.1.2) @@ -135,8 +143,8 @@ GEM childprocess (>= 0.6.3, < 5) iniparse (~> 1.4) rexml (~> 3.2) - parallel (1.23.0) - parser (3.2.2.4) + parallel (1.24.0) + parser (3.3.0.4) ast (~> 2.4.1) racc pg (1.5.4) @@ -167,6 +175,10 @@ GEM activesupport (= 7.1.1) bundler (>= 1.15.0) railties (= 7.1.1) + rails-controller-testing (1.0.5) + actionpack (>= 5.0.1.rc1) + actionview (>= 5.0.1.rc1) + activesupport (>= 5.0.1.rc1) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -186,25 +198,43 @@ GEM rake (13.0.6) rdoc (6.5.0) psych (>= 4.0.0) - regexp_parser (2.8.2) + regexp_parser (2.9.0) reline (0.3.9) io-console (~> 0.5) rexml (3.2.6) - rubocop (1.57.1) - base64 (~> 0.1.1) + rspec-core (3.12.2) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.3) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.6) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-rails (6.1.0) + actionpack (>= 6.1) + activesupport (>= 6.1) + railties (>= 6.1) + rspec-core (~> 3.12) + rspec-expectations (~> 3.12) + rspec-mocks (~> 3.12) + rspec-support (~> 3.12) + rspec-support (3.12.1) + rubocop (1.60.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.2.4) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.29.0) + rubocop-ast (1.30.0) parser (>= 3.2.1.0) ruby-progressbar (1.13.0) + ruby-vips (2.1.4) + ffi (~> 1.12) ruby2_keywords (0.0.5) sprockets (4.2.1) concurrent-ruby (~> 1.0) @@ -232,11 +262,14 @@ DEPENDENCIES activejob-web! brakeman bundler-audit + image_processing (>= 1.2) overcommit (~> 0.60.0) pg puma + rails-controller-testing (~> 1.0, >= 1.0.5) + rspec-rails rubocop sprockets-rails BUNDLED WITH - 2.4.19 + 2.4.21 diff --git a/Rakefile b/Rakefile index 34bcc14..5a624a1 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'bundler/setup' APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__) diff --git a/activejob-web.gemspec b/activejob-web.gemspec index 44841da..5d8a8cd 100644 --- a/activejob-web.gemspec +++ b/activejob-web.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'lib/activejob/web/version' Gem::Specification.new do |spec| @@ -5,18 +7,19 @@ Gem::Specification.new do |spec| spec.version = Activejob::Web::VERSION spec.authors = %w[gowtham mohammednazeer] spec.email = %w[gowtham.kuppusamy@mallow-tech.com mohammednazeer@mallow-tech.com] - spec.homepage = 'TODO' - spec.summary = 'TODO: Summary of Activejob::Web.' - spec.description = 'TODO: Description of Activejob::Web.' + spec.homepage = 'https://github.com/mallowtechdev/activejob-web' + spec.summary = 'Web-based dashboard for managing and monitoring background jobs' + spec.description = 'Activejob-web simplifies the background job management in rails' spec.license = 'MIT' # Prevent pushing this gem to RubyGems.org. To allow pushes either set the "allowed_push_host" # to allow pushing to a single host or delete this section to allow pushing to any host. - spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'" + spec.metadata['allowed_push_host'] = 'https://github.com/mallowtechdev/activejob-web' - spec.metadata['homepage_uri'] = spec.homepage - spec.metadata['source_code_uri'] = "TODO: Put your gem's public repo URL here." - spec.metadata['changelog_uri'] = "TODO: Put your gem's CHANGELOG.md URL here." + spec.metadata['homepage_uri'] = 'https://github.com/mallowtechdev/activejob-web' + spec.metadata['source_code_uri'] = 'https://github.com/mallowtechdev/activejob-web' + spec.metadata['changelog_uri'] = 'https://github.com/mallowtechdev/activejob-web' + spec.metadata['rubygems_mfa_required'] = 'true' spec.files = Dir.chdir(File.expand_path(__dir__)) do Dir['{app,config,db,lib}/**/*', 'MIT-LICENSE', 'Rakefile', 'README.md'] @@ -24,5 +27,4 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 3.2.2' spec.add_dependency 'rails', '>= 7.0.8' - spec.metadata['rubygems_mfa_required'] = 'true' end diff --git a/app/controllers/activejob_web/jobs_controller.rb b/app/controllers/activejob_web/jobs_controller.rb new file mode 100644 index 0000000..d45efa3 --- /dev/null +++ b/app/controllers/activejob_web/jobs_controller.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module ActivejobWeb + class JobsController < ApplicationController + def index + @jobs = ActivejobWeb::Job.all + end + + def show + @job = ActivejobWeb::Job.find(params[:id]) + end + + def download_pdf + if @job.template_file.attached? + send_file @job.template_file.download + else + flash[:error] = 'Template file not found.' + redirect_to @job + end + end + end +end diff --git a/app/helpers/activejob_web/jobs_helper.rb b/app/helpers/activejob_web/jobs_helper.rb new file mode 100644 index 0000000..316f2c4 --- /dev/null +++ b/app/helpers/activejob_web/jobs_helper.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +module ActivejobWeb + module JobsHelper + end +end diff --git a/app/models/activejob_web.rb b/app/models/activejob_web.rb new file mode 100644 index 0000000..3ff9a03 --- /dev/null +++ b/app/models/activejob_web.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module ActivejobWeb + def self.table_name_prefix + 'activejob_web_' + end +end diff --git a/app/models/activejob_web/job.rb b/app/models/activejob_web/job.rb new file mode 100644 index 0000000..b4ca82b --- /dev/null +++ b/app/models/activejob_web/job.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +module ActivejobWeb + class Job < ApplicationRecord + self.primary_key = 'id' + + enum queue: { + default: 0, + long_processing: 1 + } + # == Validations =================================================================================================== + validates :title, presence: true, length: { maximum: 255 } + validates :description, presence: true, length: { maximum: 1000 } + + # == Callbacks ===================================================================================================== + after_initialize :set_default_queue + has_one_attached :template_file + + private + + # Default value for queue + def set_default_queue + self.queue ||= 'default' # Set your desired default value for the queue attribute + end + end +end diff --git a/app/views/activejob_web/jobs/index.html.erb b/app/views/activejob_web/jobs/index.html.erb new file mode 100644 index 0000000..21546a4 --- /dev/null +++ b/app/views/activejob_web/jobs/index.html.erb @@ -0,0 +1,22 @@ +

Active Job Web Jobs

+ + + + + + + + + + + + <% @jobs.each do |job| %> + + + + + + + <% end %> + +
TitleDescriptionqueueActions
<%= job.title %><%= job.description %><%= job.queue == 'default' ? 'Default' : 'Long Processing' %><%= link_to 'Show', activejob_web_job_path(job) %>
\ No newline at end of file diff --git a/app/views/activejob_web/jobs/show.html.erb b/app/views/activejob_web/jobs/show.html.erb new file mode 100644 index 0000000..fe44fd6 --- /dev/null +++ b/app/views/activejob_web/jobs/show.html.erb @@ -0,0 +1,37 @@ +

<%= @job.title %>

+ +

Description: <%= @job.description %>

+

Max Run Time: <%= @job.max_run_time %>

+

Minimum Approvals Required: <%= @job.minimum_approvals_required %>

+

Priority: <%= @job.priority %>

+

Queue: <%= @job.queue == 'default' ? 'Default' : 'Long Processing' %>

+

Input Arguments

+ + + + + + + + + + + + <% @job.input_arguments.each do |argument| %> + + + + + + + + <% end %> + +
NameTypeAllowed CharactersMax LengthRequired
<%= argument["name"] %><%= argument["type"] %><%= argument["allowed_characters"] %><%= argument["max_length"] %><%= argument["required"] %>
+ +<% if @job.template_file.attached? %> + <%= link_to "Download Supporting Files", rails_blob_path(@job.template_file, disposition: "attachment"), class: "btn btn-primary" %> +<% else %> +

no template available

+<% end %> +<%= link_to 'Back', activejob_web_jobs_path %> \ No newline at end of file diff --git a/bin/rails b/bin/rails index dd5828f..d8e745b 100755 --- a/bin/rails +++ b/bin/rails @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + # This command will automatically be run when you run "rails" with Rails gems # installed from the root of your application. diff --git a/config/routes.rb b/config/routes.rb index 643baa7..aa36674 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,12 @@ +# frozen_string_literal: true + Rails.application.routes.draw do - # Defines the root path route ("/") + namespace :activejob_web do + root 'jobs#index' + resources :jobs do + member do + get :download_pdf + end + end + end end diff --git a/db/migrate/20231024051840_create_jobs.rb b/db/migrate/20231024051840_create_jobs.rb new file mode 100644 index 0000000..113b771 --- /dev/null +++ b/db/migrate/20231024051840_create_jobs.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class CreateJobs < ActiveRecord::Migration[7.1] + def change + create_table :activejob_web_jobs, id: false do |t| + t.uuid :id, default: -> { 'gen_random_uuid()' }, null: false + t.string :title + t.string :description + t.json :input_arguments + t.integer :max_run_time + t.integer :minimum_approvals_required + t.integer :priority + t.integer :queue + + t.timestamps + end + end +end diff --git a/db/migrate/20231030145254_create_active_storage_tables.active_storage.rb b/db/migrate/20231030145254_create_active_storage_tables.active_storage.rb new file mode 100644 index 0000000..61b6a02 --- /dev/null +++ b/db/migrate/20231030145254_create_active_storage_tables.active_storage.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +# This migration comes from active_storage (originally 20170806125915) +class CreateActiveStorageTables < ActiveRecord::Migration[7.0] + def change + unless table_exists?(:active_storage_blobs) + create_table :active_storage_blobs, id: primary_key_type do |t| + t.string :key, null: false + t.string :filename, null: false + t.string :content_type + t.text :metadata + t.string :service_name, null: false + t.bigint :byte_size, null: false + t.string :checksum + + if connection.supports_datetime_with_precision? + t.datetime :created_at, precision: 6, null: false + else + t.datetime :created_at, null: false + end + + t.index [:key], unique: true + end + end + # Use Active Record's configured type for primary and foreign keys + primary_key_type, foreign_key_type = primary_and_foreign_key_types + + unless table_exists?(:active_storage_attachments) + create_table :active_storage_attachments, id: primary_key_type do |t| + t.string :name, null: false + t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type + t.references :blob, null: false, type: foreign_key_type + + if connection.supports_datetime_with_precision? + t.datetime :created_at, precision: 6, null: false + else + t.datetime :created_at, null: false + end + + t.index %i[record_type record_id name blob_id], name: :index_active_storage_attachments_uniqueness, unique: true + t.foreign_key :active_storage_blobs, column: :blob_id + end + end + + return if table_exists?(:active_storage_variant_records) + + create_table :active_storage_variant_records, id: primary_key_type do |t| + t.belongs_to :blob, null: false, index: false, type: foreign_key_type + t.string :variation_digest, null: false + + t.index %i[blob_id variation_digest], name: :index_active_storage_variant_records_uniqueness, unique: true + t.foreign_key :active_storage_blobs, column: :blob_id + end + end + + private + + def primary_and_foreign_key_types + config = Rails.configuration.generators + setting = config.options[config.orm][:primary_key_type] + primary_key_type = setting || :primary_key + foreign_key_type = setting || :bigint + [primary_key_type, foreign_key_type] + end +end diff --git a/lib/activejob/web.rb b/lib/activejob/web.rb index cb94080..0cad6cc 100644 --- a/lib/activejob/web.rb +++ b/lib/activejob/web.rb @@ -1,8 +1,9 @@ +# frozen_string_literal: true + require 'activejob/web/version' require 'activejob/web/engine' module Activejob module Web - # Your code goes here... end end diff --git a/lib/activejob/web/engine.rb b/lib/activejob/web/engine.rb index 6cab492..f08d16a 100644 --- a/lib/activejob/web/engine.rb +++ b/lib/activejob/web/engine.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Activejob module Web class Engine < ::Rails::Engine diff --git a/lib/activejob/web/version.rb b/lib/activejob/web/version.rb index f5c83eb..0eeffe7 100644 --- a/lib/activejob/web/version.rb +++ b/lib/activejob/web/version.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + module Activejob module Web - VERSION = '0.1.0'.freeze + VERSION = '0.1.0' end end diff --git a/lib/tasks/activejob/web_tasks.rake b/lib/tasks/activejob/web_tasks.rake index 0f60b46..1996cc2 100644 --- a/lib/tasks/activejob/web_tasks.rake +++ b/lib/tasks/activejob/web_tasks.rake @@ -1,3 +1,4 @@ +# frozen_string_literal: true # desc "Explaining what the task does" # task :activejob_web do # # Task goes here diff --git a/spec/helpers/activejob_web/jobs_helper_spec.rb b/spec/helpers/activejob_web/jobs_helper_spec.rb new file mode 100644 index 0000000..563ba52 --- /dev/null +++ b/spec/helpers/activejob_web/jobs_helper_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the ActivejobWeb::JobsHelper. For example: +# +# describe ActivejobWeb::JobsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe ActivejobWeb::JobsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/activejob_web/job_spec.rb b/spec/models/activejob_web/job_spec.rb new file mode 100644 index 0000000..b83f934 --- /dev/null +++ b/spec/models/activejob_web/job_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe ActivejobWeb::Job, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 0000000..78c9bc5 --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,66 @@ +# frozen_string_literal: true + +# This file is copied to spec/ when you run 'rails generate rspec:install' +require 'spec_helper' +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../test/dummy/config/environment', __dir__) +# Prevent database truncation if the environment is production +abort('The Rails environment is running in production mode!') if Rails.env.production? +require 'rspec/rails' +# Add additional requires below this line. Rails is not loaded until this point! + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# +# The following line is provided for convenience purposes. It has the downside +# of increasing the boot-up time by auto-requiring all files in the support +# directory. Alternatively, in the individual `*_spec.rb` files, manually +# require only the support files necessary. +# +# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f } + +# Checks for pending migrations and applies them before tests are run. +# If you are not using ActiveRecord, you can remove these lines. +begin + ActiveRecord::Migration.maintain_test_schema! +rescue ActiveRecord::PendingMigrationError => e + puts e.to_s.strip + exit 1 +end +RSpec.configure do |config| + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_path = "#{Rails.root}/spec/fixtures" + + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + config.use_transactional_fixtures = true + + # You can uncomment this line to turn off ActiveRecord support entirely. + # config.use_active_record = false + + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, type: :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://relishapp.com/rspec/rspec-rails/docs + config.infer_spec_type_from_file_location! + + # Filter lines from Rails gems in backtraces. + config.filter_rails_from_backtrace! + # arbitrary gems may also be filtered via: + # config.filter_gems_from_backtrace("gem name") +end diff --git a/spec/requests/activejob_web/jobs_spec.rb b/spec/requests/activejob_web/jobs_spec.rb new file mode 100644 index 0000000..8833a94 --- /dev/null +++ b/spec/requests/activejob_web/jobs_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'ActivejobWeb::Jobs', type: :request do + describe 'GET /index' do + context 'returns a successful response' do + it 'Valid index' do + get activejob_web_jobs_path + expect(response).to render_template('index') + expect(response).to have_http_status 200 + end + end + end + describe 'GET #show' do + context 'returns a successful response' do + it 'Valid show' do + data = ActivejobWeb::Job.create(title: 'Test1', description: 'Test description', input_arguments: [{ + name: 'File', + type: 'File', + allowed_characters: '', + max_length: '10', + required: true + }]) + get activejob_web_job_path(data.id) + expect(response).to render_template('show') + expect(response).to have_http_status 200 + end + end + + context 'invalid show' do + it 'should not render show page without vaid job id' do + expect { get activejob_web_job_path(SecureRandom.uuid) }.to raise_error(ActiveRecord::RecordNotFound) + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..409c64b --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,94 @@ +# frozen_string_literal: true + +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + # # This allows you to limit a spec run to individual examples or groups + # # you care about by tagging them with `:focus` metadata. When nothing + # # is tagged with `:focus`, all examples get run. RSpec also provides + # # aliases for `it`, `describe`, and `context` that include `:focus` + # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + # config.filter_run_when_matching :focus + # + # # Allows RSpec to persist some state between runs in order to support + # # the `--only-failures` and `--next-failure` CLI options. We recommend + # # you configure your source control system to ignore this file. + # config.example_status_persistence_file_path = "spec/examples.txt" + # + # # Limits the available syntax to the non-monkey patched syntax that is + # # recommended. For more details, see: + # # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/ + # config.disable_monkey_patching! + # + # # Many RSpec users commonly either run the entire suite or an individual + # # file, and it's useful to allow more verbose output when running an + # # individual spec file. + # if config.files_to_run.one? + # # Use the documentation formatter for detailed output, + # # unless a formatter has already been configured + # # (e.g. via a command-line flag). + # config.default_formatter = "doc" + # end + # + # # Print the 10 slowest examples and example groups at the + # # end of the spec run, to help surface which specs are running + # # particularly slow. + # config.profile_examples = 10 + # + # # Run specs in random order to surface order dependencies. If you find an + # # order dependency and want to debug it, you can fix the order by providing + # # the seed, which is printed after each run. + # # --seed 1234 + # config.order = :random + # + # # Seed global randomization in this process using the `--seed` CLI option. + # # Setting this allows you to use `--seed` to deterministically reproduce + # # test failures related to randomization by passing the same `--seed` value + # # as the one that triggered the failure. + # Kernel.srand config.seed +end diff --git a/test/activejob/web_test.rb b/test/activejob/web_test.rb index 8593d80..98dcd1e 100644 --- a/test/activejob/web_test.rb +++ b/test/activejob/web_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' module Activejob diff --git a/test/controllers/activejob_web_jobs_controller_test.rb b/test/controllers/activejob_web_jobs_controller_test.rb new file mode 100644 index 0000000..8a57acb --- /dev/null +++ b/test/controllers/activejob_web_jobs_controller_test.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'test_helper' + +class ActivejobWebJobsControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/dummy/Rakefile b/test/dummy/Rakefile index e85f913..488c551 100644 --- a/test/dummy/Rakefile +++ b/test/dummy/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # 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. diff --git a/test/dummy/app/channels/application_cable/channel.rb b/test/dummy/app/channels/application_cable/channel.rb index d672697..9aec230 100644 --- a/test/dummy/app/channels/application_cable/channel.rb +++ b/test/dummy/app/channels/application_cable/channel.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Channel < ActionCable::Channel::Base end diff --git a/test/dummy/app/channels/application_cable/connection.rb b/test/dummy/app/channels/application_cable/connection.rb index 0ff5442..8d6c2a1 100644 --- a/test/dummy/app/channels/application_cable/connection.rb +++ b/test/dummy/app/channels/application_cable/connection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Connection < ActionCable::Connection::Base end diff --git a/test/dummy/app/controllers/application_controller.rb b/test/dummy/app/controllers/application_controller.rb index 09705d1..7944f9f 100644 --- a/test/dummy/app/controllers/application_controller.rb +++ b/test/dummy/app/controllers/application_controller.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::Base end diff --git a/test/dummy/app/helpers/application_helper.rb b/test/dummy/app/helpers/application_helper.rb index de6be79..15b06f0 100644 --- a/test/dummy/app/helpers/application_helper.rb +++ b/test/dummy/app/helpers/application_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module ApplicationHelper end diff --git a/test/dummy/app/jobs/application_job.rb b/test/dummy/app/jobs/application_job.rb index d394c3d..bef3959 100644 --- a/test/dummy/app/jobs/application_job.rb +++ b/test/dummy/app/jobs/application_job.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationJob < ActiveJob::Base # Automatically retry jobs that encountered a deadlock # retry_on ActiveRecord::Deadlocked diff --git a/test/dummy/app/mailers/application_mailer.rb b/test/dummy/app/mailers/application_mailer.rb index 286b223..d84cb6e 100644 --- a/test/dummy/app/mailers/application_mailer.rb +++ b/test/dummy/app/mailers/application_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationMailer < ActionMailer::Base default from: 'from@example.com' layout 'mailer' diff --git a/test/dummy/app/models/application_record.rb b/test/dummy/app/models/application_record.rb index b63caeb..08dc537 100644 --- a/test/dummy/app/models/application_record.rb +++ b/test/dummy/app/models/application_record.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationRecord < ActiveRecord::Base primary_abstract_class end diff --git a/test/dummy/bin/rails b/test/dummy/bin/rails index 0739660..a31728a 100755 --- a/test/dummy/bin/rails +++ b/test/dummy/bin/rails @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands' diff --git a/test/dummy/bin/rake b/test/dummy/bin/rake index 1724048..c199955 100755 --- a/test/dummy/bin/rake +++ b/test/dummy/bin/rake @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require_relative '../config/boot' require 'rake' Rake.application.run diff --git a/test/dummy/bin/setup b/test/dummy/bin/setup index d6e019a..516b651 100755 --- a/test/dummy/bin/setup +++ b/test/dummy/bin/setup @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require 'fileutils' # path to your application root. diff --git a/test/dummy/config.ru b/test/dummy/config.ru index ad1fbf2..6dc8321 100644 --- a/test/dummy/config.ru +++ b/test/dummy/config.ru @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is used by Rack-based servers to start the application. require_relative 'config/environment' diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index 0bdeaf2..d491b46 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'boot' require 'rails/all' diff --git a/test/dummy/config/boot.rb b/test/dummy/config/boot.rb index c9aef85..6d2cba0 100644 --- a/test/dummy/config/boot.rb +++ b/test/dummy/config/boot.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__) diff --git a/test/dummy/config/database.yml b/test/dummy/config/database.yml index e188530..f01a924 100644 --- a/test/dummy/config/database.yml +++ b/test/dummy/config/database.yml @@ -11,14 +11,14 @@ default: &default development: <<: *default - database: activejob_web_development + database: activejob_web_dev # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default - database: activejob_web_test + database: activejob_web_testing production: <<: *default diff --git a/test/dummy/config/environment.rb b/test/dummy/config/environment.rb index 426333b..d5abe55 100644 --- a/test/dummy/config/environment.rb +++ b/test/dummy/config/environment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Load the Rails application. require_relative 'application' diff --git a/test/dummy/config/environments/development.rb b/test/dummy/config/environments/development.rb index e522e6e..84a57f4 100644 --- a/test/dummy/config/environments/development.rb +++ b/test/dummy/config/environments/development.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'active_support/core_ext/integer/time' Rails.application.configure do diff --git a/test/dummy/config/environments/production.rb b/test/dummy/config/environments/production.rb index 5db20e5..5e458f7 100644 --- a/test/dummy/config/environments/production.rb +++ b/test/dummy/config/environments/production.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'active_support/core_ext/integer/time' Rails.application.configure do diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb index 5f6cef4..8f3f63c 100644 --- a/test/dummy/config/environments/test.rb +++ b/test/dummy/config/environments/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'active_support/core_ext/integer/time' # The test environment is used exclusively to run your application's diff --git a/test/dummy/config/initializers/assets.rb b/test/dummy/config/initializers/assets.rb index fe48fc3..bcafccd 100644 --- a/test/dummy/config/initializers/assets.rb +++ b/test/dummy/config/initializers/assets.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. diff --git a/test/dummy/config/initializers/content_security_policy.rb b/test/dummy/config/initializers/content_security_policy.rb index 54f47cf..691cfa1 100644 --- a/test/dummy/config/initializers/content_security_policy.rb +++ b/test/dummy/config/initializers/content_security_policy.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Define an application-wide content security policy. diff --git a/test/dummy/config/initializers/filter_parameter_logging.rb b/test/dummy/config/initializers/filter_parameter_logging.rb index 166997c..3df77c5 100644 --- a/test/dummy/config/initializers/filter_parameter_logging.rb +++ b/test/dummy/config/initializers/filter_parameter_logging.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Configure parameters to be filtered from the log file. Use this to limit dissemination of diff --git a/test/dummy/config/initializers/inflections.rb b/test/dummy/config/initializers/inflections.rb index 3860f65..6c78420 100644 --- a/test/dummy/config/initializers/inflections.rb +++ b/test/dummy/config/initializers/inflections.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections diff --git a/test/dummy/config/initializers/permissions_policy.rb b/test/dummy/config/initializers/permissions_policy.rb index 00f64d7..50bcf4e 100644 --- a/test/dummy/config/initializers/permissions_policy.rb +++ b/test/dummy/config/initializers/permissions_policy.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Define an application-wide HTTP permissions policy. For further # information see https://developers.google.com/web/updates/2018/06/feature-policy # diff --git a/test/dummy/config/puma.rb b/test/dummy/config/puma.rb index df14fbe..1713441 100644 --- a/test/dummy/config/puma.rb +++ b/test/dummy/config/puma.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match diff --git a/test/dummy/config/routes.rb b/test/dummy/config/routes.rb index 262ffd5..7b329f5 100644 --- a/test/dummy/config/routes.rb +++ b/test/dummy/config/routes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.routes.draw do # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb new file mode 100644 index 0000000..964f188 --- /dev/null +++ b/test/dummy/db/schema.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema[7.1].define(version: 20_231_122_070_102) do + # These are extensions that must be enabled in order to support this database + enable_extension 'plpgsql' + + create_table 'active_storage_attachments', force: :cascade do |t| + t.string 'name', null: false + t.string 'record_type', null: false + t.bigint 'record_id', null: false + t.bigint 'blob_id', null: false + t.datetime 'created_at', null: false + t.index ['blob_id'], name: 'index_active_storage_attachments_on_blob_id' + t.index %w[record_type record_id name blob_id], name: 'index_active_storage_attachments_uniqueness', unique: true + end + + create_table 'active_storage_blobs', force: :cascade do |t| + t.string 'key', null: false + t.string 'filename', null: false + t.string 'content_type' + t.text 'metadata' + t.string 'service_name', null: false + t.bigint 'byte_size', null: false + t.string 'checksum' + t.datetime 'created_at', null: false + t.index ['key'], name: 'index_active_storage_blobs_on_key', unique: true + end + + create_table 'active_storage_variant_records', force: :cascade do |t| + t.bigint 'blob_id', null: false + t.string 'variation_digest', null: false + t.index %w[blob_id variation_digest], name: 'index_active_storage_variant_records_uniqueness', unique: true + end + + create_table 'activejob_web_jobs', id: false, force: :cascade do |t| + t.uuid 'id', default: -> { 'gen_random_uuid()' }, null: false + t.string 'title' + t.string 'description' + t.json 'input_arguments' + t.integer 'max_run_time' + t.integer 'minimum_approvals_required' + t.integer 'priority' + t.integer 'queue' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + end + + add_foreign_key 'active_storage_attachments', 'active_storage_blobs', column: 'blob_id' + add_foreign_key 'active_storage_variant_records', 'active_storage_blobs', column: 'blob_id' +end diff --git a/test/dummy/db/seeds.rb b/test/dummy/db/seeds.rb new file mode 100644 index 0000000..f5a6ffb --- /dev/null +++ b/test/dummy/db/seeds.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +10.times do |i| + job = ActivejobWeb::Job.new( + title: "Job Title #{i + 1}", + description: "Job Description #{i + 1}", + input_arguments: [ + { + name: 'File', + type: 'File', + allowed_characters: '', + max_length: '10', + required: true + }, + { + name: 'Imported Date', + type: 'Date', + required: true + }, + { + name: 'Imported Date and Time', + type: 'DateTime', + required: true + }, + { + name: 'client name', + type: 'String', + required: true, + allowed_characters: '', + max_length: '10' + }, + { + name: 'Booking ID', + type: 'integer' + } + ], + max_run_time: 60, + minimum_approvals_required: 2, + priority: 1 + ) + + if job.save + puts "Job #{i + 1} has been created successfully." + else + puts "Error creating Job #{i + 1}: #{job.errors.full_messages.join(', ')}" + end +end +#==== specified the file path and used File.open method to get the file, then attached the file +file_path = 'app/assets/images/activejob/web/sample.png' +file = File.open(file_path, 'rb') +ActivejobWeb::Job.first.template_file.attach(io: file, filename: 'sample.png') diff --git a/test/integration/navigation_test.rb b/test/integration/navigation_test.rb index 29e59d8..91d920f 100644 --- a/test/integration/navigation_test.rb +++ b/test/integration/navigation_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' class NavigationTest < ActionDispatch::IntegrationTest diff --git a/test/models/activejob_web_job_test.rb b/test/models/activejob_web_job_test.rb new file mode 100644 index 0000000..3d14188 --- /dev/null +++ b/test/models/activejob_web_job_test.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'test_helper' + +class ActivejobWebJobTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 3dfa6f5..de45395 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Configure Rails Environment ENV['RAILS_ENV'] = 'test'