MS DC added aspect presenter, and include the data on the user
This commit is contained in:
parent
bf4dabc4f4
commit
cc04f492f2
6 changed files with 67 additions and 5 deletions
15
app/presenters/aspect_presenter.rb
Normal file
15
app/presenters/aspect_presenter.rb
Normal 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
|
||||
5
app/presenters/base_presenter.rb
Normal file
5
app/presenters/base_presenter.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class BasePresenter
|
||||
def self.as_collection(collection)
|
||||
collection.map{|object| self.new(object).as_json}
|
||||
end
|
||||
end
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
13
spec/presenters/aspect_presenter_spec.rb
Normal file
13
spec/presenters/aspect_presenter_spec.rb
Normal 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
|
||||
21
spec/presenters/user_presenter_spec.rb
Normal file
21
spec/presenters/user_presenter_spec.rb
Normal 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
|
||||
Loading…
Reference in a new issue