v3: rename account to owner (so we can use account for private accounts api)
This commit is contained in:
parent
3680fcf389
commit
344979a2a8
|
@ -1,5 +1,5 @@
|
||||||
module Travis::API::V3
|
module Travis::API::V3
|
||||||
class Queries::Account < Query
|
class Queries::Owner < Query
|
||||||
def find
|
def find
|
||||||
find!(:organization) || find!(:user)
|
find!(:organization) || find!(:user)
|
||||||
end
|
end
|
||||||
|
@ -7,8 +7,8 @@ module Travis::API::V3
|
||||||
private
|
private
|
||||||
|
|
||||||
def query(type, main_type: self.main_type, params: self.params)
|
def query(type, main_type: self.main_type, params: self.params)
|
||||||
main_type = type if main_type == :account
|
main_type = type if main_type == :owner
|
||||||
params = params.merge("#{type}.login" => params["account.login".freeze]) if params["account.login".freeze]
|
params = params.merge("#{type}.login" => params["owner.login".freeze]) if params["owner.login".freeze]
|
||||||
Queries[type].new(params, main_type)
|
Queries[type].new(params, main_type)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'travis/api/v3/renderer/model_renderer'
|
require 'travis/api/v3/renderer/owner'
|
||||||
|
|
||||||
module Travis::API::V3
|
module Travis::API::V3
|
||||||
class Renderer::Organization < Renderer::Account
|
class Renderer::Organization < Renderer::Owner
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@ require 'travis/api/v3/renderer/model_renderer'
|
||||||
require 'travis/api/v3/renderer/avatar_url'
|
require 'travis/api/v3/renderer/avatar_url'
|
||||||
|
|
||||||
module Travis::API::V3
|
module Travis::API::V3
|
||||||
class Renderer::Account < Renderer::ModelRenderer
|
class Renderer::Owner < Renderer::ModelRenderer
|
||||||
include Renderer::AvatarURL
|
include Renderer::AvatarURL
|
||||||
|
|
||||||
representation(:minimal, :id, :login)
|
representation(:minimal, :id, :login)
|
|
@ -1,7 +1,7 @@
|
||||||
require 'travis/api/v3/renderer/model_renderer'
|
require 'travis/api/v3/renderer/owner'
|
||||||
|
|
||||||
module Travis::API::V3
|
module Travis::API::V3
|
||||||
class Renderer::User < Renderer::Account
|
class Renderer::User < Renderer::Owner
|
||||||
representation(:standard, :is_syncing, :synced_at)
|
representation(:standard, :is_syncing, :synced_at)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,8 +3,8 @@ module Travis::API::V3
|
||||||
require 'travis/api/v3/routes/dsl'
|
require 'travis/api/v3/routes/dsl'
|
||||||
extend DSL
|
extend DSL
|
||||||
|
|
||||||
resource :account do
|
resource :owner do
|
||||||
route '/account/({account.login}|{user.login}|{organization.login})'
|
route '/owner/({owner.login}|{user.login}|{organization.login})'
|
||||||
get :find
|
get :find
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,11 @@ module Travis::API::V3
|
||||||
module Services
|
module Services
|
||||||
extend ConstantResolver
|
extend ConstantResolver
|
||||||
|
|
||||||
Account = Module.new { extend Services }
|
|
||||||
Branch = Module.new { extend Services }
|
Branch = Module.new { extend Services }
|
||||||
Build = Module.new { extend Services }
|
Build = Module.new { extend Services }
|
||||||
Organization = Module.new { extend Services }
|
Organization = Module.new { extend Services }
|
||||||
Organizations = Module.new { extend Services }
|
Organizations = Module.new { extend Services }
|
||||||
|
Owner = Module.new { extend Services }
|
||||||
Repositories = Module.new { extend Services }
|
Repositories = Module.new { extend Services }
|
||||||
Repository = Module.new { extend Services }
|
Repository = Module.new { extend Services }
|
||||||
Requests = Module.new { extend Services }
|
Requests = Module.new { extend Services }
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
module Travis::API::V3
|
module Travis::API::V3
|
||||||
class Services::Account::Find < Service
|
class Services::Owner::Find < Service
|
||||||
def result_type
|
def result_type
|
||||||
@result_type ||= super
|
@result_type ||= super
|
||||||
end
|
end
|
||||||
|
|
||||||
def run!
|
def run!
|
||||||
account = find
|
owner = find
|
||||||
@result_type = type_for(account)
|
@result_type = type_for(owner)
|
||||||
account
|
owner
|
||||||
end
|
end
|
||||||
|
|
||||||
def type_for(account)
|
def type_for(owner)
|
||||||
case account
|
case owner
|
||||||
when Models::User then :user
|
when Models::User then :user
|
||||||
when Models::Organization then :organization
|
when Models::Organization then :organization
|
||||||
end
|
end
|
|
@ -90,16 +90,16 @@ describe Travis::API::V3::ServiceIndex do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "account resource" do
|
describe "owner resource" do
|
||||||
let(:resource) { resources.fetch("account") }
|
let(:resource) { resources.fetch("owner") }
|
||||||
specify { expect(resources) .to include("account") }
|
specify { expect(resources) .to include("owner") }
|
||||||
specify { expect(resource["@type"]) .to be == "resource" }
|
specify { expect(resource["@type"]) .to be == "resource" }
|
||||||
|
|
||||||
describe "find action" do
|
describe "find action" do
|
||||||
let(:action) { resource.fetch("actions").fetch("find") }
|
let(:action) { resource.fetch("actions").fetch("find") }
|
||||||
specify { expect(action).to include("@type"=>"template", "request_method"=>"GET", "uri_template"=>"#{path}account/{account.login}{?include}") }
|
specify { expect(action).to include("@type"=>"template", "request_method"=>"GET", "uri_template"=>"#{path}owner/{owner.login}{?include}") }
|
||||||
specify { expect(action).to include("@type"=>"template", "request_method"=>"GET", "uri_template"=>"#{path}account/{user.login}{?include}") }
|
specify { expect(action).to include("@type"=>"template", "request_method"=>"GET", "uri_template"=>"#{path}owner/{user.login}{?include}") }
|
||||||
specify { expect(action).to include("@type"=>"template", "request_method"=>"GET", "uri_template"=>"#{path}account/{organization.login}{?include}") }
|
specify { expect(action).to include("@type"=>"template", "request_method"=>"GET", "uri_template"=>"#{path}owner/{organization.login}{?include}") }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Travis::API::V3::Services::Account::Find do
|
describe Travis::API::V3::Services::Owner::Find do
|
||||||
describe "organization" do
|
describe "organization" do
|
||||||
let(:org) { Organization.new(login: 'example-org') }
|
let(:org) { Organization.new(login: 'example-org') }
|
||||||
before { org.save! }
|
before { org.save! }
|
||||||
after { org.delete }
|
after { org.delete }
|
||||||
|
|
||||||
describe 'existing org, public api' do
|
describe 'existing org, public api' do
|
||||||
before { get("/v3/account/example-org") }
|
before { get("/v3/owner/example-org") }
|
||||||
example { expect(last_response).to be_ok }
|
example { expect(last_response).to be_ok }
|
||||||
example { expect(JSON.load(body)).to be == {
|
example { expect(JSON.load(body)).to be == {
|
||||||
"@type" => "organization",
|
"@type" => "organization",
|
||||||
|
@ -21,7 +21,7 @@ describe Travis::API::V3::Services::Account::Find do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'it is not case sensitive' do
|
describe 'it is not case sensitive' do
|
||||||
before { get("/v3/account/example-ORG") }
|
before { get("/v3/owner/example-ORG") }
|
||||||
example { expect(last_response).to be_ok }
|
example { expect(last_response).to be_ok }
|
||||||
example { expect(JSON.load(body)).to be == {
|
example { expect(JSON.load(body)).to be == {
|
||||||
"@type" => "organization",
|
"@type" => "organization",
|
||||||
|
@ -39,7 +39,7 @@ describe Travis::API::V3::Services::Account::Find do
|
||||||
before { other.save! }
|
before { other.save! }
|
||||||
after { other.delete }
|
after { other.delete }
|
||||||
|
|
||||||
before { get("/v3/account/example-org?organization.id=#{other.id}") }
|
before { get("/v3/owner/example-org?organization.id=#{other.id}") }
|
||||||
example { expect(last_response).to be_ok }
|
example { expect(last_response).to be_ok }
|
||||||
example { expect(JSON.load(body)).to be == {
|
example { expect(JSON.load(body)).to be == {
|
||||||
"@type" => "organization",
|
"@type" => "organization",
|
||||||
|
@ -59,7 +59,7 @@ describe Travis::API::V3::Services::Account::Find do
|
||||||
after { user.delete }
|
after { user.delete }
|
||||||
|
|
||||||
describe 'existing user, public api' do
|
describe 'existing user, public api' do
|
||||||
before { get("/v3/account/example-user") }
|
before { get("/v3/owner/example-user") }
|
||||||
example { expect(last_response).to be_ok }
|
example { expect(last_response).to be_ok }
|
||||||
example { expect(JSON.load(body)).to be == {
|
example { expect(JSON.load(body)).to be == {
|
||||||
"@type" => "user",
|
"@type" => "user",
|
||||||
|
@ -75,7 +75,7 @@ describe Travis::API::V3::Services::Account::Find do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'it is not case sensitive' do
|
describe 'it is not case sensitive' do
|
||||||
before { get("/v3/account/example-USER") }
|
before { get("/v3/owner/example-USER") }
|
||||||
example { expect(last_response).to be_ok }
|
example { expect(last_response).to be_ok }
|
||||||
example { expect(JSON.load(body)).to be == {
|
example { expect(JSON.load(body)).to be == {
|
||||||
"@type" => "user",
|
"@type" => "user",
|
||||||
|
@ -95,7 +95,7 @@ describe Travis::API::V3::Services::Account::Find do
|
||||||
before { other.save! }
|
before { other.save! }
|
||||||
after { other.delete }
|
after { other.delete }
|
||||||
|
|
||||||
before { get("/v3/account/example-user?user.id=#{other.id}") }
|
before { get("/v3/owner/example-user?user.id=#{other.id}") }
|
||||||
example { expect(last_response).to be_ok }
|
example { expect(last_response).to be_ok }
|
||||||
example { expect(JSON.load(body)).to be == {
|
example { expect(JSON.load(body)).to be == {
|
||||||
"@type" => "user",
|
"@type" => "user",
|
Loading…
Reference in New Issue
Block a user