-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ensure we correctly wrap nested classes
- Loading branch information
Showing
17 changed files
with
388 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
59 changes: 59 additions & 0 deletions
59
spec/fixtures/integration_app/app/interactors/all_the_things.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
class AllTheThings | ||
include Interactify | ||
|
||
expect :things | ||
optional :optional_thing | ||
promise :a | ||
|
||
organize \ | ||
self.if( | ||
:things, | ||
then: [If::A, If::B], | ||
else: [If::C, If::D] | ||
), | ||
|
||
self.each( | ||
:things, | ||
If::A, | ||
If::B, | ||
-> (c) { c.lambda_set = true } | ||
), | ||
|
||
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.more_things = [1, 2, 3, 4] }, | ||
|
||
self.each( | ||
:more_things, | ||
-> (c) { | ||
if c.more_thing_index.zero? | ||
c.first_more_thing = true | ||
end | ||
}, | ||
-> (c) { | ||
if c.more_thing_index == 1 | ||
c.next_more_thing = true | ||
end | ||
}, | ||
{if: :not_set_thing, then: -> (c) { c.not_set_thing = true } }, | ||
-> (c) { c.more_thing = true } | ||
), | ||
|
||
self.if( | ||
:optional_thing, | ||
then: [ | ||
-> (c) { c.optional_thing_was_set = true }, | ||
-> (c) { c.and_then_another_thing = true }, | ||
-> (c) { c.and_one_more_thing = true }, | ||
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 } | ||
) | ||
], | ||
else: -> (c) { c.optional_thing_was_set = false } | ||
) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Each | ||
class A | ||
include Interactify | ||
|
||
def call | ||
context.a = 'a' | ||
return unless context.thing | ||
|
||
context.thing.a = 'a' | ||
context.thing.a_index = context.thing_index | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Each | ||
class B | ||
include Interactify | ||
|
||
def call | ||
context.b = 'b' | ||
return unless context.thing | ||
|
||
context.thing.b = 'b' | ||
context.thing.b_index = context.thing_index | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Each | ||
class C | ||
include Interactify | ||
|
||
def call | ||
context.c = 'c' | ||
return unless context.thing | ||
|
||
context.thing.c = 'c' | ||
context.thing.c_index = context.thing_index | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Each | ||
class D | ||
include Interactify | ||
|
||
def call | ||
context.d = 'd' | ||
return unless context.thing | ||
|
||
context.thing.d = 'd' | ||
context.thing.d_index = context.thing_index | ||
end | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
spec/fixtures/integration_app/app/interactors/each/organizer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Each | ||
class Organizer | ||
include Interactify | ||
expect :things | ||
|
||
organize \ | ||
A, B, C, D, | ||
self.each(:things, A, B, C, D) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module If | ||
class A | ||
include Interactify | ||
|
||
def call | ||
context.a = 'a' | ||
return unless context.thing | ||
|
||
context.thing.a = 'a' | ||
context.thing.a_index = context.thing_index | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module If | ||
class B | ||
include Interactify | ||
|
||
def call | ||
context.b = 'b' | ||
return unless context.thing | ||
|
||
context.thing.b = 'b' | ||
context.thing.b_index = context.thing_index | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module If | ||
class C | ||
include Interactify | ||
|
||
def call | ||
context.c = 'c' | ||
return unless context.thing | ||
|
||
context.thing.c = 'c' | ||
context.thing.c_index = context.thing_index | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module If | ||
class D | ||
include Interactify | ||
|
||
def call | ||
context.d = 'd' | ||
return unless context.thing | ||
|
||
context.thing.d = 'd' | ||
context.thing.d_index = context.thing_index | ||
end | ||
end | ||
end |
40 changes: 40 additions & 0 deletions
40
spec/fixtures/integration_app/app/interactors/if/organizer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module If | ||
class Anyways | ||
include Interactify | ||
|
||
expect :blah, filled: false | ||
|
||
def call | ||
context.anyways = blah | ||
end | ||
end | ||
|
||
class MethodSyntaxOrganizer | ||
include Interactify | ||
expect :blah, filled: false | ||
|
||
organize \ | ||
self.if(:blah, [A, B], [C, D]), | ||
Anyways | ||
end | ||
|
||
class AlternativeMethodSyntaxOrganizer | ||
include Interactify | ||
expect :blah, filled: false | ||
|
||
organize( | ||
self.if(:blah, then: [A, B], else: [C, D]), | ||
Anyways | ||
) | ||
end | ||
|
||
class HashSyntaxOrganizer | ||
include Interactify | ||
expect :blah, filled: false | ||
|
||
organize( | ||
{if: :blah, then: [A, B], else: [C, D]}, | ||
Anyways | ||
) | ||
end | ||
end |
1 change: 1 addition & 0 deletions
1
spec/fixtures/integration_app/app/services/not_an_interactor.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe "Interactify" do | ||
let(:things) do | ||
[thing1, thing2] | ||
end | ||
|
||
let(:thing1) do | ||
OpenStruct.new | ||
end | ||
|
||
let(:thing2) do | ||
OpenStruct.new | ||
end | ||
|
||
before do | ||
require_files("each/") | ||
require_files("if/") | ||
require_files('') | ||
end | ||
|
||
context 'without an optional thing' do | ||
let(:result) { AllTheThings.promising(:a).call!(things:, optional_thing: false) } | ||
|
||
it "sets A and B, then lambda_set, then both_a_and_b, then first_more_thing, next_more_thing" do | ||
expect(result.a).to eq("a") | ||
expect(result.b).to eq("b") | ||
expect(result.c).to eq(nil) | ||
expect(result.d).to eq(nil) | ||
expect(result.lambda_set).to eq(true) | ||
expect(result.both_a_and_b).to eq(true) | ||
expect(result.more_things).to eq([1, 2, 3, 4]) | ||
expect(result.first_more_thing).to eq(true) | ||
expect(result.next_more_thing).to eq(true) | ||
expect(result.optional_thing_was_set).to eq(false) | ||
end | ||
end | ||
|
||
context "with an optional thing" do | ||
let(:result) { AllTheThings.promising(:a).call!(things:, optional_thing: true) } | ||
|
||
it "sets A and B, then lambda_set, then both_a_and_b, then first_more_thing, next_more_thing" do | ||
expect(result.a).to eq("a") | ||
expect(result.b).to eq("b") | ||
expect(result.c).to eq(nil) | ||
expect(result.d).to eq(nil) | ||
expect(result.lambda_set).to eq(true) | ||
expect(result.both_a_and_b).to eq(true) | ||
expect(result.more_things).to eq([6, 7, 8, 9]) | ||
expect(result.first_more_thing).to eq(true) | ||
expect(result.next_more_thing).to eq(true) | ||
expect(result.optional_thing_was_set).to eq(true) | ||
end | ||
end | ||
|
||
def require_files(dir) | ||
files = Dir.glob("./spec/fixtures/integration_app/app/interactors/#{dir}**/*.rb") | ||
|
||
files.each do |file| | ||
require file | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe "Interactify.each" do | ||
before do | ||
files = Dir.glob("./spec/fixtures/integration_app/app/interactors/each/**/*.rb") | ||
files.each do |file| | ||
require file | ||
end | ||
end | ||
|
||
let(:thing_1) do | ||
OpenStruct.new | ||
end | ||
|
||
let(:thing_2) do | ||
OpenStruct.new | ||
end | ||
|
||
it "runs the outer interactors" do | ||
result = Each::Organizer.call!(things: [thing_1, thing_2]) | ||
|
||
expect(result.a).to eq("a") | ||
expect(result.b).to eq("b") | ||
expect(result.c).to eq("c") | ||
expect(result.d).to eq("d") | ||
end | ||
end |
Oops, something went wrong.