Initial commit of making ar-extensions import Rails 3 friendly
This commit is contained in:
commit
ca5f83e1cf
10 changed files with 701 additions and 0 deletions
28
test/database.yml
Normal file
28
test/database.yml
Normal file
|
@ -0,0 +1,28 @@
|
|||
common: &common
|
||||
username: root
|
||||
password:
|
||||
encoding: utf8
|
||||
host: localhost
|
||||
database: aroptests
|
||||
|
||||
mysql:
|
||||
<<: *common
|
||||
adapter: mysql
|
||||
|
||||
postgres:
|
||||
<<: *common
|
||||
adapter: postgres
|
||||
min_messages: warning
|
||||
|
||||
oracle:
|
||||
<<: *common
|
||||
adapter: oracle
|
||||
min_messages: debug
|
||||
|
||||
sqlite:
|
||||
adapter: sqlite
|
||||
dbfile: test.db
|
||||
|
||||
sqlite3:
|
||||
adapter: sqlite3
|
||||
database: test.db
|
28
test/database.yml.sample
Normal file
28
test/database.yml.sample
Normal file
|
@ -0,0 +1,28 @@
|
|||
common: &common
|
||||
username: myuser
|
||||
password: password
|
||||
encoding: utf8
|
||||
host: localhost
|
||||
database: aroptests
|
||||
|
||||
mysql:
|
||||
<<: *common
|
||||
adapter: mysql
|
||||
|
||||
postgres:
|
||||
<<: *common
|
||||
adapter: postgres
|
||||
min_messages: warning
|
||||
|
||||
oracle:
|
||||
<<: *common
|
||||
adapter: oracle
|
||||
min_messages: debug
|
||||
|
||||
sqlite:
|
||||
adapter: sqlite
|
||||
dbfile: test.db
|
||||
|
||||
sqlite3:
|
||||
adapter: sqlite3
|
||||
dbfile: test.db
|
114
test/import_test.rb
Normal file
114
test/import_test.rb
Normal file
|
@ -0,0 +1,114 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
||||
|
||||
describe "#import" do
|
||||
context "with :validation option" do
|
||||
let(:columns) { %w(title author_name) }
|
||||
let(:valid_values) { [[ "LDAP", "Jerry Carter"], ["Rails Recipes", "Chad Fowler"]] }
|
||||
let(:invalid_values) { [[ "The RSpec Book", ""], ["Agile+UX", ""]] }
|
||||
|
||||
context "with validation checks turned off" do
|
||||
it "should import valid data" do
|
||||
assert_difference "Topic.count", +2 do
|
||||
Topic.import columns, valid_values, :validate => false
|
||||
end
|
||||
end
|
||||
|
||||
it "should import invalid data" do
|
||||
assert_difference "Topic.count", +2 do
|
||||
Topic.import columns, invalid_values, :validate => false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with validation checks turned on" do
|
||||
it "should import valid data" do
|
||||
assert_difference "Topic.count", +2 do
|
||||
Topic.import columns, valid_values, :validate => true
|
||||
end
|
||||
end
|
||||
|
||||
it "should not import invalid data" do
|
||||
assert_no_difference "Topic.count" do
|
||||
Topic.import columns, invalid_values, :validate => true
|
||||
end
|
||||
end
|
||||
|
||||
it "should import valid data when mixed with invalid data" do
|
||||
assert_difference "Topic.count", +2 do
|
||||
Topic.import columns, valid_values + invalid_values, :validate => true
|
||||
end
|
||||
assert_equal 0, Topic.find_all_by_title(invalid_values.map(&:first)).count
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
#
|
||||
# context "with an array of model instances" do
|
||||
# it "should import attributes from those model instances"
|
||||
#
|
||||
# it "should import unsaved model instances"
|
||||
# end
|
||||
#
|
||||
# context "ActiveRecord model niceties" do
|
||||
# context "created_on columns" do
|
||||
# it "should set the created_on column"
|
||||
#
|
||||
# it "should set the created_on column respecting the time zone"
|
||||
# end
|
||||
#
|
||||
# context "created_at columns" do
|
||||
# it "should set the created_at column"
|
||||
#
|
||||
# it "should set the created_at column respecting the time zone"
|
||||
# end
|
||||
#
|
||||
# context "updated_on columns" do
|
||||
# it "should set the updated_on column"
|
||||
#
|
||||
# it "should set the updated_on column respecting the time zone"
|
||||
# end
|
||||
#
|
||||
# context "updated_at columns" do
|
||||
# it "should set the updated_at column"
|
||||
#
|
||||
# it "should set the updated_at column respecting the time zone"
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# context "importing over existing records" do
|
||||
# it "should not add duplicate records"
|
||||
#
|
||||
# it "should not overwrite existing records"
|
||||
# end
|
||||
#
|
||||
# it "should import models with attribute fields that are database reserved words"
|
||||
#
|
||||
# it "should return the number of inserts performed"
|
||||
# end
|
||||
#
|
||||
# describe "computing insert value sets" do
|
||||
# context "when the max allowed bytes is 33 and the base SQL is 26 bytes" do
|
||||
# it "should return 3 value sets when given 3 value sets of 7 bytes a piece"
|
||||
# end
|
||||
#
|
||||
# context "when the max allowed bytes is 40 and the base SQL is 26 bytes" do
|
||||
# it "should return 3 value sets when given 3 value sets of 7 bytes a piece"
|
||||
# end
|
||||
#
|
||||
# context "when the max allowed bytes is 41 and the base SQL is 26 bytes" do
|
||||
# it "should return 3 value sets when given 2 value sets of 7 bytes a piece"
|
||||
# end
|
||||
#
|
||||
# context "when the max allowed bytes is 48 and the base SQL is 26 bytes" do
|
||||
# it "should return 3 value sets when given 2 value sets of 7 bytes a piece"
|
||||
# end
|
||||
#
|
||||
# context "when the max allowed bytes is 49 and the base SQL is 26 bytes" do
|
||||
# it "should return 3 value sets when given 1 value sets of 7 bytes a piece"
|
||||
# end
|
||||
#
|
||||
# context "when the max allowed bytes is 999999 and the base SQL is 26 bytes" do
|
||||
# it "should return 3 value sets when given 1 value sets of 7 bytes a piece"
|
||||
# end
|
||||
# end
|
||||
# end
|
6
test/models/topic.rb
Normal file
6
test/models/topic.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
class Topic < ActiveRecord::Base
|
||||
validates_presence_of :author_name
|
||||
has_many :books
|
||||
|
||||
composed_of :description, :mapping => [ %w(title title), %w(author_name author_name)], :allow_nil => true, :class_name => "TopicDescription"
|
||||
end
|
96
test/schema/generic_schema.rb
Normal file
96
test/schema/generic_schema.rb
Normal file
|
@ -0,0 +1,96 @@
|
|||
ActiveRecord::Schema.define do
|
||||
|
||||
create_table :schema_info, :force=>true do |t|
|
||||
t.column :version, :integer, :unique=>true
|
||||
end
|
||||
SchemaInfo.create :version=>SchemaInfo::VERSION
|
||||
|
||||
create_table :group, :force => true do |t|
|
||||
t.column :order, :string
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :topics, :force=>true do |t|
|
||||
t.column :title, :string, :null=>false
|
||||
t.column :author_name, :string
|
||||
t.column :author_email_address, :string
|
||||
t.column :written_on, :datetime
|
||||
t.column :bonus_time, :time
|
||||
t.column :last_read, :datetime
|
||||
t.column :content, :text
|
||||
t.column :approved, :boolean, :default=>'1'
|
||||
t.column :replies_count, :integer
|
||||
t.column :parent_id, :integer
|
||||
t.column :type, :string
|
||||
t.column :created_at, :datetime
|
||||
t.column :updated_at, :datetime
|
||||
end
|
||||
|
||||
create_table :projects, :force=>true do |t|
|
||||
t.column :name, :string
|
||||
t.column :type, :string
|
||||
end
|
||||
|
||||
create_table :developers, :force=>true do |t|
|
||||
t.column :name, :string
|
||||
t.column :salary, :integer, :default=>'70000'
|
||||
t.column :created_at, :datetime
|
||||
t.column :team_id, :integer
|
||||
t.column :updated_at, :datetime
|
||||
end
|
||||
|
||||
create_table :addresses, :force=>true do |t|
|
||||
t.column :address, :string
|
||||
t.column :city, :string
|
||||
t.column :state, :string
|
||||
t.column :zip, :string
|
||||
t.column :developer_id, :integer
|
||||
end
|
||||
|
||||
create_table :teams, :force=>true do |t|
|
||||
t.column :name, :string
|
||||
end
|
||||
|
||||
create_table :books, :force=>true do |t|
|
||||
t.column :title, :string, :null=>false
|
||||
t.column :publisher, :string, :null=>false, :default => 'Default Publisher'
|
||||
t.column :author_name, :string, :null=>false
|
||||
t.column :created_at, :datetime
|
||||
t.column :created_on, :datetime
|
||||
t.column :updated_at, :datetime
|
||||
t.column :updated_on, :datetime
|
||||
t.column :publish_date, :date
|
||||
t.column :topic_id, :integer
|
||||
t.column :for_sale, :boolean, :default => true
|
||||
end
|
||||
|
||||
create_table :languages, :force=>true do |t|
|
||||
t.column :name, :string
|
||||
t.column :developer_id, :integer
|
||||
end
|
||||
|
||||
create_table :shopping_carts, :force=>true do |t|
|
||||
t.column :name, :string, :null => true
|
||||
t.column :created_at, :datetime
|
||||
t.column :updated_at, :datetime
|
||||
end
|
||||
|
||||
create_table :cart_items, :force => true do |t|
|
||||
t.column :shopping_cart_id, :string, :null => false
|
||||
t.column :book_id, :string, :null => false
|
||||
t.column :copies, :integer, :default => 1
|
||||
t.column :created_at, :datetime
|
||||
t.column :updated_at, :datetime
|
||||
end
|
||||
|
||||
add_index :cart_items, [:shopping_cart_id, :book_id], :unique => true, :name => 'uk_shopping_cart_books'
|
||||
|
||||
create_table :animals, :force => true do |t|
|
||||
t.column :name, :string, :null => false
|
||||
t.column :size, :string, :default => nil
|
||||
t.column :created_at, :datetime
|
||||
t.column :updated_at, :datetime
|
||||
end
|
||||
|
||||
add_index :animals, [:name], :unique => true, :name => 'uk_animals'
|
||||
end
|
4
test/schema/version.rb
Normal file
4
test/schema/version.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
class SchemaInfo < ActiveRecord::Base
|
||||
set_table_name 'schema_info'
|
||||
VERSION = 12
|
||||
end
|
63
test/test_helper.rb
Normal file
63
test/test_helper.rb
Normal file
|
@ -0,0 +1,63 @@
|
|||
ENV["RAILS_ENV"] = "test"
|
||||
require 'pathname'
|
||||
|
||||
this_dir = Pathname.new File.dirname(__FILE__)
|
||||
$LOAD_PATH << this_dir.join("../lib")
|
||||
|
||||
gem "rails", "3.0.0.beta"
|
||||
require "rails"
|
||||
require "rails/test_help"
|
||||
require "active_record/fixtures"
|
||||
|
||||
require "ar-extensions"
|
||||
require "logger"
|
||||
|
||||
require "ruby-debug"
|
||||
|
||||
class ActiveSupport::TestCase
|
||||
include ActiveRecord::TestFixtures
|
||||
self.use_transactional_fixtures = true
|
||||
|
||||
class << self
|
||||
def describe(description, toplevel=nil, &blk)
|
||||
text = toplevel ? description : "#{name} #{description}"
|
||||
klass = Class.new(self)
|
||||
klass.class_eval <<-RUBY_EVAL
|
||||
def self.name
|
||||
"#{text}"
|
||||
end
|
||||
RUBY_EVAL
|
||||
klass.instance_eval &blk
|
||||
end
|
||||
alias_method :context, :describe
|
||||
|
||||
def let(name, &blk)
|
||||
define_method(name, &blk)
|
||||
end
|
||||
|
||||
def it(description, &blk)
|
||||
define_method("test: #{name} #{description}", &blk)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def describe(description, &blk)
|
||||
ActiveSupport::TestCase.describe(description, true, &blk)
|
||||
end
|
||||
|
||||
adapter = "sqlite3"
|
||||
|
||||
ActiveRecord::Base.logger = Logger.new("foo.log")
|
||||
ActiveRecord::Base.configurations["test"] = YAML.load(this_dir.join("database.yml").open)[adapter]
|
||||
ActiveRecord::Base.establish_connection "test"
|
||||
|
||||
# Load base/generic schema
|
||||
require this_dir.join("schema/version")
|
||||
require this_dir.join("schema/generic_schema")
|
||||
|
||||
# Load adapter specific schema if one exists
|
||||
adapter_schema = this_dir.join("schema/#{adapter}_schema")
|
||||
require adapter_schema if File.exists?(adapter_schema)
|
||||
|
||||
Dir[File.dirname(__FILE__) + "/models/*.rb"].each{ |file| require file }
|
Loading…
Add table
Add a link
Reference in a new issue