MS DC added aspect presenter, and include the data on the user

This commit is contained in:
Dennis Collinson 2012-03-06 17:50:11 -08:00
parent bf4dabc4f4
commit cc04f492f2
6 changed files with 67 additions and 5 deletions

View file

@ -0,0 +1,15 @@
class AspectPresenter < BasePresenter
def initialize(aspect)
@aspect = aspect
end
def as_json
{ :id => @aspect.id,
:name => @aspect.name,
}
end
def to_json(options = {})
as_json.to_json(options)
end
end

View file

@ -0,0 +1,5 @@
class BasePresenter
def self.as_collection(collection)
collection.map{|object| self.new(object).as_json}
end
end

View file

@ -9,12 +9,15 @@ class UserPresenter
self.user.person.as_api_response(:backbone).update(
{ :notifications_count => notifications_count,
:unread_messages_count => unread_messages_count,
:admin => admin
:admin => admin,
:aspects => aspects
}
).to_json(options)
end
protected
def aspects
AspectPresenter.as_collection(user.aspects)
end
def notifications_count
@notification_count ||= user.unread_notifications.count

View file

@ -3,10 +3,15 @@ Feature: Creating a new post
Background:
Given a user with username "bob"
And I sign in as "bob@bob.bob"
And I trumpet
And I write "Rectangles are awesome"
Scenario: Posting a public message
When I trumpet
And I write "Rectangles are awesome"
And I press "Share"
When I press "Share"
When I go to "/stream"
Then I should see "Rectangles are awesome" as the first post in my stream
Scenario: Posting to Aspects
When I select "generic" in my aspects dropdown
And I press "Share"
Then I should see "Rectangles are awesome" as a limited post in my stream

View file

@ -0,0 +1,13 @@
require 'spec_helper'
describe AspectPresenter do
before do
@presenter = AspectPresenter.new(bob.aspects.first)
end
describe '#to_json' do
it 'works' do
@presenter.to_json.should be_present
end
end
end

View file

@ -0,0 +1,21 @@
require 'spec_helper'
describe UserPresenter do
before do
@presenter = UserPresenter.new(bob)
end
describe '#to_json' do
it 'works' do
@presenter.to_json.should be_present
end
end
describe '#aspects' do
it 'provides an array of the jsonified aspects' do
aspect = bob.aspects.first
@presenter.aspects.first[:id].should == aspect.id
@presenter.aspects.first[:name].should == aspect.name
end
end
end