Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alejanderl committed May 29, 2024
1 parent 638942f commit ea9caa4
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 11 deletions.
22 changes: 22 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ruby
{
"name": "Ruby",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/ruby:1-3.3-bullseye"

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "ruby --version",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inherit_from: .rubocop_todo.yml
36 changes: 36 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-05-29 15:00:00 UTC using RuboCop version 1.64.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'hanikamu-services-async.gemspec'

# Offense count: 1
# Configuration parameters: AllowedMethods.
# AllowedMethods: enums
Lint/ConstantDefinitionInBlock:
Exclude:
- 'spec/hanikamu/services/async_spec.rb'

# Offense count: 2
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 34

# Offense count: 1
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
# CheckDefinitionPathHierarchyRoots: lib, spec, test, src
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
Naming/FileName:
Exclude:
- 'Rakefile.rb'
- 'lib/hanikamu-services-async.rb'
138 changes: 138 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,149 @@
PATH
remote: .
specs:
hanikamu-active_async (0.1.0)
activejob (< 8)
hanikamu-service (~> 0.1)

GEM
remote: https://rubygems.org/
specs:
activejob (7.1.3.3)
activesupport (= 7.1.3.3)
globalid (>= 0.3.6)
activesupport (7.1.3.3)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.8)
coderay (1.1.3)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
diff-lcs (1.5.1)
drb (2.2.1)
dry-configurable (1.1.0)
dry-core (~> 1.0, < 2)
zeitwerk (~> 2.6)
dry-core (1.0.1)
concurrent-ruby (~> 1.0)
zeitwerk (~> 2.6)
dry-inflector (1.0.0)
dry-logic (1.5.0)
concurrent-ruby (~> 1.0)
dry-core (~> 1.0, < 2)
zeitwerk (~> 2.6)
dry-monads (1.6.0)
concurrent-ruby (~> 1.0)
dry-core (~> 1.0, < 2)
zeitwerk (~> 2.6)
dry-struct (1.6.0)
dry-core (~> 1.0, < 2)
dry-types (>= 1.7, < 2)
ice_nine (~> 0.11)
zeitwerk (~> 2.6)
dry-types (1.7.2)
bigdecimal (~> 3.0)
concurrent-ruby (~> 1.0)
dry-core (~> 1.0)
dry-inflector (~> 1.0)
dry-logic (~> 1.4)
zeitwerk (~> 2.6)
globalid (1.2.1)
activesupport (>= 6.1)
hanikamu-service (0.1.5)
dry-configurable (~> 1.1.0)
dry-monads (~> 1.6.0)
dry-struct (~> 1.6.0)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
ice_nine (0.11.2)
json (2.7.2)
language_server-protocol (3.17.0.3)
method_source (1.1.0)
minitest (5.23.1)
mutex_m (0.2.0)
parallel (1.24.0)
parser (3.3.1.0)
ast (~> 2.4.1)
racc
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
racc (1.8.0)
rainbow (3.1.1)
rake (13.2.1)
regexp_parser (2.9.2)
rexml (3.2.8)
strscan (>= 3.0.9)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.0)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.0)
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-support (3.13.1)
rubocop (1.64.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.3)
parser (>= 3.3.1.0)
rubocop-capybara (2.20.0)
rubocop (~> 1.41)
rubocop-factory_bot (2.25.1)
rubocop (~> 1.41)
rubocop-performance (1.21.0)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rspec (2.29.2)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
rubocop-rspec_rails (~> 2.28)
rubocop-rspec_rails (2.28.3)
rubocop (~> 1.40)
ruby-progressbar (1.13.0)
strscan (3.1.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
zeitwerk (2.6.15)

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
bundler (>= 2)
hanikamu-active_async!
hanikamu-service (~> 0.1.0)
pry (>= 0.14.0)
rake
rspec (~> 3.0)
rubocop
rubocop-performance
rubocop-rspec

BUNDLED WITH
2.5.9
Empty file added Gemfile.runtime
Empty file.
File renamed without changes.
14 changes: 12 additions & 2 deletions lib/hanikamu/services/async.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# frozen_string_literal: true

require 'active_support/concern'
require 'active_job'
require 'active_support/core_ext/module/introspection'

module Hanikamu
module Services
# You can call from the operation the method
Expand Down Expand Up @@ -30,7 +34,7 @@ def self.included(base)
base.class_eval do
const_set(
:Async,
Class.new(ApplicationJob) do
Class.new(ActiveJob::Base) do
class << self
def call!(args = {})
perform_later(args: args, bang: true)
Expand All @@ -42,7 +46,13 @@ def call(args = {})
end

def perform(args:, bang:)
self.class.module_parent.send(bang ? :call! : :call, args)
parent_name_space.send(bang ? :call! : :call, args)
end

private

def parent_name_space
self.class.name.deconstantize.constantize
end
end
)
Expand Down
21 changes: 13 additions & 8 deletions spec/hanikamu/services/async_spec.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# frozen_string_literal: true

require 'spec_helper'
require 'hanikamu-service'

RSpec.describe Hanikamu::Services::Async do
RSpec.describe Hanikamu::Services::Async, type: :job do
context 'when passing the wrong argument type' do
let(:service) do
class TestFooModule::Bar < Hanikamu::Service
include Services::Async
module TestFooModule
class Bar < Hanikamu::Service
include Hanikamu::Services::Async

attribute :some_string, Dry::Types['string']
attribute :some_string, Dry::Types['string']

def call!
'hola'
def call!
'hola'
end
end
end
TestFooModule::Bar
Expand All @@ -24,7 +27,8 @@ def call!

subject { service::Async.call(some_string: 'hey') }
it 'calls the the service .call method' do
expect(service).to have_received(:call).with_arguments(some_string: 'hey')
subject
expect(service).to have_received(:call).with(some_string: 'hey')
end
end

Expand All @@ -35,7 +39,8 @@ def call!

subject { service::Async.call!(some_string: 'hey') }
it 'returns a Hanikamu::ActiveCommand::Error' do
expect(service).to have_received(:call!).with_arguments(some_string: 'hey')
subject
expect(service).to have_received(:call!).with(some_string: 'hey')
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
RSpec.configure do |config|
config.disable_monkey_patching!
config.filter_run_when_matching :focus

config.before(:each) do
ActiveJob::Base.queue_adapter = :inline
end
config.before do
stub_const('TestFooModule', Module.new)
end
Expand Down

0 comments on commit ea9caa4

Please sign in to comment.