Commit a67cc855a77c5eb300954c9aae3192495737ad74
Committed by
Daniela Feitosa
1 parent
2537fc30
Exists in
master
and in
29 other branches
Adding Community Track Plugin
Showing
47 changed files
with
1985 additions
and
9 deletions
Show diff stats
app/controllers/my_profile/memberships_controller.rb
@@ -9,9 +9,10 @@ class MembershipsController < MyProfileController | @@ -9,9 +9,10 @@ class MembershipsController < MyProfileController | ||
9 | def new_community | 9 | def new_community |
10 | @community = Community.new(params[:community]) | 10 | @community = Community.new(params[:community]) |
11 | @community.environment = environment | 11 | @community.environment = environment |
12 | + @back_to = params[:back_to] || url_for(:action => 'index') | ||
12 | if request.post? && @community.valid? | 13 | if request.post? && @community.valid? |
13 | @community = Community.create_after_moderation(user, {:environment => environment}.merge(params[:community])) | 14 | @community = Community.create_after_moderation(user, {:environment => environment}.merge(params[:community])) |
14 | - redirect_to :action => 'index' | 15 | + redirect_to @back_to |
15 | return | 16 | return |
16 | end | 17 | end |
17 | end | 18 | end |
app/helpers/categories_helper.rb
@@ -3,10 +3,20 @@ module CategoriesHelper | @@ -3,10 +3,20 @@ module CategoriesHelper | ||
3 | 3 | ||
4 | COLORS = [ | 4 | COLORS = [ |
5 | [ N_('Do not display at the menu'), nil ], | 5 | [ N_('Do not display at the menu'), nil ], |
6 | - [ N_('Orange'), 1 ], | ||
7 | - [ N_('Green'), 2 ], | ||
8 | - [ N_('Purple'), 3 ], | ||
9 | - [ N_('Red'), 4 ], | 6 | + [ N_('Orange'), 1], |
7 | + [ N_('Blue Oil'), 2], | ||
8 | + [ N_('Purple'), 3], | ||
9 | + [ N_('Light Brown'), 4], | ||
10 | + [ N_('Dark Green'), 5], | ||
11 | + [ N_('Green'), 6], | ||
12 | + [ N_('Blue'), 7], | ||
13 | + [ N_('Brown'), 8], | ||
14 | + [ N_('Light Green'), 9], | ||
15 | + [ N_('Light Blue'), 10], | ||
16 | + [ N_('Dark Blue'), 11], | ||
17 | + [ N_('Blue Pool'), 12], | ||
18 | + [ N_('Beige'), 13], | ||
19 | + [ N_('Yellow'), 14], | ||
10 | ] | 20 | ] |
11 | 21 | ||
12 | TYPES = [ | 22 | TYPES = [ |
app/models/article.rb
@@ -2,6 +2,8 @@ require 'hpricot' | @@ -2,6 +2,8 @@ require 'hpricot' | ||
2 | 2 | ||
3 | class Article < ActiveRecord::Base | 3 | class Article < ActiveRecord::Base |
4 | 4 | ||
5 | + acts_as_having_image | ||
6 | + | ||
5 | SEARCHABLE_FIELDS = { | 7 | SEARCHABLE_FIELDS = { |
6 | :name => 10, | 8 | :name => 10, |
7 | :abstract => 3, | 9 | :abstract => 3, |
app/models/category.rb
@@ -12,7 +12,7 @@ class Category < ActiveRecord::Base | @@ -12,7 +12,7 @@ class Category < ActiveRecord::Base | ||
12 | validates_uniqueness_of :slug,:scope => [ :environment_id, :parent_id ], :message => N_('%{fn} is already being used by another category.').fix_i18n | 12 | validates_uniqueness_of :slug,:scope => [ :environment_id, :parent_id ], :message => N_('%{fn} is already being used by another category.').fix_i18n |
13 | belongs_to :environment | 13 | belongs_to :environment |
14 | 14 | ||
15 | - validates_inclusion_of :display_color, :in => [ 1, 2, 3, 4, nil ] | 15 | + validates_inclusion_of :display_color, :in => 1..15, :allow_nil => true |
16 | validates_uniqueness_of :display_color, :scope => :environment_id, :if => (lambda { |cat| ! cat.display_color.nil? }), :message => N_('%{fn} was already assigned to another category.').fix_i18n | 16 | validates_uniqueness_of :display_color, :scope => :environment_id, :if => (lambda { |cat| ! cat.display_color.nil? }), :message => N_('%{fn} was already assigned to another category.').fix_i18n |
17 | 17 | ||
18 | # Finds all top level categories for a given environment. | 18 | # Finds all top level categories for a given environment. |
app/views/memberships/new_community.rhtml
@@ -45,10 +45,12 @@ | @@ -45,10 +45,12 @@ | ||
45 | </div> | 45 | </div> |
46 | 46 | ||
47 | <%= template_options(Community, 'community')%> | 47 | <%= template_options(Community, 'community')%> |
48 | + | ||
49 | + <%= hidden_field_tag('back_to', @back_to) %> | ||
48 | 50 | ||
49 | <% button_bar do %> | 51 | <% button_bar do %> |
50 | <%= submit_button(:save, _('Create')) %> | 52 | <%= submit_button(:save, _('Create')) %> |
51 | - <%= button(:cancel, _('Cancel'), :action => 'index') %> | 53 | + <%= button(:cancel, _('Cancel'), @back_to ) %> |
52 | <% end %> | 54 | <% end %> |
53 | 55 | ||
54 | <% end %> | 56 | <% end %> |
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +class AddImageToArticle < ActiveRecord::Migration | ||
2 | + | ||
3 | + def self.up | ||
4 | + add_column :articles, :image_id, :integer | ||
5 | + add_column :article_versions, :image_id, :integer | ||
6 | + end | ||
7 | + | ||
8 | + def self.down | ||
9 | + remove_column :articles, :image_id | ||
10 | + remove_column :article_versions, :image_id | ||
11 | + end | ||
12 | + | ||
13 | +end |
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +class AddPositionToArticle < ActiveRecord::Migration | ||
2 | + | ||
3 | + def self.up | ||
4 | + add_column :articles, :position, :integer | ||
5 | + add_column :article_versions, :position, :integer | ||
6 | + end | ||
7 | + | ||
8 | + def self.down | ||
9 | + remove_column :articles, :position | ||
10 | + remove_column :article_versions, :position | ||
11 | + end | ||
12 | + | ||
13 | +end |
plugins/community_track/controllers/myprofile/community_track_plugin_myprofile_controller.rb
0 → 100644
@@ -0,0 +1,18 @@ | @@ -0,0 +1,18 @@ | ||
1 | +class CommunityTrackPluginMyprofileController < MyProfileController | ||
2 | + append_view_path File.join(File.dirname(__FILE__) + '/../../views') | ||
3 | + | ||
4 | + before_filter :allow_edit_track, :only => :save_order | ||
5 | + | ||
6 | + def save_order | ||
7 | + track = profile.articles.find(params[:track]) | ||
8 | + track.reorder_steps(params[:step_ids]) | ||
9 | + redirect_to track.url | ||
10 | + end | ||
11 | + | ||
12 | + protected | ||
13 | + | ||
14 | + def allow_edit_track | ||
15 | + render_access_denied unless profile.articles.find(params[:track]).allow_edit?(user) | ||
16 | + end | ||
17 | + | ||
18 | +end |
plugins/community_track/controllers/public/community_track_plugin_public_controller.rb
0 → 100644
@@ -0,0 +1,47 @@ | @@ -0,0 +1,47 @@ | ||
1 | +class CommunityTrackPluginPublicController < PublicController | ||
2 | + append_view_path File.join(File.dirname(__FILE__) + '/../../views') | ||
3 | + | ||
4 | + no_design_blocks | ||
5 | + | ||
6 | + before_filter :login_required, :only => :select_community | ||
7 | + | ||
8 | + def view_tracks | ||
9 | + block = Block.find(params[:id]) | ||
10 | + p = params[:page].to_i | ||
11 | + per_page = params[:per_page] | ||
12 | + per_page ||= block.limit | ||
13 | + per_page = per_page.to_i | ||
14 | + tracks = block.tracks(p, per_page) | ||
15 | + | ||
16 | + render :update do |page| | ||
17 | + page.insert_html :bottom, "track_list_#{block.id}", :partial => "blocks/#{block.track_partial}", :collection => tracks, :locals => {:block => block} | ||
18 | + | ||
19 | + if block.has_page?(p+1, 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} | ||
21 | + else | ||
22 | + page.replace_html "track_list_more_#{block.id}", '' | ||
23 | + end | ||
24 | + end | ||
25 | + end | ||
26 | + | ||
27 | + def all_tracks | ||
28 | + @per_page = 5 #FIXME | ||
29 | + @block = Block.find(params[:id]) | ||
30 | + @tracks = @block.tracks(1, @per_page) | ||
31 | + @show_more = @block.has_page?(2, @per_page) | ||
32 | + end | ||
33 | + | ||
34 | + def select_community | ||
35 | + @communities = user.memberships.select{ |community| user.has_permission?('post_content', community) } | ||
36 | + @back_to = request.url | ||
37 | + if request.post? | ||
38 | + community_identifier = params[:community_identifier] | ||
39 | + if community_identifier.nil? | ||
40 | + @failed = [_('Select one community to proceed')] | ||
41 | + else | ||
42 | + redirect_to :controller => 'cms', :action => 'new', :type => "CommunityTrackPlugin::Track", :profile => community_identifier | ||
43 | + end | ||
44 | + end | ||
45 | + end | ||
46 | + | ||
47 | +end |
@@ -0,0 +1,36 @@ | @@ -0,0 +1,36 @@ | ||
1 | +class CommunityTrackPlugin < Noosfero::Plugin | ||
2 | + | ||
3 | + def self.plugin_name | ||
4 | + 'Community Track' | ||
5 | + end | ||
6 | + | ||
7 | + def self.plugin_description | ||
8 | + _("New kind of content for communities.") | ||
9 | + end | ||
10 | + | ||
11 | + def stylesheet? | ||
12 | + true | ||
13 | + end | ||
14 | + | ||
15 | + def content_types | ||
16 | + if context.respond_to?(:params) && context.params | ||
17 | + types = [] | ||
18 | + parent_id = context.params[:parent_id] | ||
19 | + types << CommunityTrackPlugin::Track if context.profile.community? && !parent_id | ||
20 | + parent = parent_id ? context.profile.articles.find(parent_id) : nil | ||
21 | + types << CommunityTrackPlugin::Step if parent.kind_of?(CommunityTrackPlugin::Track) | ||
22 | + types | ||
23 | + else | ||
24 | + [CommunityTrackPlugin::Track, CommunityTrackPlugin::Step] | ||
25 | + end | ||
26 | + end | ||
27 | + | ||
28 | + def self.extra_blocks | ||
29 | + { CommunityTrackPlugin::TrackListBlock => {:position => 1}, CommunityTrackPlugin::TrackCardListBlock => {} } | ||
30 | + end | ||
31 | + | ||
32 | + def content_remove_new(page) | ||
33 | + page.kind_of?(CommunityTrackPlugin::Track) | ||
34 | + end | ||
35 | + | ||
36 | +end |
plugins/community_track/lib/community_track_plugin/step.rb
0 → 100644
@@ -0,0 +1,105 @@ | @@ -0,0 +1,105 @@ | ||
1 | +class CommunityTrackPlugin::Step < Folder | ||
2 | + | ||
3 | + settings_items :hidden, :type => :boolean, :default => false | ||
4 | + | ||
5 | + alias :tools :children | ||
6 | + | ||
7 | + acts_as_list :scope => :parent | ||
8 | + | ||
9 | + def belong_to_track | ||
10 | + errors.add(:parent, "Step not allowed at this parent.") if !parent.kind_of?(CommunityTrackPlugin::Track) | ||
11 | + end | ||
12 | + | ||
13 | + validate :belong_to_track | ||
14 | + validates_presence_of :start_date, :end_date | ||
15 | + validate :end_date_equal_or_after_start_date | ||
16 | + | ||
17 | + after_save :schedule_activation | ||
18 | + | ||
19 | + before_create do |step| | ||
20 | + step.published = false | ||
21 | + true | ||
22 | + end | ||
23 | + | ||
24 | + before_create :set_hidden_position | ||
25 | + before_save :set_hidden_position | ||
26 | + | ||
27 | + def set_hidden_position | ||
28 | + if hidden | ||
29 | + decrement_positions_on_lower_items | ||
30 | + self[:position] = 0 | ||
31 | + elsif position == 0 | ||
32 | + add_to_list_bottom | ||
33 | + end | ||
34 | + end | ||
35 | + | ||
36 | + def end_date_equal_or_after_start_date | ||
37 | + if end_date && start_date | ||
38 | + errors.add(:end_date, _('must be equal or after start date.')) unless end_date >= start_date | ||
39 | + end | ||
40 | + end | ||
41 | + | ||
42 | + def self.short_description | ||
43 | + _("Step") | ||
44 | + end | ||
45 | + | ||
46 | + def self.description | ||
47 | + _('Defines a step.') | ||
48 | + end | ||
49 | + | ||
50 | + def accept_comments? | ||
51 | + false | ||
52 | + end | ||
53 | + | ||
54 | + def enabled_tools | ||
55 | + {TinyMceArticle => {:name => _('Article')}, Forum => {:name => _('Forum')}} | ||
56 | + end | ||
57 | + | ||
58 | + def to_html(options = {}) | ||
59 | + step = self | ||
60 | + lambda do | ||
61 | + render :file => 'content_viewer/step.rhtml', :locals => {:step => step} | ||
62 | + end | ||
63 | + end | ||
64 | + | ||
65 | + def active? | ||
66 | + (start_date..end_date).include?(Date.today) | ||
67 | + end | ||
68 | + | ||
69 | + def finished? | ||
70 | + Date.today > end_date | ||
71 | + end | ||
72 | + | ||
73 | + def waiting? | ||
74 | + Date.today < start_date | ||
75 | + end | ||
76 | + | ||
77 | + 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 | ||
82 | + CommunityTrackPlugin::ActivationJob.find(id).destroy_all | ||
83 | + Delayed::Job.enqueue(CommunityTrackPlugin::ActivationJob.new(self.id), 0, schedule_date) | ||
84 | + end | ||
85 | + end | ||
86 | + | ||
87 | + def publish | ||
88 | + self[:published] = active? && !hidden | ||
89 | + save! | ||
90 | + end | ||
91 | + | ||
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 | ||
97 | + | ||
98 | + def perform | ||
99 | + step = CommunityTrackPlugin::Step.find(step_id) | ||
100 | + step.publish | ||
101 | + end | ||
102 | + | ||
103 | + end | ||
104 | + | ||
105 | +end |
plugins/community_track/lib/community_track_plugin/step_helper.rb
0 → 100644
@@ -0,0 +1,30 @@ | @@ -0,0 +1,30 @@ | ||
1 | +module CommunityTrackPlugin::StepHelper | ||
2 | + | ||
3 | + def self.status_descriptions | ||
4 | + [_('Finished'), _('In progress'), _('Waiting')] | ||
5 | + end | ||
6 | + | ||
7 | + def self.status_classes | ||
8 | + ['step_finished', 'step_active', 'step_waiting'] | ||
9 | + end | ||
10 | + | ||
11 | + def status_description(step) | ||
12 | + CommunityTrackPlugin::StepHelper.status_descriptions[status_index(step)] | ||
13 | + end | ||
14 | + | ||
15 | + def status_class(step) | ||
16 | + CommunityTrackPlugin::StepHelper.status_classes[status_index(step)] | ||
17 | + end | ||
18 | + | ||
19 | + def custom_options_for_article(article) | ||
20 | + #no options for step? | ||
21 | + nil | ||
22 | + end | ||
23 | + | ||
24 | + protected | ||
25 | + | ||
26 | + def status_index(step) | ||
27 | + [step.finished?, step.active?, step.waiting?].find_index(true) | ||
28 | + end | ||
29 | + | ||
30 | +end |
plugins/community_track/lib/community_track_plugin/track.rb
0 → 100644
@@ -0,0 +1,70 @@ | @@ -0,0 +1,70 @@ | ||
1 | +class CommunityTrackPlugin::Track < Folder | ||
2 | + | ||
3 | + settings_items :goals, :type => :string | ||
4 | + settings_items :expected_results, :type => :string | ||
5 | + | ||
6 | + def self.icon_name(article = nil) | ||
7 | + 'community-track' | ||
8 | + end | ||
9 | + | ||
10 | + def self.short_description | ||
11 | + _("Track") | ||
12 | + end | ||
13 | + | ||
14 | + def self.description | ||
15 | + _('Defines a track.') | ||
16 | + end | ||
17 | + | ||
18 | + def steps | ||
19 | + #XXX article default order is name (acts_as_filesystem) -> should use reorder (rails3) | ||
20 | + steps_unsorted.sort_by(&:position).select{|s| !s.hidden} | ||
21 | + end | ||
22 | + | ||
23 | + def hidden_steps | ||
24 | + steps_unsorted.select{|s| s.hidden} | ||
25 | + end | ||
26 | + | ||
27 | + def reorder_steps(step_ids) | ||
28 | + transaction do | ||
29 | + step_ids.each_with_index do |step_id, i| | ||
30 | + step = steps_unsorted.find(step_id) | ||
31 | + step.update_attribute(:position, step.position = i + 1) | ||
32 | + end | ||
33 | + end | ||
34 | + end | ||
35 | + | ||
36 | + def steps_unsorted | ||
37 | + children.where(:type => 'CommunityTrackPlugin::Step') | ||
38 | + end | ||
39 | + | ||
40 | + def accept_comments? | ||
41 | + false | ||
42 | + end | ||
43 | + | ||
44 | + def comments_count | ||
45 | + steps_unsorted.joins(:children).sum('childrens_articles.comments_count') | ||
46 | + end | ||
47 | + | ||
48 | + def css_class_name | ||
49 | + "community-track-plugin-track" | ||
50 | + end | ||
51 | + | ||
52 | + #FIXME make this test | ||
53 | + def first_paragraph | ||
54 | + paragraphs = Hpricot(body).search('p') | ||
55 | + paragraphs.empty? ? '' : paragraphs.first.to_html | ||
56 | + end | ||
57 | + | ||
58 | + def category_name | ||
59 | + category = categories.first | ||
60 | + category ? category.name : '' | ||
61 | + end | ||
62 | + | ||
63 | + def to_html(options = {}) | ||
64 | + track = self | ||
65 | + lambda do | ||
66 | + render :file => 'content_viewer/track.rhtml', :locals => {:track => track} | ||
67 | + end | ||
68 | + end | ||
69 | + | ||
70 | +end |
plugins/community_track/lib/community_track_plugin/track_card_list_block.rb
0 → 100644
@@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
1 | +class CommunityTrackPlugin::TrackCardListBlock < CommunityTrackPlugin::TrackListBlock | ||
2 | + | ||
3 | + def self.description | ||
4 | + _('Track Card List') | ||
5 | + end | ||
6 | + | ||
7 | + def help | ||
8 | + _('This block displays a list of most relevant tracks as cards.') | ||
9 | + end | ||
10 | + | ||
11 | + def track_partial | ||
12 | + 'track_card' | ||
13 | + end | ||
14 | + | ||
15 | +end |
plugins/community_track/lib/community_track_plugin/track_helper.rb
0 → 100644
@@ -0,0 +1,12 @@ | @@ -0,0 +1,12 @@ | ||
1 | +module CommunityTrackPlugin::TrackHelper | ||
2 | + | ||
3 | + def category_class(track) | ||
4 | + 'category_' + (track.categories.empty? ? 'not_defined' : track.categories.first.name.to_slug) | ||
5 | + end | ||
6 | + | ||
7 | + def track_card_lead(track) | ||
8 | + lead_stripped = strip_tags(track.lead) | ||
9 | + excerpt(lead_stripped, lead_stripped.first(3), track.image ? 180 : 300) | ||
10 | + end | ||
11 | + | ||
12 | +end |
plugins/community_track/lib/community_track_plugin/track_list_block.rb
0 → 100644
@@ -0,0 +1,64 @@ | @@ -0,0 +1,64 @@ | ||
1 | +class CommunityTrackPlugin::TrackListBlock < Block | ||
2 | + | ||
3 | + include CommunityTrackPlugin::StepHelper | ||
4 | + | ||
5 | + settings_items :limit, :type => :integer, :default => 3 | ||
6 | + settings_items :more_another_page, :type => :boolean, :default => false | ||
7 | + settings_items :category_ids, :type => Array, :default => [] | ||
8 | + | ||
9 | + def self.description | ||
10 | + _('Track List') | ||
11 | + end | ||
12 | + | ||
13 | + def help | ||
14 | + _('This block displays a list of most relevant tracks.') | ||
15 | + end | ||
16 | + | ||
17 | + def track_partial | ||
18 | + 'track' | ||
19 | + end | ||
20 | + | ||
21 | + def tracks(page=1, per_page=limit) | ||
22 | + all_tracks.order('hits DESC').paginate(:per_page => per_page, :page => page) | ||
23 | + end | ||
24 | + | ||
25 | + def count_tracks | ||
26 | + all_tracks.count | ||
27 | + end | ||
28 | + | ||
29 | + def accept_category?(cat) | ||
30 | + true #accept all? | ||
31 | + end | ||
32 | + | ||
33 | + def category_ids=(ids) | ||
34 | + settings[:category_ids] = ids.uniq.map{|item| item.to_i unless item.to_i.zero?}.compact | ||
35 | + end | ||
36 | + | ||
37 | + def all_tracks | ||
38 | + tracks = owner.articles.where(:type => 'CommunityTrackPlugin::Track') | ||
39 | + if !category_ids.empty? | ||
40 | + tracks = tracks.joins(:article_categorizations).where(:articles_categories => {:category_id => category_ids}) | ||
41 | + end | ||
42 | + tracks | ||
43 | + end | ||
44 | + | ||
45 | + def content(args={}) | ||
46 | + block = self | ||
47 | + lambda do | ||
48 | + render :file => 'blocks/track_list.rhtml', :locals => {:block => block} | ||
49 | + end | ||
50 | + end | ||
51 | + | ||
52 | + def has_page?(page, per_page=limit) | ||
53 | + return (page-1) * per_page < count_tracks | ||
54 | + end | ||
55 | + | ||
56 | + def footer | ||
57 | + block = self | ||
58 | + return nil if !has_page?(2) | ||
59 | + lambda do | ||
60 | + render :partial => 'blocks/track_list_more', :locals => {:block => block, :page => 2, :per_page => block.limit} | ||
61 | + end | ||
62 | + end | ||
63 | + | ||
64 | +end |
1.49 KB
@@ -0,0 +1,190 @@ | @@ -0,0 +1,190 @@ | ||
1 | +.icon-newcommunity-track { | ||
2 | + background-image: url(/plugins/community_track/icons/community-track.png) | ||
3 | +} | ||
4 | + | ||
5 | +.step_active, #article .step_active a { | ||
6 | + background-color: #CCEBD6; | ||
7 | + color: #338533; | ||
8 | +} | ||
9 | + | ||
10 | +.step_waiting, #article .step_waiting a { | ||
11 | + background-color: #FFFFD1; | ||
12 | + color: #D17519; | ||
13 | +} | ||
14 | + | ||
15 | +.step_finished, #article .step_finished a { | ||
16 | + background-color: #D1FFFF; | ||
17 | + color: #00297A; | ||
18 | +} | ||
19 | + | ||
20 | +.step_status_description { | ||
21 | + float: right; | ||
22 | +} | ||
23 | + | ||
24 | +.step { | ||
25 | + font-weight: bold; | ||
26 | +} | ||
27 | + | ||
28 | +.track_list .item .step { | ||
29 | + padding: 8px 5px; | ||
30 | +} | ||
31 | + | ||
32 | +#article .step a { | ||
33 | + text-decoration: none; | ||
34 | +} | ||
35 | + | ||
36 | +.track_list .item .track_content .lead { | ||
37 | + float: left; | ||
38 | + width: 50%; | ||
39 | +} | ||
40 | + | ||
41 | +.track_list .item .track_content .steps { | ||
42 | + float: right; | ||
43 | + width: 50%; | ||
44 | +} | ||
45 | + | ||
46 | +.track_list .item { | ||
47 | + border-bottom: 1px solid #DDDDDD; | ||
48 | +} | ||
49 | + | ||
50 | +.track_stats, .track_content { | ||
51 | + clear: both; | ||
52 | +} | ||
53 | + | ||
54 | +.track_stats .comments { | ||
55 | + float: left; | ||
56 | +} | ||
57 | + | ||
58 | +.track_stats .hits { | ||
59 | + float: right; | ||
60 | +} | ||
61 | + | ||
62 | +.track_list .item_card { | ||
63 | + width: 155px; | ||
64 | + border: 1px solid #DDDDDD; | ||
65 | + float: left; | ||
66 | + padding: 0px 8px; | ||
67 | + margin-left: 3px; | ||
68 | + margin-right: 3px; | ||
69 | + margin-bottom: 8px; | ||
70 | +} | ||
71 | + | ||
72 | +.steps .step { | ||
73 | + margin-top: 3px; | ||
74 | + margin-bottom: 3px; | ||
75 | +} | ||
76 | + | ||
77 | +.track_list .item_card .track_stats { | ||
78 | + border-top: 1px solid #DDDDDD; | ||
79 | +} | ||
80 | + | ||
81 | +.track_list .item_card a, .track_list .item_card a:hover, .track_list .item_card a:visited { | ||
82 | + text-decoration: none; | ||
83 | + color: #444; | ||
84 | +} | ||
85 | + | ||
86 | +.track_list .item_card:hover { | ||
87 | + background: #EEE; | ||
88 | +} | ||
89 | + | ||
90 | +.track_list .title { | ||
91 | + font-size: 16px; | ||
92 | + font-weight: bold; | ||
93 | + border-bottom: 1px solid #DDDDDD; | ||
94 | + padding: 2px 0px; | ||
95 | + margin-bottom: 5px; | ||
96 | + min-height: 10px; | ||
97 | +} | ||
98 | + | ||
99 | +.track_list .image img { | ||
100 | + max-width: 100%; | ||
101 | + max-height: 100px; | ||
102 | + display: block; | ||
103 | + margin-left: auto; | ||
104 | + margin-right: auto; | ||
105 | +} | ||
106 | + | ||
107 | +.track_list .name { | ||
108 | + padding-top: 5px; | ||
109 | +} | ||
110 | + | ||
111 | +.track_list .item_card { | ||
112 | + height: 270px; | ||
113 | +} | ||
114 | + | ||
115 | +.track_list .track_content { | ||
116 | + height: 250px; | ||
117 | +} | ||
118 | + | ||
119 | +#track .step_list { | ||
120 | + list-style-type: none; | ||
121 | + margin: 0; | ||
122 | + padding: 0; | ||
123 | +} | ||
124 | + | ||
125 | +#track .position { | ||
126 | + font-size: 24px; | ||
127 | + font-weight: bold; | ||
128 | + float: left; | ||
129 | + margin: 0 10px; | ||
130 | +} | ||
131 | + | ||
132 | +#track .step .name, #track .step .name a { | ||
133 | + font-weight: bold; | ||
134 | + color: #333; | ||
135 | +} | ||
136 | + | ||
137 | +#track .step .name a:hover { | ||
138 | + color: #555; | ||
139 | +} | ||
140 | + | ||
141 | +#track .step .date { | ||
142 | + font-size: 12px; | ||
143 | + color: #AAA; | ||
144 | +} | ||
145 | + | ||
146 | +#track .step .lead { | ||
147 | + margin: 0px 10px; | ||
148 | + color: #555; | ||
149 | +} | ||
150 | + | ||
151 | +#track .content { | ||
152 | + margin: 6px 0px; | ||
153 | + border-bottom: 1px solid #DDDDDD; | ||
154 | +} | ||
155 | + | ||
156 | +#track .ui-state-default .content { | ||
157 | + border-bottom: 0px; | ||
158 | +} | ||
159 | + | ||
160 | +.track_list .item .step .position { | ||
161 | + float: left; | ||
162 | + padding-right: 5px; | ||
163 | +} | ||
164 | + | ||
165 | +#track .actions .save_button { | ||
166 | + display: none; | ||
167 | +} | ||
168 | + | ||
169 | +#track .actions, #step .actions { | ||
170 | + margin-bottom: 20px; | ||
171 | +} | ||
172 | + | ||
173 | +#edit-track-list-block .categorie_box a { | ||
174 | + float: left; | ||
175 | +} | ||
176 | + | ||
177 | +.all_tracks .more_button { | ||
178 | + text-align: center; | ||
179 | +} | ||
180 | + | ||
181 | +#step .tools .item .name a, #step .tools .item .name a:hover { | ||
182 | + border: none; | ||
183 | + background-color: transparent; | ||
184 | + color: #666; | ||
185 | + font-weight: bold; | ||
186 | +} | ||
187 | + | ||
188 | +#step .tools .item .name a:hover { | ||
189 | + color: #888; | ||
190 | +} |
plugins/community_track/test/functional/community_track_plugin_cms_controller_test.rb
0 → 100644
@@ -0,0 +1,47 @@ | @@ -0,0 +1,47 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +# Re-raise errors caught by the controller. | ||
4 | +class CmsController; def rescue_action(e) raise e end; end | ||
5 | + | ||
6 | +class CmsControllerTest < ActionController::TestCase | ||
7 | + | ||
8 | + def setup | ||
9 | + @profile = fast_create(Community) | ||
10 | + @track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track', :profile => @profile) | ||
11 | + @step = CommunityTrackPlugin::Step.create!(:name => 'step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) | ||
12 | + | ||
13 | + user = create_user('testinguser') | ||
14 | + @profile.add_admin(user.person) | ||
15 | + login_as(user.login) | ||
16 | + end | ||
17 | + | ||
18 | + should 'be able to edit track' do | ||
19 | + get :edit, :id => @track.id, :profile => @profile.identifier | ||
20 | + assert_tag :tag => 'input', :attributes => { :id => 'article_name' } | ||
21 | + end | ||
22 | + | ||
23 | + should 'be able to edit step' do | ||
24 | + get :edit, :id => @step.id, :profile => @profile.identifier | ||
25 | + assert_tag :tag => 'input', :attributes => { :id => 'article_name' } | ||
26 | + end | ||
27 | + | ||
28 | + should 'be able to save track' do | ||
29 | + get :edit, :id => @track.id, :profile => @profile.identifier | ||
30 | + post :edit, :id => @track.id, :profile => @profile.identifier, :article => {:name => 'changed'} | ||
31 | + @track.reload | ||
32 | + assert_equal 'changed', @track.name | ||
33 | + end | ||
34 | + | ||
35 | + should 'be able to save step' do | ||
36 | + get :edit, :id => @step.id, :profile => @profile.identifier | ||
37 | + post :edit, :id => @step.id, :profile => @profile.identifier, :article => {:name => 'changed'} | ||
38 | + @step.reload | ||
39 | + assert_equal 'changed', @step.name | ||
40 | + end | ||
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 |
plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb
0 → 100644
@@ -0,0 +1,147 @@ | @@ -0,0 +1,147 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class ContentViewerController | ||
4 | + append_view_path File.join(File.dirname(__FILE__) + '/../../views') | ||
5 | + def rescue_action(e) | ||
6 | + raise e | ||
7 | + end | ||
8 | +end | ||
9 | + | ||
10 | +class ContentViewerControllerTest < ActionController::TestCase | ||
11 | + | ||
12 | + def setup | ||
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) | ||
19 | + | ||
20 | + user = create_user('testinguser') | ||
21 | + login_as(user.login) | ||
22 | + @profile.add_admin(user.person) | ||
23 | + end | ||
24 | + | ||
25 | + should 'show actions for tracks when user has permission for edit' do | ||
26 | + get :view_page, @track.url | ||
27 | + assert_tag :tag => 'div', :attributes => {:id => 'track' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } } | ||
28 | + end | ||
29 | + | ||
30 | + should 'do not show actions for tracks when user has not permission for edit' do | ||
31 | + user = create_user('intruder') | ||
32 | + logout | ||
33 | + login_as(user.login) | ||
34 | + get :view_page, @track.url | ||
35 | + assert_no_tag :tag => 'div', :attributes => {:id => 'track' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } } | ||
36 | + end | ||
37 | + | ||
38 | + should 'do not show new button at article toolbar for tracks' do | ||
39 | + user = create_user('intruder') | ||
40 | + logout | ||
41 | + login_as(user.login) | ||
42 | + get :view_page, @track.url | ||
43 | + assert_no_tag :tag => 'div', :attributes => {:id => 'article-actions'}, :descendant => { :tag => 'div', :attributes => { :id => 'icon-new' } } | ||
44 | + end | ||
45 | + | ||
46 | + should 'display steps for tracks' do | ||
47 | + get :view_page, @track.url | ||
48 | + assert_tag :tag => 'ul', :attributes => { :id => 'sortable' }, :descendant => {:tag => 'li', :attributes => { :class => 'step' } } | ||
49 | + end | ||
50 | + | ||
51 | + should 'display hidden field with step id' do | ||
52 | + get :view_page, @track.url | ||
53 | + assert_tag :tag => 'input', :attributes => { :name => 'step_ids[]' } | ||
54 | + end | ||
55 | + | ||
56 | + should 'show step' do | ||
57 | + get :view_page, @step.url | ||
58 | + assert_tag :tag => 'div', :attributes => { :id => 'step' } | ||
59 | + end | ||
60 | + | ||
61 | + should 'show tools for a step' do | ||
62 | + Article.create!(:profile => @profile, :name => 'article', :parent => @step) | ||
63 | + get :view_page, @step.url | ||
64 | + assert_tag :tag => 'div', :attributes => { :class => 'tools' }, :descendant => { :tag => 'div', :attributes => { :class => 'item' } } | ||
65 | + end | ||
66 | + | ||
67 | + should 'show actions for steps when user has permission for edit' do | ||
68 | + get :view_page, @step.url | ||
69 | + assert_tag :tag => 'div', :attributes => {:id => 'step' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } } | ||
70 | + end | ||
71 | + | ||
72 | + should 'show actions for enabled tools in step' do | ||
73 | + 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' } } | ||
76 | + end | ||
77 | + | ||
78 | + should 'do not show actions for steps when user has not permission for edit' do | ||
79 | + user = create_user('intruder') | ||
80 | + logout | ||
81 | + login_as(user.login) | ||
82 | + get :view_page, @step.url | ||
83 | + assert_no_tag :tag => 'div', :attributes => {:id => 'step' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } } | ||
84 | + end | ||
85 | + | ||
86 | + should 'render a div with block id for track list block' do | ||
87 | + box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name) | ||
88 | + @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box) | ||
89 | + @profile.boxes << box | ||
90 | + get :view_page, @step.url | ||
91 | + assert_tag :tag => 'div', :attributes => { :class => 'track_list', :id => "track_list_#{@block.id}" } | ||
92 | + end | ||
93 | + | ||
94 | + should 'render a div with block id for track card list block' do | ||
95 | + box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name) | ||
96 | + @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) | ||
97 | + @profile.boxes << box | ||
98 | + get :view_page, @step.url | ||
99 | + assert_tag :tag => 'div', :attributes => { :class => 'track_list', :id => "track_list_#{@block.id}" } | ||
100 | + end | ||
101 | + | ||
102 | + should 'render tracks in track list block' do | ||
103 | + box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name) | ||
104 | + @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box) | ||
105 | + @profile.boxes << box | ||
106 | + 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)}" } } } | ||
108 | + end | ||
109 | + | ||
110 | + should 'render tracks in track card list block' do | ||
111 | + box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name) | ||
112 | + @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) | ||
113 | + @profile.boxes << box | ||
114 | + 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' } } | ||
117 | + end | ||
118 | + | ||
119 | + should 'render link to display more tracks in track list block' do | ||
120 | + box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name) | ||
121 | + @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) | ||
122 | + @profile.boxes << box | ||
123 | + | ||
124 | + (@block.limit+1).times do |i| | ||
125 | + CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @profile) | ||
126 | + end | ||
127 | + | ||
128 | + get :view_page, @step.url | ||
129 | + assert_tag :tag => 'div', :attributes => { :id => "track_list_more_#{@block.id}" }, :descendant => { :tag => 'div', :attributes => { :class => 'more' } } | ||
130 | + end | ||
131 | + | ||
132 | + should 'render link to show all tracks in track list block' do | ||
133 | + box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name) | ||
134 | + @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) | ||
135 | + @profile.boxes << box | ||
136 | + @block.more_another_page = true | ||
137 | + @block.save! | ||
138 | + | ||
139 | + (@block.limit+1).times do |i| | ||
140 | + CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @profile) | ||
141 | + end | ||
142 | + | ||
143 | + get :view_page, @step.url | ||
144 | + assert_tag :tag => 'div', :attributes => { :id => "track_list_more_#{@block.id}" }, :descendant => { :tag => 'div', :attributes => { :class => 'view_all' } } | ||
145 | + end | ||
146 | + | ||
147 | +end |
plugins/community_track/test/functional/community_track_plugin_environment_design_controller_test.rb
0 → 100644
@@ -0,0 +1,47 @@ | @@ -0,0 +1,47 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +# Re-raise errors caught by the controller. | ||
4 | +class EnvironmentDesignController; def rescue_action(e) raise e end; end | ||
5 | + | ||
6 | +class EnvironmentDesignControllerTest < ActionController::TestCase | ||
7 | + | ||
8 | + def setup | ||
9 | + Environment.delete_all | ||
10 | + @environment = Environment.new(:name => 'testenv', :is_default => true) | ||
11 | + @environment.enabled_plugins = ['CommunityTrackPlugin'] | ||
12 | + @environment.save! | ||
13 | + | ||
14 | + user = create_user('testinguser') | ||
15 | + @environment.add_admin(user.person) | ||
16 | + login_as(user.login) | ||
17 | + | ||
18 | + box = Box.create!(:owner => @environment) | ||
19 | + @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box) | ||
20 | + @block_card = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) | ||
21 | + end | ||
22 | + | ||
23 | + should 'be able to edit TrackListBlock' do | ||
24 | + get :edit, :id => @block.id | ||
25 | + assert_tag :tag => 'input', :attributes => { :id => 'block_title' } | ||
26 | + end | ||
27 | + | ||
28 | + should 'be able to save TrackListBlock' do | ||
29 | + get :edit, :id => @block.id | ||
30 | + post :save, :id => @block.id, :block => {:title => 'Tracks' } | ||
31 | + @block.reload | ||
32 | + assert_equal 'Tracks', @block.title | ||
33 | + end | ||
34 | + | ||
35 | + should 'be able to edit TrackCardListBlock' do | ||
36 | + get :edit, :id => @block_card.id | ||
37 | + assert_tag :tag => 'input', :attributes => { :id => 'block_title' } | ||
38 | + end | ||
39 | + | ||
40 | + should 'be able to save TrackCardListBlock' do | ||
41 | + get :edit, :id => @block_card.id | ||
42 | + post :save, :id => @block_card.id, :block => {:title => 'Tracks' } | ||
43 | + @block_card.reload | ||
44 | + assert_equal 'Tracks', @block_card.title | ||
45 | + end | ||
46 | + | ||
47 | +end |
plugins/community_track/test/functional/community_track_plugin_myprofile_controller_test.rb
0 → 100644
@@ -0,0 +1,49 @@ | @@ -0,0 +1,49 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | +require File.dirname(__FILE__) + '/../../controllers/myprofile/community_track_plugin_myprofile_controller' | ||
3 | + | ||
4 | +# Re-raise errors caught by the controller. | ||
5 | +class CommunityTrackPluginMyprofileController; def rescue_action(e) raise e end; end | ||
6 | + | ||
7 | +class CommunityTrackPluginMyprofileControllerTest < ActionController::TestCase | ||
8 | + | ||
9 | + def setup | ||
10 | + @controller = CommunityTrackPluginMyprofileController.new | ||
11 | + @request = ActionController::TestRequest.new | ||
12 | + @response = ActionController::TestResponse.new | ||
13 | + | ||
14 | + @profile = fast_create(Community) | ||
15 | + @track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track', :profile => @profile) | ||
16 | + | ||
17 | + @user = create_user('testinguser') | ||
18 | + login_as(@user.login) | ||
19 | + @profile.add_admin(@user.person) | ||
20 | + end | ||
21 | + | ||
22 | + should 'redirect to track on save order' do | ||
23 | + get :save_order, :profile => @profile.identifier, :track => @track.id, :step_ids => [] | ||
24 | + assert_redirected_to @track.url | ||
25 | + end | ||
26 | + | ||
27 | + should 'save new step positions on save order' do | ||
28 | + step1 = CommunityTrackPlugin::Step.create!(:name => 'step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) | ||
29 | + step2 = CommunityTrackPlugin::Step.create!(:name => 'step2', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) | ||
30 | + assert_equal [step1, step2], @track.steps | ||
31 | + get :save_order, :profile => @profile.identifier, :track => @track.id, :step_ids => [step2.id, step1.id] | ||
32 | + assert_equal [step2, step1], @track.steps | ||
33 | + end | ||
34 | + | ||
35 | + should 'do not allow a user without permission to save order' do | ||
36 | + logout | ||
37 | + user = create_user('intruder') | ||
38 | + login_as(user.login) | ||
39 | + get :save_order, :profile => @profile.identifier, :track => @track.id, :step_ids => [] | ||
40 | + assert_response 403 | ||
41 | + end | ||
42 | + | ||
43 | + should 'redirect to login page if there is no user logged in' do | ||
44 | + logout | ||
45 | + get :save_order, :profile => @profile.identifier, :track => @track.id, :step_ids => [] | ||
46 | + assert_response 302 | ||
47 | + end | ||
48 | + | ||
49 | +end |
plugins/community_track/test/functional/community_track_plugin_public_controller_test.rb
0 → 100644
@@ -0,0 +1,109 @@ | @@ -0,0 +1,109 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | +require File.dirname(__FILE__) + '/../../controllers/public/community_track_plugin_public_controller' | ||
3 | + | ||
4 | +# Re-raise errors caught by the controller. | ||
5 | +class CommunityTrackPluginPublicController; def rescue_action(e) raise e end; end | ||
6 | + | ||
7 | +class CommunityTrackPluginPublicControllerTest < ActionController::TestCase | ||
8 | + | ||
9 | + def setup | ||
10 | + @community = fast_create(Community) | ||
11 | + @track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track', :profile => @community) | ||
12 | + | ||
13 | + box = fast_create(Box, :owner_id => @community.id, :owner_type => 'Community') | ||
14 | + @card_block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) | ||
15 | + @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box) | ||
16 | + end | ||
17 | + | ||
18 | + should 'display tracks for card block' do | ||
19 | + xhr :get, :view_tracks, :id => @card_block.id, :page => 1 | ||
20 | + assert_match /track_list_#{@card_block.id}/, @response.body | ||
21 | + end | ||
22 | + | ||
23 | + should 'display tracks for list block' do | ||
24 | + xhr :get, :view_tracks, :id => @block.id, :page => 1 | ||
25 | + assert_match /track_list_#{@block.id}/, @response.body | ||
26 | + end | ||
27 | + | ||
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 | ||
32 | + xhr :get, :view_tracks, :id => @block.id, :page => 1, :per_page => 10 | ||
33 | + assert_equal 10, @response.body.scan(/item/).size | ||
34 | + end | ||
35 | + | ||
36 | + 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 | ||
40 | + xhr :get, :view_tracks, :id => @block.id, :page => 1 | ||
41 | + assert_equal @block.limit, @response.body.scan(/item/).size | ||
42 | + end | ||
43 | + | ||
44 | + should 'display page for all tracks' do | ||
45 | + get :all_tracks, :id => @block.id | ||
46 | + assert_match /track_list_#{@block.id}/, @response.body | ||
47 | + end | ||
48 | + | ||
49 | + 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 | ||
53 | + get :all_tracks, :id => @block.id | ||
54 | + assert assigns['show_more'] | ||
55 | + assert_match /track_list_more_#{@block.id}/, @response.body | ||
56 | + end | ||
57 | + | ||
58 | + should 'do not show more link in all tracks if there is no more tracks to show' do | ||
59 | + CommunityTrackPlugin::Track.destroy_all | ||
60 | + get :all_tracks, :id => @block.id | ||
61 | + assert !assigns['show_more'] | ||
62 | + assert_no_match /track_list_more_#{@block.id}/, @response.body | ||
63 | + end | ||
64 | + | ||
65 | + should 'show select community page if user is logged in' do | ||
66 | + user = create_user('testinguser') | ||
67 | + login_as(user.login) | ||
68 | + get :select_community | ||
69 | + assert_template 'select_community' | ||
70 | + end | ||
71 | + | ||
72 | + should 'redirect to login page if user try to access community selection' do | ||
73 | + logout | ||
74 | + get :select_community | ||
75 | + assert_redirected_to :controller => 'account', :action => 'login' | ||
76 | + end | ||
77 | + | ||
78 | + should 'display for selection communities where user has permission to post content' do | ||
79 | + user = create_user('testinguser') | ||
80 | + login_as(user.login) | ||
81 | + @community.add_member(user.person) | ||
82 | + get :select_community | ||
83 | + assert_tag :tag => 'li', :attributes => {:class => 'search-profile-item'} | ||
84 | + assert_tag :tag => 'input', :attributes => {:id => "community_identifier_#{@community.identifier}"} | ||
85 | + end | ||
86 | + | ||
87 | + should 'do not display communities where user has not permission to post content' do | ||
88 | + user = create_user('testinguser') | ||
89 | + login_as(user.login) | ||
90 | + get :select_community | ||
91 | + assert_no_tag :tag => 'input', :attributes => {:id => "community_identifier_#{@community.identifier}"} | ||
92 | + end | ||
93 | + | ||
94 | + should 'redirect to new content with track content type' do | ||
95 | + user = create_user('testinguser') | ||
96 | + login_as(user.login) | ||
97 | + post :select_community, :profile => user.person.identifier, :community_identifier => @community.identifier | ||
98 | + assert_redirected_to :controller => 'cms', :action => 'new', :type => "CommunityTrackPlugin::Track", :profile => @community.identifier | ||
99 | + end | ||
100 | + | ||
101 | + should 'return error message if user do not select a community' do | ||
102 | + user = create_user('testinguser') | ||
103 | + login_as(user.login) | ||
104 | + post :select_community, :profile => user.person.identifier, :community_identifier => nil | ||
105 | + assert_equal 1, assigns(:failed).count | ||
106 | + assert_tag :tag => 'div', :attributes => {:id => 'errorExplanation'} | ||
107 | + end | ||
108 | + | ||
109 | +end |
@@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../../test/test_helper' |
plugins/community_track/test/unit/community_track_plugin/step_helper_test.rb
0 → 100644
@@ -0,0 +1,38 @@ | @@ -0,0 +1,38 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../test_helper' | ||
2 | + | ||
3 | +class StepHelperTest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + include CommunityTrackPlugin::StepHelper | ||
6 | + | ||
7 | + def setup | ||
8 | + @step = CommunityTrackPlugin::Step.new | ||
9 | + @step.stubs(:active?).returns(false) | ||
10 | + @step.stubs(:finished?).returns(false) | ||
11 | + @step.stubs(:waiting?).returns(false) | ||
12 | + end | ||
13 | + | ||
14 | + should 'return active class when step is active' do | ||
15 | + @step.stubs(:active?).returns(true) | ||
16 | + assert_equal 'step_active', status_class(@step) | ||
17 | + end | ||
18 | + | ||
19 | + should 'return finished class when step is finished' do | ||
20 | + @step.stubs(:finished?).returns(true) | ||
21 | + assert_equal 'step_finished', status_class(@step) | ||
22 | + end | ||
23 | + | ||
24 | + should 'return waiting class when step is active' do | ||
25 | + @step.stubs(:waiting?).returns(true) | ||
26 | + assert_equal 'step_waiting', status_class(@step) | ||
27 | + end | ||
28 | + | ||
29 | + should 'return a description for status' do | ||
30 | + @step.stubs(:waiting?).returns(true) | ||
31 | + assert_equal _('Waiting'), status_description(@step) | ||
32 | + end | ||
33 | + | ||
34 | + should 'return nil at custom_options_for_article' do | ||
35 | + assert !custom_options_for_article(fast_create(Article)) | ||
36 | + end | ||
37 | + | ||
38 | +end |
plugins/community_track/test/unit/community_track_plugin/step_test.rb
0 → 100644
@@ -0,0 +1,265 @@ | @@ -0,0 +1,265 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../test_helper' | ||
2 | + | ||
3 | +class StepTest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + def setup | ||
6 | + @profile = fast_create(Community) | ||
7 | + @track = CommunityTrackPlugin::Track.create(:profile_id => @profile.id, :name => 'track') | ||
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 'describe yourself' do | ||
13 | + assert CommunityTrackPlugin::Step.description | ||
14 | + end | ||
15 | + | ||
16 | + should 'has a short description' do | ||
17 | + assert CommunityTrackPlugin::Step.short_description | ||
18 | + end | ||
19 | + | ||
20 | + should 'set published to false on create' do | ||
21 | + today = Date.today | ||
22 | + step = CommunityTrackPlugin::Step.create(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :start_date => today, :end_date => today, :published => true) | ||
23 | + assert !step.published | ||
24 | + end | ||
25 | + | ||
26 | + should 'do not allow step creation with a parent that is not a track' do | ||
27 | + today = Date.today | ||
28 | + blog = fast_create(Blog) | ||
29 | + step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => blog, :start_date => today, :end_date => today, :published => true) | ||
30 | + assert !step.save | ||
31 | + end | ||
32 | + | ||
33 | + should 'do not allow step creation without a parent' do | ||
34 | + today = Date.today | ||
35 | + step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => nil, :start_date => today, :end_date => today, :published => true) | ||
36 | + assert !step.save | ||
37 | + end | ||
38 | + | ||
39 | + should 'create step if end date is equal to start date' do | ||
40 | + @step.start_date = Date.today | ||
41 | + @step.end_date = Date.today | ||
42 | + assert @step.save | ||
43 | + end | ||
44 | + | ||
45 | + should 'create step if end date is after start date' do | ||
46 | + @step.start_date = Date.today | ||
47 | + @step.end_date = Date.today + 1.day | ||
48 | + assert @step.save | ||
49 | + end | ||
50 | + | ||
51 | + should 'do not create step if end date is before start date' do | ||
52 | + @step.start_date = Date.today | ||
53 | + @step.end_date = Date.today - 1.day | ||
54 | + assert !@step.save | ||
55 | + end | ||
56 | + | ||
57 | + should 'do not validate date period if start date is nil' do | ||
58 | + @step.start_date = nil | ||
59 | + @step.end_date_equal_or_after_start_date.inspect | ||
60 | + assert [], @step.errors | ||
61 | + end | ||
62 | + | ||
63 | + should 'do not validate date period if end date is nil' do | ||
64 | + @step.end_date = nil | ||
65 | + @step.end_date_equal_or_after_start_date.inspect | ||
66 | + assert [], @step.errors | ||
67 | + end | ||
68 | + | ||
69 | + should 'be active if today is between start and end dates' do | ||
70 | + @step.start_date = Date.today | ||
71 | + @step.end_date = Date.today + 1.day | ||
72 | + assert @step.active? | ||
73 | + end | ||
74 | + | ||
75 | + should 'be finished if today is after the end date' do | ||
76 | + @step.start_date = Date.today - 2.day | ||
77 | + @step.end_date = Date.today - 1.day | ||
78 | + assert @step.finished? | ||
79 | + end | ||
80 | + | ||
81 | + should 'be waiting if today is before the end date' do | ||
82 | + @step.start_date = Date.today + 1.day | ||
83 | + @step.end_date = Date.today + 2.day | ||
84 | + assert @step.waiting? | ||
85 | + end | ||
86 | + | ||
87 | + should 'return delayed job created with a specific step_id' do | ||
88 | + step_id = 0 | ||
89 | + CommunityTrackPlugin::ActivationJob.new(step_id) | ||
90 | + assert CommunityTrackPlugin::ActivationJob.find(step_id) | ||
91 | + end | ||
92 | + | ||
93 | + should 'create delayed job' do | ||
94 | + @step.start_date = Date.today | ||
95 | + @step.end_date = Date.today | ||
96 | + @step.schedule_activation | ||
97 | + assert_equal 1, Delayed::Job.count | ||
98 | + assert_equal @step.start_date, Delayed::Job.first.run_at.to_date | ||
99 | + end | ||
100 | + | ||
101 | + should 'do not duplicate delayed job' do | ||
102 | + @step.start_date = Date.today | ||
103 | + @step.end_date = Date.today | ||
104 | + @step.schedule_activation | ||
105 | + @step.schedule_activation | ||
106 | + assert_equal 1, Delayed::Job.count | ||
107 | + end | ||
108 | + | ||
109 | + should 'create delayed job when a step is saved' do | ||
110 | + @step.start_date = Date.today | ||
111 | + @step.end_date = Date.today | ||
112 | + @step.save! | ||
113 | + assert_equal @step.start_date, Delayed::Job.first.run_at.to_date | ||
114 | + end | ||
115 | + | ||
116 | + should 'create delayed job even if start date has passed' do | ||
117 | + @step.start_date = Date.today - 2.days | ||
118 | + @step.end_date = Date.today | ||
119 | + @step.schedule_activation | ||
120 | + assert_equal @step.start_date, Delayed::Job.first.run_at.to_date | ||
121 | + end | ||
122 | + | ||
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 | ||
132 | + @step.start_date = Date.today - 5.days | ||
133 | + @step.end_date = Date.today - 2.days | ||
134 | + @step.published = true | ||
135 | + @step.schedule_activation | ||
136 | + assert_equal @step.end_date + 1.day, Delayed::Job.first.run_at.to_date | ||
137 | + end | ||
138 | + | ||
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 | ||
160 | + @step.start_date = Date.today | ||
161 | + @step.end_date = Date.today | ||
162 | + @step.published = false | ||
163 | + @step.save! | ||
164 | + assert_equal 1, Delayed::Job.count | ||
165 | + Delayed::Job.destroy_all | ||
166 | + @step.name = 'changed name' | ||
167 | + @step.save! | ||
168 | + assert_equal 0, Delayed::Job.count | ||
169 | + end | ||
170 | + | ||
171 | + should 'set position on save' do | ||
172 | + assert !@step.position | ||
173 | + @step.save! | ||
174 | + assert_equal 1, @step.position | ||
175 | + step2 = CommunityTrackPlugin::Step.new(:name => 'Step2', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) | ||
176 | + step2.save! | ||
177 | + assert_equal 2, step2.position | ||
178 | + end | ||
179 | + | ||
180 | + should 'publish step if it is active' do | ||
181 | + @step.start_date = Date.today | ||
182 | + @step.save! | ||
183 | + assert !@step.published | ||
184 | + @step.publish | ||
185 | + @step.reload | ||
186 | + assert @step.published | ||
187 | + end | ||
188 | + | ||
189 | + should 'do not publish step if it is not active' do | ||
190 | + @step.start_date = Date.today + 2.days | ||
191 | + @step.end_date = Date.today + 3.days | ||
192 | + @step.save! | ||
193 | + assert !@step.published | ||
194 | + @step.publish | ||
195 | + @step.reload | ||
196 | + assert !@step.published | ||
197 | + end | ||
198 | + | ||
199 | + should 'unpublish step if it is not active anymore' do | ||
200 | + @step.start_date = Date.today | ||
201 | + @step.save! | ||
202 | + @step.publish | ||
203 | + @step.reload | ||
204 | + assert @step.published | ||
205 | + | ||
206 | + @step.start_date = Date.today - 2.days | ||
207 | + @step.end_date = Date.today - 1.day | ||
208 | + @step.save! | ||
209 | + @step.publish | ||
210 | + @step.reload | ||
211 | + assert !@step.published | ||
212 | + end | ||
213 | + | ||
214 | + should 'set position to zero if step is hidden' do | ||
215 | + @step.hidden = true | ||
216 | + @step.save! | ||
217 | + assert_equal 0, @step.position | ||
218 | + end | ||
219 | + | ||
220 | + should 'change position to zero if step becomes hidden' do | ||
221 | + @step.save! | ||
222 | + assert_equal 1, @step.position | ||
223 | + @step.hidden = true | ||
224 | + @step.save! | ||
225 | + assert_equal 0, @step.position | ||
226 | + end | ||
227 | + | ||
228 | + should 'change position to botton if a hidden step becomes visible' do | ||
229 | + step1 = CommunityTrackPlugin::Step.new(:name => 'Step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) | ||
230 | + step1.save! | ||
231 | + @step.hidden = true | ||
232 | + @step.save! | ||
233 | + assert_equal 0, @step.position | ||
234 | + @step.hidden = false | ||
235 | + @step.save! | ||
236 | + assert_equal 2, @step.position | ||
237 | + end | ||
238 | + | ||
239 | + should 'decrement lower items positions if a step becomes hidden' do | ||
240 | + @step.save! | ||
241 | + step1 = CommunityTrackPlugin::Step.new(:name => 'Step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) | ||
242 | + step1.save! | ||
243 | + assert_equal 2, step1.position | ||
244 | + @step.hidden = true | ||
245 | + @step.save! | ||
246 | + step1.reload | ||
247 | + assert_equal 1, step1.position | ||
248 | + end | ||
249 | + | ||
250 | + should 'do not publish a hidden step' do | ||
251 | + @step.start_date = Date.today | ||
252 | + @step.hidden = true | ||
253 | + @step.save! | ||
254 | + assert !@step.published | ||
255 | + @step.publish | ||
256 | + @step.reload | ||
257 | + assert !@step.published | ||
258 | + end | ||
259 | + | ||
260 | + should 'return enabled tools for a step' do | ||
261 | + assert_includes @step.enabled_tools, TinyMceArticle | ||
262 | + assert_includes @step.enabled_tools, Forum | ||
263 | + end | ||
264 | + | ||
265 | +end |
plugins/community_track/test/unit/community_track_plugin/track_card_list_block_test.rb
0 → 100644
@@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../test_helper' | ||
2 | + | ||
3 | +class TrackCardListBlockTest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + def setup | ||
6 | + @community = fast_create(Community) | ||
7 | + box = fast_create(Box, :owner_id => @community.id, :owner_type => @community.class.name) | ||
8 | + @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) | ||
9 | + end | ||
10 | + | ||
11 | + should 'describe yourself' do | ||
12 | + assert CommunityTrackPlugin::TrackCardListBlock.description | ||
13 | + end | ||
14 | + | ||
15 | + should 'return track_card as track partial' do | ||
16 | + assert_equal 'track_card', @block.track_partial | ||
17 | + end | ||
18 | + | ||
19 | +end |
plugins/community_track/test/unit/community_track_plugin/track_helper_test.rb
0 → 100644
@@ -0,0 +1,55 @@ | @@ -0,0 +1,55 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../test_helper' | ||
2 | + | ||
3 | +class TrackHelperTest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + include CommunityTrackPlugin::TrackHelper | ||
6 | + include NoosferoTestHelper | ||
7 | + include ActionView::Helpers::TextHelper | ||
8 | + | ||
9 | + def setup | ||
10 | + @track = CommunityTrackPlugin::Track.new | ||
11 | + end | ||
12 | + | ||
13 | + should 'return css class for track with category' do | ||
14 | + category = fast_create(Category, :name => 'education') | ||
15 | + @track.categories << category | ||
16 | + assert_equal 'category_education', category_class(@track) | ||
17 | + end | ||
18 | + | ||
19 | + should 'return default css class for a track without category' do | ||
20 | + assert_equal 'category_not_defined', category_class(@track) | ||
21 | + end | ||
22 | + | ||
23 | + should 'return css class for first category that the class belongs' do | ||
24 | + category1 = fast_create(Category, :name => 'education') | ||
25 | + @track.categories << category1 | ||
26 | + category2 = fast_create(Category, :name => 'tech') | ||
27 | + @track.categories << category2 | ||
28 | + assert_equal 'category_education', category_class(@track) | ||
29 | + end | ||
30 | + | ||
31 | + should 'return css class with category name properly formated' do | ||
32 | + category = fast_create(Category, :name => 'not defined') | ||
33 | + @track.categories << category | ||
34 | + assert_equal 'category_not-defined', category_class(@track) | ||
35 | + end | ||
36 | + | ||
37 | + should 'return lead for track removing html tags' do | ||
38 | + @track.abstract = "display <div>pure text</div>" | ||
39 | + assert_equal "display pure text", track_card_lead(@track) | ||
40 | + end | ||
41 | + | ||
42 | + should 'limit lead char length' do | ||
43 | + @track.abstract = "" | ||
44 | + 400.times { @track.abstract += "a" } | ||
45 | + assert_equal 306, track_card_lead(@track).length | ||
46 | + end | ||
47 | + | ||
48 | + should 'display a shorter lead if track has a image' do | ||
49 | + @track.abstract = "" | ||
50 | + @track.image = Image.new | ||
51 | + 400.times { @track.abstract += "a" } | ||
52 | + assert_equal 186, track_card_lead(@track).length | ||
53 | + end | ||
54 | + | ||
55 | +end |
plugins/community_track/test/unit/community_track_plugin/track_list_block_test.rb
0 → 100644
@@ -0,0 +1,105 @@ | @@ -0,0 +1,105 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../test_helper' | ||
2 | + | ||
3 | +class TrackListBlockTest < ActiveSupport::TestCase | ||
4 | + | ||
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) | ||
10 | + @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box) | ||
11 | + end | ||
12 | + | ||
13 | + should 'describe yourself' do | ||
14 | + assert CommunityTrackPlugin::TrackListBlock.description | ||
15 | + end | ||
16 | + | ||
17 | + should 'return track as track partial' do | ||
18 | + assert_equal 'track', @block.track_partial | ||
19 | + end | ||
20 | + | ||
21 | + should 'load more at another page default to false' do | ||
22 | + assert !@block.more_another_page | ||
23 | + end | ||
24 | + | ||
25 | + should 'list articles only of track type' do | ||
26 | + article = fast_create(Article, :profile_id => @community.id) | ||
27 | + assert_includes @community.articles, article | ||
28 | + assert_equal [@track], @block.tracks | ||
29 | + end | ||
30 | + | ||
31 | + 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 | ||
35 | + assert_equal @block.limit, @block.tracks.count | ||
36 | + end | ||
37 | + | ||
38 | + 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 | ||
42 | + assert @block.footer | ||
43 | + end | ||
44 | + | ||
45 | + 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 | ||
49 | + assert !@block.footer | ||
50 | + end | ||
51 | + | ||
52 | + should 'count all tracks' do | ||
53 | + @block.owner.articles.destroy_all | ||
54 | + 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 | ||
58 | + article = fast_create(Article, :profile_id => @block.owner.id) | ||
59 | + @block.reload | ||
60 | + assert_includes @block.owner.articles, article | ||
61 | + assert_equal tracks_to_insert, @block.count_tracks | ||
62 | + end | ||
63 | + | ||
64 | + should 'have a second page if there is more tracks than limit' do | ||
65 | + @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 | ||
69 | + assert @block.has_page?(2) | ||
70 | + assert !@block.has_page?(3) | ||
71 | + end | ||
72 | + | ||
73 | + should 'filter tracks by category' do | ||
74 | + @block.owner.articles.destroy_all | ||
75 | + category = fast_create(Category) | ||
76 | + 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) | ||
80 | + track1.add_category(category) | ||
81 | + @block.category_ids = [category.id] | ||
82 | + assert_equal [track1], @block.all_tracks | ||
83 | + end | ||
84 | + | ||
85 | + should 'return all tracks if block does not filter by category' do | ||
86 | + @block.owner.articles.destroy_all | ||
87 | + 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) | ||
90 | + track1.add_category(category) | ||
91 | + assert_includes @block.all_tracks, track1 | ||
92 | + assert_includes @block.all_tracks, track2 | ||
93 | + end | ||
94 | + | ||
95 | + should 'accept any categories' do | ||
96 | + assert @block.accept_category?(nil) | ||
97 | + assert @block.accept_category?(fast_create(Category)) | ||
98 | + end | ||
99 | + | ||
100 | + should 'format category ids array avoiding duplicates and zeros' do | ||
101 | + @block.category_ids = ["0", "0", "1", "1", "2", nil] | ||
102 | + assert_equal [1, 2], @block.category_ids | ||
103 | + end | ||
104 | + | ||
105 | +end |
plugins/community_track/test/unit/community_track_plugin/track_test.rb
0 → 100644
@@ -0,0 +1,113 @@ | @@ -0,0 +1,113 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../test_helper' | ||
2 | + | ||
3 | +class TrackTest < ActiveSupport::TestCase | ||
4 | + | ||
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) | ||
10 | + end | ||
11 | + | ||
12 | + should 'describe yourself' do | ||
13 | + assert CommunityTrackPlugin::Track.description | ||
14 | + end | ||
15 | + | ||
16 | + should 'has a short descriptionf' do | ||
17 | + assert CommunityTrackPlugin::Track.short_description | ||
18 | + end | ||
19 | + | ||
20 | + should 'has a css class name' do | ||
21 | + assert_equal 'community-track-plugin-track', @track.css_class_name | ||
22 | + end | ||
23 | + | ||
24 | + should 'return comments count of children tools' do | ||
25 | + assert_equal 0, @track.comments_count | ||
26 | + owner = create_user('testuser').person | ||
27 | + article = create(Article, :name => 'article', :parent_id => @step.id, :profile_id => owner.id) | ||
28 | + comment = create(Comment, :source => article, :author_id => owner.id) | ||
29 | + assert_equal 1, @track.comments_count | ||
30 | + end | ||
31 | + | ||
32 | + should 'return children steps' do | ||
33 | + assert_equal [@step], @track.steps_unsorted | ||
34 | + end | ||
35 | + | ||
36 | + should 'do not return other articles type at steps' do | ||
37 | + article = fast_create(Article, :parent_id => @track.id, :profile_id => @track.profile.id) | ||
38 | + assert_includes @track.children, article | ||
39 | + assert_equal [@step], @track.steps_unsorted | ||
40 | + end | ||
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 | ||
46 | + end | ||
47 | + | ||
48 | + should 'return empty for category name if it has no category' do | ||
49 | + @track.categories.delete_all | ||
50 | + assert_equal '', @track.category_name | ||
51 | + end | ||
52 | + | ||
53 | + should 'return category name of first category' do | ||
54 | + category = fast_create(Category, :name => 'category') | ||
55 | + @track.add_category(category, true) | ||
56 | + category2 = fast_create(Category, :name => 'category2') | ||
57 | + @track.add_category(category2, true) | ||
58 | + assert_equal 'category', @track.category_name | ||
59 | + end | ||
60 | + | ||
61 | + should 'return steps with insert order' do | ||
62 | + @track.children.destroy_all | ||
63 | + step1 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step1", :profile => @track.profile) | ||
64 | + step2 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step2", :profile => @track.profile) | ||
65 | + step3 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step3", :profile => @track.profile) | ||
66 | + assert_equal 1, step1.position | ||
67 | + assert_equal 2, step2.position | ||
68 | + assert_equal 3, step3.position | ||
69 | + assert_equal [step1, step2, step3], @track.steps | ||
70 | + end | ||
71 | + | ||
72 | + should 'return steps with order defined by position attribute' do | ||
73 | + @track.children.destroy_all | ||
74 | + step1 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step1", :profile => @track.profile) | ||
75 | + step2 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step2", :profile => @track.profile) | ||
76 | + step3 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step3", :profile => @track.profile) | ||
77 | + step1.position = 3 | ||
78 | + step1.save! | ||
79 | + step2.position = 1 | ||
80 | + step2.save! | ||
81 | + step3.position = 2 | ||
82 | + step3.save! | ||
83 | + assert_equal [step2, step3, step1], @track.steps | ||
84 | + end | ||
85 | + | ||
86 | + should 'save steps in a new order' do | ||
87 | + @track.children.destroy_all | ||
88 | + | ||
89 | + step1 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step1", :profile => @track.profile) | ||
90 | + step2 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step2", :profile => @track.profile) | ||
91 | + step3 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step3", :profile => @track.profile) | ||
92 | + | ||
93 | + assert_equal [step1.id, step2.id, step3.id], @track.steps.map(&:id) | ||
94 | + @track.reorder_steps([step3.id, step1.id, step2.id]) | ||
95 | + @track.reload | ||
96 | + assert_equal [step3.id, step1.id, step2.id], @track.steps.map(&:id) | ||
97 | + end | ||
98 | + | ||
99 | + should 'do not return hidden steps' do | ||
100 | + hidden_step = CommunityTrackPlugin::Step.new(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => 'hidden step', :profile => @track.profile) | ||
101 | + hidden_step.hidden = true | ||
102 | + hidden_step.save! | ||
103 | + assert_equal [@step], @track.steps | ||
104 | + end | ||
105 | + | ||
106 | + should 'return hidden steps' do | ||
107 | + hidden_step = CommunityTrackPlugin::Step.new(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => 'hidden step', :profile => @track.profile) | ||
108 | + hidden_step.hidden = true | ||
109 | + hidden_step.save! | ||
110 | + assert_equal [hidden_step], @track.hidden_steps | ||
111 | + end | ||
112 | + | ||
113 | +end |
plugins/community_track/test/unit/community_track_plugin_test.rb
0 → 100644
@@ -0,0 +1,78 @@ | @@ -0,0 +1,78 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class CommunityTrackPluginTest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + def setup | ||
6 | + @plugin = CommunityTrackPlugin.new | ||
7 | + @profile = fast_create(Community) | ||
8 | + @params = {} | ||
9 | + @plugin.stubs(:context).returns(self) | ||
10 | + end | ||
11 | + | ||
12 | + attr_reader :profile, :params | ||
13 | + | ||
14 | + should 'has name' do | ||
15 | + assert CommunityTrackPlugin.plugin_name | ||
16 | + end | ||
17 | + | ||
18 | + should 'describe yourself' do | ||
19 | + assert CommunityTrackPlugin.plugin_description | ||
20 | + end | ||
21 | + | ||
22 | + should 'has stylesheet' do | ||
23 | + assert @plugin.stylesheet? | ||
24 | + end | ||
25 | + | ||
26 | + should 'return Track as a content type if profile is a community' do | ||
27 | + assert_includes @plugin.content_types, CommunityTrackPlugin::Track | ||
28 | + end | ||
29 | + | ||
30 | + should 'do not return Track as a content type if profile is not a community' do | ||
31 | + @profile = Organization.new | ||
32 | + assert_not_includes @plugin.content_types, CommunityTrackPlugin::Track | ||
33 | + end | ||
34 | + | ||
35 | + should 'do not return Track as a content type if there is a parent' do | ||
36 | + parent = fast_create(Blog, :profile_id => @profile.id) | ||
37 | + @params[:parent_id] = parent.id | ||
38 | + assert_not_includes @plugin.content_types, CommunityTrackPlugin::Track | ||
39 | + end | ||
40 | + | ||
41 | + should 'return Step as a content type if parent is a Track' do | ||
42 | + parent = fast_create(CommunityTrackPlugin::Track, :profile_id => @profile.id) | ||
43 | + @params[:parent_id] = parent.id | ||
44 | + assert_includes @plugin.content_types, CommunityTrackPlugin::Step | ||
45 | + end | ||
46 | + | ||
47 | + should 'do not return Step as a content type if parent is not a Track' do | ||
48 | + parent = fast_create(Blog, :profile_id => @profile.id) | ||
49 | + @params[:parent_id] = parent.id | ||
50 | + assert_not_includes @plugin.content_types, CommunityTrackPlugin::Step | ||
51 | + end | ||
52 | + | ||
53 | + should 'return Track and Step as a content type if context has no params' do | ||
54 | + parent = fast_create(Blog, :profile_id => @profile.id) | ||
55 | + expects(:respond_to?).with(:params).returns(false) | ||
56 | + assert_equivalent [CommunityTrackPlugin::Step, CommunityTrackPlugin::Track], @plugin.content_types | ||
57 | + end | ||
58 | + | ||
59 | + should 'return Track and Step as a content type if params is nil' do | ||
60 | + parent = fast_create(Blog, :profile_id => @profile.id) | ||
61 | + @params = nil | ||
62 | + assert_equivalent [CommunityTrackPlugin::Step, CommunityTrackPlugin::Track], @plugin.content_types | ||
63 | + end | ||
64 | + | ||
65 | + should 'return track card as an extra block' do | ||
66 | + assert_includes CommunityTrackPlugin.extra_blocks, CommunityTrackPlugin::TrackListBlock | ||
67 | + end | ||
68 | + | ||
69 | + should 'return true at content_remove_new if page is a track' do | ||
70 | + assert @plugin.content_remove_new(CommunityTrackPlugin::Track.new) | ||
71 | + end | ||
72 | + | ||
73 | + should 'return false at content_remove_new if page is not a track' do | ||
74 | + assert !@plugin.content_remove_new(CommunityTrackPlugin::Step.new) | ||
75 | + assert !@plugin.content_remove_new(Article.new) | ||
76 | + end | ||
77 | + | ||
78 | +end |
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +<% extend CommunityTrackPlugin::TrackHelper %> | ||
2 | +<div class="item <%= category_class(track) %>"> | ||
3 | + <div class="track_content"> | ||
4 | + <div class="lead"> | ||
5 | + <h3><%= link_to track.name, track.url %></h3> | ||
6 | + <div class="content"> | ||
7 | + <%= track.lead %> | ||
8 | + </div> | ||
9 | + </div> | ||
10 | + <div class="steps"> | ||
11 | + <h3><%= _("Steps") %></h3> | ||
12 | + <% 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> | ||
17 | + <% end %> | ||
18 | + </div> | ||
19 | + </div> | ||
20 | +</div> | ||
21 | +<br style="clear: both;"/> |
@@ -0,0 +1,27 @@ | @@ -0,0 +1,27 @@ | ||
1 | +<% extend CommunityTrackPlugin::TrackHelper %> | ||
2 | +<div class="item_card <%= category_class(track_card) %>"> | ||
3 | + <a href="<%= url_for track_card.url %>"> | ||
4 | + <div class="track_content"> | ||
5 | + <div class="title"> | ||
6 | + <%= track_card.category_name %> | ||
7 | + </div> | ||
8 | + <div class="image"> | ||
9 | + <%= image_tag track_card.image.public_filename if track_card.image %> | ||
10 | + </div> | ||
11 | + <div class="name"> | ||
12 | + <%= track_card.name %> | ||
13 | + </div> | ||
14 | + <div class="lead"> | ||
15 | + <%= track_card_lead(track_card) %> | ||
16 | + </div> | ||
17 | + </div> | ||
18 | + <div class="track_stats"> | ||
19 | + <div class="comments"> | ||
20 | + <%= "#{track_card.comments_count} comments" %> | ||
21 | + </div> | ||
22 | + <div class="hits"> | ||
23 | + <%= "#{track_card.hits} hits" %> | ||
24 | + </div> | ||
25 | + </div> | ||
26 | + </a> | ||
27 | +</div> |
plugins/community_track/views/blocks/_track_list_more.rhtml
0 → 100644
@@ -0,0 +1,12 @@ | @@ -0,0 +1,12 @@ | ||
1 | +<% force_same_page ||= false %> | ||
2 | +<div id="track_list_more_<%= block.id %>" class="more_button"> | ||
3 | + <% if block.more_another_page && !force_same_page %> | ||
4 | + <div class="view_all"> | ||
5 | + <%= link_to _('View All'), :id => block.id, :controller => 'community_track_plugin_public', :action => 'all_tracks' %> | ||
6 | + </div> | ||
7 | + <% else %> | ||
8 | + <div class="more"> | ||
9 | + <%= link_to_remote(_('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}")) %> | ||
10 | + </div> | ||
11 | + <% end %> | ||
12 | +</div> |
plugins/community_track/views/box_organizer/community_track_plugin/_track_list_block.rhtml
0 → 100644
@@ -0,0 +1,5 @@ | @@ -0,0 +1,5 @@ | ||
1 | +<div id='edit-track-list-block'> | ||
2 | + <%= labelled_form_field _('Limit of items'), text_field(:block, :limit, :size => 3) %> | ||
3 | + <%= labelled_form_field check_box(:block, :more_another_page) + _('Show more at another page'), '' %> | ||
4 | + <%= select_categories(:block, _('Select Categories')) %> | ||
5 | +</div> |
plugins/community_track/views/cms/community_track_plugin/_step.rhtml
0 → 100644
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +<%= required_fields_message %> | ||
2 | + | ||
3 | +<%= render :file => 'shared/tiny_mce' %> | ||
4 | + | ||
5 | +<div> | ||
6 | + <%= required f.text_field('name', :size => '64', :maxlength => 150) %> | ||
7 | + <%= labelled_form_field(_('Start date'), pick_date(:article, :start_date)) %> | ||
8 | + <%= labelled_form_field(_('End date'), pick_date(:article, :end_date)) %> | ||
9 | +</div> | ||
10 | + | ||
11 | +<%= labelled_form_field check_box(:article, :hidden) + _('Hidden Step'), '' %> | ||
12 | + | ||
13 | +<%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :body_label => 'Description:'} %> |
plugins/community_track/views/cms/community_track_plugin/_track.rhtml
0 → 100644
@@ -0,0 +1,18 @@ | @@ -0,0 +1,18 @@ | ||
1 | +<%= required_fields_message %> | ||
2 | + | ||
3 | +<%= render :file => 'shared/tiny_mce' %> | ||
4 | + | ||
5 | +<div> | ||
6 | + <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64', :maxlength => 150)) %> | ||
7 | +</div> | ||
8 | + | ||
9 | +<%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :body_label => 'Description:'} %> | ||
10 | + | ||
11 | +<div> | ||
12 | + <% f.fields_for :image_builder, @article.image do |i| %> | ||
13 | + <%= file_field_or_thumbnail(_('Image:'), @article.image, i) %> | ||
14 | + <% end %> | ||
15 | + | ||
16 | + <%= labelled_form_field(_('Goals:'), text_area(:article, :goals, :rows => 3, :cols => 64)) %> | ||
17 | + <%= labelled_form_field(_('Expected Results:'), text_area(:article, :expected_results, :rows => 3, :cols => 64)) %> | ||
18 | +</div> |
plugins/community_track/views/community_track_plugin_public/all_tracks.rhtml
0 → 100644
@@ -0,0 +1,10 @@ | @@ -0,0 +1,10 @@ | ||
1 | +<h1><%= _('Tracks') %></h1> | ||
2 | +<div class="all_tracks"> | ||
3 | + <div class="track_list track_card_list" id="track_list_<%= @block.id %>"> | ||
4 | + <%= render :partial => "blocks/#{@block.track_partial}", :collection => @tracks, :locals => {:block => @block} %> | ||
5 | + </div> | ||
6 | + <br style="clear: both;"/> | ||
7 | + <% if @show_more %> | ||
8 | + <%= render :partial => "blocks/track_list_more", :locals => {:block => @block, :force_same_page => true, :page => 2, :per_page => @per_page} %> | ||
9 | + <% end %> | ||
10 | +</div> |
plugins/community_track/views/community_track_plugin_public/select_community.rhtml
0 → 100644
@@ -0,0 +1,41 @@ | @@ -0,0 +1,41 @@ | ||
1 | +<div> | ||
2 | + | ||
3 | +<h1><%= _('Select Community') %></h1> | ||
4 | + | ||
5 | +<% if !@failed.blank? %> | ||
6 | + <div class="errorExplanation" id="errorExplanation"> | ||
7 | + <div style="color: #c00;"> | ||
8 | + <% @failed.each do |error|%> | ||
9 | + <strong> <%= error %></strong> | ||
10 | + <% end %> | ||
11 | + </div> | ||
12 | + </div> | ||
13 | +<% end %> | ||
14 | + | ||
15 | +<% button_bar do %> | ||
16 | + <%= button(:add, __('Create a new community'), :controller => 'memberships', :action => 'new_community', :profile => user.identifier, :back_to => @back_to) %> | ||
17 | +<% end %> | ||
18 | + | ||
19 | +<% form_tag({:controller => 'community_track_plugin_public', :action => 'select_community', :profile => user.identifier}) do %> | ||
20 | +<div class="common-profile-list-block"> | ||
21 | + <ul> | ||
22 | + <% @communities.each do |community| %> | ||
23 | + <li class="search-profile-item"> | ||
24 | + <div class="common-profile-list-block"> | ||
25 | + <div class="vcard"> | ||
26 | + <a href="#" onclick="jQuery('<%= "#community_identifier_#{community.identifier}" %>').attr('checked', true);"> | ||
27 | + <span class="profile-image"><%= profile_image(community) %></span> | ||
28 | + <span class="org"><%= community.name %></span> | ||
29 | + <span class="select_community"><%= radio_button_tag(:community_identifier, community.identifier) %></span> | ||
30 | + </a> | ||
31 | + </div> | ||
32 | + </div> | ||
33 | + </li> | ||
34 | + <% end %> | ||
35 | + </ul> | ||
36 | + </div> | ||
37 | + <div class="clear"></div> | ||
38 | + <br/> | ||
39 | + <%= submit_button :save, _('New Track') %> | ||
40 | +<% end %> | ||
41 | +</div> |
@@ -0,0 +1,31 @@ | @@ -0,0 +1,31 @@ | ||
1 | +<div id="step"> | ||
2 | + <div class="event-info"> | ||
3 | + <ul class="event-data"> | ||
4 | + <li class="event-dates"> | ||
5 | + <span><%= _('When:') %></span><%= show_period(step.start_date, step.end_date) %> | ||
6 | + </li> | ||
7 | + </ul> | ||
8 | + </div> | ||
9 | + <div> | ||
10 | + <%= step.body %> | ||
11 | + </div> | ||
12 | + <h3><%= _("Tools") %></h3> | ||
13 | + <% if step.allow_create?(user) %> | ||
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 %> | ||
20 | + </div> | ||
21 | + <% end %> | ||
22 | + <div class="tools"> | ||
23 | + <% step.tools.each do |tool| %> | ||
24 | + <div class="item"> | ||
25 | + <div class="name"> | ||
26 | + <%= link_to tool.name, tool.url, :class=>"button with-text icon-new icon-new#{tool.class.icon_name}" %> | ||
27 | + </div> | ||
28 | + </div> | ||
29 | + <% end %> | ||
30 | + </div> | ||
31 | +</div> |
plugins/community_track/views/content_viewer/track.rhtml
0 → 100644
@@ -0,0 +1,67 @@ | @@ -0,0 +1,67 @@ | ||
1 | +<% extend CommunityTrackPlugin::StepHelper %> | ||
2 | + | ||
3 | +<% form_tag({:controller => 'community_track_plugin_myprofile', :action => 'save_order', :track => track}) do %> | ||
4 | +<div id="track"> | ||
5 | + <div> | ||
6 | + <%= track.body %> | ||
7 | + </div> | ||
8 | + | ||
9 | + <h3><%= _("Steps") %></h3> | ||
10 | + | ||
11 | + <% if track.allow_create?(user) %> | ||
12 | + <div class="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 %> | ||
14 | + <strong><%= _("New %s") % CommunityTrackPlugin::Step.short_description %></strong> | ||
15 | + <% end %> | ||
16 | + <a href="#" class="reorder_button button with-text icon-up" onclick="enableReorder();"><%= _('Reorder Steps') %></a> | ||
17 | + <%= submit_button :save, _('Save Order'), :class => "save_button" %> | ||
18 | + </div> | ||
19 | + <script> | ||
20 | + function enableReorder() { | ||
21 | + jQuery(".reorder_button").hide(); | ||
22 | + jQuery(".save_button").show(); | ||
23 | + jQuery("#sortable li").addClass("ui-state-default"); | ||
24 | + jQuery("#sortable").sortable(); | ||
25 | + jQuery("#sortable").disableSelection(); | ||
26 | + } | ||
27 | + </script> | ||
28 | + <% end %> | ||
29 | + | ||
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 %> | ||
44 | + </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 %> | ||
65 | +</div> | ||
66 | +<% end %> | ||
67 | +</div> |
plugins/community_track/views/environment_design/community_track_plugin
0 → 120000
plugins/community_track/views/profile_design/community_track_plugin
0 → 120000
test/functional/memberships_controller_test.rb
@@ -245,4 +245,17 @@ class MembershipsControllerTest < ActionController::TestCase | @@ -245,4 +245,17 @@ class MembershipsControllerTest < ActionController::TestCase | ||
245 | assert_tag :tag => 'input', :attributes => {:id => 'community_plugin2', :type => 'hidden', :value => 'Plugin 2'} | 245 | assert_tag :tag => 'input', :attributes => {:id => 'community_plugin2', :type => 'hidden', :value => 'Plugin 2'} |
246 | end | 246 | end |
247 | 247 | ||
248 | + should 'redirect to back_to parameter when create a new community' do | ||
249 | + back_to = '/' | ||
250 | + post :new_community, :profile => profile.identifier, :community => { :name => 'My shiny new community', :description => 'This is a community devoted to anything interesting we find in the internet '}, :back_to => back_to | ||
251 | + assert_response :redirect | ||
252 | + assert_redirected_to back_to | ||
253 | + end | ||
254 | + | ||
255 | + should 'cancel button redirect to back_to parameter' do | ||
256 | + back_to = '/' | ||
257 | + get :new_community, :profile => profile.identifier, :back_to => back_to | ||
258 | + assert_tag :tag => 'a', :attributes => { :class => 'button icon-cancel with-text', :href => back_to } | ||
259 | + end | ||
260 | + | ||
248 | end | 261 | end |
test/unit/article_test.rb
@@ -1764,4 +1764,13 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1764,4 +1764,13 @@ class ArticleTest < ActiveSupport::TestCase | ||
1764 | assert !a.belongs_to_forum? | 1764 | assert !a.belongs_to_forum? |
1765 | end | 1765 | end |
1766 | 1766 | ||
1767 | + should 'save image on create article' do | ||
1768 | + assert_difference Article, :count do | ||
1769 | + p = Article.create!(:name => 'test', :image_builder => { | ||
1770 | + :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') | ||
1771 | + }, :profile_id => @profile.id) | ||
1772 | + assert_equal p.image(true).filename, 'rails.png' | ||
1773 | + end | ||
1774 | + end | ||
1775 | + | ||
1767 | end | 1776 | end |
test/unit/category_test.rb
@@ -168,11 +168,11 @@ class CategoryTest < ActiveSupport::TestCase | @@ -168,11 +168,11 @@ class CategoryTest < ActiveSupport::TestCase | ||
168 | should "limit the possibile display colors" do | 168 | should "limit the possibile display colors" do |
169 | c = Category.new(:name => 'test category', :environment_id => @env.id) | 169 | c = Category.new(:name => 'test category', :environment_id => @env.id) |
170 | 170 | ||
171 | - c.display_color = 10 | 171 | + c.display_color = 16 |
172 | c.valid? | 172 | c.valid? |
173 | assert c.errors.invalid?(:display_color) | 173 | assert c.errors.invalid?(:display_color) |
174 | 174 | ||
175 | - valid = %w[ 1 2 3 4 ].map { |item| item.to_i } | 175 | + valid = (1..15).map { |item| item.to_i } |
176 | valid.each do |item| | 176 | valid.each do |item| |
177 | c.display_color = item | 177 | c.display_color = item |
178 | c.valid? | 178 | c.valid? |