debian-mirror-gitlab/spec/controllers/user_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'
2020-06-23 00:09:42 +05:30
RSpec.describe UserCalloutsController 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
2020-03-13 15:44:24 +05:30
let(:feature_name) { UserCallout.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
2018-03-17 18:26:18 +05:30
expect { subject }.to change { UserCallout.count }.by(1)
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
2020-03-13 15:44:24 +05:30
let!(:callout) { create(:user_callout, feature_name: UserCallout.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
expect { subject }.not_to change { UserCallout.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