2012-10-02 17:54:55 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-02-19 01:12:08 +00:00
|
|
|
describe AutocompletesController, type: :controller do
|
2012-12-17 15:44:14 +00:00
|
|
|
before {stub_symlink_methods}
|
2012-10-02 17:54:55 +01:00
|
|
|
|
|
|
|
context 'for user' do
|
2013-06-05 14:48:11 +01:00
|
|
|
let(:user) { FactoryGirl.create(:user) }
|
2012-10-02 17:54:55 +01:00
|
|
|
before do
|
2013-06-05 14:48:11 +01:00
|
|
|
set_session_for user
|
2012-10-02 17:54:55 +01:00
|
|
|
end
|
|
|
|
|
2014-11-24 21:29:21 +00:00
|
|
|
it 'should be able to perform autocomplete_user_or_group action' do
|
|
|
|
get :autocomplete_user_or_group
|
2012-10-02 17:54:55 +01:00
|
|
|
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
|
|
|
|
|
2013-06-05 14:48:11 +01:00
|
|
|
context 'autocomplete_extra_build_list' do
|
2014-01-21 04:51:49 +00:00
|
|
|
let(:build_list) { FactoryGirl.create(:build_list, user: user) }
|
2013-06-05 14:48:11 +01:00
|
|
|
let(:params) { { :term => build_list.id,
|
|
|
|
:platform_id => build_list.save_to_platform_id } }
|
|
|
|
|
|
|
|
it 'no data when build_list without container' do
|
|
|
|
get :autocomplete_extra_build_list, params
|
|
|
|
response.body.should == '[]'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows data when build_list with container' do
|
|
|
|
build_list.update_column(:container_status, BuildList::BUILD_PUBLISHED)
|
|
|
|
get :autocomplete_extra_build_list, params
|
|
|
|
response.body.should_not == '[]'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'autocomplete_extra_repositories' do
|
|
|
|
let(:repository) { FactoryGirl.create(:repository) }
|
|
|
|
let(:params) { { :term => repository.platform.name,
|
|
|
|
:platform_id => repository.platform_id } }
|
|
|
|
|
|
|
|
before do
|
|
|
|
repository.platform.add_member(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'no data when repository of main platform' do
|
|
|
|
get :autocomplete_extra_repositories, params
|
|
|
|
response.body.should == '[]'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows data when repository of personal platform' do
|
2014-01-21 04:51:49 +00:00
|
|
|
Platform.update_all(platform_type: 'personal')
|
2013-06-05 14:48:11 +01:00
|
|
|
get :autocomplete_extra_repositories, params
|
|
|
|
response.body.should_not == '[]'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-10-02 17:54:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for guest' do
|
|
|
|
|
|
|
|
before do
|
|
|
|
set_session_for(User.new)
|
|
|
|
end
|
|
|
|
|
2013-06-05 14:48:11 +01:00
|
|
|
[
|
2014-11-24 21:29:21 +00:00
|
|
|
:autocomplete_user_or_group,
|
2013-06-05 14:48:11 +01:00
|
|
|
:autocomplete_user_uname,
|
|
|
|
:autocomplete_extra_build_list,
|
|
|
|
:autocomplete_extra_repositories
|
|
|
|
].each do |action|
|
|
|
|
it "should not be able to perform #{action} action" do
|
|
|
|
get action
|
|
|
|
response.should redirect_to(new_user_session_path)
|
|
|
|
end
|
2012-10-02 17:54:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|