Commit a5313c2adba85ebef8ba1f62a21e98c5e19ff702

Authored by JoenioCosta
1 parent 7679e33d

ActionItem518: add article to enterprise homepage (and removing unnused

code)

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2155 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/my_profile/cms_controller.rb
... ... @@ -9,14 +9,20 @@ class CmsController < MyProfileController
9 9  
10 10 include CmsHelper
11 11  
12   - ARTICLE_TYPES = [
13   - Folder,
14   - TinyMceArticle,
15   - TextileArticle,
16   - RssFeed,
17   - UploadedFile,
18   - Event,
19   - ]
  12 + def available_article_types
  13 + articles = [
  14 + Folder,
  15 + TinyMceArticle,
  16 + TextileArticle,
  17 + RssFeed,
  18 + UploadedFile,
  19 + Event
  20 + ]
  21 + if profile.enterprise?
  22 + articles << EnterpriseHomepage
  23 + end
  24 + articles
  25 + end
20 26  
21 27 def view
22 28 @article = profile.articles.find(params[:id])
... ... @@ -51,7 +57,7 @@ class CmsController &lt; MyProfileController
51 57 @type = params[:type]
52 58 if @type.blank?
53 59 @article_types = []
54   - ARTICLE_TYPES.each do |type|
  60 + available_article_types.each do |type|
