Skip to content

Commit

Permalink
Extract modules and extend spec coverage (#35)
Browse files Browse the repository at this point in the history
* require coverage before interactify

* update appraisals gemfile lock files

* add specs for whole integration app

* add Interactify::Wiring::ErrorContext spec

* add Interactify::Hooks spec

* fix namespacing

* satisfy rubocop

* add coverage badge
  • Loading branch information
markburns committed Mar 8, 2024
1 parent 0adca91 commit 47b0e94
Show file tree
Hide file tree
Showing 19 changed files with 257 additions and 196 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,5 @@ jobs:
with:
files: ./coverage/${{ matrix.ruby }}-${{ matrix.appraisal }}/coverage.json
token: ${{ secrets.CODECOV_TOKEN }}

- name: List coverage directory
run: ls -R ./coverage

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![Gem Version](https://badge.fury.io/rb/interactify.svg?1704215019)](https://badge.fury.io/rb/interactify)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
[![codecov](https://codecov.io/gh/markburns/interactify/graph/badge.svg?token=2VQ0PMPJKA)](https://codecov.io/gh/markburns/interactify)
![Ruby 3.3.0](https://img.shields.io/badge/ruby-3.3.0-green.svg)
![Ruby 3.2.2](https://img.shields.io/badge/ruby-3.2.2-green.svg)
![Ruby 3.1.4](https://img.shields.io/badge/ruby-3.1.4-green.svg)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/no_railties_no_sidekiq.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
interactify (0.4.0)
interactify (0.5.0)
activesupport (>= 6.0.0)
interactor
interactor-contracts
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/railties_6_no_sidekiq.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
interactify (0.4.0)
interactify (0.5.0)
activesupport (>= 6.0.0)
interactor
interactor-contracts
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/railties_6_sidekiq.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
interactify (0.4.0)
interactify (0.5.0)
activesupport (>= 6.0.0)
interactor
interactor-contracts
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/railties_7_no_sidekiq.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
interactify (0.4.0)
interactify (0.5.0)
activesupport (>= 6.0.0)
interactor
interactor-contracts
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/railties_7_sidekiq.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
interactify (0.4.0)
interactify (0.5.0)
activesupport (>= 6.0.0)
interactor
interactor-contracts
Expand Down
2 changes: 0 additions & 2 deletions lib/interactify/dependency_inference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,3 @@ def sidekiq?
rescue LoadError
Interactify.railties_missing!
end


125 changes: 58 additions & 67 deletions spec/fixtures/integration_app/app/interactors/all_the_things.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# when the code is in one place.
#
# Typically this will allow us to move closer towards a one organizer per interaction model.
# E.g. one Rails action == one organizer.
# E.g. one Rails action == one organizer.
# Even the background job firing can be handled by the organizer via YourClass::Async.
#
# An improvement we aim for is automatic diagram generation from the organizers, utilizing
Expand All @@ -32,8 +32,13 @@
# sense. They are evaluated when defining the organizer, leading to the creation of discrete
# classes that handle the respective logic.

require_relative './organizing/organized1'
require_relative './organizing/organized2'
require_relative "./organizing/organized1"
require_relative "./organizing/organized2"
require_relative "./if/a"
require_relative "./if/b"
require_relative "./if/c"
require_relative "./if/d"
require_relative "./if/organizer"

class AllTheThings
include Interactify
Expand All @@ -44,17 +49,16 @@ class AllTheThings

organize \
self.if(
:things,
then: [If::A, If::B],
:things,
then: [If::A, If::B],
else: [If::C, If::D]
),

# test nested promises
chain(
:nested_promises,
:nested_promises,
Organizing::Organized1.promising(
:organized1_called
),
),
Organizing::Organized2.organizing(
Organizing::DeeplyNestedInteractor,
Organizing::DeeplyNestedPromisingInteractor.promising(
Expand All @@ -63,90 +67,77 @@ class AllTheThings
Organizing::Organized2::Organized2Called
)
),

# test each with lambda
self.if(
-> (c) { c.things },
self.each(
:things,
If::A,
If::B,
-> (c) { c.lambda_set = true }
),
->(c) { c.things },
each(
:things,
If::A,
If::B,
->(c) { c.lambda_set = true }
)
),

# test alternative if syntax
self.if(
-> (c) { c.a && c.b } ,
then: -> (c) { c.both_a_and_b = true },
else: -> (c) { c.both_a_and_b = false}
->(c) { c.a && c.b },
then: ->(c) { c.both_a_and_b = true },
else: ->(c) { c.both_a_and_b = false }
),

# test setting a value to use later in the chain
-> (c) { c.more_things = [1, 2, 3, 4] },

->(c) { c.more_things = [1, 2, 3, 4] },
# test lambdas inside each
self.each(
:more_things,
-> (c) {
if c.more_thing_index.zero?
c.first_more_thing = true
end
each(
:more_things,
lambda { |c|
c.first_more_thing = true if c.more_thing_index.zero?
},
-> (c) {
if c.more_thing_index == 1
c.next_more_thing = true
end
lambda { |c|
c.next_more_thing = true if c.more_thing_index == 1
},
# test nested if inside each
{if: :not_set_thing, then: -> (c) { c.not_set_thing = true } },

{ if: :not_set_thing, then: ->(c) { c.not_set_thing = true } },
# test setting a value after an else
-> (c) { c.more_thing = true }
->(c) { c.more_thing = true }
),

self.if(
:optional_thing,
:optional_thing,
then: [
-> (c) { c.optional_thing_was_set = true },
-> (c) { c.and_then_another_thing = true },
-> (c) { c.and_one_more_thing = true },
->(c) { c.optional_thing_was_set = true },
->(c) { c.and_then_another_thing = true },
->(c) { c.and_one_more_thing = true },
# test nested each inside if
self.each(:more_things,
-> (c) { c.more_things[c.more_thing_index] = c.more_thing + 5 },
-> (c) { c.more_things[c.more_thing_index] = c.more_thing + 5 }
)
each(:more_things,
->(c) { c.more_things[c.more_thing_index] = c.more_thing + 5 },
->(c) { c.more_things[c.more_thing_index] = c.more_thing + 5 })
],
else: -> (c) { c.optional_thing_was_set = false }
else: ->(c) { c.optional_thing_was_set = false }
),

# if -> each -> if -> each
self.if(:condition, then: [-> {}], else: [
self.each(
:things,
self.if(
:thing,
then: self.each(
:more_things,
-> (c) {
c.counter ||= 0
c.counter += 1
}
)
)
)
]),

each(
:things,
self.if(
:thing,
then: each(
:more_things,
lambda { |c|
c.counter ||= 0
c.counter += 1
}
)
)
)
]),
# each -> each -> each
self.each(
each(
:more_things,
self.each(
each(
:more_things,
self.each(
each(
:more_things,
self.each(
each(
:more_things,
-> (c) {
lambda { |c|
c.heavily_nested_counter ||= 0
c.heavily_nested_counter += 1
}
Expand Down
60 changes: 31 additions & 29 deletions spec/fixtures/integration_app/app/interactors/if/organizer.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
module If
class Anyways
include Interactify
module Organizer
class Anyways
include Interactify

expect :blah, filled: false

def call
context.anyways = blah
expect :blah, filled: false

def call
context.anyways = blah
end
end
end

class MethodSyntaxOrganizer
include Interactify
expect :blah, filled: false
class MethodSyntaxOrganizer
include Interactify
expect :blah, filled: false

organize \
self.if(:blah, [A, B], [C, D]),
Anyways
end
organize \
self.if(:blah, [A, B], [C, D]),
Anyways
end

class AlternativeMethodSyntaxOrganizer
include Interactify
expect :blah, filled: false
class AlternativeMethodSyntaxOrganizer
include Interactify
expect :blah, filled: false

organize(
self.if(:blah, then: [A, B], else: [C, D]),
Anyways
)
end
organize(
self.if(:blah, then: [A, B], else: [C, D]),
Anyways
)
end

class HashSyntaxOrganizer
include Interactify
expect :blah, filled: false
class HashSyntaxOrganizer
include Interactify
expect :blah, filled: false

organize(
{if: :blah, then: [A, B], else: [C, D]},
Anyways
)
organize(
{ if: :blah, then: [A, B], else: [C, D] },
Anyways
)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative 'deeply_nested_interactor'
require_relative 'deeply_nested_promising_interactor'
require_relative "deeply_nested_interactor"
require_relative "deeply_nested_promising_interactor"

module Organizing
class Organized2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative './organizing/organized1'
require_relative './organizing/organized2'
require_relative "./organizing/organized1"
require_relative "./organizing/organized2"

class UnfulfilledPromises
include Interactify
Expand All @@ -10,18 +10,17 @@ class UnfulfilledPromises
promise :another_thing

organize each(
:things,
:things,
{
if: :dont_fulfill,
if: :dont_fulfill,
then: chain(
:nested_promises,
:nested_promises,
each(
:things,
:things,
Organizing::Organized1.promising(
:organized1_called
),
),
SetAnothingThing = Interactify { _1.another_thing = true },

Organizing::Organized2.organizing(
Organizing::DeeplyNestedInteractor,
Organizing::DeeplyNestedPromisingInteractor.promising(
Expand Down
10 changes: 5 additions & 5 deletions spec/integration/if_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

context "with an interactified symbol to proc" do
before do
require "./spec/fixtures/integration_app/app/interactors/if_with_interactified_lambda_clause"
require "./spec/fixtures/integration_app/app/interactors/a/b/if_with_interactified_lambda_clause"
end

it "successfully runs" do
Expand All @@ -32,8 +32,8 @@
end

context "with alternative method syntax" do
let(:truthy_result) { If::AlternativeMethodSyntaxOrganizer.call!(blah: true) }
let(:falsey_result) { If::AlternativeMethodSyntaxOrganizer.call!(blah: false) }
let(:truthy_result) { If::Organizer::AlternativeMethodSyntaxOrganizer.call!(blah: true) }
let(:falsey_result) { If::Organizer::AlternativeMethodSyntaxOrganizer.call!(blah: false) }

it "runs the relevant clauses" do
expect(truthy_result.a).to eq("a")
Expand All @@ -51,8 +51,8 @@
end

context "with hash syntax" do
let(:truthy_result) { If::HashSyntaxOrganizer.call!(blah: true) }
let(:falsey_result) { If::HashSyntaxOrganizer.call!(blah: false) }
let(:truthy_result) { If::Organizer::HashSyntaxOrganizer.call!(blah: true) }
let(:falsey_result) { If::Organizer::HashSyntaxOrganizer.call!(blah: false) }

it "runs the relevant clauses" do
expect(truthy_result.a).to eq("a")
Expand Down
Loading

0 comments on commit 47b0e94

Please sign in to comment.