Commit a42673855d1b963f63de320e8ee754e10a8e7238

Authored by Rodrigo Souto
2 parents e5d9ef3a 5187f433

Merge branch 'track-fixes'

Showing 36 changed files with 530 additions and 228 deletions   Show diff stats
app/controllers/my_profile/cms_controller.rb
... ... @@ -66,6 +66,7 @@ class CmsController < MyProfileController
66 66 end
67 67  
68 68 def edit
  69 + @success_back_to = params[:success_back_to]
69 70 @article = profile.articles.find(params[:id])
70 71 @parent_id = params[:parent_id]
71 72 @type = params[:type] || @article.class.to_s
... ... @@ -87,7 +88,7 @@ class CmsController < MyProfileController
87 88 if @article.update_attributes(params[:article])
88 89 if !continue
89 90 if @article.content_type.nil? || @article.image?
90   - redirect_to @article.view_url
  91 + success_redirect
91 92 else
92 93 redirect_to :action => (@article.parent ? 'view' : 'index'), :id => @article.parent
93 94 end
... ... @@ -99,6 +100,7 @@ class CmsController < MyProfileController
99 100 def new
100 101 # FIXME this method should share some logic wirh edit !!!
101 102  
  103 + @success_back_to = params[:success_back_to]
102 104 # user must choose an article type first
103 105  
104 106 @parent = profile.articles.find(params[:parent_id]) if params && params[:parent_id]
... ... @@ -145,7 +147,7 @@ class CmsController < MyProfileController
145 147 if continue
146 148 redirect_to :action => 'edit', :id => @article
147 149 else
148   - redirect_to @article.view_url
  150 + success_redirect
149 151 end
150 152 return
151 153 end
... ... @@ -403,4 +405,12 @@ class CmsController < MyProfileController
403 405 true
404 406 end
405 407  
  408 + def success_redirect
  409 + if !@success_back_to.blank?
  410 + redirect_to @success_back_to
  411 + else
  412 + redirect_to @article.view_url
  413 + end
  414 + end
  415 +
406 416 end
... ...
app/models/article.rb
... ... @@ -449,8 +449,8 @@ class Article < ActiveRecord::Base
449 449 end
450 450  
451 451 named_scope :published, :conditions => { :published => true }
452   - named_scope :folders, :conditions => { :type => folder_types}
453   - named_scope :no_folders, :conditions => ['type NOT IN (?)', folder_types]
  452 + named_scope :folders, lambda {|profile|{:conditions => { :type => profile.folder_types} }}
  453 + named_scope :no_folders, lambda {|profile|{:conditions => ['type NOT IN (?)', profile.folder_types]}}
454 454 named_scope :galleries, :conditions => { :type => 'Gallery' }
455 455 named_scope :images, :conditions => { :is_image => true }
456 456 named_scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ]
... ...
app/models/blog.rb
... ... @@ -6,7 +6,7 @@ class Blog < Folder
6 6 #FIXME This should be used until there is a migration to fix all blogs that
7 7 # already have folders inside them
8 8 def posts_with_no_folders
9   - posts_without_no_folders.no_folders
  9 + posts_without_no_folders.no_folders(profile)
10 10 end
11 11 alias_method_chain :posts, :no_folders
12 12  
... ...
app/models/profile.rb
... ... @@ -761,8 +761,20 @@ private :generate_url, :url_options
761 761 !environment.enabled?('disable_contact_' + self.class.name.downcase)
762 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 776 def folders
765   - articles.folders
  777 + articles.folders(self)
766 778 end
767 779  
768 780 def image_galleries
... ...
app/views/cms/edit.rhtml
... ... @@ -10,6 +10,8 @@
10 10  
11 11 <%= hidden_field_tag('back_to', @back_to) %>
12 12  
  13 + <%= hidden_field_tag('success_back_to', @success_back_to) %>
  14 +
13 15 <%= render :partial => partial_for_class(@article.class), :locals => { :f => f } %>
14 16  
15 17 <% 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 25 end
26 26  
27 27 def all_tracks
28   - @per_page = 5 #FIXME
  28 + @per_page = 8 #FIXME
29 29 @block = Block.find(params[:id])
30 30 @tracks = @block.tracks(1, @per_page)
31 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 @@
  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 1 class CommunityTrackPlugin::Step < Folder
2 2  
3 3 settings_items :hidden, :type => :boolean, :default => false
  4 + settings_items :tool_type, :type => String
4 5  
5 6 alias :tools :children
6 7  
... ... @@ -17,13 +18,19 @@ class CommunityTrackPlugin::Step &lt; Folder
17 18 after_save :schedule_activation
18 19  
19 20 before_create do |step|
20   - step.published = false
  21 + step.accept_comments = false
21 22 true
22 23 end
23 24  
24 25 before_create :set_hidden_position
25 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 34 def set_hidden_position
28 35 if hidden
29 36 decrement_positions_on_lower_items
... ... @@ -48,11 +55,11 @@ class CommunityTrackPlugin::Step &lt; Folder
48 55 end
49 56  
50 57 def accept_comments?
51   - false
  58 + accept_comments
52 59 end
53 60  
54   - def enabled_tools
55   - {TinyMceArticle => {:name => _('Article')}, Forum => {:name => _('Forum')}}
  61 + def self.enabled_tools
  62 + [TinyMceArticle, Forum]
56 63 end
57 64  
58 65 def to_html(options = {})
... ... @@ -75,31 +82,31 @@ class CommunityTrackPlugin::Step &lt; Folder
75 82 end
76 83  
77 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 88 CommunityTrackPlugin::ActivationJob.find(id).destroy_all
83 89 Delayed::Job.enqueue(CommunityTrackPlugin::ActivationJob.new(self.id), 0, schedule_date)
84 90 end
85 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 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 110 end
104 111  
105 112 end
... ...
plugins/community_track/lib/community_track_plugin/step_helper.rb
1 1 module CommunityTrackPlugin::StepHelper
2 2  
3 3 def self.status_descriptions
4   - [_('Finished'), _('In progress'), _('Waiting')]
  4 + [_('Closed'), _('Join!'), _('Soon')]
5 5 end
6 6  
7 7 def self.status_classes
... ... @@ -16,9 +16,11 @@ module CommunityTrackPlugin::StepHelper
16 16 CommunityTrackPlugin::StepHelper.status_classes[status_index(step)]
17 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 24 end
23 25  
24 26 protected
... ...
plugins/community_track/lib/community_track_plugin/track.rb
... ... @@ -3,6 +3,12 @@ class CommunityTrackPlugin::Track &lt; Folder
3 3 settings_items :goals, :type => :string
4 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 12 def self.icon_name(article = nil)
7 13 'community-track'
8 14 end
... ... @@ -57,7 +63,7 @@ class CommunityTrackPlugin::Track &lt; Folder
57 63  
58 64 def category_name
59 65 category = categories.first
60   - category ? category.name : ''
  66 + category ? category.top_ancestor.name : ''
61 67 end
62 68  
63 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 34 settings[:category_ids] = ids.uniq.map{|item| item.to_i unless item.to_i.zero?}.compact
35 35 end
36 36  
  37 + def categories
  38 + Category.find(category_ids)
  39 + end
  40 +
37 41 def all_tracks
38 42 tracks = owner.articles.where(:type => 'CommunityTrackPlugin::Track')
39 43 if !category_ids.empty?
... ... @@ -61,4 +65,8 @@ class CommunityTrackPlugin::TrackListBlock &lt; Block
61 65 end
62 66 end
63 67  
  68 + def self.expire_on
  69 + { :profile => [:article, :category], :environment => [:article, :category] }
  70 + end
  71 +
64 72 end
... ...
plugins/community_track/lib/ext/article.rb 0 → 100644
... ... @@ -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 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 7 background-color: #CCEBD6;
8 8 color: #338533;
9 9 }
10 10  
11   -.step_waiting, #article .step_waiting a {
  11 +.step_waiting, #article .step_waiting {
12 12 background-color: #FFFFD1;
13 13 color: #D17519;
14 14 }
15 15  
16   -.step_finished, #article .step_finished a {
  16 +.step_finished, #article .step_finished {