55 61 @article_types.push({
56 62 :name => type.name,
57 63 :short_description => type.short_description,
... ... @@ -63,7 +69,7 @@ class CmsController &lt; MyProfileController
63 69 return
64 70 end
65 71  
66   - raise "Invalid article type #{@type}" unless ARTICLE_TYPES.map {|item| item.name}.include?(@type)
  72 + raise "Invalid article type #{@type}" unless available_article_types.map {|item| item.name}.include?(@type)
67 73 klass = @type.constantize
68 74 @article = klass.new(params[:article])
69 75  
... ...
app/helpers/profile_helper.rb
1 1 module ProfileHelper
2 2  
3   - def display_profile_info(profile)
4   - table_rows = content_tag( 'tr',
5   - content_tag( 'th',
6   - "\n" +
7   - button( :edit, _('edit your information'), :controller => 'profile_editor', :action => 'edit' ) +
8   - "\n",
9   - :colspan => 2, :class => 'header' )
10   - ) + "\n"
11   - profile.summary.each do |item|
12   - name = item[0]
13   - value = item[1]
14   - if value.is_a?(Proc)
15   - value = self.instance_eval(value)
16   - end
17   - table_rows << content_tag('tr', content_tag('th', _(name)) + content_tag('td', value))
18   - table_rows << "\n"
19   - end
20   -
21   - content_tag(
22   - 'table',
23   - table_rows,
24   - :class => 'profile_info'
25   - )
26   - end
27   -
28 3 end
... ...
app/models/enterprise_homepage.rb 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +class EnterpriseHomepage < Article
  2 +
  3 + def self.short_description
  4 + _('Enterprise homepage.')
  5 + end
  6 +
  7 + def self.description
  8 + _('Display the summary of profile.')
  9 + end
  10 +
  11 + def to_html
  12 + body || ''
  13 + end
  14 +
  15 +end
... ...
app/models/organization.rb
... ... @@ -47,12 +47,6 @@ class Organization &lt; Profile
47 47  
48 48 xss_terminate :only => [ :acronym, :contact_person, :contact_email, :legal_form, :economic_activity, :management_information ]
49 49  
50   - def summary
51   - [ 'acronym', 'foundation_year', 'contact_person', 'contact_email', 'legal_form', 'economic_activity' ].map do |col|
52   - [ col.humanize, self.send(col) ]
53   - end
54   - end
55   -
56 50 # Yes, organizations have members.
57 51 #
58 52 # Returns <tt>true</tt>.
... ...
app/models/person.rb
... ... @@ -29,12 +29,6 @@ class Person &lt; Profile
29 29 N_('Contact information'); N_('Birth date'); N_('City'); N_('State'); N_('Country'); N_('Sex');
30 30 settings_items :photo, :contact_information, :birth_date, :sex, :city, :state, :country
31 31  
32   - def summary
33   - ['name', 'contact_information', 'contact_phone', 'sex', 'birth_date', 'address', 'city', 'state', 'country'].map do |col|
34   - [ col.humanize, self.send(col) ]
35   - end
36   - end
37   -
38 32 def self.conditions_for_profiles(conditions, person)
39 33 new_conditions = sanitize_sql(['role_assignments.accessor_id = ?', person])
40 34 new_conditions << ' AND ' + sanitize_sql(conditions) unless conditions.blank?
... ...
test/functional/cms_controller_test.rb
... ... @@ -470,4 +470,14 @@ class CmsControllerTest &lt; Test::Unit::TestCase
470 470 assert_tag :input, :attributes => { :id => 'article_link' }
471 471 end
472 472  
  473 + should 'not make enterprise homepage available to person' do
  474 + @controller.stubs(:profile).returns(Person.new)
  475 + assert_not_includes @controller.available_article_types, EnterpriseHomepage
  476 + end
  477 +
  478 + should 'make enterprise homepage available to enterprises' do
  479 + @controller.stubs(:profile).returns(Enterprise.new)
  480 + assert_includes @controller.available_article_types, EnterpriseHomepage
  481 + end
  482 +
473 483 end
... ...
test/unit/enterprise_homepage_test.rb 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class EnterpriseHomepageTest < Test::Unit::TestCase
  4 +
  5 + def setup
  6 + @profile = create_user('testing').person
  7 + end
  8 + attr_reader :profile
  9 +
  10 + should 'provide a proper short description' do
  11 + assert_kind_of String, EnterpriseHomepage.short_description
  12 + end
  13 +
  14 + should 'provide a proper description' do
  15 + assert_kind_of String, EnterpriseHomepage.description
  16 + end
  17 +
  18 + should 'accept empty body' do
  19 + a = EnterpriseHomepage.new
  20 + a.expects(:body).returns(nil)
  21 + assert_nothing_raised do
  22 + assert_equal '', a.to_html
  23 + end
  24 + end
  25 +
  26 +end
... ...
test/unit/organization_test.rb
... ... @@ -162,19 +162,6 @@ class OrganizationTest &lt; Test::Unit::TestCase
162 162 assert ! org.errors.invalid?(:foundation_year)
163 163 end
164 164  
165   - should 'provide needed information in summary' do
166   - organization = Organization.new
167   -
168   - organization.acronym = 'organization acronym'
169   - organization.foundation_year = '2007'
170   - organization.contact_email = 'my contact email'
171   -
172   - summary = organization.summary
173   - assert(summary.any? { |line| line[1] == 'organization acronym' })
174   - assert(summary.any? { |line| line[1] == '2007' })
175   - assert(summary.any? { |line| line[1] == 'my contact email' })
176   - end
177   -
178 165 should 'has closed' do
179 166 org = Organization.new
180 167 assert_respond_to org, :closed
... ...
test/unit/person_test.rb
... ... @@ -248,19 +248,6 @@ class PersonTest &lt; Test::Unit::TestCase
248 248 assert p.respond_to?(:contact_information)
249 249 end
250 250  
251   - should 'provide needed information in summary' do
252   - person = Person.new
253   -
254   - person.name = 'person name'
255   - person.address = 'my address'
256   - person.contact_information = 'my contact information'
257   -
258   - summary = person.summary
259   - assert(summary.any? { |line| line[1] == 'person name' })
260   - assert(summary.any? { |line| line[1] == 'my address' })
261   - assert(summary.any? { |line| line[1] == 'my contact information' }, "summary (#{summary.map{|l| l[1] }.compact.join("; ")}) do not contain 'my contact informatidon'")
262   - end
263   -
264 251 should 'required name' do
265 252 person = Person.new
266 253 assert !person.valid?
... ...
test/unit/profile_helper_test.rb
... ... @@ -9,37 +9,8 @@ class ProfileHelperTest &lt; Test::Unit::TestCase
9 9 end
10 10 attr_reader :profile, :helper
11 11  
12   - should 'display info' do
13   - f1 = 'Field 1'
14   - v1 = 'value 1'
15   - f2 = 'Field 2'
16   - v2 = 'value 2'
17   - array = [
18   - [ f1, v1 ],
19   - [ f2, v2 ]
20   - ]
21   - profile.expects(:summary).returns(array)
22   -
23   - helper.expects(:content_tag).returns('').at_least_once
24   -
25   - helper.expects(:_).at_least_once
26   - helper.expects(:_).with('edit your information').returns('edit your information')
27   - helper.expects(:button).with(:edit, 'edit your information', :controller => 'profile_editor', :action => 'edit').returns("BUTTON")
28   -
29   - helper.display_profile_info(profile)
30   - end
31   -
32   - should 'call blocks' do
33   - myproc = lambda { content_tag('div', 'lalala') }
34   - profile.expects(:summary).returns([['f1', myproc ]])
35   - helper.stubs(:content_tag).returns('')
36   -
37   - helper.expects(:instance_eval).with(myproc)
38   -
39   - helper.expects(:_).at_least_once
40   - helper.expects(:button).returns('')
41   -
42   - helper.display_profile_info(profile)
  12 + def test_true
  13 + assert true
43 14 end
44 15  
45 16 end
... ...