22
33require_relative "spec_helper"
44
5+ # rubocop:disable Metrics/ModuleLength
56module ReactOnRailsPro
67 RSpec . describe Utils do
78 describe "cache helpers .bundle_hash and .bundle_file_name" do
@@ -21,9 +22,7 @@ module ReactOnRailsPro
2122
2223 before do
2324 allow ( ReactOnRails . configuration )
24- . to receive ( :server_bundle_js_file ) . and_return ( nil )
25- allow ( ReactOnRails . configuration )
26- . to receive ( :rsc_bundle_js_file ) . and_return ( nil )
25+ . to receive_messages ( server_bundle_js_file : nil , rsc_bundle_js_file : nil )
2726 allow ( Shakapacker ) . to receive_message_chain ( "manifest.lookup!" )
2827 . with ( "client-bundle.js" )
2928 . and_return ( "/webpack/production/client-bundle-0123456789abcdef.js" )
@@ -42,9 +41,8 @@ module ReactOnRailsPro
4241 allow ( ReactOnRails ::Utils ) . to receive ( :server_bundle_js_file_path )
4342 . and_return ( server_bundle_js_file_path )
4443 allow ( ReactOnRails . configuration )
45- . to receive ( :server_bundle_js_file ) . and_return ( "webpack-bundle.js" )
46- allow ( ReactOnRails . configuration )
47- . to receive ( :rsc_bundle_js_file ) . and_return ( "rsc-webpack-bundle.js" )
44+ . to receive_messages ( server_bundle_js_file : "webpack-bundle.js" ,
45+ rsc_bundle_js_file : "rsc-webpack-bundle.js" )
4846 allow ( File ) . to receive ( :mtime ) . with ( server_bundle_js_file_path ) . and_return ( 123 )
4947
5048 result = described_class . bundle_hash
@@ -80,14 +78,13 @@ module ReactOnRailsPro
8078 rsc_bundle_js_file_path = File . expand_path ( "./public/#{ rsc_bundle_js_file } " )
8179 allow ( Shakapacker ) . to receive_message_chain ( "manifest.lookup!" )
8280 . and_return ( rsc_bundle_js_file )
83- allow ( ReactOnRails ::Utils ) . to receive ( :server_bundle_js_file_path )
84- . and_return ( rsc_bundle_js_file_path . gsub ( "rsc-" , "" ) )
85- allow ( ReactOnRails ::Utils ) . to receive ( :rsc_bundle_js_file_path )
86- . and_return ( rsc_bundle_js_file_path )
87- allow ( ReactOnRails . configuration )
88- . to receive ( :server_bundle_js_file ) . and_return ( "webpack-bundle.js" )
81+ allow ( ReactOnRails ::Utils ) . to receive_messages (
82+ server_bundle_js_file_path : rsc_bundle_js_file_path . gsub ( "rsc-" , "" ) ,
83+ rsc_bundle_js_file_path : rsc_bundle_js_file_path
84+ )
8985 allow ( ReactOnRails . configuration )
90- . to receive ( :rsc_bundle_js_file ) . and_return ( "rsc-webpack-bundle.js" )
86+ . to receive_messages ( server_bundle_js_file : "webpack-bundle.js" ,
87+ rsc_bundle_js_file : "rsc-webpack-bundle.js" )
9188 allow ( Digest ::MD5 ) . to receive ( :file )
9289 . with ( rsc_bundle_js_file_path )
9390 . and_return ( "barfoobarfoo" )
@@ -221,5 +218,73 @@ module ReactOnRailsPro
221218
222219 it { expect ( printable_cache_key ) . to eq ( "1_2_3_4_5" ) }
223220 end
221+
222+ describe ".pro_attribution_comment" do
223+ before do
224+ allow ( Rails ) . to receive ( :env ) . and_return ( ActiveSupport ::StringInquirer . new ( "production" ) )
225+ end
226+
227+ context "when license is valid and not in grace period" do
228+ before do
229+ allow ( ReactOnRailsPro ::LicenseValidator ) . to receive_messages ( grace_days_remaining : nil , evaluation? : false )
230+ end
231+
232+ it "returns the standard licensed attribution comment" do
233+ result = described_class . pro_attribution_comment
234+ expect ( result ) . to eq ( "<!-- Powered by React on Rails Pro (c) ShakaCode | Licensed -->" )
235+ end
236+ end
237+
238+ context "when license is in grace period" do
239+ before do
240+ allow ( ReactOnRailsPro ::LicenseValidator ) . to receive ( :grace_days_remaining ) . and_return ( 15 )
241+ end
242+
243+ it "returns attribution comment with grace period information" do
244+ result = described_class . pro_attribution_comment
245+ expected = "<!-- Powered by React on Rails Pro (c) ShakaCode | " \
246+ "Licensed (Expired - Grace Period: 15 days remaining) -->"
247+ expect ( result ) . to eq ( expected )
248+ end
249+ end
250+
251+ context "when license is in grace period with 1 day remaining" do
252+ before do
253+ allow ( ReactOnRailsPro ::LicenseValidator ) . to receive ( :grace_days_remaining ) . and_return ( 1 )
254+ end
255+
256+ it "returns attribution comment with singular day" do
257+ result = described_class . pro_attribution_comment
258+ expected = "<!-- Powered by React on Rails Pro (c) ShakaCode | " \
259+ "Licensed (Expired - Grace Period: 1 days remaining) -->"
260+ expect ( result ) . to eq ( expected )
261+ end
262+ end
263+
264+ context "when using evaluation license" do
265+ before do
266+ allow ( ReactOnRailsPro ::LicenseValidator ) . to receive_messages ( grace_days_remaining : nil , evaluation? : true )
267+ end
268+
269+ it "returns evaluation license attribution comment" do
270+ result = described_class . pro_attribution_comment
271+ expect ( result ) . to eq ( "<!-- Powered by React on Rails Pro (c) ShakaCode | Evaluation License -->" )
272+ end
273+ end
274+
275+ context "when grace_days_remaining returns 0" do
276+ before do
277+ allow ( ReactOnRailsPro ::LicenseValidator ) . to receive ( :grace_days_remaining ) . and_return ( 0 )
278+ end
279+
280+ it "returns attribution comment with grace period information" do
281+ result = described_class . pro_attribution_comment
282+ expected = "<!-- Powered by React on Rails Pro (c) ShakaCode | " \
283+ "Licensed (Expired - Grace Period: 0 days remaining) -->"
284+ expect ( result ) . to eq ( expected )
285+ end
286+ end
287+ end
224288 end
225289end
290+ # rubocop:enable Metrics/ModuleLength
0 commit comments