Commit acfd70f0 authored by Tim Zallmann's avatar Tim Zallmann

Added Specs + Fixed Tests

parent f95109d0
......@@ -2,7 +2,7 @@ class Groups::AnalyticsController < Groups::ApplicationController
include LicenseHelper
before_action :group
before_action :check_contribution_analytics_available! && !LicenseHelper.show_promotions?
before_action :check_contribution_analytics_available!
layout 'group'
......@@ -32,4 +32,8 @@ class Groups::AnalyticsController < Groups::ApplicationController
def user_ids
@user_ids ||= @users.map(&:id)
end
def check_contribution_analytics_available!
render_404 unless (@group.feature_available?(:contribution_analytics) || LicenseHelper.show_promotions?(current_user))
end
end
class Projects::AuditEventsController < Projects::ApplicationController
include LicenseHelper
before_action :authorize_admin_project!
before_action :check_audit_events_available!
layout 'project_settings'
def index
@events = project.audit_events.page(params[:page])
end
def check_audit_events_available!
render_404 unless (@project.feature_available?(:audit_events) || LicenseHelper.show_promotions?(current_user))
end
end
......@@ -75,8 +75,8 @@ module LicenseHelper
end
end
def show_promotions?
if current_user
def show_promotions?(selected_user = current_user)
if selected_user
if current_application_settings.should_check_namespace_plan?
true
else
......
......@@ -38,6 +38,24 @@ describe Groups::AnalyticsController do
create_push_event(user3, project)
end
it 'returns 404 when feature is not available and we dont show promotions' do
stub_licensed_features(contribution_analytics: false)
get :show, group_id: group.path
expect(response).to have_http_status(404)
end
it 'returns page when feature is not available and we show promotions' do
stub_licensed_features(contribution_analytics: false)
let!(:license) { nil }
get :show, group_id: group.path
expect(response).to have_http_status(200)
end
it 'sets instance variables properly' do
get :show, group_id: group.path
......
......@@ -6,6 +6,23 @@ describe 'layouts/nav/_group' do
end
describe 'contribution analytics tab' do
it 'is not visible when there is no valid license and we dont show promotions' do
stub_licensed_features(contribution_analytics: false)
render
expect(rendered).not_to have_text 'Contribution Analytics'
end
it 'is visible when there is no valid license but we show promotions' do
stub_licensed_features(contribution_analytics: false)
let!(:license) { nil }
render
expect(rendered).to have_text 'Contribution Analytics'
end
it 'is visible' do
stub_licensed_features(contribution_analytics: true)
......
......@@ -10,6 +10,44 @@ feature 'Projects > Audit Events', :js do
sign_in(user)
end
context 'unlicensed' do
before do
stub_licensed_features(audit_events: false)
end
it 'returns 404' do
visit project_audit_events_path(project)
expect(page.status_code).to eq(404)
end
it 'does not have Audit Events button in head nav bar' do
visit edit_project_path(project)
expect(page).not_to have_link('Audit Events')
end
end
context 'unlicensed but we show promotions' do
before do
stub_licensed_features(audit_events: false)
let!(:license) { nil }
end
it 'returns 404' do
visit project_audit_events_path(project)
expect(page.status_code).to eq(200)
end
it 'does not have Audit Events button in head nav bar' do
visit edit_project_path(project)
expect(page).to have_link('Audit Events')
end
end
it 'has Audit Events button in head nav bar' do
visit edit_project_path(project)
......
......@@ -25,7 +25,7 @@ describe 'Promotions', js: true do
describe 'for project features in general on premise' do
context 'no license installed' do
before do
License.destroy_all
allow(License).to receive(:current).and_return(nil)
stub_application_setting(check_namespace_plan: false)
project.team << [user, :master]
end
......@@ -183,7 +183,7 @@ describe 'Promotions', js: true do
it 'should appear in milestone page' do
visit project_milestone_path(project, milestone)
expect(find('#promote_burndown_charts')).to have_content 'Improve milestone with Burndown Charts.'
expect(find('#promote_burndown_charts')).to have_content 'Improve milestones with Burndown Charts.'
end
it 'does not show when cookie is set' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment