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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -3
  3. data/db/migrate/{20130918110826_create_groups.rb → 20130918110827_create_groups.rb} +1 -1
  4. data/db/migrate/{20130918113133_create_invitations.rb → 20130918113135_create_invitations.rb} +2 -1
  5. data/db/migrate/{20130918113142_create_memberships.rb → 20130918113143_create_memberships.rb} +1 -1
  6. data/db/migrate/20131108130143_create_configurations.rb +10 -0
  7. data/lib/restpack_group_service.rb +3 -1
  8. data/lib/restpack_group_service/commands/configuration/get.rb +15 -0
  9. data/lib/restpack_group_service/commands/configuration/update.rb +33 -0
  10. data/lib/restpack_group_service/commands/group/create.rb +14 -21
  11. data/lib/restpack_group_service/commands/group/get.rb +16 -14
  12. data/lib/restpack_group_service/commands/group/list.rb +21 -22
  13. data/lib/restpack_group_service/commands/invitation/create.rb +49 -0
  14. data/lib/restpack_group_service/commands/invitation/rsvp.rb +29 -0
  15. data/lib/restpack_group_service/commands/membership/list.rb +22 -23
  16. data/lib/restpack_group_service/models/configuration.rb +12 -0
  17. data/lib/restpack_group_service/models/group.rb +2 -2
  18. data/lib/restpack_group_service/models/invitation.rb +22 -7
  19. data/lib/restpack_group_service/models/membership.rb +2 -2
  20. data/lib/restpack_group_service/serializers/configuration.rb +14 -0
  21. data/lib/restpack_group_service/serializers/group.rb +2 -2
  22. data/lib/restpack_group_service/serializers/invitation.rb +13 -0
  23. data/lib/restpack_group_service/serializers/membership.rb +2 -2
  24. data/lib/restpack_group_service/version.rb +1 -1
  25. data/restpack_group_service.gemspec +1 -0
  26. data/spec/commands/configuration/get_spec.rb +43 -0
  27. data/spec/commands/configuration/update_spec.rb +28 -0
  28. data/spec/commands/group/create_spec.rb +4 -36
  29. data/spec/commands/group/get_spec.rb +2 -2
  30. data/spec/commands/group/list_spec.rb +2 -2
  31. data/spec/commands/invitation/create_spec.rb +8 -0
  32. data/spec/commands/invitation/rsvp_spec.rb +73 -0
  33. data/spec/commands/membership/list_spec.rb +2 -2
  34. data/spec/factories/api_group_factory.rb +11 -0
  35. data/spec/factories/api_invitation_factory.rb +10 -0
  36. data/spec/factories/group_factory.rb +1 -1
  37. data/spec/factories/invitation_factory.rb +2 -1
  38. data/spec/models/configuration_spec.rb +5 -0
  39. data/spec/models/group_spec.rb +1 -1
  40. data/spec/models/{invitiation_spec.rb → invitation_spec.rb} +24 -3
  41. data/spec/models/membership_spec.rb +1 -1
  42. metadata +43 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7395223837a8aaa33cbb9054201f46f615a31cd7
4
- data.tar.gz: 81a14c3743bf75865909f8c7ceb28d8f75f7279b
3
+ metadata.gz: 68180be95743e5008442414f2063cf1582a6a5a3
4
+ data.tar.gz: 819eca2f6575920ad8d3c679df00285120819fe4
5
5
  SHA512:
6
- metadata.gz: 14dac8077e3e51a8c791aeec672138406ef8ba0f6e7cc3fe6516ab11a4f21661026a921c21630eaa7f3454d22a80d46995143e3272dc6c0631cabc5830e9502d
7
- data.tar.gz: 52b0a754ab827b3301f0f677de139f3060bca281ab6eb45c89499997ad9d0d164e006a8b6c984fe8d0323462693a6e4efeb65596471f54ccf5eaf24323e7deff
6
+ metadata.gz: 2973637a39e8d16e6ed12f818e1fa0c65887f6bd7f9a969900aa895046f65b3105f693ffd6a3d8f1a2ff45d3d67eeb7bb8dde56aac9215e7d1220a07ec66251c
7
+ data.tar.gz: 28e560019d656534bde6d7f31d8b6fc2f0549874a7f68ba8fbaa28edfb3bf54ca59d89ce52e496336d55065a61ca2611ca81c22bdacf855187af3d4d0d0c15c8
data/Gemfile CHANGED
@@ -1,6 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in restpack_group_service.gemspec
4
3
  gemspec
5
-
6
- gem 'restpack_service', :path => '../restpack_service'
@@ -1,6 +1,6 @@
1
1
  class CreateGroups < ActiveRecord::Migration
2
2
  def change
3
- create_table :restpack_groups do |t|
3
+ create_table :restpack_group_groups do |t|
4
4
  t.integer :application_id, :null => false
5
5
  t.integer :account_id
6
6
  t.integer :created_by, :null => false
@@ -1,9 +1,10 @@
1
1
  class CreateInvitations < ActiveRecord::Migration
2
2
  def change
3
- create_table :restpack_invitations do |t|
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
@@ -1,6 +1,6 @@
1
1
  class CreateMemberships < ActiveRecord::Migration
2
2
  def change
3
- create_table :restpack_memberships do |t|
3
+ create_table :restpack_group_memberships do |t|
4
4
  t.integer :application_id, :null => false
5
5
  t.integer :account_id
6
6
  t.integer :group_id, :null => false
@@ -0,0 +1,10 @@
1
+ class CreateConfigurations < ActiveRecord::Migration
2
+ def change
3
+ create_table :restpack_group_configurations do |t|
4
+ t.integer :application_id, :null => false
5
+ t.integer :domain_id
6
+ t.json :data
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -1,2 +1,4 @@
1
1
  require 'restpack_service'
