mirror of
https://github.com/plashchynski/crono.git
synced 2026-03-29 22:02:06 +02:00
Cleanup and get rspec to run again
This commit is contained in:
BIN
spec/internal/:memory
Normal file
BIN
spec/internal/:memory
Normal file
Binary file not shown.
0
spec/internal/app/assets/config/manifest.js
Normal file
0
spec/internal/app/assets/config/manifest.js
Normal file
3
spec/internal/app/controllers/application_controller.rb
Normal file
3
spec/internal/app/controllers/application_controller.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
protect_from_forgery with: :exception
|
||||
end
|
||||
5
spec/internal/app/controllers/pages_controller.rb
Normal file
5
spec/internal/app/controllers/pages_controller.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class PagesController < ApplicationController
|
||||
def index
|
||||
#
|
||||
end
|
||||
end
|
||||
1
spec/internal/app/views/pages/index.html.erb
Normal file
1
spec/internal/app/views/pages/index.html.erb
Normal file
@@ -0,0 +1 @@
|
||||
<p>Hello World</p>
|
||||
22
spec/internal/config/application.rb
Normal file
22
spec/internal/config/application.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
require_relative 'boot'
|
||||
|
||||
require 'rails/all'
|
||||
|
||||
# Require the gems listed in Gemfile, including any gems
|
||||
# you've limited to :test, :development, or :production.
|
||||
Bundler.require(*Rails.groups)
|
||||
require 'crono'
|
||||
|
||||
module Dummy
|
||||
class Application < Rails::Application
|
||||
config.load_defaults Rails::VERSION::STRING.to_f
|
||||
|
||||
# Configuration for the application, engines, and railties goes here.
|
||||
#
|
||||
# These settings can be overridden in specific environments using the files
|
||||
# in config/environments, which are processed later.
|
||||
#
|
||||
# config.time_zone = "Central Time (US & Canada)"
|
||||
# config.eager_load_paths << Rails.root.join("extras")
|
||||
end
|
||||
end
|
||||
5
spec/internal/config/boot.rb
Normal file
5
spec/internal/config/boot.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
# Set up gems listed in the Gemfile.
|
||||
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
|
||||
|
||||
require "bundler/setup" if File.exist?(ENV['BUNDLE_GEMFILE'])
|
||||
$LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
|
||||
3
spec/internal/config/database.yml
Normal file
3
spec/internal/config/database.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
test:
|
||||
adapter: sqlite3
|
||||
database: db/crono_test.sqlite
|
||||
2
spec/internal/config/environment.rb
Normal file
2
spec/internal/config/environment.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
# Load the Rails application.
|
||||
require_relative 'application'
|
||||
3
spec/internal/config/routes.rb
Normal file
3
spec/internal/config/routes.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
Rails.application.routes.draw do
|
||||
root 'pages#index'
|
||||
end
|
||||
3
spec/internal/config/storage.yml
Normal file
3
spec/internal/config/storage.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
test:
|
||||
service: Disk
|
||||
root: /Users/chris/Sites/_playground/crono/tmp/storage
|
||||
BIN
spec/internal/db/crono_test.sqlite
Normal file
BIN
spec/internal/db/crono_test.sqlite
Normal file
Binary file not shown.
10
spec/internal/db/schema.rb
Normal file
10
spec/internal/db/schema.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
ActiveRecord::Schema.define do
|
||||
create_table :crono_jobs do |t|
|
||||
t.string :job_id, null: false
|
||||
t.text :log, limit: 1_073_741_823 # LONGTEXT for MySQL
|
||||
t.datetime :last_performed_at
|
||||
t.boolean :healthy
|
||||
t.timestamps null: false
|
||||
end
|
||||
add_index :crono_jobs, [:job_id], unique: true
|
||||
end
|
||||
1
spec/internal/log/.gitignore
vendored
Normal file
1
spec/internal/log/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.log
|
||||
0
spec/internal/public/favicon.ico
Normal file
0
spec/internal/public/favicon.ico
Normal file
@@ -1,5 +1,17 @@
|
||||
require 'spec_helper'
|
||||
|
||||
class TestJob
|
||||
def perform(args)
|
||||
puts 'Test!'
|
||||
end
|
||||
end
|
||||
|
||||
class TestFailingJob
|
||||
def perform(args)
|
||||
raise 'Some error'
|
||||
end
|
||||
end
|
||||
|
||||
describe Crono::Job do
|
||||
let(:period) { Crono::Period.new(2.day, at: '15:00') }
|
||||
let(:job_args) {[{some: 'data'}]}
|
||||
@@ -71,7 +83,7 @@ describe Crono::Job do
|
||||
it 'should call perform of performer with data' do
|
||||
test_job = double()
|
||||
expect(TestJob).to receive(:new).and_return(test_job)
|
||||
expect(test_job).to receive(:perform).with({'some' => 'data'})
|
||||
expect(test_job).to receive(:perform).with([{ 'some' => 'data' }])
|
||||
thread = job_with_args.perform.join
|
||||
expect(thread).to be_stop
|
||||
end
|
||||
|
||||
31
spec/models/crono/crono_job_spec.rb
Normal file
31
spec/models/crono/crono_job_spec.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
require 'spec_helper'
|
||||
require 'rack/test'
|
||||
|
||||
module Crono
|
||||
RSpec.describe Crono::CronoJob, type: :model do
|
||||
let(:valid_attrs) do
|
||||
{
|
||||
job_id: 'Perform TestJob every 3 days'
|
||||
}
|
||||
end
|
||||
|
||||
it 'should validate presence of job_id' do
|
||||
@crono_job = Crono::CronoJob.new
|
||||
expect(@crono_job).not_to be_valid
|
||||
expect(@crono_job.errors.added?(:job_id, :blank)).to be true
|
||||
end
|
||||
|
||||
it 'should validate uniqueness of job_id' do
|
||||
Crono::CronoJob.create!(job_id: 'TestJob every 2 days')
|
||||
@crono_job = Crono::CronoJob.create(job_id: 'TestJob every 2 days')
|
||||
expect(@crono_job).not_to be_valid
|
||||
expect(@crono_job.errors.size).to be 1
|
||||
end
|
||||
|
||||
it 'should save job_id to DB' do
|
||||
Crono::CronoJob.create!(valid_attrs)
|
||||
@crono_job = Crono::CronoJob.find_by(job_id: valid_attrs[:job_id])
|
||||
expect(@crono_job).to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,28 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Crono::CronoJob do
|
||||
let(:valid_attrs) do
|
||||
{
|
||||
job_id: 'Perform TestJob every 3 days'
|
||||
}
|
||||
end
|
||||
|
||||
it 'should validate presence of job_id' do
|
||||
@crono_job = Crono::CronoJob.new
|
||||
expect(@crono_job).not_to be_valid
|
||||
expect(@crono_job.errors.added?(:job_id, :blank)).to be true
|
||||
end
|
||||
|
||||
it 'should validate uniqueness of job_id' do
|
||||
Crono::CronoJob.create!(job_id: 'TestJob every 2 days')
|
||||
@crono_job = Crono::CronoJob.create(job_id: 'TestJob every 2 days')
|
||||
expect(@crono_job).not_to be_valid
|
||||
expect(@crono_job.errors.added?(:job_id, :taken)).to be true
|
||||
end
|
||||
|
||||
it 'should save job_id to DB' do
|
||||
Crono::CronoJob.create!(valid_attrs)
|
||||
@crono_job = Crono::CronoJob.find_by(job_id: valid_attrs[:job_id])
|
||||
expect(@crono_job).to be_present
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,11 @@
|
||||
require 'spec_helper'
|
||||
|
||||
class TestJob
|
||||
def perform
|
||||
puts 'Test!'
|
||||
end
|
||||
end
|
||||
|
||||
describe Crono::PerformerProxy do
|
||||
it 'should add job to schedule' do
|
||||
expect(Crono.scheduler).to receive(:add_job).with(kind_of(Crono::Job))
|
||||
|
||||
89
spec/rails_helper.rb
Normal file
89
spec/rails_helper.rb
Normal file
@@ -0,0 +1,89 @@
|
||||
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
||||
require 'spec_helper'
|
||||
ENV['RAILS_ENV'] ||= 'test'
|
||||
require File.expand_path('../spec/internal/config/environment.rb', __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!
|
||||
require 'bundler/setup'
|
||||
Bundler.setup
|
||||
|
||||
$LOAD_PATH.unshift File.expand_path('../../lib', __dir__)
|
||||
|
||||
require 'timecop'
|
||||
require 'byebug'
|
||||
require 'crono'
|
||||
|
||||
# setting default time zone
|
||||
# In Rails project, Time.zone_default equals "UTC"
|
||||
Time.zone_default = Time.find_zone('UTC')
|
||||
|
||||
ActiveRecord::Base.logger = Logger.new($stdout)
|
||||
|
||||
ActiveRecord::Base.establish_connection(
|
||||
adapter: 'sqlite3',
|
||||
database: ':memory'
|
||||
)
|
||||
ActiveRecord::Schema.define do
|
||||
require_relative '../lib/generators/crono/install/templates/migrations/create_crono_jobs.rb'
|
||||
@migration_version = '[6.1]'
|
||||
end
|
||||
CreateCronoJobs.up
|
||||
|
||||
|
||||
# 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
|
||||
@@ -1,5 +1,11 @@
|
||||
require 'spec_helper'
|
||||
|
||||
class TestJob
|
||||
def perform
|
||||
puts 'Test!'
|
||||
end
|
||||
end
|
||||
|
||||
describe Crono::Scheduler do
|
||||
let(:scheduler) { Crono::Scheduler.new }
|
||||
|
||||
|
||||
@@ -1,32 +1,19 @@
|
||||
require 'bundler/setup'
|
||||
Bundler.setup
|
||||
require 'bundler'
|
||||
|
||||
$LOAD_PATH.unshift File.expand_path('../../lib', __dir__)
|
||||
Bundler.require :default, :development
|
||||
|
||||
require 'timecop'
|
||||
require 'byebug'
|
||||
require 'crono'
|
||||
require 'generators/crono/install/templates/migrations/create_crono_jobs.rb'
|
||||
# If you're using all parts of Rails:
|
||||
Combustion.initialize! :all
|
||||
# Or, load just what you need:
|
||||
# Combustion.initialize! :active_record, :action_controller
|
||||
|
||||
# setting default time zone
|
||||
# In Rails project, Time.zone_default equals "UTC"
|
||||
Time.zone_default = Time.find_zone('UTC')
|
||||
require 'rspec/rails'
|
||||
# If you're using Capybara:
|
||||
# require 'capybara/rails'
|
||||
|
||||
ActiveRecord::Base.establish_connection(
|
||||
adapter: 'sqlite3',
|
||||
database: 'file::memory:?cache=shared'
|
||||
)
|
||||
|
||||
ActiveRecord::Base.logger = Logger.new($stdout)
|
||||
CreateCronoJobs.up
|
||||
|
||||
class TestJob
|
||||
def perform
|
||||
end
|
||||
end
|
||||
|
||||
class TestFailingJob
|
||||
def perform
|
||||
raise 'Some error'
|
||||
RSpec.configure do |config|
|
||||
config.use_transactional_fixtures = true
|
||||
config.mock_with :rspec do |mocks|
|
||||
mocks.allow_message_expectations_on_nil = true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -45,7 +45,7 @@ describe Crono::Engine do
|
||||
|
||||
describe '/job/:id' do
|
||||
it 'should show job log' do
|
||||
get "/job/#{@test_job.id}"
|
||||
get "/jobs/#{@test_job.id}"
|
||||
expect(last_response).to be_ok
|
||||
expect(last_response.body).to include @test_job_id
|
||||
expect(last_response.body).to include @test_job_log
|
||||
@@ -54,7 +54,7 @@ describe Crono::Engine do
|
||||
it 'should show a message about the unhealthy job' do
|
||||
message = 'An error occurs during the last execution of this job'
|
||||
@test_job.update(healthy: false)
|
||||
get "/job/#{@test_job.id}"
|
||||
get "/jobs/#{@test_job.id}"
|
||||
expect(last_response.body).to include message
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user