Skip to content

Commit

Permalink
Allow the installer to add solidus_auth_devise
Browse files Browse the repository at this point in the history
There's no need to manually add the gem to the Gemfile.

Rails installer has a `gem` method that does exactly that,
making the installation process easier for new users.

During the first installation it will be asked to users if
they want to install the gem, still making this optional.

This commit also updates Readme, Guides and avoid installing the
plugin in sandbox and rails application template (where it's already
done manually), and when building the test_app (where we don't need it).
  • Loading branch information
kennyadsl committed Mar 9, 2020
1 parent d3be0c4 commit 15fbdc2
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 24 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ created. Add the following to your Gemfile.

```ruby
gem 'solidus'
gem 'solidus_auth_devise'
```

Run the `bundle` command to install.
Expand All @@ -115,7 +114,6 @@ configuration files and migrations.

```bash
bundle exec rails g solidus:install
bundle exec rails g solidus:auth:install
bundle exec rake railties:install:migrations
```

Expand Down
1 change: 1 addition & 0 deletions bin/rails-application-template
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ after_bundle do
"--auto-accept",
"--user_class=Spree::User",
"--enforce_available_locales=true",
"--with-authentication=false",
)

generate('solidus_auth:install')
Expand Down
1 change: 1 addition & 0 deletions bin/sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ unbundled bin/rails generate solidus:install \
--auto-accept \
--user_class=Spree::User \
--enforce_available_locales=true \
--with_authentication=false \
$@

unbundled bin/rails generate solidus:auth:install
Expand Down
12 changes: 12 additions & 0 deletions core/lib/generators/solidus/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class InstallGenerator < Rails::Generators::Base
class_option :admin_email, type: :string
class_option :admin_password, type: :string
class_option :lib_name, type: :string, default: 'spree'
class_option :with_authentication, type: :boolean, default: true
class_option :enforce_available_locales, type: :boolean, default: nil

def self.source_paths
Expand Down Expand Up @@ -111,6 +112,17 @@ def configure_application
end
end

def install_default_plugins
if options[:with_authentication] && (options[:auto_accept] || yes?("
Solidus has a default authentication extension that uses Devise.
You can find more info at github.com/solidusio/solidus_auth_devise.
Would you like to install it? (y/n)"))

gem 'solidus_auth_devise'
end
end

def include_seed_data
append_file "db/seeds.rb", <<-RUBY.strip_heredoc
Expand Down
2 changes: 1 addition & 1 deletion core/lib/spree/testing_support/common_rake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ENV["RAILS_ENV"] = 'test'

Spree::DummyGenerator.start ["--lib_name=#{ENV['LIB_NAME']}", "--quiet"]
Solidus::InstallGenerator.start ["--lib_name=#{ENV['LIB_NAME']}", "--auto-accept", "--migrate=false", "--seed=false", "--sample=false", "--quiet", "--user_class=#{args[:user_class]}"]
Solidus::InstallGenerator.start ["--lib_name=#{ENV['LIB_NAME']}", "--auto-accept", "with-authentication=false", "--migrate=false", "--seed=false", "--sample=false", "--quiet", "--user_class=#{args[:user_class]}"]

puts "Setting up dummy database..."

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ lines:

```ruby
gem 'solidus'
gem 'solidus_auth_devise'
```

By requiring [`solidus`][solidus-repo] in your `Gemfile`, you are actually
Expand Down Expand Up @@ -225,23 +224,6 @@ The default values are as follows:
The password must contain a minimum of 6 characters, or the account creation
will fail without asking the user to try again.

### Prepare Solidus database migrations

Next, you need to run the `solidus:auth:install` generator and install your
database migrations using the following commands:

```bash
bundle exec rails generate solidus:auth:install
bundle exec rake railties:install:migrations
```

Finally, you need to run the migrations that Railties created. This creates the
e-commerce–friendly models that Solidus uses for its database:

```bash
bundle exec rake db:migrate
```

### Start the Rails server and use the sample store

Once the database migrations have been created, you should be able to
Expand All @@ -260,4 +242,4 @@ Once the server has started, you can access your store from the following URLs:
- [https://localhost:3000/admin/](https://localhost:3000/admin/) opens the
[`solidus_backend`][solidus-backend] admin area.

You can browse the sample store's pages and mock products, and so on.
You can browse the sample store's pages and mock products, and so on.
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,36 @@ bundle exec rake db:seed # seeds your database
bundle exec rake spree_sample:load # loads sample data
```

If you use `solidus_auth_devise` for user authentication, you can also install
and run its migrations, then seed the database separately:
## Authentication via Devise

During the installation, you have been prompted to add the default authentication extension
to your project. It is called [`solidus-auth-devise`][solidus-auth-devise] and it uses the
well-known authentication library for Rails called [Devise][devise].

If you answered "yes", there's nothing else left to do. The extension is already
added and installed in your application.

If you don't want to install the default authentication extension, you can answer "no",
or run the Solidus installer with the following command:

```bash
rails generate solidus:install --with-authentication=false
```

If you prefer to install [`solidus-auth-devise`][solidus-auth-devise] gem manually,
after adding it in your Gemfile, you can run the following commands to install and
run its migrations, then seed the database:

```bash
bundle install # install gem and dependencies
bundle exec rake solidus_auth:install:migrations # installs solidus_auth_devise migrations
bundle exec rake db:migrate # runs solidus_auth_devise migrations
bundle exec rake db:seed # seeds your database
```

[solidus-auth-devise]: https://github.com/solidusio/solidus_auth_devise
[devise]: https://github.com/heartcombo/devise

## Development environment performance gains

You may notice that your Solidus store runs slowly in development mode. You can
Expand Down

0 comments on commit 15fbdc2

Please sign in to comment.