kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
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.
323 lines
10 KiB
323 lines
10 KiB
11 years ago
|
#-- copyright
|
||
|
# OpenProject is a project management system.
|
||
7 years ago
|
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)
|
||
11 years ago
|
#
|
||
|
# 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:
|
||
8 years ago
|
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||
11 years ago
|
# 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.
|
||
|
#
|
||
7 years ago
|
# See docs/COPYRIGHT.rdoc for more details.
|
||
11 years ago
|
#++
|
||
|
|
||
|
require 'spec_helper'
|
||
|
|
||
6 years ago
|
describe ForumsController, type: :controller do
|
||
|
shared_let(:user) { FactoryBot.create(:user) }
|
||
7 years ago
|
let(:project) { FactoryBot.create(:project) }
|
||
6 years ago
|
let!(:forum) { FactoryBot.create(:forum, project: project) }
|
||
11 years ago
|
|
||
|
before do
|
||
|
disable_flash_sweep
|
||
|
end
|
||
|
|
||
6 years ago
|
describe '#index' do
|
||
|
|
||
|
context 'public project' do
|
||
|
let(:project) { FactoryBot.create(:public_project) }
|
||
|
let!(:role) { FactoryBot.create(:non_member) }
|
||
|
|
||
|
it 'renders the index template' do
|
||
|
as_logged_in_user(user) do
|
||
|
get :index, params: { project_id: project.id }
|
||
|
end
|
||
|
|
||
|
expect(response).to be_successful
|
||
|
expect(response).to render_template 'forums/show'
|
||
|
expect(assigns(:forums)).to be_present
|
||
|
expect(assigns(:project)).to be_present
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context 'assuming authorized' do
|
||
|
it 'renders the index template' do
|
||
|
as_logged_in_user(user) do
|
||
|
allow(@controller).to receive(:authorize).and_return(true)
|
||
|
get :index, params: { project_id: project.id }
|
||
|
end
|
||
|
expect(response).to be_successful
|
||
|
end
|
||
|
end
|
||
|
|
||
|
it 'renders 404 for not found' do
|
||
|
get :index, params: { project_id: 'not found' }
|
||
|
expect(response.status).to eq 404
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe '#show' do
|
||
|
before do
|
||
|
expect(project).to receive_message_chain(:forums, :find).and_return(forum)
|
||
|
expect(@controller).to receive(:authorize)
|
||
|
expect(@controller).to receive(:find_project_by_project_id) do
|
||
|
@controller.instance_variable_set(:@project, project)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
it 'renders the show template' do
|
||
|
get :show, params: { project_id: project.id, id: 1 }
|
||
|
expect(response).to be_successful
|
||
|
expect(response).to render_template 'forums/show'
|
||
|
end
|
||
|
end
|
||
|
|
||
10 years ago
|
describe '#create' do
|
||
6 years ago
|
let(:params) { { project_id: project.id, forum: forum_params } }
|
||
|
let(:forum_params) { { name: 'my forum', description: 'awesome forum' } }
|
||
11 years ago
|
|
||
|
before do
|
||
11 years ago
|
expect(@controller).to receive(:authorize)
|
||
|
expect(@controller).to receive(:find_project_by_project_id) do
|
||
11 years ago
|
@controller.instance_variable_set(:@project, project)
|
||
|
end
|
||
|
|
||
11 years ago
|
# parameter expectation needs to have strings as keys
|
||
6 years ago
|
expect(Forum)
|
||
8 years ago
|
.to receive(:new)
|
||
6 years ago
|
.with(ActionController::Parameters.new(forum_params).permit!)
|
||
|
.and_return(forum)
|
||
11 years ago
|
end
|
||
|
|
||
|
describe 'w/ the params beeing valid' do
|
||
|
before do
|
||
6 years ago
|
expect(forum).to receive(:save).and_return(true)
|
||
11 years ago
|
|
||
|
as_logged_in_user user do
|
||
8 years ago
|
post :create, params: params
|
||
11 years ago
|
end
|
||
|
end
|
||
|
|
||
|
it 'should redirect to the settings page if successful' do
|
||
8 years ago
|
expect(response)
|
||
7 years ago
|
.to redirect_to controller: '/project_settings',
|
||
|
action: 'show',
|
||
8 years ago
|
id: project,
|
||
6 years ago
|
tab: 'forums'
|
||
11 years ago
|
end
|
||
|
|
||
|
it 'have a successful creation flash' do
|
||
11 years ago
|
expect(flash[:notice]).to eq(I18n.t(:notice_successful_create))
|
||
11 years ago
|
end
|
||
|
end
|
||
|
|
||
|
describe 'w/ the params beeing invalid' do
|
||
|
before do
|
||
6 years ago
|
expect(forum).to receive(:save).and_return(false)
|
||
11 years ago
|
|
||
|
as_logged_in_user user do
|
||
8 years ago
|
post :create, params: params
|
||
11 years ago
|
end
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should render the new template' do
|
||
11 years ago
|
expect(response).to render_template('new')
|
||
11 years ago
|
end
|
||
|
end
|
||
|
end
|
||
11 years ago
|
|
||
6 years ago
|
describe '#destroy' do
|
||
|
let(:forum_params) { { name: 'my forum', description: 'awesome forum' } }
|
||
|
|
||
|
before do
|
||
|
expect(@controller).to receive(:authorize)
|
||
|
expect(project).to receive_message_chain(:forums, :find).and_return(forum)
|
||
|
expect(@controller).to receive(:find_project_by_project_id) do
|
||
|
@controller.instance_variable_set(:@project, project)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
it 'will request destruction and redirect' do
|
||
|
expect(forum).to receive(:destroy)
|
||
|
delete :destroy, params: { project_id: project.id, id: 1 }
|
||
|
expect(response).to be_redirect
|
||
|
end
|
||
|
end
|
||
|
|
||
10 years ago
|
describe '#move' do
|
||
7 years ago
|
let(:project) { FactoryBot.create(:project) }
|
||
6 years ago
|
let!(:forum_1) {
|
||
|
FactoryBot.create(:forum,
|
||
10 years ago
|
project: project,
|
||
|
position: 1)
|
||
|
}
|
||
6 years ago
|
let!(:forum_2) {
|
||
|
FactoryBot.create(:forum,
|
||
10 years ago
|
project: project,
|
||
|
position: 2)
|
||
|
}
|
||
11 years ago
|
|
||
6 years ago
|
before do
|
||
|
allow(@controller).to receive(:authorize).and_return(true)
|
||
|
end
|
||
11 years ago
|
|
||
10 years ago
|
describe '#higher' do
|
||
11 years ago
|
let(:move_to) { 'higher' }
|
||
6 years ago
|
let(:redirect_url) { "http://test.host/projects/#{project.id}/settings/forums" }
|
||
11 years ago
|
|
||
|
before do
|
||
6 years ago
|
post 'move', params: { id: forum_2.id,
|
||
|
project_id: forum_2.project_id,
|
||
|
forum: { move_to: move_to } }
|
||
11 years ago
|
end
|
||
|
|
||
6 years ago
|
it do expect(forum_2.reload.position).to eq(1) end
|
||
11 years ago
|
|
||
8 years ago
|
it do expect(response).to be_redirect end
|
||
11 years ago
|
|
||
8 years ago
|
it do expect(response).to redirect_to(redirect_url) end
|
||
11 years ago
|
end
|
||
|
end
|
||
11 years ago
|
|
||
10 years ago
|
describe '#update' do
|
||
6 years ago
|
let!(:forum) {
|
||
|
FactoryBot.create(:forum, name: 'Forum name',
|
||
|
description: 'Forum description')
|
||
10 years ago
|
}
|
||
11 years ago
|
|
||
|
before do
|
||
11 years ago
|
expect(@controller).to receive(:authorize)
|
||
11 years ago
|
end
|
||
|
|
||
|
describe 'w/ the params beeing valid' do
|
||
|
before do
|
||
|
as_logged_in_user user do
|
||
6 years ago
|
put :update, params: { id: forum.id,
|
||
|
project_id: forum.project_id,
|
||
|
forum: { name: 'New name', description: 'New description' } }
|
||
11 years ago
|
end
|
||
|
end
|
||
|
|
||
|
it 'should redirect to the settings page if successful' do
|
||
7 years ago
|
expect(response).to redirect_to controller: '/project_settings',
|
||
|
action: 'show',
|
||
6 years ago
|
id: forum.project,
|
||
|
tab: 'forums'
|
||
11 years ago
|
end
|
||
|
|
||
|
it 'have a successful update flash' do
|
||
11 years ago
|
expect(flash[:notice]).to eq(I18n.t(:notice_successful_update))
|
||
11 years ago
|
end
|
||
|
|
||
|
it 'should change the database entry' do
|
||
6 years ago
|
forum.reload
|
||
|
expect(forum.name).to eq('New name')
|
||
|
expect(forum.description).to eq('New description')
|
||
11 years ago
|
end
|
||
|
end
|
||
|
|
||
|
describe 'w/ the params beeing invalid' do
|
||
|
before do
|
||
|
as_logged_in_user user do
|
||
6 years ago
|
post :update, params: { id: forum.id,
|
||
|
project_id: forum.project_id,
|
||
|
forum: { name: '', description: 'New description' } }
|
||
11 years ago
|
end
|
||
|
end
|
||
|
|
||
|
it 'should render the edit template' do
|
||
11 years ago
|
expect(response).to render_template('edit')
|
||
11 years ago
|
end
|
||
|
|
||
|
it 'should not change the database entry' do
|
||
6 years ago
|
forum.reload
|
||
|
expect(forum.name).to eq('Forum name')
|
||
|
expect(forum.description).to eq('Forum description')
|
||
11 years ago
|
end
|
||
|
end
|
||
|
end
|
||
11 years ago
|
|
||
10 years ago
|
describe '#sticky' do
|
||
6 years ago
|
let!(:message1) { FactoryBot.create(:message, forum: forum) }
|
||
|
let!(:message2) { FactoryBot.create(:message, forum: forum) }
|
||
10 years ago
|
let!(:sticked_message1) {
|
||
6 years ago
|
FactoryBot.create(:message, forum_id: forum.id,
|
||
8 years ago
|
subject: 'How to',
|
||
|
content: 'How to install this cool app',
|
||
|
sticky: '1',
|
||
|
sticked_on: Time.now - 2.minute)
|
||
10 years ago
|
}
|
||
11 years ago
|
|
||
10 years ago
|
let!(:sticked_message2) {
|
||
6 years ago
|
FactoryBot.create(:message, forum_id: forum.id,
|
||
8 years ago
|
subject: 'FAQ',
|
||
|
content: 'Frequestly asked question',
|
||
|
sticky: '1',
|
||
|
sticked_on:
|
||
|
Time.now - 1.minute)
|
||
10 years ago
|
}
|
||
11 years ago
|
|
||
10 years ago
|
describe 'all sticky messages' do
|
||
11 years ago
|
before do
|
||
11 years ago
|
expect(@controller).to receive(:authorize)
|
||
6 years ago
|
get :show, params: { project_id: project.id, id: forum.id }
|
||
11 years ago
|
end
|
||
|
|
||
8 years ago
|
it 'renders show' do
|
||
|
expect(response).to render_template 'show'
|
||
|
end
|
||
10 years ago
|
it 'should be displayed on top' do
|
||
11 years ago
|
expect(assigns[:topics][0].id).to eq(sticked_message1.id)
|
||
|
end
|
||
|
end
|
||
|
|
||
10 years ago
|
describe 'edit a sticky message' do
|
||
11 years ago
|
before(:each) do
|
||
|
sticked_message1.sticky = 0
|
||
|
sticked_message1.save!
|
||
|
end
|
||
|
|
||
10 years ago
|
describe 'when sticky is unset from message' do
|
||
11 years ago
|
before do
|
||
11 years ago
|
expect(@controller).to receive(:authorize)
|
||
6 years ago
|
get :show, params: { project_id: project.id, id: forum.id }
|
||
11 years ago
|
end
|
||
|
|
||
10 years ago
|
it 'it should not be displayed as sticky message' do
|
||
11 years ago
|
expect(sticked_message1.sticked_on).to be_nil
|
||
10 years ago
|
expect(assigns[:topics][0].id).not_to eq(sticked_message1.id)
|
||
11 years ago
|
end
|
||
|
end
|
||
|
|
||
10 years ago
|
describe 'when sticky is set back to message' do
|
||
11 years ago
|
before do
|
||
|
sticked_message1.sticky = 1
|
||
|
sticked_message1.save!
|
||
|
|
||
11 years ago
|
expect(@controller).to receive(:authorize)
|
||
6 years ago
|
get :show, params: { project_id: project.id, id: forum.id }
|
||
11 years ago
|
end
|
||
|
|
||
10 years ago
|
it 'it should not be displayed on first position' do
|
||
11 years ago
|
expect(assigns[:topics][0].id).to eq(sticked_message2.id)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
11 years ago
|
end
|