OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/spec/controllers/api/v2/users_controller_spec.rb

120 lines
3.4 KiB

#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
describe Api::V2::UsersController do
11 years ago
shared_context "As an admin" do
let(:current_user) { FactoryGirl.create(:admin) }
before { allow(User).to receive(:current).and_return current_user }
11 years ago
end
shared_context "As a normal user" do
let(:current_user) { FactoryGirl.create(:user) }
before { allow(User).to receive(:current).and_return current_user }
11 years ago
end
shared_examples_for "valid user API call" do
it { expect(assigns(:users).size).to eq(user_count) }
11 years ago
it { expect(response).to render_template('api/v2/users/index', formats: ["api"]) }
end
describe 'index.json' do
11 years ago
describe 'scopes' do
shared_examples_for "no scope provided" do
it { expect(response.status).to eq(400) }
end
context "no scope" do
before { get 'index', format: :json }
it_behaves_like "no scope provided"
end
context "empty scope" do
before { get 'index', ids: "", format: :json }
it_behaves_like "no scope provided"
end
context "filled scope" do
before { get 'index', ids: "1", format: :json }
it_behaves_like "valid user API call" do
let(:user_count) { 0 }
end
end
end
11 years ago
describe 'with 3 users' do
11 years ago
let(:ids) { User.all.collect(&:id).join(',') }
11 years ago
before { 3.times { FactoryGirl.create(:user) } }
11 years ago
context 'as an admin' do
include_context "As an admin"
11 years ago
before { get 'index', ids: ids, format: :json }
11 years ago
it_behaves_like "valid user API call" do
let(:user_count) { 4 }
end
end
11 years ago
context 'as a normal user' do
include_context "As a normal user"
11 years ago
before { get 'index', ids: ids, :format => 'json' }
11 years ago
it_behaves_like "valid user API call" do
let(:user_count) { 4 }
end
end
end
describe 'search for ids' do
11 years ago
include_context "As an admin"
let (:user_1) {FactoryGirl.create(:user)}
let (:user_2) {FactoryGirl.create(:user)}
11 years ago
before { get 'index', ids: "#{user_1.id},#{user_2.id}", :format => 'json' }
11 years ago
subject { assigns(:users) }
11 years ago
it { expect(subject.size).to eq(2) }
11 years ago
it { expect(subject).to include(user_1, user_2) }
end
end
end