Skip to content

Creating custom-class objects with factory_bot #226

Description

@toadle

Hey guys,

I'm trying to upgrade our contentful gem to the most recent version. We are currently still on 0.8. Our test-suite relies on being able to create instances of custom Contentful-class via factory_bot.

Here is an example configuration of a factory:

FactoryBot.define do
  factory :category, class: Contentful::Category do
    title       { FFaker::DizzleIpsum.word }
    slug        { FFaker::Internet.slug.delete(".") }
  end
end

whereas Contentful::Category looks like:

class Contentful::Category < Contentful::Entry
...
end

and is mentioned in the entry_mapping.

Since upgrading to 2.15.3 I have to give factory_bot an initialize_with-methode since Content::FieldsResource requires itemand configuration as parameters (

def initialize(item, _configuration, localized = false, includes = [], entries = {}, depth = 0, errors = [])
)

But initialize_with({},{}) won't do and then I'm in the process of reconstructing real-world contentful-API-responses.

Is there a good way to quickly create instances of Contentful-Custom-Classes without the whole enchilada?

David Litvak Bruno (@dlitvakb) We solved this once waaaay back when #79 ;-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions