Skip to content

Commit

Permalink
Merge pull request #20 from kortirso/issue_17
Browse files Browse the repository at this point in the history
IS-17 Testing
  • Loading branch information
kortirso authored Jul 31, 2024
2 parents 0a90330 + a6fd555 commit 368724f
Show file tree
Hide file tree
Showing 72 changed files with 1,787 additions and 7 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Main CI

on: [push]

jobs:
linters:
name: Linters
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2.0

- name: Install latest bundler
run: |
gem install bundler --no-document
bundle config set without 'tools benchmarks docs'
- name: Bundle install
run: bundle install --jobs 4 --retry 3

- name: Run linters
run: |
bundle exec rubocop
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/.bundle/
˘/.bundle/
/doc/
/log/*.log
/pkg/
/tmp/
/spec/dummy/log/*.log
/spec/dummy/storage/
/spec/dummy/tmp/
/db

Expand Down
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--require rails_helper
--format progress
--color
22 changes: 22 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require:
- rubocop-performance
- rubocop-factory_bot
- rubocop-rake
- rubocop-rspec
- rubocop-rspec_rails

AllCops:
Exclude:
Expand Down Expand Up @@ -52,3 +55,22 @@ Gemspec/DevelopmentDependencies:

Metrics/MethodLength:
Max: 11

RSpec/ExampleLength:
Max: 20

RSpec/NestedGroups:
Max: 8

RSpec/ContextWording:
Prefixes:
- when
- with
- without
- and
- if
- in
- for

FactoryBot/ConsistentParenthesesStyle:
Enabled: false
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }

# Specify your gem's dependencies in que-web_engine.gemspec.
gemspec

group :test do
gem 'database_cleaner', '> 2.0.0'
gem 'factory_bot_rails', '> 6.0.0'
gem 'rails-controller-testing', '> 1.0.0'
gem 'rspec-rails', '> 6.0.0'
end
66 changes: 66 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,23 @@ GEM
concurrent-ruby (1.3.3)
connection_pool (2.4.1)
crass (1.0.6)
database_cleaner (2.0.2)
database_cleaner-active_record (>= 2, < 3)
database_cleaner-active_record (2.2.0)
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
date (3.3.4)
diff-lcs (1.5.1)
drb (2.2.1)
erubi (1.13.0)
factory_bot (6.4.6)
activesupport (>= 5.0.0)
factory_bot_rails (6.4.3)
factory_bot (~> 6.4)
railties (>= 5.0.0)
ffi (1.17.0-arm64-darwin)
ffi (1.17.0-x86_64-darwin)
globalid (1.2.1)
activesupport (>= 6.1)
i18n (1.14.5)
Expand Down Expand Up @@ -161,6 +175,10 @@ GEM
activesupport (= 7.1.3.4)
bundler (>= 1.15.0)
railties (= 7.1.3.4)
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 @@ -185,6 +203,23 @@ GEM
io-console (~> 0.5)
rexml (3.3.2)
strscan
rspec-core (3.13.0)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-rails (6.1.3)
actionpack (>= 6.1)
activesupport (>= 6.1)
railties (>= 6.1)
rspec-core (~> 3.13)
rspec-expectations (~> 3.13)
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-support (3.13.1)
rubocop (1.65.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
Expand All @@ -198,15 +233,38 @@ GEM
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.3)
parser (>= 3.3.1.0)
rubocop-factory_bot (2.26.1)
rubocop (~> 1.61)
rubocop-performance (1.21.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (3.0.3)
rubocop (~> 1.61)
rubocop-rspec_rails (2.30.0)
rubocop (~> 1.61)
rubocop-rspec (~> 3, >= 3.0.1)
ruby-progressbar (1.13.0)
sassc (2.4.0)
ffi (~> 1.9)
sassc-rails (2.1.2)
railties (>= 4.0.0)
sassc (>= 2.0)
sprockets (> 3.0)
sprockets-rails
tilt
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
sprockets-rails (3.5.1)
actionpack (>= 6.1)
activesupport (>= 6.1)
sprockets (>= 3.0.0)
stringio (3.1.1)
strscan (3.1.0)
thor (1.3.1)
tilt (2.4.0)
timeout (0.4.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
Expand All @@ -223,13 +281,21 @@ PLATFORMS

DEPENDENCIES
bundler
database_cleaner (> 2.0.0)
factory_bot_rails (> 6.0.0)
pg (> 1.0)
puma (= 6.3.0)
que-view!
rails-controller-testing (> 1.0.0)
rake (~> 13.0)
rspec-rails (> 6.0.0)
rubocop (~> 1.39)
rubocop-factory_bot (~> 2.0)
rubocop-performance (~> 1.8)
rubocop-rake (~> 0.6)
rubocop-rspec (~> 3.0)
rubocop-rspec_rails (~> 2.0)
sassc-rails

BUNDLED WITH
2.4.12
Binary file removed app/.DS_Store
Binary file not shown.
Binary file removed app/assets/.DS_Store
Binary file not shown.
Binary file removed app/controllers/.DS_Store
Binary file not shown.
Binary file removed app/helpers/.DS_Store
Binary file not shown.
Binary file removed app/views/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion app/views/que/view/jobs/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1><%= params[:status].capitalize %> jobs</h1>
<h1><%= params[:status]&.capitalize %> jobs</h1>
<%= form_with url: jobs_path, method: :get, class: 'search-form' do |form| %>
<%= form.hidden_field :status, value: params[:status] %>
<div class="row">
Expand Down
2 changes: 1 addition & 1 deletion app/views/que/view/jobs/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr>
<th>Args</th>
<td>
<% @job.dig(:args, 0, :arguments).each do |argument| %>
<% Array(@job.dig(:args, 0, :arguments)).each do |argument| %>
<p><%= argument %></p>
<% end %>
</td>
Expand Down
Binary file removed lib/.DS_Store
Binary file not shown.
Binary file removed lib/que/.DS_Store
Binary file not shown.
6 changes: 3 additions & 3 deletions lib/que/view/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def fetch_dashboard_stats_sql
SELECT count(*) AS total,
count(locks.job_id) AS running,
coalesce(sum((error_count > 0 AND locks.job_id IS NULL AND expired_at IS NULL)::int), 0) AS failing,
coalesce(sum((error_count = 0 AND locks.job_id IS NULL)::int), 0) AS scheduled,
coalesce(sum((error_count = 0 AND locks.job_id IS NULL AND finished_at IS NULL AND expired_at IS NULL)::int), 0) AS scheduled,
coalesce(sum((finished_at IS NOT NULL)::int), 0) AS finished,
coalesce(sum((expired_at IS NOT NULL)::int), 0) AS expired
FROM que_jobs
Expand All @@ -121,7 +121,7 @@ def fetch_queue_metrics_sql
WHEN expired_at IS NOT NULL THEN 'expired'
WHEN finished_at IS NOT NULL THEN 'finished'
WHEN locks.job_id IS NULL AND error_count > 0 AND expired_at IS NULL THEN 'failing'
WHEN locks.job_id IS NULL AND error_count = 0 THEN 'scheduled'
WHEN locks.job_id IS NULL AND error_count = 0 AND finished_at IS NULL AND expired_at IS NULL THEN 'scheduled'
ELSE 'running'
END status
FROM que_jobs
Expand All @@ -135,7 +135,7 @@ def fetch_queue_metrics_sql
WHEN expired_at IS NOT NULL THEN 'expired'
WHEN finished_at IS NOT NULL THEN 'finished'
WHEN locks.job_id IS NULL AND error_count > 0 AND expired_at IS NULL THEN 'failing'
WHEN locks.job_id IS NULL AND error_count = 0 THEN 'scheduled'
WHEN locks.job_id IS NULL AND error_count = 0 AND finished_at IS NULL AND expired_at IS NULL THEN 'scheduled'
ELSE 'running'
END
SQL
Expand Down
4 changes: 4 additions & 0 deletions que-view.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'puma', '6.3.0'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rubocop', '~> 1.39'
spec.add_development_dependency 'rubocop-factory_bot', '~> 2.0'
spec.add_development_dependency 'rubocop-performance', '~> 1.8'
spec.add_development_dependency 'rubocop-rake', '~> 0.6'
spec.add_development_dependency 'rubocop-rspec', '~> 3.0'
spec.add_development_dependency 'rubocop-rspec_rails', '~> 2.0'
spec.add_development_dependency 'sassc-rails'
end
99 changes: 99 additions & 0 deletions spec/controllers/que/view/jobs_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# frozen_string_literal: true

describe Que::View::JobsController do
routes { Que::View::Engine.routes }

describe 'GET#index' do
it 'renders page' do
get :index

expect(response).to be_successful
end
end

describe 'PATCH#update' do
context 'for unexisting job' do
it 'redirects to root_path' do
patch :update, params: { id: 0 }

expect(response).to redirect_to root_path
end
end

context 'for existing job' do
let!(:que_job) { create :que_job, run_at: 1.week.before, expired_at: 1.week.before }

it 'redirects to root_path', :aggregate_failures do
patch :update, params: { id: que_job.id }

expect(que_job.reload.expired_at).to be_nil
expect(response).to redirect_to root_path
end
end
end

describe 'POST#reschedule_all' do
context 'for unexisting job' do
it 'does not reschedule any job' do
post :reschedule_all, params: { status: 'scheduled' }

expect(response).to redirect_to jobs_path(status: 'scheduled')
end
end

context 'for existing job' do
let!(:scheduled_que_job) { create :que_job, run_at: nil }
let!(:expired_que_job) { create :que_job, :expired }

it 'reschedules jobs', :aggregate_failures do
post :reschedule_all, params: { status: 'scheduled' }

expect(scheduled_que_job.reload.run_at).not_to be_nil
expect(expired_que_job.reload.expired_at).to be_nil
expect(response).to redirect_to jobs_path(status: 'scheduled')
end
end
end

describe 'DELETE#destroy' do
context 'for unexisting jobs' do
it 'does not destroy any job', :aggregate_failures do
expect { delete :destroy_all, params: { status: 'scheduled' } }.not_to change(QueJob, :count)
expect(response).to redirect_to jobs_path(status: 'scheduled')
end
end

context 'for existing jobs' do
before do
create :que_job
create :que_job, :failing
end

it 'destroys jobs with specific status', :aggregate_failures do
expect { delete :destroy_all, params: { status: 'scheduled' } }.to change(QueJob, :count).by(-1)
expect(response).to redirect_to jobs_path(status: 'scheduled')
end
end
end

describe 'DELETE#destroy_all' do
context 'with unexisting jobs' do
it 'does not destroy any job', :aggregate_failures do
expect { delete :destroy_all, params: { status: 'scheduled' } }.not_to change(QueJob, :count)
expect(response).to redirect_to jobs_path(status: 'scheduled')
end
end

context 'with existing jobs' do
before do
create :que_job
create :que_job, :failing
end

it 'destroys jobs with specific status', :aggregate_failures do
expect { delete :destroy_all, params: { status: 'scheduled' } }.to change(QueJob, :count).by(-1)
expect(response).to redirect_to jobs_path(status: 'scheduled')
end
end
end
end
22 changes: 22 additions & 0 deletions spec/controllers/que/view/queue_metrics_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

describe Que::View::QueueMetricsController do
routes { Que::View::Engine.routes }

describe 'GET#index' do
context 'without authorization' do
before do
create :que_job
create :que_job, :failing
create :que_job, :finished
create :que_job, :expired

get :index
end

it 'renders page' do
expect(response).to be_successful
end
end
end
end
Loading

0 comments on commit 368724f

Please sign in to comment.