-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor props and fix OptionalProp.new(false)
- Loading branch information
Showing
11 changed files
with
94 additions
and
103 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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module InertiaRails | ||
class Middleware | ||
def initialize(app) | ||
|
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
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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
class ApplicationController < ActionController::Base | ||
def controller_method | ||
"controller_method value" | ||
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 |
---|---|---|
@@ -1,20 +1,3 @@ | ||
RSpec.describe InertiaRails::AlwaysProp do | ||
describe '#call' do | ||
subject(:call) { prop.call } | ||
let(:prop) { described_class.new('value') } | ||
|
||
it { is_expected.to eq('value') } | ||
|
||
context 'with a callable value' do | ||
let(:prop) { described_class.new(-> { 'callable' }) } | ||
|
||
it { is_expected.to eq('callable') } | ||
end | ||
|
||
context 'with a block' do | ||
let(:prop) { described_class.new { 'block' } } | ||
|
||
it { is_expected.to eq('block') } | ||
end | ||
end | ||
it_behaves_like 'callable prop' | ||
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,3 @@ | ||
RSpec.describe InertiaRails::BaseProp do | ||
it_behaves_like 'callable prop' | ||
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
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 |
---|---|---|
@@ -1,24 +1,11 @@ | ||
RSpec.describe InertiaRails::MergeProp do | ||
describe '#call' do | ||
subject(:call) { prop.call } | ||
let(:prop) { described_class.new('value') } | ||
let(:prop) { described_class.new('value') } | ||
|
||
it { is_expected.to eq('value') } | ||
describe '#merge?' do | ||
subject { prop.merge? } | ||
|
||
context 'with a callable value' do | ||
let(:prop) { described_class.new(-> { 'callable' }) } | ||
|
||
it { is_expected.to eq('callable') } | ||
end | ||
|
||
context 'with a block' do | ||
let(:prop) { described_class.new { 'block' } } | ||
|
||
it { is_expected.to eq('block') } | ||
end | ||
|
||
it 'returns the merge flag' do | ||
expect(prop.merge?).to eq(true) | ||
end | ||
it { is_expected.to be(true) } | ||
end | ||
|
||
it_behaves_like 'callable prop' | ||
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 |
---|---|---|
@@ -1,21 +1,3 @@ | ||
RSpec.describe InertiaRails::OptionalProp do | ||
describe '#call' do | ||
context 'with a value' do | ||
it 'returns the value' do | ||
expect(InertiaRails::OptionalProp.new('thing').call).to eq('thing') | ||
end | ||
end | ||
|
||
context 'with a callable value' do | ||
it 'returns the result of the callable value' do | ||
expect(InertiaRails::OptionalProp.new(->{ 'thing' }).call).to eq('thing') | ||
end | ||
end | ||
|
||
context 'with a block' do | ||
it 'returns the result of the block' do | ||
expect(InertiaRails::OptionalProp.new {'thing'}.call).to eq('thing') | ||
end | ||
end | ||
end | ||
it_behaves_like 'callable prop' | ||
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
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,45 @@ | ||
RSpec.shared_examples 'callable prop' do | ||
describe '#call' do | ||
subject(:call) { prop.call(controller) } | ||
let(:prop) { described_class.new('value') } | ||
let(:controller) { ApplicationController.new } | ||
|
||
it { is_expected.to eq('value') } | ||
|
||
context 'with a callable value' do | ||
let(:prop) { described_class.new(-> { 'callable' }) } | ||
|
||
it { is_expected.to eq('callable') } | ||
|
||
context "with false as value" do | ||
let(:prop) { described_class.new(false) } | ||
|
||
it { is_expected.to eq(false) } | ||
end | ||
|
||
context "with nil as value" do | ||
let(:prop) { described_class.new(nil) } | ||
|
||
it { is_expected.to eq(nil) } | ||
end | ||
|
||
context "with dependency on the context of a controller" do | ||
let(:prop) { described_class.new(-> { controller_method }) } | ||
|
||
it { is_expected.to eq('controller_method value') } | ||
end | ||
end | ||
|
||
context 'with a block' do | ||
let(:prop) { described_class.new { 'block' } } | ||
|
||
it { is_expected.to eq('block') } | ||
|
||
context "with dependency on the context of a controller" do | ||
let(:prop) { described_class.new { controller_method } } | ||
|
||
it { is_expected.to eq('controller_method value') } | ||
end | ||
end | ||
end | ||
end |