From a5313c2adba85ebef8ba1f62a21e98c5e19ff702 Mon Sep 17 00:00:00 2001 From: JoenioCosta Date: Fri, 4 Jul 2008 18:38:37 +0000 Subject: [PATCH] ActionItem518: add article to enterprise homepage (and removing unnused code) --- app/controllers/my_profile/cms_controller.rb | 26 ++++++++++++++++---------- app/helpers/profile_helper.rb | 25 ------------------------- app/models/enterprise_homepage.rb | 15 +++++++++++++++ app/models/organization.rb | 6 ------ app/models/person.rb | 6 ------ test/functional/cms_controller_test.rb | 10 ++++++++++ test/unit/enterprise_homepage_test.rb | 26 ++++++++++++++++++++++++++ test/unit/organization_test.rb | 13 ------------- test/unit/person_test.rb | 13 ------------- test/unit/profile_helper_test.rb | 33 ++------------------------------- 10 files changed, 69 insertions(+), 104 deletions(-) create mode 100644 app/models/enterprise_homepage.rb create mode 100644 test/unit/enterprise_homepage_test.rb diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 39fdabf..0e222d6 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -9,14 +9,20 @@ class CmsController < MyProfileController include CmsHelper - ARTICLE_TYPES = [ - Folder, - TinyMceArticle, - TextileArticle, - RssFeed, - UploadedFile, - Event, - ] + def available_article_types + articles = [ + Folder, + TinyMceArticle, + TextileArticle, + RssFeed, + UploadedFile, + Event + ] + if profile.enterprise? + articles << EnterpriseHomepage + end + articles + end def view @article = profile.articles.find(params[:id]) @@ -51,7 +57,7 @@ class CmsController < MyProfileController @type = params[:type] if @type.blank? @article_types = [] - ARTICLE_TYPES.each do |type| + available_article_types.each do |type| @article_types.push({ :name => type.name, :short_description => type.short_description, @@ -63,7 +69,7 @@ class CmsController < MyProfileController return end - raise "Invalid article type #{@type}" unless ARTICLE_TYPES.map {|item| item.name}.include?(@type) + raise "Invalid article type #{@type}" unless available_article_types.map {|item| item.name}.include?(@type) klass = @type.constantize @article = klass.new(params[:article]) diff --git a/app/helpers/profile_helper.rb b/app/helpers/profile_helper.rb index c2df978..f0678df 100644 --- a/app/helpers/profile_helper.rb +++ b/app/helpers/profile_helper.rb @@ -1,28 +1,3 @@ module ProfileHelper - def display_profile_info(profile) - table_rows = content_tag( 'tr', - content_tag( 'th', - "\n" + - button( :edit, _('edit your information'), :controller => 'profile_editor', :action => 'edit' ) + - "\n", - :colspan => 2, :class => 'header' ) - ) + "\n" - profile.summary.each do |item| - name = item[0] - value = item[1] - if value.is_a?(Proc) - value = self.instance_eval(value) - end - table_rows << content_tag('tr', content_tag('th', _(name)) + content_tag('td', value)) - table_rows << "\n" - end - - content_tag( - 'table', - table_rows, - :class => 'profile_info' - ) - end - end diff --git a/app/models/enterprise_homepage.rb b/app/models/enterprise_homepage.rb new file mode 100644 index 0000000..02becd7 --- /dev/null +++ b/app/models/enterprise_homepage.rb @@ -0,0 +1,15 @@ +class EnterpriseHomepage < Article + + def self.short_description + _('Enterprise homepage.') + end + + def self.description + _('Display the summary of profile.') + end + + def to_html + body || '' + end + +end diff --git a/app/models/organization.rb b/app/models/organization.rb index 63c9087..8ceca84 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -47,12 +47,6 @@ class Organization < Profile xss_terminate :only => [ :acronym, :contact_person, :contact_email, :legal_form, :economic_activity, :management_information ] - def summary - [ 'acronym', 'foundation_year', 'contact_person', 'contact_email', 'legal_form', 'economic_activity' ].map do |col| - [ col.humanize, self.send(col) ] - end - end - # Yes, organizations have members. # # Returns true. diff --git a/app/models/person.rb b/app/models/person.rb index ec19142..8af262f 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -29,12 +29,6 @@ class Person < Profile N_('Contact information'); N_('Birth date'); N_('City'); N_('State'); N_('Country'); N_('Sex'); settings_items :photo, :contact_information, :birth_date, :sex, :city, :state, :country - def summary - ['name', 'contact_information', 'contact_phone', 'sex', 'birth_date', 'address', 'city', 'state', 'country'].map do |col| - [ col.humanize, self.send(col) ] - end - end - def self.conditions_for_profiles(conditions, person) new_conditions = sanitize_sql(['role_assignments.accessor_id = ?', person]) new_conditions << ' AND ' + sanitize_sql(conditions) unless conditions.blank? diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 1928223..2e2cb13 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -470,4 +470,14 @@ class CmsControllerTest < Test::Unit::TestCase assert_tag :input, :attributes => { :id => 'article_link' } end + should 'not make enterprise homepage available to person' do + @controller.stubs(:profile).returns(Person.new) + assert_not_includes @controller.available_article_types, EnterpriseHomepage + end + + should 'make enterprise homepage available to enterprises' do + @controller.stubs(:profile).returns(Enterprise.new) + assert_includes @controller.available_article_types, EnterpriseHomepage + end + end diff --git a/test/unit/enterprise_homepage_test.rb b/test/unit/enterprise_homepage_test.rb new file mode 100644 index 0000000..6340912 --- /dev/null +++ b/test/unit/enterprise_homepage_test.rb @@ -0,0 +1,26 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class EnterpriseHomepageTest < Test::Unit::TestCase + + def setup + @profile = create_user('testing').person + end + attr_reader :profile + + should 'provide a proper short description' do + assert_kind_of String, EnterpriseHomepage.short_description + end + + should 'provide a proper description' do + assert_kind_of String, EnterpriseHomepage.description + end + + should 'accept empty body' do + a = EnterpriseHomepage.new + a.expects(:body).returns(nil) + assert_nothing_raised do + assert_equal '', a.to_html + end + end + +end diff --git a/test/unit/organization_test.rb b/test/unit/organization_test.rb index 6f80c87..9eb41fe 100644 --- a/test/unit/organization_test.rb +++ b/test/unit/organization_test.rb @@ -162,19 +162,6 @@ class OrganizationTest < Test::Unit::TestCase assert ! org.errors.invalid?(:foundation_year) end - should 'provide needed information in summary' do - organization = Organization.new - - organization.acronym = 'organization acronym' - organization.foundation_year = '2007' - organization.contact_email = 'my contact email' - - summary = organization.summary - assert(summary.any? { |line| line[1] == 'organization acronym' }) - assert(summary.any? { |line| line[1] == '2007' }) - assert(summary.any? { |line| line[1] == 'my contact email' }) - end - should 'has closed' do org = Organization.new assert_respond_to org, :closed diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index 467a0e8..280572a 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -248,19 +248,6 @@ class PersonTest < Test::Unit::TestCase assert p.respond_to?(:contact_information) end - should 'provide needed information in summary' do - person = Person.new - - person.name = 'person name' - person.address = 'my address' - person.contact_information = 'my contact information' - - summary = person.summary - assert(summary.any? { |line| line[1] == 'person name' }) - assert(summary.any? { |line| line[1] == 'my address' }) - assert(summary.any? { |line| line[1] == 'my contact information' }, "summary (#{summary.map{|l| l[1] }.compact.join("; ")}) do not contain 'my contact informatidon'") - end - should 'required name' do person = Person.new assert !person.valid? diff --git a/test/unit/profile_helper_test.rb b/test/unit/profile_helper_test.rb index b48b6b2..31902e1 100644 --- a/test/unit/profile_helper_test.rb +++ b/test/unit/profile_helper_test.rb @@ -9,37 +9,8 @@ class ProfileHelperTest < Test::Unit::TestCase end attr_reader :profile, :helper - should 'display info' do - f1 = 'Field 1' - v1 = 'value 1' - f2 = 'Field 2' - v2 = 'value 2' - array = [ - [ f1, v1 ], - [ f2, v2 ] - ] - profile.expects(:summary).returns(array) - - helper.expects(:content_tag).returns('').at_least_once - - helper.expects(:_).at_least_once - helper.expects(:_).with('edit your information').returns('edit your information') - helper.expects(:button).with(:edit, 'edit your information', :controller => 'profile_editor', :action => 'edit').returns("BUTTON") - - helper.display_profile_info(profile) - end - - should 'call blocks' do - myproc = lambda { content_tag('div', 'lalala') } - profile.expects(:summary).returns([['f1', myproc ]]) - helper.stubs(:content_tag).returns('') - - helper.expects(:instance_eval).with(myproc) - - helper.expects(:_).at_least_once - helper.expects(:button).returns('') - - helper.display_profile_info(profile) + def test_true + assert true end end -- libgit2 0.21.2