Merge pull request #675 from warpc/671-rest-api-for-plastforms

[refs #671]: REST API fo build task: elimination of discrepancies compared with the documentation
This commit is contained in:
Vladimir Sharshov 2012-10-04 08:54:49 -07:00
commit 2d7f4de3b5
8 changed files with 73 additions and 10 deletions

View File

@ -0,0 +1,9 @@
# -*- encoding : utf-8 -*-
class Api::V1::ArchesController < Api::V1::BaseController
before_filter :authenticate_user! unless APP_CONFIG['anonymous_access']
def index
@arches = Arch.order(:id).all
end
end

View File

@ -7,7 +7,8 @@ class Api::V1::PlatformsController < Api::V1::BaseController
load_and_authorize_resource load_and_authorize_resource
def index def index
@platforms = @platforms.accessible_by(current_ability, :related).paginate(:page => params[:page], :per_page => 20) @platforms = @platforms.accessible_by(current_ability, :related).
by_type(params[:type]).paginate(:page => params[:page], :per_page => 20)
end end
def show def show

View File

@ -39,8 +39,9 @@ class Platform < ActiveRecord::Base
scope :by_visibilities, lambda {|v| where(:visibility => v)} scope :by_visibilities, lambda {|v| where(:visibility => v)}
scope :opened, where(:visibility => 'open') scope :opened, where(:visibility => 'open')
scope :hidden, where(:visibility => 'hidden') scope :hidden, where(:visibility => 'hidden')
scope :main, where(:platform_type => 'main') scope :by_type, lambda {|type| where(:platform_type => type) if type.present?}
scope :personal, where(:platform_type => 'personal') scope :main, by_type('main')
scope :personal, by_type('personal')
attr_accessible :name, :distrib_type, :parent_platform_id, :platform_type, :owner, :visibility, :description, :released attr_accessible :name, :distrib_type, :parent_platform_id, :platform_type, :owner, :visibility, :description, :released
attr_readonly :name, :distrib_type, :parent_platform_id, :platform_type attr_readonly :name, :distrib_type, :parent_platform_id, :platform_type

View File

@ -0,0 +1,3 @@
json.architectures @arches do |json, arch|
json.(arch, :id, :name)
end

View File

@ -1,9 +1,13 @@
json.build_list do |json| json.build_list do |json|
json.(@build_list, :id, :name, :container_path, :status, :duration) json.(@build_list, :id, :name, :container_path, :status, :duration)
json.(@build_list, :is_circle, :update_type, :build_requires) json.(@build_list, :is_circle, :update_type, :build_requires, :priority)
json.(@build_list, :advisory, :mass_build)
json.(@build_list, :auto_publish, :package_version, :commit_hash) json.(@build_list, :auto_publish, :package_version, :commit_hash)
json.build_log_url log_build_list_path(@build_list)
json.arch_name @build_list.arch.name json.arch do |json_arch|
json_arch.(@build_list.arch, :id, :name)
end
json.created_at @build_list.created_at.to_i json.created_at @build_list.created_at.to_i
json.updated_at @build_list.updated_at.to_i json.updated_at @build_list.updated_at.to_i

View File

@ -19,6 +19,7 @@ Rosa::Application.routes.draw do
get :cancel get :cancel
} }
end end
resources :arches, :only => [:index]
resources :platforms, :only => [:index, :show] resources :platforms, :only => [:index, :show]
resources :repositories, :only => [:show] resources :repositories, :only => [:show]
resources :projects, :only => [:show] do resources :projects, :only => [:show] do

View File

@ -0,0 +1,31 @@
# -*- encoding : utf-8 -*-
require 'spec_helper'
describe Api::V1::ArchesController do
before { FactoryGirl.create(:arch) }
context 'for guest' do
it "should be able to perform index action", :anonymous_access => true do
get :index, :format => :json
should render_template(:index)
end
it 'should be able to perform get_id action', :anonymous_access => false do
get :index, :format => :json
response.status.should == 401
end
end
context 'for simple user' do
before do
stub_symlink_methods
http_login(FactoryGirl.create(:user))
end
it "should be able to perform index action" do
get :index, :format => :json
should render_template(:index)
end
end
end

View File

@ -8,6 +8,7 @@ shared_examples_for 'api platform user with reader rights' do
get :index, :format => :json get :index, :format => :json
response.should render_template(:index) response.should render_template(:index)
end end
end end
shared_examples_for 'api platform user with reader rights for hidden platform' do shared_examples_for 'api platform user with reader rights for hidden platform' do
@ -41,7 +42,7 @@ shared_examples_for "api platform user without show rights" do
end end
describe Api::V1::PlatformsController do describe Api::V1::PlatformsController do
before(:each) do before do
stub_symlink_methods stub_symlink_methods
@platform = FactoryGirl.create(:platform) @platform = FactoryGirl.create(:platform)
@ -67,7 +68,7 @@ describe Api::V1::PlatformsController do
end end
context 'for global admin' do context 'for global admin' do
before(:each) do before do
@admin = FactoryGirl.create(:admin) @admin = FactoryGirl.create(:admin)
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
http_login(@admin) http_login(@admin)
@ -78,7 +79,7 @@ describe Api::V1::PlatformsController do
end end
context 'for owner user' do context 'for owner user' do
before(:each) do before do
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
http_login(@user) http_login(@user)
@platform.owner = @user; @platform.save @platform.owner = @user; @platform.save
@ -90,10 +91,22 @@ describe Api::V1::PlatformsController do
end end
context 'for reader user' do context 'for reader user' do
before(:each) do before do
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
http_login(@user) http_login(@user)
@platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader') @platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
@personal_platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
end
context 'perform index action with type param' do
render_views
%w(main personal).each do |type|
it "ensures that filter by type = #{type} returns true result" do
get :index, :format => :json, :type => "#{type}"
JSON.parse(response.body)['platforms'].map{ |p| p['platform_type'] }.
uniq.should == ["#{type}"]
end
end
end end
it_should_behave_like 'api platform user with reader rights' it_should_behave_like 'api platform user with reader rights'
@ -101,7 +114,7 @@ describe Api::V1::PlatformsController do
end end
context 'for simple user' do context 'for simple user' do
before(:each) do before do
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
http_login(@user) http_login(@user)
end end