create activeresource model factory using Factory Bot in rails

175 Views Asked by At

How to create rspec factory of activeresource model?

1

There are 1 best solutions below

0
Cameron On

You can create factories for activeresource models just like activerecord models. For example, here is a model and corresponding factory

class Person < ActiveResource::Base
  self.site = "http://api.people.com:3000"
end

FactoryBot.define do
  factory :person do
    name { "test" }
  end
end

Note: every time you create a factory (e.g. FactoryBot.create(:person)), you will make an API request. You may want to mock out API requests when testing. Here is an example of how to use activeresource's http mocking