From dd2e5fc632b99f1f02792ae265bc1b0e320a5247 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Thu, 28 Jun 2007 19:51:04 +0000 Subject: [PATCH] adding a simple profile model --- app/models/profile.rb | 4 ++++ app/models/virtual_community.rb | 2 -- db/migrate/002_create_profiles.rb | 12 ++++++++++++ test/fixtures/profiles.yml | 5 +++++ test/unit/profile_test.rb | 24 ++++++++++++++++++++++++ 5 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 app/models/profile.rb create mode 100644 db/migrate/002_create_profiles.rb create mode 100644 test/fixtures/profiles.yml create mode 100644 test/unit/profile_test.rb diff --git a/app/models/profile.rb b/app/models/profile.rb new file mode 100644 index 0000000..df1798e --- /dev/null +++ b/app/models/profile.rb @@ -0,0 +1,4 @@ +class Profile < ActiveRecord::Base + validates_presence_of :identifier + validates_format_of :identifier, :with => /^[a-z][a-z0-9_]+[a-z0-9]$/ +end diff --git a/app/models/virtual_community.rb b/app/models/virtual_community.rb index 77f0ea6..9ed639c 100644 --- a/app/models/virtual_community.rb +++ b/app/models/virtual_community.rb @@ -2,8 +2,6 @@ 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 diff --git a/db/migrate/002_create_profiles.rb b/db/migrate/002_create_profiles.rb new file mode 100644 index 0000000..f35ad93 --- /dev/null +++ b/db/migrate/002_create_profiles.rb @@ -0,0 +1,12 @@ +class CreateProfiles < ActiveRecord::Migration + def self.up + create_table :profiles do |t| + t.column :name, :string + t.column :identifier, :string + end + end + + def self.down + drop_table :profiles + end +end diff --git a/test/fixtures/profiles.yml b/test/fixtures/profiles.yml new file mode 100644 index 0000000..8794d28 --- /dev/null +++ b/test/fixtures/profiles.yml @@ -0,0 +1,5 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html +first: + id: 1 +another: + id: 2 diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb new file mode 100644 index 0000000..5fc93bc --- /dev/null +++ b/test/unit/profile_test.rb @@ -0,0 +1,24 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class ProfileTest < Test::Unit::TestCase + fixtures :profiles + + def test_identifier_validation + p = Profile.new + p.valid? + assert p.errors.invalid?(:identifier) + + p.identifier = 'with space' + p.valid? + assert p.errors.invalid?(:identifier) + + p.identifier = 'áéíóú' + p.valid? + assert p.errors.invalid?(:identifier) + + p.identifier = 'right_format' + p.valid? + assert ! p.errors.invalid?(:identifier) + + end +end -- libgit2 0.21.2