From a67cc855a77c5eb300954c9aae3192495737ad74 Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Mon, 11 Nov 2013 16:47:50 -0300 Subject: [PATCH] Adding Community Track Plugin --- app/controllers/my_profile/memberships_controller.rb | 3 ++- app/helpers/categories_helper.rb | 18 ++++++++++++++---- app/models/article.rb | 2 ++ app/models/category.rb | 2 +- app/views/memberships/new_community.rhtml | 4 +++- db/migrate/20131011172930_add_image_to_article.rb | 13 +++++++++++++ db/migrate/20131015161830_add_position_to_article.rb | 13 +++++++++++++ plugins/community_track/controllers/myprofile/community_track_plugin_myprofile_controller.rb | 18 ++++++++++++++++++ plugins/community_track/controllers/public/community_track_plugin_public_controller.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++ plugins/community_track/lib/community_track_plugin.rb | 36 ++++++++++++++++++++++++++++++++++++ plugins/community_track/lib/community_track_plugin/step.rb | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/community_track/lib/community_track_plugin/step_helper.rb | 30 ++++++++++++++++++++++++++++++ plugins/community_track/lib/community_track_plugin/track.rb | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/community_track/lib/community_track_plugin/track_card_list_block.rb | 15 +++++++++++++++ plugins/community_track/lib/community_track_plugin/track_helper.rb | 12 ++++++++++++ plugins/community_track/lib/community_track_plugin/track_list_block.rb | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/community_track/public/icons/community-track.png | Bin 0 -> 1529 bytes plugins/community_track/public/style.css | 190 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/community_track/test/functional/community_track_plugin_cms_controller_test.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++ plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/community_track/test/functional/community_track_plugin_environment_design_controller_test.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++ plugins/community_track/test/functional/community_track_plugin_myprofile_controller_test.rb | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ plugins/community_track/test/functional/community_track_plugin_public_controller_test.rb | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/community_track/test/test_helper.rb | 1 + plugins/community_track/test/unit/community_track_plugin/step_helper_test.rb | 38 ++++++++++++++++++++++++++++++++++++++ plugins/community_track/test/unit/community_track_plugin/step_test.rb | 265 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/community_track/test/unit/community_track_plugin/track_card_list_block_test.rb | 19 +++++++++++++++++++ plugins/community_track/test/unit/community_track_plugin/track_helper_test.rb | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/community_track/test/unit/community_track_plugin/track_list_block_test.rb | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/community_track/test/unit/community_track_plugin/track_test.rb | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/community_track/test/unit/community_track_plugin_test.rb | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/community_track/views/blocks/_track.rhtml | 21 +++++++++++++++++++++ plugins/community_track/views/blocks/_track_card.rhtml | 27 +++++++++++++++++++++++++++ plugins/community_track/views/blocks/_track_list_more.rhtml | 12 ++++++++++++ plugins/community_track/views/blocks/track_list.rhtml | 6 ++++++ plugins/community_track/views/box_organizer/community_track_plugin/_track_list_block.rhtml | 5 +++++ plugins/community_track/views/cms/community_track_plugin/_step.rhtml | 13 +++++++++++++ plugins/community_track/views/cms/community_track_plugin/_track.rhtml | 18 ++++++++++++++++++ plugins/community_track/views/community_track_plugin_public/all_tracks.rhtml | 10 ++++++++++ plugins/community_track/views/community_track_plugin_public/select_community.rhtml | 41 +++++++++++++++++++++++++++++++++++++++++ plugins/community_track/views/content_viewer/step.rhtml | 31 +++++++++++++++++++++++++++++++ plugins/community_track/views/content_viewer/track.rhtml | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/community_track/views/environment_design/community_track_plugin | 1 + plugins/community_track/views/profile_design/community_track_plugin | 1 + test/functional/memberships_controller_test.rb | 13 +++++++++++++ test/unit/article_test.rb | 9 +++++++++ test/unit/category_test.rb | 4 ++-- 47 files changed, 1985 insertions(+), 9 deletions(-) create mode 100644 db/migrate/20131011172930_add_image_to_article.rb create mode 100644 db/migrate/20131015161830_add_position_to_article.rb create mode 100644 plugins/community_track/controllers/myprofile/community_track_plugin_myprofile_controller.rb create mode 100644 plugins/community_track/controllers/public/community_track_plugin_public_controller.rb create mode 100644 plugins/community_track/lib/community_track_plugin.rb create mode 100644 plugins/community_track/lib/community_track_plugin/step.rb create mode 100644 plugins/community_track/lib/community_track_plugin/step_helper.rb create mode 100644 plugins/community_track/lib/community_track_plugin/track.rb create mode 100644 plugins/community_track/lib/community_track_plugin/track_card_list_block.rb create mode 100644 plugins/community_track/lib/community_track_plugin/track_helper.rb create mode 100644 plugins/community_track/lib/community_track_plugin/track_list_block.rb create mode 100644 plugins/community_track/public/icons/community-track.png create mode 100644 plugins/community_track/public/style.css create mode 100644 plugins/community_track/test/functional/community_track_plugin_cms_controller_test.rb create mode 100644 plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb create mode 100644 plugins/community_track/test/functional/community_track_plugin_environment_design_controller_test.rb create mode 100644 plugins/community_track/test/functional/community_track_plugin_myprofile_controller_test.rb create mode 100644 plugins/community_track/test/functional/community_track_plugin_public_controller_test.rb create mode 100644 plugins/community_track/test/test_helper.rb create mode 100644 plugins/community_track/test/unit/community_track_plugin/step_helper_test.rb create mode 100644 plugins/community_track/test/unit/community_track_plugin/step_test.rb create mode 100644 plugins/community_track/test/unit/community_track_plugin/track_card_list_block_test.rb create mode 100644 plugins/community_track/test/unit/community_track_plugin/track_helper_test.rb create mode 100644 plugins/community_track/test/unit/community_track_plugin/track_list_block_test.rb create mode 100644 plugins/community_track/test/unit/community_track_plugin/track_test.rb create mode 100644 plugins/community_track/test/unit/community_track_plugin_test.rb create mode 100644 plugins/community_track/views/blocks/_track.rhtml create mode 100644 plugins/community_track/views/blocks/_track_card.rhtml create mode 100644 plugins/community_track/views/blocks/_track_list_more.rhtml create mode 100644 plugins/community_track/views/blocks/track_list.rhtml create mode 100644 plugins/community_track/views/box_organizer/community_track_plugin/_track_list_block.rhtml create mode 100644 plugins/community_track/views/cms/community_track_plugin/_step.rhtml create mode 100644 plugins/community_track/views/cms/community_track_plugin/_track.rhtml create mode 100644 plugins/community_track/views/community_track_plugin_public/all_tracks.rhtml create mode 100644 plugins/community_track/views/community_track_plugin_public/select_community.rhtml create mode 100644 plugins/community_track/views/content_viewer/step.rhtml create mode 100644 plugins/community_track/views/content_viewer/track.rhtml create mode 120000 plugins/community_track/views/environment_design/community_track_plugin create mode 120000 plugins/community_track/views/profile_design/community_track_plugin diff --git a/app/controllers/my_profile/memberships_controller.rb b/app/controllers/my_profile/memberships_controller.rb index a93480f..466ad08 100644 --- a/app/controllers/my_profile/memberships_controller.rb +++ b/app/controllers/my_profile/memberships_controller.rb @@ -9,9 +9,10 @@ class MembershipsController < MyProfileController def new_community @community = Community.new(params[:community]) @community.environment = environment + @back_to = params[:back_to] || url_for(:action => 'index') if request.post? && @community.valid? @community = Community.create_after_moderation(user, {:environment => environment}.merge(params[:community])) - redirect_to :action => 'index' + redirect_to @back_to return end end diff --git a/app/helpers/categories_helper.rb b/app/helpers/categories_helper.rb index 6350496..ba200a5 100644 --- a/app/helpers/categories_helper.rb +++ b/app/helpers/categories_helper.rb @@ -3,10 +3,20 @@ module CategoriesHelper COLORS = [ [ N_('Do not display at the menu'), nil ], - [ N_('Orange'), 1 ], - [ N_('Green'), 2 ], - [ N_('Purple'), 3 ], - [ N_('Red'), 4 ], + [ N_('Orange'), 1], + [ N_('Blue Oil'), 2], + [ N_('Purple'), 3], + [ N_('Light Brown'), 4], + [ N_('Dark Green'), 5], + [ N_('Green'), 6], + [ N_('Blue'), 7], + [ N_('Brown'), 8], + [ N_('Light Green'), 9], + [ N_('Light Blue'), 10], + [ N_('Dark Blue'), 11], + [ N_('Blue Pool'), 12], + [ N_('Beige'), 13], + [ N_('Yellow'), 14], ] TYPES = [ diff --git a/app/models/article.rb b/app/models/article.rb index d674624..5e66ee4 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -2,6 +2,8 @@ require 'hpricot' class Article < ActiveRecord::Base + acts_as_having_image + SEARCHABLE_FIELDS = { :name => 10, :abstract => 3, diff --git a/app/models/category.rb b/app/models/category.rb index 885a19f..787c5a5 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -12,7 +12,7 @@ class Category < ActiveRecord::Base validates_uniqueness_of :slug,:scope => [ :environment_id, :parent_id ], :message => N_('%{fn} is already being used by another category.').fix_i18n belongs_to :environment - validates_inclusion_of :display_color, :in => [ 1, 2, 3, 4, nil ] + validates_inclusion_of :display_color, :in => 1..15, :allow_nil => true 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 # Finds all top level categories for a given environment. diff --git a/app/views/memberships/new_community.rhtml b/app/views/memberships/new_community.rhtml index d21aa42..f21b56e 100644 --- a/app/views/memberships/new_community.rhtml +++ b/app/views/memberships/new_community.rhtml @@ -45,10 +45,12 @@ <%= template_options(Community, 'community')%> + + <%= hidden_field_tag('back_to', @back_to) %> <% button_bar do %> <%= submit_button(:save, _('Create')) %> - <%= button(:cancel, _('Cancel'), :action => 'index') %> + <%= button(:cancel, _('Cancel'), @back_to ) %> <% end %> <% end %> diff --git a/db/migrate/20131011172930_add_image_to_article.rb b/db/migrate/20131011172930_add_image_to_article.rb new file mode 100644 index 0000000..2c8980b --- /dev/null +++ b/db/migrate/20131011172930_add_image_to_article.rb @@ -0,0 +1,13 @@ +class AddImageToArticle < ActiveRecord::Migration + + def self.up + add_column :articles, :image_id, :integer + add_column :article_versions, :image_id, :integer + end + + def self.down + remove_column :articles, :image_id + remove_column :article_versions, :image_id + end + +end diff --git a/db/migrate/20131015161830_add_position_to_article.rb b/db/migrate/20131015161830_add_position_to_article.rb new file mode 100644 index 0000000..b960f61 --- /dev/null +++ b/db/migrate/20131015161830_add_position_to_article.rb @@ -0,0 +1,13 @@ +class AddPositionToArticle < ActiveRecord::Migration + + def self.up + add_column :articles, :position, :integer + add_column :article_versions, :position, :integer + end + + def self.down + remove_column :articles, :position + remove_column :article_versions, :position + end + +end diff --git a/plugins/community_track/controllers/myprofile/community_track_plugin_myprofile_controller.rb b/plugins/community_track/controllers/myprofile/community_track_plugin_myprofile_controller.rb new file mode 100644 index 0000000..3a8123f --- /dev/null +++ b/plugins/community_track/controllers/myprofile/community_track_plugin_myprofile_controller.rb @@ -0,0 +1,18 @@ +class CommunityTrackPluginMyprofileController < MyProfileController + append_view_path File.join(File.dirname(__FILE__) + '/../../views') + + before_filter :allow_edit_track, :only => :save_order + + def save_order + track = profile.articles.find(params[:track]) + track.reorder_steps(params[:step_ids]) + redirect_to track.url + end + + protected + + def allow_edit_track + render_access_denied unless profile.articles.find(params[:track]).allow_edit?(user) + end + +end diff --git a/plugins/community_track/controllers/public/community_track_plugin_public_controller.rb b/plugins/community_track/controllers/public/community_track_plugin_public_controller.rb new file mode 100644 index 0000000..dca1770 --- /dev/null +++ b/plugins/community_track/controllers/public/community_track_plugin_public_controller.rb @@ -0,0 +1,47 @@ +class CommunityTrackPluginPublicController < PublicController + append_view_path File.join(File.dirname(__FILE__) + '/../../views') + + no_design_blocks + + before_filter :login_required, :only => :select_community + + def view_tracks + block = Block.find(params[:id]) + p = params[:page].to_i + per_page = params[:per_page] + per_page ||= block.limit + per_page = per_page.to_i + tracks = block.tracks(p, per_page) + + render :update do |page| + page.insert_html :bottom, "track_list_#{block.id}", :partial => "blocks/#{block.track_partial}", :collection => tracks, :locals => {:block => block} + + if block.has_page?(p+1, per_page) + 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} + else + page.replace_html "track_list_more_#{block.id}", '' + end + end + end + + def all_tracks + @per_page = 5 #FIXME + @block = Block.find(params[:id]) + @tracks = @block.tracks(1, @per_page) + @show_more = @block.has_page?(2, @per_page) + end + + def select_community + @communities = user.memberships.select{ |community| user.has_permission?('post_content', community) } + @back_to = request.url + if request.post? + community_identifier = params[:community_identifier] + if community_identifier.nil? + @failed = [_('Select one community to proceed')] + else + redirect_to :controller => 'cms', :action => 'new', :type => "CommunityTrackPlugin::Track", :profile => community_identifier + end + end + end + +end diff --git a/plugins/community_track/lib/community_track_plugin.rb b/plugins/community_track/lib/community_track_plugin.rb new file mode 100644 index 0000000..adf5c47 --- /dev/null +++ b/plugins/community_track/lib/community_track_plugin.rb @@ -0,0 +1,36 @@ +class CommunityTrackPlugin < Noosfero::Plugin + + def self.plugin_name + 'Community Track' + end + + def self.plugin_description + _("New kind of content for communities.") + end + + def stylesheet? + true + end + + def content_types + if context.respond_to?(:params) && context.params + types = [] + parent_id = context.params[:parent_id] + types << CommunityTrackPlugin::Track if context.profile.community? && !parent_id + parent = parent_id ? context.profile.articles.find(parent_id) : nil + types << CommunityTrackPlugin::Step if parent.kind_of?(CommunityTrackPlugin::Track) + types + else + [CommunityTrackPlugin::Track, CommunityTrackPlugin::Step] + end + end + + def self.extra_blocks + { CommunityTrackPlugin::TrackListBlock => {:position => 1}, CommunityTrackPlugin::TrackCardListBlock => {} } + end + + def content_remove_new(page) + page.kind_of?(CommunityTrackPlugin::Track) + end + +end diff --git a/plugins/community_track/lib/community_track_plugin/step.rb b/plugins/community_track/lib/community_track_plugin/step.rb new file mode 100644 index 0000000..4682766 --- /dev/null +++ b/plugins/community_track/lib/community_track_plugin/step.rb @@ -0,0 +1,105 @@ +class CommunityTrackPlugin::Step < Folder + + settings_items :hidden, :type => :boolean, :default => false + + alias :tools :children + + acts_as_list :scope => :parent + + def belong_to_track + errors.add(:parent, "Step not allowed at this parent.") if !parent.kind_of?(CommunityTrackPlugin::Track) + end + + validate :belong_to_track + validates_presence_of :start_date, :end_date + validate :end_date_equal_or_after_start_date + + after_save :schedule_activation + + before_create do |step| + step.published = false + true + end + + before_create :set_hidden_position + before_save :set_hidden_position + + def set_hidden_position + if hidden + decrement_positions_on_lower_items + self[:position] = 0 + elsif position == 0 + add_to_list_bottom + end + end + + def end_date_equal_or_after_start_date + if end_date && start_date + errors.add(:end_date, _('must be equal or after start date.')) unless end_date >= start_date + end + end + + def self.short_description + _("Step") + end + + def self.description + _('Defines a step.') + end + + def accept_comments? + false + end + + def enabled_tools + {TinyMceArticle => {:name => _('Article')}, Forum => {:name => _('Forum')}} + end + + def to_html(options = {}) + step = self + lambda do + render :file => 'content_viewer/step.rhtml', :locals => {:step => step} + end + end + + def active? + (start_date..end_date).include?(Date.today) + end + + def finished? + Date.today > end_date + end + + def waiting? + Date.today < start_date + end + + def schedule_activation + return if !changes['start_date'] && !changes['end_date'] && !changes['published'] + today = Date.today + if today <= end_date || published + schedule_date = !published ? start_date : end_date + 1.day + CommunityTrackPlugin::ActivationJob.find(id).destroy_all + Delayed::Job.enqueue(CommunityTrackPlugin::ActivationJob.new(self.id), 0, schedule_date) + end + end + + def publish + self[:published] = active? && !hidden + save! + end + + class CommunityTrackPlugin::ActivationJob < Struct.new(:step_id) + + def self.find(step_id) + Delayed::Job.where(:handler => "--- !ruby/struct:CommunityTrackPlugin::ActivationJob \nstep_id: #{step_id}\n") + end + + def perform + step = CommunityTrackPlugin::Step.find(step_id) + step.publish + end + + end + +end diff --git a/plugins/community_track/lib/community_track_plugin/step_helper.rb b/plugins/community_track/lib/community_track_plugin/step_helper.rb new file mode 100644 index 0000000..625f7ed --- /dev/null +++ b/plugins/community_track/lib/community_track_plugin/step_helper.rb @@ -0,0 +1,30 @@ +module CommunityTrackPlugin::StepHelper + + def self.status_descriptions + [_('Finished'), _('In progress'), _('Waiting')] + end + + def self.status_classes + ['step_finished', 'step_active', 'step_waiting'] + end + + def status_description(step) + CommunityTrackPlugin::StepHelper.status_descriptions[status_index(step)] + end + + def status_class(step) + CommunityTrackPlugin::StepHelper.status_classes[status_index(step)] + end + + def custom_options_for_article(article) + #no options for step? + nil + end + + protected + + def status_index(step) + [step.finished?, step.active?, step.waiting?].find_index(true) + end + +end diff --git a/plugins/community_track/lib/community_track_plugin/track.rb b/plugins/community_track/lib/community_track_plugin/track.rb new file mode 100644 index 0000000..371a223 --- /dev/null +++ b/plugins/community_track/lib/community_track_plugin/track.rb @@ -0,0 +1,70 @@ +class CommunityTrackPlugin::Track < Folder + + settings_items :goals, :type => :string + settings_items :expected_results, :type => :string + + def self.icon_name(article = nil) + 'community-track' + end + + def self.short_description + _("Track") + end + + def self.description + _('Defines a track.') + end + + def steps + #XXX article default order is name (acts_as_filesystem) -> should use reorder (rails3) + steps_unsorted.sort_by(&:position).select{|s| !s.hidden} + end + + def hidden_steps + steps_unsorted.select{|s| s.hidden} + end + + def reorder_steps(step_ids) + transaction do + step_ids.each_with_index do |step_id, i| + step = steps_unsorted.find(step_id) + step.update_attribute(:position, step.position = i + 1) + end + end + end + + def steps_unsorted + children.where(:type => 'CommunityTrackPlugin::Step') + end + + def accept_comments? + false + end + + def comments_count + steps_unsorted.joins(:children).sum('childrens_articles.comments_count') + end + + def css_class_name + "community-track-plugin-track" + end + + #FIXME make this test + def first_paragraph + paragraphs = Hpricot(body).search('p') + paragraphs.empty? ? '' : paragraphs.first.to_html + end + + def category_name + category = categories.first + category ? category.name : '' + end + + def to_html(options = {}) + track = self + lambda do + render :file => 'content_viewer/track.rhtml', :locals => {:track => track} + end + end + +end diff --git a/plugins/community_track/lib/community_track_plugin/track_card_list_block.rb b/plugins/community_track/lib/community_track_plugin/track_card_list_block.rb new file mode 100644 index 0000000..4e401b0 --- /dev/null +++ b/plugins/community_track/lib/community_track_plugin/track_card_list_block.rb @@ -0,0 +1,15 @@ +class CommunityTrackPlugin::TrackCardListBlock < CommunityTrackPlugin::TrackListBlock + + def self.description + _('Track Card List') + end + + def help + _('This block displays a list of most relevant tracks as cards.') + end + + def track_partial + 'track_card' + end + +end diff --git a/plugins/community_track/lib/community_track_plugin/track_helper.rb b/plugins/community_track/lib/community_track_plugin/track_helper.rb new file mode 100644 index 0000000..a8753f8 --- /dev/null +++ b/plugins/community_track/lib/community_track_plugin/track_helper.rb @@ -0,0 +1,12 @@ +module CommunityTrackPlugin::TrackHelper + + def category_class(track) + 'category_' + (track.categories.empty? ? 'not_defined' : track.categories.first.name.to_slug) + end + + def track_card_lead(track) + lead_stripped = strip_tags(track.lead) + excerpt(lead_stripped, lead_stripped.first(3), track.image ? 180 : 300) + end + +end diff --git a/plugins/community_track/lib/community_track_plugin/track_list_block.rb b/plugins/community_track/lib/community_track_plugin/track_list_block.rb new file mode 100644 index 0000000..705e119 --- /dev/null +++ b/plugins/community_track/lib/community_track_plugin/track_list_block.rb @@ -0,0 +1,64 @@ +class CommunityTrackPlugin::TrackListBlock < Block + + include CommunityTrackPlugin::StepHelper + + settings_items :limit, :type => :integer, :default => 3 + settings_items :more_another_page, :type => :boolean, :default => false + settings_items :category_ids, :type => Array, :default => [] + + def self.description + _('Track List') + end + + def help + _('This block displays a list of most relevant tracks.') + end + + def track_partial + 'track' + end + + def tracks(page=1, per_page=limit) + all_tracks.order('hits DESC').paginate(:per_page => per_page, :page => page) + end + + def count_tracks + all_tracks.count + end + + def accept_category?(cat) + true #accept all? + end + + def category_ids=(ids) + settings[:category_ids] = ids.uniq.map{|item| item.to_i unless item.to_i.zero?}.compact + end + + def all_tracks + tracks = owner.articles.where(:type => 'CommunityTrackPlugin::Track') + if !category_ids.empty? + tracks = tracks.joins(:article_categorizations).where(:articles_categories => {:category_id => category_ids}) + end + tracks + end + + def content(args={}) + block = self + lambda do + render :file => 'blocks/track_list.rhtml', :locals => {:block => block} + end + end + + def has_page?(page, per_page=limit) + return (page-1) * per_page < count_tracks + end + + def footer + block = self + return nil if !has_page?(2) + lambda do + render :partial => 'blocks/track_list_more', :locals => {:block => block, :page => 2, :per_page => block.limit} + end + end + +end diff --git a/plugins/community_track/public/icons/community-track.png b/plugins/community_track/public/icons/community-track.png new file mode 100644 index 0000000..bd245ed Binary files /dev/null and b/plugins/community_track/public/icons/community-track.png differ diff --git a/plugins/community_track/public/style.css b/plugins/community_track/public/style.css new file mode 100644 index 0000000..adbbcd8 --- /dev/null +++ b/plugins/community_track/public/style.css @@ -0,0 +1,190 @@ +.icon-newcommunity-track { + background-image: url(/plugins/community_track/icons/community-track.png) +} + +.step_active, #article .step_active a { + background-color: #CCEBD6; + color: #338533; +} + +.step_waiting, #article .step_waiting a { + background-color: #FFFFD1; + color: #D17519; +} + +.step_finished, #article .step_finished a { + background-color: #D1FFFF; + color: #00297A; +} + +.step_status_description { + float: right; +} + +.step { + font-weight: bold; +} + +.track_list .item .step { + padding: 8px 5px; +} + +#article .step a { + text-decoration: none; +} + +.track_list .item .track_content .lead { + float: left; + width: 50%; +} + +.track_list .item .track_content .steps { + float: right; + width: 50%; +} + +.track_list .item { + border-bottom: 1px solid #DDDDDD; +} + +.track_stats, .track_content { + clear: both; +} + +.track_stats .comments { + float: left; +} + +.track_stats .hits { + float: right; +} + +.track_list .item_card { + width: 155px; + border: 1px solid #DDDDDD; + float: left; + padding: 0px 8px; + margin-left: 3px; + margin-right: 3px; + margin-bottom: 8px; +} + +.steps .step { + margin-top: 3px; + margin-bottom: 3px; +} + +.track_list .item_card .track_stats { + border-top: 1px solid #DDDDDD; +} + +.track_list .item_card a, .track_list .item_card a:hover, .track_list .item_card a:visited { + text-decoration: none; + color: #444; +} + +.track_list .item_card:hover { + background: #EEE; +} + +.track_list .title { + font-size: 16px; + font-weight: bold; + border-bottom: 1px solid #DDDDDD; + padding: 2px 0px; + margin-bottom: 5px; + min-height: 10px; +} + +.track_list .image img { + max-width: 100%; + max-height: 100px; + display: block; + margin-left: auto; + margin-right: auto; +} + +.track_list .name { + padding-top: 5px; +} + +.track_list .item_card { + height: 270px; +} + +.track_list .track_content { + height: 250px; +} + +#track .step_list { + list-style-type: none; + margin: 0; + padding: 0; +} + +#track .position { + font-size: 24px; + font-weight: bold; + float: left; + margin: 0 10px; +} + +#track .step .name, #track .step .name a { + font-weight: bold; + color: #333; +} + +#track .step .name a:hover { + color: #555; +} + +#track .step .date { + font-size: 12px; + color: #AAA; +} + +#track .step .lead { + margin: 0px 10px; + color: #555; +} + +#track .content { + margin: 6px 0px; + border-bottom: 1px solid #DDDDDD; +} + +#track .ui-state-default .content { + border-bottom: 0px; +} + +.track_list .item .step .position { + float: left; + padding-right: 5px; +} + +#track .actions .save_button { + display: none; +} + +#track .actions, #step .actions { + margin-bottom: 20px; +} + +#edit-track-list-block .categorie_box a { + float: left; +} + +.all_tracks .more_button { + text-align: center; +} + +#step .tools .item .name a, #step .tools .item .name a:hover { + border: none; + background-color: transparent; + color: #666; + font-weight: bold; +} + +#step .tools .item .name a:hover { + color: #888; +} diff --git a/plugins/community_track/test/functional/community_track_plugin_cms_controller_test.rb b/plugins/community_track/test/functional/community_track_plugin_cms_controller_test.rb new file mode 100644 index 0000000..8ae47d3 --- /dev/null +++ b/plugins/community_track/test/functional/community_track_plugin_cms_controller_test.rb @@ -0,0 +1,47 @@ +require File.dirname(__FILE__) + '/../test_helper' + +# Re-raise errors caught by the controller. +class CmsController; def rescue_action(e) raise e end; end + +class CmsControllerTest < ActionController::TestCase + + def setup + @profile = fast_create(Community) + @track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track', :profile => @profile) + @step = CommunityTrackPlugin::Step.create!(:name => 'step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) + + user = create_user('testinguser') + @profile.add_admin(user.person) + login_as(user.login) + end + + should 'be able to edit track' do + get :edit, :id => @track.id, :profile => @profile.identifier + assert_tag :tag => 'input', :attributes => { :id => 'article_name' } + end + + should 'be able to edit step' do + get :edit, :id => @step.id, :profile => @profile.identifier + assert_tag :tag => 'input', :attributes => { :id => 'article_name' } + end + + should 'be able to save track' do + get :edit, :id => @track.id, :profile => @profile.identifier + post :edit, :id => @track.id, :profile => @profile.identifier, :article => {:name => 'changed'} + @track.reload + assert_equal 'changed', @track.name + end + + should 'be able to save step' do + get :edit, :id => @step.id, :profile => @profile.identifier + post :edit, :id => @step.id, :profile => @profile.identifier, :article => {:name => 'changed'} + @step.reload + assert_equal 'changed', @step.name + end + + should 'do not be able to edit visibility of step' do + get :edit, :id => @step.id, :profile => @profile.identifier + assert_no_tag :tag => 'input', :attributes => { :name => 'article[published]' } + end + +end diff --git a/plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb b/plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb new file mode 100644 index 0000000..e82183c --- /dev/null +++ b/plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb @@ -0,0 +1,147 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class ContentViewerController + append_view_path File.join(File.dirname(__FILE__) + '/../../views') + def rescue_action(e) + raise e + end +end + +class ContentViewerControllerTest < ActionController::TestCase + + def setup + @profile = fast_create(Community) + @track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track', :profile => @profile) + category = fast_create(Category, :name => "education") + @track.add_category(category) + + @step = CommunityTrackPlugin::Step.create!(:name => 'step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) + + user = create_user('testinguser') + login_as(user.login) + @profile.add_admin(user.person) + end + + should 'show actions for tracks when user has permission for edit' do + get :view_page, @track.url + assert_tag :tag => 'div', :attributes => {:id => 'track' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } } + end + + should 'do not show actions for tracks when user has not permission for edit' do + user = create_user('intruder') + logout + login_as(user.login) + get :view_page, @track.url + assert_no_tag :tag => 'div', :attributes => {:id => 'track' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } } + end + + should 'do not show new button at article toolbar for tracks' do + user = create_user('intruder') + logout + login_as(user.login) + get :view_page, @track.url + assert_no_tag :tag => 'div', :attributes => {:id => 'article-actions'}, :descendant => { :tag => 'div', :attributes => { :id => 'icon-new' } } + end + + should 'display steps for tracks' do + get :view_page, @track.url + assert_tag :tag => 'ul', :attributes => { :id => 'sortable' }, :descendant => {:tag => 'li', :attributes => { :class => 'step' } } + end + + should 'display hidden field with step id' do + get :view_page, @track.url + assert_tag :tag => 'input', :attributes => { :name => 'step_ids[]' } + end + + should 'show step' do + get :view_page, @step.url + assert_tag :tag => 'div', :attributes => { :id => 'step' } + end + + should 'show tools for a step' do + Article.create!(:profile => @profile, :name => 'article', :parent => @step) + get :view_page, @step.url + assert_tag :tag => 'div', :attributes => { :class => 'tools' }, :descendant => { :tag => 'div', :attributes => { :class => 'item' } } + end + + should 'show actions for steps when user has permission for edit' do + get :view_page, @step.url + assert_tag :tag => 'div', :attributes => {:id => 'step' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } } + end + + should 'show actions for enabled tools in step' do + get :view_page, @step.url + assert_tag 'div', :attributes => {:class => 'actions' }, :descendant => { :tag => 'a', :attributes => { :class => 'button with-text icon-new icon-newforum' } } + assert_tag 'div', :attributes => {:class => 'actions' }, :descendant => { :tag => 'a', :attributes => { :class => 'button with-text icon-new icon-newtext-html' } } + end + + should 'do not show actions for steps when user has not permission for edit' do + user = create_user('intruder') + logout + login_as(user.login) + get :view_page, @step.url + assert_no_tag :tag => 'div', :attributes => {:id => 'step' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } } + end + + should 'render a div with block id for track list block' do + box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name) + @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box) + @profile.boxes << box + get :view_page, @step.url + assert_tag :tag => 'div', :attributes => { :class => 'track_list', :id => "track_list_#{@block.id}" } + end + + should 'render a div with block id for track card list block' do + box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name) + @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) + @profile.boxes << box + get :view_page, @step.url + assert_tag :tag => 'div', :attributes => { :class => 'track_list', :id => "track_list_#{@block.id}" } + end + + should 'render tracks in track list block' do + box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name) + @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box) + @profile.boxes << box + get :view_page, @step.url + 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)}" } } } + end + + should 'render tracks in track card list block' do + box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name) + @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) + @profile.boxes << box + get :view_page, @step.url + assert_tag :tag => 'div', :attributes => { :class => 'item_card category_education' }, :descendant => { :tag => 'div', :attributes => { :class => 'track_content' } } + assert_tag :tag => 'div', :attributes => { :class => 'item_card category_education' }, :descendant => { :tag => 'div', :attributes => { :class => 'track_stats' } } + end + + should 'render link to display more tracks in track list block' do + box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name) + @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) + @profile.boxes << box + + (@block.limit+1).times do |i| + CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @profile) + end + + get :view_page, @step.url + assert_tag :tag => 'div', :attributes => { :id => "track_list_more_#{@block.id}" }, :descendant => { :tag => 'div', :attributes => { :class => 'more' } } + end + + should 'render link to show all tracks in track list block' do + box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name) + @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) + @profile.boxes << box + @block.more_another_page = true + @block.save! + + (@block.limit+1).times do |i| + CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @profile) + end + + get :view_page, @step.url + assert_tag :tag => 'div', :attributes => { :id => "track_list_more_#{@block.id}" }, :descendant => { :tag => 'div', :attributes => { :class => 'view_all' } } + end + +end diff --git a/plugins/community_track/test/functional/community_track_plugin_environment_design_controller_test.rb b/plugins/community_track/test/functional/community_track_plugin_environment_design_controller_test.rb new file mode 100644 index 0000000..2d30668 --- /dev/null +++ b/plugins/community_track/test/functional/community_track_plugin_environment_design_controller_test.rb @@ -0,0 +1,47 @@ +require File.dirname(__FILE__) + '/../test_helper' + +# Re-raise errors caught by the controller. +class EnvironmentDesignController; def rescue_action(e) raise e end; end + +class EnvironmentDesignControllerTest < ActionController::TestCase + + def setup + Environment.delete_all + @environment = Environment.new(:name => 'testenv', :is_default => true) + @environment.enabled_plugins = ['CommunityTrackPlugin'] + @environment.save! + + user = create_user('testinguser') + @environment.add_admin(user.person) + login_as(user.login) + + box = Box.create!(:owner => @environment) + @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box) + @block_card = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) + end + + should 'be able to edit TrackListBlock' do + get :edit, :id => @block.id + assert_tag :tag => 'input', :attributes => { :id => 'block_title' } + end + + should 'be able to save TrackListBlock' do + get :edit, :id => @block.id + post :save, :id => @block.id, :block => {:title => 'Tracks' } + @block.reload + assert_equal 'Tracks', @block.title + end + + should 'be able to edit TrackCardListBlock' do + get :edit, :id => @block_card.id + assert_tag :tag => 'input', :attributes => { :id => 'block_title' } + end + + should 'be able to save TrackCardListBlock' do + get :edit, :id => @block_card.id + post :save, :id => @block_card.id, :block => {:title => 'Tracks' } + @block_card.reload + assert_equal 'Tracks', @block_card.title + end + +end diff --git a/plugins/community_track/test/functional/community_track_plugin_myprofile_controller_test.rb b/plugins/community_track/test/functional/community_track_plugin_myprofile_controller_test.rb new file mode 100644 index 0000000..a3a2887 --- /dev/null +++ b/plugins/community_track/test/functional/community_track_plugin_myprofile_controller_test.rb @@ -0,0 +1,49 @@ +require File.dirname(__FILE__) + '/../test_helper' +require File.dirname(__FILE__) + '/../../controllers/myprofile/community_track_plugin_myprofile_controller' + +# Re-raise errors caught by the controller. +class CommunityTrackPluginMyprofileController; def rescue_action(e) raise e end; end + +class CommunityTrackPluginMyprofileControllerTest < ActionController::TestCase + + def setup + @controller = CommunityTrackPluginMyprofileController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + + @profile = fast_create(Community) + @track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track', :profile => @profile) + + @user = create_user('testinguser') + login_as(@user.login) + @profile.add_admin(@user.person) + end + + should 'redirect to track on save order' do + get :save_order, :profile => @profile.identifier, :track => @track.id, :step_ids => [] + assert_redirected_to @track.url + end + + should 'save new step positions on save order' do + step1 = CommunityTrackPlugin::Step.create!(:name => 'step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) + step2 = CommunityTrackPlugin::Step.create!(:name => 'step2', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) + assert_equal [step1, step2], @track.steps + get :save_order, :profile => @profile.identifier, :track => @track.id, :step_ids => [step2.id, step1.id] + assert_equal [step2, step1], @track.steps + end + + should 'do not allow a user without permission to save order' do + logout + user = create_user('intruder') + login_as(user.login) + get :save_order, :profile => @profile.identifier, :track => @track.id, :step_ids => [] + assert_response 403 + end + + should 'redirect to login page if there is no user logged in' do + logout + get :save_order, :profile => @profile.identifier, :track => @track.id, :step_ids => [] + assert_response 302 + end + +end diff --git a/plugins/community_track/test/functional/community_track_plugin_public_controller_test.rb b/plugins/community_track/test/functional/community_track_plugin_public_controller_test.rb new file mode 100644 index 0000000..e9d5444 --- /dev/null +++ b/plugins/community_track/test/functional/community_track_plugin_public_controller_test.rb @@ -0,0 +1,109 @@ +require File.dirname(__FILE__) + '/../test_helper' +require File.dirname(__FILE__) + '/../../controllers/public/community_track_plugin_public_controller' + +# Re-raise errors caught by the controller. +class CommunityTrackPluginPublicController; def rescue_action(e) raise e end; end + +class CommunityTrackPluginPublicControllerTest < ActionController::TestCase + + def setup + @community = fast_create(Community) + @track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track', :profile => @community) + + box = fast_create(Box, :owner_id => @community.id, :owner_type => 'Community') + @card_block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) + @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box) + end + + should 'display tracks for card block' do + xhr :get, :view_tracks, :id => @card_block.id, :page => 1 + assert_match /track_list_#{@card_block.id}/, @response.body + end + + should 'display tracks for list block' do + xhr :get, :view_tracks, :id => @block.id, :page => 1 + assert_match /track_list_#{@block.id}/, @response.body + end + + should 'display tracks with page size' do + 20.times do |i| + track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community) + end + xhr :get, :view_tracks, :id => @block.id, :page => 1, :per_page => 10 + assert_equal 10, @response.body.scan(/item/).size + end + + should 'default page size is the block limit' do + 20.times do |i| + track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community) + end + xhr :get, :view_tracks, :id => @block.id, :page => 1 + assert_equal @block.limit, @response.body.scan(/item/).size + end + + should 'display page for all tracks' do + get :all_tracks, :id => @block.id + assert_match /track_list_#{@block.id}/, @response.body + end + + should 'show more link in all tracks if there is no more tracks to show' do + 10.times do |i| + CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community) + end + get :all_tracks, :id => @block.id + assert assigns['show_more'] + assert_match /track_list_more_#{@block.id}/, @response.body + end + + should 'do not show more link in all tracks if there is no more tracks to show' do + CommunityTrackPlugin::Track.destroy_all + get :all_tracks, :id => @block.id + assert !assigns['show_more'] + assert_no_match /track_list_more_#{@block.id}/, @response.body + end + + should 'show select community page if user is logged in' do + user = create_user('testinguser') + login_as(user.login) + get :select_community + assert_template 'select_community' + end + + should 'redirect to login page if user try to access community selection' do + logout + get :select_community + assert_redirected_to :controller => 'account', :action => 'login' + end + + should 'display for selection communities where user has permission to post content' do + user = create_user('testinguser') + login_as(user.login) + @community.add_member(user.person) + get :select_community + assert_tag :tag => 'li', :attributes => {:class => 'search-profile-item'} + assert_tag :tag => 'input', :attributes => {:id => "community_identifier_#{@community.identifier}"} + end + + should 'do not display communities where user has not permission to post content' do + user = create_user('testinguser') + login_as(user.login) + get :select_community + assert_no_tag :tag => 'input', :attributes => {:id => "community_identifier_#{@community.identifier}"} + end + + should 'redirect to new content with track content type' do + user = create_user('testinguser') + login_as(user.login) + post :select_community, :profile => user.person.identifier, :community_identifier => @community.identifier + assert_redirected_to :controller => 'cms', :action => 'new', :type => "CommunityTrackPlugin::Track", :profile => @community.identifier + end + + should 'return error message if user do not select a community' do + user = create_user('testinguser') + login_as(user.login) + post :select_community, :profile => user.person.identifier, :community_identifier => nil + assert_equal 1, assigns(:failed).count + assert_tag :tag => 'div', :attributes => {:id => 'errorExplanation'} + end + +end diff --git a/plugins/community_track/test/test_helper.rb b/plugins/community_track/test/test_helper.rb new file mode 100644 index 0000000..cca1fd3 --- /dev/null +++ b/plugins/community_track/test/test_helper.rb @@ -0,0 +1 @@ +require File.dirname(__FILE__) + '/../../../test/test_helper' diff --git a/plugins/community_track/test/unit/community_track_plugin/step_helper_test.rb b/plugins/community_track/test/unit/community_track_plugin/step_helper_test.rb new file mode 100644 index 0000000..37e9718 --- /dev/null +++ b/plugins/community_track/test/unit/community_track_plugin/step_helper_test.rb @@ -0,0 +1,38 @@ +require File.dirname(__FILE__) + '/../../test_helper' + +class StepHelperTest < ActiveSupport::TestCase + + include CommunityTrackPlugin::StepHelper + + def setup + @step = CommunityTrackPlugin::Step.new + @step.stubs(:active?).returns(false) + @step.stubs(:finished?).returns(false) + @step.stubs(:waiting?).returns(false) + end + + should 'return active class when step is active' do + @step.stubs(:active?).returns(true) + assert_equal 'step_active', status_class(@step) + end + + should 'return finished class when step is finished' do + @step.stubs(:finished?).returns(true) + assert_equal 'step_finished', status_class(@step) + end + + should 'return waiting class when step is active' do + @step.stubs(:waiting?).returns(true) + assert_equal 'step_waiting', status_class(@step) + end + + should 'return a description for status' do + @step.stubs(:waiting?).returns(true) + assert_equal _('Waiting'), status_description(@step) + end + + should 'return nil at custom_options_for_article' do + assert !custom_options_for_article(fast_create(Article)) + end + +end diff --git a/plugins/community_track/test/unit/community_track_plugin/step_test.rb b/plugins/community_track/test/unit/community_track_plugin/step_test.rb new file mode 100644 index 0000000..95244d1 --- /dev/null +++ b/plugins/community_track/test/unit/community_track_plugin/step_test.rb @@ -0,0 +1,265 @@ +require File.dirname(__FILE__) + '/../../test_helper' + +class StepTest < ActiveSupport::TestCase + + def setup + @profile = fast_create(Community) + @track = CommunityTrackPlugin::Track.create(:profile_id => @profile.id, :name => 'track') + @step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) + Delayed::Job.destroy_all + end + + should 'describe yourself' do + assert CommunityTrackPlugin::Step.description + end + + should 'has a short description' do + assert CommunityTrackPlugin::Step.short_description + end + + should 'set published to false on create' do + today = Date.today + step = CommunityTrackPlugin::Step.create(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :start_date => today, :end_date => today, :published => true) + assert !step.published + end + + should 'do not allow step creation with a parent that is not a track' do + today = Date.today + blog = fast_create(Blog) + step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => blog, :start_date => today, :end_date => today, :published => true) + assert !step.save + end + + should 'do not allow step creation without a parent' do + today = Date.today + step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => nil, :start_date => today, :end_date => today, :published => true) + assert !step.save + end + + should 'create step if end date is equal to start date' do + @step.start_date = Date.today + @step.end_date = Date.today + assert @step.save + end + + should 'create step if end date is after start date' do + @step.start_date = Date.today + @step.end_date = Date.today + 1.day + assert @step.save + end + + should 'do not create step if end date is before start date' do + @step.start_date = Date.today + @step.end_date = Date.today - 1.day + assert !@step.save + end + + should 'do not validate date period if start date is nil' do + @step.start_date = nil + @step.end_date_equal_or_after_start_date.inspect + assert [], @step.errors + end + + should 'do not validate date period if end date is nil' do + @step.end_date = nil + @step.end_date_equal_or_after_start_date.inspect + assert [], @step.errors + end + + should 'be active if today is between start and end dates' do + @step.start_date = Date.today + @step.end_date = Date.today + 1.day + assert @step.active? + end + + should 'be finished if today is after the end date' do + @step.start_date = Date.today - 2.day + @step.end_date = Date.today - 1.day + assert @step.finished? + end + + should 'be waiting if today is before the end date' do + @step.start_date = Date.today + 1.day + @step.end_date = Date.today + 2.day + assert @step.waiting? + end + + should 'return delayed job created with a specific step_id' do + step_id = 0 + CommunityTrackPlugin::ActivationJob.new(step_id) + assert CommunityTrackPlugin::ActivationJob.find(step_id) + end + + should 'create delayed job' do + @step.start_date = Date.today + @step.end_date = Date.today + @step.schedule_activation + assert_equal 1, Delayed::Job.count + assert_equal @step.start_date, Delayed::Job.first.run_at.to_date + end + + should 'do not duplicate delayed job' do + @step.start_date = Date.today + @step.end_date = Date.today + @step.schedule_activation + @step.schedule_activation + assert_equal 1, Delayed::Job.count + end + + should 'create delayed job when a step is saved' do + @step.start_date = Date.today + @step.end_date = Date.today + @step.save! + assert_equal @step.start_date, Delayed::Job.first.run_at.to_date + end + + should 'create delayed job even if start date has passed' do + @step.start_date = Date.today - 2.days + @step.end_date = Date.today + @step.schedule_activation + assert_equal @step.start_date, Delayed::Job.first.run_at.to_date + end + + should 'do not create delayed job if end date has passed and step is not published' do + @step.start_date = Date.today - 5.days + @step.end_date = Date.today - 2.days + @step.published = false + @step.schedule_activation + assert_equal 0, Delayed::Job.count + end + + should 'create delayed job if end date has passed and step is published' do + @step.start_date = Date.today - 5.days + @step.end_date = Date.today - 2.days + @step.published = true + @step.schedule_activation + assert_equal @step.end_date + 1.day, Delayed::Job.first.run_at.to_date + end + + should 'change publish to true on perform delayed job in a active step' do + @step.start_date = Date.today + @step.end_date = Date.today + 2.days + @step.published = false + @step.save! + CommunityTrackPlugin::ActivationJob.new(@step.id).perform + @step.reload + assert @step.published + end + + should 'reschedule delayed job after change publish to true' do + @step.start_date = Date.today + @step.end_date = Date.today + 2.days + @step.published = false + @step.save! + assert_equal @step.start_date, Delayed::Job.first.run_at.to_date + process_delayed_job_queue + assert_equal @step.end_date + 1.day, Delayed::Job.first.run_at.to_date + end + + should 'do not schedule delayed job if save but do not modify date fields and published status' do + @step.start_date = Date.today + @step.end_date = Date.today + @step.published = false + @step.save! + assert_equal 1, Delayed::Job.count + Delayed::Job.destroy_all + @step.name = 'changed name' + @step.save! + assert_equal 0, Delayed::Job.count + end + + should 'set position on save' do + assert !@step.position + @step.save! + assert_equal 1, @step.position + step2 = CommunityTrackPlugin::Step.new(:name => 'Step2', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) + step2.save! + assert_equal 2, step2.position + end + + should 'publish step if it is active' do + @step.start_date = Date.today + @step.save! + assert !@step.published + @step.publish + @step.reload + assert @step.published + end + + should 'do not publish step if it is not active' do + @step.start_date = Date.today + 2.days + @step.end_date = Date.today + 3.days + @step.save! + assert !@step.published + @step.publish + @step.reload + assert !@step.published + end + + should 'unpublish step if it is not active anymore' do + @step.start_date = Date.today + @step.save! + @step.publish + @step.reload + assert @step.published + + @step.start_date = Date.today - 2.days + @step.end_date = Date.today - 1.day + @step.save! + @step.publish + @step.reload + assert !@step.published + end + + should 'set position to zero if step is hidden' do + @step.hidden = true + @step.save! + assert_equal 0, @step.position + end + + should 'change position to zero if step becomes hidden' do + @step.save! + assert_equal 1, @step.position + @step.hidden = true + @step.save! + assert_equal 0, @step.position + end + + should 'change position to botton if a hidden step becomes visible' do + step1 = CommunityTrackPlugin::Step.new(:name => 'Step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) + step1.save! + @step.hidden = true + @step.save! + assert_equal 0, @step.position + @step.hidden = false + @step.save! + assert_equal 2, @step.position + end + + should 'decrement lower items positions if a step becomes hidden' do + @step.save! + step1 = CommunityTrackPlugin::Step.new(:name => 'Step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) + step1.save! + assert_equal 2, step1.position + @step.hidden = true + @step.save! + step1.reload + assert_equal 1, step1.position + end + + should 'do not publish a hidden step' do + @step.start_date = Date.today + @step.hidden = true + @step.save! + assert !@step.published + @step.publish + @step.reload + assert !@step.published + end + + should 'return enabled tools for a step' do + assert_includes @step.enabled_tools, TinyMceArticle + assert_includes @step.enabled_tools, Forum + end + +end diff --git a/plugins/community_track/test/unit/community_track_plugin/track_card_list_block_test.rb b/plugins/community_track/test/unit/community_track_plugin/track_card_list_block_test.rb new file mode 100644 index 0000000..2bfa47f --- /dev/null +++ b/plugins/community_track/test/unit/community_track_plugin/track_card_list_block_test.rb @@ -0,0 +1,19 @@ +require File.dirname(__FILE__) + '/../../test_helper' + +class TrackCardListBlockTest < ActiveSupport::TestCase + + def setup + @community = fast_create(Community) + box = fast_create(Box, :owner_id => @community.id, :owner_type => @community.class.name) + @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) + end + + should 'describe yourself' do + assert CommunityTrackPlugin::TrackCardListBlock.description + end + + should 'return track_card as track partial' do + assert_equal 'track_card', @block.track_partial + end + +end diff --git a/plugins/community_track/test/unit/community_track_plugin/track_helper_test.rb b/plugins/community_track/test/unit/community_track_plugin/track_helper_test.rb new file mode 100644 index 0000000..4a724f2 --- /dev/null +++ b/plugins/community_track/test/unit/community_track_plugin/track_helper_test.rb @@ -0,0 +1,55 @@ +require File.dirname(__FILE__) + '/../../test_helper' + +class TrackHelperTest < ActiveSupport::TestCase + + include CommunityTrackPlugin::TrackHelper + include NoosferoTestHelper + include ActionView::Helpers::TextHelper + + def setup + @track = CommunityTrackPlugin::Track.new + end + + should 'return css class for track with category' do + category = fast_create(Category, :name => 'education') + @track.categories << category + assert_equal 'category_education', category_class(@track) + end + + should 'return default css class for a track without category' do + assert_equal 'category_not_defined', category_class(@track) + end + + should 'return css class for first category that the class belongs' do + category1 = fast_create(Category, :name => 'education') + @track.categories << category1 + category2 = fast_create(Category, :name => 'tech') + @track.categories << category2 + assert_equal 'category_education', category_class(@track) + end + + should 'return css class with category name properly formated' do + category = fast_create(Category, :name => 'not defined') + @track.categories << category + assert_equal 'category_not-defined', category_class(@track) + end + + should 'return lead for track removing html tags' do + @track.abstract = "display
pure text
" + assert_equal "display pure text", track_card_lead(@track) + end + + should 'limit lead char length' do + @track.abstract = "" + 400.times { @track.abstract += "a" } + assert_equal 306, track_card_lead(@track).length + end + + should 'display a shorter lead if track has a image' do + @track.abstract = "" + @track.image = Image.new + 400.times { @track.abstract += "a" } + assert_equal 186, track_card_lead(@track).length + end + +end diff --git a/plugins/community_track/test/unit/community_track_plugin/track_list_block_test.rb b/plugins/community_track/test/unit/community_track_plugin/track_list_block_test.rb new file mode 100644 index 0000000..ce78dcf --- /dev/null +++ b/plugins/community_track/test/unit/community_track_plugin/track_list_block_test.rb @@ -0,0 +1,105 @@ +require File.dirname(__FILE__) + '/../../test_helper' + +class TrackListBlockTest < ActiveSupport::TestCase + + def setup + @community = fast_create(Community) + @track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track', :profile => @community) + + box = fast_create(Box, :owner_id => @community.id, :owner_type => @community.class.name) + @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box) + end + + should 'describe yourself' do + assert CommunityTrackPlugin::TrackListBlock.description + end + + should 'return track as track partial' do + assert_equal 'track', @block.track_partial + end + + should 'load more at another page default to false' do + assert !@block.more_another_page + end + + should 'list articles only of track type' do + article = fast_create(Article, :profile_id => @community.id) + assert_includes @community.articles, article + assert_equal [@track], @block.tracks + end + + should 'list of articles be limited by block configuration' do + (@block.limit + 1).times do |i| + track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community) + end + assert_equal @block.limit, @block.tracks.count + end + + should 'return more link if has more tracks to show' do + @block.limit.times do |i| + track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community) + end + assert @block.footer + end + + should 'do not return more link if there is no more tracks to show' do + (@block.limit-1).times do |i| + track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community) + end + assert !@block.footer + end + + should 'count all tracks' do + @block.owner.articles.destroy_all + tracks_to_insert = @block.limit + 1 + tracks_to_insert.times do |i| + track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community) + end + article = fast_create(Article, :profile_id => @block.owner.id) + @block.reload + assert_includes @block.owner.articles, article + assert_equal tracks_to_insert, @block.count_tracks + end + + should 'have a second page if there is more tracks than limit' do + @block.owner.articles.destroy_all + (@block.limit+1).times do |i| + track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community) + end + assert @block.has_page?(2) + assert !@block.has_page?(3) + end + + should 'filter tracks by category' do + @block.owner.articles.destroy_all + category = fast_create(Category) + category2 = fast_create(Category) + track1 = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track1', :profile => @community) + track2 = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track2', :profile => @community) + track3 = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track3', :profile => @community) + track1.add_category(category) + @block.category_ids = [category.id] + assert_equal [track1], @block.all_tracks + end + + should 'return all tracks if block does not filter by category' do + @block.owner.articles.destroy_all + category = fast_create(Category) + track1 = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track1', :profile => @community) + track2 = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track2', :profile => @community) + track1.add_category(category) + assert_includes @block.all_tracks, track1 + assert_includes @block.all_tracks, track2 + end + + should 'accept any categories' do + assert @block.accept_category?(nil) + assert @block.accept_category?(fast_create(Category)) + end + + should 'format category ids array avoiding duplicates and zeros' do + @block.category_ids = ["0", "0", "1", "1", "2", nil] + assert_equal [1, 2], @block.category_ids + end + +end diff --git a/plugins/community_track/test/unit/community_track_plugin/track_test.rb b/plugins/community_track/test/unit/community_track_plugin/track_test.rb new file mode 100644 index 0000000..da6b75f --- /dev/null +++ b/plugins/community_track/test/unit/community_track_plugin/track_test.rb @@ -0,0 +1,113 @@ +require File.dirname(__FILE__) + '/../../test_helper' + +class TrackTest < ActiveSupport::TestCase + + def setup + profile = fast_create(Community) + @track = CommunityTrackPlugin::Track.create!(:profile => profile, :name => 'track') + @step = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => 'step', :profile => profile) + @tool = fast_create(Article, :parent_id => @step.id, :profile_id => profile.id) + end + + should 'describe yourself' do + assert CommunityTrackPlugin::Track.description + end + + should 'has a short descriptionf' do + assert CommunityTrackPlugin::Track.short_description + end + + should 'has a css class name' do + assert_equal 'community-track-plugin-track', @track.css_class_name + end + + should 'return comments count of children tools' do + assert_equal 0, @track.comments_count + owner = create_user('testuser').person + article = create(Article, :name => 'article', :parent_id => @step.id, :profile_id => owner.id) + comment = create(Comment, :source => article, :author_id => owner.id) + assert_equal 1, @track.comments_count + end + + should 'return children steps' do + assert_equal [@step], @track.steps_unsorted + end + + should 'do not return other articles type at steps' do + article = fast_create(Article, :parent_id => @track.id, :profile_id => @track.profile.id) + assert_includes @track.children, article + assert_equal [@step], @track.steps_unsorted + end + + should 'return category name' do + category = fast_create(Category, :name => 'category') + @track.add_category(category, true) + assert_equal 'category', @track.category_name + end + + should 'return empty for category name if it has no category' do + @track.categories.delete_all + assert_equal '', @track.category_name + end + + should 'return category name of first category' do + category = fast_create(Category, :name => 'category') + @track.add_category(category, true) + category2 = fast_create(Category, :name => 'category2') + @track.add_category(category2, true) + assert_equal 'category', @track.category_name + end + + should 'return steps with insert order' do + @track.children.destroy_all + step1 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step1", :profile => @track.profile) + step2 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step2", :profile => @track.profile) + step3 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step3", :profile => @track.profile) + assert_equal 1, step1.position + assert_equal 2, step2.position + assert_equal 3, step3.position + assert_equal [step1, step2, step3], @track.steps + end + + should 'return steps with order defined by position attribute' do + @track.children.destroy_all + step1 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step1", :profile => @track.profile) + step2 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step2", :profile => @track.profile) + step3 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step3", :profile => @track.profile) + step1.position = 3 + step1.save! + step2.position = 1 + step2.save! + step3.position = 2 + step3.save! + assert_equal [step2, step3, step1], @track.steps + end + + should 'save steps in a new order' do + @track.children.destroy_all + + step1 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step1", :profile => @track.profile) + step2 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step2", :profile => @track.profile) + step3 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step3", :profile => @track.profile) + + assert_equal [step1.id, step2.id, step3.id], @track.steps.map(&:id) + @track.reorder_steps([step3.id, step1.id, step2.id]) + @track.reload + assert_equal [step3.id, step1.id, step2.id], @track.steps.map(&:id) + end + + should 'do not return hidden steps' do + hidden_step = CommunityTrackPlugin::Step.new(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => 'hidden step', :profile => @track.profile) + hidden_step.hidden = true + hidden_step.save! + assert_equal [@step], @track.steps + end + + should 'return hidden steps' do + hidden_step = CommunityTrackPlugin::Step.new(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => 'hidden step', :profile => @track.profile) + hidden_step.hidden = true + hidden_step.save! + assert_equal [hidden_step], @track.hidden_steps + end + +end diff --git a/plugins/community_track/test/unit/community_track_plugin_test.rb b/plugins/community_track/test/unit/community_track_plugin_test.rb new file mode 100644 index 0000000..03b039e --- /dev/null +++ b/plugins/community_track/test/unit/community_track_plugin_test.rb @@ -0,0 +1,78 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class CommunityTrackPluginTest < ActiveSupport::TestCase + + def setup + @plugin = CommunityTrackPlugin.new + @profile = fast_create(Community) + @params = {} + @plugin.stubs(:context).returns(self) + end + + attr_reader :profile, :params + + should 'has name' do + assert CommunityTrackPlugin.plugin_name + end + + should 'describe yourself' do + assert CommunityTrackPlugin.plugin_description + end + + should 'has stylesheet' do + assert @plugin.stylesheet? + end + + should 'return Track as a content type if profile is a community' do + assert_includes @plugin.content_types, CommunityTrackPlugin::Track + end + + should 'do not return Track as a content type if profile is not a community' do + @profile = Organization.new + assert_not_includes @plugin.content_types, CommunityTrackPlugin::Track + end + + should 'do not return Track as a content type if there is a parent' do + parent = fast_create(Blog, :profile_id => @profile.id) + @params[:parent_id] = parent.id + assert_not_includes @plugin.content_types, CommunityTrackPlugin::Track + end + + should 'return Step as a content type if parent is a Track' do + parent = fast_create(CommunityTrackPlugin::Track, :profile_id => @profile.id) + @params[:parent_id] = parent.id + assert_includes @plugin.content_types, CommunityTrackPlugin::Step + end + + should 'do not return Step as a content type if parent is not a Track' do + parent = fast_create(Blog, :profile_id => @profile.id) + @params[:parent_id] = parent.id + assert_not_includes @plugin.content_types, CommunityTrackPlugin::Step + end + + should 'return Track and Step as a content type if context has no params' do + parent = fast_create(Blog, :profile_id => @profile.id) + expects(:respond_to?).with(:params).returns(false) + assert_equivalent [CommunityTrackPlugin::Step, CommunityTrackPlugin::Track], @plugin.content_types + end + + should 'return Track and Step as a content type if params is nil' do + parent = fast_create(Blog, :profile_id => @profile.id) + @params = nil + assert_equivalent [CommunityTrackPlugin::Step, CommunityTrackPlugin::Track], @plugin.content_types + end + + should 'return track card as an extra block' do + assert_includes CommunityTrackPlugin.extra_blocks, CommunityTrackPlugin::TrackListBlock + end + + should 'return true at content_remove_new if page is a track' do + assert @plugin.content_remove_new(CommunityTrackPlugin::Track.new) + end + + should 'return false at content_remove_new if page is not a track' do + assert !@plugin.content_remove_new(CommunityTrackPlugin::Step.new) + assert !@plugin.content_remove_new(Article.new) + end + +end diff --git a/plugins/community_track/views/blocks/_track.rhtml b/plugins/community_track/views/blocks/_track.rhtml new file mode 100644 index 0000000..1a0feaa --- /dev/null +++ b/plugins/community_track/views/blocks/_track.rhtml @@ -0,0 +1,21 @@ +<% extend CommunityTrackPlugin::TrackHelper %> +
+
+
+

<%= link_to track.name, track.url %>

+
+ <%= track.lead %> +
+
+
+

<%= _("Steps") %>

+ <% track.steps.each do |step| %> +
+
<%= step.position %>
+ <%= link_to step.name, step.url %> +
+ <% end %> +
+
+
+
diff --git a/plugins/community_track/views/blocks/_track_card.rhtml b/plugins/community_track/views/blocks/_track_card.rhtml new file mode 100644 index 0000000..26abc58 --- /dev/null +++ b/plugins/community_track/views/blocks/_track_card.rhtml @@ -0,0 +1,27 @@ +<% extend CommunityTrackPlugin::TrackHelper %> +
+ +
+
+ <%= track_card.category_name %> +
+
+ <%= image_tag track_card.image.public_filename if track_card.image %> +
+
+ <%= track_card.name %> +
+
+ <%= track_card_lead(track_card) %> +
+
+
+
+ <%= "#{track_card.comments_count} comments" %> +
+
+ <%= "#{track_card.hits} hits" %> +
+
+
+
diff --git a/plugins/community_track/views/blocks/_track_list_more.rhtml b/plugins/community_track/views/blocks/_track_list_more.rhtml new file mode 100644 index 0000000..41755b6 --- /dev/null +++ b/plugins/community_track/views/blocks/_track_list_more.rhtml @@ -0,0 +1,12 @@ +<% force_same_page ||= false %> +
+ <% if block.more_another_page && !force_same_page %> +
+ <%= link_to _('View All'), :id => block.id, :controller => 'community_track_plugin_public', :action => 'all_tracks' %> +
+ <% else %> +
+ <%= 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}")) %> +
+ <% end %> +
diff --git a/plugins/community_track/views/blocks/track_list.rhtml b/plugins/community_track/views/blocks/track_list.rhtml new file mode 100644 index 0000000..713b1dd --- /dev/null +++ b/plugins/community_track/views/blocks/track_list.rhtml @@ -0,0 +1,6 @@ +<%= block_title(block.title) %> + +
+ <%= render :partial => "blocks/#{block.track_partial}", :collection => block.tracks, :locals => {:block => block} %> +
+
diff --git a/plugins/community_track/views/box_organizer/community_track_plugin/_track_list_block.rhtml b/plugins/community_track/views/box_organizer/community_track_plugin/_track_list_block.rhtml new file mode 100644 index 0000000..e59222c --- /dev/null +++ b/plugins/community_track/views/box_organizer/community_track_plugin/_track_list_block.rhtml @@ -0,0 +1,5 @@ +
+ <%= labelled_form_field _('Limit of items'), text_field(:block, :limit, :size => 3) %> + <%= labelled_form_field check_box(:block, :more_another_page) + _('Show more at another page'), '' %> + <%= select_categories(:block, _('Select Categories')) %> +
diff --git a/plugins/community_track/views/cms/community_track_plugin/_step.rhtml b/plugins/community_track/views/cms/community_track_plugin/_step.rhtml new file mode 100644 index 0000000..31bffbe --- /dev/null +++ b/plugins/community_track/views/cms/community_track_plugin/_step.rhtml @@ -0,0 +1,13 @@ +<%= required_fields_message %> + +<%= render :file => 'shared/tiny_mce' %> + +
+ <%= required f.text_field('name', :size => '64', :maxlength => 150) %> + <%= labelled_form_field(_('Start date'), pick_date(:article, :start_date)) %> + <%= labelled_form_field(_('End date'), pick_date(:article, :end_date)) %> +
+ +<%= labelled_form_field check_box(:article, :hidden) + _('Hidden Step'), '' %> + +<%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :body_label => 'Description:'} %> diff --git a/plugins/community_track/views/cms/community_track_plugin/_track.rhtml b/plugins/community_track/views/cms/community_track_plugin/_track.rhtml new file mode 100644 index 0000000..09145ee --- /dev/null +++ b/plugins/community_track/views/cms/community_track_plugin/_track.rhtml @@ -0,0 +1,18 @@ +<%= required_fields_message %> + +<%= render :file => 'shared/tiny_mce' %> + +
+ <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64', :maxlength => 150)) %> +
+ +<%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :body_label => 'Description:'} %> + +
+ <% f.fields_for :image_builder, @article.image do |i| %> + <%= file_field_or_thumbnail(_('Image:'), @article.image, i) %> + <% end %> + + <%= labelled_form_field(_('Goals:'), text_area(:article, :goals, :rows => 3, :cols => 64)) %> + <%= labelled_form_field(_('Expected Results:'), text_area(:article, :expected_results, :rows => 3, :cols => 64)) %> +
diff --git a/plugins/community_track/views/community_track_plugin_public/all_tracks.rhtml b/plugins/community_track/views/community_track_plugin_public/all_tracks.rhtml new file mode 100644 index 0000000..3cc50bf --- /dev/null +++ b/plugins/community_track/views/community_track_plugin_public/all_tracks.rhtml @@ -0,0 +1,10 @@ +

