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

Add some bin/ helpers #3489

Merged
merged 7 commits into from
Feb 14, 2020
Merged

Conversation

elia
Copy link
Member

@elia elia commented Jan 24, 2020

Description

Add a bunch of bin files that anyone can expect to be present when working on a gem and that can make the life a bit easier for the Solidus developer.

  • bin/setup will do the usual gem setup, with bundler, it tries with install first, then falls back to update
  • bin/console will just start irb with bundler and solidus already required
  • bin/rake it's a simple binstup, for parity with the latest habits of Rails
  • bin/sandbox formerly rake sandbox will (re)create the sandbox app, any argument will be passed to the spree:install generator
  • bin/rails will forward everything to the bin/rails of the sandbox, will also create the sandbox if it's missing
  • bin/rspec will run specs from the root, changing directory as appropriate for each group of specs (see the commit description for more details).

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have updated Guides and README accordingly to this change (if needed)
  • I have added tests to cover this change (if needed)
  • I have attached screenshots to this PR for visual changes (if needed)

@elia elia marked this pull request as ready for review January 24, 2020 18:52
@elia elia requested review from kennyadsl and tvdeyen January 28, 2020 14:19
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

This is a very nice idea.

I have some issues locally. Probably because of missing files?

echo "
🚀 This app is intended for test purposes. If you're interested in running
🚀 Solidus in production, visit:
🚀 https://guides.solidus.io/developers/getting-started/first-time-installation"
Copy link
Member

Choose a reason for hiding this comment

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

› bin/sandbox
Traceback (most recent call last):
-e:1:in `<main>': undefined method `with_unbundled_env' for Bundler:Module (NoMethodError)
Did you mean?  with_clean_env

Copy link
Member

Choose a reason for hiding this comment

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

Still having this issue:

› bin/sandbox
Successfully installed bundler-2.1.4
1 gem installed
Traceback (most recent call last):
-e:1:in `<main>': undefined method `with_unbundled_env' for Bundler:Module (NoMethodError)
Did you mean?  with_clean_env

Dir.chdir app_root

exec "#{__dir__}/unbundled", 'bin/rails', *ARGV

Copy link
Member

Choose a reason for hiding this comment

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

› bin/rails                       
Traceback (most recent call last):
-e:1:in `<main>': undefined method `with_unbundled_env' for Bundler:Module (NoMethodError)
Did you mean?  with_clean_env
Automatic creation of the sandbox app failed

Copy link
Member

Choose a reason for hiding this comment

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

Still have this issue

› bin/sandbox
Successfully installed bundler-2.1.4
1 gem installed
Traceback (most recent call last):
-e:1:in `<main>': undefined method `with_unbundled_env' for Bundler:Module (NoMethodError)
Did you mean?  with_clean_env

@elia
Copy link
Member Author

elia commented Jan 28, 2020

@tvdeyen thanks for the review, the problem you're facing is due to a deprecation within bundler that I tried to fix

https://github.com/rubygems/bundler/blob/bada03dd6d4d15828fb5b2cf7f744948e88a69a3/lib/bundler.rb#L367-L377

I'm ok with either support both methods, go back to the older one, or require bundler 2.1, let me know which of the two makes more sense to you, meanwhile installing bundler 2.1 should allow you to try the helpers out.

@tvdeyen
Copy link
Member

tvdeyen commented Jan 28, 2020

@elia since this only effects local development I am fine with both as well. Just make sure that it is obvious that we require an updated bundler version for local development.

Thanks for this, this is really great 👍

@elia elia requested a review from tvdeyen January 29, 2020 13:57
@elia
Copy link
Member Author

elia commented Jan 29, 2020

@tvdeyen I've updated the code to install 2.1 or above as part of bin/setup and bin/sandbox, that should make the experience smooth for everyone.

Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

Thanks

@kennyadsl
Copy link
Member

Thanks @elia, just one question: what is a use case of bin/console exactly?

@elia
Copy link
Member Author

elia commented Feb 3, 2020

Thanks @elia, just one question: what is a use case of bin/console exactly?

@kennyadsl that's a good point, I initially included it because it comes with the standard bundle gem template expecting others to find it useful for something 😅

Anyway, after further inspection, it was clear that had no real use-case… so I have included a helper that allows the initialization of the dummy app from within the console:

  • it relies on DATABASE_URL but defaults to an in-memory sqlite
  • it can be easily initialized and migrated
  • it features inline instructions
  • it allows interaction with all of solidus classes (after initialization) and models (after db migration)

bin/console Show resolved Hide resolved
@kennyadsl kennyadsl force-pushed the elia/bin-files branch 4 times, most recently from b91f203 to 41f0d10 Compare February 4, 2020 12:26
@kennyadsl
Copy link
Member

