diff --git a/app/models/environment.rb b/app/models/environment.rb
new file mode 100644
index 0000000..73fe8b3
--- /dev/null
+++ b/app/models/environment.rb
@@ -0,0 +1,132 @@
+# A Environment is like a website to be hosted in the platform. It may
+# contain multiple Profile's and can be identified by several different
+# domains.
+class Environment < ActiveRecord::Base
+
+ # returns the available features for a Environment, in the form of a
+ # hash, with pairs in the form 'feature_name' => 'Feature name'.
+ def self.available_features
+ {
+ 'some_feature' => _('Some feature'),
+ 'other_feature' => _('Other feature'),
+ }
+ end
+
+ # #################################################
+ # Relationships and applied behaviour
+ # #################################################
+
+ acts_as_design
+
+ # One Environment can be reached by many domains
+ has_many :domains, :as => :owner
+ has_many :profiles
+
+ # #################################################
+ # Attributes
+ # #################################################
+
+ # store the Environment settings as YAML-serialized Hash.
+ serialize :settings
+
+ # returns a Hash containing the Environment configuration
+ def settings
+ self[:settings] ||= {}
+ end
+
+ # Enables a feature identified by its name
+ def enable(feature)
+ self.settings["#{feature}_enabled"] = true
+ end
+
+ # Disables a feature identified by its name
+ def disable(feature)
+ self.settings["#{feature}_enabled"] = false
+ end
+
+ # Tells if a feature, identified by its name, is enabled
+ def enabled?(feature)
+ self.settings["#{feature}_enabled"] == true
+ end
+
+ # enables the features identified by features, which is expected to
+ # be an Enumarable object containing the identifiers of the desired features.
+ # Passing nil is the same as passing an empty Array.
+ def enabled_features=(features)
+ features ||= []
+ self.class.available_features.keys.each do |feature|
+ if features.include? feature
+ self.enable(feature)
+ else
+ self.disable(feature)
+ end
+ end
+ end
+
+ # the virtual community's terms of use: every user must accept them before
+ # registering.
+ def terms_of_use
+ self.settings['terms_of_use']
+ end
+
+ # sets the virtual community's terms of use.
+ def terms_of_use=(value)
+ self.settings['terms_of_use'] = value
+ end
+
+ # returns true if this Environment has terms of use to be
+ # accepted by users before registration.
+ def has_terms_of_use?
+ ! self.settings['terms_of_use'].nil?
+ end
+
+ # Returns the template used by +flexible_template+ plugin.
+ def flexible_template_template
+ self.settings['flexible_template_template']
+ end
+
+ # Sets the template used by +flexible_template+ plugin.
+ def flexible_template_template=(value)
+ self.settings['flexible_template_template'] = value
+ end
+
+ # Returns the theme used by +flexible_template+ plugin
+ def flexible_template_theme
+ self.settings['flexible_template_theme']
+ end
+
+ # Sets the theme used by +flexible_template+ plugin
+ def flexible_template_theme=(value)
+ self.settings['flexible_template_theme'] = value
+ end
+
+ # Returns the icon theme used by +flexible_template+ plugin
+ def flexible_template_icon_theme
+ self.settings['flexible_template_icon_theme']
+ end
+
+ # Sets the icon theme used by +flexible_template+ plugin
+ def flexible_template_icon_theme=(value)
+ self.settings['flexible_template_icon_theme'] = value
+ end
+
+ # #################################################
+ # Validations
+ # #################################################
+
+ # name is mandatory
+ validates_presence_of :name
+
+ # only one virtual community can be the default one
+ validates_uniqueness_of :is_default, :if => (lambda do |environment| environment.is_default? end), :message => _('Only one Virtual Community can be the default one')
+
+ # #################################################
+ # Business logic in general
+ # #################################################
+
+ # the default Environment.
+ def self.default
+ self.find(:first, :conditions => [ 'is_default = ?', true ] )
+ end
+
+end
diff --git a/app/models/virtual_community.rb b/app/models/virtual_community.rb
deleted file mode 100644
index 73fe8b3..0000000
--- a/app/models/virtual_community.rb
+++ /dev/null
@@ -1,132 +0,0 @@
-# A Environment is like a website to be hosted in the platform. It may
-# contain multiple Profile's and can be identified by several different
-# domains.
-class Environment < ActiveRecord::Base
-
- # returns the available features for a Environment, in the form of a
- # hash, with pairs in the form 'feature_name' => 'Feature name'.
- def self.available_features
- {
- 'some_feature' => _('Some feature'),
- 'other_feature' => _('Other feature'),
- }
- end
-
- # #################################################
- # Relationships and applied behaviour
- # #################################################
-
- acts_as_design
-
- # One Environment can be reached by many domains
- has_many :domains, :as => :owner
- has_many :profiles
-
- # #################################################
- # Attributes
- # #################################################
-
- # store the Environment settings as YAML-serialized Hash.
- serialize :settings
-
- # returns a Hash containing the Environment configuration
- def settings
- self[:settings] ||= {}
- end
-
- # Enables a feature identified by its name
- def enable(feature)
- self.settings["#{feature}_enabled"] = true
- end
-
- # Disables a feature identified by its name
- def disable(feature)
- self.settings["#{feature}_enabled"] = false
- end
-
- # Tells if a feature, identified by its name, is enabled
- def enabled?(feature)
- self.settings["#{feature}_enabled"] == true
- end
-
- # enables the features identified by features, which is expected to
- # be an Enumarable object containing the identifiers of the desired features.
- # Passing nil is the same as passing an empty Array.
- def enabled_features=(features)
- features ||= []
- self.class.available_features.keys.each do |feature|
- if features.include? feature
- self.enable(feature)
- else
- self.disable(feature)
- end
- end
- end
-
- # the virtual community's terms of use: every user must accept them before
- # registering.
- def terms_of_use
- self.settings['terms_of_use']
- end
-
- # sets the virtual community's terms of use.
- def terms_of_use=(value)
- self.settings['terms_of_use'] = value
- end
-
- # returns true if this Environment has terms of use to be
- # accepted by users before registration.
- def has_terms_of_use?
- ! self.settings['terms_of_use'].nil?
- end
-
- # Returns the template used by +flexible_template+ plugin.
- def flexible_template_template
- self.settings['flexible_template_template']
- end
-
- # Sets the template used by +flexible_template+ plugin.
- def flexible_template_template=(value)
- self.settings['flexible_template_template'] = value
- end
-
- # Returns the theme used by +flexible_template+ plugin
- def flexible_template_theme
- self.settings['flexible_template_theme']
- end
-
- # Sets the theme used by +flexible_template+ plugin
- def flexible_template_theme=(value)
- self.settings['flexible_template_theme'] = value
- end
-
- # Returns the icon theme used by +flexible_template+ plugin
- def flexible_template_icon_theme
- self.settings['flexible_template_icon_theme']
- end
-
- # Sets the icon theme used by +flexible_template+ plugin
- def flexible_template_icon_theme=(value)
- self.settings['flexible_template_icon_theme'] = value
- end
-
- # #################################################
- # Validations
- # #################################################
-
- # name is mandatory
- validates_presence_of :name
-
- # only one virtual community can be the default one
- validates_uniqueness_of :is_default, :if => (lambda do |environment| environment.is_default? end), :message => _('Only one Virtual Community can be the default one')
-
- # #################################################
- # Business logic in general
- # #################################################
-
- # the default Environment.
- def self.default
- self.find(:first, :conditions => [ 'is_default = ?', true ] )
- end
-
-end
diff --git a/test/fixtures/environments.yml b/test/fixtures/environments.yml
new file mode 100644
index 0000000..4228f5f
--- /dev/null
+++ b/test/fixtures/environments.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+colivre_net:
+ id: 1
+ name: 'Colivre.net'
+ is_default: true
+anhetegua_net:
+ id: 2
+ name: 'Anheteguá'
+ is_default: false
diff --git a/test/fixtures/virtual_communities.yml b/test/fixtures/virtual_communities.yml
deleted file mode 100644
index 4228f5f..0000000
--- a/test/fixtures/virtual_communities.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-colivre_net:
- id: 1
- name: 'Colivre.net'
- is_default: true
-anhetegua_net:
- id: 2
- name: 'Anheteguá'
- is_default: false
diff --git a/test/mocks/test/environment.rb b/test/mocks/test/environment.rb
new file mode 100644
index 0000000..131abfe
--- /dev/null
+++ b/test/mocks/test/environment.rb
@@ -0,0 +1,11 @@
+require File.expand_path(File.dirname(__FILE__) + "/../../../app/models/environment")
+
+class Environment < ActiveRecord::Base
+ def self.available_features
+ {
+ 'feature1' => 'Enable Feature 1',
+ 'feature2' => 'Enable Feature 2',
+ 'feature3' => 'Enable Feature 3',
+ }
+ end
+end
diff --git a/test/mocks/test/virtual_community.rb b/test/mocks/test/virtual_community.rb
deleted file mode 100644
index 131abfe..0000000
--- a/test/mocks/test/virtual_community.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + "/../../../app/models/environment")
-
-class Environment < ActiveRecord::Base
- def self.available_features
- {
- 'feature1' => 'Enable Feature 1',
- 'feature2' => 'Enable Feature 2',
- 'feature3' => 'Enable Feature 3',
- }
- end
-end
diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb
new file mode 100644
index 0000000..e1f3cab
--- /dev/null
+++ b/test/unit/environment_test.rb
@@ -0,0 +1,100 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class EnvironmentTest < Test::Unit::TestCase
+ fixtures :virtual_communities
+
+ def test_exists_default_and_it_is_unique
+ Environment.delete_all
+ vc = Environment.new(:name => 'Test Community')
+ vc.is_default = true
+ assert vc.save
+
+ vc2 = Environment.new(:name => 'Another Test Community')
+ vc2.is_default = true
+ assert !vc2.valid?
+ assert vc2.errors.invalid?(:is_default)
+
+ assert_equal vc, Environment.default
+ end
+
+ def test_acts_as_configurable
+ vc = Environment.new(:name => 'Testing Environment')
+ assert_kind_of Hash, vc.settings
+ vc.settings[:some_setting] = 1
+ assert vc.save
+ assert_equal 1, vc.settings[:some_setting]
+ end
+
+ def test_available_features
+ assert_kind_of Hash, Environment.available_features
+ end
+
+ def test_mock
+ assert_equal ['feature1', 'feature2', 'feature3'], Environment.available_features.keys.sort
+ end
+
+ def test_features
+ v = virtual_communities(:colivre_net)
+ v.enable('feature1')
+ assert v.enabled?('feature1')
+ v.disable('feature1')
+ assert !v.enabled?('feature1')
+ end
+
+ def test_enabled_features
+ v = virtual_communities(:colivre_net)
+ v.enabled_features = [ 'feature1', 'feature2' ]
+ assert v.enabled?('feature1') && v.enabled?('feature2') && !v.enabled?('feature3')
+ end
+
+ def test_enabled_features_no_features_enabled
+ v = virtual_communities(:colivre_net)
+ v.enabled_features = nil
+ assert !v.enabled?('feature1') && !v.enabled?('feature2') && !v.enabled?('feature3')
+ end
+
+ def test_name_is_mandatory
+ v = Environment.new
+ v.valid?
+ assert v.errors.invalid?(:name)
+ v.name = 'blablabla'
+ v.valid?
+ assert !v.errors.invalid?(:name)
+ end
+
+ def test_terms_of_use
+ v = Environment.new(:name => 'My test virtual community')
+ assert_nil v.terms_of_use
+ v.terms_of_use = 'To be part of this virtual community, you must accept the following terms: ...'
+ assert v.save
+ id = v.id
+ assert_equal 'To be part of this virtual community, you must accept the following terms: ...', Environment.find(id).terms_of_use
+ end
+
+ def test_has_terms_of_use
+ v = Environment.new
+ assert !v.has_terms_of_use?
+ v.terms_of_use = 'some terms of use'
+ assert v.has_terms_of_use?
+ end
+
+ def test_should_profive_flexible_template_stuff
+ v = Environment.new
+
+ # template
+ assert_nil v.flexible_template_template
+ v.flexible_template_template = 'bli'
+ assert_equal 'bli', v.flexible_template_template
+
+ # theme
+ assert_nil v.flexible_template_theme
+ v.flexible_template_theme = 'bli'
+ assert_equal 'bli', v.flexible_template_theme
+
+ # icon theme
+ assert_nil v.flexible_template_icon_theme
+ v.flexible_template_icon_theme = 'bli'
+ assert_equal 'bli', v.flexible_template_icon_theme
+ end
+
+end
diff --git a/test/unit/virtual_community_test.rb b/test/unit/virtual_community_test.rb
deleted file mode 100644
index e1f3cab..0000000
--- a/test/unit/virtual_community_test.rb
+++ /dev/null
@@ -1,100 +0,0 @@
-require File.dirname(__FILE__) + '/../test_helper'
-
-class EnvironmentTest < Test::Unit::TestCase
- fixtures :virtual_communities
-
- def test_exists_default_and_it_is_unique
- Environment.delete_all
- vc = Environment.new(:name => 'Test Community')
- vc.is_default = true
- assert vc.save
-
- vc2 = Environment.new(:name => 'Another Test Community')
- vc2.is_default = true
- assert !vc2.valid?
- assert vc2.errors.invalid?(:is_default)
-
- assert_equal vc, Environment.default
- end
-
- def test_acts_as_configurable
- vc = Environment.new(:name => 'Testing Environment')
- assert_kind_of Hash, vc.settings
- vc.settings[:some_setting] = 1
- assert vc.save
- assert_equal 1, vc.settings[:some_setting]
- end
-
- def test_available_features
- assert_kind_of Hash, Environment.available_features
- end
-
- def test_mock
- assert_equal ['feature1', 'feature2', 'feature3'], Environment.available_features.keys.sort
- end
-
- def test_features
- v = virtual_communities(:colivre_net)
- v.enable('feature1')
- assert v.enabled?('feature1')
- v.disable('feature1')
- assert !v.enabled?('feature1')
- end
-
- def test_enabled_features
- v = virtual_communities(:colivre_net)
- v.enabled_features = [ 'feature1', 'feature2' ]
- assert v.enabled?('feature1') && v.enabled?('feature2') && !v.enabled?('feature3')
- end
-
- def test_enabled_features_no_features_enabled
- v = virtual_communities(:colivre_net)
- v.enabled_features = nil
- assert !v.enabled?('feature1') && !v.enabled?('feature2') && !v.enabled?('feature3')
- end
-
- def test_name_is_mandatory
- v = Environment.new
- v.valid?
- assert v.errors.invalid?(:name)
- v.name = 'blablabla'
- v.valid?
- assert !v.errors.invalid?(:name)
- end
-
- def test_terms_of_use
- v = Environment.new(:name => 'My test virtual community')
- assert_nil v.terms_of_use
- v.terms_of_use = 'To be part of this virtual community, you must accept the following terms: ...'
- assert v.save
- id = v.id
- assert_equal 'To be part of this virtual community, you must accept the following terms: ...', Environment.find(id).terms_of_use
- end
-
- def test_has_terms_of_use
- v = Environment.new
- assert !v.has_terms_of_use?
- v.terms_of_use = 'some terms of use'
- assert v.has_terms_of_use?
- end
-
- def test_should_profive_flexible_template_stuff
- v = Environment.new
-
- # template
- assert_nil v.flexible_template_template
- v.flexible_template_template = 'bli'
- assert_equal 'bli', v.flexible_template_template
-
- # theme
- assert_nil v.flexible_template_theme
- v.flexible_template_theme = 'bli'
- assert_equal 'bli', v.flexible_template_theme
-
- # icon theme
- assert_nil v.flexible_template_icon_theme
- v.flexible_template_icon_theme = 'bli'
- assert_equal 'bli', v.flexible_template_icon_theme
- end
-
-end
--
libgit2 0.21.2