diff --git a/spec/factories/bling_module_situations.rb b/spec/factories/bling_module_situations.rb new file mode 100644 index 00000000..40afe8e9 --- /dev/null +++ b/spec/factories/bling_module_situations.rb @@ -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 diff --git a/spec/models/bling_module_situation_spec.rb b/spec/models/bling_module_situation_spec.rb new file mode 100644 index 00000000..9ec51b28 --- /dev/null +++ b/spec/models/bling_module_situation_spec.rb @@ -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