bootstrap my_aspects data

This commit is contained in:
Fabián Rodríguez 2012-12-23 22:25:09 -02:00
parent e9031a7bf3
commit f978a75b8c
3 changed files with 13 additions and 7 deletions

View file

@ -39,7 +39,8 @@ module LayoutHelper
def set_current_user_in_javascript
return unless user_signed_in?
user = UserPresenter.new(current_user).to_json
a_ids = session[:a_ids] || []
user = UserPresenter.new(current_user, a_ids).to_json
content_tag(:script) do
<<-JS.html_safe
window.current_user_attributes = #{user}

View file

@ -1,8 +1,9 @@
class UserPresenter
attr_accessor :user
attr_accessor :user, :aspects_ids
def initialize(user)
self.user = user
def initialize(user, aspects_ids)
self.user = user
self.aspects_ids = aspects_ids
end
def to_json(options = {})
@ -27,7 +28,11 @@ class UserPresenter
end
def aspects
AspectPresenter.as_collection(user.aspects)
@aspects ||= begin
aspects = AspectPresenter.as_collection(user.aspects)
no_aspects = self.aspects_ids.empty?
aspects.each{ |a| a[:selected] = no_aspects || self.aspects_ids.include?(a[:id].to_s) }
end
end
def notifications_count

View file

@ -2,7 +2,7 @@ require 'spec_helper'
describe UserPresenter do
before do
@presenter = UserPresenter.new(bob)
@presenter = UserPresenter.new(bob, [])
end
describe '#to_json' do
@ -34,4 +34,4 @@ describe UserPresenter do
@presenter.configured_services.should include("fakebook")
end
end
end
end