fix profile json birthday response with some tests.
This commit is contained in:
parent
0b3926d810
commit
2b3bc5a0f0
4 changed files with 31 additions and 2 deletions
|
|
@ -16,7 +16,7 @@ class ProfilesController < ApplicationController
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json { render :json => @person.as_api_response(:backbone).merge({
|
format.json { render :json => @person.as_api_response(:backbone).merge({
|
||||||
:location => @person.profile.location,
|
:location => @person.profile.location,
|
||||||
:birthday => @person.profile.birthday.to_formatted_s(:long) ,
|
:birthday => @person.profile.formatted_birthday,
|
||||||
}) }
|
}) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -130,6 +130,11 @@ class Profile < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def formatted_birthday
|
||||||
|
birthday.to_s(:long).gsub(', 1000', '') if birthday.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def tag_string
|
def tag_string
|
||||||
if @tag_string
|
if @tag_string
|
||||||
@tag_string
|
@tag_string
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ describe ProfilesController do
|
||||||
describe '#show' do
|
describe '#show' do
|
||||||
it "returns the user as json" do
|
it "returns the user as json" do
|
||||||
get :show, :id => @user.person.guid, :format => :json
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -263,6 +263,30 @@ describe Profile do
|
||||||
it_should_behave_like 'it is taggable'
|
it_should_behave_like 'it is taggable'
|
||||||
end
|
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
|
describe '#receive' do
|
||||||
it 'updates the profile in place' do
|
it 'updates the profile in place' do
|
||||||
local_luke, local_leia, remote_raphael = set_up_friends
|
local_luke, local_leia, remote_raphael = set_up_friends
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue