Commit 7d577436a6c588aa10907be9edd7fce11eb08054
1 parent
d933267b
Exists in
master
and in
29 other branches
adding domain model
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@12 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
7 changed files
with
60 additions
and
23 deletions
Show diff stats
app/models/virtual_community.rb
1 | class VirtualCommunity < ActiveRecord::Base | 1 | class VirtualCommunity < ActiveRecord::Base |
2 | - validates_presence_of :domain | ||
3 | - validates_format_of :domain, :with => /^(\w+\.)+\w+$/ | ||
4 | 2 | ||
3 | + has_many :domains, :as => :owner | ||
5 | 4 | ||
6 | - serialize :features | ||
7 | - def features | ||
8 | - self[:features] ||= {} | 5 | + serialize :configuration |
6 | + def configuration | ||
7 | + self[:configuration] ||= {} | ||
9 | end | 8 | end |
10 | end | 9 | end |
db/migrate/001_create_virtual_communities.rb
@@ -3,7 +3,7 @@ class CreateVirtualCommunities < ActiveRecord::Migration | @@ -3,7 +3,7 @@ class CreateVirtualCommunities < ActiveRecord::Migration | ||
3 | create_table :virtual_communities do |t| | 3 | create_table :virtual_communities do |t| |
4 | t.column :name, :string | 4 | t.column :name, :string |
5 | t.column :domain, :string | 5 | t.column :domain, :string |
6 | - t.column :features, :text | 6 | + t.column :configuration, :text |
7 | end | 7 | end |
8 | end | 8 | end |
9 | 9 |
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +class CreateDomains < ActiveRecord::Migration | ||
2 | + def self.up | ||
3 | + create_table :domains do |t| | ||
4 | + t.column :name, :string | ||
5 | + t.column :ownwer_type, :string | ||
6 | + t.column :owner_id, :integer | ||
7 | + end | ||
8 | + end | ||
9 | + | ||
10 | + def self.down | ||
11 | + drop_table :domains | ||
12 | + end | ||
13 | +end |
@@ -0,0 +1,28 @@ | @@ -0,0 +1,28 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class DomainTest < Test::Unit::TestCase | ||
4 | + fixtures :domains | ||
5 | + | ||
6 | + # Replace this with your real tests. | ||
7 | + def test_domain_name_format | ||
8 | + c = Domain.new | ||
9 | + c.valid? | ||
10 | + assert c.errors.invalid?(:domain) | ||
11 | + | ||
12 | + c.domain = 'bliblibli' | ||
13 | + c.valid? | ||
14 | + assert c.errors.invalid?(:domain) | ||
15 | + | ||
16 | + c.domain = 'test.net' | ||
17 | + c.valid? | ||
18 | + assert ! c.errors.invalid?(:domain) | ||
19 | + end | ||
20 | + | ||
21 | + def test_owner | ||
22 | + d = Domain.new(:name => 'example.com') | ||
23 | + d.owner = VirtualCommunity.new(:name => 'Example') | ||
24 | + assert d.save | ||
25 | + assert_kind_of VirtualCommunity, d.owner | ||
26 | + end | ||
27 | + | ||
28 | +end |
test/unit/virtual_community_test.rb
@@ -3,24 +3,9 @@ require File.dirname(__FILE__) + '/../test_helper' | @@ -3,24 +3,9 @@ require File.dirname(__FILE__) + '/../test_helper' | ||
3 | class VirtualCommunityTest < Test::Unit::TestCase | 3 | class VirtualCommunityTest < Test::Unit::TestCase |
4 | fixtures :virtual_communities | 4 | fixtures :virtual_communities |
5 | 5 | ||
6 | - def test_features | 6 | + def test_configuration |
7 | c = VirtualCommunity.new | 7 | c = VirtualCommunity.new |
8 | - assert_kind_of Hash, c.features | 8 | + assert_kind_of Hash, c.configuration |
9 | end | 9 | end |
10 | 10 | ||
11 | - def test_domain_validation | ||
12 | - c = VirtualCommunity.new | ||
13 | - c.valid? | ||
14 | - assert c.errors.invalid?(:domain) | ||
15 | - | ||
16 | - c.domain = 'bliblibli' | ||
17 | - c.valid? | ||
18 | - assert c.errors.invalid?(:domain) | ||
19 | - | ||
20 | - c.domain = 'test.net' | ||
21 | - c.valid? | ||
22 | - assert ! c.errors.invalid?(:domain) | ||
23 | - end | ||
24 | - | ||
25 | - | ||
26 | end | 11 | end |