Commit c7fd10d42a374e0601e4f052ca4768b650e95f42
Exists in
staging
and in
1 other branch
merge with master
Showing
14 changed files
with
215 additions
and
204 deletions
Show diff stats
app/api/v1/boxes.rb
... | ... | @@ -13,7 +13,7 @@ module Api |
13 | 13 | get do |
14 | 14 | profile = environment.send(kind.pluralize).find(params["#{kind}_id"]) |
15 | 15 | return forbidden! unless profile.display_info_to?(current_person) |
16 | - present profile.boxes, :with => Entities::Box | |
16 | + present profile.boxes, with: Entities::Box, current_person: current_person | |
17 | 17 | end |
18 | 18 | end |
19 | 19 | end |
... | ... | @@ -33,7 +33,7 @@ module Api |
33 | 33 | else |
34 | 34 | env = Environment.find(params[:environment_id]) |
35 | 35 | end |
36 | - present env.boxes, :with => Entities::Box | |
36 | + present env.boxes, with: Entities::Box, current_person: current_person | |
37 | 37 | end |
38 | 38 | end |
39 | 39 | end | ... | ... |
app/helpers/boxes_helper.rb
... | ... | @@ -99,15 +99,10 @@ module BoxesHelper |
99 | 99 | end |
100 | 100 | |
101 | 101 | def render_block_content block |
102 | - # FIXME: this conditional should be removed after all | |
103 | - # block footer from plugins methods get refactored into helpers and views. | |
104 | - # They are a failsafe until all of them are done. | |
105 | - return block.content if block.method(:content).owner != Block | |
106 | 102 | render_block block |
107 | 103 | end |
108 | 104 | |
109 | 105 | def render_block_footer block |
110 | - return block.footer if block.method(:footer).owner != Block | |
111 | 106 | render_block block, 'footers/' |
112 | 107 | end |
113 | 108 | ... | ... |
app/models/block.rb
... | ... | @@ -181,30 +181,6 @@ class Block < ApplicationRecord |
181 | 181 | "/images/block_preview.png" |
182 | 182 | end |
183 | 183 | |
184 | - # Returns the content to be used for this block. | |
185 | - # | |
186 | - # This method can return several types of objects: | |
187 | - # | |
188 | - # * <tt>String</tt>: if the string starts with <tt>http://</tt> or <tt>https://</tt>, then it is assumed to be address of an IFRAME. Otherwise it's is used as regular HTML. | |
189 | - # * <tt>Hash</tt>: the hash is used to build an URL that is used as the address for a IFRAME. | |
190 | - # * <tt>Proc</tt>: the Proc is evaluated in the scope of BoxesHelper. The | |
191 | - # block can then use <tt>render</tt>, <tt>link_to</tt>, etc. | |
192 | - # | |
193 | - # The method can also return <tt>nil</tt>, which means "no content". | |
194 | - # | |
195 | - # See BoxesHelper#extract_block_content for implementation details. | |
196 | - def content(args={}) | |
197 | - "This is block number %d" % self.id | |
198 | - end | |
199 | - | |
200 | - # A footer to be appended to the end of the block. Returns <tt>nil</tt>. | |
201 | - # | |
202 | - # Override in your subclasses. You can return the same types supported by | |
203 | - # #content. | |
204 | - def footer | |
205 | - nil | |
206 | - end | |
207 | - | |
208 | 184 | # Is this block editable? (Default to <tt>true</tt>) |
209 | 185 | def editable?(user=nil) |
210 | 186 | self.edit_modes == "all" | ... | ... |
plugins/display_content/lib/display_content_block.rb
... | ... | @@ -118,69 +118,28 @@ class DisplayContentBlock < Block |
118 | 118 | holder.articles.where(type: types, parent_id: if parent.nil? then nil else parent end) |
119 | 119 | end |
120 | 120 | |
121 | - def content(args={}) | |
122 | - block = self | |
123 | - | |
121 | + def docs | |
124 | 122 | order_string = "published_at" |
125 | 123 | order_string += " DESC" if order_by_recent |
126 | 124 | |
127 | 125 | limit_final = [limit_to_show, 0].max |
128 | 126 | |
129 | - docs = owner.articles.order(order_string) | |
127 | + documents = owner.articles.order(order_string) | |
130 | 128 | .where(articles: {type: self.types}) |
131 | 129 | .includes(:profile, :image, :tags) |
132 | 130 | if nodes.present? |
133 | 131 | nodes_conditions = 'articles.id IN(:nodes)' |
134 | 132 | nodes_conditions << ' OR articles.parent_id IN(:nodes) ' if display_folder_children |
135 | - docs = docs.where nodes_conditions, nodes: nodes | |
133 | + documents = documents.where nodes_conditions, nodes: nodes | |
136 | 134 | end |
137 | - docs = docs.limit limit_final if display_folder_children | |
135 | + documents = documents.limit limit_final if display_folder_children | |
138 | 136 | |
139 | 137 | if content_with_translations |
140 | - docs = docs.native_translations | |
141 | - docs.replace docs.map{ |p| p.get_translation_to(FastGettext.locale) }.compact | |
138 | + documents = documents.native_translations | |
139 | + documents.replace documents.map{ |p| p.get_translation_to(FastGettext.locale) }.compact | |
142 | 140 | end |
143 | 141 | |
144 | - proc do | |
145 | - block.block_title(block.title, block.subtitle) + | |
146 | - content_tag('ul', docs.map {|item| | |
147 | - if !item.folder? && item.class != RssFeed | |
148 | - content_sections = '' | |
149 | - read_more_section = '' | |
150 | - tags_section = '' | |
151 | - | |
152 | - block.sections.select { |section| | |
153 | - case section[:value] | |
154 | - when 'publish_date' | |
155 | - content_sections += (block.display_section?(section) ? (content_tag('div', show_date(item.published_at, false), :class => 'published-at') ) : '') | |
156 | - when 'title' | |
157 | - content_sections += (block.display_section?(section) ? (content_tag('div', link_to(h(item.title), item.url), :class => 'title') ) : '') | |
158 | - when 'abstract' | |
159 | - content_sections += (block.display_section?(section) ? (content_tag('div', (item.abstract || "").html_safe, :class => 'lead')) : '' ) | |
160 | - if block.display_section?(section) | |
161 | - read_more_section = content_tag('div', link_to(_('Read more'), item.url), :class => 'read_more') | |
162 | - end | |
163 | - when 'body' | |
164 | - content_sections += (block.display_section?(section) ? (content_tag('div', item.body.html_safe ,:class => 'body')) : '' ) | |
165 | - when 'image' | |
166 | - image_section = image_tag item.image.public_filename if item.image | |
167 | - if !image_section.blank? | |
168 | - content_sections += (block.display_section?(section) ? (content_tag('div', link_to( image_section, item.url ) ,:class => 'image')) : '' ) | |
169 | - end | |
170 | - when 'tags' | |
171 | - if !item.tags.empty? | |
172 | - tags_section = item.tags.map { |t| content_tag('span', t.name) }.join("") | |
173 | - content_sections += (block.display_section?(section) ? (content_tag('div', tags_section, :class => 'tags')) : '') | |
174 | - end | |
175 | - end | |
176 | - } | |
177 | - | |
178 | - content_sections += read_more_section if !read_more_section.blank? | |
179 | -#raise sections.inspect | |
180 | - content_tag('li', content_sections.html_safe) | |
181 | - end | |
182 | - }.join(" ").html_safe) | |
183 | - end | |
142 | + documents | |
184 | 143 | end |
185 | 144 | |
186 | 145 | def url_params | ... | ... |
plugins/display_content/test/unit/display_content_block_test.rb
... | ... | @@ -347,53 +347,6 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
347 | 347 | |
348 | 348 | end |
349 | 349 | |
350 | - should 'list links for all articles title defined in nodes' do | |
351 | - profile = create_user('testuser').person | |
352 | - Article.delete_all | |
353 | - a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id) | |
354 | - a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id) | |
355 | - | |
356 | - block = DisplayContentBlock.new | |
357 | - block.sections = [{:value => 'title', :checked => true}] | |
358 | - block.nodes = [a1.id, a2.id] | |
359 | - box = mock() | |
360 | - block.stubs(:box).returns(box) | |
361 | - box.stubs(:owner).returns(profile) | |
362 | - | |
363 | - assert_match /.*<a.*>#{a1.title}<\/a>/, instance_eval(&block.content) | |
364 | - assert_match /.*<a.*>#{a2.title}<\/a>/, instance_eval(&block.content) | |
365 | - end | |
366 | - | |
367 | - should 'list content for all articles lead defined in nodes' do | |
368 | - profile = create_user('testuser').person | |
369 | - Article.delete_all | |
370 | - a1 = fast_create(TinyMceArticle, :name => 'test article 1', :profile_id => profile.id, :abstract => 'abstract article 1') | |
371 | - a2 = fast_create(TinyMceArticle, :name => 'test article 2', :profile_id => profile.id, :abstract => 'abstract article 2') | |
372 | - | |
373 | - block = DisplayContentBlock.new | |
374 | - block.sections = [{:value => 'abstract', :checked => true}] | |
375 | - block.nodes = [a1.id, a2.id] | |
376 | - box = mock() | |
377 | - block.stubs(:box).returns(box) | |
378 | - box.stubs(:owner).returns(profile) | |
379 | - | |
380 | - assert_match /<div class="lead">#{a1.lead}<\/div>/, instance_eval(&block.content) | |
381 | - assert_match /<div class="lead">#{a2.lead}<\/div>/, instance_eval(&block.content) | |
382 | - end | |
383 | - | |
384 | - should 'not crash when referenced article is removed' do | |
385 | - profile = create_user('testuser').person | |
386 | - a1 = fast_create(TextArticle, :name => 'test article 1', :profile_id => profile.id) | |
387 | - | |
388 | - block = DisplayContentBlock.new | |
389 | - block.nodes = [a1.id] | |
390 | - box = mock() | |
391 | - block.stubs(:box).returns(box) | |
392 | - box.stubs(:owner).returns(profile) | |
393 | - | |
394 | - Article.delete_all | |
395 | - assert_match /<ul><\/ul>/, instance_eval(&block.content) | |
396 | - end | |
397 | 350 | include ActionView::Helpers |
398 | 351 | include Rails.application.routes.url_helpers |
399 | 352 | |
... | ... | @@ -420,48 +373,6 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
420 | 373 | assert_equal params, block.url_params |
421 | 374 | end |
422 | 375 | |
423 | - should 'show title if defined by user' do | |
424 | - profile = create_user('testuser').person | |
425 | - a = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id) | |
426 | - | |
427 | - block = DisplayContentBlock.new | |
428 | - block.nodes = [a.id] | |
429 | - block.sections = [{:value => 'title', :checked => true}] | |
430 | - box = mock() | |
431 | - block.stubs(:box).returns(box) | |
432 | - box.stubs(:owner).returns(profile) | |
433 | - | |
434 | - assert_match /.*<a.*>#{a.title}<\/a>/, instance_eval(&block.content) | |
435 | - end | |
436 | - | |
437 | - should 'show abstract if defined by user' do | |
438 | - profile = create_user('testuser').person | |
439 | - a = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :abstract => 'some abstract') | |
440 | - | |
441 | - block = DisplayContentBlock.new | |
442 | - block.nodes = [a.id] | |
443 | - block.sections = [{:value => 'abstract', :checked => true}] | |
444 | - box = mock() | |
445 | - block.stubs(:box).returns(box) | |
446 | - box.stubs(:owner).returns(profile) | |
447 | - | |
448 | - assert_match /#{a.abstract}/, instance_eval(&block.content) | |
449 | - end | |
450 | - | |
451 | - should 'show body if defined by user' do | |
452 | - profile = create_user('testuser').person | |
453 | - a = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :body => 'some body') | |
454 | - | |
455 | - block = DisplayContentBlock.new | |
456 | - block.nodes = [a.id] | |
457 | - block.sections = [{:value => 'body', :checked => true}] | |
458 | - box = mock() | |
459 | - block.stubs(:box).returns(box) | |
460 | - box.stubs(:owner).returns(profile) | |
461 | - | |
462 | - assert_match /#{a.body}/, instance_eval(&block.content) | |
463 | - end | |
464 | - | |
465 | 376 | should 'display_attribute be true for title by default' do |
466 | 377 | profile = create_user('testuser').person |
467 | 378 | |
... | ... | @@ -489,20 +400,6 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
489 | 400 | assert block.display_section?({:value => 'publish_date', :checked => true}) |
490 | 401 | end |
491 | 402 | |
492 | - should 'show publishd date if defined by user' do | |
493 | - profile = create_user('testuser').person | |
494 | - a = fast_create(TextArticle, :name => 'test article 1', :profile_id => profile.id, :body => 'some body') | |
495 | - | |
496 | - block = DisplayContentBlock.new | |
497 | - block.nodes = [a.id] | |
498 | - block.sections = [{:value => 'publish_date', :checked => true}] | |
499 | - box = mock() | |
500 | - block.stubs(:box).returns(box) | |
501 | - box.stubs(:owner).returns(profile) | |
502 | - | |
503 | - assert_match /#{a.published_at}/, instance_eval(&block.content) | |
504 | - end | |
505 | - | |
506 | 403 | should 'do not save children if a folder is checked' do |
507 | 404 | profile = create_user('testuser').person |
508 | 405 | Article.delete_all |
... | ... | @@ -648,6 +545,117 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
648 | 545 | assert_equal [], block.parent_nodes |
649 | 546 | end |
650 | 547 | |
548 | +end | |
549 | + | |
550 | +require 'boxes_helper' | |
551 | + | |
552 | +class DisplayContentBlockViewTest < ActionView::TestCase | |
553 | + include BoxesHelper | |
554 | + | |
555 | + should 'list links for all articles title defined in nodes' do | |
556 | + profile = create_user('testuser').person | |
557 | + Article.delete_all | |
558 | + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id) | |
559 | + a2 = fast_create(TextileArticle, :name => 'test article 2', :profile_id => profile.id) | |
560 | + | |
561 | + block = DisplayContentBlock.new | |
562 | + block.sections = [{:value => 'title', :checked => true}] | |
563 | + block.nodes = [a1.id, a2.id] | |
564 | + box = mock() | |
565 | + block.stubs(:box).returns(box) | |
566 | + box.stubs(:owner).returns(profile) | |
567 | + | |
568 | + assert_match /.*<a.*>#{a1.title}<\/a>/, render_block_content(block) | |
569 | + assert_match /.*<a.*>#{a2.title}<\/a>/, render_block_content(block) | |
570 | + end | |
571 | + | |
572 | + should 'list content for all articles lead defined in nodes' do | |
573 | + profile = create_user('testuser').person | |
574 | + Article.delete_all | |
575 | + a1 = fast_create(TinyMceArticle, :name => 'test article 1', :profile_id => profile.id, :abstract => 'abstract article 1') | |
576 | + a2 = fast_create(TinyMceArticle, :name => 'test article 2', :profile_id => profile.id, :abstract => 'abstract article 2') | |
577 | + | |
578 | + block = DisplayContentBlock.new | |
579 | + block.sections = [{:value => 'abstract', :checked => true}] | |
580 | + block.nodes = [a1.id, a2.id] | |
581 | + box = mock() | |
582 | + block.stubs(:box).returns(box) | |
583 | + box.stubs(:owner).returns(profile) | |
584 | + | |
585 | + assert_match /<div class="lead">#{a1.lead}<\/div>/, render_block_content(block) | |
586 | + assert_match /<div class="lead">#{a2.lead}<\/div>/, render_block_content(block) | |
587 | + end | |
588 | + | |
589 | + should 'not crash when referenced article is removed' do | |
590 | + profile = create_user('testuser').person | |
591 | + a1 = fast_create(TextArticle, :name => 'test article 1', :profile_id => profile.id) | |
592 | + | |
593 | + block = DisplayContentBlock.new | |
594 | + block.nodes = [a1.id] | |
595 | + box = mock() | |
596 | + block.stubs(:box).returns(box) | |
597 | + box.stubs(:owner).returns(profile) | |
598 | + | |
599 | + Article.delete_all | |
600 | + assert_match /<ul><\/ul>/, render_block_content(block) | |
601 | + end | |
602 | + | |
603 | + should 'show title if defined by user' do | |
604 | + profile = create_user('testuser').person | |
605 | + a = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id) | |
606 | + | |
607 | + block = DisplayContentBlock.new | |
608 | + block.nodes = [a.id] | |
609 | + block.sections = [{:value => 'title', :checked => true}] | |
610 | + box = mock() | |
611 | + block.stubs(:box).returns(box) | |
612 | + box.stubs(:owner).returns(profile) | |
613 | + | |
614 | + assert_match /.*<a.*>#{a.title}<\/a>/, render_block_content(block) | |
615 | + end | |
616 | + | |
617 | + should 'show abstract if defined by user' do | |
618 | + profile = create_user('testuser').person | |
619 | + a = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :abstract => 'some abstract') | |
620 | + | |
621 | + block = DisplayContentBlock.new | |
622 | + block.nodes = [a.id] | |
623 | + block.sections = [{:value => 'abstract', :checked => true}] | |
624 | + box = mock() | |
625 | + block.stubs(:box).returns(box) | |
626 | + box.stubs(:owner).returns(profile) | |
627 | + | |
628 | + assert_match /#{a.abstract}/, render_block_content(block) | |
629 | + end | |
630 | + | |
631 | + should 'show body if defined by user' do | |
632 | + profile = create_user('testuser').person | |
633 | + a = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :body => 'some body') | |
634 | + | |
635 | + block = DisplayContentBlock.new | |
636 | + block.nodes = [a.id] | |
637 | + block.sections = [{:value => 'body', :checked => true}] | |
638 | + box = mock() | |
639 | + block.stubs(:box).returns(box) | |
640 | + box.stubs(:owner).returns(profile) | |
641 | + | |
642 | + assert_match /#{a.body}/, render_block_content(block) | |
643 | + end | |
644 | + | |
645 | + should 'show publishd date if defined by user' do | |
646 | + profile = create_user('testuser').person | |
647 | + a = fast_create(TextArticle, :name => 'test article 1', :profile_id => profile.id, :body => 'some body') | |
648 | + | |
649 | + block = DisplayContentBlock.new | |
650 | + block.nodes = [a.id] | |
651 | + block.sections = [{:value => 'publish_date', :checked => true}] | |
652 | + box = mock() | |
653 | + block.stubs(:box).returns(box) | |
654 | + box.stubs(:owner).returns(profile) | |
655 | + | |
656 | + assert_match /#{a.published_at}/, render_block_content(block) | |
657 | + end | |
658 | + | |
651 | 659 | should 'show articles in recent order' do |
652 | 660 | profile = create_user('testuser').person |
653 | 661 | Article.delete_all |
... | ... | @@ -663,8 +671,8 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
663 | 671 | |
664 | 672 | block.order_by_recent = true |
665 | 673 | |
666 | - a1_index = instance_eval(&block.content).index(a1.name) | |
667 | - a2_index = instance_eval(&block.content).index(a2.name) | |
674 | + a1_index = render_block_content(block).index(a1.name) | |
675 | + a2_index = render_block_content(block).index(a2.name) | |
668 | 676 | |
669 | 677 | assert a2_index < a1_index |
670 | 678 | end |
... | ... | @@ -684,8 +692,8 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
684 | 692 | |
685 | 693 | block.order_by_recent = false |
686 | 694 | |
687 | - a1_index = instance_eval(&block.content).index(a1.name) | |
688 | - a2_index = instance_eval(&block.content).index(a2.name) | |
695 | + a1_index = render_block_content(block).index(a1.name) | |
696 | + a2_index = render_block_content(block).index(a2.name) | |
689 | 697 | |
690 | 698 | assert a1_index < a2_index |
691 | 699 | end |
... | ... | @@ -706,7 +714,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
706 | 714 | block.order_by_recent = true |
707 | 715 | block.limit_to_show = 1 |
708 | 716 | |
709 | - a1_index = instance_eval(&block.content).index(a1.name) | |
717 | + a1_index = render_block_content(block).index(a1.name) | |
710 | 718 | |
711 | 719 | assert a1_index.nil? |
712 | 720 | end |
... | ... | @@ -730,15 +738,15 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
730 | 738 | block.stubs(:box).returns(box) |
731 | 739 | box.stubs(:owner).returns(profile) |
732 | 740 | |
733 | - assert_nil instance_eval(&block.content).index(en_article.name) | |
734 | - assert_nil instance_eval(&block.content).index(en_article2.name) | |
735 | - assert instance_eval(&block.content).index(pt_article.name).present? | |
741 | + assert_nil render_block_content(block).index(en_article.name) | |
742 | + assert_nil render_block_content(block).index(en_article2.name) | |
743 | + assert render_block_content(block).index(pt_article.name).present? | |
736 | 744 | |
737 | 745 | FastGettext.stubs(:locale).returns('en') |
738 | 746 | |
739 | - assert instance_eval(&block.content).index(en_article.name) | |
740 | - assert instance_eval(&block.content).index(en_article2.name) | |
741 | - assert_nil instance_eval(&block.content).index(pt_article.name) | |
747 | + assert render_block_content(block).index(en_article.name) | |
748 | + assert render_block_content(block).index(en_article2.name) | |
749 | + assert_nil render_block_content(block).index(pt_article.name) | |
742 | 750 | end |
743 | 751 | |
744 | 752 | should 'replace article with its translation' do |
... | ... | @@ -758,13 +766,13 @@ class DisplayContentBlockTest < ActiveSupport::TestCase |
758 | 766 | block.stubs(:box).returns(box) |
759 | 767 | box.stubs(:owner).returns(profile) |
760 | 768 | |
761 | - assert_nil instance_eval(&block.content).index(en_article.name) | |
762 | - assert instance_eval(&block.content).index(pt_article.name).present? | |
769 | + assert_nil render_block_content(block).index(en_article.name) | |
770 | + assert render_block_content(block).index(pt_article.name).present? | |
763 | 771 | |
764 | 772 | FastGettext.stubs(:locale).returns('en') |
765 | 773 | |
766 | - assert instance_eval(&block.content).index(en_article.name).present? | |
767 | - assert_nil instance_eval(&block.content).index(pt_article.name) | |
774 | + assert render_block_content(block).index(en_article.name).present? | |
775 | + assert_nil render_block_content(block).index(pt_article.name) | |
768 | 776 | end |
769 | 777 | |
770 | 778 | should 'not escape html in block content' do | ... | ... |
... | ... | @@ -0,0 +1,4 @@ |
1 | +li | |
2 | + - unless item.folder? || item.class == RssFeed | |
3 | + = render partial: 'blocks/section', collection: block.sections, locals: { block: block, item: item } | |
4 | + = render partial: 'blocks/read_more', locals: { item: item, abstract_section: block.sections.bsearch { |section| section[:value] == 'abstract' }, block: block } | |
0 | 5 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,22 @@ |
1 | +- if block.display_section?(section) | |
2 | + - case section[:value] | |
3 | + - when 'publish_date' | |
4 | + div class='published-at' | |
5 | + = show_date(item.published_at, false) | |
6 | + - when 'title' | |
7 | + div class='title' | |
8 | + = link_to(h(item.title), item.url) | |
9 | + - when 'abstract' | |
10 | + div class='lead' | |
11 | + = item.abstract | |
12 | + - when 'body' | |
13 | + div class='body' | |
14 | + = item.body | |
15 | + - when 'image' | |
16 | + - unless item.image || item.image.public_filename | |
17 | + div class='image' | |
18 | + = link_to(image_tag(item.image.public_filename), item.url) | |
19 | + - when 'tags' | |
20 | + - unless item.tags.empty? | |
21 | + div class='tags' | |
22 | + = render partial: 'blocks/tag', collection: item.tags | ... | ... |
plugins/display_content/views/blocks/display_content.slim
0 → 100644
plugins/newsletter/test/integration/safe_strings_test.rb
0 → 100644
... | ... | @@ -0,0 +1,31 @@ |
1 | +require 'test_helper' | |
2 | + | |
3 | +class NewsletterPluginSafeStringsTest < ActionDispatch::IntegrationTest | |
4 | + | |
5 | + should 'not escape HTML from newsletter pending task' do | |
6 | + environment = Environment.default | |
7 | + environment.enable_plugin('newsletter') | |
8 | + person = create_user('john', :environment_id => environment.id, :password => 'test', :password_confirmation => 'test').person | |
9 | + person.user.activate | |
10 | + environment.add_admin(person) | |
11 | + | |
12 | + blog = fast_create(Blog, :profile_id => person.id) | |
13 | + post = fast_create(TextileArticle, :name => 'First post', :profile_id => person.id, :parent_id => blog.id, :body => 'Test') | |
14 | + newsletter = NewsletterPlugin::Newsletter.create!(:environment => environment, :person => person, :enabled => true) | |
15 | + newsletter.blog_ids = [blog.id] | |
16 | + newsletter.save! | |
17 | + task = NewsletterPlugin::ModerateNewsletter.create!( | |
18 | + :newsletter_id => newsletter.id, | |
19 | + :target => environment, | |
20 | + :post_ids => [post.id.to_s] | |
21 | + ) | |
22 | + | |
23 | + login 'john', 'test' | |
24 | + get '/myprofile/john/tasks' | |
25 | + | |
26 | + assert_tag :tag => 'input', | |
27 | + :attributes => { :type => 'checkbox', :name => "tasks[#{task.id}][task][post_ids][]" }, | |
28 | + :sibling => { :tag => 'span' } | |
29 | + end | |
30 | + | |
31 | +end | ... | ... |
plugins/newsletter/views/tasks/newsletter_plugin/_moderate_newsletter_accept_details.html.erb
... | ... | @@ -9,9 +9,9 @@ |
9 | 9 | <% input_name = "tasks[#{task.id}][task][post_ids][]" %> |
10 | 10 | <% post_check_box = hidden_field_tag(input_name, '0') +check_box_tag(input_name, post.id, true) %> |
11 | 11 | |
12 | - <% newsletter_content.gsub!(/<span([^>]*?) id="#{post.id}"/, post_check_box + '<span\\1')%> | |
13 | - <% newsletter_content.gsub!(/<img([^>]*?) id="#{post.id}"/, post_check_box + '<img\\1') %> | |
12 | + <% newsletter_content.gsub!(/<span([^>]*?) id="#{post.id}"/, post_check_box + '<span\\1'.html_safe) %> | |
13 | + <% newsletter_content.gsub!(/<img([^>]*?) id="#{post.id}"/, post_check_box + '<img\\1'.html_safe) %> | |
14 | 14 | <% end %> |
15 | 15 | |
16 | - <%= newsletter_content %> | |
16 | + <%= newsletter_content.html_safe %> | |
17 | 17 | </div> | ... | ... |
test/api/boxes_test.rb
... | ... | @@ -70,6 +70,17 @@ class BoxesTest < ActiveSupport::TestCase |
70 | 70 | assert_equal [], json["boxes"].first["blocks"].map {|b| b['id']} |
71 | 71 | end |
72 | 72 | |
73 | + should 'list a block with logged in display_user for a logged user' do | |
74 | + profile = fast_create(Profile) | |
75 | + box = fast_create(Box, :owner_id => profile.id, :owner_type => Profile.name) | |
76 | + block = fast_create(Block, box_id: box.id) | |
77 | + block.display_user = 'logged' | |
78 | + block.save! | |
79 | + get "/api/v1/profiles/#{profile.id}/boxes?#{params.to_query}" | |
80 | + json = JSON.parse(last_response.body) | |
81 | + assert_equal [block.id], json["boxes"].first["blocks"].map {|b| b['id']} | |
82 | + end | |
83 | + | |
73 | 84 | should 'not list boxes for user without permission' do |
74 | 85 | profile = fast_create(Profile, public_profile: false) |
75 | 86 | box = fast_create(Box, :owner_id => profile.id, :owner_type => Profile.name) | ... | ... |
test/unit/block_test.rb
... | ... | @@ -27,10 +27,6 @@ class BlockTest < ActiveSupport::TestCase |
27 | 27 | assert_nil Block.new.owner |
28 | 28 | end |
29 | 29 | |
30 | - should 'provide no footer by default' do | |
31 | - assert_nil Block.new.footer | |
32 | - end | |
33 | - | |
34 | 30 | should 'provide an empty default title' do |
35 | 31 | assert_equal '', Block.new.default_title |
36 | 32 | end | ... | ... |