wip removed some generated specs
This commit is contained in:
parent
06f886ad77
commit
fa9269541f
16 changed files with 175 additions and 7 deletions
|
|
@ -44,7 +44,7 @@ class AspectsController < ApplicationController
|
|||
|
||||
@aspect_ids = @aspects.map { |a| a.id }
|
||||
posts = current_user.visible_posts(:by_members_of => @aspect_ids,
|
||||
:type => ['StatusMessage','ActivityStreams::Photo'],
|
||||
:type => ['StatusMessage','Reshare', 'ActivityStreams::Photo'],
|
||||
:order => session[:sort_order] + ' DESC',
|
||||
:max_time => params[:max_time].to_i
|
||||
).includes(:mentions => {:person => :profile})
|
||||
|
|
|
|||
13
app/controllers/reshares_controller.rb
Normal file
13
app/controllers/reshares_controller.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
class ResharesController < ApplicationController
|
||||
before_filter :authenticate_user!
|
||||
respond_to :js
|
||||
|
||||
def create
|
||||
@reshare = current_user.build_post(:reshare, :root_id => params[:root_id])
|
||||
if @reshare.save!
|
||||
current_user.add_to_streams(@reshare, current_user.aspects)
|
||||
end
|
||||
|
||||
respond_with @reshare
|
||||
end
|
||||
end
|
||||
2
app/helpers/reshares_helper.rb
Normal file
2
app/helpers/reshares_helper.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
module ResharesHelper
|
||||
end
|
||||
19
app/models/reshare.rb
Normal file
19
app/models/reshare.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
class Reshare < Post
|
||||
belongs_to :root, :class_name => 'Post'
|
||||
validate :root_must_be_public
|
||||
attr_accessible :root_id,
|
||||
|
||||
before_validation do
|
||||
self.public = true
|
||||
end
|
||||
|
||||
delegate :photos, :text, :comments, :to => :root
|
||||
private
|
||||
|
||||
def root_must_be_public
|
||||
if self.root.nil? || !self.root.public
|
||||
errors[:base] << "you must reshare public posts"
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
1
app/views/reshares/create.js.erb
Normal file
1
app/views/reshares/create.js.erb
Normal file
|
|
@ -0,0 +1 @@
|
|||
$('.stream_element[data-guid=<%=params[:root_id]%>]').addClass('reshared');
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
-# the COPYRIGHT file.
|
||||
|
||||
|
||||
= render :partial => 'shared/stream_element',
|
||||
= render :partial => 'shared/stream_element_shim',
|
||||
:collection => posts,
|
||||
:as => :post,
|
||||
:locals => { :commenting_disabled => defined?(@commenting_disabled)}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,18 @@
|
|||
|
||||
.stream_element{:id => post.guid}
|
||||
- if current_user && post.author.owner_id == current_user.id
|
||||
- if reshare
|
||||
.reshare_attribution
|
||||
= "reshared by #{reshare.author.name}"
|
||||
.right.controls
|
||||
= link_to image_tag('deletelabel.png'), post_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete stream_element_delete", :title => t('delete')
|
||||
|
||||
- else
|
||||
.right.controls
|
||||
= link_to image_tag('deletelabel.png'), post_visibility_path(:id => "42", :post_id => post.id), :method => :put, :remote => true, :class => "delete stream_element_delete", :title => t('hide')
|
||||
.right
|
||||
- if reshare
|
||||
.reshare_attribution= "reshared by #{reshare.author.name}"
|
||||
.controls
|
||||
= link_to image_tag('deletelabel.png'), post_visibility_path(:id => "42", :post_id => post.id), :method => :put, :remote => true, :class => "delete stream_element_delete", :title => t('hide')
|
||||
.undo_text.hidden
|
||||
= t('post_visibilites.update.post_hidden', :name => post.author.name)
|
||||
= link_to t('undo'), post_visibility_path(:id => "42", :post_id => post.id), :method => :put, :remote => true, :class => "delete stream_element_delete"
|
||||
|
|
|
|||
5
app/views/shared/_stream_element_shim.haml
Normal file
5
app/views/shared/_stream_element_shim.haml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
|
||||
-if post.model.is_a?(Reshare)
|
||||
= render 'shared/stream_element', :post => post.root, :all_aspects => all_aspects, :commenting_disabled => commenting_disabled, :reshare => post
|
||||
- else
|
||||
= render 'shared/stream_element', :post => post, :all_aspects => all_aspects, :commenting_disabled => commenting_disabled, :reshare => nil
|
||||
9
db/migrate/20110525213325_add_root_id_to_posts.rb
Normal file
9
db/migrate/20110525213325_add_root_id_to_posts.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
class AddRootIdToPosts < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :posts, :root_id, :integer
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :posts, :root_id
|
||||
end
|
||||
end
|
||||
29
features/repost.feature
Normal file
29
features/repost.feature
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
@javascript
|
||||
Feature: public repost
|
||||
In order to make Diaspora more viral
|
||||
As a User
|
||||
I want to reshare my friends post
|
||||
|
||||
Background:
|
||||
Given a user named "Bob Jones" with email "bob@bob.bob"
|
||||
And a user named "Alice Smith" with email "alice@alice.alice"
|
||||
And a user with email "bob@bob.bob" is connected with "alice@alice.alice"
|
||||
And "bob@bob.bob" has a public post with text "reshare this!"
|
||||
And I sign in as "alice@alice.alice"
|
||||
And I preemptively confirm the alert
|
||||
And I follow "Reshare"
|
||||
And I wait for the ajax to finish
|
||||
|
||||
Scenario: shows up on the profile page
|
||||
Then I should see a ".reshared"
|
||||
And I am on "alice@alice.alice"'s page
|
||||
Then I should see "reshare this!"
|
||||
Then I should see a ".reshared"
|
||||
And I should see "Bob"
|
||||
|
||||
Scenario: shows up on the aspects page
|
||||
Then I should see a ".reshared"
|
||||
And I follow "All Aspects"
|
||||
Then I should see "reshare this!"
|
||||
Then I should see a ".reshared"
|
||||
And I should see "Bob"
|
||||
|
|
@ -376,6 +376,10 @@ ul.as-selections
|
|||
&:hover
|
||||
:text
|
||||
:decoration none
|
||||
.reshare_attribution
|
||||
:font-size smaller
|
||||
.reshared
|
||||
:background-color #eee
|
||||
|
||||
.stream_element
|
||||
:position relative
|
||||
|
|
|
|||
|
|
@ -179,6 +179,12 @@ describe AspectsController do
|
|||
assigns(:posts).models.length.should == 2
|
||||
end
|
||||
|
||||
it "posts include reshares" do
|
||||
reshare = alice.post(:reshare, :public => true, :root_id => Factory(:status_message, :public => true).id, :to => alice.aspects)
|
||||
get :index
|
||||
assigns[:posts].post_fakes.map{|x| x.id}.should include(reshare.id)
|
||||
end
|
||||
|
||||
it "can filter to a single aspect" do
|
||||
get :index, :a_ids => [@alices_aspect_2.id.to_s]
|
||||
assigns(:posts).models.length.should == 1
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ describe PeopleController do
|
|||
end
|
||||
|
||||
it "posts include reshares" do
|
||||
reshare = @user.post(:reshare, :public => true, :root_id => Factory(:status_message, :public => true).id)
|
||||
reshare = @user.post(:reshare, :public => true, :root_id => Factory(:status_message, :public => true).id, :to => alice.aspects)
|
||||
get :show, :id => @user.person.id
|
||||
assigns[:posts].post_fakes.map{|x| x.id}.should include(reshare.id)
|
||||
end
|
||||
|
|
@ -259,7 +259,7 @@ describe PeopleController do
|
|||
end
|
||||
|
||||
it "posts include reshares" do
|
||||
reshare = @user.post(:reshare, :public => true, :root_id => Factory(:status_message, :public => true).id)
|
||||
reshare = @user.post(:reshare, :public => true, :root_id => Factory(:status_message, :public => true).id, :to => alice.aspects)
|
||||
get :show, :id => @user.person.id
|
||||
assigns[:posts].post_fakes.map{|x| x.id}.should include(reshare.id)
|
||||
end
|
||||
|
|
@ -297,7 +297,7 @@ describe PeopleController do
|
|||
end
|
||||
|
||||
it "posts include reshares" do
|
||||
reshare = @user.post(:reshare, :public => true, :root_id => Factory(:status_message, :public => true).id)
|
||||
reshare = @user.post(:reshare, :public => true, :root_id => Factory(:status_message, :public => true).id, :to => alice.aspects)
|
||||
get :show, :id => @user.person.id
|
||||
assigns[:posts].post_fakes.map{|x| x.id}.should include(reshare.id)
|
||||
end
|
||||
|
|
|
|||
38
spec/controllers/reshares_controller_spec.rb
Normal file
38
spec/controllers/reshares_controller_spec.rb
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
require 'spec_helper'
|
||||
describe ResharesController do
|
||||
|
||||
describe '#create' do
|
||||
|
||||
it 'requires authentication' do
|
||||
post :create, :format => :js
|
||||
response.should_not be_success
|
||||
end
|
||||
|
||||
context 'with an authenticated user' do
|
||||
|
||||
before do
|
||||
|
||||
sign_in :user, bob
|
||||
@post_id = Factory(:status_message, :public => true).id
|
||||
@controller.stub(:current_user).and_return(bob)
|
||||
end
|
||||
|
||||
it 'succeeds' do
|
||||
post :create, :format => :js, :root_id => @post_id
|
||||
puts response.code
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it 'creates a reshare' do
|
||||
expect{
|
||||
post :create, :format => :js, :root_id => @post_id
|
||||
}.should change(Reshare, :count).by(1)
|
||||
end
|
||||
|
||||
it 'after save, calls add to streams' do
|
||||
bob.should_receive(:add_to_streams)
|
||||
post :create, :format => :js, :root_id => @post_id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
15
spec/helpers/reshares_helper_spec.rb
Normal file
15
spec/helpers/reshares_helper_spec.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
require 'spec_helper'
|
||||
|
||||
# Specs in this file have access to a helper object that includes
|
||||
# the ResharesHelper. For example:
|
||||
#
|
||||
# describe ResharesHelper do
|
||||
# describe "string concat" do
|
||||
# it "concats two strings with spaces" do
|
||||
# helper.concat_strings("this","that").should == "this that"
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
describe ResharesHelper do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
20
spec/models/reshare_spec.rb
Normal file
20
spec/models/reshare_spec.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Reshare do
|
||||
it 'has a valid Factory' do
|
||||
Factory(:reshare).should be_valid
|
||||
end
|
||||
|
||||
it 'requires root' do
|
||||
reshare = Factory.build(:reshare, :root => nil)
|
||||
reshare.should_not be_valid
|
||||
end
|
||||
|
||||
it 'require public root' do
|
||||
Factory.build(:reshare, :root => Factory.build(:status_message, :public => false)).should_not be_valid
|
||||
end
|
||||
|
||||
it 'forces public' do
|
||||
Factory(:reshare, :public => false).public.should be_true
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue