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 ...@@ -2,7 +2,7 @@ class Groups::AnalyticsController < Groups::ApplicationController
include LicenseHelper include LicenseHelper
before_action :group before_action :group
before_action :check_contribution_analytics_available! && !LicenseHelper.show_promotions? before_action :check_contribution_analytics_available!
layout 'group' layout 'group'
...@@ -32,4 +32,8 @@ class Groups::AnalyticsController < Groups::ApplicationController ...@@ -32,4 +32,8 @@ class Groups::AnalyticsController < Groups::ApplicationController
def user_ids def user_ids
@user_ids ||= @users.map(&:id) @user_ids ||= @users.map(&:id)
end end
def check_contribution_analytics_available!
render_404 unless (@group.feature_available?(:contribution_analytics) || LicenseHelper.show_promotions?(current_user))
end
end end
class Projects::AuditEventsController < Projects::ApplicationController class Projects::AuditEventsController < Projects::ApplicationController
include LicenseHelper
before_action :authorize_admin_project! before_action :authorize_admin_project!
before_action :check_audit_events_available!
layout 'project_settings' layout 'project_settings'
def index def index
@events = project.audit_events.page(params[:page]) @events = project.audit_events.page(params[:page])
end end
def check_audit_events_available!
render_404 unless (@project.feature_available?(:audit_events) || LicenseHelper.show_promotions?(current_user))
end
end end
...@@ -75,8 +75,8 @@ module LicenseHelper ...@@ -75,8 +75,8 @@ module LicenseHelper
end end
end end
def show_promotions? def show_promotions?(selected_user = current_user)
if current_user if selected_user
if current_application_settings.should_check_namespace_plan? if current_application_settings.should_check_namespace_plan?
true true
else else
......
...@@ -38,6 +38,24 @@ describe Groups::AnalyticsController do ...@@ -38,6 +38,24 @@ describe Groups::AnalyticsController do
create_push_event(user3, project) create_push_event(user3, project)
end 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 it 'sets instance variables properly' do
get :show, group_id: group.path get :show, group_id: group.path
......
...@@ -6,6 +6,23 @@ describe 'layouts/nav/_group' do ...@@ -6,6 +6,23 @@ describe 'layouts/nav/_group' do
end end
describe 'contribution analytics tab' do 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 it 'is visible' do
stub_licensed_features(contribution_analytics: true) stub_licensed_features(contribution_analytics: true)
......
...@@ -10,6 +10,44 @@ feature 'Projects > Audit Events', :js do ...@@ -10,6 +10,44 @@ feature 'Projects > Audit Events', :js do
sign_in(user) sign_in(user)
end 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 it 'has Audit Events button in head nav bar' do
visit edit_project_path(project) visit edit_project_path(project)
......
...@@ -25,7 +25,7 @@ describe 'Promotions', js: true do ...@@ -25,7 +25,7 @@ describe 'Promotions', js: true do
describe 'for project features in general on premise' do describe 'for project features in general on premise' do
context 'no license installed' do context 'no license installed' do
before do before do
License.destroy_all allow(License).to receive(:current).and_return(nil)
stub_application_setting(check_namespace_plan: false) stub_application_setting(check_namespace_plan: false)
project.team << [user, :master] project.team << [user, :master]
end end
...@@ -183,7 +183,7 @@ describe 'Promotions', js: true do ...@@ -183,7 +183,7 @@ describe 'Promotions', js: true do
it 'should appear in milestone page' do it 'should appear in milestone page' do
visit project_milestone_path(project, milestone) 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 end
it 'does not show when cookie is set' do 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