Commit 8ef929eb5a9b9bc0787f966d1677f928a76ce97c
1 parent
abdd2edc
Exists in
colab
and in
4 other branches
Added validations for both Project and KalibroConfiguration Attributes
Showing
4 changed files
with
14 additions
and
1 deletions
Show diff stats
app/models/kalibro_configuration_attributes.rb
| 1 | class KalibroConfigurationAttributes < ActiveRecord::Base | 1 | class KalibroConfigurationAttributes < ActiveRecord::Base |
| 2 | belongs_to :user | 2 | belongs_to :user |
| 3 | validates :kalibro_configuration_id, presence: true | 3 | validates :kalibro_configuration_id, presence: true |
| 4 | + validates :user, presence: true | ||
| 4 | 5 | ||
| 5 | def kalibro_configuration | 6 | def kalibro_configuration |
| 6 | @kalibro_configuration ||= KalibroConfiguration.find(kalibro_configuration_id) | 7 | @kalibro_configuration ||= KalibroConfiguration.find(kalibro_configuration_id) |
app/models/project_attributes.rb
| 1 | class ProjectAttributes < ActiveRecord::Base | 1 | class ProjectAttributes < ActiveRecord::Base |
| 2 | belongs_to :user | 2 | belongs_to :user |
| 3 | - | 3 | + validates :project_id, presence: true |
| 4 | + validates :user, presence: true | ||
| 5 | + | ||
| 4 | def project | 6 | def project |
| 5 | Project.find(self.project_id) | 7 | Project.find(self.project_id) |
| 6 | end | 8 | end |
spec/models/kalibro_configuration_attributes_spec.rb
| 1 | require 'rails_helper' | 1 | require 'rails_helper' |
| 2 | 2 | ||
| 3 | describe KalibroConfigurationAttributes, :type => :model do | 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 | describe 'associations' do | 9 | describe 'associations' do |
| 5 | it { is_expected.to belong_to(:user) } | 10 | it { is_expected.to belong_to(:user) } |
| 6 | end | 11 | end |
spec/models/project_attributes_spec.rb
| @@ -5,6 +5,11 @@ RSpec.describe ProjectAttributes, type: :model do | @@ -5,6 +5,11 @@ RSpec.describe ProjectAttributes, type: :model do | ||
| 5 | it { is_expected.to belong_to(:user) } | 5 | it { is_expected.to belong_to(:user) } |
| 6 | end | 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 | describe 'methods' do | 13 | describe 'methods' do |
| 9 | describe 'project' do | 14 | describe 'project' do |
| 10 | subject { FactoryGirl.build(:project_attributes) } | 15 | subject { FactoryGirl.build(:project_attributes) } |