diff options
8 files changed, 162 insertions, 0 deletions
diff --git a/vendor/plugins/active_record_base_without_table/CHANGELOG b/vendor/plugins/active_record_base_without_table/CHANGELOG new file mode 100644 index 000000000..c74809532 --- /dev/null +++ b/vendor/plugins/active_record_base_without_table/CHANGELOG @@ -0,0 +1,3 @@ +[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 new file mode 100644 index 000000000..602bda208 --- /dev/null +++ b/vendor/plugins/active_record_base_without_table/MIT-LICENSE @@ -0,0 +1,20 @@ +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 new file mode 100644 index 000000000..8200d7ad6 --- /dev/null +++ b/vendor/plugins/active_record_base_without_table/README @@ -0,0 +1,29 @@ += 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 new file mode 100644 index 000000000..ac9244515 --- /dev/null +++ b/vendor/plugins/active_record_base_without_table/Rakefile @@ -0,0 +1,22 @@ +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 new file mode 100644 index 000000000..12cb05e02 --- /dev/null +++ b/vendor/plugins/active_record_base_without_table/lib/active_record/base_without_table.rb @@ -0,0 +1,26 @@ +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)
+ 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 new file mode 100644 index 000000000..f72a8785b --- /dev/null +++ b/vendor/plugins/active_record_base_without_table/test/abstract_unit.rb @@ -0,0 +1,15 @@ +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 new file mode 100644 index 000000000..8d4bd4115 --- /dev/null +++ b/vendor/plugins/active_record_base_without_table/test/active_record_base_without_table_test.rb @@ -0,0 +1,41 @@ +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 new file mode 100644 index 000000000..b952dac55 --- /dev/null +++ b/vendor/plugins/active_record_base_without_table/test/database.yml @@ -0,0 +1,6 @@ +mysql:
+ :adapter: mysql
+ :host: localhost
+ :username: rails
+ :password:
+ :database: rails_plugin_test
|