Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#184611345] Chore / Support for rails 6.1 #1

Merged
merged 9 commits into from
Apr 11, 2023

Conversation

masonlouchart
Copy link
Collaborator

@masonlouchart masonlouchart commented Apr 7, 2023

@iusztin @NEWROPE/package

Pivotal Story

Changes

How to reproduce

  • checkout master branch
  • run bundle
  • run bundle exec rake test

How to validate

  • checkout the branch chore/support-for-rails-6.1
  • run bundle exec rake test

Please review.

@masonlouchart masonlouchart changed the title Chore / Support for rails 6.1 [#184611345] Chore / Support for rails 6.1 Apr 7, 2023
@iusztin
Copy link
Member

iusztin commented Apr 10, 2023

@masonlouchart Sorry, do you get any errors when executing the above comments?

I tried validating like suggested:

How to validate
checkout the branch chore/support-for-rails-6.1
run bundle exec rake test

 ❯ git checkout chore/support-for-rails-6.1
# or to get the code from this PR you can do:
# ❯ git fetch origin pull/1/head
# git checkout FETCH_HEAD
 ❯ rvm use 3.2.1
Using /Users/oliveriusztin/.rvm/gems/ruby-3.2.1
❯ bundle _2.4.10_
# succeeds

When trying to execute the tests it fails:

❯ bundle exec rake test
/Users/oliveriusztin/.rvm/gems/ruby-3.2.1/gems/rest-client-1.6.7/lib/restclient/exceptions.rb:157: warning: assigned but unused variable - message
/Users/oliveriusztin/.rvm/gems/ruby-3.2.1/gems/rest-client-1.6.7/lib/restclient/exceptions.rb:167: warning: assigned but unused variable - message
/Users/oliveriusztin/.rvm/gems/ruby-3.2.1/gems/rest-client-1.6.7/lib/restclient/response.rb:11: warning: method redefined; discarding old body
/Users/oliveriusztin/.rvm/gems/ruby-3.2.1/gems/rest-client-1.6.7/lib/restclient/payload.rb:47: warning: mismatched indentations at 'end' with 'case' at 40
/Users/oliveriusztin/Documents/typescript-rails/test/test_helper.rb:6:in `<top (required)>': [DEPRECATION] ::[] is deprecated. Use ::new instead.
/Users/oliveriusztin/.rvm/gems/ruby-3.2.1/gems/activesupport-4.2.11.3/lib/active_support/core_ext/hash/except.rb:9: warning: method redefined; discarding old except
/Users/oliveriusztin/.rvm/gems/ruby-3.2.1/gems/activesupport-4.2.11.3/lib/active_support/core_ext/hash/slice.rb:21: warning: method redefined; discarding old slice
/Users/oliveriusztin/.rvm/gems/ruby-3.2.1/gems/activesupport-4.2.11.3/lib/active_support/core_ext/hash/keys.rb:8: warning: method redefined; discarding old transform_keys
/Users/oliveriusztin/.rvm/gems/ruby-3.2.1/gems/activesupport-4.2.11.3/lib/active_support/core_ext/hash/keys.rb:19: warning: method redefined; discarding old transform_keys!
Coverage report generated for Unit Tests to /Users/oliveriusztin/Documents/typescript-rails/coverage. 0 / 0 LOC (100.0%) covered.
[Coveralls] Outside the Travis environment, not sending data.
Stopped processing SimpleCov as a previous error not related to SimpleCov has been detected
/Users/oliveriusztin/.rvm/gems/ruby-3.2.1/gems/activesupport-4.2.11.3/lib/active_support/core_ext/object/duplicable.rb:111:in `<class:BigDecimal>': undefined method `new' for BigDecimal:Class (NoMethodError)

    BigDecimal.new('4.56').dup
              ^^^^
        from /Users/oliveriusztin/.rvm/gems/ruby-3.2.1/gems/activesupport-4.2.11.3/lib/active_support/core_ext/object/duplicable.rb:106:in `<top (required)>'
        from <internal:/Users/oliveriusztin/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:/Users/oliveriusztin/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from /Users/oliveriusztin/.rvm/gems/ruby-3.2.1/gems/activesupport-4.2.11.3/lib/active_support/core_ext/object.rb:3:in `<top (required)>'
        from <internal:/Users/oliveriusztin/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:/Users/oliveriusztin/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from /Users/oliveriusztin/.rvm/gems/ruby-3.2.1/gems/railties-4.2.11.3/lib/rails/configuration.rb:2:in `<top (required)>'
        from <internal:/Users/oliveriusztin/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:/Users/oliveriusztin/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from /Users/oliveriusztin/.rvm/gems/ruby-3.2.1/gems/railties-4.2.11.3/lib/rails/railtie.rb:2:in `<top (required)>'
        from <internal:/Users/oliveriusztin/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:/Users/oliveriusztin/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from /Users/oliveriusztin/.rvm/gems/ruby-3.2.1/gems/railties-4.2.11.3/lib/rails/engine.rb:1:in `<top (required)>'
        from <internal:/Users/oliveriusztin/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:/Users/oliveriusztin/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from /Users/oliveriusztin/.rvm/gems/ruby-3.2.1/gems/railties-4.2.11.3/lib/rails/application.rb:7:in `<top (required)>'
        from <internal:/Users/oliveriusztin/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:/Users/oliveriusztin/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from /Users/oliveriusztin/.rvm/gems/ruby-3.2.1/gems/railties-4.2.11.3/lib/rails.rb:11:in `<top (required)>'
        from <internal:/Users/oliveriusztin/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:/Users/oliveriusztin/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from /Users/oliveriusztin/Documents/typescript-rails/test/test_helper.rb:17:in `<top (required)>'
        from <internal:/Users/oliveriusztin/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:/Users/oliveriusztin/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from /Users/oliveriusztin/Documents/typescript-rails/test/assets_generator_test.rb:1:in `<top (required)>'
        from <internal:/Users/oliveriusztin/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:/Users/oliveriusztin/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from /Users/oliveriusztin/.rvm/rubies/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:21:in `block in <main>'
        from /Users/oliveriusztin/.rvm/rubies/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:6:in `select'
        from /Users/oliveriusztin/.rvm/rubies/ruby-3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:6:in `<main>'
rake aborted!
Command failed with status (1)
/Users/oliveriusztin/.rvm/gems/ruby-3.2.1/bin/ruby_executable_hooks:22:in `eval'
/Users/oliveriusztin/.rvm/gems/ruby-3.2.1/bin/ruby_executable_hooks:22:in `<main>'
Tasks: TOP => test
(See full trace by running task with --trace)

@masonlouchart
Copy link
Collaborator Author

masonlouchart commented Apr 10, 2023

Actually, I got some errors but different ones. The test suite can be run entirely without Rake failure. Please take a look at the file I've attached. These errors don't have to be fixed for our purpose but are a sign that we should either update our fork or stop using this gem.

output.txt

I will go ahead with the investigation. Hoping I can reproduce the error.

@masonlouchart
Copy link
Collaborator Author

It might be due to old activesupport version. It looks like yours is 4.2.11.3 while I don't have any under 6.0 installed.

❯ gem list activesupport 

*** LOCAL GEMS ***

activesupport (6.1.7.3, 6.1.0, 6.0.6.1, 6.0.5.1)

@masonlouchart
Copy link
Collaborator Author

I fixed some warnings and configurations. But 2 errors remaining. I have no idea why it is related to missing files not being generated. As far as I understand, running the test is supposed to ask Rails to generate them. I am not sure it is worth it to invest more time in this 2 errors. Please take a look and let me know what you think 🧐

Here is the output.txt

Could you please reinstall this project and re-run the test suite?

@iusztin
Copy link
Member

iusztin commented Apr 11, 2023

I could reproduce the output. Sorry, please let me consider a bit :)

