group_settings_spec.rb 3.59 KB
Newer Older
1 2
require 'spec_helper'

3
feature 'Edit group settings' do
4 5 6 7 8
  given(:user)  { create(:user) }
  given(:group) { create(:group, path: 'foo') }

  background do
    group.add_owner(user)
9
    sign_in(user)
10 11 12 13 14 15 16 17 18 19 20
  end

  describe 'when the group path is changed' do
    let(:new_group_path) { 'bar' }
    let(:old_group_full_path) { "/#{group.path}" }
    let(:new_group_full_path) { "/#{new_group_path}" }

    scenario 'the group is accessible via the new path' do
      update_path(new_group_path)
      visit new_group_full_path
      expect(current_path).to eq(new_group_full_path)
21
      expect(find('h1.group-title')).to have_content(group.name)
22 23 24 25 26 27
    end

    scenario 'the old group path redirects to the new path' do
      update_path(new_group_path)
      visit old_group_full_path
      expect(current_path).to eq(new_group_full_path)
28
      expect(find('h1.group-title')).to have_content(group.name)
29 30 31 32 33 34 35 36 37 38 39
    end

    context 'with a subgroup' do
      given!(:subgroup) { create(:group, parent: group, path: 'subgroup') }
      given(:old_subgroup_full_path) { "/#{group.path}/#{subgroup.path}" }
      given(:new_subgroup_full_path) { "/#{new_group_path}/#{subgroup.path}" }

      scenario 'the subgroup is accessible via the new path' do
        update_path(new_group_path)
        visit new_subgroup_full_path
        expect(current_path).to eq(new_subgroup_full_path)
40
        expect(find('h1.group-title')).to have_content(subgroup.name)
41 42 43 44 45 46
      end

      scenario 'the old subgroup path redirects to the new path' do
        update_path(new_group_path)
        visit old_subgroup_full_path
        expect(current_path).to eq(new_subgroup_full_path)
47
        expect(find('h1.group-title')).to have_content(subgroup.name)
48 49 50 51
      end
    end

    context 'with a project' do
52
      given!(:project) { create(:project, group: group) }
53 54
      given(:old_project_full_path) { "/#{group.path}/#{project.path}" }
      given(:new_project_full_path) { "/#{new_group_path}/#{project.path}" }
55 56 57 58 59

      before(:context) do
        TestEnv.clean_test_path
      end

60
      after do
61 62
        TestEnv.clean_test_path
      end
63 64 65 66 67

      scenario 'the project is accessible via the new path' do
        update_path(new_group_path)
        visit new_project_full_path
        expect(current_path).to eq(new_project_full_path)
Phil Hughes's avatar
Phil Hughes committed
68
        expect(find('.breadcrumbs')).to have_content(project.path)
69 70 71 72 73 74
      end

      scenario 'the old project path redirects to the new path' do
        update_path(new_group_path)
        visit old_project_full_path
        expect(current_path).to eq(new_project_full_path)
Phil Hughes's avatar
Phil Hughes committed
75
        expect(find('.breadcrumbs')).to have_content(project.path)
76 77 78
      end
    end
  end
79 80 81 82 83 84 85

  describe 'edit group avatar' do
    before do
      visit edit_group_path(group)

      attach_file(:group_avatar, Rails.root.join('spec', 'fixtures', 'banana_sample.gif'))

86
      expect { save_group }.to change { group.reload.avatar? }.to(true)
87 88 89 90 91 92 93 94 95 96 97 98 99
    end

    it 'uploads new group avatar' do
      expect(group.avatar).to be_instance_of AvatarUploader
      expect(group.avatar.url).to eq "/uploads/-/system/group/avatar/#{group.id}/banana_sample.gif"
      expect(page).to have_link('Remove avatar')
    end

    it 'removes group avatar' do
      expect { click_link 'Remove avatar' }.to change { group.reload.avatar? }.to(false)
      expect(page).not_to have_link('Remove avatar')
    end
  end
100

101 102 103 104 105 106 107 108 109 110 111 112 113 114
  def update_path(new_group_path)
    visit edit_group_path(group)

    page.within('.gs-advanced') do
      fill_in 'group_path', with: new_group_path
      click_button 'Change group path'
    end
  end

  def save_group
    page.within('.gs-general') do
      click_button 'Save group'
    end
  end
115
end