mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Tweak no ORM check on InstallGenerator
.
* Expand the explanation of why it fail. * Raise a subclass of `Thor::Error` so the Thor doesn't output the exception backtrace as it isn't useful for developers facing this error.
This commit is contained in:
parent
0c46373c20
commit
c228227bc1
2 changed files with 23 additions and 6 deletions
|
@ -3,6 +3,8 @@ require 'securerandom'
|
|||
|
||||
module Devise
|
||||
module Generators
|
||||
MissingORMError = Class.new(Thor::Error)
|
||||
|
||||
class InstallGenerator < Rails::Generators::Base
|
||||
source_root File.expand_path("../../templates", __FILE__)
|
||||
|
||||
|
@ -10,7 +12,19 @@ module Devise
|
|||
class_option :orm
|
||||
|
||||
def copy_initializer
|
||||
raise "An ORM must be set to install Devise" unless options[:orm]
|
||||
unless options[:orm]
|
||||
raise MissingORMError, <<-ERROR.strip_heredoc
|
||||
An ORM must be set to install Devise in your application.
|
||||
|
||||
Be sure to have an ORM like Active Record or Mongoid loaded in your
|
||||
app or configure your own at `config/application.rb`.
|
||||
|
||||
config.generators do |g|
|
||||
g.orm :your_orm_gem
|
||||
end
|
||||
ERROR
|
||||
end
|
||||
|
||||
template "devise.rb", "config/initializers/devise.rb"
|
||||
end
|
||||
|
||||
|
|
|
@ -5,17 +5,20 @@ class InstallGeneratorTest < Rails::Generators::TestCase
|
|||
destination File.expand_path("../../tmp", __FILE__)
|
||||
setup :prepare_destination
|
||||
|
||||
test "Assert all files are properly created" do
|
||||
run_generator(['--orm=active_record'])
|
||||
test "assert all files are properly created" do
|
||||
run_generator(["--orm=active_record"])
|
||||
assert_file "config/initializers/devise.rb", /devise\/orm\/active_record/
|
||||
assert_file "config/locales/devise.en.yml"
|
||||
end
|
||||
|
||||
test "Fail if no ORM is specified" do
|
||||
error = assert_raises RuntimeError do
|
||||
test "fails if no ORM is specified" do
|
||||
stderr = capture(:stderr) do
|
||||
run_generator
|
||||
end
|
||||
|
||||
assert_match /An ORM must be set to install Devise/, error.message
|
||||
assert_match %r{An ORM must be set to install Devise}, stderr
|
||||
|
||||
assert_no_file "config/initializers/devise.rb"
|
||||
assert_no_file "config/locales/devise.en.yml"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue