Skip to content

Commit b11a3d9

Browse files
Remove react_on_rails_pro_licence_valid? and consolidate to react_on_rails_pro?
1 parent 9650099 commit b11a3d9

File tree

8 files changed

+47
-46
lines changed

8 files changed

+47
-46
lines changed

lib/react_on_rails/helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,10 @@ def rails_context(server_side: true)
377377
i18nDefaultLocale: I18n.default_locale,
378378
rorVersion: ReactOnRails::VERSION,
379379
# TODO: v13 just use the version if existing
380-
rorPro: ReactOnRails::Utils.react_on_rails_pro_licence_valid?
380+
rorPro: ReactOnRails::Utils.react_on_rails_pro?
381381
}
382382

383-
if ReactOnRails::Utils.react_on_rails_pro_licence_valid?
383+
if ReactOnRails::Utils.react_on_rails_pro?
384384
result[:rorProVersion] = ReactOnRails::Utils.react_on_rails_pro_version
385385

386386
if ReactOnRails::Utils.rsc_support_enabled?

lib/react_on_rails/pro_utils.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ module ProUtils
55
PRO_ONLY_OPTIONS = %i[immediate_hydration].freeze
66

77
# Checks if React on Rails Pro features are available
8-
# @return [Boolean] true if Pro license is valid, false otherwise
8+
# @return [Boolean] true if Pro is installed and licensed, false otherwise
99
def self.support_pro_features?
10-
ReactOnRails::Utils.react_on_rails_pro_licence_valid?
10+
ReactOnRails::Utils.react_on_rails_pro?
1111
end
1212

1313
def self.disable_pro_render_options_if_not_licensed(raw_options)

lib/react_on_rails/utils.rb

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,12 @@ def self.gem_available?(name)
228228
end
229229
end
230230

231-
# Todo -- remove this for v13, as we don't need both boolean and number
231+
# Checks if React on Rails Pro is installed and licensed.
232+
# With startup validation enabled, if this returns true, it means:
233+
# 1. The react_on_rails_pro gem is installed
234+
# 2. The license is valid (or the app would have failed to start)
235+
#
236+
# @return [Boolean] true if Pro is available with valid license
232237
def self.react_on_rails_pro?
233238
return @react_on_rails_pro if defined?(@react_on_rails_pro)
234239

@@ -246,21 +251,6 @@ def self.react_on_rails_pro_version
246251
end
247252
end
248253

249-
def self.react_on_rails_pro_licence_valid?
250-
return @react_on_rails_pro_licence_valid if defined?(@react_on_rails_pro_licence_valid)
251-
252-
@react_on_rails_pro_licence_valid = begin
253-
return false unless react_on_rails_pro?
254-
255-
# Maintain compatibility with legacy versions of React on Rails Pro:
256-
# Earlier releases did not require license validation, as they were distributed as private gems.
257-
# This check ensures that the method works correctly regardless of the installed version.
258-
return true unless ReactOnRailsPro::Utils.respond_to?(:licence_valid?)
259-
260-
ReactOnRailsPro::Utils.licence_valid?
261-
end
262-
end
263-
264254
def self.rsc_support_enabled?
265255
return false unless react_on_rails_pro?
266256

react_on_rails_pro/CI_SETUP.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -340,27 +340,36 @@ docker run -e REACT_ON_RAILS_PRO_LICENSE="$REACT_ON_RAILS_PRO_LICENSE" your-imag
340340

341341
## Verification
342342

343-
### Check License in CI
343+
License validation happens automatically when Rails starts.
344344

345-
Add a verification step to your CI pipeline:
345+
✅ **If your CI tests run, your license is valid**
346+
❌ **If license is invalid, Rails fails to start immediately**
346347

347-
```bash
348-
# Verify license is loaded
349-
bundle exec rails runner "puts ReactOnRails::Utils.react_on_rails_pro_licence_valid? ? '✅ License valid' : '❌ License invalid'"
350-
```
348+
**No verification step needed** - the application won't start without a valid license.
351349

352350
### Debug License Issues
353351

354-
If tests fail with license errors:
352+
If Rails fails to start in CI with license errors:
355353

356354
```bash
357-
# Check if license is set
358-
echo "License set: ${REACT_ON_RAILS_PRO_LICENSE:0:20}..." # Shows first 20 chars
359-
360-
# Check license format
361-
bundle exec rails runner "require 'jwt'; puts JWT.decode(ENV['REACT_ON_RAILS_PRO_LICENSE'], nil, false)"
355+
# Check if license environment variable is set (show first 20 chars only)
356+
echo "License set: ${REACT_ON_RAILS_PRO_LICENSE:0:20}..."
357+
358+
# Decode the license to check expiration
359+
bundle exec rails runner "
360+
require 'jwt'
361+
payload = JWT.decode(ENV['REACT_ON_RAILS_PRO_LICENSE'], nil, false).first
362+
puts 'Email: ' + payload['sub']
363+
puts 'Expires: ' + Time.at(payload['exp']).to_s
364+
puts 'Expired: ' + (Time.now.to_i > payload['exp']).to_s
365+
"
362366
```
363367

