modified app to return a hash if current_user is not present; removed view specs in postsController specs & moved logic to js/jasmine
This commit is contained in:
parent
096efee929
commit
719e265b68
12 changed files with 48 additions and 184 deletions
|
|
@ -79,11 +79,8 @@ class StatusMessagesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js {
|
format.json { render :nothing, :status => 403 }
|
||||||
errors = @status_message.errors.full_messages.collect { |msg| msg.gsub(/^Text/, "") }
|
format.html { redirect_to :back }
|
||||||
render :json =>{:errors => errors}, :status => 422
|
|
||||||
}
|
|
||||||
format.html {redirect_to :back}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
<%= {:html => render(
|
|
||||||
:partial => 'shared/stream_element',
|
|
||||||
:locals => {
|
|
||||||
:post => @status_message,
|
|
||||||
:author => @status_message.author,
|
|
||||||
:photos => @status_message.photos,
|
|
||||||
:comments => [],
|
|
||||||
:all_aspects => current_user.aspects,
|
|
||||||
:reshare => nil
|
|
||||||
}
|
|
||||||
),
|
|
||||||
:post_id => @status_message.guid}.to_json.html_safe%>
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
<ul class="comments"> </ul>
|
<ul class="comments"> </ul>
|
||||||
|
|
||||||
|
<% if(current_user) { %>
|
||||||
<div class="new_comment_form_wrapper <%= comments_count > 0 ? '' : 'hidden' %>">
|
<div class="new_comment_form_wrapper <%= comments_count > 0 ? '' : 'hidden' %>">
|
||||||
<form accept-charset="UTF-8" action="/posts/<%= id %>/comments" class="new_comment" id="new_comment_on_<%= id %>" method="post">
|
<form accept-charset="UTF-8" action="/posts/<%= id %>/comments" class="new_comment" id="new_comment_on_<%= id %>" method="post">
|
||||||
<a href="/people/<%= current_user.id %>">
|
<a href="/people/<%= current_user.id %>">
|
||||||
|
|
@ -27,4 +28,5 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ var app = {
|
||||||
user: function(user) {
|
user: function(user) {
|
||||||
if(user) { return this._user = user; }
|
if(user) { return this._user = user; }
|
||||||
|
|
||||||
return this._user;
|
return this._user || {current_user : false};
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,10 @@ app.views.Base = Backbone.View.extend({
|
||||||
var self = this;
|
var self = this;
|
||||||
_.each(this.subviews, function(property, selector){
|
_.each(this.subviews, function(property, selector){
|
||||||
var view = _.isFunction(self[property]) ? self[property]() : self[property]
|
var view = _.isFunction(self[property]) ? self[property]() : self[property]
|
||||||
|
if(view) {
|
||||||
self.$(selector).html(view.render().el)
|
self.$(selector).html(view.render().el)
|
||||||
view.delegateEvents();
|
view.delegateEvents();
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return this
|
return this
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,16 @@ app.views.Post = app.views.StreamObject.extend({
|
||||||
],
|
],
|
||||||
|
|
||||||
initialize : function() {
|
initialize : function() {
|
||||||
this.feedbackView = new app.views.Feedback({model : this.model});
|
// commentStream view
|
||||||
this.commentStreamView = new app.views.CommentStream({ model : this.model});
|
this.commentStreamView = new app.views.CommentStream({ model : this.model});
|
||||||
|
|
||||||
|
// feedback view
|
||||||
|
if(window.app.user().current_user) {
|
||||||
|
this.feedbackView = new app.views.Feedback({model : this.model});
|
||||||
|
} else {
|
||||||
|
this.feedbackView = null;
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,6 @@ describe PostsController do
|
||||||
it 'succeeds' do
|
it 'succeeds' do
|
||||||
get :show, "id" => @message.id
|
get :show, "id" => @message.id
|
||||||
response.should be_success
|
response.should be_success
|
||||||
doc.has_link?('Like').should be_true
|
|
||||||
doc.has_link?('Comment').should be_true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'succeeds on mobile' do
|
it 'succeeds on mobile' do
|
||||||
|
|
@ -38,9 +36,8 @@ describe PostsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'marks a corresponding notification as read' do
|
it 'marks a corresponding notification as read' do
|
||||||
alice.comment("comment after me", :post => @message)
|
note = Notification.create(:recipient => alice, :target => @message, :unread => true)
|
||||||
bob.comment("here you go", :post => @message)
|
|
||||||
note = Notification.where(:recipient_id => alice.id, :target_id => @message.id).first
|
|
||||||
lambda{
|
lambda{
|
||||||
get :show, :id => @message.id
|
get :show, :id => @message.id
|
||||||
note.reload
|
note.reload
|
||||||
|
|
@ -55,7 +52,6 @@ describe PostsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'user not signed in' do
|
context 'user not signed in' do
|
||||||
|
|
||||||
context 'given a public post' do
|
context 'given a public post' do
|
||||||
before :each do
|
before :each do
|
||||||
@status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all')
|
@status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all')
|
||||||
|
|
@ -76,27 +72,6 @@ describe PostsController do
|
||||||
get :show, :id => @status.guid, :format => :xml
|
get :show, :id => @status.guid, :format => :xml
|
||||||
response.body.should == @status.to_diaspora_xml
|
response.body.should == @status.to_diaspora_xml
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with more than 3 comments' do
|
|
||||||
before do
|
|
||||||
(1..5).each do |i|
|
|
||||||
alice.comment "comment #{i}", :post => @status
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'shows all comments of a public post' do
|
|
||||||
get :show, :id => @status.id
|
|
||||||
|
|
||||||
response.body.should =~ /comment 3/
|
|
||||||
response.body.should_not =~ /comment 2/
|
|
||||||
|
|
||||||
get :show, :id => @status.id, 'all_comments' => '1'
|
|
||||||
|
|
||||||
response.body.should =~ /comment 3/
|
|
||||||
response.body.should =~ /comment 2/
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not show a private post' do
|
it 'does not show a private post' do
|
||||||
|
|
@ -116,127 +91,13 @@ describe PostsController do
|
||||||
it 'assumes guids less than 8 chars are ids and not guids' do
|
it 'assumes guids less than 8 chars are ids and not guids' do
|
||||||
Post.should_receive(:where).with(hash_including(:id => @status.id)).and_return(Post)
|
Post.should_receive(:where).with(hash_including(:id => @status.id)).and_return(Post)
|
||||||
get :show, :id => @status.id
|
get :show, :id => @status.id
|
||||||
response.status= 200
|
response.should be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'assumes guids more than (or equal to) 8 chars are actually guids' do
|
it 'assumes guids more than (or equal to) 8 chars are actually guids' do
|
||||||
Post.should_receive(:where).with(hash_including(:guid => @status.guid)).and_return(Post)
|
Post.should_receive(:where).with(hash_including(:guid => @status.guid)).and_return(Post)
|
||||||
get :show, :id => @status.guid
|
get :show, :id => @status.guid
|
||||||
response.status= 200
|
response.should be_success
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when a post is public' do
|
|
||||||
before do
|
|
||||||
@post = alice.post( :status_message, :public => true, :to => alice.aspects, :text => 'abc 123' )
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'and visitor is not signed in' do
|
|
||||||
it 'does not show social links' do
|
|
||||||
get :show, 'id' => @post.id
|
|
||||||
|
|
||||||
doc.has_content?('abc 123').should be_true
|
|
||||||
doc.has_link?('Like').should be_false
|
|
||||||
doc.has_link?('Comment').should be_false
|
|
||||||
doc.has_link?('Reshare').should be_false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'and signed in as poster' do
|
|
||||||
before do
|
|
||||||
sign_in alice
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not show a reshare link' do
|
|
||||||
get :show, 'id' => @post.id
|
|
||||||
|
|
||||||
doc.has_content?('abc 123').should be_true
|
|
||||||
doc.has_link?('Like').should be_true
|
|
||||||
doc.has_link?('Comment').should be_true
|
|
||||||
doc.has_link?('Reshare').should be_false
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'a reshare of the post' do
|
|
||||||
before do
|
|
||||||
@reshare = bob.post( :reshare, :public => true, :root_guid => @post.guid, :to => bob.aspects )
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not show a reshare link' do
|
|
||||||
get :show, 'id' => @reshare.id
|
|
||||||
|
|
||||||
doc.has_content?('abc 123').should be_true
|
|
||||||
doc.has_link?('Like').should be_true
|
|
||||||
doc.has_link?('Comment').should be_true
|
|
||||||
doc.has_link?('Reshare').should be_false
|
|
||||||
doc.has_link?('Reshare original').should be_false
|
|
||||||
doc.has_link?('1 reshare').should be_false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'and signed in as someone other than the poster' do
|
|
||||||
before do
|
|
||||||
sign_in bob
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'shows reshare link' do
|
|
||||||
get :show, 'id' => @post.id
|
|
||||||
|
|
||||||
doc.has_content?('abc 123').should be_true
|
|
||||||
doc.has_link?('Like').should be_true
|
|
||||||
doc.has_link?('Comment').should be_true
|
|
||||||
doc.has_link?('Reshare').should be_true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'and signed in as the resharer of the post' do
|
|
||||||
context 'a reshare of the post' do
|
|
||||||
before do
|
|
||||||
@reshare = bob.post( :reshare, :public => true, :root_guid => @post.guid, :to => bob.aspects )
|
|
||||||
# Don't know why this is needed, but this spec fails without it
|
|
||||||
sign_in bob
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not show any reshare link' do
|
|
||||||
get :show, 'id' => @reshare.id
|
|
||||||
|
|
||||||
doc.has_content?('abc 123').should be_true
|
|
||||||
doc.has_link?('Like').should be_true
|
|
||||||
doc.has_link?('Comment').should be_true
|
|
||||||
doc.has_link?('1 reshare').should be_false
|
|
||||||
doc.has_link?('Reshare').should be_false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'and signed in as neither the poster nor the resharer of the post' do
|
|
||||||
before do
|
|
||||||
sign_in eve
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'shows reshare link' do
|
|
||||||
get :show, 'id' => @post.id
|
|
||||||
|
|
||||||
doc.has_content?('abc 123').should be_true
|
|
||||||
doc.has_link?('Like').should be_true
|
|
||||||
doc.has_link?('Comment').should be_true
|
|
||||||
doc.has_link?('Reshare').should be_true
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'a reshare of the post' do
|
|
||||||
before do
|
|
||||||
@reshare = bob.post( :reshare, :public => true, :root_guid => @post.guid, :to => bob.aspects )
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'shows a reshare link' do
|
|
||||||
get :show, 'id' => @reshare.id
|
|
||||||
|
|
||||||
doc.has_content?('abc 123').should be_true
|
|
||||||
doc.has_link?('Like').should be_true
|
|
||||||
doc.has_link?('Comment').should be_true
|
|
||||||
doc.has_link?('Reshare original').should be_true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
describe("app", function() {
|
describe("app", function() {
|
||||||
describe("user", function() {
|
describe("user", function() {
|
||||||
it("sets the user if given one and returns the current user", function() {
|
it("sets the user if given one and returns the current user", function() {
|
||||||
expect(app.user()).toBeUndefined();
|
expect(app.user()).toEqual({current_user : false});
|
||||||
|
|
||||||
app.user({name: "alice"});
|
app.user({name: "alice"});
|
||||||
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
describe("app.views.Feedback", function(){
|
describe("app.views.Feedback", function(){
|
||||||
beforeEach(function(){
|
beforeEach(function(){
|
||||||
window.current_user = app.user({id : 1, name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
|
window.current_user = app.user({id : -1, name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
|
||||||
|
|
||||||
var posts = $.parseJSON(spec.readFixture("multi_stream_json"))["posts"];
|
var posts = $.parseJSON(spec.readFixture("multi_stream_json"))["posts"];
|
||||||
|
|
||||||
|
|
@ -60,6 +60,10 @@ describe("app.views.Feedback", function(){
|
||||||
this.view.render();
|
this.view.render();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("contains a .like_action", function(){
|
||||||
|
expect($(this.view.el).html()).toContain("like_action");
|
||||||
|
})
|
||||||
|
|
||||||
it("the like action should be 'Like'", function(){
|
it("the like action should be 'Like'", function(){
|
||||||
expect(this.link().text()).toContain('Like');
|
expect(this.link().text()).toContain('Like');
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,13 @@ describe("app.views.Post", function(){
|
||||||
this.statusMessage = this.collection.models[0];
|
this.statusMessage = this.collection.models[0];
|
||||||
})
|
})
|
||||||
|
|
||||||
it("contains a '.like_action' link", function(){
|
context("user not signed in", function(){
|
||||||
var view = new app.views.Post({model : this.statusMessage}).render();
|
it("does not provide a Feedback view", function(){
|
||||||
var statusElement = $(view.el);
|
window.current_user = app.user(null);
|
||||||
|
|
||||||
expect(statusElement.find(".like_action").html()).not.toBeNull();
|
var view = new app.views.Post({model : this.statusMessage}).render();
|
||||||
|
expect(view.feedbackView).toBeNull();
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
context("NSFW", function(){
|
context("NSFW", function(){
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue