From bca1f508287d99c7b8c91c5c64504dc6129c5891 Mon Sep 17 00:00:00 2001 From: mohammednazeer Date: Wed, 1 Nov 2023 11:26:42 +0530 Subject: [PATCH 1/3] issues 4 - implementing-list-and-show-page-for-jobs --- .rspec | 1 + Gemfile | 8 ++ Gemfile.lock | 38 +++++++ activejob-web.gemspec | 15 +-- app/assets/images/activejob/web/sample.png | Bin 0 -> 7510 bytes .../activejob_web_jobs_controller.rb | 19 ++++ app/helpers/activejob_web_jobs_helper.rb | 2 + app/models/activejob_web_job.rb | 16 +++ app/views/activejob_web_jobs/index.html.erb | 24 +++++ app/views/activejob_web_jobs/show.html.erb | 15 +++ config/routes.rb | 6 ++ ...0231030135059_create_activejob_web_jobs.rb | 14 +++ ...231030135457_change_primary_key_to_uuid.rb | 11 ++ ...te_active_storage_tables.active_storage.rb | 62 ++++++++++++ lib/activejob/web.rb | 4 +- spec/rails_helper.rb | 64 ++++++++++++ spec/requests/activejob_web_jobs_spec.rb | 26 +++++ spec/spec_helper.rb | 94 ++++++++++++++++++ .../activejob_web_jobs_controller_test.rb | 7 ++ test/dummy/config/database.yml | 4 +- test/dummy/db/schema.rb | 59 +++++++++++ test/dummy/db/seeds.rb | 49 +++++++++ 22 files changed, 528 insertions(+), 10 deletions(-) create mode 100644 .rspec create mode 100644 app/assets/images/activejob/web/sample.png create mode 100644 app/controllers/activejob_web_jobs_controller.rb create mode 100644 app/helpers/activejob_web_jobs_helper.rb create mode 100644 app/models/activejob_web_job.rb create mode 100644 app/views/activejob_web_jobs/index.html.erb create mode 100644 app/views/activejob_web_jobs/show.html.erb create mode 100644 db/migrate/20231030135059_create_activejob_web_jobs.rb create mode 100644 db/migrate/20231030135457_change_primary_key_to_uuid.rb create mode 100644 db/migrate/20231030145254_create_active_storage_tables.active_storage.rb create mode 100644 spec/rails_helper.rb create mode 100644 spec/requests/activejob_web_jobs_spec.rb create mode 100644 spec/spec_helper.rb create mode 100644 test/controllers/activejob_web_jobs_controller_test.rb create mode 100644 test/dummy/db/schema.rb create mode 100644 test/dummy/db/seeds.rb 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/Gemfile b/Gemfile index a70b861..3df49aa 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,15 @@ gem "puma" gem 'pg' +gem "image_processing", ">= 1.2" + gem "sprockets-rails" +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" diff --git a/Gemfile.lock b/Gemfile.lock index 5ff6c4a..6b0b3e4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -87,13 +87,23 @@ 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) + factory_bot (6.2.1) + activesupport (>= 5.0.0) + factory_bot_rails (6.2.0) + factory_bot (~> 6.2.0) + railties (>= 5.0.0) + ffi (1.15.5) 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 @@ -107,6 +117,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) @@ -150,6 +161,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 @@ -170,6 +185,25 @@ GEM psych (>= 4.0.0) reline (0.3.9) io-console (~> 0.5) + 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) @@ -194,8 +228,12 @@ PLATFORMS DEPENDENCIES activejob-web! + factory_bot_rails + image_processing (>= 1.2) pg puma + rails-controller-testing (~> 1.0, >= 1.0.5) + rspec-rails sprockets-rails BUNDLED WITH diff --git a/activejob-web.gemspec b/activejob-web.gemspec index b1cf955..fa9fa19 100644 --- a/activejob-web.gemspec +++ b/activejob-web.gemspec @@ -1,26 +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 = ["mohammednazeer"] spec.email = ["mohammednazeer@mallow-tech.com"] - spec.homepage = "TODO" - spec.summary = "TODO: Summary of Activejob::Web." - spec.description = "TODO: Description of Activejob::Web." + 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["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"] end spec.add_dependency "rails", ">= 7.0.8" + spec.add_development_dependency 'rspec-rails' end diff --git a/app/assets/images/activejob/web/sample.png b/app/assets/images/activejob/web/sample.png new file mode 100644 index 0000000000000000000000000000000000000000..3b5aaf25bc2dff5a79033fdccae5218abcf04526 GIT binary patch literal 7510 zcmeHsWmH_-vToxJ!6mqR?H3owLWg@BP0&?pkBcs#R5AeY0xLG5@ScU2PRSY$|L30Dz~as`UI(<~|O0O!UWj zT6_@;0HDwUD=O-$DJs(Iy1UweoooRBTT>veg1DKflp2Ps&t9;d^(Zsu2S(d)4tq0(UAtC)h5w>vmDEyL@MH)PO1eYBi z;tLj8ED?BGci;Z-@G|ulCI34>&WjIz7RL(hyW#|ty1O$AqXS0J&DmvG-BJ2T`Sd|3 zpv=~gcTH~B=9$2Zi|CVz=UYvMrmx9vq256?yJQ6d1K-{MtZa26%Oqrx5E$_uf0&?o@W&#E zzN=IuscPsk5QKgZ?|b_cYsI-W1Pqd*Ter8yv1W|v(z_MC2F1{$4yKE{o-nn1p9rrR z2XMvwx()om4I06-PK@AtTJGFtLErzCdf*sao>|vwB+GIHe{&?*!Ftd+dunvqS54UUKlX43e6g6x_!6L zif~yZ7)M*6dy;o_`%+u3A!FvK^$LT6(sh(Zoczi9ehbgeOPiRGzFA`u27wWm3_2Ey zCw6V}rdt`3HjgvHRJLsFY3Xqws_cNRJl~}^BOy`{!-bo-=1T*j<-_ny+y|om@ zL`q^i<2gI7uB0XYiBn3Ci3&(_9y%hd%8({Jo+4xpCE&vbOau*3I>FI{#ZvD#2|QsO zD9EDzn<6UjLn$esC>l@DA7WRiNl#QVaC}ho*&m8l$g6DTSNU38&L6sdca;U{pM#=i zL|EX>&)$ZwWl~tj5Dws4hsMjj$@kDrXXm;q!!SZiqEf%Rl)B$m8PCP|Q9Yr!i*ToaJ!Y;korMb55gTr4mID8kc#vJ@EWWy+x!p~5Cq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q!nY2LGesfA8jB*2nFX!IlF4`)J5uyOv`-JRT%GH6?ii zAEbjxJuCn{395YK7%WGphX^5P^wTm;TF^TUSuce6uFdc#IpE3r20$?Q?G8ZTBN>2i z^oUvxeG(Z^e4T~zP0ke1Ez|`8P^#hpQn$VF=~2K)fT`OtBpZ4jfMxoccrb1u8bI?* j660gY|0ek#+moQ+5oDWgIzaWGdqhoHTd7LHGW5Ry=D*2y literal 0 HcmV?d00001 diff --git a/app/controllers/activejob_web_jobs_controller.rb b/app/controllers/activejob_web_jobs_controller.rb new file mode 100644 index 0000000..53dde4e --- /dev/null +++ b/app/controllers/activejob_web_jobs_controller.rb @@ -0,0 +1,19 @@ +class ActivejobWebJobsController < ApplicationController + + def index + @activejob_web_jobs = ActivejobWebJob.all + end + + def show + @activejob_web_job = ActivejobWebJob.find(params[:id]) + end + + def download_pdf + if @activejob_web_job.template_file.attached? + send_file @activejob_web_job.template_file.download + else + flash[:error] = "Template file not found." + redirect_to @activejob_web_job + 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..29485fc --- /dev/null +++ b/app/helpers/activejob_web_jobs_helper.rb @@ -0,0 +1,2 @@ +module ActivejobWebJobsHelper +end diff --git a/app/models/activejob_web_job.rb b/app/models/activejob_web_job.rb new file mode 100644 index 0000000..e549807 --- /dev/null +++ b/app/models/activejob_web_job.rb @@ -0,0 +1,16 @@ +class ActivejobWebJob < 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 + 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..2a14a5b --- /dev/null +++ b/app/views/activejob_web_jobs/index.html.erb @@ -0,0 +1,24 @@ +

