|
|
|
@ -40,12 +40,27 @@ shared_examples_for 'version contract' do |
|
|
|
|
end |
|
|
|
|
let(:root_project) { FactoryBot.build_stubbed(:project) } |
|
|
|
|
let(:version_project) do |
|
|
|
|
FactoryBot.build_stubbed(:project).tap do |p| |
|
|
|
|
FactoryBot.build_stubbed(:project, wiki: project_wiki).tap do |p| |
|
|
|
|
allow(p) |
|
|
|
|
.to receive(:root) |
|
|
|
|
.and_return(root_project) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
let(:project_wiki) do |
|
|
|
|
FactoryBot.build_stubbed(:wiki, pages: wiki_pages).tap do |wiki| |
|
|
|
|
allow(wiki) |
|
|
|
|
.to receive(:find_page) |
|
|
|
|
.with(version_wiki_page_title) |
|
|
|
|
.and_return(find_page_result) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
let(:find_page_result) do |
|
|
|
|
double('page found') |
|
|
|
|
end |
|
|
|
|
let(:wiki_pages) do |
|
|
|
|
[FactoryBot.build_stubbed(:wiki_page), |
|
|
|
|
FactoryBot.build_stubbed(:wiki_page)] |
|
|
|
|
end |
|
|
|
|
let(:version_name) { 'Version name' } |
|
|
|
|
let(:version_description) { 'Version description' } |
|
|
|
|
let(:version_start_date) { Date.current - 5.days } |
|
|
|
@ -56,172 +71,223 @@ shared_examples_for 'version contract' do |
|
|
|
|
let(:permissions) { [:manage_versions] } |
|
|
|
|
let(:root_permissions) { [:manage_versions] } |
|
|
|
|
|
|
|
|
|
def expect_valid(valid, symbols = {}) |
|
|
|
|
expect(contract.validate).to eq(valid) |
|
|
|
|
context 'validations' do |
|
|
|
|
def expect_valid(valid, symbols = {}) |
|
|
|
|
expect(contract.validate).to eq(valid) |
|
|
|
|
|
|
|
|
|
symbols.each do |key, arr| |
|
|
|
|
expect(contract.errors.symbols_for(key)).to match_array arr |
|
|
|
|
symbols.each do |key, arr| |
|
|
|
|
expect(contract.errors.symbols_for(key)).to match_array arr |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
shared_examples 'is valid' do |
|
|
|
|
it 'is valid' do |
|
|
|
|
expect_valid(true) |
|
|
|
|
shared_examples 'is valid' do |
|
|
|
|
it 'is valid' do |
|
|
|
|
expect_valid(true) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_behaves_like 'is valid' |
|
|
|
|
it_behaves_like 'is valid' |
|
|
|
|
|
|
|
|
|
context 'if the project is nil' do |
|
|
|
|
let(:version_project) { nil } |
|
|
|
|
context 'if the project is nil' do |
|
|
|
|
let(:version_project) { nil } |
|
|
|
|
|
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, project_id: %i(blank)) |
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, project_id: %i(blank)) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'if the name is nil' do |
|
|
|
|
let(:version_name) { nil } |
|
|
|
|
context 'if the name is nil' do |
|
|
|
|
let(:version_name) { nil } |
|
|
|
|
|
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, name: %i(blank)) |
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, name: %i(blank)) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'if the description is nil' do |
|
|
|
|
let(:version_description) { nil } |
|
|
|
|
context 'if the description is nil' do |
|
|
|
|
let(:version_description) { nil } |
|
|
|
|
|
|
|
|
|
it_behaves_like 'is valid' |
|
|
|
|
end |
|
|
|
|
it_behaves_like 'is valid' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'if the start_date is nil' do |
|
|
|
|
let(:version_start_date) { nil } |
|
|
|
|
context 'if the start_date is nil' do |
|
|
|
|
let(:version_start_date) { nil } |
|
|
|
|
|
|
|
|
|
it_behaves_like 'is valid' |
|
|
|
|
end |
|
|
|
|
it_behaves_like 'is valid' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'if the end_date is nil' do |
|
|
|
|
let(:version_due_date) { nil } |
|
|
|
|
context 'if the end_date is nil' do |
|
|
|
|
let(:version_due_date) { nil } |
|
|
|
|
|
|
|
|
|
it_behaves_like 'is valid' |
|
|
|
|
end |
|
|
|
|
it_behaves_like 'is valid' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'if the status is nil' do |
|
|
|
|
let(:version_status) { nil } |
|
|
|
|
context 'if the status is nil' do |
|
|
|
|
let(:version_status) { nil } |
|
|
|
|
|
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, status: %i(inclusion)) |
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, status: %i(inclusion)) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'if the status is something other than the allowed values' do |
|
|
|
|
let(:version_status) { 'other_status' } |
|
|
|
|
context 'if the status is something other than the allowed values' do |
|
|
|
|
let(:version_status) { 'other_status' } |
|
|
|
|
|
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, status: %i(inclusion)) |
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, status: %i(inclusion)) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'if sharing is nil' do |
|
|
|
|
before do |
|
|
|
|
version.sharing = 'nil' |
|
|
|
|
end |
|
|
|
|
context 'if sharing is nil' do |
|
|
|
|
before do |
|
|
|
|
version.sharing = 'nil' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, sharing: %i(inclusion)) |
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, sharing: %i(inclusion)) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'if sharing is bogus' do |
|
|
|
|
before do |
|
|
|
|
version.sharing = 'bogus' |
|
|
|
|
end |
|
|
|
|
context 'if sharing is bogus' do |
|
|
|
|
before do |
|
|
|
|
version.sharing = 'bogus' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, sharing: %i(inclusion)) |
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, sharing: %i(inclusion)) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'if sharing is system and the user an admin' do |
|
|
|
|
let(:current_user) { FactoryBot.build_stubbed(:admin) } |
|
|
|
|
context 'if sharing is system and the user an admin' do |
|
|
|
|
let(:current_user) { FactoryBot.build_stubbed(:admin) } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
version.sharing = 'system' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
version.sharing = 'system' |
|
|
|
|
it_behaves_like 'is valid' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_behaves_like 'is valid' |
|
|
|
|
end |
|
|
|
|
context 'if sharing is system and the user no admin' do |
|
|
|
|
before do |
|
|
|
|
version.sharing = 'system' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'if sharing is system and the user no admin' do |
|
|
|
|
before do |
|
|
|
|
version.sharing = 'system' |
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, sharing: %i(inclusion)) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, sharing: %i(inclusion)) |
|
|
|
|
context 'if sharing is descendants' do |
|
|
|
|
before do |
|
|
|
|
version.sharing = 'descendants' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_behaves_like 'is valid' |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'if sharing is descendants' do |
|
|
|
|
before do |
|
|
|
|
version.sharing = 'descendants' |
|
|
|
|
context 'if sharing is tree and the user has manage permission on the root project' do |
|
|
|
|
before do |
|
|
|
|
version.sharing = 'tree' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_behaves_like 'is valid' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_behaves_like 'is valid' |
|
|
|
|
end |
|
|
|
|
context 'if sharing is tree and the user has no manage permission on the root project' do |
|
|
|
|
let(:root_permissions) { [] } |
|
|
|
|
before do |
|
|
|
|
version.sharing = 'tree' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'if sharing is tree and the user has manage permission on the root project' do |
|
|
|
|
before do |
|
|
|
|
version.sharing = 'tree' |
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, sharing: %i(inclusion)) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_behaves_like 'is valid' |
|
|
|
|
end |
|
|
|
|
context 'if sharing is hierarchy and the user has manage permission on the root project' do |
|
|
|
|
before do |
|
|
|
|
version.sharing = 'hierarchy' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'if sharing is tree and the user has no manage permission on the root project' do |
|
|
|
|
let(:root_permissions) { [] } |
|
|
|
|
before do |
|
|
|
|
version.sharing = 'tree' |
|
|
|
|
it_behaves_like 'is valid' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, sharing: %i(inclusion)) |
|
|
|
|
context 'if sharing is hierarchy and the user has no manage permission on the root project' do |
|
|
|
|
let(:root_permissions) { [] } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
version.sharing = 'hierarchy' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, sharing: %i(inclusion)) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'if sharing is hierarchy and the user has manage permission on the root project' do |
|
|
|
|
before do |
|
|
|
|
version.sharing = 'hierarchy' |
|
|
|
|
context 'if the user lacks the manage_versions permission' do |
|
|
|
|
let(:permissions) { [] } |
|
|
|
|
|
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, base: %i(error_unauthorized)) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_behaves_like 'is valid' |
|
|
|
|
end |
|
|
|
|
context 'if the start date is after the effective date' do |
|
|
|
|
let(:version_start_date) { version_due_date + 1.day } |
|
|
|
|
|
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, effective_date: %i(greater_than_start_date)) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'if sharing is hierarchy and the user has no manage permission on the root project' do |
|
|
|
|
let(:root_permissions) { [] } |
|
|
|
|
context 'if wiki_page_title is nil' do |
|
|
|
|
let(:version_wiki_page_title) { nil } |
|
|
|
|
let(:find_page_result) do |
|
|
|
|
nil |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
version.sharing = 'hierarchy' |
|
|
|
|
it_behaves_like 'is valid' |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, sharing: %i(inclusion)) |
|
|
|
|
context 'if wiki_page_title is blank' do |
|
|
|
|
let(:version_wiki_page_title) { '' } |
|
|
|
|
let(:find_page_result) do |
|
|
|
|
nil |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it_behaves_like 'is valid' |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'if the user lacks the manage_versions permission' do |
|
|
|
|
let(:permissions) { [] } |
|
|
|
|
context 'if wiki_page_title contains a non existing page' do |
|
|
|
|
let(:version_wiki_page_title) { 'http://some/url/i/made/up' } |
|
|
|
|
let(:find_page_result) do |
|
|
|
|
nil |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, base: %i(error_unauthorized)) |
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, wiki_page_title: %i(inclusion)) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'if the start date is after the effective date' do |
|
|
|
|
let(:version_start_date) { version_due_date + 1.day } |
|
|
|
|
describe 'assignable values' do |
|
|
|
|
describe 'assignable_wiki_pages' do |
|
|
|
|
context 'with a wiki assigned' do |
|
|
|
|
it 'returns the pages of the project`s wiki' do |
|
|
|
|
expect(contract.assignable_wiki_pages) |
|
|
|
|
.to match_array(wiki_pages) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'without a wiki assigned' do |
|
|
|
|
let(:project_wiki) { nil } |
|
|
|
|
|
|
|
|
|
it 'is invalid' do |
|
|
|
|
expect_valid(false, effective_date: %i(greater_than_start_date)) |
|
|
|
|
it 'is empty' do |
|
|
|
|
expect(contract.assignable_wiki_pages) |
|
|
|
|
.to be_empty |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|