Commit bdf53d0ec87af3cf7f912414744d7ba9ef241d78
1 parent
5281e384
Exists in
master
and in
29 other branches
ActionItem68: renaming files
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@513 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
8 changed files
with
252 additions
and
252 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,132 @@ |
| 1 | +# A Environment is like a website to be hosted in the platform. It may | |
| 2 | +# contain multiple Profile's and can be identified by several different | |
| 3 | +# domains. | |
| 4 | +class Environment < ActiveRecord::Base | |
| 5 | + | |
| 6 | + # returns the available features for a Environment, in the form of a | |
| 7 | + # hash, with pairs in the form <tt>'feature_name' => 'Feature name'</tt>. | |
| 8 | + def self.available_features | |
| 9 | + { | |
| 10 | + 'some_feature' => _('Some feature'), | |
| 11 | + 'other_feature' => _('Other feature'), | |
| 12 | + } | |
| 13 | + end | |
| 14 | + | |
| 15 | + # ################################################# | |
| 16 | + # Relationships and applied behaviour | |
| 17 | + # ################################################# | |
| 18 | + | |
| 19 | + acts_as_design | |
| 20 | + | |
| 21 | + # One Environment can be reached by many domains | |
| 22 | + has_many :domains, :as => :owner | |
| 23 | + has_many :profiles | |
| 24 | + | |
| 25 | + # ################################################# | |
| 26 | + # Attributes | |
| 27 | + # ################################################# | |
| 28 | + | |
| 29 | + # store the Environment settings as YAML-serialized Hash. | |
| 30 | + serialize :settings | |
| 31 | + | |
| 32 | + # returns a Hash containing the Environment configuration | |
| 33 | + def settings | |
| 34 | + self[:settings] ||= {} | |
| 35 | + end | |
| 36 | + | |
| 37 | + # Enables a feature identified by its name | |
| 38 | + def enable(feature) | |
| 39 | + self.settings["#{feature}_enabled"] = true | |
| 40 | + end | |
| 41 | + | |
| 42 | + # Disables a feature identified by its name | |
| 43 | + def disable(feature) | |
| 44 | + self.settings["#{feature}_enabled"] = false | |
| 45 | + end | |
| 46 | + | |
| 47 | + # Tells if a feature, identified by its name, is enabled | |
| 48 | + def enabled?(feature) | |
| 49 | + self.settings["#{feature}_enabled"] == true | |
| 50 | + end | |
| 51 | + | |
| 52 | + # enables the features identified by <tt>features</tt>, which is expected to | |
| 53 | + # be an Enumarable object containing the identifiers of the desired features. | |
| 54 | + # Passing <tt>nil</tt> is the same as passing an empty Array. | |
| 55 | + def enabled_features=(features) | |
| 56 | + features ||= [] | |
| 57 | + self.class.available_features.keys.each do |feature| | |
| 58 | + if features.include? feature | |
| 59 | + self.enable(feature) | |
| 60 | + else | |
| 61 | + self.disable(feature) | |
| 62 | + end | |
| 63 | + end | |
| 64 | + end | |
| 65 | + | |
| 66 | + # the virtual community's terms of use: every user must accept them before | |
| 67 | + # registering. | |
| 68 | + def terms_of_use | |
| 69 | + self.settings['terms_of_use'] | |
| 70 | + end | |
| 71 | + | |
| 72 | + # sets the virtual community's terms of use. | |
| 73 | + def terms_of_use=(value) | |
| 74 | + self.settings['terms_of_use'] = value | |
| 75 | + end | |
| 76 | + | |
| 77 | + # returns <tt>true</tt> if this Environment has terms of use to be | |
| 78 | + # accepted by users before registration. | |
| 79 | + def has_terms_of_use? | |
| 80 | + ! self.settings['terms_of_use'].nil? | |
| 81 | + end | |
| 82 | + | |
| 83 | + # Returns the template used by +flexible_template+ plugin. | |
| 84 | + def flexible_template_template | |
| 85 | + self.settings['flexible_template_template'] | |
| 86 | + end | |
| 87 | + | |
| 88 | + # Sets the template used by +flexible_template+ plugin. | |
| 89 | + def flexible_template_template=(value) | |
| 90 | + self.settings['flexible_template_template'] = value | |
| 91 | + end | |
| 92 | + | |
| 93 | + # Returns the theme used by +flexible_template+ plugin | |
| 94 | + def flexible_template_theme | |
| 95 | + self.settings['flexible_template_theme'] | |
| 96 | + end | |
| 97 | + | |
| 98 | + # Sets the theme used by +flexible_template+ plugin | |
| 99 | + def flexible_template_theme=(value) | |
| 100 | + self.settings['flexible_template_theme'] = value | |
| 101 | + end | |
| 102 | + | |
| 103 | + # Returns the icon theme used by +flexible_template+ plugin | |
| 104 | + def flexible_template_icon_theme | |
| 105 | + self.settings['flexible_template_icon_theme'] | |
| 106 | + end | |
| 107 | + | |
| 108 | + # Sets the icon theme used by +flexible_template+ plugin | |
| 109 | + def flexible_template_icon_theme=(value) | |
| 110 | + self.settings['flexible_template_icon_theme'] = value | |
| 111 | + end | |
| 112 | + | |
| 113 | + # ################################################# | |
| 114 | + # Validations | |
| 115 | + # ################################################# | |
| 116 | + | |
| 117 | + # <tt>name</tt> is mandatory | |
| 118 | + validates_presence_of :name | |
| 119 | + | |
| 120 | + # only one virtual community can be the default one | |
| 121 | + validates_uniqueness_of :is_default, :if => (lambda do |environment| environment.is_default? end), :message => _('Only one Virtual Community can be the default one') | |
| 122 | + | |
| 123 | + # ################################################# | |
| 124 | + # Business logic in general | |
| 125 | + # ################################################# | |
| 126 | + | |
| 127 | + # the default Environment. | |
| 128 | + def self.default | |
| 129 | + self.find(:first, :conditions => [ 'is_default = ?', true ] ) | |
| 130 | + end | |
| 131 | + | |
| 132 | +end | ... | ... |
app/models/virtual_community.rb
| ... | ... | @@ -1,132 +0,0 @@ |
| 1 | -# A Environment is like a website to be hosted in the platform. It may | |
| 2 | -# contain multiple Profile's and can be identified by several different | |
| 3 | -# domains. | |
| 4 | -class Environment < ActiveRecord::Base | |
| 5 | - | |
| 6 | - # returns the available features for a Environment, in the form of a | |
| 7 | - # hash, with pairs in the form <tt>'feature_name' => 'Feature name'</tt>. | |
| 8 | - def self.available_features | |
| 9 | - { | |
| 10 | - 'some_feature' => _('Some feature'), | |
| 11 | - 'other_feature' => _('Other feature'), | |
| 12 | - } | |
| 13 | - end | |
| 14 | - | |
| 15 | - # ################################################# | |
| 16 | - # Relationships and applied behaviour | |
| 17 | - # ################################################# | |
| 18 | - | |
| 19 | - acts_as_design | |
| 20 | - | |
| 21 | - # One Environment can be reached by many domains | |
| 22 | - has_many :domains, :as => :owner | |
| 23 | - has_many :profiles | |
| 24 | - | |
| 25 | - # ################################################# | |
| 26 | - # Attributes | |
| 27 | - # ################################################# | |
| 28 | - | |
| 29 | - # store the Environment settings as YAML-serialized Hash. | |
| 30 | - serialize :settings | |
| 31 | - | |
| 32 | - # returns a Hash containing the Environment configuration | |
| 33 | - def settings | |
| 34 | - self[:settings] ||= {} | |
| 35 | - end | |
| 36 | - | |
| 37 | - # Enables a feature identified by its name | |
| 38 | - def enable(feature) | |
| 39 | - self.settings["#{feature}_enabled"] = true | |
| 40 | - end | |
| 41 | - | |
| 42 | - # Disables a feature identified by its name | |
| 43 | - def disable(feature) | |
| 44 | - self.settings["#{feature}_enabled"] = false | |
| 45 | - end | |
| 46 | - | |
| 47 | - # Tells if a feature, identified by its name, is enabled | |
| 48 | - def enabled?(feature) | |
| 49 | - self.settings["#{feature}_enabled"] == true | |
| 50 | - end | |
| 51 | - | |
| 52 | - # enables the features identified by <tt>features</tt>, which is expected to | |
| 53 | - # be an Enumarable object containing the identifiers of the desired features. | |
| 54 | - # Passing <tt>nil</tt> is the same as passing an empty Array. | |
| 55 | - def enabled_features=(features) | |
| 56 | - features ||= [] | |
| 57 | - self.class.available_features.keys.each do |feature| | |
| 58 | - if features.include? feature | |
| 59 | - self.enable(feature) | |
| 60 | - else | |
| 61 | - self.disable(feature) | |
| 62 | - end | |
| 63 | - end | |
| 64 | - end | |
| 65 | - | |
| 66 | - # the virtual community's terms of use: every user must accept them before | |
| 67 | - # registering. | |
| 68 | - def terms_of_use | |
| 69 | - self.settings['terms_of_use'] | |
| 70 | - end | |
| 71 | - | |
| 72 | - # sets the virtual community's terms of use. | |
| 73 | - def terms_of_use=(value) | |
| 74 | - self.settings['terms_of_use'] = value | |
| 75 | - end | |
| 76 | - | |
| 77 | - # returns <tt>true</tt> if this Environment has terms of use to be | |
| 78 | - # accepted by users before registration. | |
| 79 | - def has_terms_of_use? | |
| 80 | - ! self.settings['terms_of_use'].nil? | |
| 81 | - end | |
| 82 | - | |
| 83 | - # Returns the template used by +flexible_template+ plugin. | |
| 84 | - def flexible_template_template | |
| 85 | - self.settings['flexible_template_template'] | |
| 86 | - end | |
| 87 | - | |
| 88 | - # Sets the template used by +flexible_template+ plugin. | |
| 89 | - def flexible_template_template=(value) | |
| 90 | - self.settings['flexible_template_template'] = value | |
| 91 | - end | |
| 92 | - | |
| 93 | - # Returns the theme used by +flexible_template+ plugin | |
| 94 | - def flexible_template_theme | |
| 95 | - self.settings['flexible_template_theme'] | |
| 96 | - end | |
| 97 | - | |
| 98 | - # Sets the theme used by +flexible_template+ plugin | |
| 99 | - def flexible_template_theme=(value) | |
| 100 | - self.settings['flexible_template_theme'] = value | |
| 101 | - end | |
| 102 | - | |
| 103 | - # Returns the icon theme used by +flexible_template+ plugin | |
| 104 | - def flexible_template_icon_theme | |
| 105 | - self.settings['flexible_template_icon_theme'] | |
| 106 | - end | |
| 107 | - | |
| 108 | - # Sets the icon theme used by +flexible_template+ plugin | |
| 109 | - def flexible_template_icon_theme=(value) | |
| 110 | - self.settings['flexible_template_icon_theme'] = value | |
| 111 | - end | |
| 112 | - | |
| 113 | - # ################################################# | |
| 114 | - # Validations | |
| 115 | - # ################################################# | |
| 116 | - | |
| 117 | - # <tt>name</tt> is mandatory | |
| 118 | - validates_presence_of :name | |
| 119 | - | |
| 120 | - # only one virtual community can be the default one | |
| 121 | - validates_uniqueness_of :is_default, :if => (lambda do |environment| environment.is_default? end), :message => _('Only one Virtual Community can be the default one') | |
| 122 | - | |
| 123 | - # ################################################# | |
| 124 | - # Business logic in general | |
| 125 | - # ################################################# | |
| 126 | - | |
| 127 | - # the default Environment. | |
| 128 | - def self.default | |
| 129 | - self.find(:first, :conditions => [ 'is_default = ?', true ] ) | |
| 130 | - end | |
| 131 | - | |
| 132 | -end |
test/fixtures/virtual_communities.yml
| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | +require File.expand_path(File.dirname(__FILE__) + "/../../../app/models/environment") | |
| 2 | + | |
| 3 | +class Environment < ActiveRecord::Base | |
| 4 | + def self.available_features | |
| 5 | + { | |
| 6 | + 'feature1' => 'Enable Feature 1', | |
| 7 | + 'feature2' => 'Enable Feature 2', | |
| 8 | + 'feature3' => 'Enable Feature 3', | |
| 9 | + } | |
| 10 | + end | |
| 11 | +end | ... | ... |
test/mocks/test/virtual_community.rb
| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | -require File.expand_path(File.dirname(__FILE__) + "/../../../app/models/environment") | |
| 2 | - | |
| 3 | -class Environment < ActiveRecord::Base | |
| 4 | - def self.available_features | |
| 5 | - { | |
| 6 | - 'feature1' => 'Enable Feature 1', | |
| 7 | - 'feature2' => 'Enable Feature 2', | |
| 8 | - 'feature3' => 'Enable Feature 3', | |
| 9 | - } | |
| 10 | - end | |
| 11 | -end |
| ... | ... | @@ -0,0 +1,100 @@ |
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | + | |
| 3 | +class EnvironmentTest < Test::Unit::TestCase | |
| 4 | + fixtures :virtual_communities | |
| 5 | + | |
| 6 | + def test_exists_default_and_it_is_unique | |
| 7 | + Environment.delete_all | |
| 8 | + vc = Environment.new(:name => 'Test Community') | |
| 9 | + vc.is_default = true | |
| 10 | + assert vc.save | |
| 11 | + | |
| 12 | + vc2 = Environment.new(:name => 'Another Test Community') | |
| 13 | + vc2.is_default = true | |
| 14 | + assert !vc2.valid? | |
| 15 | + assert vc2.errors.invalid?(:is_default) | |
| 16 | + | |
| 17 | + assert_equal vc, Environment.default | |
| 18 | + end | |
| 19 | + | |
| 20 | + def test_acts_as_configurable | |
| 21 | + vc = Environment.new(:name => 'Testing Environment') | |
| 22 | + assert_kind_of Hash, vc.settings | |
| 23 | + vc.settings[:some_setting] = 1 | |
| 24 | + assert vc.save | |
| 25 | + assert_equal 1, vc.settings[:some_setting] | |
| 26 | + end | |
| 27 | + | |
| 28 | + def test_available_features | |
| 29 | + assert_kind_of Hash, Environment.available_features | |
| 30 | + end | |
| 31 | + | |
| 32 | + def test_mock | |
| 33 | + assert_equal ['feature1', 'feature2', 'feature3'], Environment.available_features.keys.sort | |
| 34 | + end | |
| 35 | + | |
| 36 | + def test_features | |
| 37 | + v = virtual_communities(:colivre_net) | |
| 38 | + v.enable('feature1') | |
| 39 | + assert v.enabled?('feature1') | |
| 40 | + v.disable('feature1') | |
| 41 | + assert !v.enabled?('feature1') | |
| 42 | + end | |
| 43 | + | |
| 44 | + def test_enabled_features | |
| 45 | + v = virtual_communities(:colivre_net) | |
| 46 | + v.enabled_features = [ 'feature1', 'feature2' ] | |
| 47 | + assert v.enabled?('feature1') && v.enabled?('feature2') && !v.enabled?('feature3') | |
| 48 | + end | |
| 49 | + | |
| 50 | + def test_enabled_features_no_features_enabled | |
| 51 | + v = virtual_communities(:colivre_net) | |
| 52 | + v.enabled_features = nil | |
| 53 | + assert !v.enabled?('feature1') && !v.enabled?('feature2') && !v.enabled?('feature3') | |
| 54 | + end | |
| 55 | + | |
| 56 | + def test_name_is_mandatory | |
| 57 | + v = Environment.new | |
| 58 | + v.valid? | |
| 59 | + assert v.errors.invalid?(:name) | |
| 60 | + v.name = 'blablabla' | |
| 61 | + v.valid? | |
| 62 | + assert !v.errors.invalid?(:name) | |
| 63 | + end | |
| 64 | + | |
| 65 | + def test_terms_of_use | |
| 66 | + v = Environment.new(:name => 'My test virtual community') | |
| 67 | + assert_nil v.terms_of_use | |
| 68 | + v.terms_of_use = 'To be part of this virtual community, you must accept the following terms: ...' | |
| 69 | + assert v.save | |
| 70 | + id = v.id | |
| 71 | + assert_equal 'To be part of this virtual community, you must accept the following terms: ...', Environment.find(id).terms_of_use | |
| 72 | + end | |
| 73 | + | |
| 74 | + def test_has_terms_of_use | |
| 75 | + v = Environment.new | |
| 76 | + assert !v.has_terms_of_use? | |
| 77 | + v.terms_of_use = 'some terms of use' | |
| 78 | + assert v.has_terms_of_use? | |
| 79 | + end | |
| 80 | + | |
| 81 | + def test_should_profive_flexible_template_stuff | |
| 82 | + v = Environment.new | |
| 83 | + | |
| 84 | + # template | |
| 85 | + assert_nil v.flexible_template_template | |
| 86 | + v.flexible_template_template = 'bli' | |
| 87 | + assert_equal 'bli', v.flexible_template_template | |
| 88 | + | |
| 89 | + # theme | |
| 90 | + assert_nil v.flexible_template_theme | |
| 91 | + v.flexible_template_theme = 'bli' | |
| 92 | + assert_equal 'bli', v.flexible_template_theme | |
| 93 | + | |
| 94 | + # icon theme | |
| 95 | + assert_nil v.flexible_template_icon_theme | |
| 96 | + v.flexible_template_icon_theme = 'bli' | |
| 97 | + assert_equal 'bli', v.flexible_template_icon_theme | |
| 98 | + end | |
| 99 | + | |
| 100 | +end | ... | ... |
test/unit/virtual_community_test.rb
| ... | ... | @@ -1,100 +0,0 @@ |
| 1 | -require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | - | |
| 3 | -class EnvironmentTest < Test::Unit::TestCase | |
| 4 | - fixtures :virtual_communities | |
| 5 | - | |
| 6 | - def test_exists_default_and_it_is_unique | |
| 7 | - Environment.delete_all | |
| 8 | - vc = Environment.new(:name => 'Test Community') | |
| 9 | - vc.is_default = true | |
| 10 | - assert vc.save | |
| 11 | - | |
| 12 | - vc2 = Environment.new(:name => 'Another Test Community') | |
| 13 | - vc2.is_default = true | |
| 14 | - assert !vc2.valid? | |
| 15 | - assert vc2.errors.invalid?(:is_default) | |
| 16 | - | |
| 17 | - assert_equal vc, Environment.default | |
| 18 | - end | |
| 19 | - | |
| 20 | - def test_acts_as_configurable | |
| 21 | - vc = Environment.new(:name => 'Testing Environment') | |
| 22 | - assert_kind_of Hash, vc.settings | |
| 23 | - vc.settings[:some_setting] = 1 | |
| 24 | - assert vc.save | |
| 25 | - assert_equal 1, vc.settings[:some_setting] | |
| 26 | - end | |
| 27 | - | |
| 28 | - def test_available_features | |
| 29 | - assert_kind_of Hash, Environment.available_features | |
| 30 | - end | |
| 31 | - | |
| 32 | - def test_mock | |
| 33 | - assert_equal ['feature1', 'feature2', 'feature3'], Environment.available_features.keys.sort | |
| 34 | - end | |
| 35 | - | |
| 36 | - def test_features | |
| 37 | - v = virtual_communities(:colivre_net) | |
| 38 | - v.enable('feature1') | |
| 39 | - assert v.enabled?('feature1') | |
| 40 | - v.disable('feature1') | |
| 41 | - assert !v.enabled?('feature1') | |
| 42 | - end | |
| 43 | - | |
| 44 | - def test_enabled_features | |
| 45 | - v = virtual_communities(:colivre_net) | |
| 46 | - v.enabled_features = [ 'feature1', 'feature2' ] | |
| 47 | - assert v.enabled?('feature1') && v.enabled?('feature2') && !v.enabled?('feature3') | |
| 48 | - end | |
| 49 | - | |
| 50 | - def test_enabled_features_no_features_enabled | |
| 51 | - v = virtual_communities(:colivre_net) | |
| 52 | - v.enabled_features = nil | |
| 53 | - assert !v.enabled?('feature1') && !v.enabled?('feature2') && !v.enabled?('feature3') | |
| 54 | - end | |
| 55 | - | |
| 56 | - def test_name_is_mandatory | |
| 57 | - v = Environment.new | |
| 58 | - v.valid? | |
| 59 | - assert v.errors.invalid?(:name) | |
| 60 | - v.name = 'blablabla' | |
| 61 | - v.valid? | |
| 62 | - assert !v.errors.invalid?(:name) | |
| 63 | - end | |
| 64 | - | |
| 65 | - def test_terms_of_use | |
| 66 | - v = Environment.new(:name => 'My test virtual community') | |
| 67 | - assert_nil v.terms_of_use | |
| 68 | - v.terms_of_use = 'To be part of this virtual community, you must accept the following terms: ...' | |
| 69 | - assert v.save | |
| 70 | - id = v.id | |
| 71 | - assert_equal 'To be part of this virtual community, you must accept the following terms: ...', Environment.find(id).terms_of_use | |
| 72 | - end | |
| 73 | - | |
| 74 | - def test_has_terms_of_use | |
| 75 | - v = Environment.new | |
| 76 | - assert !v.has_terms_of_use? | |
| 77 | - v.terms_of_use = 'some terms of use' | |
| 78 | - assert v.has_terms_of_use? | |
| 79 | - end | |
| 80 | - | |
| 81 | - def test_should_profive_flexible_template_stuff | |
| 82 | - v = Environment.new | |
| 83 | - | |
| 84 | - # template | |
| 85 | - assert_nil v.flexible_template_template | |
| 86 | - v.flexible_template_template = 'bli' | |
| 87 | - assert_equal 'bli', v.flexible_template_template | |
| 88 | - | |
| 89 | - # theme | |
| 90 | - assert_nil v.flexible_template_theme | |
| 91 | - v.flexible_template_theme = 'bli' | |
| 92 | - assert_equal 'bli', v.flexible_template_theme | |
| 93 | - | |
| 94 | - # icon theme | |
| 95 | - assert_nil v.flexible_template_icon_theme | |
| 96 | - v.flexible_template_icon_theme = 'bli' | |
| 97 | - assert_equal 'bli', v.flexible_template_icon_theme | |
| 98 | - end | |
| 99 | - | |
| 100 | -end |