From dc59f39050de6e6e0e6d0d82a4fdbed1f20189a1 Mon Sep 17 00:00:00 2001 From: Stuart Olivera Date: Wed, 2 Jan 2019 03:08:45 -0500 Subject: [PATCH] Define test factory classes using stringified class names As described in https://github.com/doorkeeper-gem/doorkeeper/issues/1043, factories defined by doorkeeper are unable to be loaded by host apps using the `factory_bot_rails` gem (receiving errors such as `uninitialized constant Doorkeeper::AccessGrant`) Documentation for factory_bot was later added to explain an easy fix for this: instead of defining the factory's `class: ` with a named constant, wrap the constant in a string. By doing so, the constant isn't evaluated until the factory actually runs, at which point the `Doorkeeper::` models have all been loaded. Fixes https://github.com/thoughtbot/factory_bot/issues/1188 --- NEWS.md | 1 + spec/factories.rb | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 9a2644644..05f1ebf57 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,7 @@ User-visible changes worth mentioning. - [#1162] Fix `enforce_content_type` for requests without body. - [#1164] Fix error when `root_path` is not defined. - [#1175] Internal refactor: use `scopes_string` inside `scopes`. +- [#1176] Fix test factory support for `factory_bot_rails` ## 5.0.2 diff --git a/spec/factories.rb b/spec/factories.rb index 719393fce..8258f7f94 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -1,5 +1,5 @@ FactoryBot.define do - factory :access_grant, class: Doorkeeper::AccessGrant do + factory :access_grant, class: "Doorkeeper::AccessGrant" do sequence(:resource_owner_id) { |n| n } application redirect_uri { 'https://app.com/callback' } @@ -7,7 +7,7 @@ scopes { 'public write' } end - factory :access_token, class: Doorkeeper::AccessToken do + factory :access_token, class: "Doorkeeper::AccessToken" do sequence(:resource_owner_id) { |n| n } application expires_in { 2.hours } @@ -17,7 +17,7 @@ end end - factory :application, class: Doorkeeper::Application do + factory :application, class: "Doorkeeper::Application" do sequence(:name) { |n| "Application #{n}" } redirect_uri { 'https://app.com/callback' } end