graphql_devise 0.11.1 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.rspec +1 -0
- data/.travis.yml +11 -3
- data/CHANGELOG.md +43 -0
- data/README.md +191 -32
- data/app/controllers/graphql_devise/application_controller.rb +4 -1
- data/app/controllers/graphql_devise/concerns/set_user_by_token.rb +23 -0
- data/app/controllers/graphql_devise/graphql_controller.rb +2 -0
- data/app/helpers/graphql_devise/mailer_helper.rb +2 -2
- data/config/locales/en.yml +1 -0
- data/config/routes.rb +14 -7
- data/graphql_devise.gemspec +6 -4
- data/lib/generators/graphql_devise/install_generator.rb +63 -30
- data/lib/graphql_devise.rb +39 -6
- data/lib/graphql_devise/default_operations/mutations.rb +6 -6
- data/lib/graphql_devise/default_operations/resolvers.rb +2 -2
- data/lib/graphql_devise/errors/authentication_error.rb +7 -0
- data/lib/graphql_devise/{detailed_user_error.rb → errors/detailed_user_error.rb} +1 -1
- data/lib/graphql_devise/errors/error_codes.rb +6 -0
- data/lib/graphql_devise/errors/execution_error.rb +4 -0
- data/lib/graphql_devise/{user_error.rb → errors/user_error.rb} +1 -1
- data/lib/graphql_devise/mount_method/operation_preparer.rb +2 -2
- data/lib/graphql_devise/mount_method/operation_preparers/default_operation_preparer.rb +6 -2
- data/lib/graphql_devise/mount_method/operation_preparers/gql_name_setter.rb +1 -1
- data/lib/graphql_devise/mount_method/operation_preparers/mutation_field_setter.rb +3 -2
- data/lib/graphql_devise/mount_method/operation_preparers/resolver_type_setter.rb +1 -1
- data/lib/graphql_devise/mount_method/operation_preparers/resource_name_setter.rb +2 -2
- data/lib/graphql_devise/mutations/resend_confirmation.rb +1 -4
- data/lib/graphql_devise/mutations/send_password_reset.rb +3 -1
- data/lib/graphql_devise/mutations/sign_up.rb +1 -5
- data/lib/graphql_devise/rails/routes.rb +5 -67
- data/lib/graphql_devise/resource_loader.rb +87 -0
- data/lib/graphql_devise/schema_plugin.rb +87 -0
- data/lib/graphql_devise/version.rb +1 -1
- data/spec/dummy/app/controllers/api/v1/graphql_controller.rb +11 -2
- data/spec/dummy/app/controllers/application_controller.rb +1 -0
- data/spec/dummy/app/graphql/dummy_schema.rb +9 -0
- data/spec/dummy/app/graphql/interpreter_schema.rb +9 -0
- data/spec/dummy/app/graphql/types/mutation_type.rb +1 -1
- data/spec/dummy/app/graphql/types/query_type.rb +10 -0
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/config/routes.rb +1 -0
- data/spec/generators/graphql_devise/install_generator_spec.rb +62 -30
- data/spec/rails_helper.rb +4 -1
- data/spec/requests/graphql_controller_spec.rb +80 -0
- data/spec/requests/mutations/resend_confirmation_spec.rb +2 -14
- data/spec/requests/mutations/send_password_reset_spec.rb +8 -3
- data/spec/requests/user_controller_spec.rb +180 -24
- data/spec/services/mount_method/operation_preparer_spec.rb +8 -3
- data/spec/services/mount_method/operation_preparers/custom_operation_preparer_spec.rb +1 -1
- data/spec/services/mount_method/operation_preparers/default_operation_preparer_spec.rb +15 -8
- data/spec/services/mount_method/operation_preparers/mutation_field_setter_spec.rb +18 -4
- data/spec/services/mount_method/operation_preparers/resource_name_setter_spec.rb +1 -1
- data/spec/services/resource_loader_spec.rb +82 -0
- data/spec/services/schema_plugin_spec.rb +26 -0
- data/spec/spec_helper.rb +1 -1
- metadata +107 -89
- data/lib/graphql_devise/error_codes.rb +0 -5
- data/spec/support/generators/file_helpers.rb +0 -12
@@ -22,10 +22,7 @@ module GraphqlDevise
|
|
22
22
|
template_path: ['graphql_devise/mailer']
|
23
23
|
)
|
24
24
|
|
25
|
-
{
|
26
|
-
authenticatable: resource,
|
27
|
-
message: I18n.t('graphql_devise.confirmations.send_instructions', email: email)
|
28
|
-
}
|
25
|
+
{ message: I18n.t('graphql_devise.confirmations.send_instructions', email: email) }
|
29
26
|
else
|
30
27
|
raise_user_error(I18n.t('graphql_devise.confirmations.user_not_found', email: email))
|
31
28
|
end
|
@@ -4,6 +4,8 @@ module GraphqlDevise
|
|
4
4
|
argument :email, String, required: true
|
5
5
|
argument :redirect_url, String, required: true
|
6
6
|
|
7
|
+
field :message, String, null: false
|
8
|
+
|
7
9
|
def resolve(email:, redirect_url:)
|
8
10
|
resource = find_resource(:email, get_case_insensitive_field(:email, email))
|
9
11
|
|
@@ -18,7 +20,7 @@ module GraphqlDevise
|
|
18
20
|
)
|
19
21
|
|
20
22
|
if resource.errors.empty?
|
21
|
-
{
|
23
|
+
{ message: I18n.t('graphql_devise.passwords.send_instructions') }
|
22
24
|
else
|
23
25
|
raise_user_error_list(I18n.t('graphql_devise.invalid_resource'), errors: resource.errors.full_messages)
|
24
26
|
end
|
@@ -35,7 +35,7 @@ module GraphqlDevise
|
|
35
35
|
|
36
36
|
{ authenticatable: resource }
|
37
37
|
else
|
38
|
-
clean_up_passwords
|
38
|
+
resource.try(:clean_up_passwords)
|
39
39
|
raise_user_error_list(
|
40
40
|
I18n.t('graphql_devise.registration_failed'),
|
41
41
|
errors: resource.errors.full_messages
|
@@ -48,10 +48,6 @@ module GraphqlDevise
|
|
48
48
|
def build_resource(attrs)
|
49
49
|
resource_class.new(attrs)
|
50
50
|
end
|
51
|
-
|
52
|
-
def clean_up_passwords(resource)
|
53
|
-
controller.send(:clean_up_passwords, resource)
|
54
|
-
end
|
55
51
|
end
|
56
52
|
end
|
57
53
|
end
|
@@ -1,75 +1,13 @@
|
|
1
1
|
module ActionDispatch::Routing
|
2
2
|
class Mapper
|
3
|
-
DEVISE_OPERATIONS = [
|
4
|
-
:sessions,
|
5
|
-
:registrations,
|
6
|
-
:passwords,
|
7
|
-
:confirmations,
|
8
|
-
:omniauth_callbacks,
|
9
|
-
:unlocks,
|
10
|
-
:invitations
|
11
|
-
].freeze
|
12
|
-
|
13
3
|
def mount_graphql_devise_for(resource, options = {})
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
clean_options = GraphqlDevise::MountMethod::OptionSanitizer.new(options).call!
|
18
|
-
|
19
|
-
GraphqlDevise::MountMethod::OptionsValidator.new(
|
20
|
-
[
|
21
|
-
GraphqlDevise::MountMethod::OptionValidators::SkipOnlyValidator.new(options: clean_options),
|
22
|
-
GraphqlDevise::MountMethod::OptionValidators::ProvidedOperationsValidator.new(
|
23
|
-
options: clean_options, supported_operations: default_operations
|
24
|
-
)
|
25
|
-
]
|
26
|
-
).validate!
|
27
|
-
|
28
|
-
authenticatable_type = clean_options.authenticatable_type.presence ||
|
29
|
-
"Types::#{resource}Type".safe_constantize ||
|
30
|
-
GraphqlDevise::Types::AuthenticatableType
|
31
|
-
|
32
|
-
devise_for(
|
33
|
-
resource.pluralize.underscore.tr('/', '_').to_sym,
|
34
|
-
module: :devise,
|
35
|
-
class_name: resource,
|
36
|
-
skip: DEVISE_OPERATIONS
|
4
|
+
clean_options = GraphqlDevise::ResourceLoader.new(resource, options, true).call(
|
5
|
+
GraphqlDevise::Types::QueryType,
|
6
|
+
GraphqlDevise::Types::MutationType
|
37
7
|
)
|
38
8
|
|
39
|
-
|
40
|
-
|
41
|
-
custom: clean_options.operations,
|
42
|
-
additional_operations: clean_options.additional_mutations,
|
43
|
-
preparer: GraphqlDevise::MountMethod::OperationPreparers::MutationFieldSetter.new(authenticatable_type),
|
44
|
-
selected_operations: GraphqlDevise::MountMethod::OperationSanitizer.call(
|
45
|
-
default: GraphqlDevise::DefaultOperations::MUTATIONS, only: clean_options.only, skipped: clean_options.skip
|
46
|
-
)
|
47
|
-
).call
|
48
|
-
|
49
|
-
prepared_mutations.each do |action, mutation|
|
50
|
-
GraphqlDevise::Types::MutationType.field(action, mutation: mutation)
|
51
|
-
end
|
52
|
-
|
53
|
-
prepared_queries = GraphqlDevise::MountMethod::OperationPreparer.new(
|
54
|
-
resource: resource,
|
55
|
-
custom: clean_options.operations,
|
56
|
-
additional_operations: clean_options.additional_queries,
|
57
|
-
preparer: GraphqlDevise::MountMethod::OperationPreparers::ResolverTypeSetter.new(authenticatable_type),
|
58
|
-
selected_operations: GraphqlDevise::MountMethod::OperationSanitizer.call(
|
59
|
-
default: GraphqlDevise::DefaultOperations::QUERIES, only: clean_options.only, skipped: clean_options.skip
|
60
|
-
)
|
61
|
-
).call
|
62
|
-
|
63
|
-
prepared_queries.each do |action, resolver|
|
64
|
-
GraphqlDevise::Types::QueryType.field(action, resolver: resolver)
|
65
|
-
end
|
66
|
-
|
67
|
-
Devise.mailer.helper(GraphqlDevise::MailerHelper)
|
68
|
-
|
69
|
-
devise_scope resource.underscore.tr('/', '_').to_sym do
|
70
|
-
post clean_options.at, to: 'graphql_devise/graphql#auth'
|
71
|
-
get clean_options.at, to: 'graphql_devise/graphql#auth'
|
72
|
-
end
|
9
|
+
post clean_options.at, to: 'graphql_devise/graphql#auth'
|
10
|
+
get clean_options.at, to: 'graphql_devise/graphql#auth'
|
73
11
|
end
|
74
12
|
end
|
75
13
|
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module GraphqlDevise
|
2
|
+
class ResourceLoader
|
3
|
+
def initialize(resource, options = {}, routing = false)
|
4
|
+
@resource = resource
|
5
|
+
@options = options
|
6
|
+
@routing = routing
|
7
|
+
@default_operations = GraphqlDevise::DefaultOperations::MUTATIONS.merge(GraphqlDevise::DefaultOperations::QUERIES)
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(query, mutation)
|
11
|
+
mapping_name = @resource.to_s.underscore.tr('/', '_').to_sym
|
12
|
+
|
13
|
+
# clean_options responds to all keys defined in GraphqlDevise::MountMethod::SUPPORTED_OPTIONS
|
14
|
+
clean_options = GraphqlDevise::MountMethod::OptionSanitizer.new(@options).call!
|
15
|
+
|
16
|
+
return clean_options if GraphqlDevise.resource_mounted?(mapping_name) && @routing
|
17
|
+
|
18
|
+
validate_options!(clean_options)
|
19
|
+
|
20
|
+
authenticatable_type = clean_options.authenticatable_type.presence ||
|
21
|
+
"Types::#{@resource}Type".safe_constantize ||
|
22
|
+
GraphqlDevise::Types::AuthenticatableType
|
23
|
+
|
24
|
+
prepared_mutations = prepare_mutations(mapping_name, clean_options, authenticatable_type)
|
25
|
+
|
26
|
+
if prepared_mutations.any? && mutation.blank?
|
27
|
+
raise GraphqlDevise::Error, 'You need to provide a mutation type unless all mutations are skipped'
|
28
|
+
end
|
29
|
+
|
30
|
+
prepared_mutations.each do |action, prepared_mutation|
|
31
|
+
mutation.field(action, mutation: prepared_mutation, authenticate: false)
|
32
|
+
end
|
33
|
+
|
34
|
+
prepared_resolvers = prepare_resolvers(mapping_name, clean_options, authenticatable_type)
|
35
|
+
|
36
|
+
if prepared_resolvers.any? && query.blank?
|
37
|
+
raise GraphqlDevise::Error, 'You need to provide a query type unless all queries are skipped'
|
38
|
+
end
|
39
|
+
|
40
|
+
prepared_resolvers.each do |action, resolver|
|
41
|
+
query.field(action, resolver: resolver, authenticate: false)
|
42
|
+
end
|
43
|
+
|
44
|
+
GraphqlDevise.add_mapping(mapping_name, @resource)
|
45
|
+
GraphqlDevise.mount_resource(mapping_name) if @routing
|
46
|
+
|
47
|
+
clean_options
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def prepare_resolvers(mapping_name, clean_options, authenticatable_type)
|
53
|
+
GraphqlDevise::MountMethod::OperationPreparer.new(
|
54
|
+
mapping_name: mapping_name,
|
55
|
+
custom: clean_options.operations,
|
56
|
+
additional_operations: clean_options.additional_queries,
|
57
|
+
preparer: GraphqlDevise::MountMethod::OperationPreparers::ResolverTypeSetter.new(authenticatable_type),
|
58
|
+
selected_operations: GraphqlDevise::MountMethod::OperationSanitizer.call(
|
59
|
+
default: GraphqlDevise::DefaultOperations::QUERIES, only: clean_options.only, skipped: clean_options.skip
|
60
|
+
)
|
61
|
+
).call
|
62
|
+
end
|
63
|
+
|
64
|
+
def prepare_mutations(mapping_name, clean_options, authenticatable_type)
|
65
|
+
GraphqlDevise::MountMethod::OperationPreparer.new(
|
66
|
+
mapping_name: mapping_name,
|
67
|
+
custom: clean_options.operations,
|
68
|
+
additional_operations: clean_options.additional_mutations,
|
69
|
+
preparer: GraphqlDevise::MountMethod::OperationPreparers::MutationFieldSetter.new(authenticatable_type),
|
70
|
+
selected_operations: GraphqlDevise::MountMethod::OperationSanitizer.call(
|
71
|
+
default: GraphqlDevise::DefaultOperations::MUTATIONS, only: clean_options.only, skipped: clean_options.skip
|
72
|
+
)
|
73
|
+
).call
|
74
|
+
end
|
75
|
+
|
76
|
+
def validate_options!(clean_options)
|
77
|
+
GraphqlDevise::MountMethod::OptionsValidator.new(
|
78
|
+
[
|
79
|
+
GraphqlDevise::MountMethod::OptionValidators::SkipOnlyValidator.new(options: clean_options),
|
80
|
+
GraphqlDevise::MountMethod::OptionValidators::ProvidedOperationsValidator.new(
|
81
|
+
options: clean_options, supported_operations: @default_operations
|
82
|
+
)
|
83
|
+
]
|
84
|
+
).validate!
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module GraphqlDevise
|
2
|
+
class SchemaPlugin
|
3
|
+
DEFAULT_NOT_AUTHENTICATED = ->(field) { raise GraphqlDevise::AuthenticationError, "#{field} field requires authentication" }
|
4
|
+
|
5
|
+
def initialize(query: nil, mutation: nil, authenticate_default: true, resource_loaders: [], unauthenticated_proc: DEFAULT_NOT_AUTHENTICATED)
|
6
|
+
@query = query
|
7
|
+
@mutation = mutation
|
8
|
+
@resource_loaders = resource_loaders
|
9
|
+
@authenticate_default = authenticate_default
|
10
|
+
@unauthenticated_proc = unauthenticated_proc
|
11
|
+
|
12
|
+
# Must happen on initialize so operations are loaded before the types are added to the schema on GQL < 1.10
|
13
|
+
load_fields
|
14
|
+
end
|
15
|
+
|
16
|
+
def use(schema_definition)
|
17
|
+
schema_definition.tracer(self)
|
18
|
+
end
|
19
|
+
|
20
|
+
def trace(event, trace_data)
|
21
|
+
# Authenticate only root level queries
|
22
|
+
return yield unless event == 'execute_field' && path(trace_data).count == 1
|
23
|
+
|
24
|
+
field = traced_field(trace_data)
|
25
|
+
provided_value = authenticate_option(field, trace_data)
|
26
|
+
|
27
|
+
if !provided_value.nil?
|
28
|
+
raise_on_missing_resource(context(trace_data), field) if provided_value
|
29
|
+
elsif @authenticate_default
|
30
|
+
raise_on_missing_resource(context(trace_data), field)
|
31
|
+
end
|
32
|
+
|
33
|
+
yield
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def raise_on_missing_resource(context, field)
|
39
|
+
@unauthenticated_proc.call(field.name) if context[:current_resource].blank?
|
40
|
+
end
|
41
|
+
|
42
|
+
def context(trace_data)
|
43
|
+
query = if trace_data[:context]
|
44
|
+
trace_data[:context].query
|
45
|
+
else
|
46
|
+
trace_data[:query]
|
47
|
+
end
|
48
|
+
|
49
|
+
query.context
|
50
|
+
end
|
51
|
+
|
52
|
+
def path(trace_data)
|
53
|
+
if trace_data[:context]
|
54
|
+
trace_data[:context].path
|
55
|
+
else
|
56
|
+
trace_data[:path]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def traced_field(trace_data)
|
61
|
+
if trace_data[:context]
|
62
|
+
trace_data[:context].field
|
63
|
+
else
|
64
|
+
trace_data[:field]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def authenticate_option(field, trace_data)
|
69
|
+
if trace_data[:context]
|
70
|
+
field.metadata[:authenticate]
|
71
|
+
else
|
72
|
+
field.graphql_definition.metadata[:authenticate]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def load_fields
|
77
|
+
@resource_loaders.each do |resource_loader|
|
78
|
+
raise Error, 'Invalid resource loader instance' unless resource_loader.instance_of?(GraphqlDevise::ResourceLoader)
|
79
|
+
|
80
|
+
resource_loader.call(@query, @mutation)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
GraphQL::Field.accepts_definitions(authenticate: GraphQL::Define.assign_metadata_key(:authenticate))
|
87
|
+
GraphQL::Schema::Field.accepts_definition(:authenticate)
|
@@ -3,10 +3,19 @@ module Api
|
|
3
3
|
class GraphqlController < ApplicationController
|
4
4
|
include GraphqlDevise::Concerns::SetUserByToken
|
5
5
|
|
6
|
-
before_action :
|
6
|
+
before_action -> { set_resource_by_token(:user) }
|
7
7
|
|
8
8
|
def graphql
|
9
|
-
render json: DummySchema.execute(params[:query])
|
9
|
+
render json: DummySchema.execute(params[:query], context: graphql_context)
|
10
|
+
end
|
11
|
+
|
12
|
+
def interpreter
|
13
|
+
render json: InterpreterSchema.execute(params[:query], context: graphql_context)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def verify_authenticity_token
|
10
19
|
end
|
11
20
|
end
|
12
21
|
end
|
@@ -1,4 +1,13 @@
|
|
1
1
|
class DummySchema < GraphQL::Schema
|
2
|
+
use GraphqlDevise::SchemaPlugin.new(
|
3
|
+
query: Types::QueryType,
|
4
|
+
mutation: Types::MutationType,
|
5
|
+
resource_loaders: [
|
6
|
+
GraphqlDevise::ResourceLoader.new('User', only: [:login, :confirm_account]),
|
7
|
+
GraphqlDevise::ResourceLoader.new('Guest', only: [:logout])
|
8
|
+
]
|
9
|
+
)
|
10
|
+
|
2
11
|
mutation(Types::MutationType)
|
3
12
|
query(Types::QueryType)
|
4
13
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class InterpreterSchema < GraphQL::Schema
|
2
|
+
use GraphQL::Execution::Interpreter if Gem::Version.new(GraphQL::VERSION) >= Gem::Version.new('1.9.0')
|
3
|
+
use GraphQL::Analysis::AST if Gem::Version.new(GraphQL::VERSION) >= Gem::Version.new('1.10.0')
|
4
|
+
|
5
|
+
use GraphqlDevise::SchemaPlugin.new(query: Types::QueryType, authenticate_default: false)
|
6
|
+
|
7
|
+
mutation(Types::MutationType)
|
8
|
+
query(Types::QueryType)
|
9
|
+
end
|
@@ -1,5 +1,15 @@
|
|
1
1
|
module Types
|
2
2
|
class QueryType < Types::BaseObject
|
3
3
|
field :user, resolver: Resolvers::UserShow
|
4
|
+
field :public_field, String, null: false, authenticate: false
|
5
|
+
field :private_field, String, null: false, authenticate: true
|
6
|
+
|
7
|
+
def public_field
|
8
|
+
'Field does not require authentication'
|
9
|
+
end
|
10
|
+
|
11
|
+
def private_field
|
12
|
+
'Field will always require authentication'
|
13
|
+
end
|
4
14
|
end
|
5
15
|
end
|
@@ -10,7 +10,7 @@ Rails.application.configure do
|
|
10
10
|
# Do not eager load code on boot. This avoids loading your whole application
|
11
11
|
# just for the purpose of running a single test. If you are using a tool that
|
12
12
|
# preloads Rails for running tests, you may have to set it to true.
|
13
|
-
config.eager_load =
|
13
|
+
config.eager_load = ENV['EAGER_LOAD'].present?
|
14
14
|
|
15
15
|
# Configure public file server for tests with Cache-Control for performance.
|
16
16
|
if Rails::VERSION::MAJOR >= 5
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -3,50 +3,82 @@ require 'rails_helper'
|
|
3
3
|
require 'generators/graphql_devise/install_generator'
|
4
4
|
|
5
5
|
RSpec.describe GraphqlDevise::InstallGenerator, type: :generator do
|
6
|
-
destination File.expand_path('
|
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
|
16
|
+
create_rails_project
|
17
|
+
run_generator(args)
|
10
18
|
end
|
11
19
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
)
|
22
|
-
end
|
20
|
+
context 'when mount option is schema' do
|
21
|
+
let(:args) { ['Admin', '--mount', 'GqldDummySchema'] }
|
22
|
+
|
23
|
+
it 'mounts the SchemaPlugin' do
|
24
|
+
assert_file 'config/initializers/devise.rb'
|
25
|
+
assert_file 'config/initializers/devise_token_auth.rb', /^\s{2}#{Regexp.escape('config.change_headers_on_each_request = false')}/
|
26
|
+
assert_file 'config/locales/devise.en.yml'
|
27
|
+
|
28
|
+
assert_migration 'db/migrate/devise_token_auth_create_admins.rb'
|
23
29
|
|
24
|
-
|
25
|
-
before { run_generator }
|
30
|
+
assert_file 'app/models/admin.rb', /^\s{2}devise :.+include GraphqlDevise::Concerns::Model/m
|
26
31
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
expect(routes_content).not_to match(dta_route)
|
31
|
-
end
|
32
|
+
assert_file 'app/controllers/application_controller.rb', /^\s{2}include GraphqlDevise::Concerns::SetUserByToken/
|
33
|
+
|
34
|
+
assert_file 'app/graphql/gqld_dummy_schema.rb', /\s+#{Regexp.escape("GraphqlDevise::ResourceLoader.new('Admin')")}/
|
32
35
|
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when passing no params to the generator' do
|
39
|
+
let(:args) { [] }
|
33
40
|
|
34
|
-
|
35
|
-
|
41
|
+
it 'creates and updated required files' do
|
42
|
+
assert_file 'config/routes.rb', /^\s{2}mount_graphql_devise_for 'User', at: 'auth'/
|
43
|
+
expect(routes_content).not_to match(dta_route)
|
36
44
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
45
|
+
assert_file 'config/initializers/devise.rb'
|
46
|
+
assert_file 'config/initializers/devise_token_auth.rb', /^\s{2}#{Regexp.escape('config.change_headers_on_each_request = false')}/
|
47
|
+
assert_file 'config/locales/devise.en.yml'
|
48
|
+
|
49
|
+
assert_migration 'db/migrate/devise_token_auth_create_users.rb'
|
50
|
+
|
51
|
+
assert_file 'app/models/user.rb', /^\s{2}devise :.+include GraphqlDevise::Concerns::Model/m
|
52
|
+
|
53
|
+
assert_file 'app/controllers/application_controller.rb', /^\s{2}include GraphqlDevise::Concerns::SetUserByToken/
|
42
54
|
end
|
43
55
|
end
|
44
56
|
|
45
|
-
|
46
|
-
|
57
|
+
context 'when passing custom params to the generator' do
|
58
|
+
let(:args) { %w[Admin api] }
|
59
|
+
|
60
|
+
it 'creates and updated required files' do
|
61
|
+
assert_file 'config/routes.rb', /^\s{2}mount_graphql_devise_for 'Admin', at: 'api'/
|
62
|
+
expect(routes_content).not_to match(dta_route)
|
63
|
+
|
64
|
+
assert_file 'config/initializers/devise.rb'
|
65
|
+
assert_file 'config/initializers/devise_token_auth.rb', /^\s{2}#{Regexp.escape('config.change_headers_on_each_request = false')}/
|
66
|
+
assert_file 'config/locales/devise.en.yml'
|
67
|
+
|
68
|
+
assert_migration 'db/migrate/devise_token_auth_create_admins.rb'
|
47
69
|
|
48
|
-
|
49
|
-
|
70
|
+
assert_file 'app/models/admin.rb', /^\s{2}devise :.+include GraphqlDevise::Concerns::Model/m
|
71
|
+
|
72
|
+
assert_file 'app/controllers/application_controller.rb', /^\s{2}include GraphqlDevise::Concerns::SetUserByToken/
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def create_rails_project
|
77
|
+
FileUtils.cd(File.join(destination_root, '..')) do
|
78
|
+
`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`
|
79
|
+
end
|
80
|
+
FileUtils.cd(File.join(destination_root, '../gqld_dummy')) do
|
81
|
+
`rails generate graphql:install`
|
50
82
|
end
|
51
83
|
end
|
52
84
|
end
|