-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Replace generated dummy test_app with single file rails application #2281
Conversation
end | ||
end | ||
config.paths['db/migrate'].concat migration_dirs | ||
#binding.pry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after #.
config.secret_key_base = 'SECRET_TOKEN' | ||
|
||
# FIXME: needs to add ALL engines | ||
#config.paths['db/migrate'] << File.expand_path('../../../../db/migrate', __FILE__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after #.
end | ||
|
||
def self.rails_root | ||
Pathname.new(gem_root).join(*%w[spec dummy]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass array contents as separate arguments.
|
||
module Dummy | ||
def self.gem_root | ||
Pathname.new(File.dirname ENV['BUNDLE_GEMFILE']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add parentheses to nested method call File.dirname ENV['BUNDLE_GEMFILE'].
require 'rails/commands/console/console_command' | ||
Rails::Console.new(Rails.application, sandbox: true, environment: "test").start | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 trailing blank lines detected.
end | ||
|
||
Dummy::AutoMigrate.new.migrate | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 trailing blank lines detected.
sh 'rake db:reset VERBOSE=false' | ||
|
||
# We might have a brand new database, so we must re-establish our connection | ||
ActiveRecord::Base::establish_connection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use :: for method calls.
class AutoMigrate | ||
# Ensure database exists | ||
def database_exists? | ||
begin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant begin block detected.
7791b36
to
06df2b6
Compare
2dedc3c
to
ecbbc58
Compare
I have some difficulties to build this locally. First try in root of SolidusPulled fresh branch, ran bundle update and
Fails with hundreds of errors. All the same. Seems to be routes related.Second try in
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome! Thanks for working on this John
I have some nits about changing behaviour in this PR.
config.action_mailer.delivery_method = :test | ||
config.action_controller.allow_forgery_protection = false | ||
config.active_support.deprecation = :stderr | ||
config.eager_load = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicated line 44
class Application < ::Rails::Application | ||
config.root = Dummy.rails_root | ||
config.eager_load = Rails.env.production? | ||
config.cache_classes = !Rails.env.development? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other settings have hard coded bools, while these doesn't. I think it's fine that we hard code all booleans. This dummy app is not meant to be run in other Rails env, isn't it?
Spree::Deprecation.behavior = :raise | ||
end | ||
|
||
Spree.user_class = 'Spree::LegacyUser' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we consider to move all Spree config into a file (../dummy_app/spree_defaults.rb
)?
else | ||
[] | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be nearly the same as in ../dummy_app.rb:61-67
. Can we get rid of this duplication?
expect(response).to render_template(layout: 'layouts/application') | ||
expect { | ||
get :index | ||
}.to raise_error(ActionView::MissingTemplate, %r{Missing template layouts/my_super_awesome_layout}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should not change the spec like this. Is there a way to tell the dummy app the view paths like you did with the assets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do, but can send a separate PR
@@ -1,7 +1,6 @@ | |||
module Spree | |||
class OrdersController < Spree::StoreController | |||
before_action :check_authorization | |||
rescue_from ActiveRecord::RecordNotFound, with: :render_404 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is very common in stores to overwrite render_404
and do stuff instead of rendering the 404 page. Building a dynamic 404 page for instance. Is there a way to still provide this functionality for stores? Could you tell the dummy app where to find the views like you did with the assets paths for instance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be removed anyways because it's a bad way to override the 404 behaviour.
Stores could regain this functionality by either:
- Using
config.exceptions_app
, the proper way to have a dynamic 404 page - Setting up the
rescue_from
fromApplicationController
- Class-evaling (or
send
ing) the rescue_from (if overrides are being done anyways)
But I can submit this as a separate PR if it will get this merged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I can't remove this because the render_404
behaviour is very unusual.
render status: :not_found, file: "#{::Rails.root}/public/404", formats: [:html], layout: nil
This doesn't use views, it renders the public/404.html
file relative to the Rails.root
directory. There's really no way to get around this, it's bad code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL config.exceptions_app
🎉
You are right, the code is bad and should be removed. Although it's blocking your PR I think we need a separate PR due to visibility reasons. I think we can forego with deprecating this, though.
@@ -3,7 +3,6 @@ class ProductsController < Spree::StoreController | |||
before_action :load_product, only: :show | |||
before_action :load_taxon, only: :index | |||
|
|||
rescue_from ActiveRecord::RecordNotFound, with: :render_404 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jhawthorn, looking forward to run specs without running the test_app
task!
Should we add a line to the changelog?
Also, I agree with most of the @tvdeyen notes despite I don't have a strong opinion on render_404
issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the api migrations being handled elsewhere, I am good with the rest.
@@ -1,7 +0,0 @@ | |||
class AddApiKeyToSpreeUsers < ActiveRecord::Migration[4.2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should deal with these migrations in a separate PR. The weirdness of them came up when I did the roll-up but I didn't want to change any behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this change.
Replaced the db:migrate task with a custom migration task which runs migrations one engine at a time (which simulates running railties:install:migrations
before db:migrate
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some files could not be reviewed due to errors:
.rubocop.yml: Style/FileName has the wrong namespace - should be Naming
.rubocop.yml: Style/FileName has the wrong namespace - should be Naming .rubocop.yml: Style/PredicateName has the wrong namespace - should be Naming .rubocop.yml: Style/AccessorMethodName has the wrong namespace - should be Naming .rubocop.yml: Style/VariableNumber has the wrong namespace - should be Naming Error: The `Style/OpMethod` cop has been renamed and moved to `Naming/BinaryOperatorParameterName`. (obsolete configuration found in .rubocop.yml, please update it)
I've addressed most of the feedback.
This should be fixed. We were incorrectly running specs using the top-level Gemfile instead of the individual project Gemfiles. It now runs
This is because Spree::Migrations is detecting the old dummy_app migrations (it assumes the migrations paths instead of checking the app's config.paths as it should). I was able to re-add the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The render_404
change will need a separate PR, but other than that a huge improvement I really like. All concerns addressed 👍
Thanks again John 🐈
@@ -1,7 +1,6 @@ | |||
module Spree | |||
class OrdersController < Spree::StoreController | |||
before_action :check_authorization | |||
rescue_from ActiveRecord::RecordNotFound, with: :render_404 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL config.exceptions_app
🎉
You are right, the code is bad and should be removed. Although it's blocking your PR I think we need a separate PR due to visibility reasons. I think we can forego with deprecating this, though.
This removes the need to run rake test_app. Instead, we have a checked in single-file Rails application and can re-run migrations when necessary.
This allows running db:reset db:drop and db:create from the top-level solidus directory. This also renames `rake test` to `rake spec` and `rake test_app` to `rake db:reset`, with aliases added for the previous names.
We never want the user to run this directly, instead an extension will have an alias, so this shouldn't have a description to avoid including it in `rake -T`
This hasn't been required here for a long time
We don't need to require rake from a Rakefile, if we have run the Rakefile we can assume that has been done by rake. We don't need thor/group anymore. It was required ages ago when sandbox generation was a part of the top-level Rakefile.
This fixes issues running the new dummy_app based rake tasks at the top level.
It doesn't make sense to put these under "vendor". We aren't maintaining a standard rails structure for this app.
This matches the filename better, and makes it seem less strange to have modules under this namespace (like DummyApp::Migrations)
It's cleaner to call a method (DummyApp::Migrations.auto_migrate) than to expect side effects from requiring that file.
This PR removes the need to run
rake test_app
before running specs. Migrations are automatically run before specs if the database is new or has missing migrations.This is done by adding a checked-in single-file(ish) Rails application requirable at
spree/testing_support/dummy_app
. This replaces the need to generate thespec/dummy
application, and allows us to make changes to the dummy app's configuration and have them apply without re-runningrake test_app
.The
rake test_app
task has been replaced by a newrake db:reset
task, which callsdb:drop
,db:create
, anddb:migrate
as one would expect. Most users will never have to run this, as the spec_helper for each project will detect the need to re-run migrations and automatically runrake db:reset
.test_app
has been kept as an alias fordb:reset
, which will be helpful to keep in the short-term to allow git bisects. Top-level rake tasks have been similarly adjusted.A new
rake console
command opens up a sandboxed (in a transaction) pry console in thetest
environment. I'm hoping this meets most of the needs of developers who would previouslycd
intospec/dummy
and fire uprails c
.Todo:
api
andfrontend
rake test_app
(auto run migrations)