#349: created autocompletes_controller, refactoring, updated specs

This commit is contained in:
Vokhmin Alexey V 2012-10-02 20:54:55 +04:00
parent 37b5f710c2
commit cb994c6fd6
13 changed files with 66 additions and 29 deletions

View File

@ -0,0 +1,7 @@
# -*- encoding : utf-8 -*-
class AutocompletesController < ApplicationController
before_filter :authenticate_user!
autocomplete :group, :uname
autocomplete :user, :uname
end

View File

@ -3,8 +3,6 @@ class Groups::ProfileController < Groups::BaseController
load_and_authorize_resource :class => Group, :instance_name => 'group'
skip_before_filter :authenticate_user!, :only => :show if APP_CONFIG['anonymous_access']
autocomplete :group, :uname
def index
@groups = current_user.groups.paginate(:page => params[:group_page]) # accessible_by(current_ability)
@groups = @groups.search(params[:query]) if params[:query].present?

View File

@ -5,8 +5,6 @@ class Platforms::PlatformsController < Platforms::BaseController
skip_before_filter :authenticate_user!, :only => [:advisories, :members, :show] if APP_CONFIG['anonymous_access']
load_and_authorize_resource
autocomplete :user, :uname
def index
@platforms = @platforms.accessible_by(current_ability, :related).paginate(:page => params[:page], :per_page => 20)
end

View File

@ -1,6 +1,5 @@
# -*- encoding : utf-8 -*-
class Users::ProfileController < Users::BaseController
autocomplete :user, :uname
skip_before_filter :authenticate_user!, :only => :show if APP_CONFIG['anonymous_access']
def show

View File

@ -50,9 +50,8 @@ class Ability
end
if user.user?
can [:show, :autocomplete_user_uname], User
can [:read, :create, :autocomplete_group_uname], Group
can :show, User
can [:read, :create], Group
can [:update, :manage_members], Group do |group|
group.actors.exists?(:actor_type => 'User', :actor_id => user.id, :role => 'admin') # or group.owner_id = user.id
end
@ -92,7 +91,6 @@ class Ability
can([:read, :related, :members], Platform, read_relations_for('platforms')) {|platform| local_reader? platform}
can([:update, :members], Platform) {|platform| local_admin? platform}
can([:destroy, :members, :add_member, :remove_member, :remove_members] , Platform) {|platform| owner?(platform) || local_admin?(platform) }
can [:autocomplete_user_uname], Platform
can([:failed_builds_list, :create], MassBuild) {|mass_build| (owner?(mass_build.platform) || local_admin?(mass_build.platform)) && mass_build.platform.main? }
can(:cancel, MassBuild) {|mass_build| (owner?(mass_build.platform) || local_admin?(mass_build.platform)) && !mass_build.stop_build && mass_build.platform.main?}

View File

@ -25,7 +25,7 @@
.hr.top
= form_tag add_group_members_path(parent) do
.admin-search= autocomplete_field_tag 'user_id', params[:user_id], autocomplete_user_uname_users_path#, :id_element => '#member_id_field'
.admin-search= autocomplete_field_tag 'user_id', params[:user_id], autocomplete_user_uname_autocompletes_path#, :id_element => '#member_id_field'
.admin-role
.lineForm= select_tag 'role', options_for_collaborators_roles_select
.both

View File

@ -22,7 +22,7 @@
.both
.leftlist= label_tag "", t("layout.platforms.admin_id"), :class => :label
.rightlist= autocomplete_field_tag 'admin_id', @admin_uname, autocomplete_user_uname_platforms_path, :id_element => '#admin_id_field'
.rightlist= autocomplete_field_tag 'admin_id', @admin_uname, autocomplete_user_uname_autocompletes_path, :id_element => '#admin_id_field'
= hidden_field_tag 'admin_id', @admin_id, :id => 'admin_id_field'
.both

View File

@ -7,7 +7,7 @@
= form_tag add_project_collaborators_path(@project) do
.admin-search
= autocomplete_field_tag 'member_id', params[:member_id], autocomplete_user_uname_users_path, :id_element => '#member_id_field'
= autocomplete_field_tag 'member_id', params[:member_id], autocomplete_user_uname_autocompletes_path, :id_element => '#member_id_field'
.admin-role
.lineForm
= select_tag 'role', options_for_collaborators_roles_select
@ -54,7 +54,7 @@
= form_tag add_project_collaborators_path(@project) do
.admin-search
= autocomplete_field_tag 'group_id', params[:group_id], autocomplete_group_uname_groups_path, :id_element => '#group_id_field'
= autocomplete_field_tag 'group_id', params[:group_id], autocomplete_group_uname_autocompletes_path, :id_element => '#group_id_field'
.admin-role
.lineForm
= select_tag 'role', options_for_collaborators_roles_select, :id => 'group_role'