Active Job Web Jobs

+ + + + + + + + + + + + + <% @activejob_web_jobs.each do |job| %> + + + + + + + + <% end %> + +
TitleDescriptionIDqueueActions
<%= job.title %><%= job.description %><%= job.id %><%= job.queue %><%= link_to 'Show', activejob_web_job_path(job) %>
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..a1f5f67 --- /dev/null +++ b/app/views/activejob_web_jobs/show.html.erb @@ -0,0 +1,15 @@ +

<%= @activejob_web_job.title %>

+ +

Description: <%= @activejob_web_job.description %>

+

Input Arguments: <%= @activejob_web_job.input_arguments %>

+

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

+

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

+

Priority: <%= @activejob_web_job.priority %>

+

Queue: <%= @activejob_web_job.queue %>

+<% if @activejob_web_job.template_file.attached? %> + <%= link_to "Download PDF", rails_blob_path(@activejob_web_job.template_file, disposition: "attachment"), class: "btn btn-primary" %> +<% else %> +

no template available

+<% end %> + +<%= link_to 'Back', activejob_web_jobs_path %> diff --git a/config/routes.rb b/config/routes.rb index 1daf9a4..a632385 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,2 +1,8 @@ Rails.application.routes.draw do + resources :activejob_web_jobs do + member do + get :download_pdf + end + end + end diff --git a/db/migrate/20231030135059_create_activejob_web_jobs.rb b/db/migrate/20231030135059_create_activejob_web_jobs.rb new file mode 100644 index 0000000..9942f72 --- /dev/null +++ b/db/migrate/20231030135059_create_activejob_web_jobs.rb @@ -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 diff --git a/db/migrate/20231030135457_change_primary_key_to_uuid.rb b/db/migrate/20231030135457_change_primary_key_to_uuid.rb new file mode 100644 index 0000000..483a140 --- /dev/null +++ b/db/migrate/20231030135457_change_primary_key_to_uuid.rb @@ -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 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..3781086 --- /dev/null +++ b/db/migrate/20231030145254_create_active_storage_tables.active_storage.rb @@ -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 diff --git a/lib/activejob/web.rb b/lib/activejob/web.rb index b875ffa..173f6ce 100644 --- a/lib/activejob/web.rb +++ b/lib/activejob/web.rb @@ -3,6 +3,8 @@ module Activejob module Web - # Your code goes here... + # config.generators do |g| + # g.test_framework :rspec + # end end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 0000000..3ba12de --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,64 @@ +# 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', __FILE__) +# 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..8cc1603 --- /dev/null +++ b/spec/requests/activejob_web_jobs_spec.rb @@ -0,0 +1,26 @@ +# spec/requests/jobs_request_spec.rb +require 'rails_helper' + +RSpec.describe "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 = ActivejobWebJob.create(title: "Test1", description: "Test description") + get activejob_web_job_path(data.id) + expect(response).to render_template('show') + expect(response).to have_http_status 200 + end + end +end +end + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..327b58e --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,94 @@ +# 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. +=begin + # 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 +end 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..767bfce --- /dev/null +++ b/test/controllers/activejob_web_jobs_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class ActivejobWebJobsControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end 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/db/schema.rb b/test/dummy/db/schema.rb new file mode 100644 index 0000000..c037468 --- /dev/null +++ b/test/dummy/db/schema.rb @@ -0,0 +1,59 @@ +# 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: 2023_10_30_145254) 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 ["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 ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true + end + + create_table "activejob_web_jobs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade 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.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..61b9787 --- /dev/null +++ b/test/dummy/db/seeds.rb @@ -0,0 +1,49 @@ +10.times do |i| + job = ActivejobWebJob.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') +ActivejobWebJob.first.template_file.attach(io: file, filename: 'sample.png') From 1b1751fad7f03e510d983cbe3f0af8305a0cb806 Mon Sep 17 00:00:00 2001 From: mohammednazeer Date: Wed, 1 Nov 2023 12:43:18 +0530 Subject: [PATCH 2/3] updated-changes --- lib/activejob/web.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/activejob/web.rb b/lib/activejob/web.rb index 173f6ce..510e8d8 100644 --- a/lib/activejob/web.rb +++ b/lib/activejob/web.rb @@ -3,8 +3,5 @@ module Activejob module Web - # config.generators do |g| - # g.test_framework :rspec - # end end end From e23e1715d1fcfacfed212551f30764da1c029caf Mon Sep 17 00:00:00 2001 From: mohammednazeer Date: Thu, 2 Nov 2023 11:00:39 +0530 Subject: [PATCH 3/3] Updated-class-names-with-namespace --- .../activejob_web/jobs_controller.rb | 19 ++++++++++++++ .../activejob_web_jobs_controller.rb | 19 -------------- app/helpers/activejob_web/jobs_helper.rb | 2 ++ app/helpers/activejob_web_jobs_helper.rb | 2 -- app/models/activejob_web.rb | 5 ++++ .../job.rb} | 2 +- .../jobs}/index.html.erb | 4 +-- app/views/activejob_web/jobs/show.html.erb | 14 ++++++++++ app/views/activejob_web_jobs/show.html.erb | 15 ----------- config/routes.rb | 5 +++- .../helpers/activejob_web/jobs_helper_spec.rb | 15 +++++++++++ spec/models/activejob_web/job_spec.rb | 5 ++++ spec/requests/activejob_web/jobs_spec.rb | 23 ++++++++++++++++ spec/requests/activejob_web_jobs_spec.rb | 26 ------------------- test/dummy/db/seeds.rb | 4 +-- test/models/activejob_web_job_test.rb | 7 +++++ 16 files changed, 99 insertions(+), 68 deletions(-) create mode 100644 app/controllers/activejob_web/jobs_controller.rb delete mode 100644 app/controllers/activejob_web_jobs_controller.rb create mode 100644 app/helpers/activejob_web/jobs_helper.rb delete mode 100644 app/helpers/activejob_web_jobs_helper.rb create mode 100644 app/models/activejob_web.rb rename app/models/{activejob_web_job.rb => activejob_web/job.rb} (92%) rename app/views/{activejob_web_jobs => activejob_web/jobs}/index.html.erb (89%) create mode 100644 app/views/activejob_web/jobs/show.html.erb delete mode 100644 app/views/activejob_web_jobs/show.html.erb create mode 100644 spec/helpers/activejob_web/jobs_helper_spec.rb create mode 100644 spec/models/activejob_web/job_spec.rb create mode 100644 spec/requests/activejob_web/jobs_spec.rb delete mode 100644 spec/requests/activejob_web_jobs_spec.rb create mode 100644 test/models/activejob_web_job_test.rb diff --git a/app/controllers/activejob_web/jobs_controller.rb b/app/controllers/activejob_web/jobs_controller.rb new file mode 100644 index 0000000..c9454f3 --- /dev/null +++ b/app/controllers/activejob_web/jobs_controller.rb @@ -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 diff --git a/app/controllers/activejob_web_jobs_controller.rb b/app/controllers/activejob_web_jobs_controller.rb deleted file mode 100644 index 53dde4e..0000000 --- a/app/controllers/activejob_web_jobs_controller.rb +++ /dev/null @@ -1,19 +0,0 @@ -class ActivejobWebJobsController < ApplicationController - - def index - @activejob_web_jobs = ActivejobWebJob.all - end - - def show - @activejob_web_job = ActivejobWebJob.find(params[:id]) - end - - def download_pdf - if @activejob_web_job.template_file.attached? - send_file @activejob_web_job.template_file.download - else - flash[:error] = "Template file not found." - redirect_to @activejob_web_job - 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..1712e5b --- /dev/null +++ b/app/helpers/activejob_web/jobs_helper.rb @@ -0,0 +1,2 @@ +module ActivejobWeb::JobsHelper +end diff --git a/app/helpers/activejob_web_jobs_helper.rb b/app/helpers/activejob_web_jobs_helper.rb deleted file mode 100644 index 29485fc..0000000 --- a/app/helpers/activejob_web_jobs_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ActivejobWebJobsHelper -end diff --git a/app/models/activejob_web.rb b/app/models/activejob_web.rb new file mode 100644 index 0000000..0dd4bde --- /dev/null +++ b/app/models/activejob_web.rb @@ -0,0 +1,5 @@ +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 similarity index 92% rename from app/models/activejob_web_job.rb rename to app/models/activejob_web/job.rb index e549807..89b9b08 100644 --- a/app/models/activejob_web_job.rb +++ b/app/models/activejob_web/job.rb @@ -1,4 +1,4 @@ -class ActivejobWebJob < ApplicationRecord +class ActivejobWeb::Job < ApplicationRecord self.primary_key = 'id' # Validations validates :title, presence: true, length: { maximum: 255 } # Maximum 255 characters for title diff --git a/app/views/activejob_web_jobs/index.html.erb b/app/views/activejob_web/jobs/index.html.erb similarity index 89% rename from app/views/activejob_web_jobs/index.html.erb rename to app/views/activejob_web/jobs/index.html.erb index 2a14a5b..5a36384 100644 --- a/app/views/activejob_web_jobs/index.html.erb +++ b/app/views/activejob_web/jobs/index.html.erb @@ -11,7 +11,7 @@ - <% @activejob_web_jobs.each do |job| %> + <% @jobs.each do |job| %> <%= job.title %> <%= job.description %> @@ -21,4 +21,4 @@ <% end %> - + \ 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..32456a6 --- /dev/null +++ b/app/views/activejob_web/jobs/show.html.erb @@ -0,0 +1,14 @@ +

