happy_seed 0.0.14 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/happy_seed.rb +1 -0
- data/lib/generators/happy_seed/api/api_generator.rb +97 -0
- data/lib/generators/happy_seed/api/templates/app/controllers/api/v1/base_controller.rb +20 -0
- data/lib/generators/happy_seed/api/templates/app/controllers/api/v1/configurations_controller.rb +11 -0
- data/lib/generators/happy_seed/api/templates/app/controllers/api/v1/model_hash.rb +34 -0
- data/lib/generators/happy_seed/api/templates/app/controllers/api/v1/user_tokens_controller.rb +79 -0
- data/lib/generators/happy_seed/api/templates/app/controllers/api/v1/users_controller.rb +108 -0
- data/lib/generators/happy_seed/api/templates/config/initializers/apitome.rb +42 -0
- data/lib/generators/happy_seed/api/templates/docs/README.01.api.rdoc +27 -0
- data/lib/generators/happy_seed/api/templates/docs/api.md +4 -0
- data/lib/generators/happy_seed/api/templates/spec/acceptance/api/v1/configurations_spec.rb +21 -0
- data/lib/generators/happy_seed/api/templates/spec/acceptance/api/v1/user_tokens_spec.rb +95 -0
- data/lib/generators/happy_seed/api/templates/spec/acceptance/api/v1/users_spec.rb +125 -0
- data/lib/generators/happy_seed/base/base_generator.rb +2 -1
- data/lib/generators/happy_seed/devise/devise_generator.rb +2 -1
- data/lib/generators/happy_seed/devise_invitable/devise_invitable_generator.rb +1 -1
- data/lib/happy_seed/version.rb +1 -1
- metadata +14 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c24745a37c137a7c5bbbf197b783f85a648c2bb
|
4
|
+
data.tar.gz: d16da5cdce762fa346230941a7503a45dcffb363
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 048e4f10faaf60e1ffad9acdc824e570164f41e1eca9f29778a6a5f560ab63c6e92a0ae610c647c031a6c5662bb8dece54241bf6c61f8ba08c84983177a000b9
|
7
|
+
data.tar.gz: 18b760d9db4a4439b4d9e6ac33d6029a21ab4b7f0d750c73afdc3b865b0985b389ec74d8a25deedb1e64e6a67ce62ae143deb71ab6c1311a6074936b3e975673
|
data/happy_seed.rb
CHANGED
@@ -0,0 +1,97 @@
|
|
1
|
+
module HappySeed
|
2
|
+
module Generators
|
3
|
+
class ApiGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
def install_device_invitable
|
7
|
+
unless gem_available?( "devise" )
|
8
|
+
puts "The api generator requires devise"
|
9
|
+
|
10
|
+
if yes?( "Run happy_seed:devise now?" )
|
11
|
+
generate "happy_seed:devise"
|
12
|
+
else
|
13
|
+
exit
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
gem 'apitome'
|
18
|
+
gem 'rspec_api_documentation', :groups => [:development, :test]
|
19
|
+
|
20
|
+
Bundler.with_clean_env do
|
21
|
+
run "bundle install > /dev/null"
|
22
|
+
end
|
23
|
+
|
24
|
+
generate "model user_token user:belongs_to:index token installation_identifier:index push_token locked:boolean"
|
25
|
+
generate "migration add_user_tokens_count_to_users user_tokens_count:integer"
|
26
|
+
|
27
|
+
directory '.'
|
28
|
+
|
29
|
+
route " scope module: :api, defaults: {format: :json} do
|
30
|
+
%w(v1).each do |version|
|
31
|
+
namespace version.to_sym do
|
32
|
+
resource :configuration, only: %w(show)
|
33
|
+
resource :user_token, path: :token, only: %w(create destroy update)
|
34
|
+
resources :users, only: %w(create update show) do
|
35
|
+
resources :questions, only: %w(index)
|
36
|
+
collection do
|
37
|
+
post :forgot_password
|
38
|
+
put :reset_password
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
"
|
45
|
+
inject_into_class "app/models/user.rb", "User", " has_many :user_tokens, dependent: :destroy\n"
|
46
|
+
|
47
|
+
gsub_file "app/models/user_token.rb", /belongs_to :user\n/," validates :user, presence: true
|
48
|
+
validates :token, presence: true, uniqueness: {case_sensitive: false}
|
49
|
+
validates :installation_identifier, presence: true, uniqueness: {case_sensitive: false, scope: %w(user_id)}
|
50
|
+
validates :push_token, allow_blank: true, uniqueness: {case_sensitive: false}
|
51
|
+
|
52
|
+
scope :with_push_token, -> { where.not push_token: nil }
|
53
|
+
|
54
|
+
belongs_to :user, counter_cache: true
|
55
|
+
|
56
|
+
before_validation :set_token
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def set_token
|
61
|
+
self.token ||= loop do
|
62
|
+
token = Devise.friendly_token.downcase
|
63
|
+
break token unless self.class.where(token: token).first.present?
|
64
|
+
end
|
65
|
+
end
|
66
|
+
"
|
67
|
+
|
68
|
+
prepend_to_file 'spec/spec_helper.rb', "require 'rspec_api_documentation'\n"
|
69
|
+
append_to_file 'spec/spec_helper.rb', "\nRspecApiDocumentation.configure do |config|
|
70
|
+
config.format = :json
|
71
|
+
config.docs_dir = Pathname( 'docs/api' )
|
72
|
+
|
73
|
+
config.request_headers_to_include = %w(Authorization)
|
74
|
+
config.response_headers_to_include = %w()
|
75
|
+
end"
|
76
|
+
|
77
|
+
append_to_file 'spec/factories/users.rb', "\nFactoryGirl.define do
|
78
|
+
factory :user_with_token, parent: :user do
|
79
|
+
after :build do |user, evaluator|
|
80
|
+
user.user_tokens.build installation_identifier: Faker::Lorem.characters(10), push_token: Faker::Lorem.characters(10)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end"
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
def gem_available?(name)
|
88
|
+
Gem::Specification.find_by_name(name)
|
89
|
+
rescue Gem::LoadError
|
90
|
+
false
|
91
|
+
rescue
|
92
|
+
Gem.available?(name)
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Api::V1::BaseController < ApplicationController
|
2
|
+
include ModelHash
|
3
|
+
|
4
|
+
attr_accessor :current_user, :current_user_token, :installation_identifier
|
5
|
+
|
6
|
+
protected
|
7
|
+
|
8
|
+
def set_user
|
9
|
+
@user = params[:user_id].present? ? User.where(id: params[:user_id]).first : nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def requires_authentication_token
|
13
|
+
authenticate_or_request_with_http_token do |token, options|
|
14
|
+
self.installation_identifier = options[:installation_identifier]
|
15
|
+
self.current_user_token = UserToken.where(token: token, installation_identifier: installation_identifier).first
|
16
|
+
self.current_user = sign_in(:user, current_user_token.user) if current_user_token.try(:user).present?
|
17
|
+
current_user.present? ? (current_user_token.try(:touch); true) : false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Api::V1::ModelHash
|
2
|
+
def configuration_hash
|
3
|
+
{
|
4
|
+
pusher: {
|
5
|
+
url: Rails.application.secrets.pusher_url
|
6
|
+
},
|
7
|
+
aws: {
|
8
|
+
access_key_id: Rails.application.secrets.aws_access_key_id,
|
9
|
+
secret_access_key: Rails.application.secrets.aws_secret_access_key,
|
10
|
+
s3_bucket: Rails.application.secrets.s3_bucket
|
11
|
+
}
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def user_hash(user)
|
16
|
+
{
|
17
|
+
id: user.id,
|
18
|
+
login: user.login,
|
19
|
+
email: user.email,
|
20
|
+
first_name: user.first_name,
|
21
|
+
last_name: user.last_name
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def user_token_hash(user_token, *args)
|
26
|
+
options = args.extract_options!
|
27
|
+
output = {
|
28
|
+
token: user_token.token,
|
29
|
+
push_token: user_token.push_token
|
30
|
+
}
|
31
|
+
output.update(user: user_hash(user_token.user)) if true == options[:user]
|
32
|
+
output
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
class Api::V1::UserTokensController < Api::V1::BaseController
|
2
|
+
before_action :requires_authentication_token, only: %w(update destroy)
|
3
|
+
|
4
|
+
def create
|
5
|
+
respond_to do |format|
|
6
|
+
user = User.where('LOWER(email) = ?', user_token_params[:email].try(:downcase)).first
|
7
|
+
if user.present?
|
8
|
+
if user.valid_password?(user_token_params[:password])
|
9
|
+
if user.active_for_authentication?
|
10
|
+
user_token = user.user_tokens.where(installation_identifier: user_token_params[:installation_identifier]).first_or_initialize
|
11
|
+
user_token.update push_token: user_token_params[:push_token]
|
12
|
+
if user_token.persisted?
|
13
|
+
format.json do
|
14
|
+
render json: {user_token: user_token_hash(user_token, user: true)}, status: :ok
|
15
|
+
end
|
16
|
+
else
|
17
|
+
format.json do
|
18
|
+
render json: {errors: user_token.errors}, status: :unprocessable_entity
|
19
|
+
end
|
20
|
+
end
|
21
|
+
else
|
22
|
+
format.json do
|
23
|
+
render json: {errors: {user: 'is locked'}}, status: :forbidden
|
24
|
+
end
|
25
|
+
end
|
26
|
+
else
|
27
|
+
format.json do
|
28
|
+
render json: {errors: {password: 'is invalid'}}, status: :forbidden
|
29
|
+
end
|
30
|
+
end
|
31
|
+
else
|
32
|
+
format.json do
|
33
|
+
render json: {errors: {email: 'not found'}}, status: :not_found
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def update
|
40
|
+
respond_to do |format|
|
41
|
+
if current_user_token.try(:persisted?)
|
42
|
+
if current_user_token.update(user_token_params.slice :push_token)
|
43
|
+
format.json do
|
44
|
+
render json: {user_token: user_token_hash(current_user_token)}, status: :ok
|
45
|
+
end
|
46
|
+
else
|
47
|
+
format.json do
|
48
|
+
render json: {errors: current_user_token.errors}, status: :unprocessable_entity
|
49
|
+
end
|
50
|
+
end
|
51
|
+
else
|
52
|
+
format.json do
|
53
|
+
render json: {errors: {token: 'not found'}}, status: :not_found
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def destroy
|
60
|
+
respond_to do |format|
|
61
|
+
if current_user_token.try(:persisted?)
|
62
|
+
current_user_token.destroy
|
63
|
+
format.json do
|
64
|
+
render json: {user_token: user_token_hash(current_user_token, user: true)}, status: :ok
|
65
|
+
end
|
66
|
+
else
|
67
|
+
format.json do
|
68
|
+
render json: {errors: {token: 'not found'}}, status: :not_found
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def user_token_params
|
77
|
+
params[:user_token].permit :email, :password, :installation_identifier, :push_token
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
|
2
|
+
class Api::V1::UsersController < Api::V1::BaseController
|
3
|
+
before_action :requires_authentication_token, except: %w(create forgot_password reset_password)
|
4
|
+
before_action :set_user, only: %w(show update)
|
5
|
+
|
6
|
+
def show
|
7
|
+
respond_to do |format|
|
8
|
+
if @user.present?
|
9
|
+
format.json do
|
10
|
+
render json: {user: user_hash(@user)}, status: :ok
|
11
|
+
end
|
12
|
+
else
|
13
|
+
format.json do
|
14
|
+
render json: {errors: {id: 'not found'}}, status: :not_found
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def create
|
21
|
+
respond_to do |format|
|
22
|
+
user = User.new user_params
|
23
|
+
if user.save
|
24
|
+
user_token = user.user_tokens.where(installation_identifier: user_token_params[:installation_identifier]).first_or_create
|
25
|
+
if user_token.persisted?
|
26
|
+
format.json do
|
27
|
+
render json: {user_token: user_token_hash(user_token, user: true)}, status: :created
|
28
|
+
end
|
29
|
+
else
|
30
|
+
format.json do
|
31
|
+
render json: {errors: user_token.errors}, status: :unprocessable_entity
|
32
|
+
end
|
33
|
+
end
|
34
|
+
else
|
35
|
+
format.json do
|
36
|
+
render json: {errors: user.errors}, status: :unprocessable_entity
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def update
|
43
|
+
respond_to do |format|
|
44
|
+
if @user.present?
|
45
|
+
if @user.update(user_params)
|
46
|
+
format.json do
|
47
|
+
render json: {user: user_hash(@user)}, status: :ok
|
48
|
+
end
|
49
|
+
else
|
50
|
+
format.json do
|
51
|
+
render json: {errors: @user.errors}, status: :unprocessable_entity
|
52
|
+
end
|
53
|
+
end
|
54
|
+
else
|
55
|
+
format.json do
|
56
|
+
render json: {errors: {id: 'not found'}}, status: :not_found
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def forgot_password
|
63
|
+
respond_to do |format|
|
64
|
+
user = FormUser.where(email: user_params[:email]).first
|
65
|
+
format.json do
|
66
|
+
if user.present?
|
67
|
+
user.send_reset_password_instructions
|
68
|
+
user.save
|
69
|
+
render json: {user: user_hash(user).slice(:email)}, status: :ok
|
70
|
+
else
|
71
|
+
render json: {errors: {email: 'not found'}}, status: :not_found
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def reset_password
|
78
|
+
respond_to do |format|
|
79
|
+
user = User.reset_password_by_token user_params.slice(:reset_password_token, :password, :password_confirmation)
|
80
|
+
format.json do
|
81
|
+
if user.present?
|
82
|
+
if user.errors.empty?
|
83
|
+
render json: {user: user_hash(user)}, status: :ok
|
84
|
+
else
|
85
|
+
p user.errors
|
86
|
+
render json: {errors: user.errors}, status: :unprocessable_entity
|
87
|
+
end
|
88
|
+
else
|
89
|
+
render json: {errors: {email: 'not found'}}, status: :not_found
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def set_user
|
98
|
+
@user = User.where(id: params[:id]).first
|
99
|
+
end
|
100
|
+
|
101
|
+
def user_params
|
102
|
+
params.require(:user).permit :email, :password, :username, :first_name, :last_name, :avatar, :reset_password_token, :password_confirmation, invited: %w(email full_name).map(&:to_sym)
|
103
|
+
end
|
104
|
+
|
105
|
+
def user_token_params
|
106
|
+
params[:user_token].permit :installation_identifier
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
Apitome.setup do |config|
|
2
|
+
# This determines where the Apitome routes will be mounted. Changing this to '/api/documentation' for instance would
|
3
|
+
# allow you to browse to http://localhost:3000/api/documentation to see your api documentation. Set to nil and mount
|
4
|
+
# it yourself if you need to.
|
5
|
+
config.mount_at = '/api/docs'
|
6
|
+
|
7
|
+
# This defaults to Rails.root if left nil. If you're providing documentation for an engine using a dummy application
|
8
|
+
# it can be useful to set this to your engines root.. E.g. Application::Engine.root
|
9
|
+
config.root = nil
|
10
|
+
|
11
|
+
# This is where rspec_api_documentation outputs the JSON files. This is configurable within RAD, and so is
|
12
|
+
# configurable here.
|
13
|
+
config.doc_path = 'docs/api'
|
14
|
+
|
15
|
+
# The title of the documentation -- If your project has a name, you'll want to put it here.
|
16
|
+
config.title = 'API Documentation'
|
17
|
+
|
18
|
+
# The main layout view for all documentation pages. By default this is pretty basic, but you may want to use your own
|
19
|
+
# application layout.
|
20
|
+
config.layout = 'apitome/application'
|
21
|
+
|
22
|
+
# We're using highlight.js (https://github.com/isagalaev/highlight.js) for code highlighting, and it comes with some
|
23
|
+
# great themes. You can check http://softwaremaniacs.org/media/soft/highlight/test.html for themes, and enter the
|
24
|
+
# theme as lowercase/underscore.
|
25
|
+
config.code_theme = 'monokai'
|
26
|
+
|
27
|
+
# This allows you to override the css manually. You typically want to require `apitome/application` within the
|
28
|
+
# override, but if you want to override it entirely you can do so.
|
29
|
+
config.css_override = nil
|
30
|
+
|
31
|
+
# This allows you to override the javascript manually. You typically want to require `apitome/application` within the
|
32
|
+
# override, but if you want to override it entirely you can do so.
|
33
|
+
config.js_override = nil
|
34
|
+
|
35
|
+
# You can provide a 'README' style markdown file for the documentation, which is a useful place to include general
|
36
|
+
# information. This path is relative to your doc_path configuration.
|
37
|
+
config.readme = '../api.md'
|
38
|
+
|
39
|
+
# Apitome can render the documentation into a single page that uses scrollspy, or it can render the documentation on
|
40
|
+
# individual pages on demand. This allows you to specify which one you want, as a single page may impact performance.
|
41
|
+
config.single_page = true
|
42
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
HappySeed API Install
|
2
|
+
===================
|
3
|
+
|
4
|
+
### What does this do?
|
5
|
+
|
6
|
+
The `happy_seed:api` generator
|
7
|
+
|
8
|
+
* Installs `apitome`
|
9
|
+
* Installs `rspec_api_documentation`
|
10
|
+
|
11
|
+
### Why do you want this?
|
12
|
+
|
13
|
+
This allows you to invite users to the site and have them sign up through a link.
|
14
|
+
|
15
|
+
### Environment Variables
|
16
|
+
|
17
|
+
na
|
18
|
+
|
19
|
+
### What needs to be done?
|
20
|
+
|
21
|
+
After you update your specs in spec/acceptance, run
|
22
|
+
|
23
|
+
```
|
24
|
+
rake docs:generate
|
25
|
+
```
|
26
|
+
|
27
|
+
to output the files into the docs/api directory.
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
require 'rspec_api_documentation/dsl'
|
3
|
+
|
4
|
+
resource 'Configuration' do
|
5
|
+
header 'AUTHORIZATION', :token
|
6
|
+
|
7
|
+
let(:user) { FactoryGirl.create :user_with_token }
|
8
|
+
let(:token) { ActionController::HttpAuthentication::Token.encode_credentials user.user_tokens.first.try(:token), installation_identifier: user.user_tokens.first.try(:installation_identifier) }
|
9
|
+
|
10
|
+
get '/v1/configuration', format: :json do
|
11
|
+
example_request 'show' do
|
12
|
+
response_json = JSON.parse response_body
|
13
|
+
|
14
|
+
expect(status).to eq(200)
|
15
|
+
expect(response_json['pusher']['url']).to eq(Rails.application.secrets.pusher_url)
|
16
|
+
expect(response_json['aws']['access_key_id']).to eq(Rails.application.secrets.aws_access_key_id)
|
17
|
+
expect(response_json['aws']['secret_access_key']).to eq(Rails.application.secrets.aws_secret_access_key)
|
18
|
+
expect(response_json['aws']['s3_bucket']).to eq(Rails.application.secrets.s3_bucket)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
require 'rspec_api_documentation/dsl'
|
3
|
+
|
4
|
+
resource 'Token' do
|
5
|
+
let(:user) { FactoryGirl.create :user_with_token }
|
6
|
+
|
7
|
+
post '/v1/token', format: :json do
|
8
|
+
parameter :email, 'Email', required: true, scope: :user_token
|
9
|
+
parameter :password, 'Password', required: true, scope: :user_token
|
10
|
+
parameter :installation_identifier, 'Unique Installation Identifier', required: true, scope: :user_token
|
11
|
+
parameter :push_token, 'Unique push token', required: true, scope: :user_token
|
12
|
+
|
13
|
+
let(:email) { user.email }
|
14
|
+
let(:password) { user.password }
|
15
|
+
let(:installation_identifier) { Faker::Lorem.characters 10 }
|
16
|
+
let(:push_token) { Faker::Lorem.characters 10 }
|
17
|
+
|
18
|
+
example_request 'sign in' do
|
19
|
+
response_json = JSON.parse response_body
|
20
|
+
|
21
|
+
expect(response_headers['Content-Type']).to eq('application/json; charset=utf-8')
|
22
|
+
expect(status).to eq(200)
|
23
|
+
expect(response_json['user_token']).to have_key('token')
|
24
|
+
expect(response_json['user_token']['push_token']).to eq(push_token)
|
25
|
+
expect(response_json['user_token']).to have_key('user')
|
26
|
+
end
|
27
|
+
|
28
|
+
example 'sign in with wrong email', document: false do
|
29
|
+
do_request params.tap { |parameters| parameters['user_token']['email'] = Faker::Internet.free_email }
|
30
|
+
response_json = JSON.parse response_body
|
31
|
+
|
32
|
+
expect(status).to eq(404)
|
33
|
+
expect(response_json['id']).to be_nil
|
34
|
+
expect(response_json['errors']).to have_key('email')
|
35
|
+
end
|
36
|
+
|
37
|
+
# example 'sign in with locked user', document: false do
|
38
|
+
# user.lock_access! send_instructions: false
|
39
|
+
# do_request
|
40
|
+
# response_json = JSON.parse response_body
|
41
|
+
|
42
|
+
# expect(status).to eq(403)
|
43
|
+
# expect(response_json['id']).to be_nil
|
44
|
+
# expect(response_json['errors']).to have_key('user')
|
45
|
+
# end
|
46
|
+
|
47
|
+
example 'sign in with wrong password', document: false do
|
48
|
+
do_request params.tap { |parameters| parameters['user_token']['password'] = Faker::Lorem.characters 8 }
|
49
|
+
response_json = JSON.parse response_body
|
50
|
+
|
51
|
+
expect(status).to eq(403)
|
52
|
+
expect(response_json['id']).to be_nil
|
53
|
+
expect(response_json['errors']).to have_key('password')
|
54
|
+
end
|
55
|
+
|
56
|
+
example 'sign in without installation identifier', document: false do
|
57
|
+
do_request params.tap { |parameters| parameters['user_token'].delete 'installation_identifier' }
|
58
|
+
response_json = JSON.parse response_body
|
59
|
+
|
60
|
+
expect(status).to eq(422)
|
61
|
+
expect(response_json['id']).to be_nil
|
62
|
+
expect(response_json['errors']).to have_key('installation_identifier')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
put '/v1/token', format: :json do
|
67
|
+
header 'AUTHORIZATION', :token
|
68
|
+
|
69
|
+
parameter :push_token, 'Unique push token', required: true, scope: :user_token
|
70
|
+
|
71
|
+
let(:token) { ActionController::HttpAuthentication::Token.encode_credentials user.user_tokens.first.try(:token), installation_identifier: user.user_tokens.first.try(:installation_identifier) }
|
72
|
+
let(:push_token) { Faker::Lorem.characters 10 }
|
73
|
+
|
74
|
+
example_request 'update' do
|
75
|
+
explanation 'At the moment, only push token can be updated'
|
76
|
+
response_json = JSON.parse response_body
|
77
|
+
|
78
|
+
expect(status).to eq(200)
|
79
|
+
expect(response_json['user_token']['push_token']).to eq(push_token)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
delete '/v1/token', format: :json do
|
84
|
+
header 'AUTHORIZATION', :token
|
85
|
+
let(:token) { ActionController::HttpAuthentication::Token.encode_credentials user.user_tokens.first.try(:token), installation_identifier: user.user_tokens.first.try(:installation_identifier) }
|
86
|
+
|
87
|
+
example_request 'sign out' do
|
88
|
+
response_json = JSON.parse response_body
|
89
|
+
|
90
|
+
expect(status).to eq(200)
|
91
|
+
expect(response_json['user_token']).to have_key('token')
|
92
|
+
expect(response_json['user_token']).to have_key('user')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
require 'rspec_api_documentation/dsl'
|
3
|
+
|
4
|
+
class User
|
5
|
+
def _set_reset_password_token
|
6
|
+
set_reset_password_token
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
resource 'User' do
|
11
|
+
let(:user) { FactoryGirl.build :user_with_token }
|
12
|
+
# before {
|
13
|
+
# @request.env["devise.mapping"] = Devise.mappings[:user]
|
14
|
+
# }
|
15
|
+
|
16
|
+
post '/v1/users', format: :json do
|
17
|
+
parameter :first_name, 'First Name', scope: :user
|
18
|
+
parameter :last_name, 'Last Name', scope: :user
|
19
|
+
parameter :login, 'Login', required: true, scope: :user
|
20
|
+
parameter :email, 'Email', required: true, scope: :user
|
21
|
+
parameter :password, 'Password', required: true, scope: :user
|
22
|
+
parameter :installation_identifier, 'Unique Installation Identifier', required: true, scope: :user_token
|
23
|
+
parameter :avatar, 'Avatar', scope: :user
|
24
|
+
|
25
|
+
let(:first_name) { user.first_name }
|
26
|
+
let(:last_name) { user.last_name }
|
27
|
+
let(:login) { user.login }
|
28
|
+
let(:email) { user.email }
|
29
|
+
let(:password) { user.password }
|
30
|
+
let(:installation_identifier) { Faker::Lorem.characters 10 }
|
31
|
+
# let(:avatar) { fixture_file_upload Rails.root.join('spec', 'resources', 'photo.jpg'), 'image/jpeg' }
|
32
|
+
|
33
|
+
example_request 'sign up' do
|
34
|
+
response_json = JSON.parse response_body
|
35
|
+
|
36
|
+
expect(status).to eq(201)
|
37
|
+
expect(response_json['user_token']).to have_key('token')
|
38
|
+
expect(response_json['user_token']).to have_key('user')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
post '/v1/users/forgot_password', format: :json do
|
43
|
+
before do
|
44
|
+
user.save
|
45
|
+
# @request.env["devise.mapping"] = :user
|
46
|
+
# user.send_reset_password_instructions
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
parameter :email, 'Email', required: true, scope: :user
|
51
|
+
let(:email) { user.email }
|
52
|
+
|
53
|
+
example_request 'forgot password' do
|
54
|
+
response_json = JSON.parse response_body
|
55
|
+
|
56
|
+
expect(status).to eq(200)
|
57
|
+
expect(response_json['user']['email']).to eq(email)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
put '/v1/users/reset_password', format: :json do
|
62
|
+
before do
|
63
|
+
user.save
|
64
|
+
end
|
65
|
+
|
66
|
+
parameter :reset_password_token, 'Reset password token', required: true, scope: :user
|
67
|
+
parameter :password, 'Password', required: true, scope: :user
|
68
|
+
parameter :password_confirmation, 'Password confirmation', required: true, scope: :user
|
69
|
+
|
70
|
+
let(:reset_password_token) { user._set_reset_password_token }
|
71
|
+
let(:password) { Faker::Internet.password 8 }
|
72
|
+
let(:password_confirmation) { password }
|
73
|
+
|
74
|
+
example_request 'reset password' do
|
75
|
+
response_json = JSON.parse response_body
|
76
|
+
|
77
|
+
expect(status).to eq(200)
|
78
|
+
expect(response_json['user']).to have_key('id')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
get '/v1/users/:id', format: :json do
|
83
|
+
before { user.save }
|
84
|
+
|
85
|
+
header 'AUTHORIZATION', :token
|
86
|
+
|
87
|
+
parameter :id, 'User Unique Identifier', required: true
|
88
|
+
|
89
|
+
let(:token) { ActionController::HttpAuthentication::Token.encode_credentials user.user_tokens.first.try(:token), installation_identifier: user.user_tokens.first.try(:installation_identifier) }
|
90
|
+
let(:id) { user.id }
|
91
|
+
|
92
|
+
example_request 'show' do
|
93
|
+
response_json = JSON.parse response_body
|
94
|
+
|
95
|
+
expect(status).to eq(200)
|
96
|
+
expect(response_json['user']).to have_key('id')
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
put '/v1/users/:id', format: :json do
|
101
|
+
before { user.save }
|
102
|
+
|
103
|
+
header 'AUTHORIZATION', :token
|
104
|
+
|
105
|
+
parameter :id, 'User Unique Identifier', required: true
|
106
|
+
parameter :first_name, 'Full Name', scope: :user
|
107
|
+
parameter :last_name, 'Full Name', scope: :user
|
108
|
+
parameter :login, 'User Name', scope: :user
|
109
|
+
|
110
|
+
let(:token) { ActionController::HttpAuthentication::Token.encode_credentials user.user_tokens.first.try(:token), installation_identifier: user.user_tokens.first.try(:installation_identifier) }
|
111
|
+
let(:id) { user.id }
|
112
|
+
let(:first_name) { Faker::Name.first_name }
|
113
|
+
let(:last_name) { Faker::Name.last_name }
|
114
|
+
let(:login) { Faker::Internet.user_name }
|
115
|
+
# let(:avatar) { fixture_file_upload Rails.root.join('spec', 'resources', 'photo.jpg'), 'image/jpeg' }
|
116
|
+
|
117
|
+
example_request 'update' do
|
118
|
+
explanation 'While this illustrates all possible parameters, any subset can be used. Example: to change only full_name, omit other optional parameters'
|
119
|
+
response_json = JSON.parse response_body
|
120
|
+
|
121
|
+
expect(status).to eq(200)
|
122
|
+
expect(response_json['user']).to have_key('id')
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -22,7 +22,8 @@ module HappySeed
|
|
22
22
|
inject_into_file 'config/environments/test.rb', " config.log_level = :error\n", before: "end\n"
|
23
23
|
|
24
24
|
begin
|
25
|
-
inject_into_file 'spec/spec_helper.rb', "\n config.include ControllerHelpers\n Warden.test_mode!\n", :before => "\nend\n"
|
25
|
+
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"
|
26
|
+
prepend_to_file 'spec/spec_helper.rb', "require_relative 'support/controller_helpers'\n"
|
26
27
|
rescue
|
27
28
|
say_status :spec, "Unable to add login helpers to spec_helper.rb"
|
28
29
|
end
|
@@ -32,7 +32,8 @@ module HappySeed
|
|
32
32
|
|
33
33
|
begin
|
34
34
|
prepend_to_file 'spec/spec_helper.rb', "require 'devise'\n"
|
35
|
-
|
35
|
+
inject_into_file 'spec/spec_helper.rb', "\n config.include Devise::TestHelpers, type: :controller\n", :before => "\nend\n"
|
36
|
+
|
36
37
|
rescue
|
37
38
|
say_status :spec, "Unable to add devise helpers to spec_helper.rb", :red
|
38
39
|
end
|
@@ -5,7 +5,7 @@ module HappySeed
|
|
5
5
|
|
6
6
|
def install_device_invitable
|
7
7
|
unless gem_available?( "devise" )
|
8
|
-
puts "The
|
8
|
+
puts "The devise invitable generator requires devise"
|
9
9
|
|
10
10
|
if yes?( "Run happy_seed:devise now?" )
|
11
11
|
generate "happy_seed:devise"
|
data/lib/happy_seed/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: happy_seed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Will Schenk
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-02-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -90,6 +90,18 @@ files:
|
|
90
90
|
- lib/generators/happy_seed/angular_view/templates/app/assets/javascripts/controllers/controller.js.coffee
|
91
91
|
- lib/generators/happy_seed/angular_view/templates/app/assets/templates/view.html
|
92
92
|
- lib/generators/happy_seed/angular_view/templates/docs/README.11.angular_view.rdoc
|
93
|
+
- lib/generators/happy_seed/api/api_generator.rb
|
94
|
+
- lib/generators/happy_seed/api/templates/app/controllers/api/v1/base_controller.rb
|
95
|
+
- lib/generators/happy_seed/api/templates/app/controllers/api/v1/configurations_controller.rb
|
96
|
+
- lib/generators/happy_seed/api/templates/app/controllers/api/v1/model_hash.rb
|
97
|
+
- lib/generators/happy_seed/api/templates/app/controllers/api/v1/user_tokens_controller.rb
|
98
|
+
- lib/generators/happy_seed/api/templates/app/controllers/api/v1/users_controller.rb
|
99
|
+
- lib/generators/happy_seed/api/templates/config/initializers/apitome.rb
|
100
|
+
- lib/generators/happy_seed/api/templates/docs/README.01.api.rdoc
|
101
|
+
- lib/generators/happy_seed/api/templates/docs/api.md
|
102
|
+
- lib/generators/happy_seed/api/templates/spec/acceptance/api/v1/configurations_spec.rb
|
103
|
+
- lib/generators/happy_seed/api/templates/spec/acceptance/api/v1/user_tokens_spec.rb
|
104
|
+
- lib/generators/happy_seed/api/templates/spec/acceptance/api/v1/users_spec.rb
|
93
105
|
- lib/generators/happy_seed/base/.DS_Store
|
94
106
|
- lib/generators/happy_seed/base/base_generator.rb
|
95
107
|
- lib/generators/happy_seed/base/templates/.DS_Store
|