aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/about_me_validator.rb12
-rw-r--r--app/models/change_email_validator.rb21
-rw-r--r--app/models/contact_validator.rb15
-rw-r--r--vendor/plugins/active_record_base_without_table/CHANGELOG3
-rw-r--r--vendor/plugins/active_record_base_without_table/MIT-LICENSE20
-rw-r--r--vendor/plugins/active_record_base_without_table/README29
-rw-r--r--vendor/plugins/active_record_base_without_table/Rakefile22
-rw-r--r--vendor/plugins/active_record_base_without_table/lib/active_record/base_without_table.rb27
-rw-r--r--vendor/plugins/active_record_base_without_table/test/abstract_unit.rb15
-rw-r--r--vendor/plugins/active_record_base_without_table/test/active_record_base_without_table_test.rb41
-rw-r--r--vendor/plugins/active_record_base_without_table/test/database.yml6
11 files changed, 29 insertions, 182 deletions
diff --git a/app/models/about_me_validator.rb b/app/models/about_me_validator.rb
index 8ee505ac8..1bef11aed 100644
--- a/app/models/about_me_validator.rb
+++ b/app/models/about_me_validator.rb
@@ -12,14 +12,20 @@
# Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
-class AboutMeValidator < ActiveRecord::BaseWithoutTable
- strip_attributes!
+class AboutMeValidator
+ include ActiveModel::Validations
- column :about_me, :text, "I...", false
+ attr_accessor :about_me
# TODO: Switch to built in validations
validate :length_of_about_me
+ def initialize(attributes = {})
+ attributes.each do |name, value|
+ send("#{name}=", value)
+ end
+ end
+
private
def length_of_about_me
diff --git a/app/models/change_email_validator.rb b/app/models/change_email_validator.rb
index 37eb3c176..515683536 100644
--- a/app/models/change_email_validator.rb
+++ b/app/models/change_email_validator.rb
@@ -15,22 +15,24 @@
# Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
-class ChangeEmailValidator < ActiveRecord::BaseWithoutTable
- strip_attributes!
+class ChangeEmailValidator
+ include ActiveModel::Validations
- column :old_email, :string
- column :new_email, :string
- column :password, :string
- column :user_circumstance, :string
-
- attr_accessor :logged_in_user
+ attr_accessor :old_email, :new_email, :password, :user_circumstance, :logged_in_user
validates_presence_of :old_email, :message => N_("Please enter your old email address")
validates_presence_of :new_email, :message => N_("Please enter your new email address")
validates_presence_of :password, :message => N_("Please enter your password"), :unless => :changing_email
validate :password_and_format_of_email
- def changing_email()
+ def initialize(attributes = {})
+ attributes.each do |name, value|
+ send("#{name}=", value)
+ end
+ end
+
+
+ def changing_email
self.user_circumstance == 'change_email'
end
@@ -55,5 +57,4 @@ class ChangeEmailValidator < ActiveRecord::BaseWithoutTable
errors.add(:new_email, _("New email doesn't look like a valid address"))
end
end
-
end
diff --git a/app/models/contact_validator.rb b/app/models/contact_validator.rb
index 830ba3019..d01f186a3 100644
--- a/app/models/contact_validator.rb
+++ b/app/models/contact_validator.rb
@@ -15,13 +15,10 @@
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
-class ContactValidator < ActiveRecord::BaseWithoutTable
- strip_attributes!
+class ContactValidator
+ include ActiveModel::Validations
- column :name, :string
- column :email, :string
- column :subject, :text
- column :message, :text
+ attr_accessor :name, :email, :subject, :message
validates_presence_of :name, :message => N_("Please enter your name")
validates_presence_of :email, :message => N_("Please enter your email address")
@@ -29,6 +26,12 @@ class ContactValidator < ActiveRecord::BaseWithoutTable
validates_presence_of :message, :message => N_("Please enter the message you want to send")
validate :email_format
+ def initialize(attributes = {})
+ attributes.each do |name, value|
+ send("#{name}=", value)
+ end
+ end
+
private
def email_format
diff --git a/vendor/plugins/active_record_base_without_table/CHANGELOG b/vendor/plugins/active_record_base_without_table/CHANGELOG
deleted file mode 100644
index c74809532..000000000
--- a/vendor/plugins/active_record_base_without_table/CHANGELOG
+++ /dev/null
@@ -1,3 +0,0 @@
-[27 April 2007]
-
-* Correctly cache class instance variables containing column information [Reported by Nils Jonsson]
diff --git a/vendor/plugins/active_record_base_without_table/MIT-LICENSE b/vendor/plugins/active_record_base_without_table/MIT-LICENSE
deleted file mode 100644
index 602bda208..000000000
--- a/vendor/plugins/active_record_base_without_table/MIT-LICENSE
+++ /dev/null
@@ -1,20 +0,0 @@
-Copyright (c) 2006 Jonathan Viney
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/vendor/plugins/active_record_base_without_table/README b/vendor/plugins/active_record_base_without_table/README
deleted file mode 100644
index 8200d7ad6..000000000
--- a/vendor/plugins/active_record_base_without_table/README
+++ /dev/null
@@ -1,29 +0,0 @@
-= ActiveRecordBaseWithoutTable
-
-If you find this plugin useful, please consider a donation to show your support!
-
- http://www.paypal.com/cgi-bin/webscr?cmd=_send-money
-
- Email address: jonathan.viney@gmail.com
-
-== Instructions
-
-* For edge Rails r7315 or above use http://svn.viney.net.nz/things/branches/active_record_base_without_table
-
-Get the power of ActiveRecord models, including validation, without having a table in the database.
-
- class Contact < ActiveRecord::BaseWithoutTable
- column :name, :string
- column :email_address, :string
- column :message, :text
-
- validates_presence_of :name, :email_address, :string
- end
-
-This model can be used just like a regular model based on a table, except it will never be saved to the database.
-
-There is a good blog post available on the plugin:
-
- http://www.kangarooit.com/developer_blog/2007/02/email-form-validation-in-ruby-on-rails.php
-
-Any bugs, questions, comments please feel free to email me: jonathan.viney@gmail.com
diff --git a/vendor/plugins/active_record_base_without_table/Rakefile b/vendor/plugins/active_record_base_without_table/Rakefile
deleted file mode 100644
index ac9244515..000000000
--- a/vendor/plugins/active_record_base_without_table/Rakefile
+++ /dev/null
@@ -1,22 +0,0 @@
-require 'rake'
-require 'rake/testtask'
-require 'rake/rdoctask'
-
-desc 'Default: run unit tests.'
-task :default => :test
-
-desc 'Test the active_record_base_without_table plugin.'
-Rake::TestTask.new(:test) do |t|
- t.libs << 'lib'
- t.pattern = 'test/**/*_test.rb'
- t.verbose = true
-end
-
-desc 'Generate documentation for the active_record_base_without_table plugin.'
-Rake::RDocTask.new(:rdoc) do |rdoc|
- rdoc.rdoc_dir = 'rdoc'
- rdoc.title = 'ActiveRecordBaseWithoutTable'
- rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README')
- rdoc.rdoc_files.include('lib/**/*.rb')
-end
diff --git a/vendor/plugins/active_record_base_without_table/lib/active_record/base_without_table.rb b/vendor/plugins/active_record_base_without_table/lib/active_record/base_without_table.rb
deleted file mode 100644
index 14e9f935d..000000000
--- a/vendor/plugins/active_record_base_without_table/lib/active_record/base_without_table.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-module ActiveRecord
- class BaseWithoutTable < Base
- self.abstract_class = true
-
- def create_or_update
- errors.empty?
- end
-
- class << self
- def columns()
- @columns ||= []
- end
-
- def column(name, sql_type = nil, default = nil, null = true)
- columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
- # FIXME: Disabled temporarily during Rails 3 upgrade
- # reset_column_information
- end
-
- # Do not reset @columns
- def reset_column_information
- generated_methods.each { |name| undef_method(name) }
- @column_names = @columns_hash = @content_columns = @dynamic_methods_hash = @read_methods = nil
- end
- end
- end
-end
diff --git a/vendor/plugins/active_record_base_without_table/test/abstract_unit.rb b/vendor/plugins/active_record_base_without_table/test/abstract_unit.rb
deleted file mode 100644
index f72a8785b..000000000
--- a/vendor/plugins/active_record_base_without_table/test/abstract_unit.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require 'test/unit'
-
-begin
- require File.dirname(__FILE__) + '/../../../../config/boot'
- require 'active_record'
-rescue LoadError
- require 'rubygems'
- require_gem 'activerecord'
-end
-
-require File.dirname(__FILE__) + '/../lib/active_record/base_without_table'
-
-config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
-ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/debug.log')
-ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'mysql'])
diff --git a/vendor/plugins/active_record_base_without_table/test/active_record_base_without_table_test.rb b/vendor/plugins/active_record_base_without_table/test/active_record_base_without_table_test.rb
deleted file mode 100644
index 8d4bd4115..000000000
--- a/vendor/plugins/active_record_base_without_table/test/active_record_base_without_table_test.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-require File.dirname(__FILE__) + '/abstract_unit'
-
-class Person < ActiveRecord::BaseWithoutTable
- column :name, :string
- column :lucky_number, :integer, 4
-
- validates_presence_of :name
-end
-
-class ActiveRecordBaseWithoutTableTest < Test::Unit::TestCase
- def test_default_value
- assert_equal 4, Person.new.lucky_number
- end
-
- def test_validation
- p = Person.new
-
- assert !p.save
- assert p.errors[:name]
-
- assert p.update_attributes(:name => 'Name')
- end
-
- def test_typecast
- assert_equal 1, Person.new(:lucky_number => "1").lucky_number
- end
-
- def test_cached_column_variables_reset_when_column_defined
- cached_variables = %w(column_names columns_hash content_columns dynamic_methods_hash read_methods)
-
- Person.column_names
- Person.columns_hash
- Person.content_columns
- Person.column_methods_hash
- Person.read_methods
-
- cached_variables.each { |v| assert_not_nil Person.instance_variable_get("@#{v}") }
- Person.column :new_column, :string
- cached_variables.each { |v| assert_nil Person.instance_variable_get("@#{v}") }
- end
-end
diff --git a/vendor/plugins/active_record_base_without_table/test/database.yml b/vendor/plugins/active_record_base_without_table/test/database.yml
deleted file mode 100644
index b952dac55..000000000
--- a/vendor/plugins/active_record_base_without_table/test/database.yml
+++ /dev/null
@@ -1,6 +0,0 @@
-mysql:
- :adapter: mysql
- :host: localhost
- :username: rails
- :password:
- :database: rails_plugin_test