View File

@ -33,7 +33,7 @@
.hr.top
= form_tag add_member_path do
.admin-search
= autocomplete_field_tag 'member_id', params[:member_id], autocomplete_user_uname_users_path, :id_element => '#member_id_field'
= autocomplete_field_tag 'member_id', params[:member_id], autocomplete_user_uname_autocompletes_path, :id_element => '#member_id_field'
= hidden_field_tag 'member_id', nil, :id => 'member_id_field'
= submit_tag t("layout.add"), :class => 'button'
.both

View File

@ -87,7 +87,6 @@ Rosa::Application.routes.draw do
end
end
get :autocomplete_user_uname, :on => :collection
resources :repositories do
member do
get :add_project
@ -110,6 +109,13 @@ Rosa::Application.routes.draw do
match 'product_status', :to => 'product_build_lists#status_build'
end
resources :autocompletes, :only => [] do
collection do
get :autocomplete_user_uname
get :autocomplete_group_uname
end
end
scope :module => 'users' do
resources :settings, :only => [] do
collection do
@ -122,9 +128,6 @@ Rosa::Application.routes.draw do
end
end
resources :users, :controller => 'profile', :only => [] do
get :autocomplete_user_uname, :on => :collection
end
resources :register_requests, :only => [:new, :create], :format => /ru|en/ #view support only two languages
end
@ -132,7 +135,6 @@ Rosa::Application.routes.draw do
get '/groups/new' => 'profile#new' # need to force next route exclude :id => 'new'
get '/groups/:id' => redirect("/%{id}"), :as => :profile_group # override default group show route
resources :groups, :controller => 'profile' do
get :autocomplete_group_uname, :on => :collection
delete :remove_user, :on => :member
resources :members, :only => [:index] do
collection do

View File

@ -0,0 +1,40 @@
# -*- encoding : utf-8 -*-
require 'spec_helper'
describe AutocompletesController do
context 'for user' do
before do
set_session_for(FactoryGirl.create(:user))
end
it 'should be able to perform autocomplete_group_uname action' do
get :autocomplete_group_uname
response.should be_success
end
it 'should be able to perform autocomplete_user_uname action' do
get :autocomplete_user_uname
response.should be_success
end
end
context 'for guest' do
before do
set_session_for(User.new)
end
it 'should not be able to perform autocomplete_group_uname action' do
get :autocomplete_group_uname
response.should redirect_to(new_user_session_path)
end
it 'should not be able to perform autocomplete_user_uname action' do
get :autocomplete_user_uname
response.should redirect_to(new_user_session_path)
end
end
end

View File

@ -54,11 +54,6 @@ shared_examples_for 'no group user' do
it 'should change objects count on create' do
lambda { post :create, @create_params }.should change{ Group.count }.by(1)
end
it 'should be able to perform autocomplete_group_uname action' do
get :autocomplete_group_uname
response.should be_success
end
end
shared_examples_for 'group owner' do

View File

@ -10,7 +10,7 @@ describe Group do
end
context 'for guest' do
[:read, :update, :destroy, :manage_members, :autocomplete_group_uname].each do |action|
[:read, :update, :destroy, :manage_members].each do |action|
it "should not be able to #{action} group" do
@ability.should_not be_able_to(action, @group)
end
@ -23,7 +23,7 @@ describe Group do
@ability = Ability.new(@admin)
end
[:read, :update, :destroy, :manage_members, :autocomplete_group_uname].each do |action|
[:read, :update, :destroy, :manage_members].each do |action|
it "should be able to #{action} group" do
@ability.should be_able_to(action, @group)
end
@ -38,7 +38,7 @@ describe Group do
@ability = Ability.new(@user)
end
[:read, :update, :manage_members, :autocomplete_group_uname].each do |action|
[:read, :update, :manage_members].each do |action|
it "should be able to #{action} group" do
@ability.should be_able_to(action, @group)
end
@ -70,7 +70,7 @@ describe Group do
@ability = Ability.new(@user)
end
[:read, :update, :destroy, :manage_members, :autocomplete_group_uname].each do |action|
[:read, :update, :destroy, :manage_members].each do |action|
it "should be able to #{action} group" do
@ability.should be_able_to(action, @group)
end
@ -84,7 +84,7 @@ describe Group do
@ability = Ability.new(@user)
end
[:read, :autocomplete_group_uname].each do |action|
[:read].each do |action|
it "should be able to #{action} group" do
@ability.should be_able_to(action, @group)
end