diff --git a/Guardfile b/Guardfile index b2246a2..cb1189a 100644 --- a/Guardfile +++ b/Guardfile @@ -1,6 +1,6 @@ guard 'rspec', :version => 2 do watch(%r{^spec/.+_spec\.rb$}) - watch(%r{^lib/tent-server/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" } + watch(%r{^lib/tentd/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" } watch(%r{^lib/[^/]+\.rb$}) { "spec" } watch(%r{spec/(spec_helper|support/).*\.rb}) { "spec" } end diff --git a/README.md b/README.md index 55b6035..a1ad699 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Tent::Server +# TentD TODO: Write a gem description @@ -6,7 +6,7 @@ TODO: Write a gem description Add this line to your application's Gemfile: - gem 'tent-server' + gem 'tentd' And then execute: @@ -14,7 +14,7 @@ And then execute: Or install it yourself as: - $ gem install tent-server + $ gem install tentd ## Usage diff --git a/lib/tent-server.rb b/lib/tent-server.rb deleted file mode 100644 index bb7fc33..0000000 --- a/lib/tent-server.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'tent-server/version' -require 'tent-client' - -module TentServer - autoload :API, 'tent-server/api' - autoload :Action, 'tent-server/action' - autoload :JsonPatch, 'tent-server/json_patch' - autoload :TentVersion, 'tent-server/tent_version' - autoload :RackRequest, 'tent-server/rack_request' - - def self.new(options={}) - DataMapper.setup(:default, options[:database] || ENV['DATABASE_URL']) - API.new - end -end - -require 'tent-server/model' diff --git a/lib/tent-server/api.rb b/lib/tent-server/api.rb deleted file mode 100644 index 1ea9186..0000000 --- a/lib/tent-server/api.rb +++ /dev/null @@ -1,30 +0,0 @@ -module TentServer - class API - PER_PAGE = 50 - MAX_PER_PAGE = 200 - MEDIA_TYPE = 'application/vnd.tent.v0+json' - - autoload :Apps, 'tent-server/api/apps' - autoload :Posts, 'tent-server/api/posts' - autoload :Groups, 'tent-server/api/groups' - autoload :Profile, 'tent-server/api/profile' - autoload :Followers, 'tent-server/api/followers' - autoload :Followings, 'tent-server/api/followings' - autoload :CoreProfileData, 'tent-server/api/core_profile_data' - autoload :AuthenticationLookup, 'tent-server/api/authentication_lookup' - autoload :AuthenticationVerification, 'tent-server/api/authentication_verification' - autoload :AuthenticationFinalize, 'tent-server/api/authentication_finalize' - autoload :Authorization, 'tent-server/api/authorization' - autoload :Authorizable, 'tent-server/api/authorizable' - autoload :Router, 'tent-server/api/router' - autoload :Middleware, 'tent-server/api/middleware' - include Router - - mount Apps - mount Posts - mount Groups - mount Profile - mount Followers - mount Followings - end -end diff --git a/lib/tent-server/model.rb b/lib/tent-server/model.rb deleted file mode 100644 index 6c53c19..0000000 --- a/lib/tent-server/model.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'data_mapper' -require 'dm-ar-finders' -require 'tent-server/datamapper/array_property' -require 'tent-server/datamapper/binary_string_property' -require 'tent-server/datamapper/query' - -module TentServer - module Model - require 'tent-server/model/permissible' - require 'tent-server/model/random_public_id' - require 'tent-server/model/post' - require 'tent-server/model/post_attachment' - require 'tent-server/model/follower' - require 'tent-server/model/following' - require 'tent-server/model/app' - require 'tent-server/model/app_authorization' - require 'tent-server/model/notification_subscription' - require 'tent-server/model/profile_info' - require 'tent-server/model/group' - require 'tent-server/model/permission' - end -end - -DataMapper.finalize diff --git a/lib/tent-server/model/permission.rb b/lib/tent-server/model/permission.rb deleted file mode 100644 index d41be30..0000000 --- a/lib/tent-server/model/permission.rb +++ /dev/null @@ -1,18 +0,0 @@ -module TentServer - module Model - class Permission - include DataMapper::Resource - - storage_names[:default] = "permissions" - - belongs_to :post, 'TentServer::Model::Post', :required => false - belongs_to :group, 'TentServer::Model::Group', :required => false, :parent_key => :public_id - belongs_to :following, 'TentServer::Model::Following', :required => false - belongs_to :follower_visibility, 'TentServer::Model::Follower', :required => false - belongs_to :follower_access, 'TentServer::Model::Follower', :required => false - - property :id, Serial - property :visible, Boolean - end - end -end diff --git a/lib/tentd.rb b/lib/tentd.rb new file mode 100644 index 0000000..4b36a17 --- /dev/null +++ b/lib/tentd.rb @@ -0,0 +1,17 @@ +require 'tentd/version' +require 'tent-client' + +module TentD + autoload :API, 'tentd/api' + autoload :Action, 'tentd/action' + autoload :JsonPatch, 'tentd/json_patch' + autoload :TentVersion, 'tentd/tent_version' + autoload :RackRequest, 'tentd/rack_request' + + def self.new(options={}) + DataMapper.setup(:default, options[:database] || ENV['DATABASE_URL']) + API.new + end +end + +require 'tentd/model' diff --git a/lib/tentd/api.rb b/lib/tentd/api.rb new file mode 100644 index 0000000..d074815 --- /dev/null +++ b/lib/tentd/api.rb @@ -0,0 +1,30 @@ +module TentD + class API + PER_PAGE = 50 + MAX_PER_PAGE = 200 + MEDIA_TYPE = 'application/vnd.tent.v0+json' + + autoload :Apps, 'tentd/api/apps' + autoload :Posts, 'tentd/api/posts' + autoload :Groups, 'tentd/api/groups' + autoload :Profile, 'tentd/api/profile' + autoload :Followers, 'tentd/api/followers' + autoload :Followings, 'tentd/api/followings' + autoload :CoreProfileData, 'tentd/api/core_profile_data' + autoload :AuthenticationLookup, 'tentd/api/authentication_lookup' + autoload :AuthenticationVerification, 'tentd/api/authentication_verification' + autoload :AuthenticationFinalize, 'tentd/api/authentication_finalize' + autoload :Authorization, 'tentd/api/authorization' + autoload :Authorizable, 'tentd/api/authorizable' + autoload :Router, 'tentd/api/router' + autoload :Middleware, 'tentd/api/middleware' + include Router + + mount Apps + mount Posts + mount Groups + mount Profile + mount Followers + mount Followings + end +end diff --git a/lib/tent-server/api/apps.rb b/lib/tentd/api/apps.rb similarity index 99% rename from lib/tent-server/api/apps.rb rename to lib/tentd/api/apps.rb index 7753f98..a19da18 100644 --- a/lib/tent-server/api/apps.rb +++ b/lib/tentd/api/apps.rb @@ -1,4 +1,4 @@ -module TentServer +module TentD class API class Apps include Router diff --git a/lib/tent-server/api/authentication_finalize.rb b/lib/tentd/api/authentication_finalize.rb similarity index 95% rename from lib/tent-server/api/authentication_finalize.rb rename to lib/tentd/api/authentication_finalize.rb index 9b6d076..7e9cd46 100644 --- a/lib/tent-server/api/authentication_finalize.rb +++ b/lib/tentd/api/authentication_finalize.rb @@ -1,4 +1,4 @@ -module TentServer +module TentD class API class AuthenticationFinalize < Middleware def action(env) diff --git a/lib/tent-server/api/authentication_lookup.rb b/lib/tentd/api/authentication_lookup.rb similarity index 63% rename from lib/tent-server/api/authentication_lookup.rb rename to lib/tentd/api/authentication_lookup.rb index 2d07416..e42863f 100644 --- a/lib/tent-server/api/authentication_lookup.rb +++ b/lib/tentd/api/authentication_lookup.rb @@ -1,4 +1,4 @@ -module TentServer +module TentD class API class AuthenticationLookup < Middleware def action(env) @@ -6,11 +6,11 @@ def action(env) env['hmac'] = Hash[env['HTTP_AUTHORIZATION'].scan(/([a-z]+)="([^"]+)"/i)] case env['hmac']['id'].to_s[0,1] when 's' - env.potential_auth = TentServer::Model::Follower.first(:mac_key_id => env['hmac']['id']) + env.potential_auth = TentD::Model::Follower.first(:mac_key_id => env['hmac']['id']) when 'a' - env.potential_auth = TentServer::Model::App.first(:mac_key_id => env['hmac']['id']) + env.potential_auth = TentD::Model::App.first(:mac_key_id => env['hmac']['id']) when 'u' - env.potential_auth = TentServer::Model::AppAuthorization.first(:mac_key_id => env['hmac']['id']) + env.potential_auth = TentD::Model::AppAuthorization.first(:mac_key_id => env['hmac']['id']) end env.hmac.secret = env.potential_auth.mac_key env.hmac.algorithm = env.potential_auth.mac_algorithm diff --git a/lib/tent-server/api/authentication_verification.rb b/lib/tentd/api/authentication_verification.rb similarity index 98% rename from lib/tent-server/api/authentication_verification.rb rename to lib/tentd/api/authentication_verification.rb index 0daa3d9..3d2fba3 100644 --- a/lib/tent-server/api/authentication_verification.rb +++ b/lib/tentd/api/authentication_verification.rb @@ -1,7 +1,7 @@ require 'openssl' require 'base64' -module TentServer +module TentD class API class AuthenticationVerification < Middleware def action(env) diff --git a/lib/tent-server/api/authorizable.rb b/lib/tentd/api/authorizable.rb similarity index 95% rename from lib/tent-server/api/authorizable.rb rename to lib/tentd/api/authorizable.rb index 71b9584..e508ecc 100644 --- a/lib/tent-server/api/authorizable.rb +++ b/lib/tentd/api/authorizable.rb @@ -1,4 +1,4 @@ -module TentServer +module TentD class API module Authorizable class Error < StandardError diff --git a/lib/tent-server/api/authorization.rb b/lib/tentd/api/authorization.rb similarity index 95% rename from lib/tent-server/api/authorization.rb rename to lib/tentd/api/authorization.rb index 68c13db..f3b15db 100644 --- a/lib/tent-server/api/authorization.rb +++ b/lib/tentd/api/authorization.rb @@ -1,4 +1,4 @@ -module TentServer +module TentD class API class Authorization < Middleware def action(env) diff --git a/lib/tent-server/api/core_profile_data.rb b/lib/tentd/api/core_profile_data.rb similarity index 97% rename from lib/tent-server/api/core_profile_data.rb rename to lib/tentd/api/core_profile_data.rb index 3b7b6aa..ce0692e 100644 --- a/lib/tent-server/api/core_profile_data.rb +++ b/lib/tentd/api/core_profile_data.rb @@ -1,6 +1,6 @@ require 'hashie' -module TentServer +module TentD class API class CoreProfileData < Hashie::Mash def expected_version diff --git a/lib/tent-server/api/followers.rb b/lib/tentd/api/followers.rb similarity index 99% rename from lib/tent-server/api/followers.rb rename to lib/tentd/api/followers.rb index b2238af..13f5da4 100644 --- a/lib/tent-server/api/followers.rb +++ b/lib/tentd/api/followers.rb @@ -1,4 +1,4 @@ -module TentServer +module TentD class API class Followers include Router diff --git a/lib/tent-server/api/followings.rb b/lib/tentd/api/followings.rb similarity index 99% rename from lib/tent-server/api/followings.rb rename to lib/tentd/api/followings.rb index 61c5809..3db35ec 100644 --- a/lib/tent-server/api/followings.rb +++ b/lib/tentd/api/followings.rb @@ -1,4 +1,4 @@ -module TentServer +module TentD class API class Followings include Router diff --git a/lib/tent-server/api/groups.rb b/lib/tentd/api/groups.rb similarity index 99% rename from lib/tent-server/api/groups.rb rename to lib/tentd/api/groups.rb index ba996a7..7d92024 100644 --- a/lib/tent-server/api/groups.rb +++ b/lib/tentd/api/groups.rb @@ -1,4 +1,4 @@ -module TentServer +module TentD class API class Groups include Router diff --git a/lib/tent-server/api/middleware.rb b/lib/tentd/api/middleware.rb similarity index 95% rename from lib/tent-server/api/middleware.rb rename to lib/tentd/api/middleware.rb index ba9f9ec..7c93427 100644 --- a/lib/tent-server/api/middleware.rb +++ b/lib/tentd/api/middleware.rb @@ -1,6 +1,6 @@ require 'hashie' -module TentServer +module TentD class API class Middleware include Authorizable diff --git a/lib/tent-server/api/posts.rb b/lib/tentd/api/posts.rb similarity index 96% rename from lib/tent-server/api/posts.rb rename to lib/tentd/api/posts.rb index 5130a0e..7b55e0c 100644 --- a/lib/tent-server/api/posts.rb +++ b/lib/tentd/api/posts.rb @@ -1,4 +1,4 @@ -module TentServer +module TentD class API class Posts include Router @@ -56,9 +56,9 @@ def action(env) conditions[:type] = env.current_auth.post_types end if env.params.limit - conditions[:limit] = [env.params.limit.to_i, TentServer::API::MAX_PER_PAGE].min + conditions[:limit] = [env.params.limit.to_i, TentD::API::MAX_PER_PAGE].min else - conditions[:limit] = TentServer::API::PER_PAGE + conditions[:limit] = TentD::API::PER_PAGE end if conditions[:limit] == 0 env.response = [] diff --git a/lib/tent-server/api/profile.rb b/lib/tentd/api/profile.rb similarity index 99% rename from lib/tent-server/api/profile.rb rename to lib/tentd/api/profile.rb index c85b4b4..28ec523 100644 --- a/lib/tent-server/api/profile.rb +++ b/lib/tentd/api/profile.rb @@ -1,4 +1,4 @@ -module TentServer +module TentD class API class Profile include Router diff --git a/lib/tent-server/api/router.rb b/lib/tentd/api/router.rb similarity index 93% rename from lib/tent-server/api/router.rb rename to lib/tentd/api/router.rb index 257372c..59d7936 100644 --- a/lib/tent-server/api/router.rb +++ b/lib/tentd/api/router.rb @@ -19,12 +19,12 @@ def merge_route(route) end end -module TentServer +module TentD class API module Router - autoload :ExtractParams, 'tent-server/api/router/extract_params' - autoload :SerializeResponse, 'tent-server/api/router/serialize_response' - autoload :CachingHeaders, 'tent-server/api/router/caching_headers' + autoload :ExtractParams, 'tentd/api/router/extract_params' + autoload :SerializeResponse, 'tentd/api/router/serialize_response' + autoload :CachingHeaders, 'tentd/api/router/caching_headers' def self.included(base) base.extend(ClassMethods) diff --git a/lib/tent-server/api/router/caching_headers.rb b/lib/tentd/api/router/caching_headers.rb similarity index 98% rename from lib/tent-server/api/router/caching_headers.rb rename to lib/tentd/api/router/caching_headers.rb index 1c8a777..1ce1525 100644 --- a/lib/tent-server/api/router/caching_headers.rb +++ b/lib/tentd/api/router/caching_headers.rb @@ -1,6 +1,6 @@ require 'time' -module TentServer +module TentD class API module Router class CachingHeaders diff --git a/lib/tent-server/api/router/extract_params.rb b/lib/tentd/api/router/extract_params.rb similarity index 99% rename from lib/tent-server/api/router/extract_params.rb rename to lib/tentd/api/router/extract_params.rb index 5dc0a32..456b246 100644 --- a/lib/tent-server/api/router/extract_params.rb +++ b/lib/tentd/api/router/extract_params.rb @@ -1,4 +1,4 @@ -module TentServer +module TentD class API module Router class ExtractParams diff --git a/lib/tent-server/api/router/serialize_response.rb b/lib/tentd/api/router/serialize_response.rb similarity index 95% rename from lib/tent-server/api/router/serialize_response.rb rename to lib/tentd/api/router/serialize_response.rb index 89b5338..af12223 100644 --- a/lib/tent-server/api/router/serialize_response.rb +++ b/lib/tentd/api/router/serialize_response.rb @@ -1,6 +1,6 @@ require 'json' -module TentServer +module TentD class API module Router class SerializeResponse diff --git a/lib/tent-server/core_ext/hash/slice.rb b/lib/tentd/core_ext/hash/slice.rb similarity index 100% rename from lib/tent-server/core_ext/hash/slice.rb rename to lib/tentd/core_ext/hash/slice.rb diff --git a/lib/tent-server/datamapper/array_property.rb b/lib/tentd/datamapper/array_property.rb similarity index 100% rename from lib/tent-server/datamapper/array_property.rb rename to lib/tentd/datamapper/array_property.rb diff --git a/lib/tent-server/datamapper/binary_string_property.rb b/lib/tentd/datamapper/binary_string_property.rb similarity index 100% rename from lib/tent-server/datamapper/binary_string_property.rb rename to lib/tentd/datamapper/binary_string_property.rb diff --git a/lib/tent-server/datamapper/query.rb b/lib/tentd/datamapper/query.rb similarity index 100% rename from lib/tent-server/datamapper/query.rb rename to lib/tentd/datamapper/query.rb diff --git a/lib/tent-server/json_patch.rb b/lib/tentd/json_patch.rb similarity index 99% rename from lib/tent-server/json_patch.rb rename to lib/tentd/json_patch.rb index 5007904..30f29ff 100644 --- a/lib/tent-server/json_patch.rb +++ b/lib/tentd/json_patch.rb @@ -1,4 +1,4 @@ -module TentServer +module TentD class JsonPatch OPERATIONS = %w( add remove replace move copy test ) diff --git a/lib/tentd/model.rb b/lib/tentd/model.rb new file mode 100644 index 0000000..17b0af1 --- /dev/null +++ b/lib/tentd/model.rb @@ -0,0 +1,24 @@ +require 'data_mapper' +require 'dm-ar-finders' +require 'tentd/datamapper/array_property' +require 'tentd/datamapper/binary_string_property' +require 'tentd/datamapper/query' + +module TentD + module Model + require 'tentd/model/permissible' + require 'tentd/model/random_public_id' + require 'tentd/model/post' + require 'tentd/model/post_attachment' + require 'tentd/model/follower' + require 'tentd/model/following' + require 'tentd/model/app' + require 'tentd/model/app_authorization' + require 'tentd/model/notification_subscription' + require 'tentd/model/profile_info' + require 'tentd/model/group' + require 'tentd/model/permission' + end +end + +DataMapper.finalize diff --git a/lib/tent-server/model/app.rb b/lib/tentd/model/app.rb similarity index 91% rename from lib/tent-server/model/app.rb rename to lib/tentd/model/app.rb index fcbc86b..3cde505 100644 --- a/lib/tent-server/model/app.rb +++ b/lib/tentd/model/app.rb @@ -1,7 +1,7 @@ require 'securerandom' -require 'tent-server/core_ext/hash/slice' +require 'tentd/core_ext/hash/slice' -module TentServer +module TentD module Model class App include DataMapper::Resource @@ -23,7 +23,7 @@ class App property :created_at, DateTime property :updated_at, DateTime - has n, :authorizations, 'TentServer::Model::AppAuthorization', :constraint => :destroy + has n, :authorizations, 'TentD::Model::AppAuthorization', :constraint => :destroy def self.create_from_params(params) create(params.slice(:name, :description, :url, :icon, :redirect_uris, :scopes)) diff --git a/lib/tent-server/model/app_authorization.rb b/lib/tentd/model/app_authorization.rb similarity index 82% rename from lib/tent-server/model/app_authorization.rb rename to lib/tentd/model/app_authorization.rb index 70c40f8..7c0445b 100644 --- a/lib/tent-server/model/app_authorization.rb +++ b/lib/tentd/model/app_authorization.rb @@ -1,6 +1,6 @@ require 'securerandom' -module TentServer +module TentD module Model class AppAuthorization include DataMapper::Resource @@ -22,8 +22,8 @@ class AppAuthorization property :created_at, DateTime property :updated_at, DateTime - belongs_to :app, 'TentServer::Model::App' - has n, :notification_subscriptions, 'TentServer::Model::NotificationSubscription', :constraint => :destroy + belongs_to :app, 'TentD::Model::App' + has n, :notification_subscriptions, 'TentD::Model::NotificationSubscription', :constraint => :destroy end end end diff --git a/lib/tent-server/model/follower.rb b/lib/tentd/model/follower.rb similarity index 87% rename from lib/tent-server/model/follower.rb rename to lib/tentd/model/follower.rb index 79e4cd6..636e166 100644 --- a/lib/tent-server/model/follower.rb +++ b/lib/tentd/model/follower.rb @@ -1,7 +1,7 @@ -require 'tent-server/core_ext/hash/slice' +require 'tentd/core_ext/hash/slice' require 'securerandom' -module TentServer +module TentD module Model class Follower include DataMapper::Resource @@ -23,13 +23,13 @@ class Follower property :created_at, DateTime property :updated_at, DateTime - has n, :notification_subscriptions, 'TentServer::Model::NotificationSubscription', :constraint => :destroy + has n, :notification_subscriptions, 'TentD::Model::NotificationSubscription', :constraint => :destroy # permissions describing who can see them - has n, :visibility_permissions, 'TentServer::Model::Permission', :child_key => [ :follower_visibility_id ], :constraint => :destroy + has n, :visibility_permissions, 'TentD::Model::Permission', :child_key => [ :follower_visibility_id ], :constraint => :destroy # permissions describing what they have access to - has n, :access_permissions, 'TentServer::Model::Permission', :child_key => [ :follower_access_id ], :constraint => :destroy + has n, :access_permissions, 'TentD::Model::Permission', :child_key => [ :follower_access_id ], :constraint => :destroy def self.create_follower(data, authorized_scopes = []) if authorized_scopes.include?(:write_followers) && authorized_scopes.include?(:write_secrets) diff --git a/lib/tent-server/model/following.rb b/lib/tentd/model/following.rb similarity index 93% rename from lib/tent-server/model/following.rb rename to lib/tentd/model/following.rb index f74c462..59a2d61 100644 --- a/lib/tent-server/model/following.rb +++ b/lib/tentd/model/following.rb @@ -1,6 +1,6 @@ -require 'tent-server/core_ext/hash/slice' +require 'tentd/core_ext/hash/slice' -module TentServer +module TentD module Model class Following include DataMapper::Resource @@ -23,7 +23,7 @@ class Following property :created_at, DateTime property :updated_at, DateTime - has n, :permissions, 'TentServer::Model::Permission', :constraint => :destroy + has n, :permissions, 'TentD::Model::Permission', :constraint => :destroy def self.create_from_params(params) create( diff --git a/lib/tent-server/model/group.rb b/lib/tentd/model/group.rb similarity index 77% rename from lib/tent-server/model/group.rb rename to lib/tentd/model/group.rb index 2233f18..fcc84f7 100644 --- a/lib/tent-server/model/group.rb +++ b/lib/tentd/model/group.rb @@ -1,4 +1,4 @@ -module TentServer +module TentD module Model class Group include DataMapper::Resource @@ -11,7 +11,7 @@ class Group property :created_at, DateTime property :updated_at, DateTime - has n, :permissions, 'TentServer::Model::Permission', :constraint => :destroy, :parent_key => :public_id + has n, :permissions, 'TentD::Model::Permission', :constraint => :destroy, :parent_key => :public_id def as_json(options = {}) attributes = super diff --git a/lib/tent-server/model/notification_subscription.rb b/lib/tentd/model/notification_subscription.rb similarity index 74% rename from lib/tent-server/model/notification_subscription.rb rename to lib/tentd/model/notification_subscription.rb index f4b12ef..2e39105 100644 --- a/lib/tent-server/model/notification_subscription.rb +++ b/lib/tentd/model/notification_subscription.rb @@ -1,4 +1,4 @@ -module TentServer +module TentD module Model class NotificationSubscription include DataMapper::Resource @@ -11,8 +11,8 @@ class NotificationSubscription property :created_at, DateTime property :updated_at, DateTime - belongs_to :app_authorization, 'TentServer::Model::AppAuthorization', :required => false - belongs_to :follower, 'TentServer::Model::Follower', :required => false + belongs_to :app_authorization, 'TentD::Model::AppAuthorization', :required => false + belongs_to :follower, 'TentD::Model::Follower', :required => false before :save, :extract_view diff --git a/lib/tent-server/model/permissible.rb b/lib/tentd/model/permissible.rb similarity index 96% rename from lib/tent-server/model/permissible.rb rename to lib/tentd/model/permissible.rb index 540e74a..759417f 100644 --- a/lib/tent-server/model/permissible.rb +++ b/lib/tentd/model/permissible.rb @@ -1,6 +1,6 @@ require 'hashie' -module TentServer +module TentD module Model module Permissible def self.included(base) @@ -75,7 +75,7 @@ def fetch_all(params) end query << "LIMIT ?" - query_bindings << [(params.limit ? params.limit.to_i : TentServer::API::PER_PAGE), TentServer::API::MAX_PER_PAGE].min + query_bindings << [(params.limit ? params.limit.to_i : TentD::API::PER_PAGE), TentD::API::MAX_PER_PAGE].min find_by_sql([query.join(' '), *query_bindings]) end @@ -99,7 +99,7 @@ def fetch_with_permissions(params, current_auth, &block) end query << "LIMIT ?" - query_bindings << [(params.limit ? params.limit.to_i : TentServer::API::PER_PAGE), TentServer::API::MAX_PER_PAGE].min + query_bindings << [(params.limit ? params.limit.to_i : TentD::API::PER_PAGE), TentD::API::MAX_PER_PAGE].min find_by_sql([query.join(' '), *query_bindings]) end diff --git a/lib/tentd/model/permission.rb b/lib/tentd/model/permission.rb new file mode 100644 index 0000000..eecaa7b --- /dev/null +++ b/lib/tentd/model/permission.rb @@ -0,0 +1,18 @@ +module TentD + module Model + class Permission + include DataMapper::Resource + + storage_names[:default] = "permissions" + + belongs_to :post, 'TentD::Model::Post', :required => false + belongs_to :group, 'TentD::Model::Group', :required => false, :parent_key => :public_id + belongs_to :following, 'TentD::Model::Following', :required => false + belongs_to :follower_visibility, 'TentD::Model::Follower', :required => false + belongs_to :follower_access, 'TentD::Model::Follower', :required => false + + property :id, Serial + property :visible, Boolean + end + end +end diff --git a/lib/tent-server/model/post.rb b/lib/tentd/model/post.rb similarity index 91% rename from lib/tent-server/model/post.rb rename to lib/tentd/model/post.rb index 2692fd1..352e9f5 100644 --- a/lib/tent-server/model/post.rb +++ b/lib/tentd/model/post.rb @@ -1,6 +1,6 @@ require 'securerandom' -module TentServer +module TentD module Model class Post include DataMapper::Resource @@ -19,8 +19,8 @@ class Post property :received_at, DateTime property :updated_at, DateTime - has n, :permissions, 'TentServer::Model::Permission', :constraint => :destroy - has n, :attachments, 'TentServer::Model::PostAttachment', :constraint => :destroy + has n, :permissions, 'TentD::Model::Permission', :constraint => :destroy + has n, :attachments, 'TentD::Model::PostAttachment', :constraint => :destroy def self.fetch_with_permissions(params, current_auth) super do |params, query, query_bindings| diff --git a/lib/tent-server/model/post_attachment.rb b/lib/tentd/model/post_attachment.rb similarity index 87% rename from lib/tent-server/model/post_attachment.rb rename to lib/tentd/model/post_attachment.rb index 0ceeb85..a5e2c6a 100644 --- a/lib/tent-server/model/post_attachment.rb +++ b/lib/tentd/model/post_attachment.rb @@ -1,4 +1,4 @@ -module TentServer +module TentD module Model class PostAttachment include DataMapper::Resource @@ -13,7 +13,7 @@ class PostAttachment property :size, Integer timestamps :at - belongs_to :post, 'TentServer::Model::Post' + belongs_to :post, 'TentD::Model::Post' def as_json(options = {}) super({ :exclude => [:id, :data, :post_id, :created_at, :updated_at] }.merge(options)) diff --git a/lib/tent-server/model/profile_info.rb b/lib/tentd/model/profile_info.rb similarity index 98% rename from lib/tent-server/model/profile_info.rb rename to lib/tentd/model/profile_info.rb index ad22390..9dbd9f2 100644 --- a/lib/tent-server/model/profile_info.rb +++ b/lib/tentd/model/profile_info.rb @@ -1,6 +1,6 @@ require 'hashie' -module TentServer +module TentD module Model class ProfileInfo include DataMapper::Resource diff --git a/lib/tent-server/model/random_public_id.rb b/lib/tentd/model/random_public_id.rb similarity index 98% rename from lib/tent-server/model/random_public_id.rb rename to lib/tentd/model/random_public_id.rb index 7c8c6c5..ff75968 100644 --- a/lib/tent-server/model/random_public_id.rb +++ b/lib/tentd/model/random_public_id.rb @@ -1,4 +1,4 @@ -module TentServer +module TentD module Model module RandomPublicId def self.included(base) diff --git a/lib/tent-server/rack_request.rb b/lib/tentd/rack_request.rb similarity index 98% rename from lib/tent-server/rack_request.rb rename to lib/tentd/rack_request.rb index ba55206..7b6e23b 100644 --- a/lib/tent-server/rack_request.rb +++ b/lib/tentd/rack_request.rb @@ -1,7 +1,7 @@ require 'rack/request' # All this so that we can have duplicate multipart names. -module TentServer +module TentD class RackRequest < Rack::Request # Use our custom multipart parser def parse_multipart(env) diff --git a/lib/tent-server/tent_version.rb b/lib/tentd/tent_version.rb similarity index 97% rename from lib/tent-server/tent_version.rb rename to lib/tentd/tent_version.rb index 25e3d57..e594ecd 100644 --- a/lib/tent-server/tent_version.rb +++ b/lib/tentd/tent_version.rb @@ -1,4 +1,4 @@ -module TentServer +module TentD class TentVersion Infinity = 1 / 0.0 diff --git a/lib/tent-server/version.rb b/lib/tentd/version.rb similarity index 57% rename from lib/tent-server/version.rb rename to lib/tentd/version.rb index 3016c8f..a2887c4 100644 --- a/lib/tent-server/version.rb +++ b/lib/tentd/version.rb @@ -1,3 +1,3 @@ -module TentServer +module TentD VERSION = '0.0.1' end diff --git a/spec/fabricators/app_authorizations_fabricator.rb b/spec/fabricators/app_authorizations_fabricator.rb index d47324b..6b08835 100644 --- a/spec/fabricators/app_authorizations_fabricator.rb +++ b/spec/fabricators/app_authorizations_fabricator.rb @@ -1 +1 @@ -Fabricator(:app_authorization, :class_name => 'TentServer::Model::AppAuthorization') +Fabricator(:app_authorization, :class_name => 'TentD::Model::AppAuthorization') diff --git a/spec/fabricators/apps_fabricator.rb b/spec/fabricators/apps_fabricator.rb index c77da77..8bb5ae4 100644 --- a/spec/fabricators/apps_fabricator.rb +++ b/spec/fabricators/apps_fabricator.rb @@ -1,4 +1,4 @@ -Fabricator(:app, :class_name => 'TentServer::Model::App') do +Fabricator(:app, :class_name => 'TentD::Model::App') do name "MicroBlogger" description "Manages your status updates" url "https://microbloggerapp.example.com" diff --git a/spec/fabricators/followers_fabricator.rb b/spec/fabricators/followers_fabricator.rb index 2635d1a..a964ebd 100644 --- a/spec/fabricators/followers_fabricator.rb +++ b/spec/fabricators/followers_fabricator.rb @@ -1,4 +1,4 @@ -Fabricator(:follower, :class_name => "TentServer::Model::Follower") do |f| +Fabricator(:follower, :class_name => "TentD::Model::Follower") do |f| f.entity "https://smith.example.com" f.public true f.licenses ["http://creativecommons.org/licenses/by-nc-sa/3.0/", "http://www.gnu.org/copyleft/gpl.html"] diff --git a/spec/fabricators/followings_fabricator.rb b/spec/fabricators/followings_fabricator.rb index 314bbcf..b2f5c4e 100644 --- a/spec/fabricators/followings_fabricator.rb +++ b/spec/fabricators/followings_fabricator.rb @@ -1,4 +1,4 @@ -Fabricator(:following, :class_name => "TentServer::Model::Following") do +Fabricator(:following, :class_name => "TentD::Model::Following") do entity "https://smith.example.com" licenses ["http://creativecommons.org/licenses/by-nc-sa/3.0/", "http://www.gnu.org/copyleft/gpl.html"] groups { ["family", "friends"].map {|name| g = Fabricate(:group); g.name = name; g.save!; g.public_id } } diff --git a/spec/fabricators/groups_fabricator.rb b/spec/fabricators/groups_fabricator.rb index 269f70a..f38b30a 100644 --- a/spec/fabricators/groups_fabricator.rb +++ b/spec/fabricators/groups_fabricator.rb @@ -1 +1 @@ -Fabricator(:group, :class_name => "TentServer::Model::Group") +Fabricator(:group, :class_name => "TentD::Model::Group") diff --git a/spec/fabricators/post_attachments_fabricator.rb b/spec/fabricators/post_attachments_fabricator.rb index e287b74..b8d546d 100644 --- a/spec/fabricators/post_attachments_fabricator.rb +++ b/spec/fabricators/post_attachments_fabricator.rb @@ -1,4 +1,4 @@ -Fabricator(:post_attachment, :class_name => "TentServer::Model::PostAttachment") do |f| +Fabricator(:post_attachment, :class_name => "TentD::Model::PostAttachment") do |f| post f.category 'foo-category' f.type 'text/plain' diff --git a/spec/fabricators/posts_fabricator.rb b/spec/fabricators/posts_fabricator.rb index dc89896..a4566a3 100644 --- a/spec/fabricators/posts_fabricator.rb +++ b/spec/fabricators/posts_fabricator.rb @@ -1,4 +1,4 @@ -Fabricator(:post, :class_name => "TentServer::Model::Post") do |f| +Fabricator(:post, :class_name => "TentD::Model::Post") do |f| f.entity "https://smith.example.com" f.public true f.type "https://tent.io/types/posts/status" diff --git a/spec/fabricators/profile_infos_fabricator.rb b/spec/fabricators/profile_infos_fabricator.rb index 0119354..e1bc375 100644 --- a/spec/fabricators/profile_infos_fabricator.rb +++ b/spec/fabricators/profile_infos_fabricator.rb @@ -1,4 +1,4 @@ -Fabricator(:profile_info, :class_name => 'TentServer::Model::ProfileInfo') do |f| +Fabricator(:profile_info, :class_name => 'TentD::Model::ProfileInfo') do |f| f.transient :tent f.entity "https://johnsmith.example.org" f.public true diff --git a/spec/integration/api/apps_spec.rb b/spec/integration/api/apps_spec.rb index a18e092..77f005c 100644 --- a/spec/integration/api/apps_spec.rb +++ b/spec/integration/api/apps_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' -require 'tent-server/core_ext/hash/slice' +require 'tentd/core_ext/hash/slice' -describe TentServer::API::Apps do +describe TentD::API::Apps do def app - TentServer::API.new + TentD::API.new end def authorize!(*scopes) @@ -30,7 +30,7 @@ def authorize!(*scopes) body = JSON.parse(last_response.body) body.each { |actual| - app = TentServer::Model::App.first(:public_id => actual['id']) + app = TentD::Model::App.first(:public_id => actual['id']) [:name, :description, :url, :icon, :redirect_uris, :scopes, :mac_key_id, :mac_key, :mac_algorithm, :mac_timestamp_delta].each { |key| expect(actual[key.to_s].to_json).to eq(app.send(key).to_json) } @@ -46,7 +46,7 @@ def authorize!(*scopes) expect(last_response.status).to eq(200) body = JSON.parse(last_response.body) body.each { |actual| - app = TentServer::Model::App.first(:public_id => actual['id']) + app = TentD::Model::App.first(:public_id => actual['id']) [:name, :description, :url, :icon, :redirect_uris, :scopes, :mac_key_id, :mac_algorithm].each { |key| expect(actual[key.to_s].to_json).to eq(app.send(key).to_json) } @@ -182,10 +182,10 @@ def authorize!(*scopes) it 'should create app' do data = Fabricate.build(:app).as_json(:only => [:name, :description, :url, :icon, :redirect_uris, :scopes]) - TentServer::Model::App.all.destroy - expect(lambda { json_post '/apps', data, env }).to change(TentServer::Model::App, :count).by(1) + TentD::Model::App.all.destroy + expect(lambda { json_post '/apps', data, env }).to change(TentD::Model::App, :count).by(1) - app = TentServer::Model::App.last + app = TentD::Model::App.last expect(last_response.status).to eq(200) data.slice(:name, :description, :url, :icon, :redirect_uris, :scopes).each_pair do |key, val| expect(app.send(key)).to eq(val) @@ -228,7 +228,7 @@ def authorize!(*scopes) context 'app with :id does not exist' do it 'should return 404' do - json_put "/apps/#{(TentServer::Model::App.count + 1) * 100}", params, env + json_put "/apps/#{(TentD::Model::App.count + 1) * 100}", params, env expect(last_response.status).to eq(404) end end @@ -269,7 +269,7 @@ def authorize!(*scopes) expect(lambda { delete "/apps/#{app.public_id}", params, env expect(last_response.status).to eq(200) - }).to change(TentServer::Model::App, :count).by(-1) + }).to change(TentD::Model::App, :count).by(-1) end end end diff --git a/spec/integration/api/followers_spec.rb b/spec/integration/api/followers_spec.rb index 3ac18f6..8dc1da4 100644 --- a/spec/integration/api/followers_spec.rb +++ b/spec/integration/api/followers_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' -describe TentServer::API::Followers do +describe TentD::API::Followers do def app - TentServer::API.new + TentD::API.new end def link_header(entity_url) @@ -79,9 +79,9 @@ def authorize!(*scopes) it 'should create follower db record and respond with hmac secret' do expect(lambda { json_post '/followers', follower_data, 'tent.entity' => 'smith.example.com' }). - to change(TentServer::Model::Follower, :count).by(1) + to change(TentD::Model::Follower, :count).by(1) expect(last_response.status).to eq(200) - follow = TentServer::Model::Follower.last + follow = TentD::Model::Follower.last expect(JSON.parse(last_response.body)).to eq({ "id" => follow.public_id, "mac_key_id" => follow.mac_key_id, @@ -92,9 +92,9 @@ def authorize!(*scopes) it 'should create notification subscription for each type given' do expect(lambda { json_post '/followers', follower_data, 'tent.entity' => 'smith.example.com' }). - to change(TentServer::Model::NotificationSubscription, :count).by(2) + to change(TentD::Model::NotificationSubscription, :count).by(2) expect(last_response.status).to eq(200) - expect(TentServer::Model::NotificationSubscription.last.view).to eq('meta') + expect(TentD::Model::NotificationSubscription.last.view).to eq('meta') end end end @@ -126,14 +126,14 @@ def authorize!(*scopes) it 'should create follower without discovery' do expect(lambda { json_post '/followers', follower_data, env }). - to change(TentServer::Model::Follower, :count).by(1) + to change(TentD::Model::Follower, :count).by(1) expect(last_response.status).to eq(200) end it 'should create notification subscription for each type given' do expect(lambda { json_post '/followers', follower_data, env }). - to change(TentServer::Model::NotificationSubscription, :count).by(2) - expect(TentServer::Model::NotificationSubscription.last.view).to eq('meta') + to change(TentD::Model::NotificationSubscription, :count).by(2) + expect(TentD::Model::NotificationSubscription.last.view).to eq('meta') expect(last_response.status).to eq(200) end end @@ -141,10 +141,10 @@ def authorize!(*scopes) context 'when write_secrets scope not authorized' do it 'should respond 403' do expect(lambda { json_post '/followers', follower_data, env }). - to_not change(TentServer::Model::Follower, :count) + to_not change(TentD::Model::Follower, :count) expect(lambda { json_post '/followers', follower_data, env }). - to_not change(TentServer::Model::NotificationSubscription, :count) + to_not change(TentD::Model::NotificationSubscription, :count) expect(last_response.status).to eq(403) end @@ -154,7 +154,7 @@ def authorize!(*scopes) describe 'GET /followers' do authorized_permissible = proc do it 'should return a list of followers' do - TentServer::Model::Follower.all.destroy! + TentD::Model::Follower.all.destroy! followers = 2.times.map { Fabricate(:follower, :public => true) } json_get '/followers', params, env expect(last_response.body).to eq(followers.map { |f| @@ -165,7 +165,7 @@ def authorize!(*scopes) authorized_full = proc do it 'should return a list of followers without mac keys' do - TentServer::Model::Follower.all.destroy! + TentD::Model::Follower.all.destroy! followers = 2.times.map { Fabricate(:follower, :public => false) } json_get '/followers', params, env expect(last_response.body).to eq(followers.map { |f| @@ -184,7 +184,7 @@ def authorize!(*scopes) before { authorize!(:read_followers, :read_secrets) } context 'when read_secrets param set to true' do it 'should return a list of followers with mac keys' do - TentServer::Model::Follower.all.destroy! + TentD::Model::Follower.all.destroy! followers = 2.times.map { Fabricate(:follower, :public => false) } json_get '/followers', params, env expect(last_response.body).to eq(followers.map { |f| @@ -344,14 +344,14 @@ def authorize!(*scopes) :types => follower.notification_subscriptions.map {|ns| ns.type.to_s}.concat(["https://tent.io/types/post/video/v0.1.x#meta"]) } expect( lambda { json_put "/followers/#{follower.public_id}", data, env } ). - to change(TentServer::Model::NotificationSubscription, :count).by (1) + to change(TentD::Model::NotificationSubscription, :count).by (1) follower.reload data = { :types => follower.notification_subscriptions.map {|ns| ns.type.to_s}[0..-2] } expect( lambda { json_put "/followers/#{follower.public_id}", data, env } ). - to change(TentServer::Model::NotificationSubscription, :count).by (-1) + to change(TentD::Model::NotificationSubscription, :count).by (-1) end end @@ -396,7 +396,7 @@ def authorize!(*scopes) authorized = proc do it 'should delete follower' do follower # create follower - expect(lambda { delete "/followers/#{follower.public_id}", params, env }).to change(TentServer::Model::Follower, :count).by(-1) + expect(lambda { delete "/followers/#{follower.public_id}", params, env }).to change(TentD::Model::Follower, :count).by(-1) expect(last_response.status).to eq(200) end end diff --git a/spec/integration/api/followings_spec.rb b/spec/integration/api/followings_spec.rb index 9e59587..cb8ed73 100644 --- a/spec/integration/api/followings_spec.rb +++ b/spec/integration/api/followings_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' -describe TentServer::API::Followings do +describe TentD::API::Followings do def app - TentServer::API.new + TentD::API.new end def authorize!(*scopes) @@ -22,7 +22,7 @@ def authorize!(*scopes) before do @create_permission = lambda do |following| - TentServer::Model::Permission.create( + TentD::Model::Permission.create( :following_id => following.id, current_auth.permissible_foreign_key => current_auth.id ) @@ -46,7 +46,7 @@ def authorize!(*scopes) context '[:before_id]' do it 'should only return followings with id < :before_id' do - TentServer::Model::Following.all.destroy! + TentD::Model::Following.all.destroy! following = Fabricate(:following, :public => !create_permissions?) before_following = Fabricate(:following, :public => !create_permissions?) @@ -72,9 +72,9 @@ def authorize!(*scopes) expect(JSON.parse(last_response.body).size).to eq(limit) end - context 'when [:limit] > TentServer::API::MAX_PER_PAGE' do - it 'should only return TentServer::API::MAX_PER_PAGE number of followings' do - with_constants "TentServer::API::MAX_PER_PAGE" => 0 do + context 'when [:limit] > TentD::API::MAX_PER_PAGE' do + it 'should only return TentD::API::MAX_PER_PAGE number of followings' do + with_constants "TentD::API::MAX_PER_PAGE" => 0 do limit = 1 following = Fabricate(:following, :public => !create_permissions?) @@ -90,8 +90,8 @@ def authorize!(*scopes) end context 'without [:limit]' do - it 'should only return TentServer::API::PER_PAGE number of followings' do - with_constants "TentServer::API::PER_PAGE" => 0 do + it 'should only return TentD::API::PER_PAGE number of followings' do + with_constants "TentD::API::PER_PAGE" => 0 do following = Fabricate(:following, :public => !create_permissions?) if create_permissions? @@ -107,7 +107,7 @@ def authorize!(*scopes) without_permissions = proc do it 'should only return public followings' do - TentServer::Model::Following.all(:public => true).destroy! + TentD::Model::Following.all(:public => true).destroy! public_following = Fabricate(:following, :public => true) private_following = Fabricate(:following, :public => false) @@ -144,7 +144,7 @@ def authorize!(*scopes) context 'via group' do it 'should return permissible and public followings' do current_auth.update(:groups => [group.public_id]) - TentServer::Model::Permission.create( + TentD::Model::Permission.create( :following_id => private_permissible_following.id, :group_public_id => group.public_id ) @@ -189,14 +189,14 @@ def authorize!(*scopes) it 'should return all followings without mac keys' do Fabricate(:following, :public => true) Fabricate(:following, :public => false) - count = TentServer::Model::Following.count - with_constants "TentServer::API::MAX_PER_PAGE" => count do + count = TentD::Model::Following.count + with_constants "TentD::API::MAX_PER_PAGE" => count do json_get '/followings', params, env expect(last_response.status).to eq(200) body = JSON.parse(last_response.body) expect(body.size).to eq(count) body.each do |actual| - following = TentServer::Model::Following.first(:public_id => actual['id']) + following = TentD::Model::Following.first(:public_id => actual['id']) [:remote_id, :entity, :groups, :public, :profile, :licenses].each { |key| expect(actual[key.to_s].to_json).to eq(following.send(key).to_json) } @@ -219,7 +219,7 @@ def authorize!(*scopes) expect(last_response.status).to eq(200) body = JSON.parse(last_response.body) body.each do |actual| - following = TentServer::Model::Following.first(:public_id => actual['id']) + following = TentD::Model::Following.first(:public_id => actual['id']) [:mac_key_id, :mac_key, :mac_algorithm, :mac_timestamp_delta, :remote_id, :entity, :groups, :public, :profile, :licenses].each { |key| expect(actual[key.to_s].to_json).to eq(following.send(key).to_json) } @@ -258,7 +258,7 @@ def authorize!(*scopes) context 'explicitly' do it 'should return following' do following = Fabricate(:following, :public => false) - TentServer::Model::Permission.create( + TentD::Model::Permission.create( :following_id => following.id, current_auth.permissible_foreign_key => current_auth.id ) @@ -272,7 +272,7 @@ def authorize!(*scopes) group = Fabricate(:group, :name => 'foo') current_auth.update(:groups => [group.public_id]) following = Fabricate(:following, :public => false, :groups => [group.public_id.to_s]) - TentServer::Model::Permission.create( + TentD::Model::Permission.create( :following_id => following.id, :group_public_id => group.public_id ) @@ -382,9 +382,9 @@ def authorize!(*scopes) context 'when write_followings scope authorized' do before do - @tent_profile = TentServer::Model::ProfileInfo.create( + @tent_profile = TentD::Model::ProfileInfo.create( :entity => tent_entity, - :type => TentServer::Model::ProfileInfo::TENT_PROFILE_TYPE_URI, + :type => TentD::Model::ProfileInfo::TENT_PROFILE_TYPE_URI, :content => { :licenses => ["http://creativecommons.org/licenses/by/3.0/"] } @@ -477,9 +477,9 @@ def authorize!(*scopes) it 'should create following' do expect(lambda { json_post '/followings', following_data, env - }).to change(TentServer::Model::Following, :count).by(1) + }).to change(TentD::Model::Following, :count).by(1) - following = TentServer::Model::Following.last + following = TentD::Model::Following.last expect(following.entity.to_s).to eq("https://sam.example.org") expect(following.groups).to eq([group.public_id.to_s]) expect(following.remote_id).to eq(follower.public_id.to_s) @@ -583,14 +583,14 @@ def authorize!(*scopes) context 'when exists' do it 'should delete following' do expect(lambda { delete "/followings/#{following.public_id}", params, env }). - to change(TentServer::Model::Following, :count).by(-1) + to change(TentD::Model::Following, :count).by(-1) end end context 'when does not exist' do it 'should return 404' do expect(lambda { delete "/followings/invalid-id", params, env }). - to_not change(TentServer::Model::Following, :count) + to_not change(TentD::Model::Following, :count) expect(last_response.status).to eq(404) end end @@ -599,7 +599,7 @@ def authorize!(*scopes) context 'when write_followings scope unauthorized' do it 'should return 403' do expect(lambda { delete "/followings/invalid-id", params, env }). - to_not change(TentServer::Model::Following, :count) + to_not change(TentD::Model::Following, :count) expect(last_response.status).to eq(403) end end diff --git a/spec/integration/api/groups_spec.rb b/spec/integration/api/groups_spec.rb index 869cb13..f1d064e 100644 --- a/spec/integration/api/groups_spec.rb +++ b/spec/integration/api/groups_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' -describe TentServer::API::Groups do +describe TentD::API::Groups do def app - TentServer::API.new + TentD::API.new end def authorize!(*scopes) @@ -24,7 +24,7 @@ def authorize!(*scopes) Fabricate(:group, :name => 'chunky-bacon').save! get '/groups', params, env - expect(last_response.body).to eq(TentServer::Model::Group.all.to_json) + expect(last_response.body).to eq(TentD::Model::Group.all.to_json) end end @@ -69,7 +69,7 @@ def authorize!(*scopes) group.name = 'bar-baz' expect(group.save).to be_true json_put "/groups/#{group.public_id}", group, env - actual_group = TentServer::Model::Group.get(group.id) + actual_group = TentD::Model::Group.get(group.id) expect(actual_group.name).to eq(group.name) expect(last_response.body).to eq(actual_group.to_json) end @@ -94,7 +94,7 @@ def authorize!(*scopes) it 'should create group' do expect(lambda { json_post "/groups", { :name => 'bacon-bacon' }, env }). - to change(TentServer::Model::Group, :count).by(1) + to change(TentD::Model::Group, :count).by(1) end end @@ -113,13 +113,13 @@ def authorize!(*scopes) it 'should destroy group' do group = Fabricate(:group, :name => 'foo-bar-baz') expect(lambda { delete "/groups/#{group.public_id}", params, env }). - to change(TentServer::Model::Group, :count).by(-1) + to change(TentD::Model::Group, :count).by(-1) end it 'should returh 404 if group does not exist' do Fabricate(:group, :name => 'baz') expect(lambda { delete "/groups/invalid-id", params, env }). - to change(TentServer::Model::Group, :count).by(0) + to change(TentD::Model::Group, :count).by(0) expect(last_response.status).to eq(404) end end diff --git a/spec/integration/api/posts_spec.rb b/spec/integration/api/posts_spec.rb index 47c0c74..f59f353 100644 --- a/spec/integration/api/posts_spec.rb +++ b/spec/integration/api/posts_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' -describe TentServer::API::Posts do +describe TentD::API::Posts do def app - TentServer::API.new + TentD::API.new end let(:authorized_post_types) { [] } @@ -34,7 +34,7 @@ def authorize!(*scopes) end it "should be 404 if post_id doesn't exist" do - TentServer::Model::Post.all.destroy! + TentD::Model::Post.all.destroy! json_get "/posts/1" expect(last_response.status).to eq(404) end @@ -50,7 +50,7 @@ def authorize!(*scopes) context 'when has explicit permission' do before do case current_auth - when TentServer::Model::Follower + when TentD::Model::Follower current_auth.access_permissions.create(:post_id => post.id) else current_auth.permissions.create(:post_id => post.id) @@ -155,9 +155,9 @@ def authorize!(*scopes) describe 'GET /posts' do let(:post_public?) { true } with_params = proc do - it "should respond with first TentServer::API::PER_PAGE posts if no params given" do - with_constants "TentServer::API::PER_PAGE" => 1 do - 0.upto(TentServer::API::PER_PAGE+1).each { Fabricate(:post, :public => post_public?).save! } + it "should respond with first TentD::API::PER_PAGE posts if no params given" do + with_constants "TentD::API::PER_PAGE" => 1 do + 0.upto(TentD::API::PER_PAGE+1).each { Fabricate(:post, :public => post_public?).save! } json_get '/posts', params, env expect(JSON.parse(last_response.body).size).to eq(1) end @@ -176,7 +176,7 @@ def authorize!(*scopes) blog_post.type = blog_type_uri blog_post.save! - posts = TentServer::Model::Post.all(:type => [picture_type_uri, blog_type_uri]) + posts = TentD::Model::Post.all(:type => [picture_type_uri, blog_type_uri]) post_types = [picture_post, blog_post].map { |p| URI.escape(p.type.to_s, "://") } json_get "/posts?post_types=#{post_types.join(',')}", params, env @@ -194,7 +194,7 @@ def authorize!(*scopes) end it "should filter by params[:before_id]" do - TentServer::Model::Post.all.destroy! + TentD::Model::Post.all.destroy! post = Fabricate(:post, :public => post_public?) post.save! before_post = Fabricate(:post, :public => post_public?) @@ -262,8 +262,8 @@ def authorize!(*scopes) expect(JSON.parse(last_response.body).size).to eq(1) end - it "limit should never exceed TentServer::API::MAX_PER_PAGE" do - with_constants "TentServer::API::MAX_PER_PAGE" => 0 do + it "limit should never exceed TentD::API::MAX_PER_PAGE" do + with_constants "TentD::API::MAX_PER_PAGE" => 0 do 0.upto(2).each { Fabricate(:post, :public => post_public?).save! } json_get '/posts?limit=1', params, env expect(last_response.body).to eq([].to_json) @@ -291,7 +291,7 @@ def authorize!(*scopes) context 'when post type not authorized' do it 'should return empty array' do - TentServer::Model::Post.all.destroy + TentD::Model::Post.all.destroy post = Fabricate(:post, :public => false) json_get "/posts", params, env expect(last_response.body).to eq([].to_json) @@ -306,8 +306,8 @@ def authorize!(*scopes) it "should create post" do post = Fabricate(:post) post_attributes = post.as_json(:exclude => [:id]) - expect(lambda { json_post "/posts", post_attributes, env }).to change(TentServer::Model::Post, :count).by(1) - expect(last_response.body).to eq(TentServer::Model::Post.last.to_json) + expect(lambda { json_post "/posts", post_attributes, env }).to change(TentD::Model::Post, :count).by(1) + expect(last_response.body).to eq(TentD::Model::Post.last.to_json) end it 'should create post with multipart attachments' do @@ -320,15 +320,15 @@ def authorize!(*scopes) expect(lambda { expect(lambda { multipart_post('/posts', post_attributes, attachments, env) - }).to change(TentServer::Model::Post, :count).by(1) - }).to change(TentServer::Model::PostAttachment, :count).by(4) - expect(last_response.body).to eq(TentServer::Model::Post.last.to_json) + }).to change(TentD::Model::Post, :count).by(1) + }).to change(TentD::Model::PostAttachment, :count).by(4) + expect(last_response.body).to eq(TentD::Model::Post.last.to_json) end end context 'without write_posts scope authorized' do it 'should respond 403' do - expect(lambda { json_post "/posts", {}, env }).to_not change(TentServer::Model::Post, :count) + expect(lambda { json_post "/posts", {}, env }).to_not change(TentD::Model::Post, :count) expect(last_response.status).to eq(403) end end diff --git a/spec/integration/api/profile_spec.rb b/spec/integration/api/profile_spec.rb index 66a44f5..e14958f 100644 --- a/spec/integration/api/profile_spec.rb +++ b/spec/integration/api/profile_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' -describe TentServer::API::Profile do +describe TentD::API::Profile do def app - TentServer::API.new + TentD::API.new end let(:entity) { 'https://smith.example.org' } @@ -52,7 +52,7 @@ def create_info(type, content, options = {}) let(:authorized_info_types) { ['all'] } it 'should return all info types' do - TentServer::Model::ProfileInfo.all.destroy + TentD::Model::ProfileInfo.all.destroy profile_infos = [] profile_infos << Fabricate(:profile_info, :public => false, :entity => entity, :tent => true) @@ -70,7 +70,7 @@ def create_info(type, content, options = {}) let(:authorized_info_types) { ['https://tent.io/types/info/basic-info'] } it 'should only return authorized info types' do - TentServer::Model::ProfileInfo.all.destroy + TentD::Model::ProfileInfo.all.destroy profile_infos = [] profile_infos << Fabricate(:profile_info, :public => false, :entity => entity, :type => "https://tent.io/types/info/basic-info") @@ -86,7 +86,7 @@ def create_info(type, content, options = {}) context 'when read_profile scope unauthorized' do it 'should only return public profile into types' do - TentServer::Model::ProfileInfo.all.destroy + TentD::Model::ProfileInfo.all.destroy profile_infos = [] profile_infos << Fabricate(:profile_info, :public => true, :entity => entity, :tent => true) @@ -121,7 +121,7 @@ def create_info(type, content, options = {}) end it 'should create unless exists' do - TentServer::Model::ProfileInfo.all.destroy + TentD::Model::ProfileInfo.all.destroy data = { "name" => "John Doe" @@ -129,9 +129,9 @@ def create_info(type, content, options = {}) expect(lambda { json_put "/profile/#{url_encode_type(basic_info_type)}", data, env - }).to change(TentServer::Model::ProfileInfo, :count).by(1) + }).to change(TentD::Model::ProfileInfo, :count).by(1) - info = TentServer::Model::ProfileInfo.last + info = TentD::Model::ProfileInfo.last expect(info.content).to eq(data) expect(last_response.status).to eq(200) end @@ -179,7 +179,7 @@ def diff_encode_type(type) can_update_basic_info_type = proc do it 'should update basic info with diff' do - TentServer::Model::ProfileInfo.all.destroy + TentD::Model::ProfileInfo.all.destroy info = create_info(basic_info_type, basic_info_content, :public => false) @@ -201,7 +201,7 @@ def diff_encode_type(type) end it 'should return 422 if diff tests fail' do - TentServer::Model::ProfileInfo.all.destroy + TentD::Model::ProfileInfo.all.destroy info = create_info(basic_info_type, basic_info_content, :public => false) @@ -227,7 +227,7 @@ def diff_encode_type(type) context '', &can_update_basic_info_type it 'should update any info' do - TentServer::Model::ProfileInfo.all.destroy + TentD::Model::ProfileInfo.all.destroy info = create_info(basic_info_type, basic_info_content, :public => false) @@ -253,12 +253,12 @@ def diff_encode_type(type) expect(lambda { json_patch "/profile", diff, env - }).to change(TentServer::Model::ProfileInfo, :count).by(1) + }).to change(TentD::Model::ProfileInfo, :count).by(1) expect(last_response.status).to eq(200) expect(info.reload.content).to eq(expected_basic_data) - work_info = TentServer::Model::ProfileInfo.last + work_info = TentD::Model::ProfileInfo.last expect(work_info.content).to eq(expected_work_data) end end diff --git a/spec/integration/api/router_spec.rb b/spec/integration/api/router_spec.rb index 13d4e12..aa59d67 100644 --- a/spec/integration/api/router_spec.rb +++ b/spec/integration/api/router_spec.rb @@ -1,21 +1,21 @@ require 'spec_helper' -describe TentServer::API::Router do - class TestMiddleware < TentServer::API::Middleware +describe TentD::API::Router do + class TestMiddleware < TentD::API::Middleware def action(env) env['response'] = { 'params' => env['params'] } env end end - class TestMiddlewarePrematureResponse < TentServer::API::Middleware + class TestMiddlewarePrematureResponse < TentD::API::Middleware def action(env) [200, { 'Content-Type' => 'text/plain' }, 'Premature-Response'] end end class TestMountedApp - include TentServer::API::Router + include TentD::API::Router get '/chunky/:bacon' do |b| b.use TestMiddleware @@ -23,7 +23,7 @@ class TestMountedApp end class TestApp - include TentServer::API::Router + include TentD::API::Router get '/foo/:bar' do |b| b.use TestMiddleware diff --git a/spec/integration/model/follower_spec.rb b/spec/integration/model/follower_spec.rb index 6961d6b..1bb59f0 100644 --- a/spec/integration/model/follower_spec.rb +++ b/spec/integration/model/follower_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe TentServer::Model::Follower do +describe TentD::Model::Follower do describe 'find_with_permissions(id, current_auth)' do public_expectations = proc do it 'should return follower if public' do @@ -27,7 +27,7 @@ context 'when has permission' do it 'should return follower' do follower = Fabricate(:follower, :public => false) - TentServer::Model::Permission.create( + TentD::Model::Permission.create( :follower_visibility_id => follower.id, current_auth.permissible_foreign_key => current_auth.id) response = described_class.find_with_permissions(follower.id, current_auth) @@ -55,8 +55,8 @@ public_follower = Fabricate(:follower, :public => true) private_follower = Fabricate(:follower, :public => false) - max_count = TentServer::Model::Follower.count - with_constants "TentServer::API::MAX_PER_PAGE" => max_count, "TentServer::API::PER_PAGE" => max_count do + max_count = TentD::Model::Follower.count + with_constants "TentD::API::MAX_PER_PAGE" => max_count, "TentD::API::PER_PAGE" => max_count do res = described_class.fetch_all(params) expect(res).to include(public_follower) expect(res).to include(private_follower) @@ -78,7 +78,7 @@ context '[:before_id]' do it 'should only return followers with id < :since_id' do - TentServer::Model::Follower.all.destroy + TentD::Model::Follower.all.destroy follower = Fabricate(:follower, :public => false) before_follower = Fabricate(:follower, :public => false) @@ -100,13 +100,13 @@ expect(res.size).to eq(limit) end - it 'should never return more than TentServer::API::MAX_PER_PAGE followers' do + it 'should never return more than TentD::API::MAX_PER_PAGE followers' do limit = 1 Fabricate(:follower, :public => false) params['limit'] = limit - with_constants "TentServer::API::MAX_PER_PAGE" => 0 do + with_constants "TentD::API::MAX_PER_PAGE" => 0 do res = described_class.fetch_all(params) expect(res.size).to eq(0) end @@ -114,10 +114,10 @@ end context 'without [:limit]' do - it 'should never return more than TentServer::API::MAX_PER_PAGE followers' do + it 'should never return more than TentD::API::MAX_PER_PAGE followers' do Fabricate(:follower, :public => false) - with_constants "TentServer::API::MAX_PER_PAGE" => 0 do + with_constants "TentD::API::MAX_PER_PAGE" => 0 do res = described_class.fetch_all(params) expect(res.size).to eq(0) end @@ -134,7 +134,7 @@ before do if current_auth && authorize_folower @authorize_folower = lambda do |follower| - TentServer::Model::Permission.create( + TentD::Model::Permission.create( :follower_visibility_id => follower.id, current_auth.permissible_foreign_key => current_auth.id ) @@ -160,11 +160,11 @@ context '[:before_id]' do it 'should only return followers with id < :before_id' do - if current_auth.kind_of?(TentServer::Model::Follower) - TentServer::Model::Follower.all(:id.not => current_auth.id).destroy! + if current_auth.kind_of?(TentD::Model::Follower) + TentD::Model::Follower.all(:id.not => current_auth.id).destroy! follower = current_auth else - TentServer::Model::Follower.all.destroy! + TentD::Model::Follower.all.destroy! follower = Fabricate(:follower, :public => !authorize_folower) end @@ -196,8 +196,8 @@ expect(response.size).to eq(limit) end - it 'should never return more than TentServer::API::MAX_PER_PAGE followers' do - with_constants "TentServer::API::MAX_PER_PAGE" => 0 do + it 'should never return more than TentD::API::MAX_PER_PAGE followers' do + with_constants "TentD::API::MAX_PER_PAGE" => 0 do followers = [Fabricate(:follower, :public => !authorize_folower)] if authorize_folower @@ -211,8 +211,8 @@ end context 'without [:limit]' do - it 'should only return TentServer::API::PER_PAGE number of followers' do - with_constants "TentServer::API::PER_PAGE" => 1 do + it 'should only return TentD::API::PER_PAGE number of followers' do + with_constants "TentD::API::PER_PAGE" => 1 do followers = 2.times.map { Fabricate(:follower, :public => !authorize_folower) } if authorize_folower @@ -228,8 +228,8 @@ public_expectations = proc do it 'should only return public followers' do - max_results = TentServer::Model::Follower.count + 100 - with_constants "TentServer::API::MAX_PER_PAGE" => max_results, "TentServer::API::PER_PAGE" => max_results do + max_results = TentD::Model::Follower.count + 100 + with_constants "TentD::API::MAX_PER_PAGE" => max_results, "TentD::API::PER_PAGE" => max_results do public_follower = Fabricate(:follower, :public => true) private_follower = Fabricate(:follower, :public => false) @@ -254,7 +254,7 @@ public_follower = Fabricate(:follower, :public => true) private_follower = Fabricate(:follower, :public => false) - TentServer::Model::Permission.create( + TentD::Model::Permission.create( :follower_visibility_id => private_follower.id, current_auth.permissible_foreign_key => current_auth.id ) diff --git a/spec/integration/model/following_spec.rb b/spec/integration/model/following_spec.rb index a04eaa8..5114732 100644 --- a/spec/integration/model/following_spec.rb +++ b/spec/integration/model/following_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe TentServer::Model::Following do +describe TentD::Model::Following do describe "#as_json" do it "should replace id with public_id" do post = Fabricate(:post) diff --git a/spec/integration/model/group_spec.rb b/spec/integration/model/group_spec.rb index 5b110a1..2c54e6c 100644 --- a/spec/integration/model/group_spec.rb +++ b/spec/integration/model/group_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe TentServer::Model::Group do +describe TentD::Model::Group do it 'should set random_uid for public_id' do group = Fabricate(:group) expect(group.public_id).to be_a(String) diff --git a/spec/integration/model/notification_subscription_spec.rb b/spec/integration/model/notification_subscription_spec.rb index 4013ca1..ec6fa64 100644 --- a/spec/integration/model/notification_subscription_spec.rb +++ b/spec/integration/model/notification_subscription_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe TentServer::Model::NotificationSubscription do +describe TentD::Model::NotificationSubscription do it 'should parse view from type URI before save' do instance = described_class.new(:type => "https://tent.io/types/posts/photo/v0.1.x#meta") expect(instance.save).to be_true diff --git a/spec/integration/model/post_spec.rb b/spec/integration/model/post_spec.rb index 5d23021..8c63905 100644 --- a/spec/integration/model/post_spec.rb +++ b/spec/integration/model/post_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe TentServer::Model::Post do +describe TentD::Model::Post do describe 'find_with_permissions(id, current_auth)' do shared_examples 'current_auth param' do let(:group) { Fabricate(:group, :name => 'family') } @@ -8,7 +8,7 @@ context 'when has permission via explicit' do before do - TentServer::Model::Permission.create( + TentD::Model::Permission.create( :post_id => post.id, current_auth.permissible_foreign_key => current_auth.id ) @@ -56,13 +56,13 @@ with_params = proc do before do if current_auth && create_permissions == true - @authorize_post = lambda { |post| TentServer::Model::Permission.create(:post_id => post.id, current_auth.permissible_foreign_key => current_auth.id) } + @authorize_post = lambda { |post| TentD::Model::Permission.create(:post_id => post.id, current_auth.permissible_foreign_key => current_auth.id) } end end context '[:since_id]' do it 'should only return posts with ids > :since_id' do - TentServer::Model::Post.all.destroy! + TentD::Model::Post.all.destroy! since_post = Fabricate(:post, :public => !create_permissions) post = Fabricate(:post, :public => !create_permissions) @@ -79,7 +79,7 @@ context '[:before_id]' do it 'should only return posts with ids < :before_id' do - TentServer::Model::Post.all.destroy! + TentD::Model::Post.all.destroy! post = Fabricate(:post, :public => !create_permissions) before_post = Fabricate(:post, :public => !create_permissions) @@ -96,7 +96,7 @@ context '[:since_time]' do it 'should only return posts with published_at > :since_time' do - TentServer::Model::Post.all.destroy! + TentD::Model::Post.all.destroy! since_post = Fabricate(:post, :public => !create_permissions, :published_at => Time.at(Time.now.to_i + (86400 * 10))) # 10.days.from_now post = Fabricate(:post, :public => !create_permissions, @@ -115,7 +115,7 @@ context '[:before_time]' do it 'should only return posts with published_at < :before_time' do - TentServer::Model::Post.all.destroy! + TentD::Model::Post.all.destroy! post = Fabricate(:post, :public => !create_permissions, :published_at => Time.at(Time.now.to_i - (86400 * 10))) # 10.days.ago before_post = Fabricate(:post, :public => !create_permissions, @@ -134,7 +134,7 @@ context '[:post_types]' do it 'should only return posts type in :post_types' do - TentServer::Model::Post.all.destroy! + TentD::Model::Post.all.destroy! photo_post = Fabricate(:post, :public => !create_permissions, :type => "https://tent.io/types/posts/photo") blog_post = Fabricate(:post, :public => !create_permissions, :type => "https://tent.io/types/posts/blog") status_post = Fabricate(:post, :public => !create_permissions, :type => "https://tent.io/types/posts/status") @@ -167,7 +167,7 @@ expect(returned_posts.size).to eq(limit) end - it 'should never return more than TentServer::API::MAX_PER_PAGE' do + it 'should never return more than TentD::API::MAX_PER_PAGE' do limit = 1 posts = 0.upto(limit).map { Fabricate(:post, :public => !create_permissions) } @@ -177,7 +177,7 @@ params['limit'] = limit.to_s - with_constants "TentServer::API::MAX_PER_PAGE" => 0 do + with_constants "TentD::API::MAX_PER_PAGE" => 0 do returned_posts = described_class.fetch_with_permissions(params, current_auth) expect(returned_posts.size).to eq(0) end @@ -185,9 +185,9 @@ end context 'no [:limit]' do - it 'should return TentServer::API::PER_PAGE number of posts' do - with_constants "TentServer::API::PER_PAGE" => 1, "TentServer::API::MAX_PER_PAGE" => 2 do - limit = TentServer::API::PER_PAGE + it 'should return TentD::API::PER_PAGE number of posts' do + with_constants "TentD::API::PER_PAGE" => 1, "TentD::API::MAX_PER_PAGE" => 2 do + limit = TentD::API::PER_PAGE posts = 0.upto(limit+1).map { Fabricate(:post, :public => !create_permissions) } if create_permissions @@ -223,7 +223,7 @@ it 'should return private posts' do private_post = Fabricate(:post, :public => false) public_post = Fabricate(:post, :public => true) - TentServer::Model::Permission.create(:post_id => private_post.id, current_auth.permissible_foreign_key => current_auth.id) + TentD::Model::Permission.create(:post_id => private_post.id, current_auth.permissible_foreign_key => current_auth.id) returned_posts = described_class.fetch_with_permissions(params, current_auth) expect(returned_posts).to include(private_post) @@ -346,12 +346,12 @@ let(:follower) { Fabricate(:follower) } it "should be true for permission group" do - TentServer::Model::Permission.create(:group_public_id => follower.groups.first, :post_id => post.id) + TentD::Model::Permission.create(:group_public_id => follower.groups.first, :post_id => post.id) expect(post.can_notify?(follower)).to be_true end it "should be true for explicit permission" do - TentServer::Model::Permission.create(:follower_access_id => follower.id, :post_id => post.id) + TentD::Model::Permission.create(:follower_access_id => follower.id, :post_id => post.id) expect(post.can_notify?(follower)).to be_true end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 53c9436..74070a7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,7 +4,7 @@ require 'bundler/setup' require 'mocha_standalone' require 'rack/test' -require 'tent-server' +require 'tentd' require 'fabrication' Dir["#{File.dirname(__FILE__)}/support/*.rb"].each { |f| require f } diff --git a/spec/support/json_request.rb b/spec/support/json_request.rb index 9154fb1..280e0ad 100644 --- a/spec/support/json_request.rb +++ b/spec/support/json_request.rb @@ -2,31 +2,31 @@ module JsonRequest def json_patch(path, data = {}, rack_env = {}) - patch path, data.to_json, { 'CONTENT_TYPE' => TentServer::API::MEDIA_TYPE }.merge(rack_env) + patch path, data.to_json, { 'CONTENT_TYPE' => TentD::API::MEDIA_TYPE }.merge(rack_env) end def json_put(path, data = {}, rack_env= {}) - put path, data.to_json, { 'CONTENT_TYPE' => TentServer::API::MEDIA_TYPE }.merge(rack_env) + put path, data.to_json, { 'CONTENT_TYPE' => TentD::API::MEDIA_TYPE }.merge(rack_env) end def json_post(path, data = {}, rack_env = {}) - post path, data.to_json, { 'CONTENT_TYPE' => TentServer::API::MEDIA_TYPE }.merge(rack_env) + post path, data.to_json, { 'CONTENT_TYPE' => TentD::API::MEDIA_TYPE }.merge(rack_env) end def json_get(path, data = {}, rack_env = {}) - get path, data, { 'HTTP_ACCEPT' => TentServer::API::MEDIA_TYPE }.merge(rack_env) + get path, data, { 'HTTP_ACCEPT' => TentD::API::MEDIA_TYPE }.merge(rack_env) end def multipart_post(path, json, parts, rack_env = {}) body = build_json_part(json) + build_parts(parts) + "--#{Rack::Multipart::MULTIPART_BOUNDARY}--\r" post path, body, { 'CONTENT_TYPE' => "multipart/form-data; boundary=#{Rack::Multipart::MULTIPART_BOUNDARY}", - 'HTTP_ACCEPT' => TentServer::API::MEDIA_TYPE }.merge(rack_env) + 'HTTP_ACCEPT' => TentD::API::MEDIA_TYPE }.merge(rack_env) end private def build_json_part(json) - build_part('post', :filename => 'post.json', :content_type => TentServer::API::MEDIA_TYPE, :content => json.to_json) + build_part('post', :filename => 'post.json', :content_type => TentD::API::MEDIA_TYPE, :content => json.to_json) end def build_parts(parts) diff --git a/spec/unit/api/authentication_finalize_spec.rb b/spec/unit/api/authentication_finalize_spec.rb index 05b257f..e79359d 100644 --- a/spec/unit/api/authentication_finalize_spec.rb +++ b/spec/unit/api/authentication_finalize_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' -describe TentServer::API::AuthenticationFinalize do +describe TentD::API::AuthenticationFinalize do def app - TentServer::API.new + TentD::API.new end it "should set current_auth" do diff --git a/spec/unit/api/authentication_lookup_spec.rb b/spec/unit/api/authentication_lookup_spec.rb index 92ed242..cacb569 100644 --- a/spec/unit/api/authentication_lookup_spec.rb +++ b/spec/unit/api/authentication_lookup_spec.rb @@ -1,16 +1,16 @@ require 'spec_helper' -describe TentServer::API::AuthenticationLookup do +describe TentD::API::AuthenticationLookup do def app - TentServer::API.new + TentD::API.new end let(:env) { Hashie::Mash.new({}) } let(:auth_header) { 'MAC id="%s:h480djs93hd8", ts="1336363200", nonce="dj83hs9s", mac="hqpo01mLJLSYDbxmfRgNMEw38Wg="' } it 'should parse hmac authorization header' do - TentServer::Model::Follower.all.destroy - follow = TentServer::Model::Follower.create(:mac_key_id => "s:h480djs93hd8") + TentD::Model::Follower.all.destroy + follow = TentD::Model::Follower.create(:mac_key_id => "s:h480djs93hd8") env['HTTP_AUTHORIZATION'] = auth_header % 's' described_class.new(app).call(env) expect(env['hmac']).to eq({ @@ -24,8 +24,8 @@ def app end it 'should lookup server authentication model' do - TentServer::Model::Follower.all(:mac_key_id => "s:h480djs93hd8").destroy - follow = TentServer::Model::Follower.create(:mac_key_id => "s:h480djs93hd8") + TentD::Model::Follower.all(:mac_key_id => "s:h480djs93hd8").destroy + follow = TentD::Model::Follower.create(:mac_key_id => "s:h480djs93hd8") expect(follow.saved?).to be_true env['HTTP_AUTHORIZATION'] = auth_header % 's' described_class.new(app).call(env) @@ -35,8 +35,8 @@ def app end it 'should lookup app authentication model' do - TentServer::Model::App.all.destroy - authed_app = TentServer::Model::App.create(:mac_key_id => "a:h480djs93hd8") + TentD::Model::App.all.destroy + authed_app = TentD::Model::App.create(:mac_key_id => "a:h480djs93hd8") expect(authed_app.saved?).to be_true env['HTTP_AUTHORIZATION'] = auth_header % 'a' described_class.new(app).call(env) @@ -46,9 +46,9 @@ def app end it 'should lookup user authentication model' do - TentServer::Model::AppAuthorization.all.destroy - authed_user = TentServer::Model::AppAuthorization.create(:mac_key_id => "u:h480djs93hd8", - :app => TentServer::Model::App.create) + TentD::Model::AppAuthorization.all.destroy + authed_user = TentD::Model::AppAuthorization.create(:mac_key_id => "u:h480djs93hd8", + :app => TentD::Model::App.create) expect(authed_user.saved?).to be_true env['HTTP_AUTHORIZATION'] = auth_header % 'u' described_class.new(app).call(env) diff --git a/spec/unit/api/authentication_verification_spec.rb b/spec/unit/api/authentication_verification_spec.rb index 93730f6..6eb4333 100644 --- a/spec/unit/api/authentication_verification_spec.rb +++ b/spec/unit/api/authentication_verification_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' -describe TentServer::API::AuthenticationVerification do +describe TentD::API::AuthenticationVerification do def app - TentServer::API.new + TentD::API.new end it 'should verify mac signature' do diff --git a/spec/unit/api/authorizable_spec.rb b/spec/unit/api/authorizable_spec.rb index 79035af..3740b80 100644 --- a/spec/unit/api/authorizable_spec.rb +++ b/spec/unit/api/authorizable_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' require 'hashie' -describe TentServer::API::Authorizable do +describe TentD::API::Authorizable do class TestMiddleware2 - include TentServer::API::Authorizable + include TentD::API::Authorizable def initialize(app) @app = app @@ -15,7 +15,7 @@ def call(env) end end - class OtherTestMiddleware < TentServer::API::Middleware + class OtherTestMiddleware < TentD::API::Middleware def action(env) authorize_env!(env, :read_posts) env @@ -23,7 +23,7 @@ def action(env) end def app - TentServer::API.new + TentD::API.new end let(:env) { Hashie::Mash.new } @@ -39,7 +39,7 @@ def app expect( lambda { middleware.call(env) } ).to_not raise_error end - context 'when TentServer::API::Middleware' do + context 'when TentD::API::Middleware' do it 'should respond 403 unless env.authorized_scopes includes scope' do response = OtherTestMiddleware.new(app).call(env) expect(response).to be_an(Array) diff --git a/spec/unit/api/authorization_spec.rb b/spec/unit/api/authorization_spec.rb index 3af310a..ee0a2b6 100644 --- a/spec/unit/api/authorization_spec.rb +++ b/spec/unit/api/authorization_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' require 'hashie' -describe TentServer::API::Authorization do +describe TentD::API::Authorization do def app - TentServer::API.new + TentD::API.new end let(:env) { Hashie::Mash.new } diff --git a/spec/unit/api/caching_headers_spec.rb b/spec/unit/api/caching_headers_spec.rb index 9fe9cb5..dc448a4 100644 --- a/spec/unit/api/caching_headers_spec.rb +++ b/spec/unit/api/caching_headers_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' -describe TentServer::API::Router::CachingHeaders do +describe TentD::API::Router::CachingHeaders do let(:app) { lambda { |env| [200, {}, ''] } } - let(:middleware) { TentServer::API::Router::CachingHeaders.new(app) } + let(:middleware) { TentD::API::Router::CachingHeaders.new(app) } let(:env) { Hashie::Mash.new } shared_examples 'conditional get' do diff --git a/spec/unit/core_profile_data_spec.rb b/spec/unit/core_profile_data_spec.rb index c26eb6c..50e6c36 100644 --- a/spec/unit/core_profile_data_spec.rb +++ b/spec/unit/core_profile_data_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe TentServer::API::CoreProfileData do +describe TentD::API::CoreProfileData do let(:tent_profile_type_uri) { "https://tent.io/types/info/core/v0.1.0" } let(:entity_url) { "https://smith.example.com" } let(:another_entity_url) { "https://alex.example.org" } @@ -24,8 +24,8 @@ end describe '#expected_version' do it 'should return TentVersion representing sever tent profile type uri version' do - with_constants "TentServer::Model::ProfileInfo::TENT_PROFILE_TYPE_URI" => tent_profile_type_uri do - expect(described_class.new(data).expected_version).to eq(TentServer::TentVersion.new('0.1.0')) + with_constants "TentD::Model::ProfileInfo::TENT_PROFILE_TYPE_URI" => tent_profile_type_uri do + expect(described_class.new(data).expected_version).to eq(TentD::TentVersion.new('0.1.0')) end end end @@ -33,16 +33,16 @@ describe '#versions' do it 'should return array of TentVersions found in data matching core info type' do expect(described_class.new(data).versions).to eq([ - TentServer::TentVersion.new('0.1.1'), - TentServer::TentVersion.new('0.1.5'), - TentServer::TentVersion.new('0.2.0') + TentD::TentVersion.new('0.1.1'), + TentD::TentVersion.new('0.1.5'), + TentD::TentVersion.new('0.2.0') ]) end end describe '#version' do it 'should return closest compatible version' do - expect(described_class.new(data).version).to eq(TentServer::TentVersion.new('0.1.1')) + expect(described_class.new(data).version).to eq(TentD::TentVersion.new('0.1.1')) end end diff --git a/spec/unit/json_patch_spec.rb b/spec/unit/json_patch_spec.rb index e5f8e04..4b653aa 100644 --- a/spec/unit/json_patch_spec.rb +++ b/spec/unit/json_patch_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe TentServer::JsonPatch::HashPointer do +describe TentD::JsonPatch::HashPointer do context 'when finding pointer' do it 'should find nested hash' do hash = { "a" => { "b" => { "c" => "foo" } } } @@ -135,24 +135,24 @@ end end -describe TentServer::JsonPatch do +describe TentD::JsonPatch do describe 'add' do it 'should add new value at specified location' do object = {} patch_object = [{ "add" => "a/b/c", "value" => ["foo", "bar", "baz"] }] - TentServer::JsonPatch.merge(object, patch_object) + TentD::JsonPatch.merge(object, patch_object) expect(object).to be_a(Hash) expect(object["a"]["b"]["c"]).to eq(["foo", "bar", "baz"]) object = { "a" => {} } patch_object = [{ "add" => "a/b/c", "value" => ["foo", "bar", "baz"] }] - TentServer::JsonPatch.merge(object, patch_object) + TentD::JsonPatch.merge(object, patch_object) expect(object).to be_a(Hash) expect(object["a"]["b"]["c"]).to eq(["foo", "bar", "baz"]) object = { "a" => { "b" => {} } } patch_object = [{ "add" => "a/b/c", "value" => ["foo", "bar", "baz"] }] - TentServer::JsonPatch.merge(object, patch_object) + TentD::JsonPatch.merge(object, patch_object) expect(object).to be_a(Hash) expect(object["a"]["b"]["c"]).to eq(["foo", "bar", "baz"]) end @@ -160,31 +160,31 @@ it 'should throw exception if specified location exists' do object = { "a" => "foo" } patch_object = [{ "add" => "a/b/c", "value" => ["foo", "bar", "baz"] }] - expect( lambda { TentServer::JsonPatch.merge(object, patch_object) } ). + expect( lambda { TentD::JsonPatch.merge(object, patch_object) } ). to raise_error(described_class::ObjectExists) expect(object["a"]).to eq("foo") object = { "a" => { "b" => "foo" } } patch_object = [{ "add" => "a/b/c", "value" => ["foo", "bar", "baz"] }] - expect( lambda { TentServer::JsonPatch.merge(object, patch_object) } ). + expect( lambda { TentD::JsonPatch.merge(object, patch_object) } ). to raise_error(described_class::ObjectExists) expect(object["a"]).to eq("b" => "foo") object = { "a" => { "b" => { "c" => "foo" } } } patch_object = [{ "add" => "a/b/c", "value" => ["foo", "bar", "baz"] }] - expect( lambda { TentServer::JsonPatch.merge(object, patch_object) } ). + expect( lambda { TentD::JsonPatch.merge(object, patch_object) } ). to raise_error(described_class::ObjectExists) expect(object["a"]).to eq("b" => { "c" => "foo" }) object = { "a" => { "b" => { "c" => "foo" } } } patch_object = [{ "add" => "a/b/c/d/e/f/g", "value" => ["foo", "bar", "baz"] }] - expect( lambda { TentServer::JsonPatch.merge(object, patch_object) } ). + expect( lambda { TentD::JsonPatch.merge(object, patch_object) } ). to raise_error(described_class::ObjectExists) expect(object["a"]).to eq("b" => { "c" => "foo" }) object = { "a" => { "b" => ["foo", "bar"] } } patch_object = [{ "add" => "a/b/c/d/e/f/g", "value" => ["foo", "bar", "baz"] }] - expect( lambda { TentServer::JsonPatch.merge(object, patch_object) } ). + expect( lambda { TentD::JsonPatch.merge(object, patch_object) } ). to raise_error(described_class::ObjectExists) expect(object).to eq({ "a" => { "b" => ["foo", "bar"] } }) end @@ -193,7 +193,7 @@ it 'should add new value at specified index' do object = { "a" => ["foo", "bar"] } patch_object = [{ "add" => "a/1", "value" => "baz" }] - TentServer::JsonPatch.merge(object, patch_object) + TentD::JsonPatch.merge(object, patch_object) expect(object["a"]).to eq(["foo", "baz", "bar"]) end end diff --git a/spec/unit/tent_version_spec.rb b/spec/unit/tent_version_spec.rb index 434a583..f290304 100644 --- a/spec/unit/tent_version_spec.rb +++ b/spec/unit/tent_version_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe TentServer::TentVersion do +describe TentD::TentVersion do describe '.from_uri' do it 'should parse version from URI' do uri = "https://tent.io/types/posts/photo/v0.x.x#meta" diff --git a/tent-server.gemspec b/tentd.gemspec similarity index 92% rename from tent-server.gemspec rename to tentd.gemspec index d69b9c4..ef4380c 100644 --- a/tent-server.gemspec +++ b/tentd.gemspec @@ -1,11 +1,11 @@ # -*- encoding: utf-8 -*- lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'tent-server/version' +require 'tentd/version' Gem::Specification.new do |gem| - gem.name = "tent-server" - gem.version = TentServer::VERSION + gem.name = "tentd" + gem.version = TentD::VERSION gem.authors = ["Jonathan Rudenberg", "Jesse Stuart"] gem.email = ["jonathan@titanous.com", "jessestuart@gmail.com"] gem.description = %q{TODO: Write a gem description}