<%= @job.title %>

+ +

Description: <%= @job.description %>

+

Input Arguments: <%= @job.input_arguments %>

+

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

+

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

+

Priority: <%= @job.priority %>

+

Queue: <%= @job.queue %>

+<% if @job.template_file.attached? %> + <%= link_to "Download PDF", 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/app/views/activejob_web_jobs/show.html.erb b/app/views/activejob_web_jobs/show.html.erb deleted file mode 100644 index a1f5f67..0000000 --- a/app/views/activejob_web_jobs/show.html.erb +++ /dev/null @@ -1,15 +0,0 @@ -

<%= @activejob_web_job.title %>

- -

Description: <%= @activejob_web_job.description %>

-

Input Arguments: <%= @activejob_web_job.input_arguments %>

-

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

-

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

-

Priority: <%= @activejob_web_job.priority %>

-

Queue: <%= @activejob_web_job.queue %>

-<% if @activejob_web_job.template_file.attached? %> - <%= link_to "Download PDF", rails_blob_path(@activejob_web_job.template_file, disposition: "attachment"), class: "btn btn-primary" %> -<% else %> -

no template available

-<% end %> - -<%= link_to 'Back', activejob_web_jobs_path %> diff --git a/config/routes.rb b/config/routes.rb index a632385..bc0511c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,8 +1,11 @@ Rails.application.routes.draw do - resources :activejob_web_jobs do + namespace :activejob_web do + root 'jobs#index' + resources :jobs do member do get :download_pdf end + end end end 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..3764efc --- /dev/null +++ b/spec/helpers/activejob_web/jobs_helper_spec.rb @@ -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 diff --git a/spec/models/activejob_web/job_spec.rb b/spec/models/activejob_web/job_spec.rb new file mode 100644 index 0000000..3efaa53 --- /dev/null +++ b/spec/models/activejob_web/job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ActivejobWeb::Job, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +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..08b6e1f --- /dev/null +++ b/spec/requests/activejob_web/jobs_spec.rb @@ -0,0 +1,23 @@ +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") + get activejob_web_job_path(data.id) + expect(response).to render_template('show') + expect(response).to have_http_status 200 + end + end + end +end \ No newline at end of file diff --git a/spec/requests/activejob_web_jobs_spec.rb b/spec/requests/activejob_web_jobs_spec.rb deleted file mode 100644 index 8cc1603..0000000 --- a/spec/requests/activejob_web_jobs_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -# spec/requests/jobs_request_spec.rb -require 'rails_helper' - -RSpec.describe "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 = ActivejobWebJob.create(title: "Test1", description: "Test description") - get activejob_web_job_path(data.id) - expect(response).to render_template('show') - expect(response).to have_http_status 200 - end - end -end -end - diff --git a/test/dummy/db/seeds.rb b/test/dummy/db/seeds.rb index 61b9787..ee11ad0 100644 --- a/test/dummy/db/seeds.rb +++ b/test/dummy/db/seeds.rb @@ -1,5 +1,5 @@ 10.times do |i| - job = ActivejobWebJob.new( + job = ActivejobWeb::Job.new( title: "Job Title #{i + 1}", description: "Job Description #{i + 1}", input_arguments: [ @@ -46,4 +46,4 @@ #==== 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') -ActivejobWebJob.first.template_file.attach(io: file, filename: 'sample.png') +ActivejobWeb::Job.first.template_file.attach(io: file, filename: 'sample.png') diff --git a/test/models/activejob_web_job_test.rb b/test/models/activejob_web_job_test.rb new file mode 100644 index 0000000..9a10c0c --- /dev/null +++ b/test/models/activejob_web_job_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class ActivejobWebJobTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end