Commit 5187f433a4ac6552b4f16617c5cc1fed6127b4e9

Authored by Rodrigo Souto
2 parents abdeef43 e48e8f42

Merge remote-tracking branch 'participa/AI2919-track_fixes' into track-fixes

Conflicts:
	test/functional/cms_controller_test.rb
	test/unit/profile_test.rb
Showing 36 changed files with 530 additions and 228 deletions   Show diff stats
app/controllers/my_profile/cms_controller.rb
@@ -64,6 +64,7 @@ class CmsController < MyProfileController @@ -64,6 +64,7 @@ class CmsController < MyProfileController
64 end 64 end
65 65
66 def edit 66 def edit
  67 + @success_back_to = params[:success_back_to]
67 @article = profile.articles.find(params[:id]) 68 @article = profile.articles.find(params[:id])
68 @parent_id = params[:parent_id] 69 @parent_id = params[:parent_id]
69 @type = params[:type] || @article.class.to_s 70 @type = params[:type] || @article.class.to_s
@@ -78,7 +79,7 @@ class CmsController < MyProfileController @@ -78,7 +79,7 @@ class CmsController < MyProfileController
78 if @article.update_attributes(params[:article]) 79 if @article.update_attributes(params[:article])
79 if !continue 80 if !continue
80 if @article.content_type.nil? || @article.image? 81 if @article.content_type.nil? || @article.image?
81 - redirect_to @article.view_url 82 + success_redirect
82 else 83 else
83 redirect_to :action => (@article.parent ? 'view' : 'index'), :id => @article.parent 84 redirect_to :action => (@article.parent ? 'view' : 'index'), :id => @article.parent
84 end 85 end
@@ -90,6 +91,7 @@ class CmsController < MyProfileController @@ -90,6 +91,7 @@ class CmsController < MyProfileController
90 def new 91 def new
91 # FIXME this method should share some logic wirh edit !!! 92 # FIXME this method should share some logic wirh edit !!!
92 93
  94 + @success_back_to = params[:success_back_to]
93 # user must choose an article type first 95 # user must choose an article type first
94 96
95 @parent = profile.articles.find(params[:parent_id]) if params && params[:parent_id] 97 @parent = profile.articles.find(params[:parent_id]) if params && params[:parent_id]
@@ -134,7 +136,7 @@ class CmsController < MyProfileController @@ -134,7 +136,7 @@ class CmsController < MyProfileController
134 if continue 136 if continue
135 redirect_to :action => 'edit', :id => @article 137 redirect_to :action => 'edit', :id => @article
136 else 138 else
137 - redirect_to @article.view_url 139 + success_redirect
138 end 140 end
139 return 141 return
140 end 142 end
@@ -386,4 +388,12 @@ class CmsController < MyProfileController @@ -386,4 +388,12 @@ class CmsController < MyProfileController
386 true 388 true
387 end 389 end
388 390
  391 + def success_redirect
  392 + if !@success_back_to.blank?
  393 + redirect_to @success_back_to
  394 + else
  395 + redirect_to @article.view_url
  396 + end
  397 + end
  398 +
389 end 399 end
app/models/article.rb
@@ -448,8 +448,8 @@ class Article < ActiveRecord::Base @@ -448,8 +448,8 @@ class Article < ActiveRecord::Base
448 end 448 end
449 449
450 named_scope :published, :conditions => { :published => true } 450 named_scope :published, :conditions => { :published => true }
451 - named_scope :folders, :conditions => { :type => folder_types}  
452 - named_scope :no_folders, :conditions => ['type NOT IN (?)', folder_types] 451 + named_scope :folders, lambda {|profile|{:conditions => { :type => profile.folder_types} }}
  452 + named_scope :no_folders, lambda {|profile|{:conditions => ['type NOT IN (?)', profile.folder_types]}}
453 named_scope :galleries, :conditions => { :type => 'Gallery' } 453 named_scope :galleries, :conditions => { :type => 'Gallery' }
454 named_scope :images, :conditions => { :is_image => true } 454 named_scope :images, :conditions => { :is_image => true }
455 named_scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ] 455 named_scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ]
app/models/blog.rb
@@ -6,7 +6,7 @@ class Blog < Folder @@ -6,7 +6,7 @@ class Blog < Folder
6 #FIXME This should be used until there is a migration to fix all blogs that 6 #FIXME This should be used until there is a migration to fix all blogs that
7 # already have folders inside them 7 # already have folders inside them
8 def posts_with_no_folders 8 def posts_with_no_folders
9 - posts_without_no_folders.no_folders 9 + posts_without_no_folders.no_folders(profile)
10 end 10 end
11 alias_method_chain :posts, :no_folders 11 alias_method_chain :posts, :no_folders
12 12
app/models/profile.rb
@@ -761,8 +761,20 @@ private :generate_url, :url_options @@ -761,8 +761,20 @@ private :generate_url, :url_options
761 !environment.enabled?('disable_contact_' + self.class.name.downcase) 761 !environment.enabled?('disable_contact_' + self.class.name.downcase)
762 end 762 end
763 763
  764 + include Noosfero::Plugin::HotSpot
  765 +
  766 + def folder_types
  767 + types = Article.folder_types
  768 + plugins.dispatch(:content_types).each {|type|
  769 + if type < Folder
  770 + types << type.name
  771 + end
  772 + }
  773 + types
  774 + end
  775 +
764 def folders 776 def folders
765 - articles.folders 777 + articles.folders(self)
766 end 778 end
767 779
768 def image_galleries 780 def image_galleries
app/views/cms/edit.rhtml
@@ -9,6 +9,8 @@ @@ -9,6 +9,8 @@
9 9
10 <%= hidden_field_tag('back_to', @back_to) %> 10 <%= hidden_field_tag('back_to', @back_to) %>
11 11
  12 + <%= hidden_field_tag('success_back_to', @success_back_to) %>
  13 +
12 <%= render :partial => partial_for_class(@article.class), :locals => { :f => f } %> 14 <%= render :partial => partial_for_class(@article.class), :locals => { :f => f } %>
13 15
14 <% if environment.is_portal_community?(profile) %> 16 <% if environment.is_portal_community?(profile) %>
plugins/community_track/controllers/public/community_track_plugin_public_controller.rb
@@ -25,7 +25,7 @@ class CommunityTrackPluginPublicController &lt; PublicController @@ -25,7 +25,7 @@ class CommunityTrackPluginPublicController &lt; PublicController
25 end 25 end
26 26
27 def all_tracks 27 def all_tracks
28 - @per_page = 5 #FIXME 28 + @per_page = 8 #FIXME
29 @block = Block.find(params[:id]) 29 @block = Block.find(params[:id])
30 @tracks = @block.tracks(1, @per_page) 30 @tracks = @block.tracks(1, @per_page)
31 @show_more = @block.has_page?(2, @per_page) 31 @show_more = @block.has_page?(2, @per_page)
plugins/community_track/lib/community_track_plugin/activation_job.rb 0 → 100644
@@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
  1 +class CommunityTrackPlugin::ActivationJob < Struct.new(:step_id)
  2 +
  3 + def self.find(step_id)
  4 + Delayed::Job.where(:handler => "--- !ruby/struct:CommunityTrackPlugin::ActivationJob \nstep_id: #{step_id}\n")
  5 + end
  6 +
  7 + def perform
  8 + step = CommunityTrackPlugin::Step.find(step_id)
  9 + step.toggle_activation
  10 + end
  11 +
  12 +end
plugins/community_track/lib/community_track_plugin/step.rb
1 class CommunityTrackPlugin::Step < Folder 1 class CommunityTrackPlugin::Step < Folder
2 2
3 settings_items :hidden, :type => :boolean, :default => false 3 settings_items :hidden, :type => :boolean, :default => false
  4 + settings_items :tool_type, :type => String
4 5
5 alias :tools :children 6 alias :tools :children
6 7
@@ -17,13 +18,19 @@ class CommunityTrackPlugin::Step &lt; Folder @@ -17,13 +18,19 @@ class CommunityTrackPlugin::Step &lt; Folder
17 after_save :schedule_activation 18 after_save :schedule_activation
18 19
19 before_create do |step| 20 before_create do |step|
20 - step.published = false 21 + step.accept_comments = false
21 true 22 true
22 end 23 end
23 24
24 before_create :set_hidden_position 25 before_create :set_hidden_position
25 before_save :set_hidden_position 26 before_save :set_hidden_position
26 27
  28 + def initialize(*args)
  29 + super(*args)
  30 + self.start_date ||= Date.today
  31 + self.end_date ||= Date.today + 1.day
  32 + end
  33 +
27 def set_hidden_position 34 def set_hidden_position
28 if hidden 35 if hidden
29 decrement_positions_on_lower_items 36 decrement_positions_on_lower_items
@@ -48,11 +55,11 @@ class CommunityTrackPlugin::Step &lt; Folder @@ -48,11 +55,11 @@ class CommunityTrackPlugin::Step &lt; Folder
48 end 55 end
49 56
50 def accept_comments? 57 def accept_comments?
51 - false 58 + accept_comments
52 end 59 end
53 60
54 - def enabled_tools  
55 - {TinyMceArticle => {:name => _('Article')}, Forum => {:name => _('Forum')}} 61 + def self.enabled_tools
  62 + [TinyMceArticle, Forum]
56 end 63 end
57 64
58 def to_html(options = {}) 65 def to_html(options = {})
@@ -75,31 +82,31 @@ class CommunityTrackPlugin::Step &lt; Folder @@ -75,31 +82,31 @@ class CommunityTrackPlugin::Step &lt; Folder
75 end 82 end
76 83
77 def schedule_activation 84 def schedule_activation
78 - return if !changes['start_date'] && !changes['end_date'] && !changes['published']  
79 - today = Date.today  
80 - if today <= end_date || published  
81 - schedule_date = !published ? start_date : end_date + 1.day 85 + return if !changes['start_date'] && !changes['end_date']
  86 + if Date.today <= end_date || accept_comments
  87 + schedule_date = !accept_comments ? start_date : end_date + 1.day
