From: Jan Provaznik <[email protected]>

---
 src/spec/controllers/templates_controller_spec.rb |   73 +++++++++++++++++++++
 src/spec/fixtures/privileges.yml                  |    4 +
 src/spec/fixtures/roles.yml                       |    2 +-
 src/spec/spec_helper.rb                           |    3 +
 4 files changed, 81 insertions(+), 1 deletions(-)
 create mode 100644 src/spec/controllers/templates_controller_spec.rb

diff --git a/src/spec/controllers/templates_controller_spec.rb 
b/src/spec/controllers/templates_controller_spec.rb
new file mode 100644
index 0000000..af4fb2c
--- /dev/null
+++ b/src/spec/controllers/templates_controller_spec.rb
@@ -0,0 +1,73 @@
+require 'spec_helper'
+
+describe TemplatesController do
+
+  fixtures :all
+  before(:each) do
+    @admin_permission = Factory :admin_permission
+    @admin = @admin_permission.user
+    @tuser = Factory :tuser
+    activate_authlogic
+  end
+
+  it "should allow a user with image_modify permission to create new 
image_descriptor" do
+     UserSession.create(@admin)
+     lambda do
+       post :new, :xml => { :name => 'fooimg', :platform => 'fedora' }, :next 
=> true
+     end.should change(ImageDescriptor, :count).by(1)
+     id = ImageDescriptor.find(:first, :order => 'created_at DESC').id
+     response.should redirect_to("http://test.host/templates/services/#{id}";)
+  end
+
+  it "should allow a user with image_modify permission to add service" do
+     UserSession.create(@admin)
+     img = ImageDescriptor.new(:xml => '')
+     lambda do
+       img.save!
+     end.should change(ImageDescriptor, :count).by(1)
+     post :services, :xml => { :xml => {:services => ['jboss']} }, :next => 
true, :id => img.id
+     response.should 
redirect_to("http://test.host/templates/software/#{img.id}";)
+  end
+
+  # FIXME: these two tests depends on jboss repository which defines 'JBoss 
Core
+  # Packages' groups (this repository is currently only internal), uncomment
+  # when repository is ready
+  #
+  #it "should allow a user with image_modify permission to add and remove a 
group" do
+  #   UserSession.create(@admin)
+  #   img = ImageDescriptor.new(:xml => '')
+  #   lambda do
+  #     img.save!
+  #   end.should change(ImageDescriptor, :count).by(1)
+  #   post :select_group, :id => img.id, :group => 'JBoss Core Packages'
+  #   response.should 
redirect_to("http://test.host/templates/software/#{img.id}";)
+  #   post :remove_group, :id => img.id, :group => 'JBoss Core Packages'
+  #   response.should 
redirect_to("http://test.host/templates/software/#{img.id}";)
+  #end
+
+  #it "should allow a user with image_modify permission to add a package" do
+  #   UserSession.create(@admin)
+  #   img = ImageDescriptor.new(:xml => '')
+  #   lambda do
+  #     img.save!
+  #     post :select_package, :id => img.id, :package => 'jboss-rails', :group 
=> 'JBoss Core Packages'
+  #   end.should change(ImageDescriptor, :count).by(1)
+  #   response.should 
redirect_to("http://test.host/templates/software/#{img.id}";)
+  #end
+
+  it "should allow a user with image_modify permission to build image 
descriptor" do
+     UserSession.create(@admin)
+     img = ImageDescriptor.new
+     lambda do
+       post :summary, :id => img.id, :targets => ['rhevm'], :build => true
+     end.should change(ImageDescriptorTarget, :count).by(1)
+  end
+
+  it "should deny access to new template ui without image modify permission" do
+    UserSession.create(@tuser)
+    %w(new services software summary).each do |tab|
+      get tab.intern
+      response.should_not render_template("new")
+    end
+  end
+end
diff --git a/src/spec/fixtures/privileges.yml b/src/spec/fixtures/privileges.yml
index d1f44ab..16723de 100644
--- a/src/spec/fixtures/privileges.yml
+++ b/src/spec/fixtures/privileges.yml
@@ -37,3 +37,7 @@ user_modify:
   name: user_modify
 user_view:
   name: user_view
+image_modify:
+  name: image_modify
+image_view:
+  name: image_view
diff --git a/src/spec/fixtures/roles.yml b/src/spec/fixtures/roles.yml
index 9a4c550..d3ed623 100644
--- a/src/spec/fixtures/roles.yml
+++ b/src/spec/fixtures/roles.yml
@@ -44,4 +44,4 @@ provider_creator:
 administrator:
   name: Administrator
   scope: BasePermissionObject
-  privileges: provider_modify, provider_view, account_modify, account_view, 
user_modify, user_view, set_perms, view_perms, pool_modify, pool_view, 
quota_modify, quota_view, stats_view, instance_modify, instance_control, 
instance_view
+  privileges: provider_modify, provider_view, account_modify, account_view, 
user_modify, user_view, set_perms, view_perms, pool_modify, pool_view, 
quota_modify, quota_view, stats_view, instance_modify, instance_control, 
instance_view, image_modify, image_view
diff --git a/src/spec/spec_helper.rb b/src/spec/spec_helper.rb
index 5181389..4a72e06 100644
--- a/src/spec/spec_helper.rb
+++ b/src/spec/spec_helper.rb
@@ -13,6 +13,9 @@ require 'authlogic/test_case'
 # in ./support/ and its subdirectories.
 
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each
 {|f| require f}
 
+# factories are not loaded automatically (at least with rspec 1.3.0 on Fedora 
13)
+Dir[File.expand_path(File.join(File.dirname(__FILE__),'factories','**','*.rb'))].each
 {|f| puts f;require f}
+
 Spec::Runner.configure do |config|
   # If you're not using ActiveRecord you should remove these
   # lines, delete config/database.yml and disable :active_record
-- 
1.7.0.1

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

Reply via email to