Commit 52badfa0 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Add initial models/associations

parent 205fdac9
class BoardFilter < ActiveRecord::Base
belongs_to :board
belongs_to :milestone
belongs_to :author, class_name: 'User'
belongs_to :assignee, class_name: 'User'
has_many :board_filter_labels
has_many :labels, through: :board_filter_labels
validates :board, presence: true
def milestone
return nil unless board.parent.feature_available?(:scoped_issue_board)
if milestone_id == ::Milestone::Upcoming.id
::Milestone::Upcoming
else
super
end
end
end
class BoardFilterLabel < ActiveRecord::Base
belongs_to :board_filter
belongs_to :label
validates :board_filter, presence: true
validates :label, presence: true
validates :board_filter, uniqueness: { scope: :label_id }
end
\ No newline at end of file
require 'spec_helper'
describe BoardFilterLabel, type: :model do
describe 'validations' do
subject { create(:board_filter_label) }
it { is_expected.to validate_presence_of(:board_filter) }
it { is_expected.to validate_presence_of(:label) }
it { is_expected.to validate_uniqueness_of(:board_filter).scoped_to(:label_id) }
end
describe 'associations' do
it { is_expected.to belong_to(:board_filter) }
it { is_expected.to belong_to(:label) }
end
end
\ No newline at end of file
...@@ -3,7 +3,8 @@ module EE ...@@ -3,7 +3,8 @@ module EE
extend ActiveSupport::Concern extend ActiveSupport::Concern
prepended do prepended do
belongs_to :milestone has_one :board_filter
belongs_to :group belongs_to :group
validates :name, presence: true validates :name, presence: true
...@@ -14,16 +15,6 @@ module EE ...@@ -14,16 +15,6 @@ module EE
!group !group
end end
def milestone
return nil unless parent.feature_available?(:issue_board_milestone)
if milestone_id == ::Milestone::Upcoming.id
::Milestone::Upcoming
else
super
end
end
def parent def parent
@parent ||= group || project @parent ||= group || project
end end
......
...@@ -16,41 +16,4 @@ describe Board do ...@@ -16,41 +16,4 @@ describe Board do
it { is_expected.not_to validate_presence_of(:group) } it { is_expected.not_to validate_presence_of(:group) }
end end
end end
describe 'milestone' do
subject(:board) { build(:board) }
context 'when the feature is available' do
before do
stub_licensed_features(issue_board_milestone: true)
end
it 'returns Milestone::Upcoming for upcoming milestone id' do
board.milestone_id = Milestone::Upcoming.id
expect(board.milestone).to eq Milestone::Upcoming
end
it 'returns milestone for valid milestone id' do
milestone = create(:milestone)
board.milestone_id = milestone.id
expect(board.milestone).to eq milestone
end
it 'returns nil for invalid milestone id' do
board.milestone_id = -1
expect(board.milestone).to be_nil
end
end
it 'returns nil when the feature is not available' do
stub_licensed_features(issue_board_milestone: false)
milestone = create(:milestone)
board.milestone_id = milestone.id
expect(board.milestone).to be_nil
end
end
end end
FactoryGirl.define do
factory :board_filter_label do
association :board_filter
association :label
end
end
FactoryGirl.define do
factory :board_filter do
association :board
association :milestone
association :author, factory: :user
association :assignee, factory: :user
end
end
require 'spec_helper'
describe BoardFilter, type: :model do
describe 'validations' do
it { is_expected.to validate_presence_of(:board) }
end
describe 'associations' do
it { is_expected.to belong_to(:board) }
it { is_expected.to belong_to(:milestone) }
it { is_expected.to belong_to(:author).class_name('User') }
it { is_expected.to belong_to(:assignee).class_name('User') }
it { is_expected.to have_many(:board_filter_labels) }
it { is_expected.to have_many(:labels).through(:board_filter_labels) }
end
describe 'milestone' do
subject(:board_filter) { build(:board_filter) }
context 'when the feature is available' do
before do
stub_licensed_features(scoped_issue_board: true)
end
it 'returns Milestone::Upcoming for upcoming milestone id' do
board_filter.milestone_id = Milestone::Upcoming.id
expect(board_filter.milestone).to eq Milestone::Upcoming
end
it 'returns milestone for valid milestone id' do
milestone = create(:milestone)
board_filter.milestone_id = milestone.id
expect(board_filter.milestone).to eq milestone
end
it 'returns nil for invalid milestone id' do
board_filter.milestone_id = -1
expect(board_filter.milestone).to be_nil
end
end
it 'returns nil when the feature is not available' do
stub_licensed_features(scoped_issue_board: false)
milestone = create(:milestone)
board_filter.milestone_id = milestone.id
expect(board_filter.milestone).to be_nil
end
end
end
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