diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb
index 620fa8e40..3717cd472 100644
--- a/app/controllers/status_messages_controller.rb
+++ b/app/controllers/status_messages_controller.rb
@@ -79,11 +79,8 @@ class StatusMessagesController < ApplicationController
end
respond_to do |format|
- format.js {
- errors = @status_message.errors.full_messages.collect { |msg| msg.gsub(/^Text/, "") }
- render :json =>{:errors => errors}, :status => 422
- }
- format.html {redirect_to :back}
+ format.json { render :nothing, :status => 403 }
+ format.html { redirect_to :back }
end
end
end
diff --git a/app/views/status_messages/create.js.erb b/app/views/status_messages/create.js.erb
deleted file mode 100644
index 7d2d2a0eb..000000000
--- a/app/views/status_messages/create.js.erb
+++ /dev/null
@@ -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%>
diff --git a/app/views/templates/comment_stream.ujs b/app/views/templates/comment_stream.ujs
index ab4158941..20e1a25ec 100644
--- a/app/views/templates/comment_stream.ujs
+++ b/app/views/templates/comment_stream.ujs
@@ -12,19 +12,21 @@
-
+ <% } %>
diff --git a/public/javascripts/app/app.js b/public/javascripts/app/app.js
index 9f7e3b84a..c8d4cc73f 100644
--- a/public/javascripts/app/app.js
+++ b/public/javascripts/app/app.js
@@ -6,7 +6,7 @@ var app = {
user: function(user) {
if(user) { return this._user = user; }
- return this._user;
+ return this._user || {current_user : false};
},
initialize: function() {
diff --git a/public/javascripts/app/views.js b/public/javascripts/app/views.js
index dfa6323f8..e763df952 100644
--- a/public/javascripts/app/views.js
+++ b/public/javascripts/app/views.js
@@ -26,8 +26,10 @@ app.views.Base = Backbone.View.extend({
var self = this;
_.each(this.subviews, function(property, selector){
var view = _.isFunction(self[property]) ? self[property]() : self[property]
- self.$(selector).html(view.render().el)
- view.delegateEvents();
+ if(view) {
+ self.$(selector).html(view.render().el)
+ view.delegateEvents();
+ }
})
return this
diff --git a/public/javascripts/app/views/post_view.js b/public/javascripts/app/views/post_view.js
index 15479fb8e..b5f7be150 100644
--- a/public/javascripts/app/views/post_view.js
+++ b/public/javascripts/app/views/post_view.js
@@ -22,8 +22,16 @@ app.views.Post = app.views.StreamObject.extend({
],
initialize : function() {
- this.feedbackView = new app.views.Feedback({model : this.model});
+ // commentStream view
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;
},
diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb
index c7060bbe2..5141ee383 100644
--- a/spec/controllers/posts_controller_spec.rb
+++ b/spec/controllers/posts_controller_spec.rb
@@ -23,8 +23,6 @@ describe PostsController do
it 'succeeds' do
get :show, "id" => @message.id
response.should be_success
- doc.has_link?('Like').should be_true
- doc.has_link?('Comment').should be_true
end
it 'succeeds on mobile' do
@@ -38,9 +36,8 @@ describe PostsController do
end
it 'marks a corresponding notification as read' do
- alice.comment("comment after me", :post => @message)
- bob.comment("here you go", :post => @message)
- note = Notification.where(:recipient_id => alice.id, :target_id => @message.id).first
+ note = Notification.create(:recipient => alice, :target => @message, :unread => true)
+
lambda{
get :show, :id => @message.id
note.reload
@@ -55,7 +52,6 @@ describe PostsController do
end
context 'user not signed in' do
-
context 'given a public post' do
before :each do
@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
response.body.should == @status.to_diaspora_xml
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
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
Post.should_receive(:where).with(hash_including(:id => @status.id)).and_return(Post)
get :show, :id => @status.id
- response.status= 200
+ response.should be_success
end
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)
get :show, :id => @status.guid
- response.status= 200
- 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
+ response.should be_success
end
end
end
diff --git a/spec/javascripts/app/app-spec.js b/spec/javascripts/app/app_spec.js
similarity index 80%
rename from spec/javascripts/app/app-spec.js
rename to spec/javascripts/app/app_spec.js
index 5f2e3b19a..49d75124a 100644
--- a/spec/javascripts/app/app-spec.js
+++ b/spec/javascripts/app/app_spec.js
@@ -1,7 +1,7 @@
describe("app", function() {
describe("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"});
diff --git a/spec/javascripts/app/collections/stream-spec.js b/spec/javascripts/app/collections/stream_spec.js
similarity index 100%
rename from spec/javascripts/app/collections/stream-spec.js
rename to spec/javascripts/app/collections/stream_spec.js
diff --git a/spec/javascripts/app/models/post-spec.js b/spec/javascripts/app/models/post_spec.js
similarity index 100%
rename from spec/javascripts/app/models/post-spec.js
rename to spec/javascripts/app/models/post_spec.js
diff --git a/spec/javascripts/app/views/feedback_view_spec.js b/spec/javascripts/app/views/feedback_view_spec.js
index b79a75aa2..55b7798f7 100644
--- a/spec/javascripts/app/views/feedback_view_spec.js
+++ b/spec/javascripts/app/views/feedback_view_spec.js
@@ -1,6 +1,6 @@
describe("app.views.Feedback", 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"];
@@ -60,6 +60,10 @@ describe("app.views.Feedback", function(){
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(){
expect(this.link().text()).toContain('Like');
})
diff --git a/spec/javascripts/app/views/post_view_spec.js b/spec/javascripts/app/views/post_view_spec.js
index 68120b351..48922fc65 100644
--- a/spec/javascripts/app/views/post_view_spec.js
+++ b/spec/javascripts/app/views/post_view_spec.js
@@ -11,11 +11,13 @@ describe("app.views.Post", function(){
this.statusMessage = this.collection.models[0];
})
- it("contains a '.like_action' link", function(){
- var view = new app.views.Post({model : this.statusMessage}).render();
- var statusElement = $(view.el);
+ context("user not signed in", function(){
+ it("does not provide a Feedback view", function(){
+ 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(){