restpack_user_service 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +21 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +13 -0
- data/Rakefile +2 -0
- data/config/database.yml +8 -0
- data/db/migrate/20130807130942_create_users.rb +15 -0
- data/db/migrate/20130807130949_create_authentications.rb +13 -0
- data/lib/restpack_user_service.rb +17 -0
- data/lib/restpack_user_service/commands/user/get.rb +23 -0
- data/lib/restpack_user_service/commands/user/omni_authenticate.rb +32 -0
- data/lib/restpack_user_service/configuration.rb +12 -0
- data/lib/restpack_user_service/models/authentication.rb +32 -0
- data/lib/restpack_user_service/models/user.rb +36 -0
- data/lib/restpack_user_service/serializers/user_serializer.rb +15 -0
- data/lib/restpack_user_service/version.rb +7 -0
- data/restpack_user_service.gemspec +35 -0
- data/spec/commands/user/get_spec.rb +54 -0
- data/spec/commands/user/omni_authenticate_spec.rb +63 -0
- data/spec/factories/authentication_factory.rb +21 -0
- data/spec/factories/user_factory.rb +11 -0
- data/spec/models/authentication_spec.rb +50 -0
- data/spec/models/user_spec.rb +16 -0
- data/spec/spec_helper.rb +25 -0
- metadata +259 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 305b65f0af474c793bf5ed8456ba074dfd8a1dd3
|
4
|
+
data.tar.gz: d0551fded91a57aa7118da7a91fb37faf31d7113
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 26acf3d25dda874723ed27c40c7bd08a01947898860149b56a7b9fcaa7cbc27d28d8e022fc5c94d7fb2ba0bfc92fd21a12034f44e285f5ed4cce06f276644cca
|
7
|
+
data.tar.gz: 451d6fa95a5dd7cc1958a3cefc0c84577183464b2816d18f41f901d37dc18e7941b103dbd00b27541f6d6a2619b0830d0f06410534377d40b335e340327873d5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.0.0
|
4
|
+
#http://reefpoints.dockyard.com/ruby/2013/03/29/running-postgresql-9-2-on-travis-ci.html
|
5
|
+
before_script:
|
6
|
+
- sudo /etc/init.d/postgresql stop
|
7
|
+
- sudo cp /etc/postgresql/9.1/main/pg_hba.conf ./
|
8
|
+
- sudo apt-get remove postgresql postgresql-9.1 -qq --purge
|
9
|
+
- source /etc/lsb-release
|
10
|
+
- echo "deb http://apt.postgresql.org/pub/repos/apt/ $DISTRIB_CODENAME-pgdg main" > pgdg.list
|
11
|
+
- sudo mv pgdg.list /etc/apt/sources.list.d/
|
12
|
+
- wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
|
13
|
+
- sudo apt-get update
|
14
|
+
- sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" install postgresql-9.2 postgresql-contrib-9.2 -qq
|
15
|
+
- sudo /etc/init.d/postgresql stop
|
16
|
+
- sudo cp ./pg_hba.conf /etc/postgresql/9.2/main
|
17
|
+
- sudo /etc/init.d/postgresql start
|
18
|
+
- psql -c 'create database restpack_user_service_test;' -U postgres
|
19
|
+
- psql -c 'create role travis login;' -U postgres
|
20
|
+
|
21
|
+
script: bundle exec rake test
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Gavin Joyce
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# restpack_user_service
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/RestPack/restpack_user_service.png?branch=master)](https://travis-ci.org/RestPack/restpack_user_service) [![Code Climate](https://codeclimate.com/github/RestPack/restpack_user_service.png)](https://codeclimate.com/github/RestPack/restpack_user_service) [![Dependency Status](https://gemnasium.com/RestPack/restpack_user_service.png)](https://gemnasium.com/RestPack/restpack_user_service) [![Gem Version](https://badge.fury.io/rb/restpack_user_service.png)](http://badge.fury.io/rb/restpack_user_service)
|
4
|
+
|
5
|
+
**Work In Progress**
|
6
|
+
|
7
|
+
This gem provides services for managing Users and Authentications.
|
8
|
+
|
9
|
+
## Development Setup
|
10
|
+
|
11
|
+
1. install postgres
|
12
|
+
2. create a `restpack_user_service_test` database
|
13
|
+
3. rake
|
data/Rakefile
ADDED
data/config/database.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateUsers < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :restpack_users do |t|
|
4
|
+
t.string :name, :limit => 128
|
5
|
+
t.string :nickname, :limit => 128
|
6
|
+
t.string :email, :limit => 512
|
7
|
+
t.string :image, :limit => 1024
|
8
|
+
t.string :location, :limit => 512
|
9
|
+
t.string :description, :limit => 1024
|
10
|
+
t.integer :application_id, :null => false
|
11
|
+
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateAuthentications < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :restpack_authentications do |t|
|
4
|
+
t.string :provider, :limit => 128, :null => false
|
5
|
+
t.string :uid, :limit => 1024, :null => false
|
6
|
+
t.json :omniauth, :null => false
|
7
|
+
t.integer :application_id, :null => false
|
8
|
+
t.integer :user_id, :null => false
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'require_all'
|
2
|
+
|
3
|
+
require "restpack_service"
|
4
|
+
require "restpack_serializer"
|
5
|
+
require "active_support/core_ext"
|
6
|
+
|
7
|
+
require "restpack_user_service/version"
|
8
|
+
require "restpack_user_service/configuration"
|
9
|
+
|
10
|
+
require_rel "restpack_user_service/models"
|
11
|
+
require_rel "restpack_user_service/serializers"
|
12
|
+
|
13
|
+
module RestPack::User::Service::Commands
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
require_rel "restpack_user_service/commands"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module RestPack::User::Service::Commands::User
|
2
|
+
class Get < RestPack::Service::Command
|
3
|
+
required do
|
4
|
+
integer :id
|
5
|
+
integer :application_id
|
6
|
+
end
|
7
|
+
|
8
|
+
def execute
|
9
|
+
#TODO: GJ: remove the :application_id scope when we can specify custom serializer filters
|
10
|
+
# https://github.com/RestPack/restpack_serializer/issues/42
|
11
|
+
result = RestPack::User::Service::Serializers::UserSerializer.resource(
|
12
|
+
inputs,
|
13
|
+
RestPack::User::Service::Models::User.where(application_id: inputs[:application_id])
|
14
|
+
)
|
15
|
+
|
16
|
+
if result[:users].empty?
|
17
|
+
status :not_found
|
18
|
+
else
|
19
|
+
result
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module RestPack::User::Service::Commands::User
|
2
|
+
class OmniAuthenticate < RestPack::Service::Command
|
3
|
+
required do
|
4
|
+
integer :application_id
|
5
|
+
hash :omniauth_response do
|
6
|
+
required do
|
7
|
+
string :provider
|
8
|
+
string :uid
|
9
|
+
hash :info
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
optional do
|
15
|
+
integer :user_id
|
16
|
+
end
|
17
|
+
|
18
|
+
def execute
|
19
|
+
user = RestPack::User::Service::Models::User.authenticate(
|
20
|
+
user_id,
|
21
|
+
application_id,
|
22
|
+
omniauth_response
|
23
|
+
)
|
24
|
+
|
25
|
+
if user
|
26
|
+
return RestPack::User::Service::Serializers::UserSerializer.resource(user)
|
27
|
+
else
|
28
|
+
status :unauthorized
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
module RestPack::User::Service::Models
|
3
|
+
class Authentication < ActiveRecord::Base
|
4
|
+
self.table_name = :restpack_authentications
|
5
|
+
|
6
|
+
attr_accessible :application_id, :oauth, :provider, :uid, :user_id, :omniauth
|
7
|
+
serialize :oauth, JSON
|
8
|
+
|
9
|
+
validates_presence_of :application_id, :omniauth, :provider, :uid, :user_id
|
10
|
+
validates :provider, :length => { :maximum => 128 }
|
11
|
+
validates :uid, :length => { :maximum => 1024 }
|
12
|
+
|
13
|
+
belongs_to :user
|
14
|
+
|
15
|
+
def self.from_omniauth(application_id, omniauth)
|
16
|
+
Authentication.new(
|
17
|
+
application_id: application_id,
|
18
|
+
provider: omniauth['provider'],
|
19
|
+
uid: omniauth['uid'],
|
20
|
+
omniauth: omniauth
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.get_by_omniauth(application_id, omniauth)
|
25
|
+
Authentication.where(
|
26
|
+
application_id: application_id,
|
27
|
+
provider: omniauth['provider'],
|
28
|
+
uid: omniauth['uid']
|
29
|
+
).first
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module RestPack::User::Service::Models
|
2
|
+
class User < ActiveRecord::Base
|
3
|
+
self.table_name = :restpack_users
|
4
|
+
attr_accessible :application_id, :description, :email, :image, :location, :name, :nickname
|
5
|
+
|
6
|
+
validates_presence_of :application_id
|
7
|
+
validates :name, :length => { :maximum => 128 }
|
8
|
+
validates :nickname, :length => { :maximum => 128 }
|
9
|
+
validates :email, :length => { :maximum => 512 }
|
10
|
+
validates :image, :length => { :maximum => 1024 }
|
11
|
+
validates :location, :length => { :maximum => 512 }
|
12
|
+
validates :description, :length => { :maximum => 1024 }
|
13
|
+
|
14
|
+
has_many :authentications
|
15
|
+
|
16
|
+
def self.authenticate(user_id, application_id, omniauth)
|
17
|
+
authentication = Authentication.get_by_omniauth(application_id, omniauth)
|
18
|
+
if authentication
|
19
|
+
return authentication.user
|
20
|
+
else
|
21
|
+
if user_id.blank?
|
22
|
+
user = User.new(application_id: application_id)
|
23
|
+
else
|
24
|
+
user = User.find(user_id)
|
25
|
+
end
|
26
|
+
[:name, :nickname, :email, :image, :location, :description].each do |attribute|
|
27
|
+
user[attribute] ||= omniauth['info'][attribute.to_s]
|
28
|
+
end
|
29
|
+
|
30
|
+
user.save!
|
31
|
+
user.authentications << Authentication.from_omniauth(application_id, omniauth)
|
32
|
+
user
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module RestPack::User::Service::Serializers
|
2
|
+
class UserSerializer
|
3
|
+
include RestPack::Serializer
|
4
|
+
|
5
|
+
self.model_class = RestPack::User::Service::Models::User
|
6
|
+
self.key = :users
|
7
|
+
|
8
|
+
attributes :id, :application_id, :description, :email,
|
9
|
+
:image, :avatar, :location, :name, :nickname, :href
|
10
|
+
|
11
|
+
def avatar
|
12
|
+
image || "http://robohash.org/#{id}.png?size=200x200"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'restpack_user_service/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "restpack_user_service"
|
8
|
+
spec.version = RestPack::User::Service::VERSION
|
9
|
+
spec.authors = ["Gavin Joyce"]
|
10
|
+
spec.email = ["gavinjoyce@gmail.com"]
|
11
|
+
spec.description = %q{Users and Authentications service}
|
12
|
+
spec.summary = %q{Users and Authentications}
|
13
|
+
spec.homepage = "https://github.com/RestPack"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "restpack_service"#, "~> 0.0.25"
|
22
|
+
spec.add_dependency "restpack_serializer"#, "~> 0.4.1"
|
23
|
+
spec.add_dependency "restpack_gem"#, "~> 0.0.9"
|
24
|
+
spec.add_dependency "sinatra", "~> 1.4.3"
|
25
|
+
spec.add_dependency "pg", "~> 0.16"
|
26
|
+
spec.add_dependency "require_all", "~> 1.3.0"
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
29
|
+
spec.add_development_dependency "database_cleaner", "~> 1.0.1"
|
30
|
+
spec.add_development_dependency "rake"
|
31
|
+
spec.add_development_dependency "rspec"
|
32
|
+
spec.add_development_dependency "bump"
|
33
|
+
spec.add_development_dependency "shoulda-matchers", "~> 1.4.2"
|
34
|
+
spec.add_development_dependency "factory_girl", "~> 4.0"
|
35
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe RestPack::User::Service::Commands::User::Get do
|
4
|
+
is_required :id, :application_id
|
5
|
+
|
6
|
+
let(:response) { subject.class.run(params) }
|
7
|
+
let(:params) { {} }
|
8
|
+
|
9
|
+
before do
|
10
|
+
@user = create(:user)
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'with valid params' do
|
14
|
+
let(:params) { {
|
15
|
+
id: @user.id,
|
16
|
+
application_id: @user.application_id
|
17
|
+
} }
|
18
|
+
|
19
|
+
it 'is valid' do
|
20
|
+
response.success?.should == true
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'return the user' do
|
24
|
+
response.result[:users].length.should == 1
|
25
|
+
response.result[:users].first[:id].should == @user.id.to_s
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with invalid :id' do
|
30
|
+
let(:params) { {
|
31
|
+
id: 142857,
|
32
|
+
application_id: @user.application_id
|
33
|
+
}}
|
34
|
+
|
35
|
+
it 'is :not_found' do
|
36
|
+
response.success?.should == false
|
37
|
+
response.result.should == {}
|
38
|
+
response.status.should == :not_found
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'with invalid :application_id' do
|
43
|
+
let(:params) { {
|
44
|
+
id: @user.id,
|
45
|
+
application_id: 142857
|
46
|
+
}}
|
47
|
+
|
48
|
+
it 'is :not_found' do
|
49
|
+
response.success?.should == false
|
50
|
+
response.result.should == {}
|
51
|
+
response.status.should == :not_found
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe RestPack::User::Service::Commands::User::OmniAuthenticate do
|
4
|
+
is_required :application_id, :omniauth_response
|
5
|
+
is_optional :user_id
|
6
|
+
|
7
|
+
UserSerializer = RestPack::User::Service::Serializers::UserSerializer
|
8
|
+
User = RestPack::User::Service::Models::User
|
9
|
+
Authentication = RestPack::User::Service::Models::Authentication
|
10
|
+
|
11
|
+
let(:response) { subject.class.run(params) }
|
12
|
+
|
13
|
+
before do
|
14
|
+
@authentication = create(:authentication)
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'existing user' do
|
18
|
+
let(:params) { {
|
19
|
+
application_id: @authentication.application_id,
|
20
|
+
omniauth_response: @authentication.omniauth,
|
21
|
+
user_id: @authentication.user_id
|
22
|
+
} }
|
23
|
+
|
24
|
+
context 'existing authentication' do
|
25
|
+
it 'returns the existing user' do
|
26
|
+
response.success?.should == true
|
27
|
+
response.result.should == UserSerializer.resource(@authentication.user)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'new authentication' do
|
32
|
+
before do
|
33
|
+
@authentication.uid += '_OLD'
|
34
|
+
@authentication.save!
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns the existing user' do
|
38
|
+
response.success?.should == true
|
39
|
+
response.result.should == UserSerializer.resource(@authentication.user)
|
40
|
+
@authentication.user.authentications.length.should == 2
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'new user' do
|
46
|
+
let(:params) {
|
47
|
+
@authentication.omniauth['uid'] += '_new'
|
48
|
+
{
|
49
|
+
application_id: @authentication.application_id,
|
50
|
+
omniauth_response: @authentication.omniauth
|
51
|
+
} }
|
52
|
+
|
53
|
+
context 'new authentication' do
|
54
|
+
it 'created a new user and authentication' do
|
55
|
+
@existing_user_count = User.count
|
56
|
+
@existing_auth_count = Authentication.count
|
57
|
+
response.success?.should == true
|
58
|
+
User.count.should == @existing_user_count + 1
|
59
|
+
Authentication.count.should == @existing_auth_count + 1
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :authentication, :class => RestPack::User::Service::Models::Authentication do
|
3
|
+
user
|
4
|
+
application_id { user.application_id }
|
5
|
+
provider 'twitter'
|
6
|
+
sequence(:uid) {|n| "UID_#{n}" }
|
7
|
+
omniauth {
|
8
|
+
{
|
9
|
+
provider: provider,
|
10
|
+
uid: uid,
|
11
|
+
info: {
|
12
|
+
name: 'Gavin Joyce',
|
13
|
+
nickname: 'gavinjoyce',
|
14
|
+
email: 'gavinjoyce@gmail.com',
|
15
|
+
location: 'Dublin, Ireland',
|
16
|
+
description: 'Building cool things with Ruby & Ember.js'
|
17
|
+
}
|
18
|
+
}.to_json
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :user, :class => RestPack::User::Service::Models::User do
|
3
|
+
sequence(:application_id)
|
4
|
+
sequence(:description) {|n| "Description ##{n}" }
|
5
|
+
sequence(:email) {|n| "email ##{n}" }
|
6
|
+
sequence(:image) {|n| "image ##{n}" }
|
7
|
+
sequence(:location) {|n| "location ##{n}" }
|
8
|
+
sequence(:name) {|n| "name ##{n}" }
|
9
|
+
sequence(:nickname) {|n| "nickname ##{n}" }
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RestPack::User::Service::Models::Authentication do
|
4
|
+
it { should validate_presence_of(:application_id) }
|
5
|
+
it { should validate_presence_of(:omniauth) }
|
6
|
+
it { should validate_presence_of(:provider) }
|
7
|
+
it { should validate_presence_of(:uid) }
|
8
|
+
it { should validate_presence_of(:user_id) }
|
9
|
+
|
10
|
+
it { should ensure_length_of(:provider).is_at_most(128) }
|
11
|
+
it { should ensure_length_of(:uid).is_at_most(1024) }
|
12
|
+
|
13
|
+
it { should belong_to(:user) }
|
14
|
+
it { subject.class.table_name.should == 'restpack_authentications' }
|
15
|
+
|
16
|
+
let(:application_id) { 123 }
|
17
|
+
let(:omniauth) { {
|
18
|
+
'provider' => 'twitter',
|
19
|
+
'uid' => 'gavinjoyce',
|
20
|
+
'email' => 'gavinjoyce@gmail.com'
|
21
|
+
} }
|
22
|
+
|
23
|
+
describe '#from_omniauth' do
|
24
|
+
it "constructs a new Authentication" do
|
25
|
+
authentication = subject.class.from_omniauth(application_id, omniauth)
|
26
|
+
authentication.id.should == nil
|
27
|
+
authentication.application_id.should == application_id
|
28
|
+
authentication.provider.should == 'twitter'
|
29
|
+
authentication.uid.should == 'gavinjoyce'
|
30
|
+
authentication.omniauth.should == omniauth
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#get_from_omniauth' do
|
35
|
+
context "a valid omniauth" do
|
36
|
+
before do
|
37
|
+
@user_id = 999
|
38
|
+
@auth = subject.class.from_omniauth(application_id, omniauth)
|
39
|
+
@auth.user_id = @user_id
|
40
|
+
@auth.save!
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns the correct authentication" do
|
44
|
+
auth = subject.class.get_by_omniauth(application_id, @auth.omniauth)
|
45
|
+
auth.id.should == @auth.id
|
46
|
+
auth.user_id.should == @user_id
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RestPack::User::Service::Models::User do
|
4
|
+
it { should validate_presence_of(:application_id) }
|
5
|
+
it { should ensure_length_of(:name).is_at_most(128) }
|
6
|
+
it { should ensure_length_of(:nickname).is_at_most(128) }
|
7
|
+
it { should ensure_length_of(:email).is_at_most(512) }
|
8
|
+
it { should ensure_length_of(:image).is_at_most(1024) }
|
9
|
+
it { should ensure_length_of(:location).is_at_most(512) }
|
10
|
+
it { should ensure_length_of(:description).is_at_most(1024) }
|
11
|
+
it { subject.class.table_name.should == 'restpack_users' }
|
12
|
+
|
13
|
+
describe "#authenticate" do
|
14
|
+
pending
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'restpack_service/support/spec_helper'
|
2
|
+
require 'restpack_user_service'
|
3
|
+
|
4
|
+
config = YAML.load_file('./config/database.yml')
|
5
|
+
ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'] || config['test'])
|
6
|
+
|
7
|
+
migrations_path = File.dirname(__FILE__) + "/../db/migrate"
|
8
|
+
migrator = ActiveRecord::Migrator.new(:up, migrations_path)
|
9
|
+
migrator.migrate
|
10
|
+
|
11
|
+
FactoryGirl.find_definitions
|
12
|
+
|
13
|
+
DatabaseCleaner.strategy = :transaction
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.include FactoryGirl::Syntax::Methods
|
17
|
+
|
18
|
+
config.before(:each) do
|
19
|
+
DatabaseCleaner.start
|
20
|
+
end
|
21
|
+
|
22
|
+
config.after(:each) do
|
23
|
+
DatabaseCleaner.clean
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,259 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: restpack_user_service
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gavin Joyce
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: restpack_service
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: restpack_serializer
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: restpack_gem
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sinatra
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.4.3
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.4.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pg
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.16'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.16'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: require_all
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.3.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.3.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bundler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.3'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.3'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: database_cleaner
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.0.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.0.1
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rake
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rspec
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: bump
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: shoulda-matchers
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ~>
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 1.4.2
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ~>
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 1.4.2
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: factory_girl
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ~>
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '4.0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ~>
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '4.0'
|
195
|
+
description: Users and Authentications service
|
196
|
+
email:
|
197
|
+
- gavinjoyce@gmail.com
|
198
|
+
executables: []
|
199
|
+
extensions: []
|
200
|
+
extra_rdoc_files: []
|
201
|
+
files:
|
202
|
+
- .gitignore
|
203
|
+
- .rspec
|
204
|
+
- .travis.yml
|
205
|
+
- Gemfile
|
206
|
+
- LICENSE.txt
|
207
|
+
- README.md
|
208
|
+
- Rakefile
|
209
|
+
- config/database.yml
|
210
|
+
- db/migrate/20130807130942_create_users.rb
|
211
|
+
- db/migrate/20130807130949_create_authentications.rb
|
212
|
+
- lib/restpack_user_service.rb
|
213
|
+
- lib/restpack_user_service/commands/user/get.rb
|
214
|
+
- lib/restpack_user_service/commands/user/omni_authenticate.rb
|
215
|
+
- lib/restpack_user_service/configuration.rb
|
216
|
+
- lib/restpack_user_service/models/authentication.rb
|
217
|
+
- lib/restpack_user_service/models/user.rb
|
218
|
+
- lib/restpack_user_service/serializers/user_serializer.rb
|
219
|
+
- lib/restpack_user_service/version.rb
|
220
|
+
- restpack_user_service.gemspec
|
221
|
+
- spec/commands/user/get_spec.rb
|
222
|
+
- spec/commands/user/omni_authenticate_spec.rb
|
223
|
+
- spec/factories/authentication_factory.rb
|
224
|
+
- spec/factories/user_factory.rb
|
225
|
+
- spec/models/authentication_spec.rb
|
226
|
+
- spec/models/user_spec.rb
|
227
|
+
- spec/spec_helper.rb
|
228
|
+
homepage: https://github.com/RestPack
|
229
|
+
licenses:
|
230
|
+
- MIT
|
231
|
+
metadata: {}
|
232
|
+
post_install_message:
|
233
|
+
rdoc_options: []
|
234
|
+
require_paths:
|
235
|
+
- lib
|
236
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
237
|
+
requirements:
|
238
|
+
- - '>='
|
239
|
+
- !ruby/object:Gem::Version
|
240
|
+
version: '0'
|
241
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
242
|
+
requirements:
|
243
|
+
- - '>='
|
244
|
+
- !ruby/object:Gem::Version
|
245
|
+
version: '0'
|
246
|
+
requirements: []
|
247
|
+
rubyforge_project:
|
248
|
+
rubygems_version: 2.0.7
|
249
|
+
signing_key:
|
250
|
+
specification_version: 4
|
251
|
+
summary: Users and Authentications
|
252
|
+
test_files:
|
253
|
+
- spec/commands/user/get_spec.rb
|
254
|
+
- spec/commands/user/omni_authenticate_spec.rb
|
255
|
+
- spec/factories/authentication_factory.rb
|
256
|
+
- spec/factories/user_factory.rb
|
257
|
+
- spec/models/authentication_spec.rb
|
258
|
+
- spec/models/user_spec.rb
|
259
|
+
- spec/spec_helper.rb
|