Skip to content

Commit

Permalink
create spec to bling_module_situation
Browse files Browse the repository at this point in the history
  • Loading branch information
puppe1990 committed Oct 23, 2024
1 parent 7ba49aa commit da56bd0
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
9 changes: 9 additions & 0 deletions spec/factories/bling_module_situations.rb
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
49 changes: 49 additions & 0 deletions spec/models/bling_module_situation_spec.rb
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

0 comments on commit da56bd0

Please sign in to comment.