|
3 | 3 | require 'generators/graphql_devise/install_generator' |
4 | 4 |
|
5 | 5 | RSpec.describe GraphqlDevise::InstallGenerator, type: :generator do |
6 | | - destination File.expand_path('../../../tmp/dummy', __dir__) |
| 6 | + destination File.expand_path('../../../../dummy', __dir__) |
7 | 7 |
|
8 | 8 | before do |
9 | 9 | prepare_destination |
10 | | - copy_rails_bin |
| 10 | + create_rails_project |
11 | 11 | end |
12 | 12 |
|
13 | 13 | let(:routes_path) { "#{destination_root}/config/routes.rb" } |
14 | 14 | let(:routes_content) { File.read(routes_path) } |
15 | | - let(:dta_route) { "mount_devise_token_auth_for 'User', at: 'auth'" } |
16 | | - |
17 | | - context 'when the file exists' do |
18 | | - before do |
19 | | - create_file_with_content( |
20 | | - routes_path, |
21 | | - "Rails.application.routes.draw do\n#{dta_route}\nend" |
22 | | - ) |
23 | | - end |
24 | | - |
25 | | - context 'when passing no params to the generator' do |
26 | | - before { run_generator } |
| 15 | + let(:dta_route) { 'mount_devise_token_auth_for' } |
27 | 16 |
|
28 | | - it 'replaces dta route using the default values for class and path' do |
29 | | - generator_added_route = / mount_graphql_devise_for 'User', at: 'auth'/ |
30 | | - expect(routes_content).to match(generator_added_route) |
31 | | - expect(routes_content).not_to match(dta_route) |
32 | | - end |
33 | | - end |
| 17 | + context 'when passing no params to the generator' do |
| 18 | + before { run_generator } |
34 | 19 |
|
35 | | - context 'when passing custom params to the generator' do |
36 | | - before { run_generator %w[Admin api] } |
| 20 | + it 'creates and updated required files' do |
| 21 | + assert_file 'config/routes.rb', /\s{2,}mount_graphql_devise_for 'User', at: 'auth'/ |
| 22 | + expect(routes_content).not_to match(dta_route) |
37 | 23 |
|
38 | | - it 'add the routes using the provided values for class and path and keeps dta route' do |
39 | | - generator_added_route = / mount_graphql_devise_for 'Admin', at: 'api'/ |
40 | | - expect(routes_content).to match(generator_added_route) |
41 | | - expect(routes_content).to match(dta_route) |
42 | | - end |
| 24 | + assert_file 'config/initializers/devise.rb' |
| 25 | + assert_file 'config/initializers/devise_token_auth.rb' |
43 | 26 | end |
44 | 27 | end |
45 | 28 |
|
46 | | - context 'when file does *NOT* exist' do |
47 | | - before { run_generator } |
| 29 | + context 'when passing custom params to the generator' do |
| 30 | + before { run_generator %w[Admin api] } |
| 31 | + |
| 32 | + it 'creates and updated required files' do |
| 33 | + assert_file 'config/routes.rb', /\s{2,}mount_graphql_devise_for 'Admin', at: 'api'/ |
| 34 | + expect(routes_content).not_to match(dta_route) |
48 | 35 |
|
49 | | - it 'does *NOT* create the file and throw no exception' do |
50 | | - expect(File).not_to exist(routes_path) |
| 36 | + assert_file 'config/initializers/devise.rb' |
| 37 | + assert_file 'config/initializers/devise_token_auth.rb' |
51 | 38 | end |
52 | 39 | end |
53 | 40 |
|
54 | | - def copy_rails_bin |
55 | | - FileUtils.mkdir_p(File.join(destination_root, 'bin')) |
56 | | - FileUtils.copy_file('spec/fixtures/rails', File.join(destination_root, 'bin/rails')) |
| 41 | + def create_rails_project |
| 42 | + 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` |
| 44 | + end |
57 | 45 | end |
58 | 46 | end |
0 commit comments