Fix StatusMessagesController. Refactor specs to take out stuff that's tested elsewhere. MOAR REFAKTRNG PLZ. Is ugly.
This commit is contained in:
parent
3d7d8b51d2
commit
787d550a1f
3 changed files with 28 additions and 43 deletions
|
|
@ -9,9 +9,8 @@ class StatusMessagesController < ApplicationController
|
||||||
respond_to :json, :only => :show
|
respond_to :json, :only => :show
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|
||||||
if params[:status_message][:aspect_ids] == "all"
|
if params[:status_message][:aspect_ids] == "all"
|
||||||
params[:status_message][:aspect_ids] = current_user.aspects.collect{|x| x.id}
|
params[:status_message][:aspect_ids] = current_user.aspects.collect { |x| x.id }
|
||||||
end
|
end
|
||||||
|
|
||||||
photos = Photo.where(:id => [*params[:photos]], :diaspora_handle => current_user.person.diaspora_handle)
|
photos = Photo.where(:id => [*params[:photos]], :diaspora_handle => current_user.person.diaspora_handle)
|
||||||
|
|
@ -19,29 +18,25 @@ class StatusMessagesController < ApplicationController
|
||||||
public_flag = params[:status_message][:public]
|
public_flag = params[:status_message][:public]
|
||||||
public_flag.to_s.match(/(true)/) ? public_flag = true : public_flag = false
|
public_flag.to_s.match(/(true)/) ? public_flag = true : public_flag = false
|
||||||
params[:status_message][:public] = public_flag
|
params[:status_message][:public] = public_flag
|
||||||
|
|
||||||
@status_message = current_user.build_post(:status_message, params[:status_message])
|
@status_message = current_user.build_post(:status_message, params[:status_message])
|
||||||
|
|
||||||
|
if @status_message.save
|
||||||
if !photos.empty? || @status_message.save
|
|
||||||
pp photos
|
|
||||||
pp @status_message
|
|
||||||
raise 'MongoMapper failed to catch a failed save' unless @status_message.id
|
|
||||||
|
|
||||||
@status_message.photos += photos unless photos.nil?
|
|
||||||
current_user.add_to_streams(@status_message, params[:status_message][:aspect_ids])
|
current_user.add_to_streams(@status_message, params[:status_message][:aspect_ids])
|
||||||
current_user.dispatch_post(@status_message,
|
current_user.dispatch_post(@status_message,
|
||||||
:to => params[:status_message][:aspect_ids],
|
:to => params[:status_message][:aspect_ids],
|
||||||
:url => post_url(@status_message))
|
:url => post_url(@status_message))
|
||||||
|
if !photos.empty?
|
||||||
for photo in photos
|
@status_message.photos += photos
|
||||||
photo.public = public_flag
|
for photo in photos
|
||||||
photo.save
|
photo.public = public_flag
|
||||||
current_user.add_to_streams(photo, params[:status_message][:aspect_ids])
|
photo.save
|
||||||
current_user.dispatch_post(photo, :to => params[:status_message][:aspect_ids])
|
current_user.add_to_streams(photo, params[:status_message][:aspect_ids])
|
||||||
|
current_user.dispatch_post(photo, :to => params[:status_message][:aspect_ids])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js{ render :json => { :post_id => @status_message.id,
|
format.js { render :json => {:post_id => @status_message.id,
|
||||||
:html => render_to_string(
|
:html => render_to_string(
|
||||||
:partial => 'shared/stream_element',
|
:partial => 'shared/stream_element',
|
||||||
:locals => {
|
:locals => {
|
||||||
|
|
@ -51,21 +46,21 @@ class StatusMessagesController < ApplicationController
|
||||||
:comments => [],
|
:comments => [],
|
||||||
:aspects => current_user.aspects,
|
:aspects => current_user.aspects,
|
||||||
:current_user => current_user
|
:current_user => current_user
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
:status => 201 }
|
:status => 201 }
|
||||||
format.html{ respond_with @status_message }
|
format.html { respond_with @status_message }
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js{ render :status => 406 }
|
format.js { render :status => 406 }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@status_message = current_user.posts.where(:id => params[:id]).first
|
@status_message = current_user.posts.where(:id => params[:id]).first
|
||||||
if @status_message
|
if @status_message
|
||||||
@status_message.destroy
|
@status_message.destroy
|
||||||
render :nothing => true, :status => 200
|
render :nothing => true, :status => 200
|
||||||
|
|
@ -81,9 +76,10 @@ class StatusMessagesController < ApplicationController
|
||||||
person_hash = Person.from_post_comment_hash comments_hash
|
person_hash = Person.from_post_comment_hash comments_hash
|
||||||
@comment_hashes = comments_hash[@status_message.id].map do |comment|
|
@comment_hashes = comments_hash[@status_message.id].map do |comment|
|
||||||
{:comment => comment,
|
{:comment => comment,
|
||||||
:person => person_hash[comment.person_id]
|
:person => person_hash[comment.person_id]
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
respond_with @status_message
|
respond_with @status_message
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -21,31 +21,17 @@ describe StatusMessagesController do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#show' do
|
describe '#show' do
|
||||||
before do
|
it 'succeeds' do
|
||||||
@video_id = "ABYnqp-bxvg"
|
message = user1.build_post :status_message, :message => "ohai", :to => aspect1.id
|
||||||
@url="http://www.youtube.com/watch?v=#{@video_id}&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1"
|
|
||||||
end
|
|
||||||
it 'renders posts with youtube urls' do
|
|
||||||
message = user1.build_post :status_message, :message => @url, :to => aspect1.id
|
|
||||||
message[:youtube_titles]= {@video_id => "title"}
|
|
||||||
message.save!
|
message.save!
|
||||||
user1.add_to_streams(message, aspect1.id)
|
user1.add_to_streams(message, aspect1.id)
|
||||||
user1.dispatch_post message, :to => aspect1.id
|
user1.dispatch_post message, :to => aspect1.id
|
||||||
|
|
||||||
get :show, :id => message.id
|
get :show, "id" => message.id.to_s
|
||||||
response.body.should match /Youtube: title/
|
response.should be_success
|
||||||
end
|
|
||||||
it 'renders posts with comments with youtube urls' do
|
|
||||||
message = user1.post :status_message, :message => "Respond to this with a video!", :to => aspect1.id
|
|
||||||
@comment = user1.comment "none", :on => message
|
|
||||||
@comment.text = @url
|
|
||||||
@comment[:youtube_titles][@video_id] = "title"
|
|
||||||
@comment.save!
|
|
||||||
|
|
||||||
get :show, :id => message.id
|
|
||||||
response.body.should match /Youtube: title/
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#create' do
|
describe '#create' do
|
||||||
let(:status_message_hash) {
|
let(:status_message_hash) {
|
||||||
{ :status_message => {
|
{ :status_message => {
|
||||||
|
|
@ -90,6 +76,7 @@ describe StatusMessagesController do
|
||||||
post :create, hash
|
post :create, hash
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#destroy' do
|
describe '#destroy' do
|
||||||
let!(:message) {user1.post(:status_message, :message => "hey", :to => aspect1.id)}
|
let!(:message) {user1.post(:status_message, :message => "hey", :to => aspect1.id)}
|
||||||
let!(:message2) {user2.post(:status_message, :message => "hey", :to => aspect2.id)}
|
let!(:message2) {user2.post(:status_message, :message => "hey", :to => aspect2.id)}
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,7 @@ describe ApplicationHelper do
|
||||||
video_id = "0x__dDWdf23"
|
video_id = "0x__dDWdf23"
|
||||||
url = "http://www.youtube.com/watch?v=" + video_id + "&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1"
|
url = "http://www.youtube.com/watch?v=" + video_id + "&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1"
|
||||||
res = markdownify(url)
|
res = markdownify(url)
|
||||||
|
res.should =~ /Youtube:/
|
||||||
res.should =~ /data-host="youtube.com"/
|
res.should =~ /data-host="youtube.com"/
|
||||||
res.should =~ /data-video-id="#{video_id}"/
|
res.should =~ /data-video-id="#{video_id}"/
|
||||||
end
|
end
|
||||||
|
|
@ -101,6 +102,7 @@ describe ApplicationHelper do
|
||||||
video_id = "ABYnqp-bxvg"
|
video_id = "ABYnqp-bxvg"
|
||||||
url = "http://www.youtube.com/watch?v=" + video_id + "&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1"
|
url = "http://www.youtube.com/watch?v=" + video_id + "&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1"
|
||||||
res = markdownify(url)
|
res = markdownify(url)
|
||||||
|
res.should =~ /Youtube:/
|
||||||
res.should =~ /data-host="youtube.com"/
|
res.should =~ /data-host="youtube.com"/
|
||||||
res.should =~ /data-video-id="#{video_id}"/
|
res.should =~ /data-video-id="#{video_id}"/
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue