diff --git a/app/presenters/aspect_presenter.rb b/app/presenters/aspect_presenter.rb new file mode 100644 index 000000000..881be4b3a --- /dev/null +++ b/app/presenters/aspect_presenter.rb @@ -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 \ No newline at end of file diff --git a/app/presenters/base_presenter.rb b/app/presenters/base_presenter.rb new file mode 100644 index 000000000..8f83962e9 --- /dev/null +++ b/app/presenters/base_presenter.rb @@ -0,0 +1,5 @@ +class BasePresenter + def self.as_collection(collection) + collection.map{|object| self.new(object).as_json} + end +end diff --git a/app/presenters/user_presenter.rb b/app/presenters/user_presenter.rb index 38436efd5..9804b49fa 100644 --- a/app/presenters/user_presenter.rb +++ b/app/presenters/user_presenter.rb @@ -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 diff --git a/features/trumpeter.feature b/features/trumpeter.feature index 7b42452d7..17b07e384 100644 --- a/features/trumpeter.feature +++ b/features/trumpeter.feature @@ -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 diff --git a/spec/presenters/aspect_presenter_spec.rb b/spec/presenters/aspect_presenter_spec.rb new file mode 100644 index 000000000..d38b97f42 --- /dev/null +++ b/spec/presenters/aspect_presenter_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/presenters/user_presenter_spec.rb b/spec/presenters/user_presenter_spec.rb new file mode 100644 index 000000000..685dcc357 --- /dev/null +++ b/spec/presenters/user_presenter_spec.rb @@ -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 \ No newline at end of file