82 CommunityTrackPlugin::ActivationJob.find(id).destroy_all 88 CommunityTrackPlugin::ActivationJob.find(id).destroy_all
83 Delayed::Job.enqueue(CommunityTrackPlugin::ActivationJob.new(self.id), 0, schedule_date) 89 Delayed::Job.enqueue(CommunityTrackPlugin::ActivationJob.new(self.id), 0, schedule_date)
84 end 90 end
85 end 91 end
86 92
87 - def publish  
88 - self[:published] = active? && !hidden  
89 - save! 93 + def toggle_activation
  94 + accept_comments = active?
  95 + # set accept_comments = true on all children
  96 + self.class.toggle_activation(self, accept_comments)
90 end 97 end
91 98
92 - class CommunityTrackPlugin::ActivationJob < Struct.new(:step_id)  
93 -  
94 - def self.find(step_id)  
95 - Delayed::Job.where(:handler => "--- !ruby/struct:CommunityTrackPlugin::ActivationJob \nstep_id: #{step_id}\n")  
96 - end 99 + def self.toggle_activation(article, accept_comments)
  100 + article.update_attribute(:accept_comments, accept_comments)
  101 + article.children.each {|a| toggle_activation(a, accept_comments)}
  102 + end
97 103
98 - def perform  
99 - step = CommunityTrackPlugin::Step.find(step_id)  
100 - step.publish  
101 - end 104 + def tool_class
  105 + tool_type ? tool_type.constantize : nil
  106 + end
102 107
  108 + def tool
  109 + tools.find(:first, :conditions => {:type => tool_type })
103 end 110 end
104 111
105 end 112 end
plugins/community_track/lib/community_track_plugin/step_helper.rb
1 module CommunityTrackPlugin::StepHelper 1 module CommunityTrackPlugin::StepHelper
2 2
3 def self.status_descriptions 3 def self.status_descriptions
4 - [_('Finished'), _('In progress'), _('Waiting')] 4 + [_('Closed'), _('Join!'), _('Soon')]
5 end 5 end
6 6
7 def self.status_classes 7 def self.status_classes
@@ -16,9 +16,11 @@ module CommunityTrackPlugin::StepHelper @@ -16,9 +16,11 @@ module CommunityTrackPlugin::StepHelper
16 CommunityTrackPlugin::StepHelper.status_classes[status_index(step)] 16 CommunityTrackPlugin::StepHelper.status_classes[status_index(step)]
17 end 17 end
18 18
19 - def custom_options_for_article(article)  
20 - #no options for step?  
21 - nil 19 + def link_to_step(step, options={}, name=nil)
  20 + url = step.tool ? step.tool.view_url : step.view_url
  21 + link_to url, options do
  22 + block_given? ? yield : name
  23 + end
22 end 24 end
23 25
24 protected 26 protected
plugins/community_track/lib/community_track_plugin/track.rb
@@ -3,6 +3,12 @@ class CommunityTrackPlugin::Track &lt; Folder @@ -3,6 +3,12 @@ class CommunityTrackPlugin::Track &lt; Folder
3 settings_items :goals, :type => :string 3 settings_items :goals, :type => :string
4 settings_items :expected_results, :type => :string 4 settings_items :expected_results, :type => :string
5 5
  6 + validate :validate_categories
  7 +
  8 + def validate_categories
  9 + errors.add(:categories, _('should not be blank.')) if categories.empty? && pending_categorizations.blank?
  10 + end
  11 +
6 def self.icon_name(article = nil) 12 def self.icon_name(article = nil)
7 'community-track' 13 'community-track'
8 end 14 end
@@ -57,7 +63,7 @@ class CommunityTrackPlugin::Track &lt; Folder @@ -57,7 +63,7 @@ class CommunityTrackPlugin::Track &lt; Folder
57 63
58 def category_name 64 def category_name
59 category = categories.first 65 category = categories.first
60 - category ? category.name : '' 66 + category ? category.top_ancestor.name : ''
61 end 67 end
62 68
63 def to_html(options = {}) 69 def to_html(options = {})
plugins/community_track/lib/community_track_plugin/track_list_block.rb
@@ -34,6 +34,10 @@ class CommunityTrackPlugin::TrackListBlock &lt; Block @@ -34,6 +34,10 @@ class CommunityTrackPlugin::TrackListBlock &lt; Block
34 settings[:category_ids] = ids.uniq.map{|item| item.to_i unless item.to_i.zero?}.compact 34 settings[:category_ids] = ids.uniq.map{|item| item.to_i unless item.to_i.zero?}.compact
35 end 35 end
36 36
  37 + def categories
  38 + Category.find(category_ids)
  39 + end
  40 +
37 def all_tracks 41 def all_tracks
38 tracks = owner.articles.where(:type => 'CommunityTrackPlugin::Track') 42 tracks = owner.articles.where(:type => 'CommunityTrackPlugin::Track')
39 if !category_ids.empty? 43 if !category_ids.empty?
@@ -61,4 +65,8 @@ class CommunityTrackPlugin::TrackListBlock &lt; Block @@ -61,4 +65,8 @@ class CommunityTrackPlugin::TrackListBlock &lt; Block
61 end 65 end
62 end 66 end
63 67
  68 + def self.expire_on
  69 + { :profile => [:article, :category], :environment => [:article, :category] }
  70 + end
  71 +
64 end 72 end
plugins/community_track/lib/ext/article.rb 0 → 100644
@@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
  1 +require_dependency 'article'
  2 +
  3 +class Article
  4 +
  5 + before_create do |article|
  6 + if article.parent.kind_of?(CommunityTrackPlugin::Step)
  7 + article.accept_comments = article.parent.accept_comments
  8 + end
  9 + true
  10 + end
  11 +
  12 +end
plugins/community_track/public/style.css
@@ -3,17 +3,17 @@ @@ -3,17 +3,17 @@
3 background-image: url(/plugins/community_track/icons/community-track.png) 3 background-image: url(/plugins/community_track/icons/community-track.png)
4 } 4 }
5 5
6 -.step_active, #article .step_active a { 6 +.step_active, #article .step_active {
7 background-color: #CCEBD6; 7 background-color: #CCEBD6;
8 color: #338533; 8 color: #338533;
9 } 9 }
10 10
11 -.step_waiting, #article .step_waiting a { 11 +.step_waiting, #article .step_waiting {
12 background-color: #FFFFD1; 12 background-color: #FFFFD1;
13 color: #D17519; 13 color: #D17519;
14 } 14 }
15 15
16 -.step_finished, #article .step_finished a { 16 +.step_finished, #article .step_finished {
17 background-color: #D1FFFF; 17 background-color: #D1FFFF;
18 color: #00297A; 18 color: #00297A;
19 } 19 }
@@ -24,6 +24,7 @@ @@ -24,6 +24,7 @@
24 24
25 .step { 25 .step {
26 font-weight: bold; 26 font-weight: bold;
  27 + margin-bottom: 3px;
27 } 28 }
28 29
29 .track_list .item .step { 30 .track_list .item .step {
@@ -73,6 +74,11 @@ @@ -73,6 +74,11 @@
73 .steps .step { 74 .steps .step {
74 margin-top: 3px; 75 margin-top: 3px;
75 margin-bottom: 3px; 76 margin-bottom: 3px;
  77 + display: block;
  78 +}
  79 +
  80 +.steps a {
  81 + text-decoration: none;
76 } 82 }
77 83
78 .track_list .item_card .track_stats { 84 .track_list .item_card .track_stats {
@@ -126,13 +132,15 @@ @@ -126,13 +132,15 @@
126 #track .position { 132 #track .position {
127 font-size: 24px; 133 font-size: 24px;
128 font-weight: bold; 134 font-weight: bold;
129 - float: left;  
130 margin: 0 10px; 135 margin: 0 10px;
  136 + display: inline-block;
  137 + vertical-align: top;
131 } 138 }
132 139
133 -#track .step .name, #track .step .name a { 140 +#track .step .name {
134 font-weight: bold; 141 font-weight: bold;
135 color: #333; 142 color: #333;
  143 + clear: both;
136 } 144 }
137 145
138 #track .step .name a:hover { 146 #track .step .name a:hover {
@@ -142,6 +150,7 @@ @@ -142,6 +150,7 @@
142 #track .step .date { 150 #track .step .date {
143 font-size: 12px; 151 font-size: 12px;
144 color: #AAA; 152 color: #AAA;
  153 + float: left;
145 } 154 }
146 155
147 #track .step .lead { 156 #track .step .lead {
@@ -151,7 +160,7 @@ @@ -151,7 +160,7 @@
151 160
152 #track .content { 161 #track .content {
153 margin: 6px 0px; 162 margin: 6px 0px;
154 - border-bottom: 1px solid #DDDDDD; 163 + display: inline-block;
155 } 164 }
156 165
157 #track .ui-state-default .content { 166 #track .ui-state-default .content {
@@ -199,3 +208,60 @@ @@ -199,3 +208,60 @@
199 width: 115px; 208 width: 115px;
200 background: url(/plugins/community_track/icons/calendar.png) right center no-repeat; 209 background: url(/plugins/community_track/icons/calendar.png) right center no-repeat;
201 } 210 }
  211 +
  212 +.step_list .step .tools {
  213 + margin-top: 5px;
  214 +}
  215 +
  216 +#article .step_list .step .tool_icon,
  217 +.tool_icon {
  218 + color: #888;
  219 + background-color: transparent;
  220 + border: 0px;
  221 + background-repeat: no-repeat;
  222 + line-height: 20px;
  223 + height: 20px;
  224 + padding: 3px 2px 3px 22px;
  225 +}
  226 +
  227 +#article .step .tool_link {
  228 + cursor: pointer;
  229 +}
  230 +
  231 +#article .step_active .tool_link:hover,
  232 +#content .steps .step_active:hover {
  233 + background-color: #B8D4C1;
  234 +}
  235 +
  236 +#article .step_waiting .tool_link:hover,
  237 +#content .steps .step_waiting:hover {
  238 + background-color: #E6E6BC;
  239 +}
  240 +
  241 +#article .step_finished .tool_link:hover,
  242 +#content .steps .step_finished:hover {
  243 + background-color: #BCE6E6;
  244 +}
  245 +
  246 +.step_list .step .step_actions {
  247 + text-align: right;
  248 +}
  249 +
  250 +#article .step_list .step .step_actions .button {
  251 + color: #888;
  252 + background-color: transparent;
  253 + border: 0px;
  254 + border-right: 1px solid;
  255 +}
  256 +
  257 +#article .step_list .step .step_actions .button:hover {
  258 + color: #444;
  259 +}
  260 +
  261 +.step .content {
  262 + width: 80%;
  263 +}
  264 +
  265 +.step .legend {
  266 + float: right;
  267 +}
