Ch Zeeshan
Ch Zeeshan

Reputation: 11

create activeresource model factory using Factory Bot in rails

How to create rspec factory of activeresource model?

Upvotes: 1

Views: 204

Answers (1)

Cameron
Cameron

Reputation: 931

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

Upvotes: 1

Related Questions