<%= _('Tracks') %>

+
+
+ <%= render :partial => "blocks/#{@block.track_partial}", :collection => @tracks, :locals => {:block => @block} %> +
+
+ <% if @show_more %> + <%= render :partial => "blocks/track_list_more", :locals => {:block => @block, :force_same_page => true, :page => 2, :per_page => @per_page} %> + <% end %> +
diff --git a/plugins/community_track/views/community_track_plugin_public/select_community.rhtml b/plugins/community_track/views/community_track_plugin_public/select_community.rhtml new file mode 100644 index 0000000..47692dd --- /dev/null +++ b/plugins/community_track/views/community_track_plugin_public/select_community.rhtml @@ -0,0 +1,41 @@ +
+ +

<%= _('Select Community') %>

+ +<% if !@failed.blank? %> +
+
+ <% @failed.each do |error|%> + <%= error %> + <% end %> +
+
+<% end %> + +<% button_bar do %> + <%= button(:add, __('Create a new community'), :controller => 'memberships', :action => 'new_community', :profile => user.identifier, :back_to => @back_to) %> +<% end %> + +<% form_tag({:controller => 'community_track_plugin_public', :action => 'select_community', :profile => user.identifier}) do %> + +
+
+ <%= submit_button :save, _('New Track') %> +<% end %> +
diff --git a/plugins/community_track/views/content_viewer/step.rhtml b/plugins/community_track/views/content_viewer/step.rhtml new file mode 100644 index 0000000..895dac8 --- /dev/null +++ b/plugins/community_track/views/content_viewer/step.rhtml @@ -0,0 +1,31 @@ +
+
+
    +
  • + <%= _('When:') %><%= show_period(step.start_date, step.end_date) %> +
  • +
