[PATCH 2/2] notifications tests

tzumainn at redhat.com tzumainn at redhat.com
Fri Oct 5 19:44:14 UTC 2012


From: Tzu-Mainn Chen <tzumainn at redhat.com>

---
 src/features/notifications.feature                |   14 +++++++
 src/features/step_definitions/deployment_steps.rb |   11 +++++
 src/spec/factories/notification.rb                |   33 ++++++++++++++++
 src/spec/models/notification_spec.rb              |   43 +++++++++++++++++++++
 4 files changed, 101 insertions(+), 0 deletions(-)
 create mode 100644 src/features/notifications.feature
 create mode 100644 src/spec/factories/notification.rb
 create mode 100644 src/spec/models/notification_spec.rb

diff --git a/src/features/notifications.feature b/src/features/notifications.feature
new file mode 100644
index 0000000..5fcffbc
--- /dev/null
+++ b/src/features/notifications.feature
@@ -0,0 +1,14 @@
+Feature: View Notifications
+  In order to manage my cloud infrastructure
+  As a user
+  I want to view notifications
+
+  Background:
+    Given I am an authorised user
+    And I am logged in
+
+  Scenario: View notifications
+    Given there is a deployment named "Test-Deployment" belonging to "Databases" owned by "bob"
+    And deployement "Test-Deployment" has associated notification "notifications.deployments.all_instances_running"
+    And I am on the notifications page
+    Then I should see "All instances running for deployment Test-Deployment"
diff --git a/src/features/step_definitions/deployment_steps.rb b/src/features/step_definitions/deployment_steps.rb
index b452535..550678b 100644
--- a/src/features/step_definitions/deployment_steps.rb
+++ b/src/features/step_definitions/deployment_steps.rb
@@ -93,3 +93,14 @@ Given /^deployement "([^"]*)" has associated event "([^"]*)"$/ do |arg1, arg2|
     :summary => arg2
   )
 end
+
+Given /^deployement "([^"]*)" has associated notification "([^"]*)"$/ do |arg1, arg2|
+  depl = Deployment.find_by_name(arg1)
+  notification = Notification.create(
+    :source => depl,
+    :level => :notice,
+    :key => "notifications.deployments.all_instances_running",
+    :user_notifications =>
+        [UserNotification.new(:user => @user, :viewed => false)]
+  )
+end
diff --git a/src/spec/factories/notification.rb b/src/spec/factories/notification.rb
new file mode 100644
index 0000000..9af2212
--- /dev/null
+++ b/src/spec/factories/notification.rb
@@ -0,0 +1,33 @@
+#
+#   Copyright 2011 Red Hat, Inc.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+
+FactoryGirl.define do
+
+  factory :user_notification do
+    association :user, :factory => :user
+   end
+
+   factory :notification do
+     key 'notifications.deployments.all_instances_running'
+     level :notice
+     after_build do |notification|
+       user = Factory.create(:tuser)
+       FactoryGirl.create(:user_notification,
+                          :notification => notification)
+    end
+  end
+
+end
diff --git a/src/spec/models/notification_spec.rb b/src/spec/models/notification_spec.rb
new file mode 100644
index 0000000..9f8ebe0
--- /dev/null
+++ b/src/spec/models/notification_spec.rb
@@ -0,0 +1,43 @@
+#
+#   Copyright 2011 Red Hat, Inc.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+
+require 'spec_helper'
+
+describe Notification do
+  before(:each) do
+  end
+
+  it "should be able to find a soft deleted source" do
+    deployment = Factory :deployment
+    notification = Factory.build(:notification, :source => deployment)
+
+    notification.source.should_not be_nil
+
+    deployment.destroy
+    notification.source.should_not be_nil
+  end
+
+  it "should allow multiple users to be associated with it" do
+    deployment = Factory :deployment
+    notification = Factory.build(:notification, :source => deployment)
+    notification.save
+
+    notification.users.count.should == 1
+    user_notification = Factory.create(:user_notification,
+                                      :notification => notification)
+    notification.users.count.should == 2
+  end
+end
-- 
1.7.6.5




More information about the aeolus-devel mailing list