cukes passing

This commit is contained in:
Dennis Collinson 2012-02-23 17:23:52 -08:00
parent b38c49883b
commit 9769dfb303
13 changed files with 16 additions and 382 deletions

View file

@ -5,8 +5,6 @@
class PhotosController < ApplicationController
before_filter :authenticate_user!, :except => :show
helper_method :parent, :photo, :additional_photos, :next_photo, :previous_photo, :ownership
respond_to :html, :json
def index
@ -143,22 +141,6 @@ class PhotosController < ApplicationController
end
end
def show
if user_signed_in?
@photo = current_user.find_visible_shareable_by_id(Photo, params[:id])
else
@photo = Photo.where(:id => params[:id], :public => true).first
end
if @photo
respond_with @photo
elsif user_signed_in?
redirect_to :back
else
redirect_to new_user_session_path
end
end
def edit
if @photo = current_user.photos.where(:id => params[:id]).first
respond_with @photo
@ -187,36 +169,6 @@ class PhotosController < ApplicationController
end
end
# helpers
def ownership
@ownership ||= (current_user.present? && current_user.owns?(photo))
end
def parent
@parent ||= StatusMessage.where(:guid => photo.status_message_guid).includes(:photos).first if photo.status_message_guid
@parent ||= photo
end
def photo
@photo ||= current_user.find_visible_shareable_by_id(Photo, params[:id])
end
def additional_photos
if photo.status_message_guid?
@additional_photos ||= photo.status_message.photos
end
end
def next_photo
@next_photo ||= additional_photos[additional_photos.index(photo)+1]
@next_photo ||= additional_photos.first
end
def previous_photo
@previous_photo ||= additional_photos[additional_photos.index(photo)-1]
end
private
def file_handler(params)

View file

@ -9,6 +9,6 @@ class ResharesController < ApplicationController
current_user.dispatch_post(@reshare, :url => post_url(@reshare), :additional_subscribers => @reshare.root.author)
end
render :json => PostPresenter.new(@reshare.root, current_user).to_json, :status => 201
render :json => PostPresenter.new(@reshare, current_user).to_json, :status => 201
end
end

View file

@ -1,63 +0,0 @@
-# Copyright (c) 2010-2011, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
- content_for :head do
= include_javascripts :photos
.span-16.append-4.prepend-4.last
#photo_controls
-if additional_photos && additional_photos.length > 1
.right
=link_to "← #{t('previous')}", previous_photo, :rel => 'prefetch', :id => 'photo_show_left'
\/
=link_to "#{t('next')} →", next_photo, :rel => 'prefetch', :id => 'photo_show_right'
#original_post_info
= render 'shared/author_info', :person => photo.author, :post => photo
#photo_container
#show_photo{:data=>{:guid=>photo.id}}
-if ownership
= image_tag 'ajax-loader.gif', :id => "photo_spinner", :class => "hidden"
= image_tag photo.url(:scaled_full)
-else
= image_tag photo.url(:scaled_full)
#caption
= photo.text
- if ownership
.photo_options{:data=>{:actor=>"#{photo.author.owner.id}", :actor_person => "#{photo.author.id}", :image_url => "#{photo.url(:thumb_large)}"}}
= link_to t('.make_profile_photo'), photo_make_profile_photo_path(photo), :method => :put, :remote => true, :class => 'make_profile_photo'
|
= link_to t('.edit'), '#', :id => "edit_photo_toggle"
%br
%hr
- if photo.status_message
.span-8.last
%p
= markdownify(photo.status_message, :oembed => true)
%span{:style=>'font-size:smaller'}
=link_to t('.collection_permalink'), post_path(photo.status_message)
%br
%br
.span-7.prepend-1
.show_photo_attachments
- for _photo in additional_photos
= link_to (image_tag _photo.url(:thumb_small), :class => 'thumb_small'), photo_path(_photo)
#photo_edit_options
%h4= t('.edit_delete_photo')
- if photo.status_message
%p
= form_for photo, :remote => true do |p|
= p.text_field :text, :value => photo.text
= p.submit t('.update_photo')
%p
= button_to t('.delete_photo'), photo, :confirm => t('are_you_sure'), :method => :delete

View file

@ -1,17 +0,0 @@
-# Copyright (c) 2010-2011, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
#show_content.photo
= image_tag photo.url(:scaled_full)
-if additional_photos && additional_photos.length > 1
#photo_controls
%table
%tr
%td
=link_to "←", previous_photo, :rel => 'prefetch', :class => 'arrow'
%td{:width => '100%'}
%td
=link_to "→", next_photo, :rel => 'prefetch', :class => 'arrow'

View file

@ -20,26 +20,6 @@ Feature: commenting
Then I should see "is that a poodle?" within ".comment"
And I should see "less than a minute ago" within ".comment time"
Scenario: comment on a photo from the photo page
When I sign in as "bob@bob.bob"
And I am on the photo page for "alice@alice.alice"'s post "Look at this dog"
And I wait for the ajax to finish
And I focus the comment field
And I fill in "text" with "hahahah"
And I press "Comment"
Then I should see "hahaha" within ".comment"
And I should see "less than a minute ago" within ".comment time"
Scenario: comment on your own photo from the photo page
When I sign in as "alice@alice.alice"
And I am on the photo page for "alice@alice.alice"'s post "Look at this dog"
And I wait for the ajax to finish
And I focus the comment field
And I fill in "text" with "hahahah"
And I press "Comment"
Then I should see "hahaha" within ".comment"
And I should see "less than a minute ago" within ".comment time"
Scenario: delete a comment
When I sign in as "bob@bob.bob"
And I am on "alice@alice.alice"'s page
@ -73,9 +53,6 @@ Feature: commenting
Then I should see "Look at this dog"
When I follow "less than a minute ago"
Then I should see "Look at this dog"
When I focus the comment field
And I fill in "text" with "I think thats a cat"
And I press "Comment"
And I wait for the ajax to finish
When I am on "alice@alice.alice"'s page
And I make a show page comment "I think thats a cat"
When I go to "alice@alice.alice"'s page
Then I should see "I think thats a cat"

View file

@ -1,64 +0,0 @@
@javascript
Feature: photos
In order to enlighten humanity for the good of society
As a rock star
I want to post pictures of a button
Background:
Given a user with username "bob"
When I sign in as "bob@bob.bob"
And I am on the home page
Scenario: deleting a photo will delete a photo-only post if the photo was the last image
Given I expand the publisher
And I attach the file "spec/fixtures/button.png" to hidden element "file" within "#file-upload"
And I wait for the ajax to finish
And I press "Share"
And I wait for the ajax to finish
When I go to the photo page for "bob@bob.bob"'s latest post
And I follow "edit_photo_toggle"
And I preemptively confirm the alert
And I press "Delete Photo"
And I go to the home page
Then I should not see any posts in my stream
Scenario: deleting a photo will not delete a photo-only post if another photo remains attached
Given I expand the publisher
And I attach the file "spec/fixtures/button.png" to hidden element "file" within "#file-upload"
And I wait for the ajax to finish
And I attach the file "spec/fixtures/button.png" to hidden element "file" within "#file-upload"
And I wait for the ajax to finish
And I press "Share"
And I wait for the ajax to finish
When I go to the photo page for "bob@bob.bob"'s latest post
And I follow "edit_photo_toggle"
And I preemptively confirm the alert
And I press "Delete Photo"
And I wait for the ajax to finish
And I go to the home page
Then I should see 1 posts
Scenario: deleting a photo will not delete its parent post if the parent also contained text
Given I expand the publisher
And I fill in "status_message_fake_text" with "I am eating a yogurt"
And I attach the file "spec/fixtures/button.png" to hidden element "file" within "#file-upload"
And I wait for the ajax to finish
And I press "Share"
And I wait for the ajax to finish
When I go to the photo page for "bob@bob.bob"'s latest post
And I follow "edit_photo_toggle"
And I preemptively confirm the alert
And I press "Delete Photo"
And I wait for the ajax to finish
And I go to the home page
Then I should see 1 posts
And I should see "I am eating a yogurt" within ".stream_element"

View file

@ -10,7 +10,12 @@ Then /^the first comment field should be closed$/ do
find("#main_stream .stream_element .new_comment").should_not be_visible
end
When /^I comment "([^"]*)" on "([^"]*)"$/ do |comment_text, post_text|
comment_on_post(post_text, comment_text)
end
When /^I make a show page comment "([^"]*)"$/ do |comment_text|
find(".label.comment").click
fill_in "new-comment-text", :with => comment_text
click_button :submit
end

View file

@ -27,10 +27,6 @@ module NavigationHelpers
person_path(User.find_by_email($1).person)
when /^my account settings page$/
edit_user_path
when /^the photo page for "([^\"]*)"'s latest post$/
photo_path(User.find_by_email($1).photos.last)
when /^the photo page for "([^\"]*)"'s post "([^\"]*)"$/
post_path(User.find_by_email($1).posts.find_by_text($2))
when /^"(\/.*)"/
$1
else

View file

