|
3 | 3 | require 'generators/graphql_devise/install_generator' |
4 | 4 |
|
5 | 5 | RSpec.describe GraphqlDevise::InstallGenerator, type: :generator do |
6 | | - destination File.expand_path('../../../../dummy', __dir__) |
| 6 | + destination File.expand_path('../../../../gqld_dummy', __dir__) |
| 7 | + |
| 8 | + let(:routes_path) { "#{destination_root}/config/routes.rb" } |
| 9 | + let(:routes_content) { File.read(routes_path) } |
| 10 | + let(:dta_route) { 'mount_devise_token_auth_for' } |
| 11 | + |
| 12 | + after(:all) { FileUtils.rm_rf(destination_root) } |
7 | 13 |
|
8 | 14 | before do |
9 | 15 | prepare_destination |
10 | 16 | create_rails_project |
| 17 | + run_generator(args) |
11 | 18 | end |
12 | 19 |
|
13 | | - let(:routes_path) { "#{destination_root}/config/routes.rb" } |
14 | | - let(:routes_content) { File.read(routes_path) } |
15 | | - let(:dta_route) { 'mount_devise_token_auth_for' } |
16 | | - |
17 | 20 | context 'when passing no params to the generator' do |
18 | | - before { run_generator } |
| 21 | + let(:args) { [] } |
19 | 22 |
|
20 | 23 | it 'creates and updated required files' do |
21 | | - assert_file 'config/routes.rb', /\s{2,}mount_graphql_devise_for 'User', at: 'auth'/ |
| 24 | + assert_file 'config/routes.rb', /^\s{2}mount_graphql_devise_for 'User', at: 'auth'/ |
22 | 25 | expect(routes_content).not_to match(dta_route) |
23 | 26 |
|
24 | 27 | assert_file 'config/initializers/devise.rb' |
25 | 28 | assert_file 'config/initializers/devise_token_auth.rb' |
| 29 | + assert_file 'config/locales/devise.en.yml' |
| 30 | + |
| 31 | + assert_migration 'db/migrate/devise_token_auth_create_users.rb' |
| 32 | + |
| 33 | + assert_file 'app/models/user.rb', /^\s{2}devise :.+include GraphqlDevise::Concerns::Model/m |
| 34 | + |
| 35 | + assert_file 'app/controllers/application_controller.rb', /^\s{2}include GraphqlDevise::Concerns::SetUserByToken/ |
26 | 36 | end |
27 | 37 | end |
28 | 38 |
|
29 | 39 | context 'when passing custom params to the generator' do |
30 | | - before { run_generator %w[Admin api] } |
| 40 | + let(:args) { %w[Admin api] } |
31 | 41 |
|
32 | 42 | it 'creates and updated required files' do |
33 | | - assert_file 'config/routes.rb', /\s{2,}mount_graphql_devise_for 'Admin', at: 'api'/ |
| 43 | + assert_file 'config/routes.rb', /^\s{2}mount_graphql_devise_for 'Admin', at: 'api'/ |
34 | 44 | expect(routes_content).not_to match(dta_route) |
35 | 45 |
|
36 | 46 | assert_file 'config/initializers/devise.rb' |
37 | 47 | assert_file 'config/initializers/devise_token_auth.rb' |
| 48 | + assert_file 'config/locales/devise.en.yml' |
| 49 | + |
| 50 | + assert_migration 'db/migrate/devise_token_auth_create_admins.rb' |
| 51 | + |
| 52 | + assert_file 'app/models/admin.rb', /^\s{2}devise :.+include GraphqlDevise::Concerns::Model/m |
| 53 | + |
| 54 | + assert_file 'app/controllers/application_controller.rb', /^\s{2}include GraphqlDevise::Concerns::SetUserByToken/ |
38 | 55 | end |
39 | 56 | end |
40 | 57 |
|
41 | 58 | def create_rails_project |
42 | 59 | FileUtils.cd(File.join(destination_root, '..')) do |
43 | | - `rails new dummy -S -C --skip-action-mailbox --skip-action-text -T --skip-spring --skip-bundle --skip-keeps -G --skip-active-storage -J --skip-listen --skip-bootsnap` |
| 60 | + `rails new gqld_dummy -S -C --skip-action-mailbox --skip-action-text -T --skip-spring --skip-bundle --skip-keeps -G --skip-active-storage -J --skip-listen --skip-bootsnap` |
44 | 61 | end |
45 | 62 | end |
46 | 63 | end |
0 commit comments