Commit cd68aebb65fe497758bd021a24f068ba077a8091
Exists in
web_steps_improvements
and in
6 other branches
Merge branch 'master_community_track' into 'master'
fixes community track plugin Signed-off-by: Evandro Magalhaes Leite Junior <evandro.leite@serpro.gov.br> Signed-off-by: Gustavo Jaruga <darkshades@gmail.com> Signed-off-by: Leandro Nunes dos Santos <leandro.santos@serpro.gov.br> Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com> Signed-off-by: Victor Costa <vfcosta@gmail.com> See merge request !816
Showing
21 changed files
with
161 additions
and
51 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
@@ -3,6 +3,7 @@ class CmsController < MyProfileController | @@ -3,6 +3,7 @@ class CmsController < MyProfileController | ||
3 | protect 'edit_profile', :profile, :only => [:set_home_page] | 3 | protect 'edit_profile', :profile, :only => [:set_home_page] |
4 | 4 | ||
5 | include ArticleHelper | 5 | include ArticleHelper |
6 | + include CategoriesHelper | ||
6 | 7 | ||
7 | def search_tags | 8 | def search_tags |
8 | arg = params[:term].downcase | 9 | arg = params[:term].downcase |
@@ -256,12 +257,7 @@ class CmsController < MyProfileController | @@ -256,12 +257,7 @@ class CmsController < MyProfileController | ||
256 | 257 | ||
257 | def update_categories | 258 | def update_categories |
258 | @object = params[:id] ? @profile.articles.find(params[:id]) : Article.new | 259 | @object = params[:id] ? @profile.articles.find(params[:id]) : Article.new |
259 | - @categories = @toplevel_categories = environment.top_level_categories | ||
260 | - if params[:category_id] | ||
261 | - @current_category = Category.find(params[:category_id]) | ||
262 | - @categories = @current_category.children | ||
263 | - end | ||
264 | - render :template => 'shared/update_categories', :locals => { :category => @current_category, :object_name => 'article' } | 260 | + render_categories 'article' |
265 | end | 261 | end |
266 | 262 | ||
267 | def search_communities_to_publish | 263 | def search_communities_to_publish |
app/controllers/my_profile/profile_design_controller.rb
@@ -6,6 +6,7 @@ class ProfileDesignController < BoxOrganizerController | @@ -6,6 +6,7 @@ class ProfileDesignController < BoxOrganizerController | ||
6 | 6 | ||
7 | before_filter :protect_uneditable_block, :only => [:save] | 7 | before_filter :protect_uneditable_block, :only => [:save] |
8 | before_filter :protect_fixed_block, :only => [:move_block] | 8 | before_filter :protect_fixed_block, :only => [:move_block] |
9 | + include CategoriesHelper | ||
9 | 10 | ||
10 | def protect_uneditable_block | 11 | def protect_uneditable_block |
11 | block = boxes_holder.blocks.find(params[:id].gsub(/^block-/, '')) | 12 | block = boxes_holder.blocks.find(params[:id].gsub(/^block-/, '')) |
@@ -67,4 +68,9 @@ class ProfileDesignController < BoxOrganizerController | @@ -67,4 +68,9 @@ class ProfileDesignController < BoxOrganizerController | ||
67 | blocks | 68 | blocks |
68 | end | 69 | end |
69 | 70 | ||
71 | + def update_categories | ||
72 | + @object = params[:id] ? @profile.blocks.find(params[:id]) : Block.new | ||
73 | + render_categories 'block' | ||
74 | + end | ||
75 | + | ||
70 | end | 76 | end |
app/controllers/my_profile/profile_editor_controller.rb
@@ -9,6 +9,7 @@ class ProfileEditorController < MyProfileController | @@ -9,6 +9,7 @@ class ProfileEditorController < MyProfileController | ||
9 | before_filter :check_user_can_edit_header_footer, :only => [:header_footer] | 9 | before_filter :check_user_can_edit_header_footer, :only => [:header_footer] |
10 | helper_method :has_welcome_page | 10 | helper_method :has_welcome_page |
11 | helper CustomFieldsHelper | 11 | helper CustomFieldsHelper |
12 | + include CategoriesHelper | ||
12 | 13 | ||
13 | def index | 14 | def index |
14 | @pending_tasks = Task.to(profile).pending.without_spam.select{|i| user.has_permission?(i.permission, profile)} | 15 | @pending_tasks = Task.to(profile).pending.without_spam.select{|i| user.has_permission?(i.permission, profile)} |
@@ -60,12 +61,7 @@ class ProfileEditorController < MyProfileController | @@ -60,12 +61,7 @@ class ProfileEditorController < MyProfileController | ||
60 | 61 | ||
61 | def update_categories | 62 | def update_categories |
62 | @object = profile | 63 | @object = profile |
63 | - @categories = @toplevel_categories = environment.top_level_categories | ||
64 | - if params[:category_id] | ||
65 | - @current_category = Category.find(params[:category_id]) | ||
66 | - @categories = @current_category.children | ||
67 | - end | ||
68 | - render :template => 'shared/update_categories', :locals => { :category => @current_category, :object_name => 'profile_data' } | 64 | + render_categories 'profile_data' |
69 | end | 65 | end |
70 | 66 | ||
71 | def header_footer | 67 | def header_footer |
app/helpers/categories_helper.rb
@@ -34,4 +34,15 @@ module CategoriesHelper | @@ -34,4 +34,15 @@ module CategoriesHelper | ||
34 | {:id => category_id ? "select-category-#{category_id}-link" : nil, :remote => true, :class => html_class}.merge(html_options) | 34 | {:id => category_id ? "select-category-#{category_id}-link" : nil, :remote => true, :class => html_class}.merge(html_options) |
35 | end | 35 | end |
36 | 36 | ||
37 | + def render_categories object_name | ||
38 | + @toplevel_categories = environment.top_level_categories | ||
39 | + if params[:category_id] | ||
40 | + @current_category = Category.find(params[:category_id]) | ||
41 | + @categories = @current_category.children | ||
42 | + else | ||
43 | + @categories = @toplevel_categories | ||
44 | + end | ||
45 | + render :template => 'shared/update_categories', :locals => { :category => @current_category, :object_name => object_name } | ||
46 | + end | ||
47 | + | ||
37 | end | 48 | end |
app/models/block.rb
@@ -4,8 +4,6 @@ class Block < ActiveRecord::Base | @@ -4,8 +4,6 @@ class Block < ActiveRecord::Base | ||
4 | :visualization_format, :language, :display_user, | 4 | :visualization_format, :language, :display_user, |
5 | :box, :edit_modes, :move_modes, :mirror | 5 | :box, :edit_modes, :move_modes, :mirror |
6 | 6 | ||
7 | - # to be able to generate HTML | ||
8 | - include ActionView::Helpers::UrlHelper | ||
9 | include ActionView::Helpers::TagHelper | 7 | include ActionView::Helpers::TagHelper |
10 | 8 | ||
11 | # Block-specific stuff | 9 | # Block-specific stuff |
plugins/community_track/controllers/public/community_track_plugin_public_controller.rb
@@ -6,14 +6,15 @@ class CommunityTrackPluginPublicController < PublicController | @@ -6,14 +6,15 @@ class CommunityTrackPluginPublicController < PublicController | ||
6 | 6 | ||
7 | def view_tracks | 7 | def view_tracks |
8 | block = Block.find(params[:id]) | 8 | block = Block.find(params[:id]) |
9 | + instance_eval(&block.set_seed) | ||
9 | p = params[:page].to_i | 10 | p = params[:page].to_i |
10 | per_page = params[:per_page] | 11 | per_page = params[:per_page] |
11 | per_page ||= block.limit | 12 | per_page ||= block.limit |
12 | per_page = per_page.to_i | 13 | per_page = per_page.to_i |
13 | - tracks = block.tracks(p, per_page) | 14 | + @tracks = block.tracks(p, per_page) |
14 | 15 | ||
15 | render :update do |page| | 16 | render :update do |page| |
16 | - page.insert_html :bottom, "track_list_#{block.id}", :partial => "blocks/#{block.track_partial}", :collection => tracks, :locals => {:block => block} | 17 | + page.insert_html :bottom, "track_list_#{block.id}", :partial => "blocks/#{block.track_partial}", :collection => @tracks, :locals => {:block => block} |
17 | 18 | ||
18 | if block.has_page?(p+1, per_page) | 19 | if block.has_page?(p+1, per_page) |
19 | page.replace_html "track_list_more_#{block.id}", :partial => 'blocks/track_list_more', :locals => {:block => block, :page => p+1, :force_same_page => params[:force_same_page], :per_page => per_page} | 20 | page.replace_html "track_list_more_#{block.id}", :partial => 'blocks/track_list_more', :locals => {:block => block, :page => p+1, :force_same_page => params[:force_same_page], :per_page => per_page} |
@@ -26,6 +27,7 @@ class CommunityTrackPluginPublicController < PublicController | @@ -26,6 +27,7 @@ class CommunityTrackPluginPublicController < PublicController | ||
26 | def all_tracks | 27 | def all_tracks |
27 | @per_page = 8 #FIXME | 28 | @per_page = 8 #FIXME |
28 | @block = Block.find(params[:id]) | 29 | @block = Block.find(params[:id]) |
30 | + instance_eval(&@block.set_seed) | ||
29 | @tracks = @block.tracks(1, @per_page) | 31 | @tracks = @block.tracks(1, @per_page) |
30 | @show_more = @block.has_page?(2, @per_page) | 32 | @show_more = @block.has_page?(2, @per_page) |
31 | end | 33 | end |
plugins/community_track/lib/community_track_plugin.rb
@@ -13,7 +13,7 @@ class CommunityTrackPlugin < Noosfero::Plugin | @@ -13,7 +13,7 @@ class CommunityTrackPlugin < Noosfero::Plugin | ||
13 | end | 13 | end |
14 | 14 | ||
15 | def content_types | 15 | def content_types |
16 | - if context.respond_to?(:params) && context.params | 16 | + if context.kind_of?(CmsController) && context.respond_to?(:params) && context.params |
17 | types = [] | 17 | types = [] |
18 | parent_id = context.params[:parent_id] | 18 | parent_id = context.params[:parent_id] |
19 | types << CommunityTrackPlugin::Track if context.profile.community? && !parent_id | 19 | types << CommunityTrackPlugin::Track if context.profile.community? && !parent_id |
plugins/community_track/lib/community_track_plugin/step.rb
@@ -60,7 +60,7 @@ class CommunityTrackPlugin::Step < Folder | @@ -60,7 +60,7 @@ class CommunityTrackPlugin::Step < Folder | ||
60 | accept_comments | 60 | accept_comments |
61 | end | 61 | end |
62 | 62 | ||
63 | - def self.enabled_tools | 63 | + def enabled_tools |
64 | [TinyMceArticle, Forum] | 64 | [TinyMceArticle, Forum] |
65 | end | 65 | end |
66 | 66 |
plugins/community_track/lib/community_track_plugin/track.rb
@@ -7,6 +7,11 @@ class CommunityTrackPlugin::Track < Folder | @@ -7,6 +7,11 @@ class CommunityTrackPlugin::Track < Folder | ||
7 | 7 | ||
8 | attr_accessible :goals, :expected_results | 8 | attr_accessible :goals, :expected_results |
9 | 9 | ||
10 | + def comments_count | ||
11 | + @comments_count = sum_children_comments self unless @comments_count | ||
12 | + @comments_count | ||
13 | + end | ||
14 | + | ||
10 | def validate_categories | 15 | def validate_categories |
11 | errors.add(:categories, _('should not be blank.')) if categories.empty? && pending_categorizations.blank? | 16 | errors.add(:categories, _('should not be blank.')) if categories.empty? && pending_categorizations.blank? |
12 | end | 17 | end |
@@ -49,8 +54,13 @@ class CommunityTrackPlugin::Track < Folder | @@ -49,8 +54,13 @@ class CommunityTrackPlugin::Track < Folder | ||
49 | false | 54 | false |
50 | end | 55 | end |
51 | 56 | ||
52 | - def comments_count | ||
53 | - steps_unsorted.joins(:children).sum('children_articles.comments_count') | 57 | + def sum_children_comments node |
58 | + result = 0 | ||
59 | + node.children.each do |c| | ||
60 | + result += c.comments_count | ||
61 | + result += sum_children_comments c | ||
62 | + end | ||
63 | + result | ||
54 | end | 64 | end |
55 | 65 | ||
56 | def css_class_name | 66 | def css_class_name |
plugins/community_track/lib/community_track_plugin/track_list_block.rb
@@ -5,6 +5,9 @@ class CommunityTrackPlugin::TrackListBlock < Block | @@ -5,6 +5,9 @@ class CommunityTrackPlugin::TrackListBlock < Block | ||
5 | settings_items :limit, :type => :integer, :default => 3 | 5 | settings_items :limit, :type => :integer, :default => 3 |
6 | settings_items :more_another_page, :type => :boolean, :default => false | 6 | settings_items :more_another_page, :type => :boolean, :default => false |
7 | settings_items :category_ids, :type => Array, :default => [] | 7 | settings_items :category_ids, :type => Array, :default => [] |
8 | + settings_items :order, :type => :string, :default => 'hits' | ||
9 | + | ||
10 | + attr_accessible :more_another_page, :category_ids, :order | ||
8 | 11 | ||
9 | def self.description | 12 | def self.description |
10 | _('Track List') | 13 | _('Track List') |
@@ -23,7 +26,16 @@ class CommunityTrackPlugin::TrackListBlock < Block | @@ -23,7 +26,16 @@ class CommunityTrackPlugin::TrackListBlock < Block | ||
23 | end | 26 | end |
24 | 27 | ||
25 | def tracks(page=1, per_page=limit) | 28 | def tracks(page=1, per_page=limit) |
26 | - all_tracks.order('hits DESC').paginate(:per_page => per_page, :page => page) | 29 | + tracks = all_tracks |
30 | + tracks = case order | ||
31 | + when 'newer' | ||
32 | + tracks.order('created_at DESC') | ||
33 | + when 'random' | ||
34 | + tracks.order('random()') | ||
35 | + else | ||
36 | + tracks.order('hits DESC') | ||
37 | + end | ||
38 | + tracks.paginate(:per_page => per_page, :page => page) | ||
27 | end | 39 | end |
28 | 40 | ||
29 | def count_tracks | 41 | def count_tracks |
@@ -50,27 +62,34 @@ class CommunityTrackPlugin::TrackListBlock < Block | @@ -50,27 +62,34 @@ class CommunityTrackPlugin::TrackListBlock < Block | ||
50 | tracks | 62 | tracks |
51 | end | 63 | end |
52 | 64 | ||
53 | - def content(args={}) | ||
54 | - block = self | ||
55 | - proc do | ||
56 | - render :file => 'blocks/track_list', :locals => {:block => block} | ||
57 | - end | ||
58 | - end | ||
59 | - | ||
60 | def has_page?(page, per_page=limit) | 65 | def has_page?(page, per_page=limit) |
61 | return (page-1) * per_page < count_tracks | 66 | return (page-1) * per_page < count_tracks |
62 | end | 67 | end |
63 | 68 | ||
64 | - def footer | 69 | + def self.expire_on |
70 | + { :profile => [:article, :category], :environment => [:article, :category] } | ||
71 | + end | ||
72 | + | ||
73 | + def timeout | ||
74 | + 1.hour | ||
75 | + end | ||
76 | + | ||
77 | + def set_seed(new_seed=false) | ||
65 | block = self | 78 | block = self |
66 | - return nil if !has_page?(2) | ||
67 | proc do | 79 | proc do |
68 | - render :partial => 'blocks/track_list_more', :locals => {:block => block, :page => 2, :per_page => block.limit} | 80 | + if block.order == 'random' |
81 | + if new_seed || cookies[:_noosfero_community_tracks_rand_seed].blank? | ||
82 | + cookies[:_noosfero_community_tracks_rand_seed] = {value: rand, expires: Time.now + 600} | ||
83 | + end | ||
84 | + #XXX postgresql specific | ||
85 | + seed_val = Environment.connection.quote(cookies[:_noosfero_community_tracks_rand_seed]) | ||
86 | + Environment.connection.execute("select setseed(#{seed_val})") | ||
87 | + end | ||
69 | end | 88 | end |
70 | end | 89 | end |
71 | 90 | ||
72 | - def self.expire_on | ||
73 | - { :profile => [:article, :category], :environment => [:article, :category] } | 91 | + def self.order_options |
92 | + {_('Hits') => 'hits', _('Random') => 'random', _('Most Recent') => 'newer'} | ||
74 | end | 93 | end |
75 | 94 | ||
76 | end | 95 | end |
plugins/community_track/test/functional/community_track_plugin_cms_controller_test.rb
@@ -3,6 +3,9 @@ require_relative '../test_helper' | @@ -3,6 +3,9 @@ require_relative '../test_helper' | ||
3 | class CmsControllerTest < ActionController::TestCase | 3 | class CmsControllerTest < ActionController::TestCase |
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | + @environment = Environment.default | ||
7 | + @environment.enabled_plugins = ['CommunityTrackPlugin'] | ||
8 | + @environment.save! | ||
6 | @profile = fast_create(Community) | 9 | @profile = fast_create(Community) |
7 | @track = create_track('track', @profile) | 10 | @track = create_track('track', @profile) |
8 | @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) |
@@ -36,4 +39,15 @@ class CmsControllerTest < ActionController::TestCase | @@ -36,4 +39,15 @@ class CmsControllerTest < ActionController::TestCase | ||
36 | assert_equal 'changed', @step.name | 39 | assert_equal 'changed', @step.name |
37 | end | 40 | end |
38 | 41 | ||
42 | + should 'have parent_id present in form' do | ||
43 | + get :new, :parent_id => @track.id, :profile => @profile.identifier, :type => CommunityTrackPlugin::Step | ||
44 | + assert_tag :tag => 'input', :attributes => { :name => 'parent_id' } | ||
45 | + end | ||
46 | + | ||
47 | + should 'be able to create an step with a parent' do | ||
48 | + amount_of_steps = CommunityTrackPlugin::Step.count | ||
49 | + post :new, :parent_id => @track.id, :profile => @profile.identifier, :type => CommunityTrackPlugin::Step, :article => {:name => 'some', :body => 'some'} | ||
50 | + assert_equal amount_of_steps + 1, CommunityTrackPlugin::Step.count | ||
51 | + end | ||
52 | + | ||
39 | end | 53 | end |
plugins/community_track/test/functional/community_track_plugin_public_controller_test.rb
@@ -97,4 +97,19 @@ class CommunityTrackPluginPublicControllerTest < ActionController::TestCase | @@ -97,4 +97,19 @@ class CommunityTrackPluginPublicControllerTest < ActionController::TestCase | ||
97 | assert_tag :tag => 'div', :attributes => {:id => 'errorExplanation'} | 97 | assert_tag :tag => 'div', :attributes => {:id => 'errorExplanation'} |
98 | end | 98 | end |
99 | 99 | ||
100 | + should 'do not repeat tracks when paging a block with random order' do | ||
101 | + @track.destroy | ||
102 | + @block.order = 'random' | ||
103 | + @block.save! | ||
104 | + | ||
105 | + per_page = 4 | ||
106 | + (per_page*3).times {|i| create_track("track_#{i}", @community) } | ||
107 | + | ||
108 | + tracks = 3.times.map do |i| | ||
109 | + xhr :get, :view_tracks, :id => @block.id, :page => i+1, :per_page => per_page | ||
110 | + assigns[:tracks].all | ||
111 | + end.flatten | ||
112 | + assert_equal tracks.count, tracks.uniq.count | ||
113 | + end | ||
114 | + | ||
100 | end | 115 | end |
plugins/community_track/test/unit/community_track_plugin/step_test.rb
@@ -235,8 +235,8 @@ class StepTest < ActiveSupport::TestCase | @@ -235,8 +235,8 @@ class StepTest < ActiveSupport::TestCase | ||
235 | end | 235 | end |
236 | 236 | ||
237 | should 'return enabled tools for a step' do | 237 | should 'return enabled tools for a step' do |
238 | - assert_includes CommunityTrackPlugin::Step.enabled_tools, TinyMceArticle | ||
239 | - assert_includes CommunityTrackPlugin::Step.enabled_tools, Forum | 238 | + assert_includes @step.enabled_tools, TinyMceArticle |
239 | + assert_includes @step.enabled_tools, Forum | ||
240 | end | 240 | end |
241 | 241 | ||
242 | should 'return class for selected tool' do | 242 | should 'return class for selected tool' do |
plugins/community_track/test/unit/community_track_plugin/track_list_block_test.rb
@@ -9,7 +9,7 @@ class TrackListBlockTest < ActiveSupport::TestCase | @@ -9,7 +9,7 @@ class TrackListBlockTest < ActiveSupport::TestCase | ||
9 | @block = create(CommunityTrackPlugin::TrackListBlock, :box => box) | 9 | @block = create(CommunityTrackPlugin::TrackListBlock, :box => box) |
10 | end | 10 | end |
11 | 11 | ||
12 | - attr_reader :profile | 12 | + attr_reader :profile, :track |
13 | 13 | ||
14 | should 'describe yourself' do | 14 | should 'describe yourself' do |
15 | assert CommunityTrackPlugin::TrackListBlock.description | 15 | assert CommunityTrackPlugin::TrackListBlock.description |
@@ -34,16 +34,6 @@ class TrackListBlockTest < ActiveSupport::TestCase | @@ -34,16 +34,6 @@ class TrackListBlockTest < ActiveSupport::TestCase | ||
34 | assert_equal @block.limit, @block.tracks.to_a.size | 34 | assert_equal @block.limit, @block.tracks.to_a.size |
35 | end | 35 | end |
36 | 36 | ||
37 | - should 'return more link if has more tracks to show' do | ||
38 | - @block.limit.times { |i| create_track("track#{i}", profile) } | ||
39 | - assert @block.footer | ||
40 | - end | ||
41 | - | ||
42 | - should 'do not return more link if there is no more tracks to show' do | ||
43 | - (@block.limit-1).times { |i| create_track("track#{i}", profile) } | ||
44 | - refute @block.footer | ||
45 | - end | ||
46 | - | ||
47 | should 'count all tracks' do | 37 | should 'count all tracks' do |
48 | @block.owner.articles.destroy_all | 38 | @block.owner.articles.destroy_all |
49 | tracks_to_insert = @block.limit + 1 | 39 | tracks_to_insert = @block.limit + 1 |
@@ -111,4 +101,20 @@ class TrackListBlockTest < ActiveSupport::TestCase | @@ -111,4 +101,20 @@ class TrackListBlockTest < ActiveSupport::TestCase | ||
111 | assert_equivalent [], @block.categories | 101 | assert_equivalent [], @block.categories |
112 | end | 102 | end |
113 | 103 | ||
104 | + should 'list tracks in hits order by default' do | ||
105 | + track2 = create_track("track2", profile) | ||
106 | + track.update_attribute(:hits, 2) | ||
107 | + track2.update_attribute(:hits, 1) | ||
108 | + assert_equal [track, track2], @block.tracks | ||
109 | + end | ||
110 | + | ||
111 | + should 'list tracks in newer order' do | ||
112 | + @block.order = 'newer' | ||
113 | + @block.save! | ||
114 | + track2 = create_track("track2", profile) | ||
115 | + track2.update_attribute(:created_at, Date.today) | ||
116 | + track.update_attribute(:created_at, Date.today - 1.day) | ||
117 | + assert_equal [track2, track], @block.tracks | ||
118 | + end | ||
119 | + | ||
114 | end | 120 | end |
plugins/community_track/test/unit/community_track_plugin/track_test.rb
@@ -3,10 +3,12 @@ require_relative '../../test_helper' | @@ -3,10 +3,12 @@ require_relative '../../test_helper' | ||
3 | class TrackTest < ActiveSupport::TestCase | 3 | class TrackTest < ActiveSupport::TestCase |
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | - @profile = fast_create(Community) | 6 | + @profile = create(Community) |
7 | @track = create_track('track', @profile) | 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) | 8 | + @step = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => DateTime.now, :end_date => DateTime.now, :name => 'step', :profile => @profile) |
9 | + @track.children << @step | ||
9 | @tool = fast_create(Article, :parent_id => @step.id, :profile_id => @profile.id) | 10 | @tool = fast_create(Article, :parent_id => @step.id, :profile_id => @profile.id) |
11 | + @step.children << @tool | ||
10 | end | 12 | end |
11 | 13 | ||
12 | should 'describe yourself' do | 14 | should 'describe yourself' do |
@@ -25,8 +27,18 @@ class TrackTest < ActiveSupport::TestCase | @@ -25,8 +27,18 @@ class TrackTest < ActiveSupport::TestCase | ||
25 | assert_equal 0, @track.comments_count | 27 | assert_equal 0, @track.comments_count |
26 | owner = create_user('testuser').person | 28 | owner = create_user('testuser').person |
27 | article = create(Article, :name => 'article', :parent_id => @step.id, :profile_id => owner.id) | 29 | article = create(Article, :name => 'article', :parent_id => @step.id, :profile_id => owner.id) |
30 | + @track.children << @step | ||
31 | + @step.children << article | ||
28 | comment = create(Comment, :source => article, :author_id => owner.id) | 32 | comment = create(Comment, :source => article, :author_id => owner.id) |
29 | - assert_equal 1, @track.comments_count | 33 | + @step2 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => DateTime.now, :end_date => DateTime.now, :name => 'step2', :profile => @profile) |
34 | + @step2.tool_type = 'Forum' | ||
35 | + forum = fast_create(Forum, :parent_id => @step2.id, :profile_id => owner.id) | ||
36 | + article_forum = create(Article, :name => 'article_forum', :parent_id => forum.id, :profile_id => owner.id) | ||
37 | + forum.children << article_forum | ||
38 | + forum_comment = create(Comment, :source => article_forum, :author_id => owner.id) | ||
39 | + @track.children = [@step, @step2] | ||
40 | + @track = Article.find(@track.id) | ||
41 | + assert_equal 2, @track.comments_count | ||
30 | end | 42 | end |
31 | 43 | ||
32 | should 'return children steps' do | 44 | should 'return children steps' do |
@@ -35,6 +47,7 @@ class TrackTest < ActiveSupport::TestCase | @@ -35,6 +47,7 @@ class TrackTest < ActiveSupport::TestCase | ||
35 | 47 | ||
36 | should 'do not return other articles type at steps' do | 48 | should 'do not return other articles type at steps' do |
37 | article = fast_create(Article, :parent_id => @track.id, :profile_id => @track.profile.id) | 49 | article = fast_create(Article, :parent_id => @track.id, :profile_id => @track.profile.id) |
50 | + @track = Article.find(@track.id) | ||
38 | assert_includes @track.children, article | 51 | assert_includes @track.children, article |
39 | assert_equal [@step], @track.steps_unsorted | 52 | assert_equal [@step], @track.steps_unsorted |
40 | end | 53 | end |
plugins/community_track/test/unit/community_track_plugin_test.rb
@@ -7,6 +7,7 @@ class CommunityTrackPluginTest < ActiveSupport::TestCase | @@ -7,6 +7,7 @@ class CommunityTrackPluginTest < ActiveSupport::TestCase | ||
7 | @profile = fast_create(Community) | 7 | @profile = fast_create(Community) |
8 | @params = {} | 8 | @params = {} |
9 | @context = mock | 9 | @context = mock |
10 | + @context.stubs(:kind_of?).returns(CmsController) | ||
10 | @context.stubs(:profile).returns(@profile) | 11 | @context.stubs(:profile).returns(@profile) |
11 | @context.stubs(:params).returns(@params) | 12 | @context.stubs(:params).returns(@params) |
12 | @plugin.stubs(:context).returns(@context) | 13 | @plugin.stubs(:context).returns(@context) |
plugins/community_track/views/blocks/_track_list_more.html.erb
@@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
6 | </div> | 6 | </div> |
7 | <% else %> | 7 | <% else %> |
8 | <div class="more"> | 8 | <div class="more"> |
9 | - <%= link_to_remote(c_('More'), :url => {:id => block.id, :controller => 'community_track_plugin_public', :action => 'view_tracks', :page => page, :per_page => per_page, :force_same_page => force_same_page}, :loaded => visual_effect(:highlight, "track_card_list_#{block.id}")) %> | 9 | + <%= link_to c_('More'), :id => block.id, :controller => 'community_track_plugin_public', :action => 'view_tracks', :page => page, :per_page => per_page, :force_same_page => force_same_page, :remote => true %> |
10 | </div> | 10 | </div> |
11 | <% end %> | 11 | <% end %> |
12 | </div> | 12 | </div> |
plugins/community_track/views/blocks/footers/track_list.html.erb
0 → 100644
plugins/community_track/views/box_organizer/community_track_plugin/_track_list_block.html.erb
1 | <div id='edit-track-list-block'> | 1 | <div id='edit-track-list-block'> |
2 | <%= labelled_form_field c_('Limit of items'), text_field(:block, :limit, :size => 3) %> | 2 | <%= labelled_form_field c_('Limit of items'), text_field(:block, :limit, :size => 3) %> |
3 | + | ||
4 | + <%= labelled_form_field c_('Order'), | ||
5 | + select(:block, :order, | ||
6 | + options_for_select(CommunityTrackPlugin::TrackListBlock.order_options, :selected => @block.order)) %> | ||
7 | + | ||
3 | <%= labelled_form_field check_box(:block, :more_another_page) + _('Show more at another page'), '' %> | 8 | <%= labelled_form_field check_box(:block, :more_another_page) + _('Show more at another page'), '' %> |
4 | <%= select_categories(:block, _('Select Categories')) %> | 9 | <%= select_categories(:block, _('Select Categories')) %> |
5 | <br/> | 10 | <br/> |
plugins/community_track/views/cms/community_track_plugin/_step.html.erb
@@ -11,8 +11,10 @@ | @@ -11,8 +11,10 @@ | ||
11 | { :size => 14 }) | 11 | { :size => 14 }) |
12 | )) %> | 12 | )) %> |
13 | 13 | ||
14 | - <%= labelled_form_field(_('Tool type'), select(:article, :tool_type, CommunityTrackPlugin::Step.enabled_tools.map {|t| [t.short_description, t.name]} )) %> | 14 | + <%= labelled_form_field(_('Tool type'), select(:article, :tool_type, @article.enabled_tools.map {|t| [t.short_description, t.name]} )) %> |
15 | <%= hidden_field_tag('success_back_to', url_for(@article.parent.view_url)) %> | 15 | <%= hidden_field_tag('success_back_to', url_for(@article.parent.view_url)) %> |
16 | + <%= hidden_field_tag('parent_id', @article.parent_id) %> | ||
17 | + | ||
16 | </div> | 18 | </div> |
17 | 19 | ||
18 | <%= labelled_form_field check_box(:article, :hidden) + _('Hidden Step'), '' %> | 20 | <%= labelled_form_field check_box(:article, :hidden) + _('Hidden Step'), '' %> |
test/functional/profile_design_controller_test.rb
@@ -711,4 +711,17 @@ class ProfileDesignControllerTest < ActionController::TestCase | @@ -711,4 +711,17 @@ class ProfileDesignControllerTest < ActionController::TestCase | ||
711 | end | 711 | end |
712 | end | 712 | end |
713 | 713 | ||
714 | + should 'update selected categories in blocks' do | ||
715 | + env = Environment.default | ||
716 | + c1 = env.categories.build(:name => "Test category 1"); c1.save! | ||
717 | + | ||
718 | + block = profile.blocks.last | ||
719 | + | ||
720 | + Block.any_instance.expects(:accept_category?).at_least_once.returns true | ||
721 | + | ||
722 | + xhr :get, :update_categories, :profile => profile.identifier, :id => block.id, :category_id => c1.id | ||
723 | + | ||
724 | + assert_equal assigns(:current_category), c1 | ||
725 | + end | ||
726 | + | ||
714 | end | 727 | end |