restpack_account_service 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ded3d6c136056c70131b2a98844b4599852fecaf
4
- data.tar.gz: b6a4f80fcc816205333cfb98a00c12825748e9b5
3
+ metadata.gz: fd9c6e1c2c1bc0bf018d1ba4c89acef4d256abe4
4
+ data.tar.gz: 7080c9ec92f4b768ce3384412bbd384ca09e7153
5
5
  SHA512:
6
- metadata.gz: eb8ee27bd4e646ef0d17ae42c149884798585b07a470c1e0d1cd1a51ff56df14aada51719b06210abfddf24fd7d3ffdd7e75b01c6a43384e175e2fbdce6397e8
7
- data.tar.gz: dec55c113bce4008838fb7418b88f4182fdbdd27d055b543fbe36ed86ceecdee3a56b754f6fedb1ef378ff7abd09523caaf77c0faa5e214091213eaef44ff534
6
+ metadata.gz: 55d9a4bcb7c59737d59dd16f4f1ceb285544ccfe9b8f9d7404451aaa3d19e583931c3b9d9d29258c1f8a346a4c3bfd234f3ba57b3c35ac05a2bda341700d17eb
7
+ data.tar.gz: d5cd8d8d752bc9a8688a4d8564f034a2499cd0131bff71e2d307ec5a7ae18711bff51e81952e0c90b4600c12d54ef6963fb33a0edf0d6ea018efc62e6e3eb757
@@ -0,0 +1,11 @@
1
+ class CreateAccounts < ActiveRecord::Migration
2
+ def change
3
+ create_table :restpack_accounts do |t|
4
+ t.integer :created_by, :null => false
5
+ t.integer :application_id, :null => false
6
+ t.string :name, :null => false, :limit => 256
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -1 +1,2 @@
1
- require "restpack_account_service/version"
1
+ require 'restpack_service'
2
+ RestPack::Service::Loader.load 'account', Dir.pwd
@@ -0,0 +1,22 @@
1
+ module RestPack::Account::Service::Commands
2
+ module Account
3
+ class Create < RestPack::Service::Command
4
+ required do
5
+ array :accounts do
6
+ hash do
7
+ required do
8
+ integer :application_id
9
+ integer :created_by
10
+ string :name
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ def execute
17
+ accounts = Models::Account.create!(inputs[:accounts])
18
+ Serializers::Account.serialize(accounts)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module RestPack::Account::Service::Commands
2
+ module Account
3
+ class Get < RestPack::Service::Command
4
+ required do
5
+ integer :id
6
+ integer :application_id
7
+ end
8
+
9
+ def execute
10
+ scope = Models::Account.all
11
+ scope = scope.where(application_id: application_id)
12
+ result = Serializers::Account.resource(inputs, scope)
13
+
14
+ if result[:accounts].empty?
15
+ status :not_found
16
+ else
17
+ result
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ module RestPack::Account::Service
2
+ class Configuration < RestPack::Service::Configuration
3
+
4
+ end
5
+
6
+ mattr_accessor :config
7
+ @@config = Configuration.new
8
+
9
+ def self.setup
10
+ yield @@config
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ module RestPack::Account::Service::Models
2
+ class Account < ActiveRecord::Base
3
+ self.table_name = :restpack_accounts
4
+
5
+ attr_accessible :application_id, :created_by, :name
6
+ validates_presence_of :application_id, :created_by, :name
7
+
8
+ validates :name, :length => { :maximum => 256 }
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module RestPack::Account::Service::Serializers
2
+ class Account
3
+ include RestPack::Serializer
4
+
5
+ self.model_class = Models::Account
6
+ self.key = :accounts
7
+
8
+ attributes :id, :application_id, :created_by, :name, :href
9
+ end
10
+ end
@@ -0,0 +1,39 @@
1
+ namespace :restpack do
2
+ desc "Run any outstanding RestPack migrations"
3
+ task :migrate do
4
+ Rake::Task["restpack:account:migrate"].invoke
5
+ end
6
+
7
+ desc "List RestPack configuration"
8
+ task :configuration do
9
+ Rake::Task["restpack:account:configuration"].invoke
10
+ end
11
+
12
+ namespace :account do
13
+ desc "Run any outstanding RestPack::Account migrations"
14
+ task :migrate => ["connection"] do
15
+ source_migrations_path = File.dirname(__FILE__) + "/../../../db/migrate"
16
+ target_migrations_path = "db/migrate"
17
+
18
+ ActiveRecord::Migration.verbose = true
19
+ ActiveRecord::Migrator.migrate(source_migrations_path)
20
+
21
+ if File.directory?(target_migrations_path)
22
+ FileUtils.cp_r(Dir["#{source_migrations_path}/*"], target_migrations_path)
23
+ end
24
+ end
25
+
26
+ task :connection do
27
+ config = YAML.load(IO.read('config/database.yml'))
28
+ environment = ENV['RAILS_ENV'] || ENV['DB'] || 'development'
29
+ ActiveRecord::Base.establish_connection config[environment]
30
+ end
31
+
32
+ desc "List RestPack::Account::Service configuration"
33
+ task :configuration do
34
+ p "RestPack::Account::Service Configuration"
35
+ p "--------------------------------"
36
+ p "TODO"
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,7 @@
1
+ module RestPack::Account::Service
2
+ class Tasks
3
+ def self.load_tasks
4
+ load "restpack_account_service/tasks/db.rake"
5
+ end
6
+ end
7
+ end
@@ -1,7 +1,7 @@
1
1
  module RestPack
