2012-09-15 3 views
2

나는 다음과 같은 공장이 있습니다레일 3.2.8 + FactoryGirl + RABL : 어떻게 날짜에 차이가 반환됩니다

FactoryGirl.define do 
    factory :location do |f| 
    f.descrizione { Faker::Company.name } 
    f.indirizzo { 'Yellow submarine lane, 1'} 
    f.citta { 'Nowhereland' } 
    f.cap { '0100' } 
    f.provincia { 'ZZ' } 
    end 
end 

하고 다음 사양 : 예상대로

이제
describe "/api/v1/clients/:client_id/locations.json", :type => :api do 
    let(:client) { FactoryGirl.create(:client) } 
    let(:url) { "/api/v1/locations" } 

    describe 'Locations index' do 
    it_behaves_like "requires a client" 

    def do_verb 
    get url+".json", client_id: client.id 
    end 

    describe "fetches all locations for a given client" do 
    it "returns an empty array of locations when client has no locations" do 
     do_verb 
     body = JSON.parse(last_response.body) 
     body.should eq([]) 
    end 

    it "returns an array with client's locations" do 
     location = FactoryGirl.create(:location) 
     client.locations << location 
     client.save 
     do_verb 
     body = JSON.parse(last_response.body) 
     location_params = location.attributes 
     body.should eq([location_params]) 
    end 
    end 
end 
... 

, 모든 작품을 (비교 식 사이를 제외들이 의도 웃기) : created_at과 : 신체 내부의 어떤 이 FactoryGirl (location_params)에서 오는 어떤 분야 updated_at.

내가 사양을 실행 돌아갈 오류는 다음과 같습니다

Diff: 
    @@ -5,6 +5,6 @@ 
     "cap"=>"01000", 
     "citta"=>"Nowhereland", 
     "provincia"=>"ZZ", 
    - "created_at"=>Sat, 15 Sep 2012 16:39:13 UTC +00:00, 
    - "updated_at"=>Sat, 15 Sep 2012 16:39:13 UTC +00:00}] 
    + "created_at"=>"2012-09-15T16:39:13Z", 
    + "updated_at"=>"2012-09-15T16:39:13Z"}] 

당신이 응답의 몸에서 모두 created_at과 updated_at을 볼 수 있듯이

다르게 FactoryGirl에 의해 반환됩니다 것과 을 표시됩니다.

내가 분명히 여기에 누락 것이 무엇입니까? 날짜/시간 형식이없는 당신의 도움이

답변

1

JSON에 미리

감사합니다 - 모든 날짜/시간 ISO8601 형식의 문자열로 표시됩니다. 따라서 JSON에서 데이터를 인코딩하고 디코딩하면 결국 DateTime 개체와 문자열을 비교합니다.

관련 문제