diff options
author | Matthew Lemon <y@yulqen.org> | 2023-12-20 17:34:26 +0000 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2023-12-20 17:34:40 +0000 |
commit | 09064bb219279162ba3f84b6287247f9a654dc6c (patch) | |
tree | 1e314b83f5bf85e46a521cb4970b2d05c7bf5af2 | |
parent | d5f5c3d7f2d92c180c56053c994a148afd63118a (diff) |
Properly configures factory_bot and adds Faker
-rw-r--r-- | Gemfile | 1 | ||||
-rw-r--r-- | Gemfile.lock | 3 | ||||
-rw-r--r-- | spec/factories/events.rb | 10 | ||||
-rw-r--r-- | spec/rails_helper.rb | 1 | ||||
-rw-r--r-- | spec/requests/events_spec.rb | 2 | ||||
-rw-r--r-- | spec/support/factory_bot.rb | 5 |
6 files changed, 16 insertions, 6 deletions
@@ -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 |