Commit 8ef929eb5a9b9bc0787f966d1677f928a76ce97c

Authored by Rafael Manzo
1 parent abdd2edc

Added validations for both Project and KalibroConfiguration Attributes

app/models/kalibro_configuration_attributes.rb
1 1 class KalibroConfigurationAttributes < ActiveRecord::Base
2 2 belongs_to :user
3 3 validates :kalibro_configuration_id, presence: true
  4 + validates :user, presence: true
4 5  
5 6 def kalibro_configuration
6 7 @kalibro_configuration ||= KalibroConfiguration.find(kalibro_configuration_id)
... ...
app/models/project_attributes.rb
1 1 class ProjectAttributes < ActiveRecord::Base
2 2 belongs_to :user
3   -
  3 + validates :project_id, presence: true
  4 + validates :user, presence: true
  5 +
4 6 def project
5 7 Project.find(self.project_id)
6 8 end
... ...
spec/models/kalibro_configuration_attributes_spec.rb
1 1 require 'rails_helper'
2 2  
3 3 describe KalibroConfigurationAttributes, :type => :model do
  4 + describe 'validations' do
  5 + it { is_expected.to validate_presence_of(:kalibro_configuration_id) }
  6 + it { is_expected.to validate_presence_of(:user) }
  7 + end
  8 +
4 9 describe 'associations' do
5 10 it { is_expected.to belong_to(:user) }
6 11 end
... ...
spec/models/project_attributes_spec.rb
... ... @@ -5,6 +5,11 @@ RSpec.describe ProjectAttributes, type: :model do
5 5 it { is_expected.to belong_to(:user) }
6 6 end
7 7  
  8 + describe 'validations' do
  9 + it { is_expected.to validate_presence_of(:project_id) }
  10 + it { is_expected.to validate_presence_of(:user) }
  11 + end
  12 +
8 13 describe 'methods' do
9 14 describe 'project' do
10 15 subject { FactoryGirl.build(:project_attributes) }
... ...