Copy link
Member

@iusztin iusztin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for dealing with the old library :) Please take a look at the comments.

I fixed some warnings and configurations. But 2 errors remaining. I have no idea why it is related to missing files not being generated. As far as I understand, running the test is supposed to ask Rails to generate them. I am not sure it is worth it to invest more time in this 2 errors. Please take a look and let me know what you think 🧐

Here is the output.txt

The output file you shared has 4 errors, not 2 errors? And I can also reproduce the same 4 errors locally.

10 runs, 18 assertions, 4 failures, 0 errors, 0 skips

Out of those 4, wouldn't two be very important to the functionality of the library? These two:

AssetsTest#test_typescript.js_is_included_in_Sprockets_environment [/Users/mason/workspace/NEWROPE/typescript-rails/test/assets_test.rb:40]:
assert { assets["typescript"].source.include?('var ts;') }
rails test test/assets_test.rb:38

and

AssetsTest#test_assets_.js.ts_is_compiled_from_TypeScript_to_JavaScript [/Users/mason/workspace/NEWROPE/typescript-rails/test/assets_test.rb:44]:
assert { assets['javascripts/hello.js'].present? }
rails test test/assets_test.rb:43

We use the library to generate assets from TypeScript via Sprockets, so it would be important to ensure that part still works.

About the other errors related to "controller generator" and "scaffold generator": I agree they aren't so important, because they only affect developers.

@@ -31,25 +31,25 @@ def source

test 'typescript views are served as javascript' do
get '/site/index.js'
assert_match /var x = 5;\s*/,
assert_match (/var x = 5;\s*/),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What effect do the brackets have? I didn't see any difference after removing them when running tests.

Copy link
Collaborator Author

