-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create spec to bling_module_situation
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FactoryBot.define do | ||
factory :bling_module_situation do | ||
sequence(:situation_id) { |n| n } | ||
name { "Situation #{Faker::Lorem.word}" } | ||
module_id { Faker::Number.number(digits: 2).to_i } # Ensure this is an integer | ||
inherited_id { Faker::Number.number(digits: 2) } | ||
color { Faker::Color.hex_color } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe BlingModuleSituation, type: :model do | ||
describe 'validations' do | ||
subject { build(:bling_module_situation) } | ||
|
||
it { should validate_presence_of(:situation_id) } | ||
it { should validate_uniqueness_of(:situation_id) } | ||
it { should validate_presence_of(:name) } | ||
it { should validate_presence_of(:module_id) } | ||
end | ||
|
||
describe 'factory' do | ||
it 'has a valid factory' do | ||
expect(build(:bling_module_situation)).to be_valid | ||
end | ||
end | ||
|
||
describe 'attributes' do | ||
it { should respond_to(:situation_id) } | ||
it { should respond_to(:name) } | ||
it { should respond_to(:inherited_id) } | ||
it { should respond_to(:color) } | ||
it { should respond_to(:module_id) } | ||
end | ||
|
||
describe 'creation' do | ||
it 'can be created with valid attributes' do | ||
bling_module_situation = BlingModuleSituation.new( | ||
situation_id: 1, | ||
name: 'Test Situation', | ||
module_id: 1, | ||
inherited_id: 2, | ||
color: '#FF0000' | ||
) | ||
expect(bling_module_situation).to be_valid | ||
end | ||
end | ||
|
||
describe 'uniqueness' do | ||
it 'does not allow duplicate situation_ids' do | ||
create(:bling_module_situation, situation_id: 1) | ||
duplicate = build(:bling_module_situation, situation_id: 1) | ||
expect(duplicate).not_to be_valid | ||
end | ||
end | ||
end |