@gmacdougall @tvdeyen Since your review we also added support to easily load the DummyApp in the bin/console (not bin/rails console) task, otherwise it's quite useless. Would you mind re-review the last two commits?

Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

Very nice work, but I still have the bundler issue.

› bin/sandbox
Successfully installed bundler-2.1.4
1 gem installed
Traceback (most recent call last):
-e:1:in `<main>': undefined method `with_unbundled_env' for Bundler:Module (NoMethodError)
Did you mean?  with_clean_env

› bundle -v
Bundler version 1.17.3

› gem -v
3.0.3

› ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19]

It seems although Bundler 2.1.4 is installed it still uses 1.17.3

› gem list bundler

*** LOCAL GEMS ***

bundler (2.1.4, 2.0.2, 1.17.3, default: 1.17.2)

Dir.chdir app_root

exec "#{__dir__}/unbundled", 'bin/rails', *ARGV

Copy link
Member

Choose a reason for hiding this comment

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

Still have this issue

› bin/sandbox
Successfully installed bundler-2.1.4
1 gem installed
Traceback (most recent call last):
-e:1:in `<main>': undefined method `with_unbundled_env' for Bundler:Module (NoMethodError)
Did you mean?  with_clean_env

echo "
🚀 This app is intended for test purposes. If you're interested in running
🚀 Solidus in production, visit:
🚀 https://guides.solidus.io/developers/getting-started/first-time-installation"
Copy link
Member

Choose a reason for hiding this comment

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

Still having this issue:

› bin/sandbox
Successfully installed bundler-2.1.4
1 gem installed
Traceback (most recent call last):
-e:1:in `<main>': undefined method `with_unbundled_env' for Bundler:Module (NoMethodError)
Did you mean?  with_clean_env

@elia
Copy link
Member Author

elia commented Feb 5, 2020

@tvdeyen is it possible that your main Gemfile.lock is still referencing v1? Maybe we should add bundle update --bundler to bin/setup

elia added 6 commits February 6, 2020 11:49
Executing `bin/rails s` or `bin/rails c` will now work like in every
other app.
This is not a standard feature of any newly created Rails app and can
come handy during Solidus development as well.
Allow to start a console with the solidus gems loaded where you can
poke around with the library in plain Ruby.
For when a change affects multiple components or for tools relying on
bin/rspec this helper will make things a lot easier.

Will take in both paths and options and run the specs for each
component speparately keeping the options.

Example:

    $ bin/rspec core/spec/models/spree/exchange_spec.rb api/spec/features/checkout_spec.rb -f doc

Will give the following output:

```
$ cd core; bundle exec rspec -f doc /Users/elia/Code/Nebulab/solidus/core/spec/models/spree/exchange_spec.rb; cd -
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}

Randomized with seed 190

Spree::Exchange
  #description
    describes the return items' change in options
  #perform!
    creates shipments for the order with the return items exchange inventory units
    when it cannot create shipments for all items
      raises an UnableToCreateShipments error
  #display_amount
    is the total amount of all return items
  .param_key
    is expected to eq "spree_exchange"
  #to_key
    is expected to be nil

Finished in 2.22 seconds (files took 3.27 seconds to load)
6 examples, 0 failures

Randomized with seed 190

$ cd api; bundle exec rspec -f doc /Users/elia/Code/Nebulab/solidus/api/spec/features/checkout_spec.rb; cd -

Randomized with seed 55051

Api Feature Specs
  is able to checkout with the update request
  is able to checkout with individualized requests
  is able to checkout with the create request

Finished in 3.15 seconds (files took 3.3 seconds to load)
3 examples, 0 failures

Randomized with seed 55051

```

The first line is always the executed command that can be copied and
pasted as it is.
Usage example:

$ bin/console
USAGE:
  dummy_app             # Load the dummy app and return the Rails.application instance
  dummy_app.initialize! # Initialize the dummy app
  dummy_app.migrate!    # Run all the dummy app migrations
>> dummy_app
Loading the dummy app...done.
=> #<DummyApp::Application root=/Users/elia/Code/Nebulab/solidus>
>> dummy_app.initialize!
=> #<DummyApp::Application root=/Users/elia/Code/Nebulab/solidus>
>> dummy_app.migrate!
== 20100107141738 AddApiKeyToSpreeUsers: migrating ============================
-- add_column(:spree_users, :api_key, :string, {:limit=>40})
   -> 0.0019s
== 20100107141738 AddApiKeyToSpreeUsers: migrated (0.0020s) ===================

