Skip to content

Commit

Permalink
Merge pull request #16 from o2web/test-suite
Browse files Browse the repository at this point in the history
Add test suite
  • Loading branch information
ferland182 authored Feb 21, 2019
2 parents 1c52169 + 5b627ea commit d29f583
Show file tree
Hide file tree
Showing 102 changed files with 1,807 additions and 94 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,15 @@
/pkg/
/spec/reports/
/tmp/
.DS_Store

spec/dummy/db/*.sqlite3
spec/dummy/db/*.sqlite3-journal
spec/dummy/log/*.log
spec/dummy/node_modules/
spec/dummy/yarn-error.log
spec/dummy/storage/
spec/dummy/tmp/

.rspec_status
.tool-versions
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
Empty file added .rspec_status
Empty file.
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
sudo: false
language: ruby
before_install: gem install bundler -v 1.17.2
script:
- bundle exec rake db:test:prepare
- bundle exec rake
matrix:
include:
- gemfile: graphql-1.8.gemfile
env: GRAPHQL_RUBY_VERSION=1_8 CI=true
rvm: 2.6.1
- gemfile: graphql-1.8.gemfile
env: GRAPHQL_RUBY_VERSION=1_8 CI=true
rvm: 2.5.3
- gemfile: graphql-1.8.gemfile
env: GRAPHQL_RUBY_VERSION=1_8 CI=true
rvm: 2.4.5
12 changes: 8 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
source "https://rubygems.org"
source 'https://rubygems.org'

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem 'byebug'

# Specify your gem's dependencies in graphql-devise-auth.gemspec
gemspec
gem 'rails', '~> 5.2'

gem 'graphql', '~> 1.8.4'

# Specify your gem's dependencies in graphql-auth.gemspec
gemspec
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# GraphQL Auth
# GraphQL Auth

[![Build Status](https://travis-ci.org/o2web/graphql-auth.svg?branch=master)](https://travis-ci.org/o2web/graphql-auth) [![Maintainability](https://api.codeclimate.com/v1/badges/7e2515bb59f0b205a603/maintainability)](https://codeclimate.com/github/o2web/graphql-auth/maintainability)

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/graphql-auth`. To experiment with that code, run `bin/console` for an interactive prompt.

Expand Down Expand Up @@ -26,14 +28,14 @@ rails g graphql_auth:install

Make sure to read all configurations present inside the file and fill them with your own configs.

## Devise gem
## Devise gem

Use Devise with a User model and skip all route
Use Devise with a User model and skip all route

```
Rails.application.routes.draw do
devise_for :users, skip: :all
end
```
Rails.application.routes.draw do
devise_for :users, skip: :all
end
```

## Usage
Expand Down
20 changes: 18 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
require "bundler/gem_tasks"
task :default => :spec
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end

APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
load 'rails/tasks/engine.rake'

require 'rake'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = Dir.glob('spec/**/*_spec.rb')
t.rspec_opts = '--format documentation'
end

task default: :spec
8 changes: 1 addition & 7 deletions app/graphql/mutations/auth/forgot_password.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
# frozen_string_literal: true

# mutation {
# forgotPassword(email: "email@example.com") {
# valid
# success
# }
# }

class Mutations::Auth::ForgotPassword < GraphQL::Schema::Mutation
argument :email, String, required: true do
description 'The email with forgotten password'
end

field :errors, [::Types::Auth::Error], null: false
field :success, Boolean, null: false
field :valid, Boolean, null: false

def resolve(email:)
user = User.find_by email: email
Expand Down
10 changes: 0 additions & 10 deletions app/graphql/mutations/auth/reset_password.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
# frozen_string_literal: true

# mutation {
# resetPassword(resetPasswordToken: "token", password: "password", passwordConfirmation: "password") {
# success
# errors {
# field
# message
# }
# }
# }

class Mutations::Auth::ResetPassword < GraphQL::Schema::Mutation
argument :reset_password_token, String, required: true do
description "Reset password token"
Expand Down
13 changes: 0 additions & 13 deletions app/graphql/mutations/auth/sign_in.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
# frozen_string_literal: true

# mutation {
# signIn(email: "email@example.com", password: "password") {
# success
# user {
# email
# }
# errors {
# field
# message
# }
# }
# }

class Mutations::Auth::SignIn < GraphQL::Schema::Mutation
include ::Graphql::TokenHelper

Expand Down
13 changes: 0 additions & 13 deletions app/graphql/mutations/auth/sign_up.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
# frozen_string_literal: true

# mutation {
# signUp(email: "email@example.com", password: "password", passwordConfirmation: "password") {
# success
# user {
# email
# }
# errors {
# field
# message
# }
# }
# }

class Mutations::Auth::SignUp < GraphQL::Schema::Mutation
include ::Graphql::TokenHelper

Expand Down
24 changes: 11 additions & 13 deletions app/graphql/mutations/auth/update_account.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
# frozen_string_literal: true

# mutation {
# updateAccount(current_password: "currentPassword", password: "newPassword", password_confirmation: "newPassword") {
# success
# user {
# email
# }
# errors {
# field
# message
# }
# }
# }