+
+
+ <%= step.body %> +
+

<%= _("Tools") %>

+ <% if step.allow_create?(user) %> +
+ <% step.enabled_tools.each do |klass, attrs| %> + <% 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 %> + <%= _("New #{attrs[:name]}") %> + <% end %> + <% end %> +
+ <% end %> +
+ <% step.tools.each do |tool| %> +
+
+ <%= link_to tool.name, tool.url, :class=>"button with-text icon-new icon-new#{tool.class.icon_name}" %> +
+
+ <% end %> +
+
diff --git a/plugins/community_track/views/content_viewer/track.rhtml b/plugins/community_track/views/content_viewer/track.rhtml new file mode 100644 index 0000000..f71edab --- /dev/null +++ b/plugins/community_track/views/content_viewer/track.rhtml @@ -0,0 +1,67 @@ +<% extend CommunityTrackPlugin::StepHelper %> + +<% form_tag({:controller => 'community_track_plugin_myprofile', :action => 'save_order', :track => track}) do %> +
+
+ <%= track.body %> +
+ +

<%= _("Steps") %>

+ + <% if track.allow_create?(user) %> +
+ <% content_tag('a', :href => url_for({:controller => 'cms', :action => 'new', :type => "CommunityTrackPlugin::Step", :parent_id => track.id}), :class => 'button with-text icon-add') do %> + <%= _("New %s") % CommunityTrackPlugin::Step.short_description %> + <% end %> + <%= _('Reorder Steps') %> + <%= submit_button :save, _('Save Order'), :class => "save_button" %> +
+ + <% end %> + + + <% if track.allow_create?(user) && !track.hidden_steps.empty? %> +
+