2
- RestPack::Service::Loader.load 'group'
2
+ require 'restpack_service_messaging'
3
+
4
+ RestPack::Service::Loader.load 'restpack_group_service', 'Groups'
@@ -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 RestPack::Group::Service::Commands
2
- module Group
3
- class Create < RestPack::Service::Command
4
- required do
5
- array :groups do
6
- hash do
7
- required do
8
- integer :application_id
9
- integer :created_by
10
- string :name
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
- optional do
14
- integer :account_id
15
- string :description
16
- boolean :invitation_required
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 RestPack::Group::Service::Commands
2
- module Group
3
- class Get < RestPack::Service::Command
4
- required do
5
- integer :id
6
- integer :application_id
7
- end
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
- def execute
10
- result = Serializers::Group.resource(inputs)
12
+ def execute
13
+ result = Serializers::Groups::Group.resource(inputs)
11
14
 
12
- if result[:groups].empty?
13
- status :not_found
14
- else
15
- result
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 RestPack::Group::Service::Commands
2
- module Group
3
- class List < RestPack::Service::Command
4
- required do
5
- integer :application_id
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
- def execute
17
- scope = Models::Group.all
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
- 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
23
- end
16
+ def execute
17
+ scope = Models::Groups::Group.all
24
18
 
25
- Serializers::Group.resource(inputs, scope)
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 RestPack::Group::Service::Commands
2
- module Membership
3
- class List < RestPack::Service::Command
4
- required do
5
- integer :application_id
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
- def execute
18
- scope = Models::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
23
- end
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
- Serializers::Membership.resource(inputs, scope)
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 RestPack::Group::Service::Models
1
+ module Models::Groups
2
2
  class Group < ActiveRecord::Base
3
- self.table_name = :restpack_groups
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 RestPack::Group::Service::Models
1
+ module Models::Groups
2
2
  class Invitation < ActiveRecord::Base
3
- self.table_name = :restpack_invitations
3
+ self.table_name = :restpack_group_invitations
4
4
 
5
- STATUS = { pending: 0, available: 1, accepted: 2, cancelled: 3, expired: 4 }
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, :group_id, :invitee_id, :inviter_id, :remaining_uses, :status
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 RestPack::Group::Service::Models
1
+ module Models::Groups
2
2
  class Membership < ActiveRecord::Base
3
- self.table_name = :restpack_memberships
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 RestPack::Group::Service::Serializers
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 RestPack::Group::Service::Serializers
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,
@@ -1,7 +1,7 @@
1
1
  module RestPack
2
2
  module Group
3
3
  module Service
4
- VERSION = "0.0.7"
4
+ VERSION = "0.0.8"
5
5
  end
6
6
  end
7
7
  end
@@ -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
- require_relative '../../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
- describe Commands::Group::Create do
4
- #TODO: GJ: validate array
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
- context 'creating a group' do
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
@@ -1,6 +1,6 @@
1
- require_relative '../../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
- describe Commands::Group::Get do
3
+ describe Commands::Groups::Group::Get do
4
4
  is_required :id, :application_id
5
5
 
6
6
  let(:response) { subject.class.run(params) }
@@ -1,6 +1,6 @@
1
- require_relative '../../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
- describe Commands::Group::List do
3
+ describe Commands::Groups::Group::List do
4
4
  is_required :application_id
5
5
  is_optional :account_id, :created_by, :is_account_group, :page, :page_size
6
6
 
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe Commands::Groups::Invitation::Create do
4
+ it_acts_as_create_command(:groups, :invitation)
5
+
6
+ pending 'validate command inputs'
7
+ pending 'an email should be sent if email param is present'
8
+ 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
- require_relative '../../spec_helper'
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
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+ factory :api_invitation, class: Hash do
3
+ sequence(:application_id)
4
+ sequence(:group_id)
5
+ sequence(:inviter_id)
6
+ sequence(:inviter_name) {|n| "Inviter ##{n}" }
7
+
8
+ initialize_with { attributes }
9
+ end
10
+ end
@@ -1,5 +1,5 @@
1
1
  FactoryGirl.define do
2
- factory :group, :class => Models::Group do
2
+ factory :group, :class => Models::Groups::Group do
3
3
  sequence(:name) {|n| "Group ##{n}" }
4
4
  sequence(:description) {|n| "Description ##{n}" }
5
5
  sequence(:application_id)
@@ -1,7 +1,8 @@
1
1
  FactoryGirl.define do
2
- factory :invitation, :class => Models::Invitation do
2
+ factory :invitation, :class => Models::Groups::Invitation do
3
3
  sequence(:application_id)
4
4
  sequence(:inviter_id)
5
+ sequence(:inviter_name) {|n| "Inviter ##{n}" }
5
6
  group
6
7
  end
7
8
  end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Models::Groups::Configuration do
4
+ it { should validate_presence_of(:application_id) }
5
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Models::Group do
3
+ describe Models::Groups::Group do
4
4
  it { should validate_presence_of(:application_id) }
5
5
  it { should validate_presence_of(:created_by) }
6
6
  it { should validate_presence_of(:name) }
@@ -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
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Models::Membership do
3
+ describe Models::Groups::Membership 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(:user_id) }
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.7
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-09-21 00:00:00.000000000 Z
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/20130918110826_create_groups.rb
141
- - db/migrate/20130918113133_create_invitations.rb
142
- - db/migrate/20130918113142_create_memberships.rb
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/invitiation_spec.rb
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/invitiation_spec.rb
236
+ - spec/models/invitation_spec.rb
201
237
  - spec/models/membership_spec.rb
202
238
  - spec/spec_helper.rb