aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers/workgroups_controller_spec.rb
blob: d25e425725ec19b2c9dd8076a2bedcc9ac9233d1 (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
33
34
35
36
37
38
39
40
41
42
43
RSpec.describe WorkgroupsController, :type => :controller do
  login_user

  let(:workgroup) { create :workgroup }
  let(:workbench) { create :workbench, workgroup: workgroup }
  let(:compliance_control_set) { create :compliance_control_set, organisation: @user.organisation }
  let(:merge_id) { 2**64/2 - 1 } # Let's check we support Bigint

  describe 'PATCH update' do
    let(:params){
      {
        id: workgroup.id,
        workgroup: {
          workbenches_attributes: {
            "0" => {
              id: workbench.id,
              compliance_control_set_ids: {
                after_import_by_workgroup: compliance_control_set.id,
                after_merge_by_workgroup: merge_id
              }
            }
          }
        }
      }
    }
    let(:request){ patch :update, params }

    it 'should respond with 403' do
      expect(request).to have_http_status 403
    end

    context "when belonging to the owner" do
      before do
        workgroup.update owner: @user.organisation
      end
      it 'returns HTTP success' do
        expect(request).to be_redirect
        expect(workbench.reload.compliance_control_set(:after_import_by_workgroup)).to eq compliance_control_set
        expect(workbench.reload.owner_compliance_control_set_ids['after_merge_by_workgroup']).to eq merge_id.to_s
      end
    end
  end
end