Welcome to mirror list, hosted at ThFree Co, Russian Federation.

set_sort_order_from_user_preference_shared_examples.rb « controllers « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d86838719d428521eee0f4c25b942384c2592276 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
shared_examples 'set sort order from user preference' do
  describe '#set_sort_order_from_user_preference' do
    # There is no issuable_sorting_field defined in any CE controllers yet,
    # however any other field present in user_preferences table can be used for testing.
    let(:sorting_field) { :issue_notes_filter }
    let(:sorting_param) { 'any' }

    before do
      allow(controller).to receive(:issuable_sorting_field).and_return(sorting_field)
    end

    context 'when database is in read-only mode' do
      it 'it does not update user preference' do
        allow(Gitlab::Database).to receive(:read_only?).and_return(true)

        expect_any_instance_of(UserPreference).not_to receive(:update_attribute).with(sorting_field, sorting_param)

        get :index, params: { namespace_id: project.namespace, project_id: project, sort: sorting_param }
      end
    end

    context 'when database is not in read-only mode' do
      it 'updates user preference' do
        allow(Gitlab::Database).to receive(:read_only?).and_return(false)

        expect_any_instance_of(UserPreference).to receive(:update_attribute).with(sorting_field, sorting_param)

        get :index, params: { namespace_id: project.namespace, project_id: project, sort: sorting_param }
      end
    end
  end
end