From: Imre Farkas <ifarkas(a)redhat.com>
---
src/app/models/provider_account.rb | 6 +++-
...0120802080255_fix_provider_accounts_priority.rb | 32 ++++++++++++++++++++++
src/spec/models/provider_account_spec.rb | 2 +-
3 files changed, 38 insertions(+), 2 deletions(-)
create mode 100644 src/db/migrate/20120802080255_fix_provider_accounts_priority.rb
diff --git a/src/app/models/provider_account.rb b/src/app/models/provider_account.rb
index 1e8d41c..136d365 100644
--- a/src/app/models/provider_account.rb
+++ b/src/app/models/provider_account.rb
@@ -71,7 +71,11 @@ class ProviderAccount < ActiveRecord::Base
validate :validate_presence_of_credentials
validate :validate_credentials
validate :validate_unique_username
- validates :priority, :numericality => { :only_integer => true,
:greater_than_or_equal_to => -2147483647, :less_than_or_equal_to => 2147483647},
:allow_blank => true
+ validates :priority,
+ :numericality => { :only_integer => true,
+ :greater_than_or_equal_to => -100,
+ :less_than_or_equal_to => 100 },
+ :allow_blank => true
before_create :populate_profiles_and_validate
after_create :populate_realms_and_validate
diff --git a/src/db/migrate/20120802080255_fix_provider_accounts_priority.rb
b/src/db/migrate/20120802080255_fix_provider_accounts_priority.rb
new file mode 100644
index 0000000..7cac374
--- /dev/null
+++ b/src/db/migrate/20120802080255_fix_provider_accounts_priority.rb
@@ -0,0 +1,32 @@
+#
+# Copyright 2012 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.
+#
+
+class FixProviderAccountsPriority < ActiveRecord::Migration
+ def self.up
+ ProviderAccount.find_each do |provider_account|
+ if provider_account.priority.present?
+ if provider_account.priority > 100
+ provider_account.update_attributes(:priority => 100)
+ elsif provider_account.priority < -100
+ provider_account.update_attributes(:priority => -100)
+ end
+ end
+ end
+ end
+
+ def self.down
+ end
+end
diff --git a/src/spec/models/provider_account_spec.rb
b/src/spec/models/provider_account_spec.rb
index 5e212b8..756e10f 100644
--- a/src/spec/models/provider_account_spec.rb
+++ b/src/spec/models/provider_account_spec.rb
@@ -187,7 +187,7 @@ describe ProviderAccount do
end
it "can be negative integer" do
- @provider_account.priority = -32767
+ @provider_account.priority = -32
@provider_account.should be_valid
end
--
1.7.11.2