From 09064bb219279162ba3f84b6287247f9a654dc6c Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Wed, 20 Dec 2023 17:34:26 +0000 Subject: Properly configures factory_bot and adds Faker --- Gemfile | 1 + Gemfile.lock | 3 +++ spec/factories/events.rb | 10 +++++----- spec/rails_helper.rb | 1 + spec/requests/events_spec.rb | 2 +- spec/support/factory_bot.rb | 5 +++++ 6 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 spec/support/factory_bot.rb diff --git a/Gemfile b/Gemfile index cea169a..9638195 100644 --- a/Gemfile +++ b/Gemfile @@ -52,6 +52,7 @@ group :development, :test do gem "debug", platforms: %i[ mri windows ] gem 'rspec-rails', '~> 6.1.0' gem 'factory_bot_rails' + gem 'faker' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 626a9db..0e3e61a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -111,6 +111,8 @@ GEM factory_bot_rails (6.4.2) factory_bot (~> 6.4) railties (>= 5.0.0) + faker (3.2.2) + i18n (>= 1.8.11, < 2) globalid (1.2.1) activesupport (>= 6.1) i18n (1.14.1) @@ -271,6 +273,7 @@ DEPENDENCIES cssbundling-rails debug factory_bot_rails + faker jbuilder jsbundling-rails pry (~> 0.14.2) diff --git a/spec/factories/events.rb b/spec/factories/events.rb index 8fbba83..aaaae0a 100644 --- a/spec/factories/events.rb +++ b/spec/factories/events.rb @@ -1,11 +1,11 @@ FactoryBot.define do factory :event do name { "MyString" } - date { "2023-12-20" } - organisation + date { Faker::Date.backward(days: 10) } + organisation_id { "1" } end - factory :organisation do - name { "Smersh" } - end + # factory :organisation do + # name { "Smersh" } + # end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index a15455f..b30b931 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,5 +1,6 @@ # This file is copied to spec/ when you run 'rails generate rspec:install' require 'spec_helper' +require 'support/factory_bot.rb' ENV['RAILS_ENV'] ||= 'test' require_relative '../config/environment' # Prevent database truncation if the environment is production diff --git a/spec/requests/events_spec.rb b/spec/requests/events_spec.rb index 96183ae..a3f9f96 100644 --- a/spec/requests/events_spec.rb +++ b/spec/requests/events_spec.rb @@ -19,7 +19,7 @@ RSpec.describe "/events", type: :request do # adjust the attributes here as well. let(:valid_attributes) { # skip("Add a hash of attributes valid for your model") - build :event.attributes # build uses the factory and attributes converts to a hash.... + build(:event).attributes # build uses the factory and attributes converts to a hash.... } let(:invalid_attributes) { diff --git a/spec/support/factory_bot.rb b/spec/support/factory_bot.rb new file mode 100644 index 0000000..0ca1986 --- /dev/null +++ b/spec/support/factory_bot.rb @@ -0,0 +1,5 @@ +require 'factory_bot' + +RSpec.configure do |config| + config.include FactoryBot::Syntax::Methods +end -- cgit v1.2.3