17 17 background-color: #D1FFFF;
18 18 color: #00297A;
19 19 }
... ... @@ -24,6 +24,7 @@
24 24  
25 25 .step {
26 26 font-weight: bold;
  27 + margin-bottom: 3px;
27 28 }
28 29  
29 30 .track_list .item .step {
... ... @@ -73,6 +74,11 @@
73 74 .steps .step {
74 75 margin-top: 3px;
75 76 margin-bottom: 3px;
  77 + display: block;
  78 +}
  79 +
  80 +.steps a {
  81 + text-decoration: none;
76 82 }
77 83  
78 84 .track_list .item_card .track_stats {
... ... @@ -126,13 +132,15 @@
126 132 #track .position {
127 133 font-size: 24px;
128 134 font-weight: bold;
129   - float: left;
130 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 141 font-weight: bold;
135 142 color: #333;
  143 + clear: both;
136 144 }
137 145  
138 146 #track .step .name a:hover {
... ... @@ -142,6 +150,7 @@
142 150 #track .step .date {
143 151 font-size: 12px;
144 152 color: #AAA;
  153 + float: left;
145 154 }
146 155  
147 156 #track .step .lead {
... ... @@ -151,7 +160,7 @@
151 160  
152 161 #track .content {
153 162 margin: 6px 0px;
154   - border-bottom: 1px solid #DDDDDD;
  163 + display: inline-block;
155 164 }
156 165  
157 166 #track .ui-state-default .content {
... ... @@ -199,3 +208,60 @@
199 208 width: 115px;
200 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  
8 8 def setup
9 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 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 13 user = create_user('testinguser')
... ... @@ -39,9 +39,4 @@ class CmsControllerTest &lt; ActionController::TestCase
39 39 assert_equal 'changed', @step.name
40 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 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  
12 12 def setup
13 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 17 user = create_user('testinguser')
21 18 login_as(user.login)
... ... @@ -24,15 +21,15 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
24 21  
25 22 should 'show actions for tracks when user has permission for edit' do
26 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 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 28 user = create_user('intruder')
32 29 logout
33 30 login_as(user.login)
34 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 33 end
37 34  
38 35 should 'do not show new button at article toolbar for tracks' do
... ... @@ -45,7 +42,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
45 42  
46 43 should 'display steps for tracks' do
47 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 46 end
50 47  
51 48 should 'display hidden field with step id' do
... ... @@ -59,22 +56,28 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
59 56 end
60 57  
61 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 60 get :view_page, @step.url
64 61 assert_tag :tag => 'div', :attributes => { :class => 'tools' }, :descendant => { :tag => 'div', :attributes => { :class => 'item' } }
65 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 65 get :view_page, @step.url
69 66 assert_tag :tag => 'div', :attributes => {:id => 'step' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } }
70 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 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 71 assert_tag 'div', :attributes => {:class => 'actions' }, :descendant => { :tag => 'a', :attributes => { :class => 'button with-text icon-new icon-newtext-html' } }
76 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 81 should 'do not show actions for steps when user has not permission for edit' do
79 82 user = create_user('intruder')
80 83 logout
... ... @@ -104,7 +107,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
104 107 @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box)
105 108 @profile.boxes << box
106 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 111 end
109 112  
110 113 should 'render tracks in track card list block' do
... ... @@ -112,8 +115,8 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
112 115 @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box)
113 116 @profile.boxes << box
114 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 120 end
118 121  
119 122 should 'render link to display more tracks in track list block' do
... ... @@ -121,9 +124,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
121 124 @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box)
122 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 129 get :view_page, @step.url
129 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 137 @block.more_another_page = true
137 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 142 get :view_page, @step.url
144 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 12 @response = ActionController::TestResponse.new
13 13  
14 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 17 @user = create_user('testinguser')
18 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 8  
9 9 def setup
10 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 13 box = fast_create(Box, :owner_id => @community.id, :owner_type => 'Community')
14 14 @card_block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box)
... ... @@ -26,17 +26,13 @@ class CommunityTrackPluginPublicControllerTest &lt; ActionController::TestCase
26 26 end
27 27  
28 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 30 xhr :get, :view_tracks, :id => @block.id, :page => 1, :per_page => 10
33 31 assert_equal 10, @response.body.scan(/item/).size
34 32 end
35 33  
36 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 36 xhr :get, :view_tracks, :id => @block.id, :page => 1
41 37 assert_equal @block.limit, @response.body.scan(/item/).size
42 38 end
... ... @@ -47,9 +43,7 @@ class CommunityTrackPluginPublicControllerTest &lt; ActionController::TestCase
47 43 end
48 44  
49 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 47 get :all_tracks, :id => @block.id
54 48 assert assigns['show_more']
55 49 assert_match /track_list_more_#{@block.id}/, @response.body
... ...
plugins/community_track/test/test_helper.rb
1 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 @@
  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 @@
  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  
7 7 def setup
8 8 @step = CommunityTrackPlugin::Step.new
  9 + @profile = fast_create(Community)
  10 + @step.stubs(:profile).returns(@profile)
9 11 @step.stubs(:active?).returns(false)
10 12 @step.stubs(:finished?).returns(false)
11 13 @step.stubs(:waiting?).returns(false)
... ... @@ -28,11 +30,31 @@ class StepHelperTest &lt; ActiveSupport::TestCase
28 30  
29 31 should 'return a description for status' do
30 32 @step.stubs(:waiting?).returns(true)
31   - assert_equal _('Waiting'), status_description(@step)
  33 + assert_equal _('Soon'), status_description(@step)
32 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 58 end
37 59  
38 60 end
... ...
plugins/community_track/test/unit/community_track_plugin/step_test.rb
... ... @@ -4,7 +4,11 @@ class StepTest &lt; ActiveSupport::TestCase
4 4  
5 5 def setup
6 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 12 @step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today)
9 13 Delayed::Job.destroy_all
10 14 end
... ... @@ -17,10 +21,10 @@ class StepTest &lt; ActiveSupport::TestCase
17 21 assert CommunityTrackPlugin::Step.short_description
18 22 end
19 23  
20   - should 'set published to false on create' do
  24 + should 'set accept_comments to false on create' do
21 25 today = Date.today
22 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 28 end
25 29  
26 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 97 should 'create delayed job' do
94 98 @step.start_date = Date.today
95 99 @step.end_date = Date.today
  100 + @step.accept_comments = false
96 101 @step.schedule_activation
97 102 assert_equal 1, Delayed::Job.count
98 103 assert_equal @step.start_date, Delayed::Job.first.run_at.to_date
... ... @@ -102,6 +107,7 @@ class StepTest &lt; ActiveSupport::TestCase
102 107 @step.start_date = Date.today
103 108 @step.end_date = Date.today
104 109 @step.schedule_activation
  110 + assert_equal 1, Delayed::Job.count
105 111 @step.schedule_activation
106 112 assert_equal 1, Delayed::Job.count
107 113 end
... ... @@ -116,50 +122,21 @@ class StepTest &lt; ActiveSupport::TestCase
116 122 should 'create delayed job even if start date has passed' do
117 123 @step.start_date = Date.today - 2.days
118 124 @step.end_date = Date.today
  125 + @step.accept_comments = false
119 126 @step.schedule_activation
120 127 assert_equal @step.start_date, Delayed::Job.first.run_at.to_date
121 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 131 @step.start_date = Date.today - 5.days
133 132 @step.end_date = Date.today - 2.days
134   - @step.published = true
135 133 @step.schedule_activation
136 134 assert_equal @step.end_date + 1.day, Delayed::Job.first.run_at.to_date
137 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 138 @step.start_date = Date.today
161 139 @step.end_date = Date.today
162   - @step.published = false
163 140 @step.save!
164 141 assert_equal 1, Delayed::Job.count
165 142 Delayed::Job.destroy_all
... ... @@ -177,38 +154,38 @@ class StepTest &lt; ActiveSupport::TestCase
177 154 assert_equal 2, step2.position
178 155 end
179 156  
180   - should 'publish step if it is active' do
  157 + should 'accept comments if step is active' do
181 158 @step.start_date = Date.today
182 159 @step.save!
183   - assert !@step.published
184   - @step.publish
  160 + assert !@step.accept_comments
  161 + @step.toggle_activation
185 162 @step.reload
186   - assert @step.published
  163 + assert @step.accept_comments
187 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 167 @step.start_date = Date.today + 2.days
191 168 @step.end_date = Date.today + 3.days
192 169 @step.save!
193 170 assert !@step.published
194   - @step.publish
  171 + @step.toggle_activation
195 172 @step.reload
196 173 assert !@step.published
197 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 177 @step.start_date = Date.today
201 178 @step.save!
202   - @step.publish
  179 + @step.toggle_activation
203 180 @step.reload
204   - assert @step.published
  181 + assert @step.accept_comments
205 182  
206 183 @step.start_date = Date.today - 2.days
207 184 @step.end_date = Date.today - 1.day
208 185 @step.save!
209   - @step.publish
  186 + @step.toggle_activation
210 187 @step.reload
211   - assert !@step.published
  188 + assert !@step.accept_comments
212 189 end
213 190  
214 191 should 'set position to zero if step is hidden' do
... ... @@ -252,14 +229,60 @@ class StepTest &lt; ActiveSupport::TestCase
252 229 @step.hidden = true
253 230 @step.save!
254 231 assert !@step.published
255   - @step.publish
  232 + @step.toggle_activation
