Commit dd2e5fc632b99f1f02792ae265bc1b0e320a5247

Authored by AntonioTerceiro
1 parent 36ac32c6

adding a simple profile model



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@7 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/profile.rb 0 → 100644
... ... @@ -0,0 +1,4 @@
  1 +class Profile < ActiveRecord::Base
  2 + validates_presence_of :identifier
  3 + validates_format_of :identifier, :with => /^[a-z][a-z0-9_]+[a-z0-9]$/
  4 +end
... ...
app/models/virtual_community.rb
... ... @@ -2,8 +2,6 @@ class VirtualCommunity &lt; ActiveRecord::Base
2 2 validates_presence_of :domain
3 3 validates_format_of :domain, :with => /^(\w+\.)+\w+$/
4 4  
5   - validates_presence_of :identifier
6   - validates_format_of :identifier, :with => /^[a-z][a-z0-9_]+[a-z0-9]$/
7 5  
8 6 serialize :features
9 7 def features
... ...
db/migrate/002_create_profiles.rb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +class CreateProfiles < ActiveRecord::Migration
  2 + def self.up
  3 + create_table :profiles do |t|
  4 + t.column :name, :string
  5 + t.column :identifier, :string
  6 + end
  7 + end
  8 +
  9 + def self.down
  10 + drop_table :profiles
  11 + end
  12 +end
... ...
test/fixtures/profiles.yml 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
  2 +first:
  3 + id: 1
  4 +another:
  5 + id: 2
... ...
test/unit/profile_test.rb 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class ProfileTest < Test::Unit::TestCase
  4 + fixtures :profiles
  5 +
  6 + def test_identifier_validation
  7 + p = Profile.new
  8 + p.valid?
  9 + assert p.errors.invalid?(:identifier)
  10 +
  11 + p.identifier = 'with space'
  12 + p.valid?
  13 + assert p.errors.invalid?(:identifier)
  14 +
  15 + p.identifier = 'áéíóú'
  16 + p.valid?
  17 + assert p.errors.invalid?(:identifier)
  18 +
  19 + p.identifier = 'right_format'
  20 + p.valid?
  21 + assert ! p.errors.invalid?(:identifier)
  22 +
  23 + end
  24 +end
... ...