I am trying to create a json that contains an array with FactoryGirl. This is for unit testing a Rails controller that sends back a api.
From rails: how to unit test a json controller?, I would have:
describe "GET 'show'" do
before(:each) do
@company = Factory(:company)
get 'show', :format => :json, :id => @company.id
end
it "should be successful" do
response.should be_success
end
it "should return the correct company when correct id is passed" do
body = JSON.parse(response.body)
body["id"].should == @company.id
end
end
but the issue I am having is trying to make the json with the array in Factory Girl:
FactoryGirl.define do
factory :datacenter, class:Array do
datacenters ["TX", "WA", "MI", "foo"]
end
end
which the json would look like:
{"datacenters": "TX", "WA", "MI", "foo"]}
Aucun commentaire:
Enregistrer un commentaire