2020-04-29 20:09:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Metrics::UsersStarredDashboard do
|
2020-04-29 20:09:37 -04:00
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to belong_to(:project).inverse_of(:metrics_users_starred_dashboards) }
|
|
|
|
it { is_expected.to belong_to(:user).inverse_of(:metrics_users_starred_dashboards) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validation' do
|
|
|
|
subject { build(:metrics_users_starred_dashboard) }
|
|
|
|
|
|
|
|
it { is_expected.to validate_presence_of(:user_id) }
|
|
|
|
it { is_expected.to validate_presence_of(:project_id) }
|
|
|
|
it { is_expected.to validate_presence_of(:dashboard_path) }
|
|
|
|
it { is_expected.to validate_length_of(:dashboard_path).is_at_most(255) }
|
|
|
|
it { is_expected.to validate_uniqueness_of(:dashboard_path).scoped_to(%i[user_id project_id]) }
|
|
|
|
end
|
2020-05-11 14:09:55 -04:00
|
|
|
|
|
|
|
context 'scopes' do
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:starred_dashboard_a) { create(:metrics_users_starred_dashboard, project: project, dashboard_path: 'path_a') }
|
|
|
|
let_it_be(:starred_dashboard_b) { create(:metrics_users_starred_dashboard, project: project, dashboard_path: 'path_b') }
|
|
|
|
let_it_be(:starred_dashboard_c) { create(:metrics_users_starred_dashboard, dashboard_path: 'path_b') }
|
|
|
|
|
|
|
|
describe '#for_project' do
|
|
|
|
it 'selects only starred dashboards belonging to project' do
|
|
|
|
expect(described_class.for_project(project)).to contain_exactly starred_dashboard_a, starred_dashboard_b
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#for_project_dashboard' do
|
|
|
|
it 'selects only starred dashboards belonging to project with given dashboard path' do
|
|
|
|
expect(described_class.for_project_dashboard(project, 'path_b')).to contain_exactly starred_dashboard_b
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-04-29 20:09:37 -04:00
|
|
|
end
|