plugins/community_track/test/functional/community_track_plugin_cms_controller_test.rb
@@ -7,7 +7,7 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -7,7 +7,7 @@ class CmsControllerTest &lt; ActionController::TestCase
7 7
8 def setup 8 def setup
9 @profile = fast_create(Community) 9 @profile = fast_create(Community)
10 - @track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track', :profile => @profile) 10 + @track = create_track('track', @profile)
11 @step = CommunityTrackPlugin::Step.create!(:name => 'step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) 11 @step = CommunityTrackPlugin::Step.create!(:name => 'step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today)
12 12
13 user = create_user('testinguser') 13 user = create_user('testinguser')
@@ -39,9 +39,4 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -39,9 +39,4 @@ class CmsControllerTest &lt; ActionController::TestCase
39 assert_equal 'changed', @step.name 39 assert_equal 'changed', @step.name
40 end 40 end
41 41
42 - should 'do not be able to edit visibility of step' do  
43 - get :edit, :id => @step.id, :profile => @profile.identifier  
44 - assert_no_tag :tag => 'input', :attributes => { :name => 'article[published]' }  
45 - end  
46 -  
47 end 42 end
plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb
@@ -11,11 +11,8 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -11,11 +11,8 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
11 11
12 def setup 12 def setup
13 @profile = fast_create(Community) 13 @profile = fast_create(Community)
14 - @track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track', :profile => @profile)  
15 - category = fast_create(Category, :name => "education")  
16 - @track.add_category(category)  
17 -  
18 - @step = CommunityTrackPlugin::Step.create!(:name => 'step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) 14 + @track = create_track('track', @profile)
  15 + @step = CommunityTrackPlugin::Step.create!(:name => 'step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today, :tool_type => TinyMceArticle.name)
19 16
20 user = create_user('testinguser') 17 user = create_user('testinguser')
21 login_as(user.login) 18 login_as(user.login)
@@ -24,15 +21,15 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -24,15 +21,15 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
24 21
25 should 'show actions for tracks when user has permission for edit' do 22 should 'show actions for tracks when user has permission for edit' do
26 get :view_page, @track.url 23 get :view_page, @track.url
27 - assert_tag :tag => 'div', :attributes => {:id => 'track' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } } 24 + assert_tag :tag => 'div', :attributes => {:id => 'track' }, :descendant => { :tag => 'div', :attributes => { :class => 'track actions' } }
28 end 25 end
29 26
30 - should 'do not show actions for tracks when user has not permission for edit' do 27 + should 'do not show actions for tracks when user has not permission to edit' do
31 user = create_user('intruder') 28 user = create_user('intruder')
32 logout 29 logout
33 login_as(user.login) 30 login_as(user.login)
34 get :view_page, @track.url 31 get :view_page, @track.url
35 - assert_no_tag :tag => 'div', :attributes => {:id => 'track' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } } 32 + assert_no_tag :tag => 'div', :attributes => {:id => 'track' }, :descendant => { :tag => 'div', :attributes => { :class => 'track actions' } }
36 end 33 end
37 34
38 should 'do not show new button at article toolbar for tracks' do 35 should 'do not show new button at article toolbar for tracks' do
@@ -45,7 +42,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -45,7 +42,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
45 42
46 should 'display steps for tracks' do 43 should 'display steps for tracks' do
47 get :view_page, @track.url 44 get :view_page, @track.url
48 - assert_tag :tag => 'ul', :attributes => { :id => 'sortable' }, :descendant => {:tag => 'li', :attributes => { :class => 'step' } } 45 + assert_tag :tag => 'ul', :attributes => { :id => 'sortable' }, :descendant => {:tag => 'li', :attributes => { :class => 'step step_active' } }
49 end 46 end
50 47
51 should 'display hidden field with step id' do 48 should 'display hidden field with step id' do
@@ -59,22 +56,28 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -59,22 +56,28 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
59 end 56 end
60 57
61 should 'show tools for a step' do 58 should 'show tools for a step' do
62 - Article.create!(:profile => @profile, :name => 'article', :parent => @step) 59 + TinyMceArticle.create!(:profile => @profile, :name => 'article', :parent => @step)
63 get :view_page, @step.url 60 get :view_page, @step.url
64 assert_tag :tag => 'div', :attributes => { :class => 'tools' }, :descendant => { :tag => 'div', :attributes => { :class => 'item' } } 61 assert_tag :tag => 'div', :attributes => { :class => 'tools' }, :descendant => { :tag => 'div', :attributes => { :class => 'item' } }
65 end 62 end
66 63
67 - should 'show actions for steps when user has permission for edit' do 64 + should 'show actions for steps when user has permission to edit' do
68 get :view_page, @step.url 65 get :view_page, @step.url
69 assert_tag :tag => 'div', :attributes => {:id => 'step' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } } 66 assert_tag :tag => 'div', :attributes => {:id => 'step' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } }
70 end 67 end
71 68
72 - should 'show actions for enabled tools in step' do 69 + should 'show action for tiny mce article tool in step' do
73 get :view_page, @step.url 70 get :view_page, @step.url
74 - assert_tag 'div', :attributes => {:class => 'actions' }, :descendant => { :tag => 'a', :attributes => { :class => 'button with-text icon-new icon-newforum' } }  
75 assert_tag 'div', :attributes => {:class => 'actions' }, :descendant => { :tag => 'a', :attributes => { :class => 'button with-text icon-new icon-newtext-html' } } 71 assert_tag 'div', :attributes => {:class => 'actions' }, :descendant => { :tag => 'a', :attributes => { :class => 'button with-text icon-new icon-newtext-html' } }
76 end 72 end
77 73
  74 + should 'show action for forum tool in step' do
  75 + @step.tool_type = Forum.name
  76 + @step.save!
  77 + get :view_page, @step.url
  78 + assert_tag 'div', :attributes => {:class => 'actions' }, :descendant => { :tag => 'a', :attributes => { :class => 'button with-text icon-new icon-newforum' } }
  79 + end
  80 +
78 should 'do not show actions for steps when user has not permission for edit' do 81 should 'do not show actions for steps when user has not permission for edit' do
79 user = create_user('intruder') 82 user = create_user('intruder')
80 logout 83 logout
@@ -104,7 +107,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -104,7 +107,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
104 @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box) 107 @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box)
105 @profile.boxes << box 108 @profile.boxes << box
106 get :view_page, @step.url 109 get :view_page, @step.url
107 - assert_tag :tag => 'div', :attributes => { :class => 'item category_education' }, :descendant => { :tag => 'div', :attributes => { :class => 'steps' }, :descendant => { :tag => 'div', :attributes => { :class => "step #{@block.status_class(@step)}" } } } 110 + assert_tag :tag => 'div', :attributes => { :class => "item category_#{@track.category_name}" }, :descendant => { :tag => 'div', :attributes => { :class => 'steps' }, :descendant => { :tag => 'span', :attributes => { :class => "step #{@block.status_class(@step)}" } } }
108 end 111 end
109 112
110 should 'render tracks in track card list block' do 113 should 'render tracks in track card list block' do
@@ -112,8 +115,8 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -112,8 +115,8 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
112 @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) 115 @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box)
113 @profile.boxes << box 116 @profile.boxes << box
114 get :view_page, @step.url 117 get :view_page, @step.url
115 - assert_tag :tag => 'div', :attributes => { :class => 'item_card category_education' }, :descendant => { :tag => 'div', :attributes => { :class => 'track_content' } }  
116 - assert_tag :tag => 'div', :attributes => { :class => 'item_card category_education' }, :descendant => { :tag => 'div', :attributes => { :class => 'track_stats' } } 118 + assert_tag :tag => 'div', :attributes => { :class => "item_card category_#{@track.category_name}" }, :descendant => { :tag => 'div', :attributes => { :class => 'track_content' } }
  119 + assert_tag :tag => 'div', :attributes => { :class => "item_card category_#{@track.category_name}" }, :descendant => { :tag => 'div', :attributes => { :class => 'track_stats' } }
117 end 120 end
118 121
119 should 'render link to display more tracks in track list block' do 122 should 'render link to display more tracks in track list block' do
@@ -121,9 +124,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -121,9 +124,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
121 @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) 124 @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box)
122 @profile.boxes << box 125 @profile.boxes << box
123 126
124 - (@block.limit+1).times do |i|  
125 - CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @profile)  
126 - end 127 + (@block.limit+1).times { |i| create_track("track#{i}", @profile) }
127 128
128 get :view_page, @step.url 129 get :view_page, @step.url
129 assert_tag :tag => 'div', :attributes => { :id => "track_list_more_#{@block.id}" }, :descendant => { :tag => 'div', :attributes => { :class => 'more' } } 130 assert_tag :tag => 'div', :attributes => { :id => "track_list_more_#{@block.id}" }, :descendant => { :tag => 'div', :attributes => { :class => 'more' } }
@@ -136,9 +137,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -136,9 +137,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
136 @block.more_another_page = true 137 @block.more_another_page = true
137 @block.save! 138 @block.save!
138 139
139 - (@block.limit+1).times do |i|  
140 - CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @profile)  
141 - end 140 + (@block.limit+1).times { |i| create_track("track#{i}", @profile) }
142 141
143 get :view_page, @step.url 142 get :view_page, @step.url
144 assert_tag :tag => 'div', :attributes => { :id => "track_list_more_#{@block.id}" }, :descendant => { :tag => 'div', :attributes => { :class => 'view_all' } } 143 assert_tag :tag => 'div', :attributes => { :id => "track_list_more_#{@block.id}" }, :descendant => { :tag => 'div', :attributes => { :class => 'view_all' } }
plugins/community_track/test/functional/community_track_plugin_myprofile_controller_test.rb
@@ -12,7 +12,7 @@ class CommunityTrackPluginMyprofileControllerTest &lt; ActionController::TestCase @@ -12,7 +12,7 @@ class CommunityTrackPluginMyprofileControllerTest &lt; ActionController::TestCase
12 @response = ActionController::TestResponse.new 12 @response = ActionController::TestResponse.new
13 13
14 @profile = fast_create(Community) 14 @profile = fast_create(Community)
15 - @track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track', :profile => @profile) 15 + @track = create_track('track', @profile)
16 16
17 @user = create_user('testinguser') 17 @user = create_user('testinguser')
18 login_as(@user.login) 18 login_as(@user.login)
plugins/community_track/test/functional/community_track_plugin_public_controller_test.rb
@@ -8,7 +8,7 @@ class CommunityTrackPluginPublicControllerTest &lt; ActionController::TestCase @@ -8,7 +8,7 @@ class CommunityTrackPluginPublicControllerTest &lt; ActionController::TestCase
8 8
9 def setup 9 def setup
10 @community = fast_create(Community) 10 @community = fast_create(Community)
11 - @track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track', :profile => @community) 11 + @track = create_track('track', @community)
12 12
13 box = fast_create(Box, :owner_id => @community.id, :owner_type => 'Community') 13 box = fast_create(Box, :owner_id => @community.id, :owner_type => 'Community')
14 @card_block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) 14 @card_block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box)
@@ -26,17 +26,13 @@ class CommunityTrackPluginPublicControllerTest &lt; ActionController::TestCase @@ -26,17 +26,13 @@ class CommunityTrackPluginPublicControllerTest &lt; ActionController::TestCase
26 end 26 end
27 27
28 should 'display tracks with page size' do 28 should 'display tracks with page size' do
29 - 20.times do |i|  
30 - track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community)  
31 - end 29 + 20.times { |i| create_track("track#{i}", @community) }
32 xhr :get, :view_tracks, :id => @block.id, :page => 1, :per_page => 10 30 xhr :get, :view_tracks, :id => @block.id, :page => 1, :per_page => 10
33 assert_equal 10, @response.body.scan(/item/).size 31 assert_equal 10, @response.body.scan(/item/).size
34 end 32 end
35 33
36 should 'default page size is the block limit' do 34 should 'default page size is the block limit' do
37 - 20.times do |i|  
38 - track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community)  
39 - end 35 + 20.times { |i| create_track("track#{i}", @community) }
40 xhr :get, :view_tracks, :id => @block.id, :page => 1 36 xhr :get, :view_tracks, :id => @block.id, :page => 1
41 assert_equal @block.limit, @response.body.scan(/item/).size 37 assert_equal @block.limit, @response.body.scan(/item/).size
42 end 38 end
@@ -47,9 +43,7 @@ class CommunityTrackPluginPublicControllerTest &lt; ActionController::TestCase @@ -47,9 +43,7 @@ class CommunityTrackPluginPublicControllerTest &lt; ActionController::TestCase
47 end 43 end
48 44
49 should 'show more link in all tracks if there is no more tracks to show' do 45 should 'show more link in all tracks if there is no more tracks to show' do
50 - 10.times do |i|  
51 - CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community)  
52 - end 46 + 10.times { |i| create_track("track#{i}", @community) }
53 get :all_tracks, :id => @block.id 47 get :all_tracks, :id => @block.id
54 assert assigns['show_more'] 48 assert assigns['show_more']
55 assert_match /track_list_more_#{@block.id}/, @response.body 49 assert_match /track_list_more_#{@block.id}/, @response.body
plugins/community_track/test/test_helper.rb
1 require File.dirname(__FILE__) + '/../../../test/test_helper' 1 require File.dirname(__FILE__) + '/../../../test/test_helper'
  2 +
  3 +def create_track(name, profile)
  4 + track = CommunityTrackPlugin::Track.new(:abstract => 'abstract', :body => 'body', :name => name, :profile => profile)
  5 + track.add_category(fast_create(Category))
  6 + track.save!
  7 + track
  8 +end
plugins/community_track/test/unit/article_test.rb 0 → 100644
@@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class ArticleTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @profile = fast_create(Community)
  7 + @track = create_track('track', @profile)
  8 + @step = CommunityTrackPlugin::Step.create!(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today)
  9 + end
  10 +
  11 + should 'inherit accept_comments from parent if it is a step' do
  12 + @step.accept_comments = true
  13 + @step.save!
  14 + article = Article.create!(:parent => @step, :profile => @profile, :accept_comments => false, :name => "article")
  15 + assert article.accept_comments
  16 + end
  17 +
  18 + should 'do nothing if parent is not a step' do
  19 + folder = fast_create(Folder, :profile_id => @profile.id)
  20 + article = Article.create!(:parent => folder, :profile => @profile, :accept_comments => false, :name => "article")
  21 + assert !article.accept_comments
  22 + end
  23 +
  24 +end
plugins/community_track/test/unit/community_track_plugin/activation_job_test.rb 0 → 100644
@@ -0,0 +1,28 @@ @@ -0,0 +1,28 @@
  1 +require File.dirname(__FILE__) + '/../../test_helper'
  2 +
  3 +class ActivationJobTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @profile = fast_create(Community)
  7 + @track = create_track('track', @profile)
  8 + @step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today)
  9 + Delayed::Job.destroy_all
  10 + end
  11 +
  12 + should 'return delayed job created with a specific step_id' do
  13 + step_id = 0
  14 + CommunityTrackPlugin::ActivationJob.new(step_id)
  15 + assert CommunityTrackPlugin::ActivationJob.find(step_id)
  16 + end
  17 +
  18 + should 'change accept_comments to true on perform delayed job in a active step' do
  19 + @step.start_date = Date.today
  20 + @step.end_date = Date.today + 2.days
  21 + @step.accept_comments = false
  22 + @step.save!
  23 + CommunityTrackPlugin::ActivationJob.new(@step.id).perform
  24 + @step.reload
  25 + assert @step.accept_comments
  26 + end
  27 +
  28 +end
plugins/community_track/test/unit/community_track_plugin/step_helper_test.rb
@@ -6,6 +6,8 @@ class StepHelperTest &lt; ActiveSupport::TestCase @@ -6,6 +6,8 @@ class StepHelperTest &lt; ActiveSupport::TestCase
6 6
7 def setup 7 def setup
8 @step = CommunityTrackPlugin::Step.new 8 @step = CommunityTrackPlugin::Step.new
  9 + @profile = fast_create(Community)
  10 + @step.stubs(:profile).returns(@profile)
9 @step.stubs(:active?).returns(false) 11 @step.stubs(:active?).returns(false)
10 @step.stubs(:finished?).returns(false) 12 @step.stubs(:finished?).returns(false)
11 @step.stubs(:waiting?).returns(false) 13 @step.stubs(:waiting?).returns(false)
@@ -28,11 +30,31 @@ class StepHelperTest &lt; ActiveSupport::TestCase @@ -28,11 +30,31 @@ class StepHelperTest &lt; ActiveSupport::TestCase
28 30
29 should 'return a description for status' do 31 should 'return a description for status' do
30 @step.stubs(:waiting?).returns(true) 32 @step.stubs(:waiting?).returns(true)
31 - assert_equal _('Waiting'), status_description(@step) 33 + assert_equal _('Soon'), status_description(@step)
32 end 34 end
33 35
34 - should 'return nil at custom_options_for_article' do  
35 - assert !custom_options_for_article(fast_create(Article)) 36 + should 'return link to step if there is no tool in a step' do
  37 + expects(:link_to).with(@step.view_url, {}).once
  38 + link = link_to_step(@step) do
  39 + "content"
  40 + end
  41 + end
  42 +
  43 + should 'return link to step tool if there is a tool' do
  44 + tool = fast_create(Article, :profile_id => @profile.id)
  45 + @step.stubs(:tool).returns(tool)
  46 + expects(:link_to).with(tool.view_url, {}).once
  47 + link = link_to_step(@step) do
  48 + "content"
  49 + end
  50 + end
  51 +
  52 + should 'return link with name if no block is given' do
  53 + def link_to(url, options)
  54 + yield
  55 + end
  56 + link = link_to_step(@step, {}, 'link name')
  57 + assert_equal 'link name', link
36 end 58 end
37 59
38 end 60 end
plugins/community_track/test/unit/community_track_plugin/step_test.rb
@@ -4,7 +4,11 @@ class StepTest &lt; ActiveSupport::TestCase @@ -4,7 +4,11 @@ class StepTest &lt; ActiveSupport::TestCase
4 4
5 def setup 5 def setup
6 @profile = fast_create(Community) 6 @profile = fast_create(Community)
7 - @track = CommunityTrackPlugin::Track.create(:profile_id => @profile.id, :name => 'track') 7 + @track = CommunityTrackPlugin::Track.new(:profile_id => @profile.id, :name => 'track')
  8 + @category = fast_create(Category)
  9 + @track.add_category(@category)
  10 + @track.save!
  11 +
