@@ -98,6 +98,8 @@ def mock_dev_server_running
9898 . and_return ( "server-bundle.js" )
9999 allow ( ReactOnRails ) . to receive_message_chain ( "configuration.rsc_bundle_js_file" )
100100 . and_return ( "rsc-bundle.js" )
101+ allow ( ReactOnRails ) . to receive_message_chain ( "configuration.react_server_client_manifest_file" )
102+ . and_return ( "react-server-client-manifest.json" )
101103 end
102104
103105 subject do
@@ -786,90 +788,50 @@ def mock_dev_server_running
786788 end
787789
788790 describe ".react_server_client_manifest_file_path" do
791+ let ( :asset_name ) { "react-server-client-manifest.json" }
792+
789793 before do
790794 described_class . instance_variable_set ( :@react_server_manifest_path , nil )
791- allow ( ReactOnRails . configuration ) . to receive ( :react_server_client_manifest_file )
792- . and_return ( "react-server-client-manifest.json" )
795+ allow ( ReactOnRails . configuration ) . to receive ( :react_server_client_manifest_file ) . and_return ( asset_name )
793796 allow ( Rails . env ) . to receive ( :development? ) . and_return ( false )
794797 end
795798
796799 after do
797800 described_class . instance_variable_set ( :@react_server_manifest_path , nil )
798801 end
799802
800- context "when in development environment" do
801- before do
802- allow ( Rails . env ) . to receive ( :development? ) . and_return ( true )
803- allow ( described_class ) . to receive ( :public_bundles_full_path )
804- . and_return ( "/path/to/generated/assets" )
805- end
806-
807- it "does not use cached path" do
808- # Call once to potentially set the cached path
809- described_class . react_server_client_manifest_file_path
810-
811- # Change the configuration value
812- allow ( ReactOnRails . configuration ) . to receive ( :react_server_client_manifest_file )
813- . and_return ( "changed-manifest.json" )
814-
815- # Should use the new value
816- expect ( described_class . react_server_client_manifest_file_path )
817- . to eq ( "/path/to/generated/assets/changed-manifest.json" )
818- end
803+ it "calls bundle_js_file_path with the correct asset name and returns its value" do
804+ allow ( described_class ) . to receive ( :bundle_js_file_path ) . with ( asset_name ) . and_return ( "/some/path/#{ asset_name } " )
805+ result = described_class . react_server_client_manifest_file_path
806+ expect ( described_class ) . to have_received ( :bundle_js_file_path ) . with ( asset_name )
807+ expect ( result ) . to eq ( "/some/path/#{ asset_name } " )
819808 end
820809
821- context "when not in development environment" do
822- before do
823- allow ( described_class ) . to receive ( :public_bundles_full_path )
824- . and_return ( "/path/to/generated/assets" )
825- end
826-
827- it "caches the path" do
828- # Call once to set the cached path
829- expected_path = "/path/to/generated/assets/react-server-client-manifest.json"
830- expect ( described_class . react_server_client_manifest_file_path ) . to eq ( expected_path )
831-
832- # Change the configuration value
833- allow ( ReactOnRails . configuration ) . to receive ( :react_server_client_manifest_file )
834- . and_return ( "changed-manifest.json" )
835-
836- # Should still use the cached path
837- expect ( described_class . react_server_client_manifest_file_path ) . to eq ( expected_path )
838- end
810+ it "caches the path when not in development" do
811+ allow ( described_class ) . to receive ( :bundle_js_file_path ) . with ( asset_name ) . and_return ( "/some/path/#{ asset_name } " )
812+ result1 = described_class . react_server_client_manifest_file_path
813+ result2 = described_class . react_server_client_manifest_file_path
814+ expect ( described_class ) . to have_received ( :bundle_js_file_path ) . once . with ( asset_name )
815+ expect ( result1 ) . to eq ( "/some/path/#{ asset_name } " )
816+ expect ( result2 ) . to eq ( "/some/path/#{ asset_name } " )
839817 end
840818
841- context "with different manifest file names" do
842- before do
843- allow ( described_class ) . to receive ( :public_bundles_full_path )
844- . and_return ( "/path/to/generated/assets" )
845- end
846-
847- it "returns the correct path for default manifest name" do
848- allow ( ReactOnRails . configuration ) . to receive ( :react_server_client_manifest_file )
849- . and_return ( "react-server-client-manifest.json" )
850-
851- expect ( described_class . react_server_client_manifest_file_path )
852- . to eq ( "/path/to/generated/assets/react-server-client-manifest.json" )
853- end
854-
855- it "returns the correct path for custom manifest name" do
856- allow ( ReactOnRails . configuration ) . to receive ( :react_server_client_manifest_file )
857- . and_return ( "custom-server-client-manifest.json" )
858-
859- expect ( described_class . react_server_client_manifest_file_path )
860- . to eq ( "/path/to/generated/assets/custom-server-client-manifest.json" )
861- end
819+ it "does not cache the path in development" do
820+ allow ( Rails . env ) . to receive ( :development? ) . and_return ( true )
821+ allow ( described_class ) . to receive ( :bundle_js_file_path ) . with ( asset_name ) . and_return ( "/some/path/#{ asset_name } " )
822+ result1 = described_class . react_server_client_manifest_file_path
823+ result2 = described_class . react_server_client_manifest_file_path
824+ expect ( described_class ) . to have_received ( :bundle_js_file_path ) . twice . with ( asset_name )
825+ expect ( result1 ) . to eq ( "/some/path/#{ asset_name } " )
826+ expect ( result2 ) . to eq ( "/some/path/#{ asset_name } " )
862827 end
863828
864- context "with nil manifest file name" do
829+ context "when manifest file name is nil " do
865830 before do
866- allow ( ReactOnRails . configuration ) . to receive ( :react_server_client_manifest_file )
867- . and_return ( nil )
868- allow ( described_class ) . to receive ( :public_bundles_full_path )
869- . and_return ( "/path/to/generated/assets" )
831+ allow ( ReactOnRails . configuration ) . to receive ( :react_server_client_manifest_file ) . and_return ( nil )
870832 end
871833
872- it "raises an error when the manifest file name is nil " do
834+ it "raises an error" do
873835 expect { described_class . react_server_client_manifest_file_path }
874836 . to raise_error ( ReactOnRails ::Error , /react_server_client_manifest_file is nil/ )
875837 end
0 commit comments