restpack_core_service 0.0.6 → 0.0.7

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: 274fbf1cecbca4f5bedc1b02ae49fea9eb077492
4
- data.tar.gz: 58e4777bf47d36144b57be6fa139c9d166422fff
3
+ metadata.gz: 52807d51108a48deef41bc8969a19bd5ff468554
4
+ data.tar.gz: a6f046e023180cd7d79ddf81dfe6345b55d28c1d
5
5
  SHA512:
6
- metadata.gz: 1e71253fad5eb5ce4c381033945e594b04187e53cdc74d381a049e0f2c5af46a5317851e0c50912ded7e09483eeb4fd25a367ace6d46fc70bf531287a0424226
7
- data.tar.gz: 5c2ffe4f2dce2fe189386b8b52d27dc5b0c8b9bc3c006fdcd3cda9c46d55abc3bc651a45f331b857f693eddf1d3220dce26593d1fd1533bcd706fddfa953fa88
6
+ metadata.gz: 4256c522beddff5e9bc2544cd5662ee4eed7c3d813dd519be24d7fdd9d0e361dc88beb5193cfd93390e13cea01c6dd503f68b193e3ba331da56aefb17979cc14
7
+ data.tar.gz: e362b39a88c302963f21ef1bf2e28fa1cc88ee7fff1a2bcc4adc3853f1ec1480c0d35737979cf19ff60387d067773205a249df7ca5f1ba921965189d80cfd87c
@@ -1,8 +1,9 @@
1
- class CreateHosts < ActiveRecord::Migration
1
+ class CreateDomains < ActiveRecord::Migration
2
2
  def change
3
- create_table :restpack_hosts do |t|
4
- t.string :name, :null => false, :limit => 256
3
+ create_table :restpack_domains do |t|
4
+ t.string :identifier, :null => false, :limit => 215
5
5
  t.integer :application_id, :null => false
6
+ t.boolean :is_verified, :null => false, :default => false
6
7
  t.string :session_secret, :null => false, :limit => 128
7
8
  t.json :oauth_providers, :null => false
8
9
 
@@ -6,7 +6,7 @@ module RestPack::Core::Service::Models
6
6
  validates_presence_of :name, :account_id
7
7
  validates :name, :length => { :maximum => 256 }
8
8
 
9
- has_many :hosts
9
+ has_many :domains
10
10
 