...

== 20190220093635 DropSpreeStoreCreditUpdateReasons: migrating ================
-- table_exists?(:spree_store_credit_update_reasons)
   -> 0.0003s
-- drop_table(:spree_store_credit_update_reasons)
   -> 0.0002s
-- column_exists?(:spree_store_credit_events, :update_reason_id)
   -> 0.0004s
-- remove_column(:spree_store_credit_events, :update_reason_id)
   -> 0.0075s
== 20190220093635 DropSpreeStoreCreditUpdateReasons: migrated (0.0084s) =======

=> #<DummyApp::Application root=/Users/elia/Code/Nebulab/solidus>
>>
@elia
Copy link
Member Author

elia commented Feb 6, 2020

@tvdeyen I think it's fixed now, bin/sandbox will check bundler's version and redirect the user to run bin/setup to fix the problem. bin/setup will install bundler 2.1 and update the lock file if bundler is older than 2.1.

$ bin/sandbox                                                                                                             ~/C/N/solidus
The sandbox requires at least Bundler 2.1, please run bin/setup to update it.

$ bin/setup                                                                                                               ~/C/N/solidus
== Installing dependencies ==
$ gem install bundler -v"~> 2.1" --conservative
Successfully installed bundler-2.1.4
Parsing documentation for bundler-2.1.4
Done installing documentation for bundler after 2 seconds
1 gem installed
$ bundle update --bundler
...
Using bundler 2.1.4
...
Warning: the lockfile is being updated to Bundler 2, after which you will be unable to return to Bundler 1.
Bundle updated!
$ bundle check
The dependency jruby-openssl (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for java. To add those platforms to the bundle, run `bundle lock --add-platform java`.
The dependency activerecord-jdbcsqlite3-adapter (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for java. To add those platforms to the bundle, run `bundle lock --add-platform java`.
The Gemfile's dependencies are satisfied

$ bin/setup                                                                                                               ~/C/N/solidus
== Installing dependencies ==
$ bundle check
The dependency jruby-openssl (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for java. To add those platforms to the bundle, run `bundle lock --add-platform java`.
The dependency activerecord-jdbcsqlite3-adapter (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for java. To add those platforms to the bundle, run `bundle lock --add-platform java`.
The Gemfile's dependencies are satisfied

$ bin/sandbox                                                                                                             ~/C/N/solidus
      create  
      create  README.md
      create  Rakefile
...

@elia elia requested a review from tvdeyen February 6, 2020 10:54
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

Works like charm. Thanks 🙏

Copy link
Member

@spaghetticode spaghetticode left a comment

Choose a reason for hiding this comment

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

@elia thanks 🍰

@spaghetticode spaghetticode merged commit 0b88118 into solidusio:master Feb 14, 2020
@spaghetticode spaghetticode deleted the elia/bin-files branch February 14, 2020 15:34
@mabry1985
Copy link

mabry1985 commented Jul 22, 2020

Sorry if this isn't the right place to post this, but I'm trying to get a sandbox setup and am running into a bundler error that @elia worked on and I'm not sure where to go from here. It's been a few months since using Rails regularly so maybe I'm missing something basic, but I've been stuck on this for awhile, so thought I'd reach out for advice.

$ bin/sandbox
The sandbox requires at least Bundler 2.1, please run bin/setup to update it.

$ bin/setup
== Installing dependencies ==
$ gem install bundler -v"~> 2.1" --conservative
$ bundle update --bundler
The dependency jruby-openssl (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for java. To add those platforms to the bundle, run `bundle lock --add-platform java`.
The dependency activerecord-jdbcsqlite3-adapter (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for java. To add those platforms to the bundle, run `bundle lock --add-platform java`.
...
Bundle updated!
$ bundle check
The dependency jruby-openssl (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for java. To add those platforms to the bundle, run `bundle lock --add-platform java`.
The dependency activerecord-jdbcsqlite3-adapter (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for java. To add those platforms to the bundle, run `bundle lock --add-platform java`.
The Gemfile's dependencies are satisfied

$ bundler -v
Bundler version 2.1.4

$ bin/sandbox            
The sandbox requires at least Bundler 2.1, please run bin/setup to update it.

UPDATE:

gem update --system

This is what I had to do in my case. Decided to update in case someone else has the same issue. Remove if unhelpful. Cheers.

@elia
Copy link
Member Author

elia commented Jul 23, 2020

gem update --system

This is what I had to do in my case. Decided to update in case someone else has the same issue. Remove if unhelpful. Cheers.

@mabry1985 thanks for posting the solution! I guess this will be very helpful for people bumping into the same problem 👍

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.

6 participants