debian-mirror-gitlab/spec/controllers/users/callouts_controller_spec.rb

53 lines
1.3 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2022-01-26 12:08:38 +05:30
RSpec.describe Users::CalloutsController do
2021-11-11 11:23:49 +05:30
let_it_be(:user) { create(:user) }
2018-03-17 18:26:18 +05:30
before do
sign_in(user)
end
describe "POST #create" do
2021-11-11 11:23:49 +05:30
let(:params) { { feature_name: feature_name } }
subject { post :create, params: params, format: :json }
2018-03-17 18:26:18 +05:30
context 'with valid feature name' do
2022-01-26 12:08:38 +05:30
let(:feature_name) { Users::Callout.feature_names.each_key.first }
2018-03-17 18:26:18 +05:30
context 'when callout entry does not exist' do
2019-07-07 11:18:12 +05:30
it 'creates a callout entry with dismissed state' do
2022-01-26 12:08:38 +05:30
expect { subject }.to change { Users::Callout.count }.by(1)
2018-03-17 18:26:18 +05:30
end
2019-07-07 11:18:12 +05:30
it 'returns success' do
2018-03-17 18:26:18 +05:30
subject
expect(response).to have_gitlab_http_status(:ok)
end
end
context 'when callout entry already exists' do
2022-01-26 12:08:38 +05:30
let!(:callout) { create(:callout, feature_name: Users::Callout.feature_names.each_key.first, user: user) }
2018-03-17 18:26:18 +05:30
2021-11-11 11:23:49 +05:30
it 'returns success', :aggregate_failures do
2022-01-26 12:08:38 +05:30
expect { subject }.not_to change { Users::Callout.count }
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(:ok)
end
end
end
context 'with invalid feature name' do
let(:feature_name) { 'bogus_feature_name' }
2019-07-07 11:18:12 +05:30
it 'returns bad request' do
2018-03-17 18:26:18 +05:30
subject
expect(response).to have_gitlab_http_status(:bad_request)
end
end
end
end