gitlab-org--gitlab-foss/spec/controllers/user_callouts_controller_spec.rb

50 lines
1.2 KiB
Ruby
Raw Normal View History

2018-01-26 16:49:20 -05:00
require 'spec_helper'
2018-02-02 16:51:03 -05:00
describe UserCalloutsController do
2018-01-26 16:49:20 -05:00
let(:user) { create(:user) }
before do
sign_in(user)
end
2018-02-02 16:23:26 -05:00
describe "POST #create" do
subject { post :create, feature_name: feature_name, format: :json }
2018-01-26 16:49:20 -05:00
context 'with valid feature name' do
let(:feature_name) { UserCallout.feature_names.keys.first }
context 'when callout entry does not exist' do
it 'should create a callout entry with dismissed state' do
expect { subject }.to change { UserCallout.count }.by(1)
end
it 'should return success' do
subject
expect(response).to have_gitlab_http_status(:ok)
end
2018-01-26 16:49:20 -05:00
end
context 'when callout entry already exists' do
let!(:callout) { create(:user_callout, feature_name: UserCallout.feature_names.keys.first, user: user) }
it 'should return success' do
subject
2018-01-26 16:49:20 -05:00
expect(response).to have_gitlab_http_status(:ok)
end
2018-01-26 16:49:20 -05:00
end
end
context 'with invalid feature name' do
let(:feature_name) { 'bogus_feature_name' }
2018-01-26 16:49:20 -05:00
it 'should return bad request' do
2018-01-26 16:49:20 -05:00
subject
expect(response).to have_gitlab_http_status(:bad_request)
2018-01-26 16:49:20 -05:00
end
end
end
end