Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
9 changes: 9 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@ gem 'puma'

gem 'pg'

gem "image_processing", ">= 1.2"

gem "sprockets-rails"
gem 'sprockets-rails'

group :development, :test do
gem 'rubocop', require: false
end

group :development, :test do
gem 'rspec-rails'
end
gem 'rails-controller-testing', '~> 1.0', '>= 1.0.5'


# Start debugger with binding.b [https://github.com/ruby/debug]
# gem "debug", ">= 1.0.0"
47 changes: 31 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,17 @@ 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)
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)
io-console (0.6.0)
irb (1.8.3)
rdoc
Expand All @@ -110,6 +114,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)
Expand Down Expand Up @@ -157,6 +162,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
Expand All @@ -179,22 +188,25 @@ GEM
regexp_parser (2.8.2)
reline (0.3.9)
io-console (~> 0.5)
rexml (3.2.6)
rubocop (1.57.1)
base64 (~> 0.1.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.4)
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)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
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 (5.1.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
railties (>= 5.2)
rspec-core (~> 3.10)
rspec-expectations (~> 3.10)
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-support (3.12.1)
ruby-vips (2.1.4)
ffi (~> 1.12)
ruby2_keywords (0.0.5)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
Expand All @@ -220,9 +232,12 @@ PLATFORMS

DEPENDENCIES
activejob-web!
image_processing (>= 1.2)
pg
puma
rubocop
rails-controller-testing (~> 1.0, >= 1.0.5)
rspec-rails
sprockets-rails

BUNDLED WITH
Expand Down
28 changes: 14 additions & 14 deletions activejob-web.gemspec
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
require_relative 'lib/activejob/web/version'
require_relative "lib/activejob/web/version"

Gem::Specification.new do |spec|
spec.name = 'activejob-web'
spec.version = Activejob::Web::VERSION
spec.authors = %w[gowtham mohammednazeer]
spec.email = %w[[email protected] [email protected]]
spec.homepage = 'TODO'
spec.summary = 'TODO: Summary of Activejob::Web.'
spec.description = 'TODO: Description of Activejob::Web.'
spec.license = 'MIT'
spec.authors = ["mohammednazeer"]
spec.email = ["[email protected]"]
spec.homepage = 'https://example.com'
spec.summary = "Summary of Activejob::Web."
spec.description = "Description of Activejob::Web."
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"] = 'http://mygemserver.com'

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"] = spec.homepage
spec.metadata["source_code_uri"] = 'https://example.com'
spec.metadata["changelog_uri"] = 'https://example.com'

spec.files = Dir.chdir(File.expand_path(__dir__)) do
Dir['{app,config,db,lib}/**/*', 'MIT-LICENSE', 'Rakefile', 'README.md']
Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
end

spec.required_ruby_version = '>= 3.2.2'
spec.add_dependency 'rails', '>= 7.0.8'
spec.add_dependency "rails", ">= 7.0.8"
spec.add_development_dependency 'rspec-rails'
end
Binary file added app/assets/images/activejob/web/sample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions app/controllers/activejob_web/jobs_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class ActivejobWeb::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
2 changes: 2 additions & 0 deletions app/helpers/activejob_web/jobs_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ActivejobWeb::JobsHelper
end
5 changes: 5 additions & 0 deletions app/models/activejob_web.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module ActivejobWeb
def self.table_name_prefix
"activejob_web_"
end
end
16 changes: 16 additions & 0 deletions app/models/activejob_web/job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class ActivejobWeb::Job < ApplicationRecord
self.primary_key = 'id'
# Validations
validates :title, presence: true, length: { maximum: 255 } # Maximum 255 characters for title
validates :description, presence: true, length: { maximum: 1000 } # Maximum 1000 characters for description
# The input_arguments is optional, so no validation needed
# Default value for queue
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

24 changes: 24 additions & 0 deletions app/views/activejob_web/jobs/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<h1>Active Job Web Jobs</h1>

<table>
<thead>
<tr>
<th>Title</th>
<th>Description</th>
<th>ID</th>
<th>queue</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% @jobs.each do |job| %>
<tr>
<td><%= job.title %></td>
<td><%= job.description %></td>
<td><%= job.id %></td>
<td><%= job.queue %></td>
<td><%= link_to 'Show', activejob_web_job_path(job) %></td>
</tr>
<% end %>
</tbody>
</table>
14 changes: 14 additions & 0 deletions app/views/activejob_web/jobs/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<h1><%= @job.title %></h1>

<p><strong>Description:</strong> <%= @job.description %></p>
<p><strong>Input Arguments:</strong> <%= @job.input_arguments %></p>
<p><strong>Max Run Time:</strong> <%= @job.max_run_time %></p>
<p><strong>Minimum Approvals Required:</strong> <%= @job.minimum_approvals_required %></p>
<p><strong>Priority:</strong> <%= @job.priority %></p>
<p><strong>Queue:</strong> <%= @job.queue %></p>
<% if @job.template_file.attached? %>
<%= link_to "Download PDF", rails_blob_path(@job.template_file, disposition: "attachment"), class: "btn btn-primary" %>
<% else %>
<p>no template available</p>
<% end %>
<%= link_to 'Back', activejob_web_jobs_path %>
10 changes: 9 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
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
14 changes: 14 additions & 0 deletions db/migrate/20231030135059_create_activejob_web_jobs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateActivejobWebJobs < ActiveRecord::Migration[7.1]
def change
create_table :activejob_web_jobs do |t|
t.string :title
t.string :description
t.json :input_arguments
t.integer :max_run_time
t.integer :minimum_approvals_required
t.integer :priority
t.string :queue
t.timestamps
end
end
end
11 changes: 11 additions & 0 deletions db/migrate/20231030135457_change_primary_key_to_uuid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class ChangePrimaryKeyToUuid < ActiveRecord::Migration[7.1]
def up
remove_column :activejob_web_jobs, :id
add_column :activejob_web_jobs, :id, :uuid, default: 'gen_random_uuid()', primary_key: true
end

def down
remove_column :activejob_web_jobs, :id
add_column :activejob_web_jobs, :id, :primary_key
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# 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 [ :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

unless 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 [ :blob_id, :variation_digest ], name: :index_active_storage_variant_records_uniqueness, unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
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
1 change: 0 additions & 1 deletion lib/activejob/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@

module Activejob
module Web
# Your code goes here...
end
end
15 changes: 15 additions & 0 deletions spec/helpers/activejob_web/jobs_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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
5 changes: 5 additions & 0 deletions spec/models/activejob_web/job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe ActivejobWeb::Job, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading