Skip to content

Commit

Permalink
chore: Format to 80 column max width
Browse files Browse the repository at this point in the history
  • Loading branch information
elpete committed Jan 31, 2020
1 parent 7a7b7ca commit a43c6c8
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .cfformat.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"keywords.padding_inside_group":true,
"keywords.spacing_to_block":"spaced",
"keywords.spacing_to_group":true,
"max_columns":120,
"max_columns":80,
"method_call.chain.multiline":3,
"newline":"os",
"parentheses.padding":true,
Expand Down
28 changes: 22 additions & 6 deletions interceptors/InertiaLifecycle.cfc
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
component {

property name="version" inject="coldbox:setting:version@cbInertia";
property name="defaultViewArgs" inject="coldbox:setting:defaultViewArgs@cbInertia";
property
name="defaultViewArgs"
inject="coldbox:setting:defaultViewArgs@cbInertia";

function preProcess( event ) {
if ( event.getHTTPHeader( "X-Inertia", "" ) == "" ) {
Expand All @@ -12,15 +14,20 @@ component {
return;
}

var version = wirebox.getInstance( dsl = "coldbox:setting:version@cbInertia" );
var version = wirebox.getInstance(
dsl = "coldbox:setting:version@cbInertia"
);
version = isCallable( version ) ? version() : version;
if ( event.getHTTPHeader( "X-Inertia-Version", "" ) == version ) {
return;
}

event.noExecution();
event.setHTTPHeader( statusCode = 409, statusText = "Conflict" );
event.setHTTPHeader( name = "X-Inertia-Location", value = event.getFullUrl() );
event.setHTTPHeader(
name = "X-Inertia-Location",
value = event.getFullUrl()
);
event.renderData( type = "plain", data = "Conflict", statusCode = 409 );
}

Expand All @@ -37,8 +44,13 @@ component {

page.props = resolveClosures(
filterForPartialData(
page.component == event.getHTTPHeader( "X-Inertia-Partial-Component", "" ),
event.getHTTPHeader( "X-Inertia-Partial-Data", "" ).listToArray( "," ),
page.component == event.getHTTPHeader(
"X-Inertia-Partial-Component",
""
),
event
.getHTTPHeader( "X-Inertia-Partial-Data", "" )
.listToArray( "," ),
sharedProps
)
);
Expand Down Expand Up @@ -71,7 +83,11 @@ component {
}
}

private struct function filterForPartialData( required boolean isSameComponent, array only = [], struct props = {} ) {
private struct function filterForPartialData(
required boolean isSameComponent,
array only = [],
struct props = {}
) {
if ( !arguments.isSameComponent || arguments.only.isEmpty() ) {
return arguments.props;
}
Expand Down
7 changes: 6 additions & 1 deletion models/InertiaControllerDecorator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ component extends="coldbox.system.web.ControllerDecorator" {
) {
var requestContext = getRequestService().getContext();
if ( requestContext.getHTTPHeader( "X-Inertia", "" ) != "" ) {
if ( arrayContainsNoCase( [ "PUT", "PATCH", "DELETE" ], requestContext.getHTTPMethod() ) ) {
if (
arrayContainsNoCase(
[ "PUT", "PATCH", "DELETE" ],
requestContext.getHTTPMethod()
)
) {
arguments.statusCode = 303;
}
}
Expand Down
103 changes: 80 additions & 23 deletions tests/specs/integration/InertiaSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,28 @@ component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" {
describe( "Inertia", function() {
describe( "template rendering", function() {
it( "renders a view when called normally", function() {
var event = execute( event = "Inertia.normal", renderResults = true );
var event = execute(
event = "Inertia.normal",
renderResults = true
);
var html = event.getValue( "cbox_rendered_content", "" );
expect( html ).toMatch( ""component":"Home"" );
expect( html ).toMatch( ""props":{"foo":"bar"}" );
expect( html ).toMatch(
""component":"Home""
);
expect( html ).toMatch(
""props":{"foo":"bar"}"
);
} );

it( "combines shared props with view props", function() {
var event = execute( event = "Inertia.withShared", renderResults = true );
var event = execute(
event = "Inertia.withShared",
renderResults = true
);
var html = event.getValue( "cbox_rendered_content", "" );
expect( html ).toMatch( ""component":"Home"" );
expect( html ).toMatch(
""component":"Home""
);
expect( html ).toMatch(
""props":{"shared":"value","foo":"bar"}"
);
Expand All @@ -36,8 +48,13 @@ component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" {
.$args( "X-Inertia-Version", "" )
.$results( "" );

var event = execute( event = "Inertia.normal", renderResults = true );
var actual = deserializeJSON( event.getValue( "cbox_rendered_content", "" ) );
var event = execute(
event = "Inertia.normal",
renderResults = true
);
var actual = deserializeJSON(
event.getValue( "cbox_rendered_content", "" )
);

expect( actual ).toHaveKey( "component" );
expect( actual.component ).toBe( "Home" );
Expand All @@ -64,8 +81,13 @@ component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" {
.$args( "X-Inertia-Version", "" )
.$results( "" );
;
var event = execute( event = "Inertia.withShared", renderResults = true );
var actual = deserializeJSON( event.getValue( "cbox_rendered_content", "" ) );
var event = execute(
event = "Inertia.withShared",
renderResults = true
);
var actual = deserializeJSON(
event.getValue( "cbox_rendered_content", "" )
);

expect( actual ).toHaveKey( "component" );
expect( actual.component ).toBe( "Home" );
Expand All @@ -92,8 +114,13 @@ component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" {
.$args( "X-Inertia-Version", "" )
.$results( "" );
;
var event = execute( event = "Inertia.withSharedClosures", renderResults = true );
var actual = deserializeJSON( event.getValue( "cbox_rendered_content", "" ) );
var event = execute(
event = "Inertia.withSharedClosures",
renderResults = true
);
var actual = deserializeJSON(
event.getValue( "cbox_rendered_content", "" )
);

expect( actual ).toHaveKey( "component" );
expect( actual.component ).toBe( "Home" );
Expand All @@ -120,8 +147,13 @@ component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" {
.$args( "X-Inertia-Version", "" )
.$results( "" );
;
var event = execute( event = "Inertia.withArrayProp", renderResults = true );
var actual = deserializeJSON( event.getValue( "cbox_rendered_content", "" ) );
var event = execute(
event = "Inertia.withArrayProp",
renderResults = true
);
var actual = deserializeJSON(
event.getValue( "cbox_rendered_content", "" )
);

expect( actual ).toHaveKey( "component" );
expect( actual.component ).toBe( "Home" );
Expand All @@ -147,8 +179,13 @@ component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" {
.$( "getHTTPHeader" )
.$args( "X-Inertia-Version", "" )
.$results( "" );
var event = execute( event = "Inertia.withShared", renderResults = true );
var actual = deserializeJSON( event.getValue( "cbox_rendered_content", "" ) );
var event = execute(
event = "Inertia.withShared",
renderResults = true
);
var actual = deserializeJSON(
event.getValue( "cbox_rendered_content", "" )
);

expect( actual ).toHaveKey( "component" );
expect( actual.component ).toBe( "Home" );
Expand All @@ -174,8 +211,13 @@ component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" {
.$( "getHTTPHeader" )
.$args( "X-Inertia-Version", "" )
.$results( "" );
var event = execute( event = "Inertia.withShared", renderResults = true );
var actual = deserializeJSON( event.getValue( "cbox_rendered_content", "" ) );
var event = execute(
event = "Inertia.withShared",
renderResults = true
);
var actual = deserializeJSON(
event.getValue( "cbox_rendered_content", "" )
);

expect( actual ).toHaveKey( "component" );
expect( actual.component ).toBe( "Home" );
Expand All @@ -201,8 +243,13 @@ component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" {
.$( "getHTTPHeader" )
.$args( "X-Inertia-Version", "" )
.$results( "" );
var event = execute( event = "Inertia.withShared", renderResults = true );
var actual = deserializeJSON( event.getValue( "cbox_rendered_content", "" ) );
var event = execute(
event = "Inertia.withShared",
renderResults = true
);
var actual = deserializeJSON(
event.getValue( "cbox_rendered_content", "" )
);

expect( actual ).toHaveKey( "component" );
expect( actual.component ).toBe( "Home" );
Expand All @@ -225,8 +272,13 @@ component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" {
.$( "getHTTPHeader" )
.$args( "X-Inertia-Version", "" )
.$results( "" );
var event = execute( event = "Inertia.relocateTest", renderResults = true );
expect( event.getValue( "relocate_STATUSCODE", "" ) ).toBe( 303 );
var event = execute(
event = "Inertia.relocateTest",
renderResults = true
);
expect( event.getValue( "relocate_STATUSCODE", "" ) ).toBe(
303
);
} );
} );

Expand All @@ -239,11 +291,16 @@ component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" {
.$( "getHTTPHeader" )
.$args( "X-Inertia-Version", "" )
.$results( "not-matching-version" );
var event = execute( event = "Inertia.normal", renderResults = true );
var event = execute(
event = "Inertia.normal",
renderResults = true
);
expect( event.getStatusCode() ).toBe( 409 );
var headers = event.getValue( "cbox_headers", {} );
expect( headers ).toHaveKey( "X-Inertia-Location" );
expect( headers[ "X-Inertia-Location" ] ).toBe( event.getFullUrl() );
expect( headers[ "X-Inertia-Location" ] ).toBe(
event.getFullUrl()
);
} );
} );
} );
Expand Down

0 comments on commit a43c6c8

Please sign in to comment.