diff --git a/Gemfile b/Gemfile index cdbb8ab..5eb981a 100644 --- a/Gemfile +++ b/Gemfile @@ -24,9 +24,10 @@ gem 'rubytree' group :development, :test do gem 'debug', platforms: %i[mri windows] gem 'factory_bot_rails' + gem 'license_finder' gem 'pry' gem 'rspec-rails', '~> 7.0.0' - gem 'license_finder' + gem 'shoulda-matchers', '~> 6.0' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index a1ac3c1..09646a4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -289,6 +289,8 @@ GEM json (~> 2.0, > 2.3.1) rubyzip (2.3.2) securerandom (0.3.1) + shoulda-matchers (6.4.0) + activesupport (>= 5.2.0) solid_queue (1.0.1) activejob (>= 7.1) activerecord (>= 7.1) @@ -361,6 +363,7 @@ DEPENDENCIES rspec-rails (~> 7.0.0) rubocop rubytree + shoulda-matchers (~> 6.0) solid_queue (~> 1.0) sprockets-rails stimulus-rails diff --git a/app/models/guest.rb b/app/models/guest.rb index 87680bf..774eee3 100644 --- a/app/models/guest.rb +++ b/app/models/guest.rb @@ -3,7 +3,7 @@ class Guest < ApplicationRecord belongs_to :group - enum status: { + enum :status, { considered: 0, invited: 10, confirmed: 20, diff --git a/spec/models/guest_spec.rb b/spec/models/guest_spec.rb index 1d3e530..6861079 100644 --- a/spec/models/guest_spec.rb +++ b/spec/models/guest_spec.rb @@ -3,5 +3,37 @@ require 'rails_helper' RSpec.describe Guest, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + it do + should define_enum_for(:status).with_values( + considered: 0, + invited: 10, + confirmed: 20, + declined: 30, + tentative: 40 + ) + end + + it { should belong_to(:group) } + + describe 'scopes' do + describe '.potential' do + it 'returns guests that are not declined or considered' do + _declined_guest = create(:guest, status: :declined) + _considered_guest = create(:guest, status: :considered) + invited_guest = create(:guest, status: :invited) + confirmed_guest = create(:guest, status: :confirmed) + tentative_guest = create(:guest, status: :tentative) + + expect(Guest.potential).to match_array([invited_guest, confirmed_guest, tentative_guest]) + end + end + end + + describe '#full_name' do + it 'returns the full name of the guest' do + guest = create(:guest, first_name: 'John', last_name: 'Doe') + + expect(guest.full_name).to eq('John Doe') + end + end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 233f83a..fa81db3 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -66,3 +66,10 @@ RSpec.configure do |config| # config.filter_gems_from_backtrace("gem name") config.include FactoryBot::Syntax::Methods end + +Shoulda::Matchers.configure do |config| + config.integrate do |with| + with.test_framework :rspec + with.library :rails + end +end