restpack_group_service 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -3
- data/db/migrate/{20130918110826_create_groups.rb → 20130918110827_create_groups.rb} +1 -1
- data/db/migrate/{20130918113133_create_invitations.rb → 20130918113135_create_invitations.rb} +2 -1
- data/db/migrate/{20130918113142_create_memberships.rb → 20130918113143_create_memberships.rb} +1 -1
- data/db/migrate/20131108130143_create_configurations.rb +10 -0
- data/lib/restpack_group_service.rb +3 -1
- data/lib/restpack_group_service/commands/configuration/get.rb +15 -0
- data/lib/restpack_group_service/commands/configuration/update.rb +33 -0
- data/lib/restpack_group_service/commands/group/create.rb +14 -21
- data/lib/restpack_group_service/commands/group/get.rb +16 -14
- data/lib/restpack_group_service/commands/group/list.rb +21 -22
- data/lib/restpack_group_service/commands/invitation/create.rb +49 -0
- data/lib/restpack_group_service/commands/invitation/rsvp.rb +29 -0
- data/lib/restpack_group_service/commands/membership/list.rb +22 -23
- data/lib/restpack_group_service/models/configuration.rb +12 -0
- data/lib/restpack_group_service/models/group.rb +2 -2
- data/lib/restpack_group_service/models/invitation.rb +22 -7
- data/lib/restpack_group_service/models/membership.rb +2 -2
- data/lib/restpack_group_service/serializers/configuration.rb +14 -0
- data/lib/restpack_group_service/serializers/group.rb +2 -2
- data/lib/restpack_group_service/serializers/invitation.rb +13 -0
- data/lib/restpack_group_service/serializers/membership.rb +2 -2
- data/lib/restpack_group_service/version.rb +1 -1
- data/restpack_group_service.gemspec +1 -0
- data/spec/commands/configuration/get_spec.rb +43 -0
- data/spec/commands/configuration/update_spec.rb +28 -0
- data/spec/commands/group/create_spec.rb +4 -36
- data/spec/commands/group/get_spec.rb +2 -2
- data/spec/commands/group/list_spec.rb +2 -2
- data/spec/commands/invitation/create_spec.rb +8 -0
- data/spec/commands/invitation/rsvp_spec.rb +73 -0
- data/spec/commands/membership/list_spec.rb +2 -2
- data/spec/factories/api_group_factory.rb +11 -0
- data/spec/factories/api_invitation_factory.rb +10 -0
- data/spec/factories/group_factory.rb +1 -1
- data/spec/factories/invitation_factory.rb +2 -1
- data/spec/models/configuration_spec.rb +5 -0
- data/spec/models/group_spec.rb +1 -1
- data/spec/models/{invitiation_spec.rb → invitation_spec.rb} +24 -3
- data/spec/models/membership_spec.rb +1 -1
- metadata +43 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68180be95743e5008442414f2063cf1582a6a5a3
|
4
|
+
data.tar.gz: 819eca2f6575920ad8d3c679df00285120819fe4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2973637a39e8d16e6ed12f818e1fa0c65887f6bd7f9a969900aa895046f65b3105f693ffd6a3d8f1a2ff45d3d67eeb7bb8dde56aac9215e7d1220a07ec66251c
|
7
|
+
data.tar.gz: 28e560019d656534bde6d7f31d8b6fc2f0549874a7f68ba8fbaa28edfb3bf54ca59d89ce52e496336d55065a61ca2611ca81c22bdacf855187af3d4d0d0c15c8
|
data/Gemfile
CHANGED
data/db/migrate/{20130918113133_create_invitations.rb → 20130918113135_create_invitations.rb}
RENAMED
@@ -1,9 +1,10 @@
|
|
1
1
|
class CreateInvitations < ActiveRecord::Migration
|
2
2
|
def change
|
3
|
-
create_table :
|
3
|
+
create_table :restpack_group_invitations do |t|
|
4
4
|
t.integer :application_id, :null => false
|
5
5
|
t.integer :group_id, :null => false
|
6
6
|
t.integer :inviter_id, :null => false
|
7
|
+
t.string :inviter_name, :limit => 128
|
7
8
|
t.integer :invitee_id
|
8
9
|
t.integer :status_id, :null => false
|
9
10
|
t.string :email, :limit => 512
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Commands::Groups::Configuration
|
2
|
+
class Get < RestPack::Service::Command
|
3
|
+
required do
|
4
|
+
integer :application_id
|
5
|
+
end
|
6
|
+
|
7
|
+
def execute
|
8
|
+
models = Models::Groups::Configuration.find_or_create_by({
|
9
|
+
application_id: inputs[:application_id]
|
10
|
+
})
|
11
|
+
|
12
|
+
Serializers::Groups::Configuration.serialize(models)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Commands::Groups::Configuration
|
2
|
+
class Update < RestPack::Service::Command
|
3
|
+
required do
|
4
|
+
array :configurations do
|
5
|
+
hash do
|
6
|
+
required do
|
7
|
+
integer :id
|
8
|
+
string :rsvp_url
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute
|
15
|
+
result = {
|
16
|
+
configurations: []
|
17
|
+
}
|
18
|
+
|
19
|
+
Models::Groups::Configuration.transaction do
|
20
|
+
inputs[:configurations].each do |configuration|
|
21
|
+
model = Models::Groups::Configuration.find configuration[:id]
|
22
|
+
model.data = {
|
23
|
+
rsvp_url: configuration[:rsvp_url]
|
24
|
+
}
|
25
|
+
model.save!
|
26
|
+
result[:configurations] << Serializers::Groups::Configuration.as_json(model)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
return result
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,28 +1,21 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
1
|
+
module Commands::Groups::Group
|
2
|
+
class Create < RestPack::Service::Commands::Create
|
3
|
+
required do
|
4
|
+
array :groups do
|
5
|
+
hash do
|
6
|
+
required do
|
7
|
+
integer :application_id
|
8
|
+
integer :created_by
|
9
|
+
string :name
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
12
|
+
optional do
|
13
|
+
integer :account_id
|
14
|
+
string :description
|
15
|
+
boolean :invitation_required
|
18
16
|
end
|
19
17
|
end
|
20
18
|
end
|
21
|
-
|
22
|
-
def execute
|
23
|
-
groups = Models::Group.create!(inputs[:groups])
|
24
|
-
Serializers::Group.serialize(groups)
|
25
|
-
end
|
26
19
|
end
|
27
20
|
end
|
28
21
|
end
|
@@ -1,19 +1,21 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
module Commands::Groups::Group
|
2
|
+
class Get < RestPack::Service::Command
|
3
|
+
required do
|
4
|
+
string :id
|
5
|
+
integer :application_id
|
6
|
+
end
|
7
|
+
|
8
|
+
optional do
|
9
|
+
string :include
|
10
|
+
end
|
8
11
|
|
9
|
-
|
10
|
-
|
12
|
+
def execute
|
13
|
+
result = Serializers::Groups::Group.resource(inputs)
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
15
|
+
if result[:groups].empty?
|
16
|
+
status :not_found
|
17
|
+
else
|
18
|
+
result
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
@@ -1,29 +1,28 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
optional do
|
9
|
-
integer :account_id
|
10
|
-
integer :created_by
|
11
|
-
boolean :is_account_group, default: false
|
12
|
-
integer :page
|
13
|
-
integer :page_size
|
14
|
-
end
|
1
|
+
module Commands::Groups::Group
|
2
|
+
class List < RestPack::Service::Command
|
3
|
+
required do
|
4
|
+
integer :application_id
|
5
|
+
end
|
15
6
|
|
16
|
-
|
17
|
-
|
7
|
+
optional do
|
8
|
+
integer :account_id
|
9
|
+
integer :created_by
|
10
|
+
boolean :is_account_group, default: false
|
11
|
+
string :include
|
12
|
+
integer :page
|
13
|
+
integer :page_size
|
14
|
+
end
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
else
|
22
|
-
scope = scope.where("account_id IS NULL") unless account_id
|
23
|
-
end
|
16
|
+
def execute
|
17
|
+
scope = Models::Groups::Group.all
|
24
18
|
|
25
|
-
|
19
|
+
if is_account_group
|
20
|
+
scope = scope.where("account_id IS NOT NULL")
|
21
|
+
else
|
22
|
+
scope = scope.where("account_id IS NULL") unless account_id
|
26
23
|
end
|
24
|
+
|
25
|
+
Serializers::Groups::Group.resource(inputs, scope)
|
27
26
|
end
|
28
27
|
end
|
29
28
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Commands::Groups::Invitation
|
2
|
+
class Create < RestPack::Service::Command
|
3
|
+
required do
|
4
|
+
array :invitations do
|
5
|
+
hash do
|
6
|
+
required do
|
7
|
+
integer :application_id
|
8
|
+
integer :group_id
|
9
|
+
integer :inviter_id
|
10
|
+
string :inviter_name
|
11
|
+
end
|
12
|
+
|
13
|
+
optional do
|
14
|
+
string :email
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def execute
|
21
|
+
invitations = Models::Groups::Invitation.create!(inputs[:invitations])
|
22
|
+
send_email(invitations)
|
23
|
+
Serializers::Groups::Invitation.serialize(invitations)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def send_email(invitations)
|
29
|
+
invitations.each do |invitation|
|
30
|
+
if invitation.email
|
31
|
+
rsvp_url = invitation.configuration.data['rsvp_url']
|
32
|
+
|
33
|
+
Messaging::Email::Send.run!({
|
34
|
+
application_id: invitation.application_id,
|
35
|
+
template: 'group.invitation',
|
36
|
+
to: invitation.email,
|
37
|
+
data: {
|
38
|
+
inviter_name: invitation.inviter_name,
|
39
|
+
access_key: invitation.access_key,
|
40
|
+
group_name: invitation.group.name,
|
41
|
+
accept_url: "#{rsvp_url}?access_key=#{invitation.access_key}",
|
42
|
+
reject_url: "#{rsvp_url}?access_key=#{invitation.access_key}&accept=false"
|
43
|
+
}
|
44
|
+
})
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Commands::Groups::Invitation
|
2
|
+
class Rsvp < RestPack::Service::Command
|
3
|
+
required do
|
4
|
+
integer :application_id
|
5
|
+
integer :user_id
|
6
|
+
string :access_key
|
7
|
+
boolean :accept, default: true
|
8
|
+
end
|
9
|
+
|
10
|
+
def execute
|
11
|
+
invitation = Models::Groups::Invitation.find_by({
|
12
|
+
application_id: inputs[:application_id],
|
13
|
+
access_key: inputs[:access_key]
|
14
|
+
})
|
15
|
+
|
16
|
+
if invitation
|
17
|
+
if inputs[:accept]
|
18
|
+
membership = invitation.accept(inputs[:user_id])
|
19
|
+
else
|
20
|
+
invitation.reject(inputs[:user_id])
|
21
|
+
end
|
22
|
+
|
23
|
+
Serializers::Groups::Invitation.serialize(invitation)
|
24
|
+
else
|
25
|
+
status :not_found unless invitation
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,29 +1,28 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
optional do
|
9
|
-
integer :account_id
|
10
|
-
integer :group_id
|
11
|
-
integer :user_id
|
12
|
-
boolean :is_account_group, default: false
|
13
|
-
integer :page
|
14
|
-
integer :page_size
|
15
|
-
end
|
1
|
+
module Commands::Groups::Membership
|
2
|
+
class List < RestPack::Service::Command
|
3
|
+
required do
|
4
|
+
integer :application_id
|
5
|
+
end
|
16
6
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
7
|
+
optional do
|
8
|
+
integer :account_id
|
9
|
+
integer :group_id
|
10
|
+
integer :user_id
|
11
|
+
boolean :is_account_group, default: false
|
12
|
+
integer :page
|
13
|
+
integer :page_size
|
14
|
+
string :include
|
15
|
+
end
|
24
16
|
|
25
|
-
|
17
|
+
def execute
|
18
|
+
scope = Models::Groups::Membership.all
|
19
|
+
if is_account_group
|
20
|
+
scope = scope.where("account_id IS NOT NULL")
|
21
|
+
else
|
22
|
+
scope = scope.where("account_id IS NULL") unless account_id
|
26
23
|
end
|
24
|
+
|
25
|
+
Serializers::Groups::Membership.resource(inputs, scope)
|
27
26
|
end
|
28
27
|
end
|
29
28
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Models::Groups
|
2
|
+
class Configuration < ActiveRecord::Base
|
3
|
+
self.table_name = :restpack_group_configurations
|
4
|
+
|
5
|
+
attr_accessible :application_id, :data
|
6
|
+
validates_presence_of :application_id
|
7
|
+
|
8
|
+
after_initialize -> {
|
9
|
+
self.data ||= {}
|
10
|
+
}
|
11
|
+
end
|
12
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
module
|
1
|
+
module Models::Groups
|
2
2
|
class Group < ActiveRecord::Base
|
3
|
-
self.table_name = :
|
3
|
+
self.table_name = :restpack_group_groups
|
4
4
|
|
5
5
|
attr_accessible :application_id, :account_id, :created_by, :name, :description, :invitation_required
|
6
6
|
validates_presence_of :application_id, :created_by, :name
|
@@ -1,13 +1,19 @@
|
|
1
|
-
module
|
1
|
+
module Models::Groups
|
2
2
|
class Invitation < ActiveRecord::Base
|
3
|
-
self.table_name = :
|
3
|
+
self.table_name = :restpack_group_invitations
|
4
4
|
|
5
|
-
STATUS = {
|
5
|
+
STATUS = {
|
6
|
+
pending: 0, available: 1, accepted: 2,
|
7
|
+
rejected: 3, cancelled: 4, expired: 5
|
8
|
+
}
|
6
9
|
attr_accessor :access_key_length, :status
|
7
|
-
attr_accessible :access_key_length, :application_id, :email, :expires_at,
|
10
|
+
attr_accessible :access_key_length, :application_id, :email, :expires_at,
|
11
|
+
:group_id, :invitee_id, :inviter_id, :inviter_name,
|
12
|
+
:remaining_uses, :status
|
8
13
|
|
9
|
-
validates_presence_of :application_id, :group_id, :inviter_id, :status_id
|
14
|
+
validates_presence_of :application_id, :group_id, :inviter_id, :inviter_name, :status_id
|
10
15
|
validates :email, :length => { maximum: 512 }
|
16
|
+
validates :inviter_name, :length => { maximum: 128 }
|
11
17
|
validates :access_key, :length => { maximum: 128 }
|
12
18
|
|
13
19
|
belongs_to :group
|
@@ -34,6 +40,10 @@ module RestPack::Group::Service::Models
|
|
34
40
|
write_attribute(:status_id, STATUS[status])
|
35
41
|
end
|
36
42
|
|
43
|
+
def configuration
|
44
|
+
Configuration.find_or_create_by({ application_id: self.application_id })
|
45
|
+
end
|
46
|
+
|
37
47
|
def self.accept(application_id, user_id, access_key) #TODO: GJ: skip if already a member
|
38
48
|
invitation = self.available.by_application_id(application_id).by_access_key(access_key).first
|
39
49
|
|
@@ -54,15 +64,20 @@ module RestPack::Group::Service::Models
|
|
54
64
|
end
|
55
65
|
end
|
56
66
|
|
67
|
+
def reject(user_id)
|
68
|
+
validate! user_id
|
69
|
+
self.use! false
|
70
|
+
end
|
71
|
+
|
57
72
|
def self.access_key_unique?(application_id, access_key)
|
58
73
|
self.by_application_id(application_id).by_access_key(access_key).empty?
|
59
74
|
end
|
60
75
|
|
61
76
|
protected
|
62
77
|
|
63
|
-
def use!
|
78
|
+
def use!(accept = true)
|
64
79
|
if single_use?
|
65
|
-
self.status = :accepted
|
80
|
+
self.status = accept ? :accepted : :rejected
|
66
81
|
else
|
67
82
|
self.remaining_uses -= 1
|
68
83
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
module
|
1
|
+
module Models::Groups
|
2
2
|
class Membership < ActiveRecord::Base
|
3
|
-
self.table_name = :
|
3
|
+
self.table_name = :restpack_group_memberships
|
4
4
|
|
5
5
|
attr_accessible :application_id, :account_id, :group_id, :invitation_id, :user_id
|
6
6
|
validates_presence_of :application_id, :group_id, :user_id
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Serializers::Groups
|
2
|
+
class Configuration
|
3
|
+
include RestPack::Serializer
|
4
|
+
|
5
|
+
self.model_class = Models::Groups::Configuration
|
6
|
+
self.key = :configurations
|
7
|
+
|
8
|
+
attributes :id, :application_id, :rsvp_url
|
9
|
+
|
10
|
+
def rsvp_url
|
11
|
+
@model.data['rsvp_url']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
module
|
1
|
+
module Serializers::Groups
|
2
2
|
class Group
|
3
3
|
include RestPack::Serializer
|
4
4
|
|
5
|
-
self.model_class = Models::Group
|
5
|
+
self.model_class = Models::Groups::Group
|
6
6
|
self.key = :groups
|
7
7
|
|
8
8
|
attributes :id, :application_id, :account_id, :created_by, :name,
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Serializers::Groups
|
2
|
+
class Invitation
|
3
|
+
include RestPack::Serializer
|
4
|
+
|
5
|
+
self.model_class = Models::Groups::Invitation
|
6
|
+
self.key = :invitations
|
7
|
+
|
8
|
+
attributes :id, :application_id, :group_id, :inviter_id, :invitee_id,
|
9
|
+
:expires_at, :remaining_uses, :href
|
10
|
+
can_include :groups
|
11
|
+
can_filter_by :application_id, :inviter_id, :invitee_id
|
12
|
+
end
|
13
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
module
|
1
|
+
module Serializers::Groups
|
2
2
|
class Membership
|
3
3
|
include RestPack::Serializer
|
4
4
|
|
5
|
-
self.model_class = Models::Membership
|
5
|
+
self.model_class = Models::Groups::Membership
|
6
6
|
self.key = :memberships
|
7
7
|
|
8
8
|
attributes :id, :application_id, :account_id, :group_id, :user_id,
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency "restpack_service"
|
22
|
+
spec.add_dependency "restpack_service_messaging"
|
22
23
|
|
23
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
25
|
spec.add_development_dependency "database_cleaner", "~> 1.0.1"
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Commands::Groups::Configuration::Get do
|
4
|
+
is_required :application_id
|
5
|
+
|
6
|
+
let(:response) { subject.class.run(params) }
|
7
|
+
let(:params) { {} }
|
8
|
+
|
9
|
+
context 'when no record exists' do
|
10
|
+
let(:params) { {
|
11
|
+
application_id: 123
|
12
|
+
} }
|
13
|
+
|
14
|
+
it 'return new configurations' do
|
15
|
+
response.success?.should == true
|
16
|
+
response.result[:configurations].length.should == 1
|
17
|
+
response.result[:configurations].first[:id].should_not == ''
|
18
|
+
response.result[:configurations].first[:application_id].should == 123
|
19
|
+
response.result[:configurations].first[:rsvp_url].should == nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when a record exists' do
|
24
|
+
before do
|
25
|
+
@configuration = Models::Groups::Configuration.create({
|
26
|
+
application_id: 123,
|
27
|
+
data: { 'rsvp_url' => 'http://somewhere.org/rsvp' }
|
28
|
+
})
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:params) { {
|
32
|
+
application_id: @configuration.application_id
|
33
|
+
} }
|
34
|
+
|
35
|
+
it 'returns the settings' do
|
36
|
+
response.success?.should == true
|
37
|
+
configurations = response.result[:configurations]
|
38
|
+
configurations.length.should == 1
|
39
|
+
configurations.first[:id].should == @configuration.id.to_s
|
40
|
+
configurations.first[:rsvp_url].should == 'http://somewhere.org/rsvp'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Commands::Groups::Configuration::Update do
|
4
|
+
let(:response) { subject.class.run(params) }
|
5
|
+
|
6
|
+
before do
|
7
|
+
@configuration = Models::Groups::Configuration.create({
|
8
|
+
application_id: 123,
|
9
|
+
data: { 'rsvp_url' => 'http://somewhere.org/rsvp' }
|
10
|
+
})
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:params) { {
|
14
|
+
configurations: [{
|
15
|
+
id: @configuration.id,
|
16
|
+
rsvp_url: 'http://new.io/rsvp'
|
17
|
+
}]
|
18
|
+
} }
|
19
|
+
|
20
|
+
it 'updates the configuration' do
|
21
|
+
response.success?.should == true
|
22
|
+
response.result[:configurations].length.should == 1
|
23
|
+
|
24
|
+
@configuration.reload
|
25
|
+
@configuration.data['rsvp_url'].should == 'http://new.io/rsvp'
|
26
|
+
response.result[:configurations].first == Serializers::Groups::Configuration.as_json(@configuration)
|
27
|
+
end
|
28
|
+
end
|
@@ -1,39 +1,7 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Commands::Group::Create do
|
4
|
-
|
5
|
-
# is_required :application_id, :created_by, :name
|
6
|
-
# is_optional :account_id, :description, :invitation_required
|
3
|
+
describe Commands::Groups::Group::Create do
|
4
|
+
it_acts_as_create_command(:groups, :group)
|
7
5
|
|
8
|
-
|
9
|
-
let(:response) { subject.class.run(params) }
|
10
|
-
|
11
|
-
context 'with valid params' do
|
12
|
-
let(:group) { {
|
13
|
-
application_id: 123,
|
14
|
-
created_by: 234,
|
15
|
-
name: 'My New Group',
|
16
|
-
account_id: 345,
|
17
|
-
description: 'this is the description',
|
18
|
-
invitation_required: true
|
19
|
-
} }
|
20
|
-
let(:params) { {
|
21
|
-
groups: [group]
|
22
|
-
} }
|
23
|
-
|
24
|
-
it 'returns the newly created group' do
|
25
|
-
response.success?.should == true
|
26
|
-
|
27
|
-
groups = response.result[:groups]
|
28
|
-
groups.length.should == 1
|
29
|
-
|
30
|
-
groups.first[:application_id].should == 123
|
31
|
-
groups.first[:created_by].should == 234
|
32
|
-
groups.first[:name].should == "My New Group"
|
33
|
-
groups.first[:account_id].should == 345
|
34
|
-
groups.first[:description].should == 'this is the description'
|
35
|
-
groups.first[:invitation_required].should == true
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
6
|
+
pending 'validate command inputs'
|
39
7
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Commands::Groups::Invitation::Rsvp do
|
4
|
+
let(:response) { subject.class.run(params) }
|
5
|
+
let(:params) { {} }
|
6
|
+
|
7
|
+
before do
|
8
|
+
@invitation = create(:invitation, email: 'gavin@restpack.org')
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'when accepting' do
|
12
|
+
context 'with valid params' do
|
13
|
+
let(:params) { {
|
14
|
+
application_id: @invitation.application_id,
|
15
|
+
access_key: @invitation.access_key,
|
16
|
+
user_id: 142857
|
17
|
+
} }
|
18
|
+
|
19
|
+
it 'adds the user to the group' do
|
20
|
+
response.success?.should == true
|
21
|
+
it_has_membership true, @invitation.group, 142857
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'updates the invite status' do
|
25
|
+
response.success?.should == true
|
26
|
+
@invitation.reload.status.should == :accepted
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with invalid key' do
|
31
|
+
let(:params) { {
|
32
|
+
application_id: @invitation.application_id,
|
33
|
+
access_key: @invitation.access_key + 'invalid',
|
34
|
+
user_id: 142857
|
35
|
+
} }
|
36
|
+
|
37
|
+
it 'fails' do
|
38
|
+
response.success?.should == false
|
39
|
+
response.status.should == :not_found
|
40
|
+
it_has_membership false, @invitation.group, 142857
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when rejecting' do
|
46
|
+
let(:params) { {
|
47
|
+
application_id: @invitation.application_id,
|
48
|
+
access_key: @invitation.access_key,
|
49
|
+
user_id: 142857,
|
50
|
+
accept: false
|
51
|
+
} }
|
52
|
+
|
53
|
+
it 'doesnt add the user to the group' do
|
54
|
+
response.success?.should == true
|
55
|
+
it_has_membership false, @invitation.group, 142857
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'updates the invite status' do
|
59
|
+
response.success?.should == true
|
60
|
+
@invitation.reload.status.should == :rejected
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def it_has_membership(expected, group, user_id)
|
65
|
+
is_member = group.memberships.any? { |member| member.user_id == user_id }
|
66
|
+
|
67
|
+
if expected
|
68
|
+
is_member.should be(true), "User #{user_id} should belong to Group #{group.id}"
|
69
|
+
else
|
70
|
+
is_member.should be(false), "User #{user_id} should not belong to Group #{group.id}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Commands::Membership::List do
|
3
|
+
describe Commands::Groups::Membership::List do
|
4
4
|
is_required :application_id
|
5
5
|
is_optional :account_id, :group_id, :user_id, :is_account_group, :page, :page_size
|
6
6
|
|
@@ -0,0 +1,11 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :api_group, class: Hash do
|
3
|
+
sequence(:name) {|n| "Group ##{n}" }
|
4
|
+
sequence(:description) {|n| "Description ##{n}" }
|
5
|
+
sequence(:application_id)
|
6
|
+
sequence(:created_by)
|
7
|
+
invitation_required true
|
8
|
+
|
9
|
+
initialize_with { attributes }
|
10
|
+
end
|
11
|
+
end
|
data/spec/models/group_spec.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Models::Invitation do
|
3
|
+
describe Models::Groups::Invitation do
|
4
4
|
it { should validate_presence_of(:application_id) }
|
5
5
|
it { should validate_presence_of(:group_id) }
|
6
6
|
it { should validate_presence_of(:inviter_id) }
|
7
|
+
it { should validate_presence_of(:inviter_name) }
|
7
8
|
it { should validate_presence_of(:status_id) }
|
8
9
|
|
9
10
|
it { should ensure_length_of(:email).is_at_most(512) }
|
11
|
+
it { should ensure_length_of(:inviter_name).is_at_most(128) }
|
10
12
|
it { should ensure_length_of(:access_key).is_at_most(128) }
|
11
13
|
|
12
14
|
it { should_not allow_mass_assignment_of(:access_key) }
|
@@ -14,8 +16,27 @@ describe Models::Invitation do
|
|
14
16
|
it { should belong_to(:group) }
|
15
17
|
it { should have_many(:memberships) }
|
16
18
|
|
17
|
-
Membership = Models::Membership
|
18
|
-
Invitation = Models::Invitation
|
19
|
+
Membership = Models::Groups::Membership
|
20
|
+
Invitation = Models::Groups::Invitation
|
21
|
+
Configuration = Models::Groups::Configuration
|
22
|
+
|
23
|
+
describe ".configuration" do
|
24
|
+
let(:invitation) { create(:invitation, invitee_id: 142857) }
|
25
|
+
context "with existing configuration" do
|
26
|
+
it "resolves the correct configuration" do
|
27
|
+
configuration = Configuration.create({
|
28
|
+
application_id: invitation.application_id
|
29
|
+
})
|
30
|
+
invitation.configuration.should == configuration
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "with no existing configuration" do
|
35
|
+
it "resolves configuration" do
|
36
|
+
invitation.configuration.id.should_not == nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
19
40
|
|
20
41
|
context "when accepting" do
|
21
42
|
context "a valid single-use user invitation" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restpack_group_service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin Joyce
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: restpack_service
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: restpack_service_messaging
|
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'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,32 +151,47 @@ files:
|
|
137
151
|
- README.md
|
138
152
|
- Rakefile
|
139
153
|
- config/database.yml
|
140
|
-
- db/migrate/
|
141
|
-
- db/migrate/
|
142
|
-
- db/migrate/
|
154
|
+
- db/migrate/20130918110827_create_groups.rb
|
155
|
+
- db/migrate/20130918113135_create_invitations.rb
|
156
|
+
- db/migrate/20130918113143_create_memberships.rb
|
157
|
+
- db/migrate/20131108130143_create_configurations.rb
|
143
158
|
- lib/restpack_group_service.rb
|
159
|
+
- lib/restpack_group_service/commands/configuration/get.rb
|
160
|
+
- lib/restpack_group_service/commands/configuration/update.rb
|
144
161
|
- lib/restpack_group_service/commands/group/create.rb
|
145
162
|
- lib/restpack_group_service/commands/group/get.rb
|
146
163
|
- lib/restpack_group_service/commands/group/list.rb
|
164
|
+
- lib/restpack_group_service/commands/invitation/create.rb
|
165
|
+
- lib/restpack_group_service/commands/invitation/rsvp.rb
|
147
166
|
- lib/restpack_group_service/commands/membership/list.rb
|
148
167
|
- lib/restpack_group_service/configuration.rb
|
168
|
+
- lib/restpack_group_service/models/configuration.rb
|
149
169
|
- lib/restpack_group_service/models/group.rb
|
150
170
|
- lib/restpack_group_service/models/invitation.rb
|
151
171
|
- lib/restpack_group_service/models/membership.rb
|
172
|
+
- lib/restpack_group_service/serializers/configuration.rb
|
152
173
|
- lib/restpack_group_service/serializers/group.rb
|
174
|
+
- lib/restpack_group_service/serializers/invitation.rb
|
153
175
|
- lib/restpack_group_service/serializers/membership.rb
|
154
176
|
- lib/restpack_group_service/tasks/db.rake
|
155
177
|
- lib/restpack_group_service/tasks/tasks.rb
|
156
178
|
- lib/restpack_group_service/version.rb
|
157
179
|
- restpack_group_service.gemspec
|
180
|
+
- spec/commands/configuration/get_spec.rb
|
181
|
+
- spec/commands/configuration/update_spec.rb
|
158
182
|
- spec/commands/group/create_spec.rb
|
159
183
|
- spec/commands/group/get_spec.rb
|
160
184
|
- spec/commands/group/list_spec.rb
|
185
|
+
- spec/commands/invitation/create_spec.rb
|
186
|
+
- spec/commands/invitation/rsvp_spec.rb
|
161
187
|
- spec/commands/membership/list_spec.rb
|
188
|
+
- spec/factories/api_group_factory.rb
|
189
|
+
- spec/factories/api_invitation_factory.rb
|
162
190
|
- spec/factories/group_factory.rb
|
163
191
|
- spec/factories/invitation_factory.rb
|
192
|
+
- spec/models/configuration_spec.rb
|
164
193
|
- spec/models/group_spec.rb
|
165
|
-
- spec/models/
|
194
|
+
- spec/models/invitation_spec.rb
|
166
195
|
- spec/models/membership_spec.rb
|
167
196
|
- spec/spec_helper.rb
|
168
197
|
homepage: https://github.com/RestPack
|
@@ -190,13 +219,20 @@ signing_key:
|
|
190
219
|
specification_version: 4
|
191
220
|
summary: Groups, Members and Invitations
|
192
221
|
test_files:
|
222
|
+
- spec/commands/configuration/get_spec.rb
|
223
|
+
- spec/commands/configuration/update_spec.rb
|
193
224
|
- spec/commands/group/create_spec.rb
|
194
225
|
- spec/commands/group/get_spec.rb
|
195
226
|
- spec/commands/group/list_spec.rb
|
227
|
+
- spec/commands/invitation/create_spec.rb
|
228
|
+
- spec/commands/invitation/rsvp_spec.rb
|
196
229
|
- spec/commands/membership/list_spec.rb
|
230
|
+
- spec/factories/api_group_factory.rb
|
231
|
+
- spec/factories/api_invitation_factory.rb
|
197
232
|
- spec/factories/group_factory.rb
|
198
233
|
- spec/factories/invitation_factory.rb
|
234
|
+
- spec/models/configuration_spec.rb
|
199
235
|
- spec/models/group_spec.rb
|
200
|
-
- spec/models/
|
236
|
+
- spec/models/invitation_spec.rb
|
201
237
|
- spec/models/membership_spec.rb
|
202
238
|
- spec/spec_helper.rb
|