diff --git a/lib/active_job/queue_adapters/litejob_adapter.rb b/lib/active_job/queue_adapters/litejob_adapter.rb index 6fe05ed..ff4c3e6 100644 --- a/lib/active_job/queue_adapters/litejob_adapter.rb +++ b/lib/active_job/queue_adapters/litejob_adapter.rb @@ -30,7 +30,7 @@ def enqueue(job) # :nodoc: end def enqueue_at(job, time) # :nodoc: - time = time.from_now if time.respond_to?(:from_now) #is_a?(ActiveSupport::Duration) + time = time.from_now if time.respond_to?(:from_now) # is_a?(ActiveSupport::Duration) Job.queue = job.queue_name Job.perform_at(time, job.serialize) end diff --git a/lib/active_record/connection_adapters/litedb_adapter.rb b/lib/active_record/connection_adapters/litedb_adapter.rb index 0b90670..f57b27e 100644 --- a/lib/active_record/connection_adapters/litedb_adapter.rb +++ b/lib/active_record/connection_adapters/litedb_adapter.rb @@ -92,9 +92,9 @@ module DatabaseTasks end end -ActiveRecord::ConnectionAdapters.register( - "litedb", "ActiveRecord::ConnectionAdapters::LitedbAdapter", - "active_record/connection_adapters/litedb_adapter" -) if ActiveRecord::ConnectionAdapters.respond_to?(:register) - - +if ActiveRecord::ConnectionAdapters.respond_to?(:register) + ActiveRecord::ConnectionAdapters.register( + "litedb", "ActiveRecord::ConnectionAdapters::LitedbAdapter", + "active_record/connection_adapters/litedb_adapter" + ) +end diff --git a/lib/active_support/cache/litecache.rb b/lib/active_support/cache/litecache.rb index 0c02b3e..a0fca29 100644 --- a/lib/active_support/cache/litecache.rb +++ b/lib/active_support/cache/litecache.rb @@ -6,7 +6,6 @@ module ActiveSupport module Cache - self.format_version = 7.0 class Litecache < Store diff --git a/lib/litestack/liteboard/liteboard.rb b/lib/litestack/liteboard/liteboard.rb index 26baa5a..b8c2551 100644 --- a/lib/litestack/liteboard/liteboard.rb +++ b/lib/litestack/liteboard/liteboard.rb @@ -12,7 +12,7 @@ class Liteboard @@res_mapping = {"hour" => "minute", "day" => "hour", "week" => "day", "year" => "week"} @@templates = {} @@app = proc do |env| - case path = env["PATH_INFO"] + case env["PATH_INFO"] when "/" Liteboard.new(env).call(:index) when "/topics/Litejob" @@ -24,13 +24,12 @@ class Liteboard when "/topics/Litecable" Liteboard.new(env).call(:litecable) end - end def initialize(env) @env = env @req = Rack::Request.new(@env) - @params = @req.params + @params = @req.params @running = true @lm = Litemetric.instance end @@ -224,7 +223,7 @@ def litejob @events.each do |event| data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event[:name]) event["counts"] = data_points.collect { |r| [r["rtime"], r["rcount"] || 0] } - event["values"] = data_points.collect { |r| [r["rtime"], (r["rtotal"] || 0.0)] } + event["values"] = data_points.collect { |r| [r["rtime"], r["rtotal"] || 0.0] } end @snapshot = read_snapshot(@topic) @size = begin diff --git a/lib/litestack/litecache.rb b/lib/litestack/litecache.rb index 39086bf..50c580b 100644 --- a/lib/litestack/litecache.rb +++ b/lib/litestack/litecache.rb @@ -125,7 +125,7 @@ def set_unless_exists(key, value, expires_in = nil) # if the key doesn't exist or it is expired then null will be returned def get(key) key = key.to_s - if (record = run_stmt(:getter, key)[0]) + if (record = run_stmt(:getter, key)[0]) capture(:get, key, 1) return record[1] end @@ -223,7 +223,7 @@ def snapshot } } end - + private def setup diff --git a/lib/litestack/liteconnection.rb b/lib/litestack/liteconnection.rb index fdf44fa..a9cb5eb 100644 --- a/lib/litestack/liteconnection.rb +++ b/lib/litestack/liteconnection.rb @@ -70,7 +70,7 @@ def configure(options = {}) end @options = defaults.merge(options) config = begin - YAML.load(ERB.new(File.read(@options[:config_path])).result) + YAML.safe_load(ERB.new(File.read(@options[:config_path])).result) rescue {} end # an empty hash won't hurt @@ -122,24 +122,20 @@ def acquire_connection if @checked_out_conn yield @checked_out_conn else - @conn.acquire{ |conn| yield conn } + @conn.acquire { |conn| yield conn } end end - # this will force the other run_* methods to use the + # this will force the other run_* methods to use the # checked out connection if one exists def with_connection - @conn.acquire do |conn| - begin - @checked_out_conn = conn - yield conn - ensure - @checked_out_conn = nil - end + @conn.acquire do |conn| + @checked_out_conn = conn + yield conn + ensure + @checked_out_conn = nil end end - - def create_pooled_connection(count = 1) count = 1 unless count&.is_a?(Integer) diff --git a/lib/litestack/litejobqueue.rb b/lib/litestack/litejobqueue.rb index 651527d..5d16c0d 100644 --- a/lib/litestack/litejobqueue.rb +++ b/lib/litestack/litejobqueue.rb @@ -137,14 +137,14 @@ def stop # @@queue = nil close end - + private - + def prepare_search_options(opts) sql_opts = super(opts) sql_opts[:klass] = opts[:klass] sql_opts[:params] = opts[:params] - sql_opts + sql_opts end def exit_callback @@ -189,7 +189,7 @@ def schedule(spawn = false, &block) # create a worker according to environment def create_worker # temporarily stop this feature until a better solution is implemented - #return if defined?(Rails) && !defined?(Rails::Server) + # return if defined?(Rails) && !defined?(Rails::Server) Litescheduler.spawn do worker_sleep_index = 0 while @running @@ -197,7 +197,7 @@ def create_worker @queues.each do |priority, queues| # iterate through the levels queues.each do |queue, spawns| # iterate through the queues in the level batched = 0 - + while (batched < priority) && (payload = pop(queue, 1)) # fearlessly use the same queue object capture(:dequeue, queue) processed += 1 diff --git a/lib/litestack/litequeue.rb b/lib/litestack/litequeue.rb index 2c2286e..29ddc1e 100644 --- a/lib/litestack/litequeue.rb +++ b/lib/litestack/litequeue.rb @@ -111,7 +111,7 @@ def snapshot queues: queues } end - + def find(opts = {}) run_stmt(:search, prepare_search_options(opts)) end @@ -120,12 +120,28 @@ def find(opts = {}) def prepare_search_options(opts) sql_opts = {} - sql_opts[:fire_at_from] = opts[:fire_at][0] rescue nil - sql_opts[:fire_at_to] = opts[:fire_at][1] rescue nil - sql_opts[:created_at_from] = opts[:created_at][0] rescue nil - sql_opts[:created_at_to] = opts[:created_at][1] rescue nil + sql_opts[:fire_at_from] = begin + opts[:fire_at][0] + rescue + nil + end + sql_opts[:fire_at_to] = begin + opts[:fire_at][1] + rescue + nil + end + sql_opts[:created_at_from] = begin + opts[:created_at][0] + rescue + nil + end + sql_opts[:created_at_to] = begin + opts[:created_at][1] + rescue + nil + end sql_opts[:name] = opts[:queue] - sql_opts[:dir] = opts[:dir] == :desc ? -1 : 1 + sql_opts[:dir] = (opts[:dir] == :desc) ? -1 : 1 sql_opts end diff --git a/lib/litestack/litescheduler.rb b/lib/litestack/litescheduler.rb index 7a7eabc..6f354cd 100644 --- a/lib/litestack/litescheduler.rb +++ b/lib/litestack/litescheduler.rb @@ -78,7 +78,7 @@ def synchronize(&block) end end end - + module ForkListener def self.listeners @listeners ||= [] @@ -99,7 +99,6 @@ def _fork(*args) result end end - end Process.singleton_class.prepend(Litescheduler::Forkable) diff --git a/lib/litestack/litesearch/model.rb b/lib/litestack/litesearch/model.rb index 2d433f2..83384e9 100644 --- a/lib/litestack/litesearch/model.rb +++ b/lib/litestack/litesearch/model.rb @@ -42,7 +42,6 @@ def similar(limit = 10) end module ClassMethods - def litesearch # it is possible that this code is running when there is no table created yet if !defined?(ActiveRecord::Base).nil? && ancestors.include?(ActiveRecord::Base) @@ -50,7 +49,7 @@ def litesearch # capture the schema block @schema = ::Litesearch::Schema.new @schema.model_class = self if @schema.respond_to? :model_class - @schema.type :backed + @schema.type :backed @schema.table table_name.to_sym yield @schema @schema.post_init @@ -137,29 +136,31 @@ def create_instance(row) end module ActiveRecordSchemaMethods - attr_accessor :model_class - + def field(name, attributes = {}) keys = attributes.keys if keys.include?(:action_text) || keys.include?(:rich_text) - attributes[:source] = "#{ActionText::RichText.table_name}.body" rescue "action_text_rich_texts.body" - attributes[:reference] = :record_id - attributes[:conditions] = { record_type: model_class.name } + attributes[:source] = begin + "#{ActionText::RichText.table_name}.body" + rescue + "action_text_rich_texts.body" + end + attributes[:reference] = :record_id + attributes[:conditions] = {record_type: model_class.name} attributes[:target] = nil elsif keys.include? :as - attributes[:source] = attributes[:target] unless attributes[:source] + attributes[:source] = attributes[:target] unless attributes[:source] attributes[:reference] = "#{attributes[:as]}_id" - attributes[:conditions] = {"#{attributes[:as]}_type".to_sym => model_class.name } + attributes[:conditions] = {"#{attributes[:as]}_type": model_class.name} attributes[:target] = nil end super(name, attributes) - end + end - def allowed_attributes - super + [:polymorphic, :as, :action_text] - end - + def allowed_attributes + super + [:polymorphic, :as, :action_text] + end end module ActiveRecordInstanceMethods; end diff --git a/lib/litestack/litesearch/schema.rb b/lib/litestack/litesearch/schema.rb index c784900..72e308c 100644 --- a/lib/litestack/litesearch/schema.rb +++ b/lib/litestack/litesearch/schema.rb @@ -1,7 +1,6 @@ require_relative "schema_adapters" class Litesearch::Schema - TOKENIZERS = { porter: "porter unicode61 remove_diacritics 2", unicode: "unicode61 remove_diacritics 2", diff --git a/lib/litestack/litesearch/schema_adapters/backed_adapter.rb b/lib/litestack/litesearch/schema_adapters/backed_adapter.rb index ed41a5d..cec6600 100644 --- a/lib/litestack/litesearch/schema_adapters/backed_adapter.rb +++ b/lib/litestack/litesearch/schema_adapters/backed_adapter.rb @@ -25,14 +25,14 @@ def drop_primary_triggers_sql def create_primary_triggers_sql(active = false) when_stmt = "TRUE" - cols = active_cols_names.select{|n| !n.nil?} + cols = active_cols_names.select { |n| !n.nil? } if (filter = @schema[:filter_column]) when_stmt = "NEW.#{filter} = TRUE" cols << filter end - update_filter = String.new + update_filter = +"" if cols.length > 0 - " OF #{cols.join(', ')} " + " OF #{cols.join(", ")} " end <<-SQL @@ -68,7 +68,7 @@ def create_secondary_trigger_sql(target_table, target_col, col) end def create_secondary_trigger_poly_sql(target_table, target_col, col, conditions) - conditions_sql = conditions.collect{|k, v| "NEW.#{k} = '#{v}'"}.join(" AND ") + conditions_sql = conditions.collect { |k, v| "NEW.#{k} = '#{v}'" }.join(" AND ") <<~SQL CREATE TRIGGER IF NOT EXISTS #{target_table}_#{target_col}_#{name}_insert AFTER INSERT ON #{target_table} WHEN #{conditions_sql} BEGIN #{rebuild_sql}; @@ -79,10 +79,8 @@ def create_secondary_trigger_poly_sql(target_table, target_col, col, conditions) SQL end - - def drop_secondary_triggers_sql - sql = String.new + sql = +"" @schema[:fields].each do |name, field| if field[:trigger_sql] if field[:col] @@ -96,7 +94,7 @@ def drop_secondary_triggers_sql end def create_secondary_triggers_sql - sql = String.new + sql = +"" @schema[:fields].each do |name, field| if field[:trigger_sql] if field[:col] @@ -129,11 +127,11 @@ def enrich_schema target_table, target_col = field[:source].split(".") field[:target_table] = target_table.to_sym field[:target_col] = target_col.to_sym - field[:conditions_sql] = field[:conditions].collect{|k, v| "#{k} = '#{v}'"}.join(" AND ") if field[:conditions] + field[:conditions_sql] = field[:conditions].collect { |k, v| "#{k} = '#{v}'" }.join(" AND ") if field[:conditions] field[:sql] = "SELECT #{field[:target_col]} FROM #{field[:target_table]} WHERE #{field[:reference]} = NEW.id" - field[:sql] += " AND #{field[:conditions_sql]}" if field[:conditions_sql] + field[:sql] += " AND #{field[:conditions_sql]}" if field[:conditions_sql] field[:sql] = "(#{field[:sql]})" - field[:trigger_sql] = true + field[:trigger_sql] = true field[:target_table_alias] = "#{field[:target_table]}_#{name}" else field[:col] = name unless field[:col] @@ -145,7 +143,7 @@ def enrich_schema end def filter_sql - sql = String.new + sql = +"" sql << " WHERE #{@schema[:filter_column]} = TRUE " if @schema[:filter_column] sql end @@ -161,12 +159,12 @@ def select_cols_sql (!field[:trigger_sql].nil?) ? "#{field[:target_table_alias]}.#{field[:target_col]}" : field[:target] end.join(", ") end - + def joins_sql joins = [@schema[:table]] active_fields.each do |name, field| if field[:trigger_sql] - join_table = String.new + join_table = +"" join_table << "#{field[:target_table]} AS #{field[:target_table_alias]} ON " if field[:col] join_table << "#{field[:target_table_alias]}.id = #{@schema[:table]}.#{field[:col]}" if field[:col] @@ -174,14 +172,12 @@ def joins_sql join_table << "#{field[:target_table_alias]}.#{field[:reference]} = #{@schema[:table]}.id" if field[:conditions] join_table << " AND " - join_table << field[:conditions].collect{|k, v| "#{field[:target_table_alias]}.#{k} = '#{v}'"}.join(" AND ") + join_table << field[:conditions].collect { |k, v| "#{field[:target_table_alias]}.#{k} = '#{v}'" }.join(" AND ") end end - joins << join_table + joins << join_table end end joins.join(" LEFT JOIN ") end - - end diff --git a/lib/litestack/litesupport.rb b/lib/litestack/litesupport.rb index da10ca1..d842198 100644 --- a/lib/litestack/litesupport.rb +++ b/lib/litestack/litesupport.rb @@ -9,7 +9,7 @@ require "erb" require_relative "litescheduler" -require_relative 'liteconnection' +require_relative "liteconnection" module Litesupport class Error < StandardError; end @@ -77,9 +77,4 @@ def acquire result end end - - end - - - diff --git a/lib/sequel/adapters/litedb.rb b/lib/sequel/adapters/litedb.rb index 58a33b0..2588b90 100644 --- a/lib/sequel/adapters/litedb.rb +++ b/lib/sequel/adapters/litedb.rb @@ -36,11 +36,10 @@ class << db db.instance_variable_set(:@prepared_statements, {}) db end - + def sqlite_version @raw_db.sqlite_version end - end class Dataset < Sequel::SQLite::Dataset diff --git a/litestack.gemspec b/litestack.gemspec index df7d02a..09dadad 100644 --- a/litestack.gemspec +++ b/litestack.gemspec @@ -30,20 +30,20 @@ Gem::Specification.new do |spec| spec.executables = ["liteboard"] spec.require_paths = ["lib", "lib/litestack"] - spec.add_dependency "sqlite3", ['>= 1.6.0', '< 2.0.0'] - spec.add_dependency "oj", '~> 3' - spec.add_dependency "rack", '~> 3' - spec.add_dependency "rackup", '~> 2' - spec.add_dependency "tilt", '~> 2' - spec.add_dependency "erubi", '~> 1' + spec.add_dependency "sqlite3", [">= 1.6.0", "< 2.0.0"] + spec.add_dependency "oj", "~> 3" + spec.add_dependency "rack", "~> 3" + spec.add_dependency "rackup", "~> 2" + spec.add_dependency "tilt", "~> 2" + spec.add_dependency "erubi", "~> 1" - spec.add_development_dependency "rake", '~> 13' - spec.add_development_dependency "activerecord", '~> 7' - spec.add_development_dependency "activejob", '~> 7' - spec.add_development_dependency "railties", '~> 7' - spec.add_development_dependency "minitest", '~> 5' - spec.add_development_dependency "simplecov", '~> 0.2' - spec.add_development_dependency "standard", '~> 1' - spec.add_development_dependency "sequel", '~> 5' - spec.add_development_dependency "debug", '~> 1' + spec.add_development_dependency "rake", "~> 13" + spec.add_development_dependency "activerecord", "~> 7" + spec.add_development_dependency "activejob", "~> 7" + spec.add_development_dependency "railties", "~> 7" + spec.add_development_dependency "minitest", "~> 5" + spec.add_development_dependency "simplecov", "~> 0.2" + spec.add_development_dependency "standard", "~> 1" + spec.add_development_dependency "sequel", "~> 5" + spec.add_development_dependency "debug", "~> 1" end diff --git a/test/Rakefile b/test/Rakefile index f1d9c38..bc0797a 100644 --- a/test/Rakefile +++ b/test/Rakefile @@ -1,7 +1,5 @@ -require 'rake/testtask' +require "rake/testtask" Rake::TestTask.new do |t| - - t.test_files = FileList['test_*.rb'] - + t.test_files = FileList["test_*.rb"] end diff --git a/test/patch_ar_adapter_path.rb b/test/patch_ar_adapter_path.rb index 2a744e1..bb190bc 100644 --- a/test/patch_ar_adapter_path.rb +++ b/test/patch_ar_adapter_path.rb @@ -1,7 +1,6 @@ # don't attempt to load the adapter to avoid requiring the gem to be installed # we can just require the adapter manually class ActiveRecord::ConnectionAdapters::ConnectionHandler - alias_method :discarded_resolve_pool_config, :resolve_pool_config def resolve_pool_config(config, connection_name, role, shard) diff --git a/test/test_ar_search.rb b/test/test_ar_search.rb index b14c1bc..314ddec 100644 --- a/test/test_ar_search.rb +++ b/test/test_ar_search.rb @@ -1,6 +1,6 @@ require "minitest/autorun" -#require_relative "../lib/litestack/litedb" +# require_relative "../lib/litestack/litedb" require "active_record" require "active_record/base" @@ -13,7 +13,7 @@ database: ":memory:" ) -#ActiveRecord::Base.logger = Logger.new(STDOUT) +# ActiveRecord::Base.logger = Logger.new(STDOUT) db = ActiveRecord::Base.connection.raw_connection db.execute("CREATE TABLE authors(id INTEGER PRIMARY KEY, name TEXT, created_at TEXT, updated_at TEXT)") @@ -66,13 +66,11 @@ class Book < ApplicationRecord end class RichText < ApplicationRecord - belongs_to :record, polymorphic: true def self.table_name "rich_texts" end - end module ActionText @@ -89,7 +87,6 @@ class Review < ApplicationRecord litesearch do |schema| schema.field :body, target: "rich_texts.body", as: :record end - end class Comment < ApplicationRecord @@ -101,7 +98,6 @@ class Comment < ApplicationRecord litesearch do |schema| schema.field :body, rich_text: true end - end # no table items was created @@ -113,7 +109,6 @@ class Item < ApplicationRecord end end - class TestActiveRecordLitesearch < Minitest::Test def setup Book.drop_index! @@ -144,10 +139,10 @@ def setup def test_polymorphic review = Review.create(book_id: 1) rt = RichText.create(record: review, body: "a new review") - rs = Review.search("review") + rs = Review.search("review") assert_equal 1, rs.length rt.destroy - review.destroy + review.destroy end def test_rich_text @@ -160,7 +155,7 @@ def test_rich_text ct.destroy comment.destroy rt.destroy - review.destroy + review.destroy end def test_similar @@ -241,24 +236,23 @@ def test_rebuild_on_create rs = Publisher.search("Penguin") assert_equal 1, rs.length end - + def test_uncreated_table db = ActiveRecord::Base.connection.raw_connection db.execute("CREATE TABLE items(id INTEGER PRIMARY KEY, name TEXT, created_at TEXT, updated_at TEXT)") - rs = Item.search('some') - assert_equal 0, rs.length - Item.create(name: 'some item') - rs = Item.search('some') - assert_equal 1, rs.length - Item.create(name: 'another item') - rs = Item.search('item') - assert_equal 2, rs.length + rs = Item.search("some") + assert_equal 0, rs.length + Item.create(name: "some item") + rs = Item.search("some") + assert_equal 1, rs.length + Item.create(name: "another item") + rs = Item.search("item") + assert_equal 2, rs.length end - + def test_ignore_tables assert_equal false, ActiveRecord::SchemaDumper.ignore_tables.empty? # we have created 6 models, one ignore regex for each assert_equal 6, ActiveRecord::SchemaDumper.ignore_tables.count end - end diff --git a/test/test_backed_index.rb b/test/test_backed_index.rb index 2f5123b..7ed889c 100644 --- a/test/test_backed_index.rb +++ b/test/test_backed_index.rb @@ -294,7 +294,7 @@ def test_update_schema_change_tokenizer_auto_rebuild schema.rebuild_on_modify true end -#pp @db.execute("SELECT email.id, email.body, person_sender.name, person_receiver.name, attachement_data.data, email.subject FROM email CROSS JOIN person AS person_sender, person AS person_receiver, attachement AS attachement_data ON person_sender.id = email.sender_id AND person_receiver.id = email.receiver_id AND attachement_data.attachee_id = email.id AND attachement_data.attachee_type = 'email'") + # pp @db.execute("SELECT email.id, email.body, person_sender.name, person_receiver.name, attachement_data.data, email.subject FROM email CROSS JOIN person AS person_sender, person AS person_receiver, attachement AS attachement_data ON person_sender.id = email.sender_id AND person_receiver.id = email.receiver_id AND attachement_data.attachee_id = email.id AND attachement_data.attachee_type = 'email'") assert_equal 2, @idx.search("computer").length @db.execute("INSERT INTO email(sender_id, receiver_id, subject, body) VALUES (1, 2, 'How are the girls?', 'I wanted to ask about the girls and the computer')") assert_equal 3, @idx.search("puter").length diff --git a/test/test_configuration.rb b/test/test_configuration.rb index ccb2dfb..2170164 100644 --- a/test/test_configuration.rb +++ b/test/test_configuration.rb @@ -11,11 +11,11 @@ def initialize(options = {}) class TestConfiguration < Minitest::Test def test_yaml_with_no_erb - config_file = Tempfile.new(['litecomponent', '.yml']) + config_file = Tempfile.new(["litecomponent", ".yml"]) config_file.write('path: ":memory:"') - + config_file.read - + sample_component = SampleLiteComponent.new({config_path: config_file.path}) assert_equal sample_component.options[:path], ":memory:" @@ -24,15 +24,15 @@ def test_yaml_with_no_erb end def test_yaml_with_erb - config_file = Tempfile.new(['litecomponent', '.yml']) + config_file = Tempfile.new(["litecomponent", ".yml"]) config_file.write('path: "<%= ":memory:" %>"') - + config_file.read - + sample_component = SampleLiteComponent.new({config_path: config_file.path}) assert_equal sample_component.options[:path], ":memory:" config_file.close! end -end \ No newline at end of file +end diff --git a/test/test_litejob_rails.rb b/test/test_litejob_rails.rb index 0ac9763..b7f57c0 100644 --- a/test/test_litejob_rails.rb +++ b/test/test_litejob_rails.rb @@ -1,5 +1,5 @@ require "minitest/autorun" -require 'active_job' +require "active_job" require_relative "../lib/litestack/litejobqueue" ActiveJob::Base.logger = Logger.new(IO::NULL) @@ -7,25 +7,22 @@ $ljq = nil class Job < ActiveJob::Base - queue_as :test - + SINK = {} def self.sink SINK end - + def perform(key, time) - #puts "called with #{key} and time = #{time}. time now is #{Time.now}" - #puts caller + # puts "called with #{key} and time = #{time}. time now is #{Time.now}" + # puts caller SINK[key] = true end - end class TestLitejobRails < Minitest::Test - def setup if $ljq.nil? require_relative "../lib/litestack/litejobqueue" @@ -38,19 +35,19 @@ def setup def teardown end - + def test_job_is_peformed_now assert Job.perform_now(:now, Time.now) assert Job.sink[:now] end - + def test_job_is_performed_later Job.perform_later(:later, Time.now) - assert Job.sink[:later] == nil + assert Job.sink[:later].nil? wait_for(Job.sink[:later].nil?, 1.0) assert Job.sink[:later] end - + def test_job_is_performed_after_one_second Job.set(wait: 1.seconds).perform_later(:one_second, Time.now) assert Job.sink[:one_second].nil? @@ -87,7 +84,4 @@ def wait_for(condition, time) slept += step end end - end - - diff --git a/test/test_queue.rb b/test/test_queue.rb index 62e810f..9ad09e2 100644 --- a/test/test_queue.rb +++ b/test/test_queue.rb @@ -40,24 +40,24 @@ def test_delay sleep 1 assert !@queue.pop.nil? end - + def test_find j1 = @queue.push(1, 0, "q1") j2 = @queue.push(2, 10, "q2") - res = @queue.find({fire_at: [Time.now.to_i+1, nil] }) + res = @queue.find({fire_at: [Time.now.to_i + 1, nil]}) assert_equal 1, res.length assert_equal j2[0], res[0][0] - res = @queue.find() + res = @queue.find assert_equal 2, res.length res = @queue.find(created_at: [Time.now.to_i, nil]) assert_equal 2, res.length - res = @queue.find({fire_at: [nil, Time.now.to_i + 1] }) + res = @queue.find({fire_at: [nil, Time.now.to_i + 1]}) assert_equal 1, res.length assert_equal j1[0], res[0][0] - res = @queue.find({fire_at: [Time.now.to_i + 1, Time.now.to_i + 11] }) + res = @queue.find({fire_at: [Time.now.to_i + 1, Time.now.to_i + 11]}) assert_equal 1, res.length assert_equal j2[0], res[0][0] - res = @queue.find({fire_at: [Time.now.to_i + 1, Time.now.to_i + 2] }) + res = @queue.find({fire_at: [Time.now.to_i + 1, Time.now.to_i + 2]}) assert_equal 0, res.length end end