class Mutations::Auth::UpdateAccount < GraphQL::Schema::Mutation
argument :current_password, String, required: true do
description "User's current password"
Expand All @@ -32,6 +19,17 @@ class Mutations::Auth::UpdateAccount < GraphQL::Schema::Mutation

def resolve(args)
user = context[:current_user]

if user.blank?
return {
errors: [
{ field: :_error, message: I18n.t('devise.failure.unauthenticated') }
],
success: false,
user: nil
}
end

user.update_with_password args

if user.errors.any?
Expand Down
12 changes: 1 addition & 11 deletions app/graphql/mutations/auth/validate_token.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
# frozen_string_literal: true

# mutation {
# validateToken {
# success
# valid
# user {
# email
# }
# }
# }

class Mutations::Auth::ValidateToken < GraphQL::Schema::Mutation
field :errors, [::Types::Auth::Error], null: false
field :success, Boolean, null: false
Expand All @@ -26,4 +16,4 @@ def resolve
valid: user.present?,
}
end
end
end
14 changes: 14 additions & 0 deletions bin/rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails gems
# installed from the root of your application.

ENGINE_ROOT = File.expand_path('..', __dir__)
ENGINE_PATH = File.expand_path('../lib/graphql-auth/engine', __dir__)
APP_PATH = File.expand_path('../spec/dummy/config/application', __dir__)

# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])

require 'rails/all'
require 'rails/engine/commands'
9 changes: 9 additions & 0 deletions graphql-1.8.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
source 'https://rubygems.org'

gem 'byebug'
gem 'coveralls'

gem 'rails', '~> 5.2'
gem 'graphql', '~> 1.8.4'

gemspec
26 changes: 16 additions & 10 deletions graphql-auth.gemspec
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
# coding: utf-8
$:.push File.expand_path("lib", __dir__)

require "graphql-auth/version"

Gem::Specification.new do |spec|
spec.name = 'graphql-auth'
spec.version = '0.2.2'
spec.version = GraphQL::Auth::VERSION
spec.authors = ['Guillaume Ferland']
spec.email = ['ferland182@gmail.com']
spec.platform = Gem::Platform::RUBY
spec.platform = Gem::Platform::RUBY
spec.summary = %q{GraphQL + JWT + Devise}
spec.description = %q{GraphQL + JWT + Devise}
spec.homepage = 'https://github.com/o2web/graphql-auth'
spec.license = 'MIT'

# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
spec.files = Dir['README.md', 'Gemfile', '{app,lib,vendor}/**/*']
spec.require_paths = %w(app lib)
spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]

spec.add_development_dependency 'bundler', '~> 1.15'
spec.add_development_dependency 'rake', '~> 10.0'
spec.required_ruby_version = '>= 2.4.5'

spec.add_dependency "rails", "~> 5.1"
spec.add_dependency 'graphql', '~> 1.8'
spec.add_dependency 'devise', '~> 4.4'
spec.add_dependency 'jwt', '~> 1.5'
end

spec.add_development_dependency 'sqlite3', '~> 1.3.6'
spec.add_development_dependency 'bundler', '~> 1.15'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'database_cleaner'
end
7 changes: 5 additions & 2 deletions lib/generators/graphql_auth/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ class InstallGenerator < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)

def copy_configuration
template 'initializer.rb', 'config/initializers/graphql_auth.rb'
template 'add_refresh_token_to_user.rb', "db/migrate/#{Time.now.strftime('%Y%m%d%H%M%S')}_add_refresh_token_to_user.rb"
template 'graphql_auth.rb.erb', 'config/initializers/graphql_auth.rb'
end

def rake_db
rake("railties:install:migrations")
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# config.update_account_mutation = ::Mutations::Auth::UpdateAccount

# config.validate_token_mutation = ::Mutations::Auth::ValidateToken
end
end
1 change: 1 addition & 0 deletions lib/graphql-auth.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'devise'
require 'graphql'
require 'graphql-auth/configuration'
require 'graphql-auth/engine'
require 'graphql-auth/reset_password'
Expand Down
4 changes: 3 additions & 1 deletion lib/graphql-auth/engine.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module GraphQL
module Auth
class Engine < ::Rails::Engine
isolate_namespace GraphQL::Auth

config.autoload_paths += Dir["#{config.root}/app/**/"]
end
end
end
end
5 changes: 5 additions & 0 deletions lib/graphql-auth/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module GraphQL
module Auth
VERSION = '0.3.0'
end
end
6 changes: 6 additions & 0 deletions spec/dummy/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative 'config/application'

Rails.application.load_tasks
4 changes: 4 additions & 0 deletions spec/dummy/app/channels/application_cable/channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end
4 changes: 4 additions & 0 deletions spec/dummy/app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module ApplicationCable
class Connection < ActionCable::Connection::Base
end
end
2 changes: 2 additions & 0 deletions spec/dummy/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ApplicationController < ActionController::API
end
Empty file.
Loading

0 comments on commit d29f583

Please sign in to comment.