11
11
  before_save -> {
12
12
  self.api_token ||= SecureRandom.hex(50)[0..31]
@@ -1,11 +1,16 @@
1
1
  module RestPack::Core::Service::Models
2
2
  class Domain < ActiveRecord::Base
3
3
  self.table_name = :restpack_domains
4
- attr_accessible :identifier, :host
4
+ attr_accessible :identifier, :application_id, :is_verified, :session_secret, :oauth_providers
5
5
 
6
- validates_presence_of :identifier
6
+ validates_presence_of :identifier, :application_id
7
7
  validates :identifier, :length => { :maximum => 512 }
8
8
 
9
- belongs_to :host
9
+ belongs_to :application
10
+
11
+ before_save -> {
12
+ self.oauth_providers ||= {}
13
+ self.session_secret ||= SecureRandom.hex(16)
14
+ }
10
15
  end
11
16
  end
@@ -0,0 +1,16 @@
1
+ module RestPack::Core::Service::Serializers
2
+ class ApplicationSerializer
3
+ include RestPack::Serializer
4
+
5
+ self.model_class = RestPack::Core::Service::Models::Application
6
+ self.key = :applications
7
+
8
+ attributes :id
9
+ end
10
+ end
11
+
12
+ #TODO: GJ: remove once this has been addressed:
13
+ # https://github.com/RestPack/restpack_serializer/issues/41
14
+ class ApplicationSerializer < RestPack::Core::Service::Serializers::ApplicationSerializer
15
+
16
+ end
@@ -0,0 +1,13 @@
1
+ module RestPack::Core::Service::Serializers
2
+ class DomainSerializer
3
+ include RestPack::Serializer
4
+
5
+ self.model_class = RestPack::Core::Service::Models::Domain
6
+ self.key = :domains
7
+
8
+ attributes :id, :identifier, :application_id, :is_verified, :session_secret,
9
+ :oauth_providers
10
+
11
+ can_include :application
12
+ end
13
+ end
@@ -0,0 +1,24 @@
1
+ module RestPack::Core::Service::Commands::Domain
2
+ class ByIdentifier < RestPack::Service::Command
3
+ required do
4
+ string :identifier
5
+ end
6
+
7
+ optional do
8
+ string :includes
9
+ end
10
+
11
+ def execute
12
+ result = Core::Serializers::DomainSerializer.resource(
13
+ inputs,
14
+ Core::Models::Domain.where(identifier: inputs[:identifier])
15
+ )
16
+
17
+ if result[:domains].any?
18
+ result
19
+ else
20
+ status :not_found
21
+ end
22
+ end
23
+ end
24
+ end
@@ -3,3 +3,4 @@ module RestPack::Core::Service::Commands
3
3
  end
4
4
 
5
5
  require "restpack_core_service/services/application/verify_api_token"
6
+ require "restpack_core_service/services/domain/by_identifier"
@@ -1,7 +1,7 @@
1
1
  module RestPack
2
2
  module Core
3
3
  module Service
4
- VERSION = "0.0.6"
4
+ VERSION = "0.0.7"
5
5
  end
6
6
  end
7
7
  end
@@ -1,19 +1,23 @@
1
1
  require "active_record"
2
2
  require "restpack_service"
3
+ require "restpack_serializer"
4
+
3
5
  require "active_support/core_ext"
4
6
 
5
7
  require "restpack_core_service/version"
6
8
  require "restpack_core_service/configuration"
7
9
 
8
10
  require "restpack_core_service/models/application"
9
- require "restpack_core_service/models/host"
10
11
  require "restpack_core_service/models/domain"
11
12
 
13
+ require "restpack_core_service/serializers/application_serializer"
14
+ require "restpack_core_service/serializers/domain_serializer"
15
+
12
16
  require "restpack_core_service/services"
13
17
  require "restpack_core_service/tasks"
14
18
 
15
19
  module Core
16
20
  Models = RestPack::Core::Service::Models
17
21
  Commands = RestPack::Core::Service::Commands
18
- # Serializers = RestPack::Core::Service::Serializers
22
+ Serializers = RestPack::Core::Service::Serializers
19
23
  end
@@ -1,6 +1,6 @@
1
1
  FactoryGirl.define do
2
2
  factory :domain, :class => Core::Models::Domain do
3
- sequence(:identifier) {|n| "subdomain_#{n}.domain.com" }
4
- host
3
+ application
4
+ sequence(:identifier) {|n| "domain_#{n}.com" }
5
5
  end
6
6
  end
@@ -2,7 +2,7 @@ describe RestPack::Core::Service::Models::Application do
2
2
  it { should validate_presence_of(:name) }
3
3
  it { should validate_presence_of(:account_id) }
4
4
  it { should ensure_length_of(:name).is_at_most(256) }
5
- it { should have_many(:hosts) }
5
+ it { should have_many(:domains) }
6
6
  it { subject.class.table_name.should == 'restpack_applications' }
7
7
 
8
8
  context "default values" do
@@ -1,6 +1,25 @@
1
1
  describe RestPack::Core::Service::Models::Domain do
2
2
  it { should validate_presence_of(:identifier) }
3
+ it { should validate_presence_of(:application_id) }
3
4
  it { should ensure_length_of(:identifier).is_at_most(512) }
4
- it { should belong_to(:host) }
5
+ it { should belong_to(:application) }
5
6
  it { subject.class.table_name.should == 'restpack_domains' }
7
+
8
+ context "default values" do
9
+ it "has a random session_secret" do
10
+ domain1 = create(:domain)
11
+ domain2 = create(:domain)
12
+
13
+ domain1.session_secret.should_not == nil
14
+ domain1.session_secret.should_not == domain2.session_secret
15
+ end
16
+
17
+ it "has empty oauth_providers as default" do
18
+ create(:domain).oauth_providers.should == {}
19
+ end
20
+
21
+ it "is not verified" do
22
+ create(:domain).is_verified.should == false
23
+ end
24
+ end
6
25
  end
@@ -0,0 +1,44 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe Core::Commands::Domain::ByIdentifier do
4
+ is_required :identifier
5
+ is_optional :includes
6
+
7
+ let(:response) { subject.class.run(params) }
8
+
9
+ before do
10
+ @domain = create(:domain)
11
+ end
12
+
13
+ context 'with valid params' do
14
+ let(:params) { {
15
+ identifier: @domain.identifier,
16
+ includes: 'application'
17
+ } }
18
+
19
+ it 'is valid' do
20
+ response.success?.should == true
21
+ end
22
+
23
+ it 'includes identifier' do
24
+ response.result[:domains].length.should == 1
25
+ response.result[:domains].first[:identifier].should == @domain.identifier
26
+ end
27
+
28
+ it 'includes related application' do
29
+ response.result[:applications].length.should == 1
30
+ end
31
+ end
32
+
33
+ context 'with invalid :identifier' do
34
+ let(:params) { {
35
+ identifier: 'invalid'
36
+ }}
37
+
38
+ it 'is :not_found' do
39
+ response.success?.should == false
40
+ response.result.should == {}
41
+ response.status.should == :not_found
42
+ end
43
+ end
44
+ end
data/spec/spec_helper.rb CHANGED
@@ -4,7 +4,7 @@ require 'restpack_core_service'
4
4
  config = YAML.load_file('./config/database.yml')
5
5
  ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'] || config['test'])
6
6
 
7
- migrations_path = File.dirname(__FILE__) + "/../db/migratore"
7
+ migrations_path = File.dirname(__FILE__) + "/../db/migrate"
8
8
  migrator = ActiveRecord::Migrator.new(:up, migrations_path)
9
9
  migrator.migrate
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restpack_core_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
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-08-23 00:00:00.000000000 Z
11
+ date: 2013-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: restpack_service
@@ -193,16 +193,16 @@ files:
193
193
  - Rakefile
194
194
  - config/database.yml
195
195
  - db/migrate/20130807103945_create_applications.rb
196
- - db/migrate/20130808135549_create_hosts.rb
197
- - db/migrate/20130808135613_create_domains.rb
196
+ - db/migrate/20130808135549_create_domains.rb
198
197
  - lib/restpack_core_service.rb
199
198
  - lib/restpack_core_service/configuration.rb
200
199
  - lib/restpack_core_service/models/application.rb
201
200
  - lib/restpack_core_service/models/domain.rb
202
- - lib/restpack_core_service/models/host.rb
203
- - lib/restpack_core_service/serializers/user_serializer.rb
201
+ - lib/restpack_core_service/serializers/application_serializer.rb
202
+ - lib/restpack_core_service/serializers/domain_serializer.rb
204
203
  - lib/restpack_core_service/services.rb
205
204
  - lib/restpack_core_service/services/application/verify_api_token.rb
205
+ - lib/restpack_core_service/services/domain/by_identifier.rb
206
206
  - lib/restpack_core_service/tasks.rb
207
207
  - lib/restpack_core_service/tasks/db.rake
208
208
  - lib/restpack_core_service/version.rb
@@ -210,11 +210,10 @@ files:
210
210
  - spec/configuration_spec.rb
211
211
  - spec/factories/application_factory.rb
212
212
  - spec/factories/domain_factory.rb
213
- - spec/factories/host_factory.rb
214
213
  - spec/models/application_spec.rb
215
214
  - spec/models/domain_spec.rb
216
- - spec/models/host_spec.rb
217
215
  - spec/services/application/verify_api_token_spec.rb
216
+ - spec/services/domain/by_identifier_spec.rb
218
217
  - spec/spec_helper.rb
219
218
  homepage: https://github.com/RestPack
220
219
  licenses:
@@ -236,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
236
235
  version: '0'
237
236
  requirements: []
238
237
  rubyforge_project:
239
- rubygems_version: 2.0.3
238
+ rubygems_version: 2.0.7
240
239
  signing_key:
241
240
  specification_version: 4
242
241
  summary: Applications, Domains and Configurations
@@ -244,9 +243,8 @@ test_files:
244
243
  - spec/configuration_spec.rb
245
244
  - spec/factories/application_factory.rb
246
245
  - spec/factories/domain_factory.rb
247
- - spec/factories/host_factory.rb
248
246
  - spec/models/application_spec.rb
249
247
  - spec/models/domain_spec.rb
250
- - spec/models/host_spec.rb
251
248
  - spec/services/application/verify_api_token_spec.rb
249
+ - spec/services/domain/by_identifier_spec.rb
252
250
  - spec/spec_helper.rb
@@ -1,10 +0,0 @@
1
- class CreateDomains < ActiveRecord::Migration
2
- def change
3
- create_table :restpack_domains do |t|
4
- t.string :identifier, :null => false, :limit => 512
5
- t.integer :host_id, :null => false
6
-
7
- t.timestamps
8
- end
9
- end
10
- end
@@ -1,17 +0,0 @@
1
- module RestPack::Core::Service::Models
2
- class Host < ActiveRecord::Base
3
- self.table_name = :restpack_hosts
4
- attr_accessible :name, :application_id, :session_secret, :oauth_providers
5
-
6
- validates_presence_of :name, :application_id
7
- validates :name, :length => { :maximum => 256 }
8
-
9
- has_many :domains
10
- belongs_to :application
11
-
12
- before_save -> {
13
- self.oauth_providers ||= {}
14
- self.session_secret ||= SecureRandom.hex(16)
15
- }
16
- end
17
- end
@@ -1,11 +0,0 @@
1
- module RestPack::Core::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, :user_id, :title, :content, :latitude, :longitude,
9
- # :tags, :access, :data, :href, :updated_at, :created_at
10
- end
11
- end
@@ -1,6 +0,0 @@
1
- FactoryGirl.define do
2
- factory :host, :class => Core::Models::Host do
3
- sequence(:name) {|n| "Host ##{n}" }
4
- application
5
- end
6
- end
@@ -1,22 +0,0 @@
1
- describe RestPack::Core::Service::Models::Host do
2
- it { should validate_presence_of(:name) }
3
- it { should validate_presence_of(:application_id) }
4
- it { should ensure_length_of(:name).is_at_most(256) }
5
- it { should belong_to(:application) }
6
- it { should have_many(:domains) }
7
- it { subject.class.table_name.should == 'restpack_hosts' }
8
-
9
- context "default values" do
10
- it "has a random session_secret" do
11
- host1 = create(:host)
12
- host2 = create(:host)
13
-
14
- host1.session_secret.should_not == nil
15
- host1.session_secret.should_not == host2.session_secret
16
- end
17
-
18
- it "has empty oauth_providers as default" do
19
- create(:host).oauth_providers.should == {}
20
- end
21
- end
22
- end