From: Tomas Sedovic <[email protected]>

One test is failing.
---
 src/spec/factories/realm.rb   |    1 +
 src/spec/models/realm_spec.rb |   62 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 0 deletions(-)
 create mode 100644 src/spec/models/realm_spec.rb

diff --git a/src/spec/factories/realm.rb b/src/spec/factories/realm.rb
index 93a6516..377b40a 100644
--- a/src/spec/factories/realm.rb
+++ b/src/spec/factories/realm.rb
@@ -1,6 +1,7 @@
 Factory.define :realm do |r|
   r.sequence(:name) { |n| "realm#{n}" }
   r.sequence(:external_key) { |n| "key#{n}" }
+  r.provider_id 1
 end
 
 Factory.define :realm1, :parent => :realm do |r|
diff --git a/src/spec/models/realm_spec.rb b/src/spec/models/realm_spec.rb
new file mode 100644
index 0000000..2ce4744
--- /dev/null
+++ b/src/spec/models/realm_spec.rb
@@ -0,0 +1,62 @@
+require 'spec_helper'
+
+describe Realm do
+  before(:each) do
+    @valid_attributes = Factory.attributes_for(:realm1)
+  end
+
+  it "should have a provider" do
+    r = Realm.new(@valid_attributes.except(:provider_id))
+    r.should_not be_valid
+
+    r.provider_id = nil
+    r.should_not be_valid
+
+    r.provider_id = 1
+    r.should be_valid
+  end
+
+  it "should have an external key" do
+    r = Realm.new(@valid_attributes.except(:external_key))
+    r.should_not be_valid
+
+    r.external_key = nil
+    r.should_not be_valid
+
+    r.external_key = 'valid external key'
+    r.should be_valid
+  end
+
+  it "should have a unique external key" do
+    r1 = Factory.create(:realm1)
+    r2 = Factory.create(:realm2)
+    r1.should be_valid
+    r2.should be_valid
+
+    r2.external_key = r1.external_key
+    r2.should_not be_valid
+  end
+
+  it "should have a name" do
+    r = Realm.new(@valid_attributes.except(:name))
+    r.should_not be_valid
+
+    [nil, ''].each do |invalid_name|
+      r.name = invalid_name
+      r.should_not be_valid
+    end
+
+    r.name = 'a valid name worthy of this realm'
+    r.should be_valid
+  end
+
+  it "should not have a name that is too long" do
+    r = Realm.new(@valid_attributes)
+    r.name = 'x' * 1025
+    r.should_not be_valid
+
+    r.name = 'x' * 1024
+    r.should be_valid
+  end
+
+end
-- 
1.6.6.1

_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to