diff --git a/app/helpers/stream_helper.rb b/app/helpers/stream_helper.rb index d29f62849..3e239807f 100644 --- a/app/helpers/stream_helper.rb +++ b/app/helpers/stream_helper.rb @@ -3,7 +3,7 @@ # the COPYRIGHT file. module StreamHelper - + GSUB_THIS = "FIUSDHVIUSHDVIUBAIUHAPOIUXJM" def comment_toggle(count) if count == 0 link_to "#{t('comments.new_comment.comment').downcase}", '#', :class => "show_post_comments" @@ -14,4 +14,9 @@ module StreamHelper end end + def new_comment_form(post_id) + @form ||= controller.render_to_string( + :partial => 'comments/new_comment', :locals => {:post_id => GSUB_THIS}) + @form.gsub(GSUB_THIS, post_id.to_s) + end end diff --git a/app/views/comments/_comments.html.haml b/app/views/comments/_comments.html.haml index 73a649060..4a2c8f71c 100644 --- a/app/views/comments/_comments.html.haml +++ b/app/views/comments/_comments.html.haml @@ -10,5 +10,5 @@ -else = render :partial => 'comments/comment', :collection => comment_hashes, :as => :hash %li.comment.show - = render 'comments/new_comment', :post_id => post_id + = new_comment_form(post_id) diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 5d8bdcadc..8ba7e98db 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -53,7 +53,7 @@ describe AspectsController do it 'takes time' do Benchmark.realtime{ get :index - }.should < 3 + }.should < 2 end end end diff --git a/spec/helpers/stream_helper_spec.rb b/spec/helpers/stream_helper_spec.rb new file mode 100644 index 000000000..0b14b7ab3 --- /dev/null +++ b/spec/helpers/stream_helper_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe StreamHelper do + before do + @user = make_user + @aspect = @user.aspects.create(:name => 'aspect') + @post = @user.post(:status_message, :message => "hi", :to => @aspect.id) + end + it 'renders a new comment form' do + new_comment_form(@post.id).should == + @controller.render_to_string(:partial => 'comments/new_comment', :locals => {:post_id => @post.id}) + end + it 'renders it fast the second time' do + new_comment_form(@post.id) + time = Benchmark.realtime{ + new_comment_form(@post.id) + } + (time*1000).should < 1 + end +end