256 233 @step.reload
257 234 assert !@step.published
258 235 end
259 236  
260 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 286 end
264 287  
265 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 3 class TrackListBlockTest < ActiveSupport::TestCase
4 4  
5 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 9 @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box)
11 10 end
12 11  
  12 + attr_reader :profile
  13 +
13 14 should 'describe yourself' do
14 15 assert CommunityTrackPlugin::TrackListBlock.description
15 16 end
... ... @@ -23,38 +24,30 @@ class TrackListBlockTest &lt; ActiveSupport::TestCase
23 24 end
24 25  
25 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 29 assert_equal [@track], @block.tracks
29 30 end
30 31  
31 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 34 assert_equal @block.limit, @block.tracks.count
36 35 end
37 36  
38 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 39 assert @block.footer
43 40 end
44 41  
45 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 44 assert !@block.footer
50 45 end
51 46  
52 47 should 'count all tracks' do
53 48 @block.owner.articles.destroy_all
54 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 51 article = fast_create(Article, :profile_id => @block.owner.id)
59 52 @block.reload
60 53 assert_includes @block.owner.articles, article
... ... @@ -63,9 +56,7 @@ class TrackListBlockTest &lt; ActiveSupport::TestCase
63 56  
64 57 should 'have a second page if there is more tracks than limit' do
65 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 60 assert @block.has_page?(2)
70 61 assert !@block.has_page?(3)
71 62 end
... ... @@ -74,9 +65,9 @@ class TrackListBlockTest &lt; ActiveSupport::TestCase
74 65 @block.owner.articles.destroy_all
75 66 category = fast_create(Category)
76 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 71 track1.add_category(category)
81 72 @block.category_ids = [category.id]
82 73 assert_equal [track1], @block.all_tracks
... ... @@ -85,8 +76,8 @@ class TrackListBlockTest &lt; ActiveSupport::TestCase
85 76 should 'return all tracks if block does not filter by category' do
86 77 @block.owner.articles.destroy_all
87 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 81 track1.add_category(category)
91 82 assert_includes @block.all_tracks, track1
92 83 assert_includes @block.all_tracks, track2
... ... @@ -102,4 +93,22 @@ class TrackListBlockTest &lt; ActiveSupport::TestCase
102 93 assert_equal [1, 2], @block.category_ids
103 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 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 3 class TrackTest < ActiveSupport::TestCase
4 4  
5 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 10 end
11 11  
12 12 should 'describe yourself' do
... ... @@ -39,10 +39,13 @@ class TrackTest &lt; ActiveSupport::TestCase
39 39 assert_equal [@step], @track.steps_unsorted
40 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 49 end
47 50  
48 51 should 'return empty for category name if it has no category' do
... ... @@ -52,6 +55,7 @@ class TrackTest &lt; ActiveSupport::TestCase
52 55  
53 56 should 'return category name of first category' do
54 57 category = fast_create(Category, :name => 'category')
  58 + @track.categories.delete_all
55 59 @track.add_category(category, true)
56 60 category2 = fast_create(Category, :name => 'category2')
57 61 @track.add_category(category2, true)
... ... @@ -124,4 +128,15 @@ class TrackTest &lt; ActiveSupport::TestCase
124 128 assert_equal '', @track.first_paragraph
125 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 142 end
... ...
plugins/community_track/views/blocks/_track.rhtml
1 1 <% extend CommunityTrackPlugin::TrackHelper %>
  2 +<% extend CommunityTrackPlugin::StepHelper %>
2 3 <div class="item <%= category_class(track) %>">
3 4 <div class="track_content">
4 5 <div class="lead">
... ... @@ -10,10 +11,14 @@
10 11 <div class="steps">
11 12 <h3><%= _("Steps") %></h3>
12 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 22 <% end %>
18 23 </div>
19 24 </div>
... ...
plugins/community_track/views/blocks/_track_card.rhtml
... ... @@ -17,10 +17,12 @@
17 17 </div>
18 18 <div class="track_stats">
19 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 22 </div>
22 23 <div class="hits">
23   - <%= "#{track_card.hits} hits" %>
  24 + <span class="counter"><%= "#{track_card.hits}" %></span>
  25 + <span class="label"><%= _('acessos') %></span>
24 26 </div>
25 27 </div>
26 28 </a>
... ...
plugins/community_track/views/cms/community_track_plugin/_step.rhtml
... ... @@ -12,6 +12,8 @@
12 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 17 </div>
16 18  
17 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 <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :body_label => 'Description:'} %>
11 11  
12 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 13 <%= labelled_form_field(_('Goals:'), text_area(:article, :goals, :rows => 3, :cols => 64)) %>
18 14 <%= labelled_form_field(_('Expected Results:'), text_area(:article, :expected_results, :rows => 3, :cols => 64)) %>
19 15 </div>
... ...
plugins/community_track/views/content_viewer/_step_item.rhtml 0 → 100644
... ... @@ -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 9 <div>
10 10 <%= step.body %>
11 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 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 16 </div>
21 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 21 <div class="item">
25 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 25 </div>
28   - </div>
29   - <% end %>
30   - </div>
  26 + </div>
  27 + <% end %>
31 28 </div>
... ...
plugins/community_track/views/content_viewer/track.rhtml
... ... @@ -9,7 +9,7 @@
9 9 <h3><%= _("Steps") %></h3>
10 10  
11 11 <% if track.allow_create?(user) %>
12   - <div class="actions">
  12 + <div class="track actions">
13 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 14 <strong><%= _("New %s") % CommunityTrackPlugin::Step.short_description %></strong>
15 15 <% end %>
... ... @@ -28,40 +28,15 @@
28 28 <% end %>
29 29  
30 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 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 41 </div>
66 42 <% end %>
67   -</div>
... ...
plugins/work_assignment/lib/work_assignment_plugin.rb
... ... @@ -18,7 +18,7 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin
18 18 end
19 19  
20 20 def content_types
21   - [WorkAssignmentPlugin::WorkAssignment] if context.profile.organization?
  21 + [WorkAssignmentPlugin::WorkAssignment] if context.respond_to?(:profile) && context.profile.organization?
22 22 end
23 23  
24 24 def stylesheet?
... ...
test/functional/cms_controller_test.rb
... ... @@ -1708,6 +1708,17 @@ class CmsControllerTest &lt; ActionController::TestCase
1708 1708 end
1709 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 1722 protected
1712 1723  
1713 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 1405 should 'return only folders' do
1406 1406 not_folders = [RssFeed, TinyMceArticle, Event, TextileArticle]
1407 1407 folders = [Folder, Blog, Gallery, Forum]
  1408 + profile = fast_create(Profile)
1408 1409  
1409 1410 not_folders.each do |klass|
1410 1411 item = fast_create(klass)
1411   - assert_not_includes Article.folders, item
  1412 + assert_not_includes Article.folders(profile), item
1412 1413 end
1413 1414  
1414 1415 folders.each do |klass|
1415 1416 item = fast_create(klass)
1416   - assert_includes Article.folders, item
  1417 + assert_includes Article.folders(profile), item
1417 1418 end
1418 1419 end
1419 1420  
1420 1421 should 'return no folders' do
1421 1422 not_folders = [RssFeed, TinyMceArticle, Event, TextileArticle]
1422 1423 folders = [Folder, Blog, Gallery, Forum]
  1424 + profile = fast_create(Profile)
1423 1425  
1424 1426 not_folders.each do |klass|
1425 1427 item = fast_create(klass)
1426   - assert_includes Article.no_folders, item
  1428 + assert_includes Article.no_folders(profile), item
1427 1429 end
1428 1430  
1429 1431 folders.each do |klass|
1430 1432 item = fast_create(klass)
1431   - assert_not_includes Article.no_folders, item
  1433 + assert_not_includes Article.no_folders(profile), item
1432 1434 end
1433 1435 end
1434 1436  
... ...
test/unit/blog_test.rb
... ... @@ -198,7 +198,8 @@ class BlogTest &lt; ActiveSupport::TestCase
198 198 #FIXME This should be used until there is a migration to fix all blogs that
199 199 # already have folders inside them
200 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 203 folder = fast_create(Folder, :parent_id => blog.id)
203 204 article = fast_create(TextileArticle, :parent_id => blog.id)
204 205  
... ... @@ -212,7 +213,8 @@ class BlogTest &lt; ActiveSupport::TestCase
212 213 end
213 214  
214 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 218 assert blog.empty?
217 219 fast_create(TextileArticle, :parent_id => blog.id)
218 220 assert ! blog.empty?
... ...
test/unit/profile_test.rb
... ... @@ -1934,4 +1934,20 @@ class ProfileTest &lt; ActiveSupport::TestCase
1934 1934 assert_not_includes Profile.public, p4
1935 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 1953 end
... ...