rosa-build/spec/controllers/autocompletes_controller_sp...

82 lines
2.3 KiB
Ruby
Raw Normal View History

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}
context 'for user' do
let(:user) { FactoryGirl.create(:user) }
before do
set_session_for user
end
it 'should be able to perform autocomplete_user_or_group action' do
get :autocomplete_user_or_group
2015-04-07 20:43:40 +01:00
expect(response).to be_success
end
it 'should be able to perform autocomplete_user_uname action' do
get :autocomplete_user_uname
2015-04-07 20:43:40 +01:00
expect(response).to be_success
end
context 'autocomplete_extra_build_list' do
2014-01-21 04:51:49 +00:00
let(:build_list) { FactoryGirl.create(:build_list, user: user) }
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
2015-04-07 20:43:40 +01:00
expect(response.body).to eq '[]'
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
2015-04-07 20:43:40 +01:00
expect(response.body).to_not eq '[]'
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
2015-04-07 20:43:40 +01:00
expect(response.body).to eq '[]'
end
it 'shows data when repository of personal platform' do
2014-01-21 04:51:49 +00:00
Platform.update_all(platform_type: 'personal')
get :autocomplete_extra_repositories, params
2015-04-07 20:43:40 +01:00
expect(response.body).to_not eq '[]'
end
end
end
context 'for guest' do
before do
set_session_for(User.new)
end
[
:autocomplete_user_or_group,
: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
2015-04-07 20:43:40 +01:00
expect(response).to redirect_to(new_user_session_path)
end
end
end
end