8 @step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) 12 @step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today)
9 Delayed::Job.destroy_all 13 Delayed::Job.destroy_all
10 end 14 end
@@ -17,10 +21,10 @@ class StepTest &lt; ActiveSupport::TestCase @@ -17,10 +21,10 @@ class StepTest &lt; ActiveSupport::TestCase
17 assert CommunityTrackPlugin::Step.short_description 21 assert CommunityTrackPlugin::Step.short_description
18 end 22 end
19 23
20 - should 'set published to false on create' do 24 + should 'set accept_comments to false on create' do
21 today = Date.today 25 today = Date.today
22 step = CommunityTrackPlugin::Step.create(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :start_date => today, :end_date => today, :published => true) 26 step = CommunityTrackPlugin::Step.create(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :start_date => today, :end_date => today, :published => true)
23 - assert !step.published 27 + assert !step.accept_comments
24 end 28 end
25 29
26 should 'do not allow step creation with a parent that is not a track' do 30 should 'do not allow step creation with a parent that is not a track' do
@@ -93,6 +97,7 @@ class StepTest &lt; ActiveSupport::TestCase @@ -93,6 +97,7 @@ class StepTest &lt; ActiveSupport::TestCase
93 should 'create delayed job' do 97 should 'create delayed job' do
94 @step.start_date = Date.today 98 @step.start_date = Date.today
95 @step.end_date = Date.today 99 @step.end_date = Date.today
  100 + @step.accept_comments = false
96 @step.schedule_activation 101 @step.schedule_activation
97 assert_equal 1, Delayed::Job.count 102 assert_equal 1, Delayed::Job.count
98 assert_equal @step.start_date, Delayed::Job.first.run_at.to_date 103 assert_equal @step.start_date, Delayed::Job.first.run_at.to_date
@@ -102,6 +107,7 @@ class StepTest &lt; ActiveSupport::TestCase @@ -102,6 +107,7 @@ class StepTest &lt; ActiveSupport::TestCase
102 @step.start_date = Date.today 107 @step.start_date = Date.today
103 @step.end_date = Date.today 108 @step.end_date = Date.today
104 @step.schedule_activation 109 @step.schedule_activation
  110 + assert_equal 1, Delayed::Job.count
105 @step.schedule_activation 111 @step.schedule_activation
106 assert_equal 1, Delayed::Job.count 112 assert_equal 1, Delayed::Job.count
107 end 113 end
@@ -116,50 +122,21 @@ class StepTest &lt; ActiveSupport::TestCase @@ -116,50 +122,21 @@ class StepTest &lt; ActiveSupport::TestCase
116 should 'create delayed job even if start date has passed' do 122 should 'create delayed job even if start date has passed' do
117 @step.start_date = Date.today - 2.days 123 @step.start_date = Date.today - 2.days
118 @step.end_date = Date.today 124 @step.end_date = Date.today
  125 + @step.accept_comments = false
119 @step.schedule_activation 126 @step.schedule_activation
120 assert_equal @step.start_date, Delayed::Job.first.run_at.to_date 127 assert_equal @step.start_date, Delayed::Job.first.run_at.to_date
121 end 128 end
122 129
123 - should 'do not create delayed job if end date has passed and step is not published' do  
124 - @step.start_date = Date.today - 5.days  
125 - @step.end_date = Date.today - 2.days  
126 - @step.published = false  
127 - @step.schedule_activation  
128 - assert_equal 0, Delayed::Job.count  
129 - end  
130 -  
131 - should 'create delayed job if end date has passed and step is published' do 130 + should 'create delayed job if end date has passed' do
132 @step.start_date = Date.today - 5.days 131 @step.start_date = Date.today - 5.days
133 @step.end_date = Date.today - 2.days 132 @step.end_date = Date.today - 2.days
134 - @step.published = true  
135 @step.schedule_activation 133 @step.schedule_activation
136 assert_equal @step.end_date + 1.day, Delayed::Job.first.run_at.to_date 134 assert_equal @step.end_date + 1.day, Delayed::Job.first.run_at.to_date
137 end 135 end
138 136
139 - should 'change publish to true on perform delayed job in a active step' do  
140 - @step.start_date = Date.today  
141 - @step.end_date = Date.today + 2.days  
142 - @step.published = false  
143 - @step.save!  
144 - CommunityTrackPlugin::ActivationJob.new(@step.id).perform  
145 - @step.reload  
146 - assert @step.published  
147 - end  
148 -  
149 - should 'reschedule delayed job after change publish to true' do  
150 - @step.start_date = Date.today  
151 - @step.end_date = Date.today + 2.days  
152 - @step.published = false  
153 - @step.save!  
154 - assert_equal @step.start_date, Delayed::Job.first.run_at.to_date  
155 - process_delayed_job_queue  
156 - assert_equal @step.end_date + 1.day, Delayed::Job.first.run_at.to_date  
157 - end  
158 -  
159 - should 'do not schedule delayed job if save but do not modify date fields and published status' do 137 + should 'do not schedule delayed job if save but do not modify date fields' do
160 @step.start_date = Date.today 138 @step.start_date = Date.today
161 @step.end_date = Date.today 139 @step.end_date = Date.today
162 - @step.published = false  
163 @step.save! 140 @step.save!
164 assert_equal 1, Delayed::Job.count 141 assert_equal 1, Delayed::Job.count
165 Delayed::Job.destroy_all 142 Delayed::Job.destroy_all
@@ -177,38 +154,38 @@ class StepTest &lt; ActiveSupport::TestCase @@ -177,38 +154,38 @@ class StepTest &lt; ActiveSupport::TestCase
177 assert_equal 2, step2.position 154 assert_equal 2, step2.position
178 end 155 end
179 156
180 - should 'publish step if it is active' do 157 + should 'accept comments if step is active' do
181 @step.start_date = Date.today 158 @step.start_date = Date.today
182 @step.save! 159 @step.save!
183 - assert !@step.published  
184 - @step.publish 160 + assert !@step.accept_comments
  161 + @step.toggle_activation
185 @step.reload 162 @step.reload
186 - assert @step.published 163 + assert @step.accept_comments
187 end 164 end
188 165
189 - should 'do not publish step if it is not active' do 166 + should 'do not accept comments if step is not active' do
190 @step.start_date = Date.today + 2.days 167 @step.start_date = Date.today + 2.days
191 @step.end_date = Date.today + 3.days 168 @step.end_date = Date.today + 3.days
192 @step.save! 169 @step.save!
193 assert !@step.published 170 assert !@step.published
194 - @step.publish 171 + @step.toggle_activation
195 @step.reload 172 @step.reload
196 assert !@step.published 173 assert !@step.published
197 end 174 end
198 175
199 - should 'unpublish step if it is not active anymore' do 176 + should 'do not accept comments if step is not active anymore' do
200 @step.start_date = Date.today 177 @step.start_date = Date.today
201 @step.save! 178 @step.save!
202 - @step.publish 179 + @step.toggle_activation
203 @step.reload 180 @step.reload
204 - assert @step.published 181 + assert @step.accept_comments
205 182
206 @step.start_date = Date.today - 2.days 183 @step.start_date = Date.today - 2.days
207 @step.end_date = Date.today - 1.day 184 @step.end_date = Date.today - 1.day
208 @step.save! 185 @step.save!
209 - @step.publish 186 + @step.toggle_activation
210 @step.reload 187 @step.reload
211 - assert !@step.published 188 + assert !@step.accept_comments
212 end 189 end
213 190
214 should 'set position to zero if step is hidden' do 191 should 'set position to zero if step is hidden' do
@@ -252,14 +229,60 @@ class StepTest &lt; ActiveSupport::TestCase @@ -252,14 +229,60 @@ class StepTest &lt; ActiveSupport::TestCase
252 @step.hidden = true 229 @step.hidden = true
253 @step.save! 230 @step.save!
254 assert !@step.published 231 assert !@step.published
255 - @step.publish 232 + @step.toggle_activation
256 @step.reload 233 @step.reload
257 assert !@step.published 234 assert !@step.published
258 end 235 end
259 236
260 should 'return enabled tools for a step' do 237 should 'return enabled tools for a step' do
261 - assert_includes @step.enabled_tools, TinyMceArticle  
262 - assert_includes @step.enabled_tools, Forum 238 + assert_includes CommunityTrackPlugin::Step.enabled_tools, TinyMceArticle
  239 + assert_includes CommunityTrackPlugin::Step.enabled_tools, Forum
  240 + end
  241 +
  242 + should 'return class for selected tool' do
  243 + @step.tool_type = 'Forum'
  244 + assert_equal Forum, @step.tool_class
  245 + end
  246 +
  247 + should 'return tool for selected type' do
  248 + @step.tool_type = 'Forum'
  249 + @step.save!
  250 + article = fast_create(Article, :parent_id => @step.id)
  251 + forum = fast_create(Forum, :parent_id => @step.id)
  252 + assert_equal forum, @step.tool
  253 + end
  254 +
  255 + should 'not return tool with different type' do
  256 + @step.tool_type = 'Forum'
  257 + @step.save!
  258 + article = fast_create(Article, :parent_id => @step.id)
  259 + assert_not_equal article, @step.tool
  260 + end
  261 +
  262 + should 'initialize start date and end date with default values' do
  263 + step = CommunityTrackPlugin::Step.new
  264 + assert step.start_date
  265 + assert step.end_date
  266 + end
  267 +
  268 + should 'enable comments on children when step is activated' do
  269 + @step.start_date = Date.today
  270 + @step.save!
  271 + assert !@step.accept_comments
  272 + article = fast_create(Article, :parent_id => @step.id, :profile_id => @step.profile.id, :accept_comments => false)
  273 + assert !article.accept_comments
  274 + @step.toggle_activation
  275 + assert article.reload.accept_comments
  276 + end
  277 +
  278 + should 'enable comments on children when step is active' do
  279 + @step.start_date = Date.today
  280 + @step.start_date = Date.today
  281 + @step.save!
  282 + assert !@step.accept_comments
  283 + @step.toggle_activation
  284 + article = Article.create!(:parent => @step, :profile => @step.profile, :accept_comments => false, :name => "article")
  285 + assert article.reload.accept_comments
