ref: refs/heads/master
commit c850341eb990a07fa54c7c48efc0b0c09b993d38
Author: Klaus Kämpf
Date: Wed Jul 15 15:22:50 2009 +0200
Validate host model, add tests for it
---
webclient/app/models/host.rb | 3 ++-
webclient/test/functional/hosts_controller_test.rb | 19 ++++++++++++++++++-
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/webclient/app/models/host.rb b/webclient/app/models/host.rb
index d9e96eb..083e727 100644
--- a/webclient/app/models/host.rb
+++ b/webclient/app/models/host.rb
@@ -1,5 +1,6 @@
require 'uri'
class Host < ActiveRecord::Base
- #validates_format_of :url, :with => URI.regexp
+ validates_format_of :url, :with => URI.regexp
+ validates_uniqueness_of :name
end
diff --git a/webclient/test/functional/hosts_controller_test.rb b/webclient/test/functional/hosts_controller_test.rb
index 8c05fa2..ed9013f 100644
--- a/webclient/test/functional/hosts_controller_test.rb
+++ b/webclient/test/functional/hosts_controller_test.rb
@@ -1,6 +1,8 @@
require File.dirname(__FILE__) + '/../test_helper'
class HostsControllerTest < ActionController::TestCase
+ fixtures :hosts
+
def test_should_get_index
get :index
assert_response :success
@@ -14,13 +16,28 @@ class HostsControllerTest < ActionController::TestCase
def test_should_create_host
assert_difference('Host.count') do
- post :create, :host => { }
+ post :create, :host => { :name => "new host", :url => "http://www.rubyonrails.org", :description => "Rails" }
end
# after creating we redirect to the full list
assert_redirected_to hosts_path
end
+ def test_should_fail_create_host
+ post :create, :host => { } # empty :host hash
+
+ assert_redirected_to new_host_path
+ end
+
+ # re-create the first host of the fixture
+ def test_host_uniqueness
+ host = Host.find(:first)
+ assert host
+ post :create, :host => { :name => host.name, :url => host.url, :description => host.description }
+
+ assert_redirected_to new_host_path
+ end
+
def test_should_show_host
get :show, :id => hosts(:one).id
assert_response :success
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org