@masonlouchart masonlouchart Apr 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It removes warnings.

❯ bundle exec rake test --trace             
** Invoke test (first_time)
** Execute test
/Users/mason/workspace/NEWROPE/typescript-rails/test/template_handler_test.rb:34: warning: ambiguous first argument; put parentheses or a space even after `/' operator
/Users/mason/workspace/NEWROPE/typescript-rails/test/template_handler_test.rb:40: warning: ambiguous first argument; put parentheses or a space even after `/' operator
/Users/mason/workspace/NEWROPE/typescript-rails/test/template_handler_test.rb:46: warning: ambiguous first argument; put parentheses or a space even after `/' operator
/Users/mason/workspace/NEWROPE/typescript-rails/test/template_handler_test.rb:52: warning: ambiguous first argument; put parentheses or a space even after `/' operator
Run options: --seed 34434

Gemfile Outdated
@@ -4,7 +4,7 @@ source 'https://rubygems.org'
gemspec

group :test do
gem 'rails', '~> 4.0'
gem 'rails', '>= 4.0', '< 7.0'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we need to use Rails 7 don't we need to test this using Rails 7? https://newrope.slack.com/archives/C02S08WDQ/p1681097711254339?thread_ts=1680764615.995429&cid=C02S08WDQ

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I thought about it last night before bed. I wanted to make sure we don't use Rails 7 yet for debugging this old dependency but actually might not be a wise decision. I will remove the lock.

@masonlouchart
Copy link
Collaborator Author

masonlouchart commented Apr 11, 2023

You will notice that running tests actually fail.

❯ bundle exec rake test --trace
** Invoke test (first_time)
** Execute test
Run options: --seed 22052

# Running:

/Users/mason/.rvm/gems/ruby-2.7.2/gems/typescript-src-1.6.2.0/lib/typescript-src.rb:12: warning: instance variable @typescript_path not initialized
.E

Error:
AssetsTest#test_typescript.js_is_included_in_Sprockets_environment:
FrozenError: can't modify frozen Array: []
    /Users/mason/.rvm/gems/ruby-2.7.2/gems/railties-7.0.4.3/lib/rails/engine.rb:574:in `unshift'
    /Users/mason/.rvm/gems/ruby-2.7.2/gems/railties-7.0.4.3/lib/rails/engine.rb:574:in `block in <class:Engine>'
    /Users/mason/.rvm/gems/ruby-2.7.2/gems/railties-7.0.4.3/lib/rails/initializable.rb:32:in `instance_exec'
    /Users/mason/.rvm/gems/ruby-2.7.2/gems/railties-7.0.4.3/lib/rails/initializable.rb:32:in `run'
    /Users/mason/.rvm/gems/ruby-2.7.2/gems/railties-7.0.4.3/lib/rails/initializable.rb:61:in `block in run_initializers'
    /Users/mason/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/tsort.rb:228:in `block in tsort_each'
    /Users/mason/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    /Users/mason/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
    /Users/mason/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
    /Users/mason/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/tsort.rb:431:in `each_strongly_connected_component_from'
    /Users/mason/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
    /Users/mason/.rvm/gems/ruby-2.7.2/gems/railties-7.0.4.3/lib/rails/initializable.rb:50:in `each'
    /Users/mason/.rvm/gems/ruby-2.7.2/gems/railties-7.0.4.3/lib/rails/initializable.rb:50:in `tsort_each_child'
    /Users/mason/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/tsort.rb:415:in `call'
    /Users/mason/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/tsort.rb:415:in `each_strongly_connected_component_from'
    /Users/mason/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
    /Users/mason/.rvm/gems/ruby-2.7.2/gems/railties-7.0.4.3/lib/rails/initializable.rb:50:in `each'
    /Users/mason/.rvm/gems/ruby-2.7.2/gems/railties-7.0.4.3/lib/rails/initializable.rb:50:in `tsort_each_child'
    /Users/mason/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/tsort.rb:415:in `call'
    /Users/mason/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/tsort.rb:415:in `each_strongly_connected_component_from'
    /Users/mason/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/tsort.rb:349:in `block in each_strongly_connected_component'
    /Users/mason/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/tsort.rb:347:in `each'
    /Users/mason/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/tsort.rb:347:in `call'
    /Users/mason/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/tsort.rb:347:in `each_strongly_connected_component'
    /Users/mason/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/tsort.rb:226:in `tsort_each'
    /Users/mason/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/tsort.rb:205:in `tsort_each'
    /Users/mason/.rvm/gems/ruby-2.7.2/gems/railties-7.0.4.3/lib/rails/initializable.rb:60:in `run_initializers'
    /Users/mason/.rvm/gems/ruby-2.7.2/gems/railties-7.0.4.3/lib/rails/application.rb:372:in `initialize!'
    /Users/mason/.rvm/gems/ruby-2.7.2/gems/railties-7.0.4.3/lib/rails/railtie.rb:226:in `public_send'
    /Users/mason/.rvm/gems/ruby-2.7.2/gems/railties-7.0.4.3/lib/rails/railtie.rb:226:in `method_missing'
    /Users/mason/workspace/NEWROPE/typescript-rails/test/assets_test.rb:23:in `setup'