<%= _('Hidden Steps') %>

+
    + <% track.hidden_steps.each do |step| %> +
  • + <%= hidden_field_tag "step_ids[]", step.id %> +
    +
    +
    + <%= show_period(step.start_date, step.end_date) %> +
    +
    <%= link_to step.name, step.url %>
    +
    <%= step.body %>
    +
    +
  • + <% end %> +
+
+ <% end %> +
+<% end %> + diff --git a/plugins/community_track/views/environment_design/community_track_plugin b/plugins/community_track/views/environment_design/community_track_plugin new file mode 120000 index 0000000..1cb32e0 --- /dev/null +++ b/plugins/community_track/views/environment_design/community_track_plugin @@ -0,0 +1 @@ +../box_organizer/community_track_plugin \ No newline at end of file diff --git a/plugins/community_track/views/profile_design/community_track_plugin b/plugins/community_track/views/profile_design/community_track_plugin new file mode 120000 index 0000000..1cb32e0 --- /dev/null +++ b/plugins/community_track/views/profile_design/community_track_plugin @@ -0,0 +1 @@ +../box_organizer/community_track_plugin \ No newline at end of file diff --git a/test/functional/memberships_controller_test.rb b/test/functional/memberships_controller_test.rb index 766312c..6e35d3a 100644 --- a/test/functional/memberships_controller_test.rb +++ b/test/functional/memberships_controller_test.rb @@ -245,4 +245,17 @@ class MembershipsControllerTest < ActionController::TestCase assert_tag :tag => 'input', :attributes => {:id => 'community_plugin2', :type => 'hidden', :value => 'Plugin 2'} end + should 'redirect to back_to parameter when create a new community' do + back_to = '/' + 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 + assert_response :redirect + assert_redirected_to back_to + end + + should 'cancel button redirect to back_to parameter' do + back_to = '/' + get :new_community, :profile => profile.identifier, :back_to => back_to + assert_tag :tag => 'a', :attributes => { :class => 'button icon-cancel with-text', :href => back_to } + end + end diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 6c5c784..f72b0c8 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -1764,4 +1764,13 @@ class ArticleTest < ActiveSupport::TestCase assert !a.belongs_to_forum? end + should 'save image on create article' do + assert_difference Article, :count do + p = Article.create!(:name => 'test', :image_builder => { + :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') + }, :profile_id => @profile.id) + assert_equal p.image(true).filename, 'rails.png' + end + end + end diff --git a/test/unit/category_test.rb b/test/unit/category_test.rb index 62c6593..1e4a3b4 100644 --- a/test/unit/category_test.rb +++ b/test/unit/category_test.rb @@ -168,11 +168,11 @@ class CategoryTest < ActiveSupport::TestCase should "limit the possibile display colors" do c = Category.new(:name => 'test category', :environment_id => @env.id) - c.display_color = 10 + c.display_color = 16 c.valid? assert c.errors.invalid?(:display_color) - valid = %w[ 1 2 3 4 ].map { |item| item.to_i } + valid = (1..15).map { |item| item.to_i } valid.each do |item| c.display_color = item c.valid? -- libgit2 0.21.2