diff --git a/app/controllers/my_profile/enterprise_validation_controller.rb b/app/controllers/my_profile/enterprise_validation_controller.rb
index c34a6d0..7375ec0 100644
--- a/app/controllers/my_profile/enterprise_validation_controller.rb
+++ b/app/controllers/my_profile/enterprise_validation_controller.rb
@@ -1,7 +1,7 @@
class EnterpriseValidationController < MyProfileController
protect 'validate_enterprise', :profile
-
+
def index
@pending_validations = profile.pending_validations
end
@@ -27,7 +27,7 @@ class EnterpriseValidationController < MyProfileController
post_only :reject
def reject
@pending = profile.find_pending_validation(params[:id])
- if @pending
+ if @pending
@pending.reject_explanation = params[:reject_explanation]
begin
@pending.reject
diff --git a/app/models/validation_info.rb b/app/models/validation_info.rb
index 7945d7c..06ab25a 100644
--- a/app/models/validation_info.rb
+++ b/app/models/validation_info.rb
@@ -2,9 +2,10 @@ class ValidationInfo < ActiveRecord::Base
attr_accessible :validation_methodology, :restrictions, :organization
- validates_presence_of :validation_methodology
-
belongs_to :organization
+ validates_presence_of :organization
+ validates_presence_of :validation_methodology
+
xss_terminate :only => [ :validation_methodology, :restrictions ], :on => 'validation'
end
diff --git a/test/functional/enterprise_validation_controller_test.rb b/test/functional/enterprise_validation_controller_test.rb
index d43758d..65a7808 100644
--- a/test/functional/enterprise_validation_controller_test.rb
+++ b/test/functional/enterprise_validation_controller_test.rb
@@ -12,126 +12,109 @@ class EnterpriseValidationControllerTest < ActionController::TestCase
@controller = EnterpriseValidationController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
-
+
login_as 'ze'
- @org = Organization.create!(:identifier => 'myorg', :name => "My Org")
+ @user = Profile['ze']
+ @org = Organization.create!(identifier: 'myorg', name: "My Org")
give_permission('ze', 'validate_enterprise', @org)
- Profile.expects(:find_by_identifier).with('myorg').returns(@org).at_least_once
end
should 'list pending validations on index' do
- empty = []
- @org.expects(:pending_validations).returns(empty)
- get :index, :profile => 'myorg'
- assert_equal empty, assigns(:pending_validations)
+ get :index, profile: 'myorg'
+ assert_equal [], assigns(:pending_validations)
assert_template 'index'
end
should 'display details and prompt for needed data when approving or rejecting enterprise' do
- validating = CreateEnterprise.new
- @org.expects(:find_pending_validation).with('kakakaka').returns(validating)
-
- get :details, :profile => 'myorg', :id => 'kakakaka'
- assert_same validating, assigns(:pending)
+ code = 'kakakaka'
+ @org.validations.create! code: code, name: 'test', identifier: 'test', requestor: @user, target: @org
+ get :details, profile: 'myorg', id: code
+ assert_equal @org.find_pending_validation(code), assigns(:pending)
end
should 'refuse to validate unexisting request' do
- @org.expects(:find_pending_validation).with('kakakaka').returns(nil)
- get :details , :profile => 'myorg', :id => 'kakakaka'
+ get :details, profile: 'myorg', id: 'kakakaka'
assert_response 404
end
should 'be able to actually validate enterprise on request' do
- validation = CreateEnterprise.new
- @org.expects(:find_pending_validation).with('kakakaka').returns(validation)
- validation.expects(:approve)
- validation.expects(:code).returns('kakakaka')
- post :approve, :profile => 'myorg', :id => 'kakakaka'
- assert_redirected_to :action => 'view_processed', :id => 'kakakaka'
+ code = 'kakakaka'
+ @org.validations.create! code: code, name: 'test2', identifier: 'test2', requestor: @user, target: @org
+ post :approve, profile: 'myorg', id: code
+ assert_redirected_to action: 'view_processed', id: code
end
should 'be able to reject an enterprise' do
- validation = CreateEnterprise.new
- @org.expects(:find_pending_validation).with('kakakaka').returns(validation)
- validation.expects(:reject)
- validation.expects(:code).returns('kakakaka')
- post :reject, :profile => 'myorg', :id => 'kakakaka', :reject_explanation => 'this is not a solidarity economy enterprise'
- assert_redirected_to :action => 'view_processed', :id => 'kakakaka'
+ code = 'kakakaka'
+ @org.validations.create! code: code, name: 'test2', identifier: 'test2', requestor: @user, target: @org
+ post :reject, profile: 'myorg', id: code, reject_explanation: 'this is not a solidarity economy enterprise'
+ assert_redirected_to action: 'view_processed', id: code
end
should 'require the user to fill in the explanation for an rejection' do
- validation = CreateEnterprise.new
- validation.stubs(:environment).returns(Environment.default)
- @org.expects(:find_pending_validation).with('kakakaka').returns(validation)
-
- # FIXME: this is not working, but should. Anyway the assert_response and
- # assert_template below in some test some things we need. But the
- # expectation below must be put to work.
- #
- #validation.expects(:reject).raises(ActiveRecord::RecordInvalid)
+ code = 'kakakaka'
+ @org.validations.create! code: code, name: 'test2', identifier: 'test2', requestor: @user, target: @org
- post :reject, :profile => 'myorg', :id => 'kakakaka'
+ post :reject, profile: 'myorg', id: code
assert_response :success
assert_template 'details'
end
should 'list validations already processed' do
- processed_validations = [CreateEnterprise.new]
- @org.expects(:processed_validations).returns(processed_validations)
-
- get :list_processed, :profile => 'myorg'
+ v = @org.validations.create! code: 'kakakaka', name: 'test2', identifier: 'test2', requestor: @user, target: @org
+ v.perform
- assert_equal processed_validations, assigns(:processed_validations)
+ get :list_processed, profile: 'myorg'
+
+ assert_equal @org.processed_validations, assigns(:processed_validations)
assert_response :success
assert_template 'list_processed'
end
-
+
should 'be able to display a validation that was already processed' do
- validation = CreateEnterprise.new
- @org.expects(:find_processed_validation).with('kakakaka').returns(validation)
- get :view_processed, :profile => 'myorg', :id => 'kakakaka'
- assert_same validation, assigns(:processed)
+ code = 'kakakaka'
+ v = @org.validations.create! code: code, name: 'test2', identifier: 'test2', requestor: @user, target: @org
+ v.perform
+
+ get :view_processed, profile: 'myorg', id: code
+ assert_same @org.processed_validations.first, assigns(:processed)
end
should 'display a form for editing the validation info' do
- info = ValidationInfo.new(:validation_methodology => 'none')
- @org.expects(:validation_info).returns(info)
- get :edit_validation_info, :profile => 'myorg'
+ info = @org.validation_info = ValidationInfo.create! validation_methodology: 'none', organization: @org
+ get :edit_validation_info, profile: 'myorg'
assert_response :success
assert_equal info, assigns(:info)
end
should 'save an alteration of the validation info' do
- info = ValidationInfo.new(:validation_methodology => 'none')
- @org.expects(:validation_info).returns(info)
- post :edit_validation_info, :profile => 'myorg', :info => {:validation_methodology => 'new methodology'}
-
+ info = @org.validation_info = ValidationInfo.create! validation_methodology: 'none', organization: @org
+ post :edit_validation_info, profile: 'myorg', info: {validation_methodology: 'new methodology'}
+
assert_response :redirect
- assert_redirected_to :action => 'index'
- assert_equal info, assigns(:info)
+ assert_redirected_to action: 'index'
+ info.reload
+ assert_equal info.reload, assigns(:info)
end
should 'not save an empaty validation mthodology' do
- info = ValidationInfo.new(:validation_methodology => 'none')
- @org.expects(:validation_info).returns(info)
- post :edit_validation_info, :profile => 'myorg', :info => {:validation_methodology => ''}
-
+ info = @org.validation_info = ValidationInfo.create! validation_methodology: 'none', organization: @org
+ post :edit_validation_info, profile: 'myorg', info: {validation_methodology: ''}
+
assert_response :success
assert_equal info, assigns(:info)
end
should 'filter html from methodology of the validation info' do
- info = ValidationInfo.new(:validation_methodology => 'none')
- @org.expects(:validation_info).returns(info)
- post :edit_validation_info, :profile => 'myorg', :info => {:validation_methodology => 'new methodology'}
+ @org.validation_info = ValidationInfo.create! validation_methodology: 'none', organization: @org
+ post :edit_validation_info, profile: 'myorg', info: {validation_methodology: 'new methodology'}
assert_sanitized assigns(:info).validation_methodology
end
should 'filter html from restrictions of the validation info' do
- info = ValidationInfo.new(:validation_methodology => 'none')
- @org.expects(:validation_info).returns(info)
- post :edit_validation_info, :profile => 'myorg', :info => {:restrictions => 'new methodology'}
+ @org.validation_info = ValidationInfo.create! validation_methodology: 'none', organization: @org
+ post :edit_validation_info, profile: 'myorg', info: {restrictions: 'new methodology'}
assert_sanitized assigns(:info).restrictions
end
diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb
index f32f3fa..e12749b 100644
--- a/test/integration/routing_test.rb
+++ b/test/integration/routing_test.rb
@@ -27,6 +27,10 @@ class RoutingTest < ActionController::IntegrationTest
assert_routing('/account/new_password/90dfhga7sadgd0as6saas', :controller => 'account', :action => 'new_password', :code => '90dfhga7sadgd0as6saas')
end
+ should 'ignore case for profiles' do
+ assert_routing '/myprofile/ZE/cms', profile: 'ZE', controller: 'cms', action: 'index'
+ end
+
def test_cms
assert_routing('/myprofile/ze/cms', :profile => 'ze', :controller => 'cms', :action => 'index')
end
--
libgit2 0.21.2