263 end 286 end
264 287
265 end 288 end
plugins/community_track/test/unit/community_track_plugin/track_list_block_test.rb
@@ -3,13 +3,14 @@ require File.dirname(__FILE__) + &#39;/../../test_helper&#39; @@ -3,13 +3,14 @@ require File.dirname(__FILE__) + &#39;/../../test_helper&#39;
3 class TrackListBlockTest < ActiveSupport::TestCase 3 class TrackListBlockTest < ActiveSupport::TestCase
4 4
5 def setup 5 def setup
6 - @community = fast_create(Community)  
7 - @track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track', :profile => @community)  
8 -  
9 - box = fast_create(Box, :owner_id => @community.id, :owner_type => @community.class.name) 6 + @profile = fast_create(Community)
  7 + @track = create_track('track', profile)
  8 + box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name)
10 @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box) 9 @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box)
11 end 10 end
12 11
  12 + attr_reader :profile
  13 +
13 should 'describe yourself' do 14 should 'describe yourself' do
14 assert CommunityTrackPlugin::TrackListBlock.description 15 assert CommunityTrackPlugin::TrackListBlock.description
15 end 16 end
@@ -23,38 +24,30 @@ class TrackListBlockTest &lt; ActiveSupport::TestCase @@ -23,38 +24,30 @@ class TrackListBlockTest &lt; ActiveSupport::TestCase
23 end 24 end
24 25
25 should 'list articles only of track type' do 26 should 'list articles only of track type' do
26 - article = fast_create(Article, :profile_id => @community.id)  
27 - assert_includes @community.articles, article 27 + article = fast_create(Article, :profile_id => profile.id)
  28 + assert_includes profile.articles, article
28 assert_equal [@track], @block.tracks 29 assert_equal [@track], @block.tracks
29 end 30 end
30 31
31 should 'list of articles be limited by block configuration' do 32 should 'list of articles be limited by block configuration' do
32 - (@block.limit + 1).times do |i|  
33 - track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community)  
34 - end 33 + (@block.limit + 1).times { |i| create_track("track#{i}", profile) }
35 assert_equal @block.limit, @block.tracks.count 34 assert_equal @block.limit, @block.tracks.count
36 end 35 end
37 36
38 should 'return more link if has more tracks to show' do 37 should 'return more link if has more tracks to show' do
39 - @block.limit.times do |i|  
40 - track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community)  
41 - end 38 + @block.limit.times { |i| create_track("track#{i}", profile) }
42 assert @block.footer 39 assert @block.footer
43 end 40 end
44 41
45 should 'do not return more link if there is no more tracks to show' do 42 should 'do not return more link if there is no more tracks to show' do
46 - (@block.limit-1).times do |i|  
47 - track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community)  
48 - end 43 + (@block.limit-1).times { |i| create_track("track#{i}", profile) }
49 assert !@block.footer 44 assert !@block.footer
50 end 45 end
51 46
52 should 'count all tracks' do 47 should 'count all tracks' do
53 @block.owner.articles.destroy_all 48 @block.owner.articles.destroy_all
54 tracks_to_insert = @block.limit + 1 49 tracks_to_insert = @block.limit + 1
55 - tracks_to_insert.times do |i|  
56 - track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community)  
57 - end 50 + tracks_to_insert.times { |i| create_track("track#{i}", profile) }
58 article = fast_create(Article, :profile_id => @block.owner.id) 51 article = fast_create(Article, :profile_id => @block.owner.id)
59 @block.reload 52 @block.reload
60 assert_includes @block.owner.articles, article 53 assert_includes @block.owner.articles, article
@@ -63,9 +56,7 @@ class TrackListBlockTest &lt; ActiveSupport::TestCase @@ -63,9 +56,7 @@ class TrackListBlockTest &lt; ActiveSupport::TestCase
63 56
64 should 'have a second page if there is more tracks than limit' do 57 should 'have a second page if there is more tracks than limit' do
65 @block.owner.articles.destroy_all 58 @block.owner.articles.destroy_all
66 - (@block.limit+1).times do |i|  
67 - track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community)  
68 - end 59 + (@block.limit+1).times { |i| create_track("track#{i}", profile) }
69 assert @block.has_page?(2) 60 assert @block.has_page?(2)
70 assert !@block.has_page?(3) 61 assert !@block.has_page?(3)
71 end 62 end
@@ -74,9 +65,9 @@ class TrackListBlockTest &lt; ActiveSupport::TestCase @@ -74,9 +65,9 @@ class TrackListBlockTest &lt; ActiveSupport::TestCase
74 @block.owner.articles.destroy_all 65 @block.owner.articles.destroy_all
75 category = fast_create(Category) 66 category = fast_create(Category)
76 category2 = fast_create(Category) 67 category2 = fast_create(Category)
77 - track1 = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track1', :profile => @community)  
78 - track2 = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track2', :profile => @community)  
79 - track3 = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track3', :profile => @community) 68 + track1 = create_track("track1", profile)
  69 + track2 = create_track("track2", profile)
  70 + track3 = create_track("track3", profile)
80 track1.add_category(category) 71 track1.add_category(category)
81 @block.category_ids = [category.id] 72 @block.category_ids = [category.id]
82 assert_equal [track1], @block.all_tracks 73 assert_equal [track1], @block.all_tracks
@@ -85,8 +76,8 @@ class TrackListBlockTest &lt; ActiveSupport::TestCase @@ -85,8 +76,8 @@ class TrackListBlockTest &lt; ActiveSupport::TestCase
85 should 'return all tracks if block does not filter by category' do 76 should 'return all tracks if block does not filter by category' do
86 @block.owner.articles.destroy_all 77 @block.owner.articles.destroy_all
87 category = fast_create(Category) 78 category = fast_create(Category)
88 - track1 = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track1', :profile => @community)  
89 - track2 = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track2', :profile => @community) 79 + track1 = create_track("track1", profile)
  80 + track2 = create_track("track2", profile)
90 track1.add_category(category) 81 track1.add_category(category)
91 assert_includes @block.all_tracks, track1 82 assert_includes @block.all_tracks, track1
92 assert_includes @block.all_tracks, track2 83 assert_includes @block.all_tracks, track2
@@ -102,4 +93,22 @@ class TrackListBlockTest &lt; ActiveSupport::TestCase @@ -102,4 +93,22 @@ class TrackListBlockTest &lt; ActiveSupport::TestCase
102 assert_equal [1, 2], @block.category_ids 93 assert_equal [1, 2], @block.category_ids
103 end 94 end
104 95
  96 + should 'define expiration condition' do
  97 + condition = CommunityTrackPlugin::TrackListBlock.expire_on
  98 + assert !condition[:profile].empty?
  99 + assert !condition[:environment].empty?
  100 + end
  101 +
  102 + should 'return track list block categories' do
  103 + category1 = fast_create(Category)
  104 + category2 = fast_create(Category)
  105 + @block.category_ids = [category1.id, category2.id]
  106 + assert_equivalent [category1, category2], @block.categories
  107 + end
  108 +
  109 + should 'return nothing if track list block has no categories' do
  110 + @block.category_ids = []
  111 + assert_equivalent [], @block.categories
  112 + end
  113 +
105 end 114 end
plugins/community_track/test/unit/community_track_plugin/track_test.rb
@@ -3,10 +3,10 @@ require File.dirname(__FILE__) + &#39;/../../test_helper&#39; @@ -3,10 +3,10 @@ require File.dirname(__FILE__) + &#39;/../../test_helper&#39;
3 class TrackTest < ActiveSupport::TestCase 3 class TrackTest < ActiveSupport::TestCase
4 4
5 def setup 5 def setup
6 - profile = fast_create(Community)  
7 - @track = CommunityTrackPlugin::Track.create!(:profile => profile, :name => 'track')  
8 - @step = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => 'step', :profile => profile)  
9 - @tool = fast_create(Article, :parent_id => @step.id, :profile_id => profile.id) 6 + @profile = fast_create(Community)
  7 + @track = create_track('track', @profile)
  8 + @step = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => 'step', :profile => @profile)
  9 + @tool = fast_create(Article, :parent_id => @step.id, :profile_id => @profile.id)
10 end 10 end
11 11
12 should 'describe yourself' do 12 should 'describe yourself' do
@@ -39,10 +39,13 @@ class TrackTest &lt; ActiveSupport::TestCase @@ -39,10 +39,13 @@ class TrackTest &lt; ActiveSupport::TestCase
39 assert_equal [@step], @track.steps_unsorted 39 assert_equal [@step], @track.steps_unsorted
40 end 40 end
41 41
42 - should 'return category name' do  
43 - category = fast_create(Category, :name => 'category')  
44 - @track.add_category(category, true)  
45 - assert_equal 'category', @track.category_name 42 + should 'return name of the top category' do
  43 + top = fast_create(Category, :name => 'top category')
  44 + category1 = fast_create(Category, :name => 'category1', :parent_id => top.id )
  45 + category2 = fast_create(Category, :name => 'category2', :parent_id => category1.id )
  46 + @track.categories.delete_all
  47 + @track.add_category(category2, true)
  48 + assert_equal 'top category', @track.category_name
46 end 49 end
47 50
48 should 'return empty for category name if it has no category' do 51 should 'return empty for category name if it has no category' do
@@ -52,6 +55,7 @@ class TrackTest &lt; ActiveSupport::TestCase @@ -52,6 +55,7 @@ class TrackTest &lt; ActiveSupport::TestCase
52 55
53 should 'return category name of first category' do 56 should 'return category name of first category' do
54 category = fast_create(Category, :name => 'category') 57 category = fast_create(Category, :name => 'category')
  58 + @track.categories.delete_all
55 @track.add_category(category, true) 59 @track.add_category(category, true)
56 category2 = fast_create(Category, :name => 'category2') 60 category2 = fast_create(Category, :name => 'category2')
57 @track.add_category(category2, true) 61 @track.add_category(category2, true)
@@ -124,4 +128,15 @@ class TrackTest &lt; ActiveSupport::TestCase @@ -124,4 +128,15 @@ class TrackTest &lt; ActiveSupport::TestCase
124 assert_equal '', @track.first_paragraph 128 assert_equal '', @track.first_paragraph
125 end 129 end
126 130
  131 + should 'not be able to create a track without category' do
  132 + track = CommunityTrackPlugin::Track.create(:profile => @profile, :name => 'track')
  133 + assert track.errors.invalid?(:categories)
  134 + end
  135 +
  136 + should 'not be able to save a track without category' do
  137 + @track.categories.delete_all
  138 + @track.save
  139 + assert @track.errors.invalid?(:categories)
  140 + end
  141 +
127 end 142 end
plugins/community_track/views/blocks/_track.rhtml
1 <% extend CommunityTrackPlugin::TrackHelper %> 1 <% extend CommunityTrackPlugin::TrackHelper %>
  2 +<% extend CommunityTrackPlugin::StepHelper %>
2 <div class="item <%= category_class(track) %>"> 3 <div class="item <%= category_class(track) %>">
3 <div class="track_content"> 4 <div class="track_content">
4 <div class="lead"> 5 <div class="lead">
@@ -10,10 +11,14 @@ @@ -10,10 +11,14 @@
10 <div class="steps"> 11 <div class="steps">
11 <h3><%= _("Steps") %></h3> 12 <h3><%= _("Steps") %></h3>
12 <% track.steps.each do |step| %> 13 <% track.steps.each do |step| %>
13 - <div class="step <%= block.status_class(step) %>">  
14 - <div class="position"><%= step.position %></div>  
15 - <%= link_to step.name, step.url %>  
16 - </div> 14 + <% link_to_step(step) do %>
  15 + <span class="step <%= block.status_class(step) %>">
  16 + <span class="position"><%= step.position %></span>
  17 + <span class="legend"><%= status_description(step) %></span>
  18 + <span class="tool_icon button with-text icon-new icon-new<%= step.tool_class.icon_name if step.tool_class %>"></span>
  19 + <span class="name"><%= step.name %></span>
  20 + </span>
  21 + <% end %>
17 <% end %> 22 <% end %>
18 </div> 23 </div>
19 </div> 24 </div>
plugins/community_track/views/blocks/_track_card.rhtml
@@ -17,10 +17,12 @@ @@ -17,10 +17,12 @@
17 </div> 17 </div>
18 <div class="track_stats"> 18 <div class="track_stats">
19 <div class="comments"> 19 <div class="comments">
20 - <%= "#{track_card.comments_count} comments" %> 20 + <span class="counter"><%= "#{track_card.comments_count}" %></span>
  21 + <span class="label"><%= _('comments') %></span>
21 </div> 22 </div>
22 <div class="hits"> 23 <div class="hits">
23 - <%= "#{track_card.hits} hits" %> 24 + <span class="counter"><%= "#{track_card.hits}" %></span>
  25 + <span class="label"><%= _('acessos') %></span>
24 </div> 26 </div>
25 </div> 27 </div>
26 </a> 28 </a>
plugins/community_track/views/cms/community_track_plugin/_step.rhtml
@@ -12,6 +12,8 @@ @@ -12,6 +12,8 @@
12 { :size => 14 }) 12 { :size => 14 })
13 )) %> 13 )) %>
14 14
  15 + <%= labelled_form_field(_('Tool type'), select(:article, :tool_type, CommunityTrackPlugin::Step.enabled_tools.map {|t| [t.short_description, t.name]} )) %>
  16 + <%= hidden_field_tag('success_back_to', url_for(@article.parent.view_url)) %>
15 </div> 17 </div>
16 18
17 <%= labelled_form_field check_box(:article, :hidden) + _('Hidden Step'), '' %> 19 <%= labelled_form_field check_box(:article, :hidden) + _('Hidden Step'), '' %>
plugins/community_track/views/cms/community_track_plugin/_track.rhtml
@@ -10,10 +10,6 @@ @@ -10,10 +10,6 @@
10 <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :body_label => 'Description:'} %> 10 <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :body_label => 'Description:'} %>
11 11
12 <div> 12 <div>
13 - <% f.fields_for :image_builder, @article.image do |i| %>  
14 - <%= file_field_or_thumbnail(_('Image:'), @article.image, i) %>  
15 - <% end %>  
16 -  
17 <%= labelled_form_field(_('Goals:'), text_area(:article, :goals, :rows => 3, :cols => 64)) %> 13 <%= labelled_form_field(_('Goals:'), text_area(:article, :goals, :rows => 3, :cols => 64)) %>
18 <%= labelled_form_field(_('Expected Results:'), text_area(:article, :expected_results, :rows => 3, :cols => 64)) %> 14 <%= labelled_form_field(_('Expected Results:'), text_area(:article, :expected_results, :rows => 3, :cols => 64)) %>
19 </div> 15 </div>
plugins/community_track/views/content_viewer/_step_item.rhtml 0 → 100644
@@ -0,0 +1,41 @@ @@ -0,0 +1,41 @@
  1 +<li class="step <%= status_class(step_item) %>">
  2 + <%= hidden_field_tag "step_ids[]", step_item.id %>
  3 + <div class="tool_link" onclick="l=jQuery('#step_link_<%= step_item.id%>'); if(l.length) window.location = l.first().attr('href');">
  4 + <div class="position"><%= step_item.hidden ? '' : step_item.position %></div>
  5 + <div class="content">
  6 + <div class="date">
  7 + <%= show_period(step_item.start_date, step_item.end_date) %>
  8 + </div>
  9 + <div class="legend">
  10 + <%= status_description(step_item) %>
  11 + </div>
  12 + <div class="name"><span class="tool_icon button with-text icon-new icon-new<%= step_item.tool_class.icon_name if step_item.tool_class %>"></span> <%= step_item.name %></div>
  13 + <div class="lead"><%= step_item.body %></div>
  14 + <div class="tools">
  15 + <% if step_item.tool %>
  16 + <%= _('Tool: ') %>
  17 +
  18 + <% link_to_step(step_item, {:id => "step_link_#{step_item.id}"}) do %>
  19 + <%= step_item.tool.name %>
  20 + <% end %>
  21 +
  22 + <% elsif step_item.allow_create?(user) && step_item.tool_class %>
  23 + <a id="step_link_<%= step_item.id %>" href="<%= url_for({:controller => 'cms', :action => 'new', :type => step_item.tool_class, :parent_id => step_item, :success_back_to => url_for(step_item.parent.view_url)}) %>" class="button icon-new with-text icon-new<%= step_item.tool_class.icon_name %>"><%= _('Create %s' % step_item.tool_class.short_description) %></a>
  24 + <% else %>
  25 + <% link_to_step(step_item, {:id => "step_link_#{step_item.id}"}, '') %>
  26 + <% end %>
  27 + </div>
  28 + </div>
  29 + </div>
  30 + <div class="step_actions">
  31 + <% if step_item.allow_edit?(user) && !remove_content_button(:edit) %>
  32 + <%= button('eyes', _('View'), step_item.url) %>
  33 + <% content = content_tag('span', label_for_edit_article(step_item)) %>
  34 + <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'edit', :id => step_item.id, :success_back_to => url_for(step_item.parent.view_url) }) %>
  35 + <%= expirable_button step_item, :edit, content, url %>
  36 + <% end %>
  37 + <% if step_item.accept_uploads? && step_item.allow_create?(user) %>
  38 + <%= button('upload-file', _('Upload files'), profile.admin_url.merge(:controller => 'cms', :action => 'upload_files', :parent_id => step_item)) unless remove_content_button(:upload)%>
  39 + <% end %>
  40 + </div>
  41 +</li>
plugins/community_track/views/content_viewer/step.rhtml
@@ -9,23 +9,20 @@ @@ -9,23 +9,20 @@
9 <div> 9 <div>
10 <%= step.body %> 10 <%= step.body %>
11 </div> 11 </div>
12 - <h3><%= _("Tools") %></h3>  
13 - <% if step.allow_create?(user) %> 12 + <% if step.allow_create?(user) && !step.tool && step.tool_class %>
  13 + <h3><%= _("Tool") %></h3>
14 <div class="actions"> 14 <div class="actions">
15 - <% step.enabled_tools.each do |klass, attrs| %>  
16 - <% content_tag('a', :href => url_for({:controller => 'cms', :action => 'new', :type => klass.name, :parent_id => @page}), :class => "button with-text icon-new icon-new#{klass.icon_name}") do %>  
17 - <%= _("New #{attrs[:name]}") %>  
18 - <% end %>  
19 - <% end %> 15 + <a href="<%= url_for({:controller => 'cms', :action => 'new', :type => step.tool_type.constantize, :parent_id => @page}) %>" class="button with-text icon-new icon-new<%= step.tool_class.icon_name %>"><%= _('Create %s' % step.tool_class.short_description) %></a>
20 </div> 16 </div>
21 <% end %> 17 <% end %>
22 - <div class="tools">  
23 - <% step.tools.each do |tool| %> 18 + <% if step.tool %>
  19 + <h3><%= _("Tool") %></h3>
  20 + <div class="tools">
