From 2b3bc5a0f05e39f775a5d6046fdb7fc5f0165d6d Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Thu, 26 Apr 2012 15:55:44 -0700 Subject: [PATCH] fix profile json birthday response with some tests. --- app/controllers/profiles_controller.rb | 2 +- app/models/profile.rb | 5 ++++ spec/controllers/profiles_controller_spec.rb | 2 +- spec/models/profile_spec.rb | 24 ++++++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index 30b974a90..158838faf 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -16,7 +16,7 @@ class ProfilesController < ApplicationController respond_to do |format| format.json { render :json => @person.as_api_response(:backbone).merge({ :location => @person.profile.location, - :birthday => @person.profile.birthday.to_formatted_s(:long) , + :birthday => @person.profile.formatted_birthday, }) } end end diff --git a/app/models/profile.rb b/app/models/profile.rb index f56db5aab..bf41aa31b 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -130,6 +130,11 @@ class Profile < ActiveRecord::Base end end + def formatted_birthday + birthday.to_s(:long).gsub(', 1000', '') if birthday.present? + end + + def tag_string if @tag_string @tag_string diff --git a/spec/controllers/profiles_controller_spec.rb b/spec/controllers/profiles_controller_spec.rb index 10165d6fb..3db5e763f 100644 --- a/spec/controllers/profiles_controller_spec.rb +++ b/spec/controllers/profiles_controller_spec.rb @@ -13,7 +13,7 @@ describe ProfilesController do describe '#show' do it "returns the user as json" do get :show, :id => @user.person.guid, :format => :json - JSON.parse(response.body).should == JSON.parse(@user.person.as_api_response(:backbone).to_json) + JSON.parse(response.body).should include(JSON.parse(@user.person.as_api_response(:backbone).to_json)) end end diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index 113f2b996..efd46b4eb 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -263,6 +263,30 @@ describe Profile do it_should_behave_like 'it is taggable' end + describe '#formatted_birthday' do + before do + @profile = Factory.build(:profile) + @profile_hash = { 'year' => '2000', 'month' => '01', 'day' => '01' } + @profile.date = @profile_hash + end + + it 'returns a formatted date' do + @profile.formatted_birthday.should == "January 1, 2000" + end + + it 'removes nil year birthdays' do + @profile_hash.delete('year') + @profile.date = @profile_hash + @profile.formatted_birthday.should == 'January 1' + end + + it 'retuns nil if no birthday is set' do + @profile.date = {} + @profile.formatted_birthday.should == nil + end + + end + describe '#receive' do it 'updates the profile in place' do local_luke, local_leia, remote_raphael = set_up_friends