368+
**Common issues:**
369+
- License not set in CI environment variables
370+
- License truncated when copying (should be 500+ characters)
371+
- License expired (get a new FREE license at https://shakacode.com/react-on-rails-pro)
372+
364373
## Security Best Practices
365374

366375
1. ✅ **Always use secrets/encrypted variables** - Never commit licenses to code

react_on_rails_pro/LICENSE_SETUP.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,16 @@ Set up CI with a license (see [CI_SETUP.md](./CI_SETUP.md) for detailed instruct
118118
**Ruby Console:**
119119
```ruby
120120
rails console
121-
> ReactOnRails::Utils.react_on_rails_pro_licence_valid?
121+
> ReactOnRails::Utils.react_on_rails_pro?
122122
# Should return: true
123123
```
124124

125+
**Note:** With startup validation enabled, your Rails app won't start with an invalid license. If you can run the Rails console, your license is valid.
126+
125127
**Check License Details:**
126128
```ruby
127129
> ReactOnRailsPro::LicenseValidator.license_data
128-
# Shows: {"sub"=>"[email protected]", "exp"=>1234567890, ...}
130+
# Shows: {"sub"=>"[email protected]", "exp"=>1234567890, "plan"=>"free", ...}
129131
```
130132

131133
**Browser JavaScript Console:**

spec/dummy/spec/helpers/react_on_rails_helper_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class PlainReactOnRailsHelper
2222
}
2323

2424
allow(ReactOnRails::Utils).to receive_messages(
25-
react_on_rails_pro_licence_valid?: true
25+
react_on_rails_pro?: true
2626
)
2727

2828
# Configure immediate_hydration to true for tests since they expect that behavior
@@ -389,7 +389,7 @@ def helper.append_javascript_pack_tag(name, **options)
389389
subject(:react_app) { react_component("App", props: props, immediate_hydration: true) }
390390

391391
before do
392-
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro_licence_valid?).and_return(false)
392+
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro?).and_return(false)
393393
end
394394

395395
it { is_expected.to include(badge_html_string) }
@@ -405,7 +405,7 @@ def helper.append_javascript_pack_tag(name, **options)
405405
subject(:react_app) { react_component("App", props: props) }
406406

407407
before do
408-
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro_licence_valid?).and_return(false)
408+
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro?).and_return(false)
409409
end
410410

411411
around do |example|
@@ -421,7 +421,7 @@ def helper.append_javascript_pack_tag(name, **options)
421421
subject(:react_app) { react_component("App", props: props, immediate_hydration: false) }
422422

423423
before do
424-
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro_licence_valid?).and_return(false)
424+
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro?).and_return(false)
425425
end
426426

427427
it { is_expected.not_to include(badge_html_string) }
@@ -437,7 +437,7 @@ def helper.append_javascript_pack_tag(name, **options)
437437

438438
before do
439439
allow(ReactOnRails::Utils).to receive_messages(
440-
react_on_rails_pro_licence_valid?: true
440+
react_on_rails_pro?: true
441441
)
442442
end
443443

@@ -483,7 +483,7 @@ def helper.append_javascript_pack_tag(name, **options)
483483
subject(:react_app) { react_component_hash("App", props: props, immediate_hydration: true) }
484484

485485
before do
486-
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro_licence_valid?).and_return(false)
486+
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro?).and_return(false)
487487
end
488488

489489
it "adds badge to componentHtml" do
@@ -496,7 +496,7 @@ def helper.append_javascript_pack_tag(name, **options)
496496

497497
before do
498498
allow(ReactOnRails::Utils).to receive_messages(
499-
react_on_rails_pro_licence_valid?: true
499+
react_on_rails_pro?: true
500500
)
501501
end
502502

@@ -541,7 +541,7 @@ def helper.append_javascript_pack_tag(name, **options)
541541
subject(:store) { redux_store("reduxStore", props: props, immediate_hydration: true) }
542542

543543
before do
544-
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro_licence_valid?).and_return(false)
544+
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro?).and_return(false)
545545
end
546546

547547
it { is_expected.to include(badge_html_string) }
@@ -557,7 +557,7 @@ def helper.append_javascript_pack_tag(name, **options)
557557
subject(:store) { redux_store("reduxStore", props: props, immediate_hydration: false) }
558558

559559
before do
560-
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro_licence_valid?).and_return(false)
560+
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro?).and_return(false)
561561
end
562562

563563
it { is_expected.not_to include(badge_html_string) }
@@ -568,7 +568,7 @@ def helper.append_javascript_pack_tag(name, **options)
568568

569569
before do
570570
allow(ReactOnRails::Utils).to receive_messages(
571-
react_on_rails_pro_licence_valid?: true
571+
react_on_rails_pro?: true
572572
)
573573
end
574574

spec/dummy/spec/system/integration_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def finished_all_ajax_requests?
8888

8989
shared_context "with pro features and immediate hydration" do
9090
before do
91-
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro_licence_valid?).and_return(true)
91+
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro?).and_return(true)
9292
end
9393

9494
around do |example|

spec/react_on_rails/react_component/render_options_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def the_attrs(react_component_name: "App", options: {})
2121

2222
# TODO: test pro features without license
2323
before do
24-
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro_licence_valid?).and_return(true)
24+
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro?).and_return(true)
2525
end
2626

2727
it "works without raising error" do

0 commit comments

Comments
 (0)