@ -71,6 +71,7 @@ app.models.Post = Backbone.Model.extend({
self.set(resp.get("post"))
self.trigger('interacted', self)
}});
},
unlike : function() {

View file

@ -1,6 +1,6 @@
app.models.Reshare = app.models.Post.extend({
rootPost : function(){
this._rootPost = this._rootPost || new app.models.Post(this.get("root"))
this._rootPost = this._rootPost || new app.models.Post(this.get("root"));
return this._rootPost
},
@ -10,5 +10,9 @@ app.models.Reshare = app.models.Post.extend({
reshareAuthor : function(){
return this.rootPost().reshareAuthor()
},
parse: function(resp){
return resp.post
}
});

View file

@ -1,6 +1,6 @@
<div id="new-post-comment-container">
<form class="form-inline">
<textarea class="new-comment-text" placeholder="Comment"></textarea>
<textarea class="new-comment-text" id="new-comment-text" placeholder="Comment"></textarea>
<button type="submit" class="btn btn-small">
<i class="icon-comment"></i>
Comment

View file

@ -40,8 +40,6 @@ app.views.Feedback = app.views.Base.extend({
url: this.model.createReshareUrl,
success : function(resp){
app.stream && app.stream.add(reshare);
model.set(resp.get("post"))
model.trigger("interacted")
}
});

View file

@ -90,105 +90,6 @@ describe PhotosController do
end
end
describe '#show' do
context "user's own photo" do
before do
get :show, :id => @alices_photo.id
end
it "succeeds" do
response.should be_success
end
it "assigns the photo" do
assigns[:photo].should == @alices_photo
@controller.ownership.should be_true
end
end
context "private photo user can see" do
it "succeeds" do
get :show, :id => @bobs_photo.id
response.should be_success
end
it "assigns the photo" do
get :show, :id => @bobs_photo.id
assigns[:photo].should == @bobs_photo
@controller.ownership.should be_false
end
it 'succeeds with a like present' do
sm = bob.post(:status_message, :text => 'parent post', :to => 'all')
@bobs_photo.status_message_guid = sm.guid
@bobs_photo.save!
alice.like!(@bobs_photo.status_message)
get :show, :id => @bobs_photo.id
response.should be_success
end
end
context "private photo user cannot see" do
before do
user3 = Factory(:user_with_aspect)
@photo = user3.post(:photo, :user_file => uploaded_photo, :to => user3.aspects.first.id)
end
it "redirects to the referrer" do
request.env["HTTP_REFERER"] = "http://google.com"
get :show, :id => @photo.to_param
response.should redirect_to("http://google.com")
end
it "redirects to the aspects page if there's no referrer" do
request.env.delete("HTTP_REFERER")
get :show, :id => @photo.to_param
response.should redirect_to(root_path)
end
it 'redirects to the sign in page if not logged in' do
controller.stub(:user_signed_in?).and_return(false) #sign_out :user doesn't work
get :show, :id => @photo.to_param
response.should redirect_to new_user_session_path
end
end
context "public photo" do
before do
user3 = Factory(:user_with_aspect)
@photo = user3.post(:photo, :user_file => uploaded_photo, :to => user3.aspects.first.id, :public => true)
end
context "user logged in" do
before do
get :show, :id => @photo.to_param
end
it "succeeds" do
response.should be_success
end
it "assigns the photo" do
assigns[:photo].should == @photo
@controller.ownership.should be_false
end
end
context "not logged in" do
before do
sign_out :user
get :show, :id => @photo.to_param
end
it "succeeds" do
response.should be_success
end
it "assigns the photo" do
assigns[:photo].should == @photo
end
end
end
end
describe '#edit' do
it "succeeds when user owns the photo" do
get :edit, :id => @alices_photo.id
@ -201,7 +102,6 @@ describe PhotosController do
end
end
describe '#destroy' do
it 'let a user delete his message' do
delete :destroy, :id => @alices_photo.id
@ -263,59 +163,4 @@ describe PhotosController do
end
end
describe 'data helpers' do
describe '.ownership' do
it 'is true if current user owns the photo' do
get :show, :id => @alices_photo.id
@controller.ownership.should be_true
end
it 'is true if current user owns the photo' do
get :show, :id => @bobs_photo.id
@controller.ownership.should be_false
end
end
describe 'parent' do
it 'grabs the status message of the photo if a parent exsists' do
sm = alice.post(:status_message, :text => 'yes', :to => alice.aspects.first)
@alices_photo.status_message = sm
@alices_photo.save
get :show, :id => @alices_photo.id
@controller.parent.id.should == sm.id
end
it 'uses the photo if no status_message exsists' do
get :show, :id => @alices_photo.id
@controller.parent.id.should == @alices_photo.id
end
end
describe '.photo' do
it 'returns a visible photo, based on the :id param' do
get :show, :id => @alices_photo.id
@controller.photo.id.should == @alices_photo.id
end
end
describe '.additional_photos' do
it 'finds all of a parent status messages photos' do
sm = alice.post(:status_message, :text => 'yes', :to => alice.aspects.first)
@alices_photo.status_message = sm
@alices_photo.save
get :show, :id => @alices_photo.id
@controller.additional_photos.should include(@alices_photo)
end
end
describe '.next_photo' do
end
describe '.previous_photo' do
end
end
end