diff --git a/app/models/virtual_community.rb b/app/models/virtual_community.rb new file mode 100644 index 0000000..77f0ea6 --- /dev/null +++ b/app/models/virtual_community.rb @@ -0,0 +1,12 @@ +class VirtualCommunity < ActiveRecord::Base + validates_presence_of :domain + validates_format_of :domain, :with => /^(\w+\.)+\w+$/ + + validates_presence_of :identifier + validates_format_of :identifier, :with => /^[a-z][a-z0-9_]+[a-z0-9]$/ + + serialize :features + def features + self[:features] ||= {} + end +end diff --git a/db/migrate/001_create_virtual_communities.rb b/db/migrate/001_create_virtual_communities.rb new file mode 100644 index 0000000..acc8119 --- /dev/null +++ b/db/migrate/001_create_virtual_communities.rb @@ -0,0 +1,13 @@ +class CreateVirtualCommunities < ActiveRecord::Migration + def self.up + create_table :virtual_communities do |t| + t.column :name, :string + t.column :domain, :string + t.column :features, :text + end + end + + def self.down + drop_table :virtual_communities + end +end diff --git a/test/fixtures/virtual_communities.yml b/test/fixtures/virtual_communities.yml new file mode 100644 index 0000000..7df90c7 --- /dev/null +++ b/test/fixtures/virtual_communities.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html +first: + id: 1 + name: 'Anheteguá' + domain: 'anhetegua.net' +another: + id: 2 + name: 'Colivre.net' + domain: 'colivre.net' diff --git a/test/unit/virtual_community_test.rb b/test/unit/virtual_community_test.rb new file mode 100644 index 0000000..2e23654 --- /dev/null +++ b/test/unit/virtual_community_test.rb @@ -0,0 +1,26 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class VirtualCommunityTest < Test::Unit::TestCase + fixtures :virtual_communities + + def test_features + c = VirtualCommunity.new + assert_kind_of Hash, c.features + end + + def test_domain_validation + c = VirtualCommunity.new + c.valid? + assert c.errors.invalid?(:domain) + + c.domain = 'bliblibli' + c.valid? + assert c.errors.invalid?(:domain) + + c.domain = 'test.net' + c.valid? + assert ! c.errors.invalid?(:domain) + end + + +end -- libgit2 0.21.2