2
2
  module Account
3
3
  module Service
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
6
6
  end
7
7
  end
@@ -19,11 +19,6 @@ 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_serializer"
23
- spec.add_dependency "restpack_gem"
24
- spec.add_dependency "sinatra", "~> 1.4.3"
25
- spec.add_dependency "pg", "~> 0.16.0"
26
- spec.add_dependency "require_all", "~> 1.3.0"
27
22
 
28
23
  spec.add_development_dependency "bundler", "~> 1.3"
29
24
  spec.add_development_dependency "database_cleaner", "~> 1.0.1"
@@ -0,0 +1,32 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe Commands::Account::Create do
4
+ #TODO: GJ: validate array
5
+ # is_required :created_by, :name
6
+
7
+ context 'creating an account' do
8
+ let(:response) { subject.class.run(params) }
9
+
10
+ context 'with valid params' do
11
+ let(:account) { {
12
+ application_id: 111,
13
+ created_by: 234,
14
+ name: 'My New Group'
15
+ } }
16
+ let(:params) { {
17
+ accounts: [account]
18
+ } }
19
+
20
+ it 'returns the newly created account' do
21
+ response.success?.should == true
22
+
23
+ accounts = response.result[:accounts]
24
+ accounts.length.should == 1
25
+
26
+ accounts.first[:application_id].should == 111
27
+ accounts.first[:created_by].should == 234
28
+ accounts.first[:name].should == "My New Group"
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,54 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe Commands::Account::Get do
4
+ is_required :id, :application_id
5
+
6
+ let(:response) { subject.class.run(params) }
7
+ let(:params) { {} }
8
+
9
+ before do
10
+ @account = create(:account)
11
+ end
12
+
13
+ context 'with valid params' do
14
+ let(:params) { {
15
+ id: @account.id,
16
+ application_id: @account.application_id
17
+ } }
18
+
19
+ it 'is valid' do
20
+ response.success?.should == true
21
+ end
22
+
23
+ it 'return the group' do
24
+ response.result[:accounts].length.should == 1
25
+ response.result[:accounts].first[:id].should == @account.id.to_s
26
+ end
27
+ end
28
+
29
+ context 'with invalid :id' do
30
+ let(:params) { {
31
+ id: 142857,
32
+ application_id: @account.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: @account.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,7 @@
1
+ FactoryGirl.define do
2
+ factory :account, :class => Models::Account do
3
+ sequence(:application_id)
4
+ sequence(:name) {|n| "Account ##{n}" }
5
+ sequence(:created_by)
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Models::Account do
4
+ it { should validate_presence_of(:application_id) }
5
+ it { should validate_presence_of(:created_by) }
6
+ it { should validate_presence_of(:name) }
7
+
8
+ it { should ensure_length_of(:name).is_at_most(256) }
9
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restpack_account_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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-18 00:00:00.000000000 Z
11
+ date: 2013-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: restpack_service
@@ -24,76 +24,6 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
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.0
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.0
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
27
  - !ruby/object:Gem::Dependency
98
28
  name: bundler
99
29
  requirement: !ruby/object:Gem::Requirement
@@ -206,12 +136,21 @@ files:
206
136
  - README.md
207
137
  - Rakefile
208
138
  - config/database.yml
139
+ - db/migrate/20130919115210_create_accounts.rb
209
140
  - lib/restpack_account_service.rb
210
- - lib/restpack_account_service/commands/.keep
211
- - lib/restpack_account_service/models/.keep
212
- - lib/restpack_account_service/serializers/.keep
141
+ - lib/restpack_account_service/commands/account/create.rb
142
+ - lib/restpack_account_service/commands/account/get.rb
143
+ - lib/restpack_account_service/configuration.rb
144
+ - lib/restpack_account_service/models/account.rb
145
+ - lib/restpack_account_service/serializers/account.rb
146
+ - lib/restpack_account_service/tasks/db.rake
147
+ - lib/restpack_account_service/tasks/tasks.rb
213
148
  - lib/restpack_account_service/version.rb
214
149
  - restpack_account_service.gemspec
150
+ - spec/commands/account/create_spec.rb
151
+ - spec/commands/account/get_spec.rb
152
+ - spec/factories/account.rb
153
+ - spec/models/account_spec.rb
215
154
  - spec/spec_helper.rb
216
155
  homepage: https://github.com/RestPack
217
156
  licenses:
@@ -233,9 +172,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
172
  version: '0'
234
173
  requirements: []
235
174
  rubyforge_project:
236
- rubygems_version: 2.0.7
175
+ rubygems_version: 2.0.5
237
176
  signing_key:
238
177
  specification_version: 4
239
178
  summary: Accounts
240
179
  test_files:
180
+ - spec/commands/account/create_spec.rb
181
+ - spec/commands/account/get_spec.rb
182
+ - spec/factories/account.rb
183
+ - spec/models/account_spec.rb
241
184
  - spec/spec_helper.rb
File without changes
File without changes
File without changes