However, if you run the for Sprocket commenting the other for TypeScript and do the opposite too, it works. We just cannot run all tests at once... I suspect Sprocket but could not find anything.

@masonlouchart
Copy link
Collaborator Author

This PR is ready to be reviewed. Please give it a try and let me know if you encounter different situation.

@iusztin
Copy link
Member

iusztin commented Apr 11, 2023

However, if you run the for Sprocket commenting the other for TypeScript and do the opposite too, it works. We just cannot run all tests at once... I suspect Sprocket but could not find anything.

I debugged this a bit.

If you look at the stack trace:

/Users/mason/workspace/NEWROPE/typescript-rails/test/assets_test.rb:23:in `setup'

You can see that it is raised by initializing Rails.

I added print debugging to setup and looks like this is called before every test.
I didn't find any way to change this properly because I don't know Rails internals enough. But how about adding a workaround like this to avoid the problem?

diff --git a/test/assets_test.rb b/test/assets_test.rb
index 95c56a5..e551230 100644
--- a/test/assets_test.rb
+++ b/test/assets_test.rb
@@ -35,12 +35,13 @@ class AssetsTest < ActiveSupport::TestCase
     @app.assets
   end

-  test 'typescript.js is included in Sprockets environment' do
+  # Run all tests in one block to avoid error from calling @app.initialize! multiple times
+  test 'generates assets successfully' do
+    # typescript.js is included in Sprockets environment
     assert { assets['typescript'].filename.to_s.end_with?('/lib/assets/javascripts/typescript.js.erb') }
     assert { assets['typescript'].source.include?('var ts;') }
-  end

-  test 'assets .js.ts is compiled from TypeScript to JavaScript' do
+    # 'assets .js.ts is compiled from TypeScript to JavaScript'
     assert { assets['javascripts/hello.js'].present? }
     assert { assets['javascripts/hello.js'].source.include?('var log_to_console = function (x) {') }
     assert { assets['javascripts/hello.js'].source.include?('var s = "Hello, world!";') }

But after this the tests still failed...

I suspect something about sprockets v4 breaking changes, because when I tried using sprockets v3 the tests passed:

diff --git a/Gemfile b/Gemfile
index 12d4128..7506172 100644
--- a/Gemfile
+++ b/Gemfile
@@ -6,9 +6,9 @@ gemspec
 group :test do
   gem 'rails', '>= 4.0'
   gem 'sprockets-rails', '> 2.0'
+  gem 'sprockets', '~> 3'
   gem 'minitest-power_assert'
   gem 'coveralls'
   gem 'simplecov'
   gem 'tzinfo-data', platforms: [:mingw, :mswin]
 end
-

CBK currently uses sprockets v3 though - if we don't need to upgrade to v4 we can keep v3 in this gem?

By the way, should we commit Gemfile.lock? I think the risk is high to forget which version we tested with & produce different results at a later time...

@masonlouchart
Copy link
Collaborator Author

You can see that it is raised by initializing Rails.

I didn't expect an internal issue from Rails because of Sprocket...

CBK currently uses sprockets v3 though - if we don't need to upgrade to v4 we can keep v3 in this gem?

I thought we would have to use v4 with Rails 7 but it does not look incompatible after checking again.

By the way, should we commit Gemfile.lock?

Definitely. I forgot about this point.

@iusztin
Copy link
Member

iusztin commented Apr 11, 2023

I thought we would have to use v4 with Rails 7 but it does not look incompatible after checking again.

TBH I didn't check this too deeply. But we can deal with it later if the need becomes evident.

Copy link
Member

@iusztin iusztin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! LGTM :)

@iusztin iusztin merged commit c509760 into master Apr 11, 2023
@masonlouchart masonlouchart deleted the chore/support-for-rails-6.1 branch April 11, 2023 09:44
@hiroara
Copy link
Member

hiroara commented Apr 12, 2023

Interesting... Recently the best practice about whether to commit Gemfile.lock or not has been updated: https://stackoverflow.com/a/4151540

@iusztin
Copy link
Member

iusztin commented Apr 12, 2023

Interesting... Recently the best practice about whether to commit Gemfile.lock or not has been updated: https://stackoverflow.com/a/4151540

Thank you for sharing that. I think for development it's convenient (=> easy to reproduce results consistently when collaborating). If we want to ensure support for ranges of versions, just in my opinion: it's difficult to manually keep up -> CI should deal with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rails 6.1 support
3 participants