24 <div class="item"> 21 <div class="item">
25 <div class="name"> 22 <div class="name">
26 - <%= link_to tool.name, tool.url, :class=>"button with-text icon-new icon-new#{tool.class.icon_name}" %> 23 + <%= link_to(step.tool.name, step.tool.view_url, :class=>"button with-text icon-new icon-new#{step.tool.class.icon_name}") %>
  24 + </div>
27 </div> 25 </div>
28 - </div>  
29 - <% end %>  
30 - </div> 26 + </div>
  27 + <% end %>
31 </div> 28 </div>
plugins/community_track/views/content_viewer/track.rhtml
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 <h3><%= _("Steps") %></h3> 9 <h3><%= _("Steps") %></h3>
10 10
11 <% if track.allow_create?(user) %> 11 <% if track.allow_create?(user) %>
12 - <div class="actions"> 12 + <div class="track actions">
13 <% content_tag('a', :href => url_for({:controller => 'cms', :action => 'new', :type => "CommunityTrackPlugin::Step", :parent_id => track.id}), :class => 'button with-text icon-add') do %> 13 <% content_tag('a', :href => url_for({:controller => 'cms', :action => 'new', :type => "CommunityTrackPlugin::Step", :parent_id => track.id}), :class => 'button with-text icon-add') do %>
14 <strong><%= _("New %s") % CommunityTrackPlugin::Step.short_description %></strong> 14 <strong><%= _("New %s") % CommunityTrackPlugin::Step.short_description %></strong>
15 <% end %> 15 <% end %>
@@ -28,40 +28,15 @@ @@ -28,40 +28,15 @@
28 <% end %> 28 <% end %>
29 29
30 <ul id="sortable" class="step_list"> 30 <ul id="sortable" class="step_list">
31 - <% track.steps.each do |step| %>  
32 - <li class="step">  
33 - <%= hidden_field_tag "step_ids[]", step.id %>  
34 - <div class="position"><%= step.position %></div>  
35 - <div class="content">  
36 - <div class="date">  
37 - <%= show_period(step.start_date, step.end_date) %>  
38 - </div>  
39 - <div class="name"><%= link_to step.name, step.url %></div>  
40 - <div class="lead"><%= step.body %></div>  
41 - </div>  
42 - </li>  
43 - <% end %> 31 + <%= render :partial => 'step_item', :collection => track.steps %>
44 </ul> 32 </ul>
45 - <% if track.allow_create?(user) && !track.hidden_steps.empty? %>  
46 - <div id="hidden_steps">  
47 - <h3><%= _('Hidden Steps') %></h3>  
48 - <ul class="step_list">  
49 - <% track.hidden_steps.each do |step| %>  
50 - <li class="step">  
51 - <%= hidden_field_tag "step_ids[]", step.id %>  
52 - <div class="position"></div>  
53 - <div class="content">  
54 - <div class="date">  
55 - <%= show_period(step.start_date, step.end_date) %>  
56 - </div>  
57 - <div class="name"><%= link_to step.name, step.url %></div>  
58 - <div class="lead"><%= step.body %></div>  
59 - </div>  
60 - </li>  
61 - <% end %>  
62 - </ul>  
63 - </div>  
64 - <% end %> 33 + <% if track.allow_create?(user) && !track.hidden_steps.empty? %>
  34 + <div id="hidden_steps">
  35 + <h3><%= _('Hidden Steps') %></h3>
  36 + <ul class="step_list">
  37 + <%= render :partial => 'step_item', :collection => track.hidden_steps %>
  38 + </ul>
  39 + </div>
  40 + <% end %>
65 </div> 41 </div>
66 <% end %> 42 <% end %>
67 -</div>  
plugins/work_assignment/lib/work_assignment_plugin.rb
@@ -18,7 +18,7 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin @@ -18,7 +18,7 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin
18 end 18 end
19 19
20 def content_types 20 def content_types
21 - [WorkAssignmentPlugin::WorkAssignment] if context.profile.organization? 21 + [WorkAssignmentPlugin::WorkAssignment] if context.respond_to?(:profile) && context.profile.organization?
22 end 22 end
23 23
24 def stylesheet? 24 def stylesheet?
test/functional/cms_controller_test.rb
@@ -1708,6 +1708,17 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1708,6 +1708,17 @@ class CmsControllerTest &lt; ActionController::TestCase
1708 end 1708 end
1709 end 1709 end
1710 1710
  1711 + should 'go back to specified url when saving with success' do
  1712 + post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'changed by me', :body => 'content ...' }, :success_back_to => '/'
  1713 + assert_redirected_to '/'
  1714 + end
  1715 +
  1716 + should 'redirect back to specified url when edit with success' do
  1717 + article = @profile.articles.create!(:name => 'myarticle')
  1718 + post :edit, :profile => 'testinguser', :id => article.id, :success_back_to => '/'
  1719 + assert_redirected_to '/'
  1720 + end
  1721 +
1711 protected 1722 protected
1712 1723
1713 # FIXME this is to avoid adding an extra dependency for a proper JSON parser. 1724 # FIXME this is to avoid adding an extra dependency for a proper JSON parser.
test/unit/article_test.rb
@@ -1405,30 +1405,32 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1405,30 +1405,32 @@ class ArticleTest &lt; ActiveSupport::TestCase
1405 should 'return only folders' do 1405 should 'return only folders' do
1406 not_folders = [RssFeed, TinyMceArticle, Event, TextileArticle] 1406 not_folders = [RssFeed, TinyMceArticle, Event, TextileArticle]
1407 folders = [Folder, Blog, Gallery, Forum] 1407 folders = [Folder, Blog, Gallery, Forum]
  1408 + profile = fast_create(Profile)
1408 1409
1409 not_folders.each do |klass| 1410 not_folders.each do |klass|
1410 item = fast_create(klass) 1411 item = fast_create(klass)
1411 - assert_not_includes Article.folders, item 1412 + assert_not_includes Article.folders(profile), item
1412 end 1413 end
1413 1414
1414 folders.each do |klass| 1415 folders.each do |klass|
1415 item = fast_create(klass) 1416 item = fast_create(klass)
1416 - assert_includes Article.folders, item 1417 + assert_includes Article.folders(profile), item
1417 end 1418 end
1418 end 1419 end
1419 1420
1420 should 'return no folders' do 1421 should 'return no folders' do
1421 not_folders = [RssFeed, TinyMceArticle, Event, TextileArticle] 1422 not_folders = [RssFeed, TinyMceArticle, Event, TextileArticle]
1422 folders = [Folder, Blog, Gallery, Forum] 1423 folders = [Folder, Blog, Gallery, Forum]
  1424 + profile = fast_create(Profile)
1423 1425
1424 not_folders.each do |klass| 1426 not_folders.each do |klass|
1425 item = fast_create(klass) 1427 item = fast_create(klass)
1426 - assert_includes Article.no_folders, item 1428 + assert_includes Article.no_folders(profile), item
1427 end 1429 end
1428 1430
1429 folders.each do |klass| 1431 folders.each do |klass|
1430 item = fast_create(klass) 1432 item = fast_create(klass)
1431 - assert_not_includes Article.no_folders, item 1433 + assert_not_includes Article.no_folders(profile), item
1432 end 1434 end
1433 end 1435 end
1434 1436
test/unit/blog_test.rb
@@ -198,7 +198,8 @@ class BlogTest &lt; ActiveSupport::TestCase @@ -198,7 +198,8 @@ class BlogTest &lt; ActiveSupport::TestCase
198 #FIXME This should be used until there is a migration to fix all blogs that 198 #FIXME This should be used until there is a migration to fix all blogs that
199 # already have folders inside them 199 # already have folders inside them
200 should 'not list folders in posts' do 200 should 'not list folders in posts' do
201 - blog = fast_create(Blog) 201 + p = create_user('testuser').person
  202 + blog = Blog.create!(:profile => p, :name => 'Blog test')
202 folder = fast_create(Folder, :parent_id => blog.id) 203 folder = fast_create(Folder, :parent_id => blog.id)
203 article = fast_create(TextileArticle, :parent_id => blog.id) 204 article = fast_create(TextileArticle, :parent_id => blog.id)
204 205
@@ -212,7 +213,8 @@ class BlogTest &lt; ActiveSupport::TestCase @@ -212,7 +213,8 @@ class BlogTest &lt; ActiveSupport::TestCase
212 end 213 end
213 214
214 should 'know when blog has or when has no posts' do 215 should 'know when blog has or when has no posts' do
215 - blog = fast_create(Blog) 216 + p = create_user('testuser').person
  217 + blog = Blog.create!(:profile => p, :name => 'Blog test')
216 assert blog.empty? 218 assert blog.empty?
217 fast_create(TextileArticle, :parent_id => blog.id) 219 fast_create(TextileArticle, :parent_id => blog.id)
218 assert ! blog.empty? 220 assert ! blog.empty?
test/unit/profile_test.rb
@@ -1934,4 +1934,20 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -1934,4 +1934,20 @@ class ProfileTest &lt; ActiveSupport::TestCase
1934 assert_not_includes Profile.public, p4 1934 assert_not_includes Profile.public, p4
1935 end 1935 end
1936 1936
  1937 + should 'folder_types search for folders in the plugins' do
  1938 + class Folder1 < Folder
  1939 + end
  1940 +
  1941 + class Plugin1 < Noosfero::Plugin
  1942 + def content_types
  1943 + [Folder1]
  1944 + end
  1945 + end
  1946 +
  1947 + environment = Environment.default
  1948 + environment.enable_plugin(Plugin1)
  1949 + plugins = Noosfero::Plugin::Manager.new(environment, self)
  1950 + p = fast_create(Profile)
  1951 + assert p.folder_types.include?('ProfileTest::Folder1')
  1952 + end
1937 end 1953 end