Class: HappySeed::Generators::DeviseGenerator

Inherits:
HappySeedGenerator
  • Object
show all
Defined in:
lib/generators/happy_seed/devise/devise_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fingerprintObject



9
10
11
# File 'lib/generators/happy_seed/devise/devise_generator.rb', line 9

def self.fingerprint
  gem_available? 'devise'
end

Instance Method Details

#install_deviseObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/generators/happy_seed/devise/devise_generator.rb', line 13

def install_devise
  return if already_installed

  require_generator BootstrapGenerator

  gem 'devise', '~> 3.4'

  Bundler.with_clean_env do
    run "bundle install --without production"
  end

  run 'bin/spring stop'

  puts "Devise: #{self.class.fingerprint}"

  Bundler.with_clean_env do
    run 'rails generate devise:install'
    run 'rails generate devise User'
    run 'rails generate devise:views'
  end
          
  if gem_available?( "haml-rails" )
    remove_file 'app/views/devise/registrations/new.html.erb'
    remove_file 'app/views/devise/registrations/edit.html.erb'
    remove_file 'app/views/devise/sessions/new.html.erb'
    remove_file 'app/views/devise/passwords/edit.html.erb'
    remove_file 'app/views/devise/passwords/new.html.erb'
  end

  remove_file "spec/factories/users.rb"
  
  begin
    prepend_to_file 'spec/spec_helper.rb', "require 'devise'\n"
    prepend_to_file 'spec/spec_helper.rb', "require_relative 'support/controller_helpers'\n"
    inject_into_file 'spec/spec_helper.rb', "\n  config.include Devise::TestHelpers, type: :controller\n", :before => "\nend\n"
    inject_into_file 'spec/spec_helper.rb', "\n  config.include Warden::Test::Helpers, type: :feature\n  config.include ControllerHelpers, type: :controller\n  Warden.test_mode!\n", :before => "\nend\n"
  rescue
    say_status :spec, "Unable to add devise helpers to spec_helper.rb", :red
  end

  begin
    inject_into_file 'spec/rails_helper.rb', "\n  config.include Devise::TestHelpers, type: :controller\n  config.include Warden::Test::Helpers, type: :feature\n", :after => "FactoryGirl::Syntax::Methods\n"
  rescue
    say_status :spec, "Unable to add devise helpers to rails_helper.rb", :red
  end

  append_to_file "features/support/env.rb", "
Warden.test_mode! 
World(Warden::Test::Helpers)
After{ Warden.test_reset! }"

  directory 'app'
  directory 'docs'
  directory 'test'
  directory 'spec'

  application(nil, env: "development") do
    "config.action_mailer.default_url_options = { host: 'localhost:3000' }"
  end

  application(nil, env: "test") do
    "config.action_mailer.default_url_options = { host: 'localhost:3000' }"
  end

  if File.exists?( File.join( destination_root, 'app/views/application/_header.html.haml' ) )
    gsub_file 'app/views/application/_header.html.haml', "/ USER NAV", '= render partial: "application/account_dropdown"'
  else
    say_status :gsub_file, "Can't find application/_header.html.haml, skipping"
  end
end