polymorphic_as_table 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Jeremiah Dodds <jeremiah.dodds@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,13 @@
1
+ PolymorphicAsTable
2
+ ==================
3
+
4
+ Introduction goes here.
5
+
6
+
7
+ Example
8
+ =======
9
+
10
+ Example goes here.
11
+
12
+
13
+ Copyright (c) 2011 [name of plugin creator], released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rdoc/task'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the polymorphic_as_table plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the polymorphic_as_table plugin.'
17
+ RDoc::Task.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'PolymorphicAsTable'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,67 @@
1
+ module PolymorphicAsTable
2
+ require 'polymorphic_as_table/association_proxy'
3
+ require 'polymorphic_as_table/belongs_to_association'
4
+ require 'polymorphic_as_table/has_many_association'
5
+ require 'polymorphic_as_table/has_one_association'
6
+ require 'polymorphic_as_table/through_reflection'
7
+ require 'polymorphic_as_table/through_association_scope'
8
+
9
+ module ClassMethods
10
+ def has_polymorphic_as_table
11
+ ActiveRecord::Associations::AssociationProxy.send(
12
+ :include, PolymorphicAsTable::AssociationProxy)
13
+ ActiveRecord::Associations::HasOneAssociation.send(
14
+ :include, PolymorphicAsTable::HasOneAssociation)
15
+ ActiveRecord::Associations::HasManyAssociation.send(
16
+ :include, PolymorphicAsTable::HasManyAssociation)
17
+ ActiveRecord::Associations::ThroughAssociationScope.send(
18
+ :include, PolymorphicAsTable::ThroughAssociationScope)
19
+ ActiveRecord::Reflection::ThroughReflection.send(
20
+ :include, PolymorphicAsTable::ThroughReflection)
21
+
22
+ class << self
23
+ def sti_name
24
+ table_name
25
+ end
26
+ end
27
+ end
28
+
29
+ def is_polymorphic_as_table
30
+ ActiveRecord::Associations::AssociationProxy.send(
31
+ :include, PolymorphicAsTable::AssociationProxy)
32
+ ActiveRecord::Associations::BelongsToPolymorphicAssociation.send(
33
+ :include, PolymorphicAsTable::BelongsToAssociation)
34
+
35
+ class << self
36
+ def define_attribute_methods
37
+ if super && @@association
38
+ define_method("#{@@association}_type=") do |value|
39
+ debugger
40
+ write_attribute("#{@@association}_type", value.tableize)
41
+ end
42
+
43
+ define_method("#{@@association}_type") do
44
+ read_attribute("#{@@association}_type").classify
45
+ end
46
+
47
+ define_method("#{@@association}=") do |association|
48
+ write_attribute("#{@@association}", association)
49
+ write_attribute("#{@@association}_type", association.class.to_s.tableize)
50
+ end
51
+ end
52
+ end
53
+
54
+ def belongs_to(association_id, options={})
55
+ @@association = association_id
56
+ super
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ def self.included(base)
63
+ base.extend(ClassMethods)
64
+ end
65
+ end
66
+
67
+ ActiveRecord::Base.send(:include, PolymorphicAsTable)
@@ -0,0 +1,19 @@
1
+ module PolymorphicAsTable
2
+ module AssociationProxy
3
+ def self.included(base)
4
+ base.class_eval do
5
+ def set_belongs_to_association_for(record)
6
+ if @reflection.options[:as]
7
+ record["#{@reflection.options[:as]}_id"] = @owner.id unless @owner.new_record?
8
+ record["#{@reflection.options[:as]}_type"] = @owner.class.base_class.table_name
9
+ else
10
+ unless @owner.new_record?
11
+ primary_key = @reflection.options[:primary_key] || :id
12
+ record[@reflection.primary_key_name] = @owner.send(primary_key)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ module PolymorphicAsTable
2
+ module BelongsToAssociation
3
+ def self.included(base)
4
+ base.class_eval do
5
+ def association_class
6
+ @owner[@reflection.options[:foreign_type]].present? ? @owner[@reflection.options[:foreign_type]].classify.constantize : nil
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,26 @@
1
+ module PolymorphicAsTable
2
+ module HasManyAssociation
3
+ def self.included(base)
4
+ base.class_eval do
5
+ def construct_sql
6
+ case
7
+ when @reflection.options[:finder_sql]
8
+ @finder_sql = interpolate_and_sanitize_sql(@reflection.options[:finder_sql])
9
+
10
+ when @reflection.options[:as]
11
+ @finder_sql =
12
+ "#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_id = #{owner_quoted_id} AND " +
13
+ "#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote_value(@owner.class.base_class.table_name)}"
14
+ @finder_sql << " AND (#{conditions})" if conditions
15
+
16
+ else
17
+ @finder_sql = "#{@reflection.quoted_table_name}.#{@reflection.primary_key_name} = #{owner_quoted_id}"
18
+ @finder_sql << " AND (#{conditions})" if conditions
19
+ end
20
+
21
+ construct_counter_sql
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ module PolymorphicAsTable
2
+ module HasOneAssociation
3
+ def self.included(base)
4
+ base.class_eval do
5
+ def find_target
6
+ options = @reflection.options.dup
7
+ (options.keys - [:select, :order, :include, :readonly]).each do |key|
8
+ options.delete key
9
+ end
10
+ options[:conditions] = @finder_sql
11
+
12
+ the_target = @reflection.klass.find(:first, options)
13
+ set_inverse_instance(the_target, @owner)
14
+ the_target
15
+ end
16
+ def construct_sql
17
+ case
18
+ when @reflection.options[:as]
19
+ @finder_sql =
20
+ "#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_id = #{owner_quoted_id} AND " +
21
+ "#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote_value(@owner.class.base_class.table_name)}"
22
+ else
23
+ @finder_sql = "#{@reflection.quoted_table_name}.#{@reflection.primary_key_name} = #{owner_quoted_id}"
24
+ end
25
+ @finder_sql << " AND (#{conditions})" if conditions
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,64 @@
1
+ module PolymorphicAsTable
2
+ module ThroughAssociationScope
3
+ def self.included(base)
4
+ base.class_eval do
5
+ def construct_owner_attributes(reflection)
6
+ if as = reflection.options[:as]
7
+ { "#{as}_id" => @owner.id,
8
+ "#{as}_type" => @owner.class.base_class.table_name }
9
+ else
10
+ { reflection.primary_key_name => @owner.id }
11
+ end
12
+ end
13
+
14
+ def construct_quoted_owner_attributes(reflection)
15
+ if as = reflection.options[:as]
16
+ { "#{as}_id" => @owner.class.quote_value(
17
+ @owner[reflection.active_record_primary_key],
18
+ reflection.klass.columns_hash["#{as}_id"]),
19
+ "#{as}_type" => reflection.klass.quote_value(
20
+ @owner.class.base_class.table_name.to_s,
21
+ reflection.klass.columns_hash["#{as}_type"]) }
22
+ elsif reflection.macro == :belongs_to
23
+ { reflection.klass.primary_key => @owner.class.quote_value(@owner[reflection.primary_key_name]) }
24
+ else
25
+ column = @owner.class.columns_hash[reflection.active_record_primary_key]
26
+
27
+ { reflection.primary_key_name => @owner.class.quote_value(@owner[reflection.active_record_primary_key], column) }
28
+ end
29
+ end
30
+ def construct_joins(custom_joins = nil)
31
+ polymorphic_join = nil
32
+ if @reflection.source_reflection.macro == :belongs_to
33
+ reflection_primary_key = @reflection.source_reflection.options[:primary_key] ||
34
+ @reflection.klass.primary_key
35
+ source_primary_key = @reflection.source_reflection.primary_key_name
36
+ if @reflection.options[:source_type]
37
+ polymorphic_join = "AND %s.%s = %s" % [
38
+ @reflection.through_reflection.quoted_table_name, "#{@reflection.source_reflection.options[:foreign_type]}",
39
+ @owner.class.quote_value(@reflection.options[:source_type])
40
+ ]
41
+ end
42
+ else
43
+ reflection_primary_key = @reflection.source_reflection.primary_key_name
44
+ source_primary_key = @reflection.source_reflection.options[:primary_key] ||
45
+ @reflection.through_reflection.klass.primary_key
46
+ if @reflection.source_reflection.options[:as]
47
+ polymorphic_join = "AND %s.%s = %s" % [
48
+ @reflection.quoted_table_name, "#{@reflection.source_reflection.options[:as]}_type",
49
+ @owner.class.quote_value(@reflection.through_reflection.klass.table_name)
50
+ ]
51
+ end
52
+ end
53
+
54
+ "INNER JOIN %s ON %s.%s = %s.%s %s #{@reflection.options[:joins]} #{custom_joins}" % [
55
+ @reflection.through_reflection.quoted_table_name,
56
+ @reflection.quoted_table_name, reflection_primary_key,
57
+ @reflection.through_reflection.quoted_table_name, source_primary_key,
58
+ polymorphic_join
59
+ ]
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,11 @@
1
+ module PolymorphicAsTable
2
+ module ThroughReflection
3
+ def self.included(base)
4
+ base.class_eval do
5
+ def klass
6
+ @klass ||= active_record.send(:compute_type, class_name.classify)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ PKG_FILES = Rake::FileList[
5
+ '[a-zA-Z]*',
6
+ 'generators/**/*',
7
+ 'lib/**/*',
8
+ 'rails/**/*',
9
+ 'tasks/**/*',
10
+ 'test/**/*'
11
+ ]
12
+
13
+ Gem::Specification.new do |s|
14
+ s.name = "polymorphic_as_table"
15
+ s.version = "0.5.0"
16
+ s.author = "Jeremiah Dodds"
17
+ s.email = "jeremiah.dodds@gmail.com"
18
+ s.homepage = "https://github.com/jdodds/polymorphic_as_table"
19
+ s.platform = Gem::Platform::RUBY
20
+ s.summary = "Allow for ActiveRecord polymorphic assocations that write their table name as their type"
21
+ s.files = PKG_FILES.to_a
22
+ s.require_path = "lib"
23
+ s.has_rdoc = false
24
+ s.extra_rdoc_files = ["README"]
25
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'active_record'
2
+ require 'active_record/associations'
3
+ require 'active_record/associations/through_association_scope'
4
+
5
+ require 'polymorphic_as_table'
data/test/database.yml ADDED
@@ -0,0 +1,18 @@
1
+ sqlite:
2
+ :adapter: sqlite
3
+ :database: vendor/plugins/polymorphic_as_table/test/polymorphic_as_table_plugin.sqlite.db
4
+ sqlite3:
5
+ :adapter: sqlite3
6
+ :database: vendor/plugins/polymorphic_as_table/test/polymorphic_as_table_plugin.sqlit3.db
7
+ postgresql:
8
+ :adapter: postgresql
9
+ :username: postgres
10
+ :password: postgres
11
+ :database: polymorphic_as_table_plugin_test
12
+ :min_messages: ERROR
13
+ mysql:
14
+ :adapter: mysql
15
+ :host: localhost
16
+ :username: root
17
+ :password: password
18
+ :database: polymorphic_as_table_plugin_test
@@ -0,0 +1,447 @@
1
+ # Logfile created on 2011-08-25 21:03:45 -0400 by logger.rb/25413
2
+ SQL (0.6ms) select sqlite_version(*)
3
+ SQL (0.1ms) SELECT name
4
+ FROM sqlite_master
5
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
6
+
7
+ SQL (11.8ms) CREATE TABLE "pictures" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "imageable_id" integer, "imageable_type" varchar(255), "created_at" datetime, "updated_at" datetime) 
8
+ SQL (0.2ms) SELECT name
9
+ FROM sqlite_master
10
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
11
+
12
+ SQL (2.6ms) CREATE TABLE "employees" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
13
+ SQL (0.3ms) SELECT name
14
+ FROM sqlite_master
15
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
16
+
17
+ SQL (3.7ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
18
+ SQL (0.1ms) PRAGMA index_list("schema_migrations")
19
+ SQL (2.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
20
+ SQL (0.2ms) SELECT name
21
+ FROM sqlite_master
22
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
23
+
24
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
25
+ SQL (2.7ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
26
+ SQL (0.7ms) select sqlite_version(*)
27
+ SQL (0.2ms) SELECT name
28
+ FROM sqlite_master
29
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
30
+
31
+ SQL (10.1ms) DROP TABLE "pictures"
32
+ SQL (2.9ms) CREATE TABLE "pictures" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "imageable_id" integer, "imageable_type" varchar(255), "created_at" datetime, "updated_at" datetime)
33
+ SQL (0.2ms)  SELECT name
34
+ FROM sqlite_master
35
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
36
+ 
37
+ SQL (2.8ms) DROP TABLE "employees"
38
+ SQL (3.1ms) CREATE TABLE "employees" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
39
+ SQL (0.2ms) SELECT name
40
+ FROM sqlite_master
41
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
42
+
43
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
44
+ PolymorphicAsTableTest::Picture Load (0.3ms) SELECT "pictures".* FROM "pictures"
45
+ PolymorphicAsTableTest::Employee Load (0.1ms) SELECT "employees".* FROM "employees"
46
+ SQL (0.7ms) select sqlite_version(*)
47
+ SQL (0.2ms) SELECT name
48
+ FROM sqlite_master
49
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
50
+
51
+ SQL (11.2ms) DROP TABLE "pictures"
52
+ SQL (3.0ms) CREATE TABLE "pictures" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "imageable_id" integer, "imageable_type" varchar(255), "created_at" datetime, "updated_at" datetime)
53
+ SQL (0.2ms)  SELECT name
54
+ FROM sqlite_master
55
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
56
+ 
57
+ SQL (2.8ms) DROP TABLE "employees"
58
+ SQL (3.1ms) CREATE TABLE "employees" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
59
+ SQL (0.2ms) SELECT name
60
+ FROM sqlite_master
61
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
62
+
63
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
64
+ PolymorphicAsTableTest::Picture Load (0.3ms) SELECT "pictures".* FROM "pictures"
65
+ PolymorphicAsTableTest::Employee Load (0.1ms) SELECT "employees".* FROM "employees"
66
+ SQL (0.7ms) select sqlite_version(*)
67
+ SQL (0.2ms) SELECT name
68
+ FROM sqlite_master
69
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
70
+
71
+ SQL (3.5ms) DROP TABLE "pictures"
72
+ SQL (2.4ms) CREATE TABLE "pictures" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "imageable_id" integer, "imageable_type" varchar(255), "created_at" datetime, "updated_at" datetime)
73
+ SQL (0.2ms)  SELECT name
74
+ FROM sqlite_master
75
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
76
+ 
77
+ SQL (2.4ms) DROP TABLE "employees"
78
+ SQL (2.4ms) CREATE TABLE "employees" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
79
+ SQL (0.2ms) SELECT name
80
+ FROM sqlite_master
81
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
82
+
83
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
84
+ SQL (0.7ms) select sqlite_version(*)
85
+ SQL (0.2ms) SELECT name
86
+ FROM sqlite_master
87
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
88
+
89
+ SQL (15.3ms) DROP TABLE "pictures"
90
+ SQL (2.5ms) CREATE TABLE "pictures" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "imageable_id" integer, "imageable_type" varchar(255), "created_at" datetime, "updated_at" datetime)
91
+ SQL (0.2ms)  SELECT name
92
+ FROM sqlite_master
93
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
94
+ 
95
+ SQL (2.3ms) DROP TABLE "employees"
96
+ SQL (2.4ms) CREATE TABLE "employees" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
97
+ SQL (0.2ms) SELECT name
98
+ FROM sqlite_master
99
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
100
+
101
+ SQL (0.2ms) SELECT version FROM "schema_migrations"
102
+ SQL (0.7ms) select sqlite_version(*)
103
+ SQL (0.2ms) SELECT name
104
+ FROM sqlite_master
105
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
106
+
107
+ SQL (10.8ms) DROP TABLE "pictures"
108
+ SQL (2.3ms) CREATE TABLE "pictures" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "imageable_id" integer, "imageable_type" varchar(255), "created_at" datetime, "updated_at" datetime)
109
+ SQL (0.3ms)  SELECT name
110
+ FROM sqlite_master
111
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
112
+ 
113
+ SQL (2.6ms) DROP TABLE "employees"
114
+ SQL (2.4ms) CREATE TABLE "employees" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
115
+ SQL (0.2ms) SELECT name
116
+ FROM sqlite_master
117
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
118
+
119
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
120
+ SQL (0.7ms) select sqlite_version(*)
121
+ SQL (0.2ms) SELECT name
122
+ FROM sqlite_master
123
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
124
+
125
+ SQL (12.0ms) DROP TABLE "pictures"
126
+ SQL (2.4ms) CREATE TABLE "pictures" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "imageable_id" integer, "imageable_type" varchar(255), "created_at" datetime, "updated_at" datetime)
127
+ SQL (0.3ms)  SELECT name
128
+ FROM sqlite_master
129
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
130
+ 
131
+ SQL (2.6ms) DROP TABLE "employees"
132
+ SQL (2.4ms) CREATE TABLE "employees" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
133
+ SQL (0.2ms) SELECT name
134
+ FROM sqlite_master
135
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
136
+
137
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
138
+ SQL (0.7ms) select sqlite_version(*)
139
+ SQL (0.2ms) SELECT name
140
+ FROM sqlite_master
141
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
142
+
143
+ SQL (12.9ms) DROP TABLE "pictures"
144
+ SQL (2.8ms) CREATE TABLE "pictures" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "imageable_id" integer, "imageable_type" varchar(255), "created_at" datetime, "updated_at" datetime)
145
+ SQL (0.2ms)  SELECT name
146
+ FROM sqlite_master
147
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
148
+ 
149
+ SQL (2.6ms) DROP TABLE "employees"
150
+ SQL (3.1ms) CREATE TABLE "employees" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
151
+ SQL (0.2ms) SELECT name
152
+ FROM sqlite_master
153
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
154
+
155
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
156
+ PolymorphicAsTableTest::Picture Load (0.3ms) SELECT "pictures".* FROM "pictures"
157
+ PolymorphicAsTableTest::Employee Load (0.1ms) SELECT "employees".* FROM "employees"
158
+ SQL (0.2ms) SELECT name
159
+ FROM sqlite_master
160
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
161
+
162
+ AREL (0.3ms) INSERT INTO "employees" ("name") VALUES ('JimBob')
163
+ SQL (0.2ms) SELECT name
164
+ FROM sqlite_master
165
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
166
+
167
+ AREL (0.2ms) INSERT INTO "employees" ("name") VALUES ('JimBob')
168
+ SQL (0.3ms) SELECT name
169
+ FROM sqlite_master
170
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
171
+
172
+ SQL (0.7ms) select sqlite_version(*)
173
+ SQL (0.2ms) SELECT name
174
+ FROM sqlite_master
175
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
176
+
177
+ SQL (9.7ms) DROP TABLE "pictures"
178
+ SQL (2.4ms) CREATE TABLE "pictures" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "imageable_id" integer, "imageable_type" varchar(255), "created_at" datetime, "updated_at" datetime)
179
+ SQL (0.2ms)  SELECT name
180
+ FROM sqlite_master
181
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
182
+ 
183
+ SQL (2.3ms) DROP TABLE "employees"
184
+ SQL (2.4ms) CREATE TABLE "employees" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
185
+ SQL (0.2ms) SELECT name
186
+ FROM sqlite_master
187
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
188
+
189
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
190
+ PolymorphicAsTableTest::Picture Load (0.3ms) SELECT "pictures".* FROM "pictures"
191
+ PolymorphicAsTableTest::Employee Load (0.1ms) SELECT "employees".* FROM "employees"
192
+ SQL (0.2ms) SELECT name
193
+ FROM sqlite_master
194
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
195
+
196
+ AREL (0.3ms) INSERT INTO "employees" ("name") VALUES ('JimBob')
197
+ AREL (0.4ms) INSERT INTO "pictures" ("name", "imageable_id", "imageable_type", "created_at", "updated_at") VALUES ('picture1', 1, 'employees', '2011-08-26 01:30:49.135365', '2011-08-26 01:30:49.135365')
198
+ AREL (0.2ms) INSERT INTO "employees" ("name") VALUES ('JimBob')
199
+ AREL (0.2ms) INSERT INTO "pictures" ("name", "imageable_id", "imageable_type", "created_at", "updated_at") VALUES ('picture1', 2, 'employees', '2011-08-26 01:30:49.153912', '2011-08-26 01:30:49.153912')
200
+ SQL (0.7ms) select sqlite_version(*)
201
+ SQL (0.2ms) SELECT name
202
+ FROM sqlite_master
203
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
204
+
205
+ SQL (11.2ms) DROP TABLE "pictures"
206
+ SQL (2.9ms) CREATE TABLE "pictures" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "imageable_id" integer, "imageable_type" varchar(255), "created_at" datetime, "updated_at" datetime)
207
+ SQL (0.2ms)  SELECT name
208
+ FROM sqlite_master
209
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
210
+ 
211
+ SQL (2.8ms) DROP TABLE "employees"
212
+ SQL (2.6ms) CREATE TABLE "employees" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
213
+ SQL (0.2ms) SELECT name
214
+ FROM sqlite_master
215
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
216
+
217
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
218
+ PolymorphicAsTableTest::Picture Load (0.3ms) SELECT "pictures".* FROM "pictures"
219
+ PolymorphicAsTableTest::Employee Load (0.1ms) SELECT "employees".* FROM "employees"
220
+ SQL (0.2ms) SELECT name
221
+ FROM sqlite_master
222
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
223
+
224
+ AREL (0.2ms) INSERT INTO "employees" ("name") VALUES ('JimBob')
225
+ AREL (0.3ms) INSERT INTO "pictures" ("name", "imageable_id", "imageable_type", "created_at", "updated_at") VALUES ('picture1', 1, 'employees', '2011-08-26 01:31:09.960169', '2011-08-26 01:31:09.960169')
226
+ AREL (0.2ms) INSERT INTO "employees" ("name") VALUES ('JimBob')
227
+ AREL (0.2ms) INSERT INTO "pictures" ("name", "imageable_id", "imageable_type", "created_at", "updated_at") VALUES ('picture1', 2, 'employees', '2011-08-26 01:31:09.979935', '2011-08-26 01:31:09.979935')
228
+ SQL (0.7ms) select sqlite_version(*)
229
+ SQL (0.3ms) SELECT name
230
+ FROM sqlite_master
231
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
232
+
233
+ SQL (12.1ms) DROP TABLE "pictures"
234
+ SQL (2.8ms) CREATE TABLE "pictures" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "imageable_id" integer, "imageable_type" varchar(255), "created_at" datetime, "updated_at" datetime)
235
+ SQL (0.2ms)  SELECT name
236
+ FROM sqlite_master
237
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
238
+ 
239
+ SQL (2.7ms) DROP TABLE "employees"
240
+ SQL (2.8ms) CREATE TABLE "employees" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
241
+ SQL (0.2ms) SELECT name
242
+ FROM sqlite_master
243
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
244
+
245
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
246
+ PolymorphicAsTableTest::Picture Load (0.3ms) SELECT "pictures".* FROM "pictures"
247
+ PolymorphicAsTableTest::Employee Load (0.1ms) SELECT "employees".* FROM "employees"
248
+ SQL (0.2ms) SELECT name
249
+ FROM sqlite_master
250
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
251
+
252
+ AREL (0.2ms) INSERT INTO "employees" ("name") VALUES ('JimBob')
253
+ AREL (0.3ms) INSERT INTO "pictures" ("name", "imageable_id", "imageable_type", "created_at", "updated_at") VALUES ('picture1', 1, 'employees', '2011-08-26 01:31:57.016395', '2011-08-26 01:31:57.016395')
254
+ AREL (0.2ms) INSERT INTO "employees" ("name") VALUES ('JimBob')
255
+ AREL (0.3ms) INSERT INTO "pictures" ("name", "imageable_id", "imageable_type", "created_at", "updated_at") VALUES ('picture1', 2, 'employees', '2011-08-26 01:31:57.035766', '2011-08-26 01:31:57.035766')
256
+ SQL (0.7ms) select sqlite_version(*)
257
+ SQL (0.2ms) SELECT name
258
+ FROM sqlite_master
259
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
260
+
261
+ SQL (13.6ms) DROP TABLE "pictures"
262
+ SQL (3.5ms) CREATE TABLE "pictures" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "imageable_id" integer, "imageable_type" varchar(255), "created_at" datetime, "updated_at" datetime)
263
+ SQL (0.2ms)  SELECT name
264
+ FROM sqlite_master
265
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
266
+ 
267
+ SQL (2.8ms) DROP TABLE "employees"
268
+ SQL (2.8ms) CREATE TABLE "employees" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
269
+ SQL (0.2ms) SELECT name
270
+ FROM sqlite_master
271
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
272
+
273
+ SQL (0.2ms) SELECT version FROM "schema_migrations"
274
+ PolymorphicAsTableTest::Picture Load (0.3ms) SELECT "pictures".* FROM "pictures"
275
+ PolymorphicAsTableTest::Employee Load (0.1ms) SELECT "employees".* FROM "employees"
276
+ SQL (0.2ms) SELECT name
277
+ FROM sqlite_master
278
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
279
+
280
+ AREL (0.2ms) INSERT INTO "employees" ("name") VALUES ('JimBob')
281
+ AREL (0.3ms) INSERT INTO "pictures" ("name", "imageable_id", "imageable_type", "created_at", "updated_at") VALUES ('picture1', 1, 'employees', '2011-08-26 01:34:20.431842', '2011-08-26 01:34:20.431842')
282
+ AREL (0.2ms) INSERT INTO "employees" ("name") VALUES ('JimBob')
283
+ AREL (0.2ms) INSERT INTO "pictures" ("name", "imageable_id", "imageable_type", "created_at", "updated_at") VALUES ('picture1', 2, 'employees', '2011-08-26 01:34:20.450938', '2011-08-26 01:34:20.450938')
284
+ SQL (0.1ms) SELECT imageable_type from `pictures` where id=?
285
+ SQL (0.7ms) select sqlite_version(*)
286
+ SQL (0.2ms) SELECT name
287
+ FROM sqlite_master
288
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
289
+
290
+ SQL (13.0ms) DROP TABLE "pictures"
291
+ SQL (2.7ms) CREATE TABLE "pictures" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "imageable_id" integer, "imageable_type" varchar(255), "created_at" datetime, "updated_at" datetime)
292
+ SQL (0.2ms)  SELECT name
293
+ FROM sqlite_master
294
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
295
+ 
296
+ SQL (2.9ms) DROP TABLE "employees"
297
+ SQL (2.9ms) CREATE TABLE "employees" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
298
+ SQL (0.2ms) SELECT name
299
+ FROM sqlite_master
300
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
301
+
302
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
303
+ PolymorphicAsTableTest::Picture Load (0.3ms) SELECT "pictures".* FROM "pictures"
304
+ PolymorphicAsTableTest::Employee Load (0.1ms) SELECT "employees".* FROM "employees"
305
+ SQL (0.2ms) SELECT name
306
+ FROM sqlite_master
307
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
308
+
309
+ AREL (0.2ms) INSERT INTO "employees" ("name") VALUES ('JimBob')
310
+ AREL (0.3ms) INSERT INTO "pictures" ("name", "imageable_id", "imageable_type", "created_at", "updated_at") VALUES ('picture1', 1, 'employees', '2011-08-26 01:34:41.808537', '2011-08-26 01:34:41.808537')
311
+ AREL (0.2ms) INSERT INTO "employees" ("name") VALUES ('JimBob')
312
+ AREL (0.2ms) INSERT INTO "pictures" ("name", "imageable_id", "imageable_type", "created_at", "updated_at") VALUES ('picture1', 2, 'employees', '2011-08-26 01:34:41.827747', '2011-08-26 01:34:41.827747')
313
+ SQL (0.1ms) SELECT imageable_type from `pictures` where id=?
314
+ SQL (0.7ms) select sqlite_version(*)
315
+ SQL (0.2ms) SELECT name
316
+ FROM sqlite_master
317
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
318
+
319
+ SQL (11.8ms) DROP TABLE "pictures"
320
+ SQL (3.0ms) CREATE TABLE "pictures" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "imageable_id" integer, "imageable_type" varchar(255), "created_at" datetime, "updated_at" datetime)
321
+ SQL (0.2ms)  SELECT name
322
+ FROM sqlite_master
323
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
324
+ 
325
+ SQL (2.9ms) DROP TABLE "employees"
326
+ SQL (2.8ms) CREATE TABLE "employees" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
327
+ SQL (0.2ms) SELECT name
328
+ FROM sqlite_master
329
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
330
+
331
+ SQL (0.2ms) SELECT version FROM "schema_migrations"
332
+ PolymorphicAsTableTest::Picture Load (0.3ms) SELECT "pictures".* FROM "pictures"
333
+ PolymorphicAsTableTest::Employee Load (0.1ms) SELECT "employees".* FROM "employees"
334
+ SQL (0.3ms) SELECT name
335
+ FROM sqlite_master
336
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
337
+
338
+ AREL (0.2ms) INSERT INTO "employees" ("name") VALUES ('JimBob')
339
+ AREL (0.3ms) INSERT INTO "pictures" ("name", "imageable_id", "imageable_type", "created_at", "updated_at") VALUES ('picture1', 1, 'employees', '2011-08-26 01:35:39.402742', '2011-08-26 01:35:39.402742')
340
+ AREL (0.2ms) INSERT INTO "employees" ("name") VALUES ('JimBob')
341
+ AREL (0.2ms) INSERT INTO "pictures" ("name", "imageable_id", "imageable_type", "created_at", "updated_at") VALUES ('picture1', 2, 'employees', '2011-08-26 01:35:39.422133', '2011-08-26 01:35:39.422133')
342
+ 2 (0.1ms) SELECT imageable_type from `pictures` where id=?
343
+ SQL (0.7ms) select sqlite_version(*)
344
+ SQL (0.2ms) SELECT name
345
+ FROM sqlite_master
346
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
347
+
348
+ SQL (9.7ms) DROP TABLE "pictures"
349
+ SQL (3.4ms) CREATE TABLE "pictures" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "imageable_id" integer, "imageable_type" varchar(255), "created_at" datetime, "updated_at" datetime)
350
+ SQL (0.2ms)  SELECT name
351
+ FROM sqlite_master
352
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
353
+ 
354
+ SQL (2.9ms) DROP TABLE "employees"
355
+ SQL (3.0ms) CREATE TABLE "employees" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
356
+ SQL (0.2ms) SELECT name
357
+ FROM sqlite_master
358
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
359
+
360
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
361
+ PolymorphicAsTableTest::Picture Load (0.3ms) SELECT "pictures".* FROM "pictures"
362
+ PolymorphicAsTableTest::Employee Load (0.1ms) SELECT "employees".* FROM "employees"
363
+ SQL (0.2ms) SELECT name
364
+ FROM sqlite_master
365
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
366
+
367
+ AREL (0.2ms) INSERT INTO "employees" ("name") VALUES ('JimBob')
368
+ AREL (0.3ms) INSERT INTO "pictures" ("name", "imageable_id", "imageable_type", "created_at", "updated_at") VALUES ('picture1', 1, 'employees', '2011-08-26 01:36:58.477784', '2011-08-26 01:36:58.477784')
369
+ AREL (0.2ms) INSERT INTO "employees" ("name") VALUES ('JimBob')
370
+ AREL (0.2ms) INSERT INTO "pictures" ("name", "imageable_id", "imageable_type", "created_at", "updated_at") VALUES ('picture1', 2, 'employees', '2011-08-26 01:36:58.496449', '2011-08-26 01:36:58.496449')
371
+ 2 (0.1ms) SELECT imageable_type from `pictures` where imageable_id=?
372
+ SQL (0.7ms) select sqlite_version(*)
373
+ SQL (0.2ms) SELECT name
374
+ FROM sqlite_master
375
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
376
+
377
+ SQL (14.9ms) DROP TABLE "pictures"
378
+ SQL (2.9ms) CREATE TABLE "pictures" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "imageable_id" integer, "imageable_type" varchar(255), "created_at" datetime, "updated_at" datetime)
379
+ SQL (0.2ms)  SELECT name
380
+ FROM sqlite_master
381
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
382
+ 
383
+ SQL (3.2ms) DROP TABLE "employees"
384
+ SQL (2.7ms) CREATE TABLE "employees" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
385
+ SQL (0.2ms) SELECT name
386
+ FROM sqlite_master
387
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
388
+
389
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
390
+ PolymorphicAsTableTest::Picture Load (0.3ms) SELECT "pictures".* FROM "pictures"
391
+ PolymorphicAsTableTest::Employee Load (0.1ms) SELECT "employees".* FROM "employees"
392
+ SQL (0.2ms) SELECT name
393
+ FROM sqlite_master
394
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
395
+
396
+ AREL (0.2ms) INSERT INTO "employees" ("name") VALUES ('JimBob')
397
+ AREL (0.3ms) INSERT INTO "pictures" ("name", "imageable_id", "imageable_type", "created_at", "updated_at") VALUES ('picture1', 1, 'employees', '2011-08-26 01:37:51.749837', '2011-08-26 01:37:51.749837')
398
+ AREL (0.3ms) INSERT INTO "employees" ("name") VALUES ('JimBob')
399
+ AREL (0.4ms) INSERT INTO "pictures" ("name", "imageable_id", "imageable_type", "created_at", "updated_at") VALUES ('picture1', 2, 'employees', '2011-08-26 01:37:51.775068', '2011-08-26 01:37:51.775068')
400
+ SQL (0.3ms) SELECT imageable_type from `pictures` where imageable_id=2
401
+ SQL (0.7ms) select sqlite_version(*)
402
+ SQL (0.2ms) SELECT name
403
+ FROM sqlite_master
404
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
405
+
406
+ SQL (13.5ms) DROP TABLE "pictures"
407
+ SQL (2.8ms) CREATE TABLE "pictures" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "imageable_id" integer, "imageable_type" varchar(255), "created_at" datetime, "updated_at" datetime)
408
+ SQL (0.4ms)  SELECT name
409
+ FROM sqlite_master
410
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
411
+ 
412
+ SQL (3.2ms) DROP TABLE "employees"
413
+ SQL (2.9ms) CREATE TABLE "employees" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
414
+ SQL (0.2ms) SELECT name
415
+ FROM sqlite_master
416
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
417
+
418
+ SQL (0.2ms) SELECT version FROM "schema_migrations"
419
+ SQL (0.7ms) select sqlite_version(*)
420
+ SQL (0.2ms) SELECT name
421
+ FROM sqlite_master
422
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
423
+
424
+ SQL (9.9ms) DROP TABLE "pictures"
425
+ SQL (3.0ms) CREATE TABLE "pictures" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "imageable_id" integer, "imageable_type" varchar(255), "created_at" datetime, "updated_at" datetime)
426
+ SQL (0.2ms)  SELECT name
427
+ FROM sqlite_master
428
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
429
+ 
430
+ SQL (2.7ms) DROP TABLE "employees"
431
+ SQL (2.8ms) CREATE TABLE "employees" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255)) 
432
+ SQL (0.2ms) SELECT name
433
+ FROM sqlite_master
434
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
435
+
436
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
437
+ PolymorphicAsTableTest::Picture Load (0.3ms) SELECT "pictures".* FROM "pictures"
438
+ PolymorphicAsTableTest::Employee Load (0.1ms) SELECT "employees".* FROM "employees"
439
+ SQL (0.2ms) SELECT name
440
+ FROM sqlite_master
441
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
442
+
443
+ AREL (0.4ms) INSERT INTO "employees" ("name") VALUES ('JimBob')
444
+ AREL (0.3ms) INSERT INTO "pictures" ("name", "imageable_id", "imageable_type", "created_at", "updated_at") VALUES ('picture1', 1, 'employees', '2011-08-26 01:42:44.175030', '2011-08-26 01:42:44.175030')
445
+ AREL (0.2ms) INSERT INTO "employees" ("name") VALUES ('JimBob')
446
+ AREL (0.2ms) INSERT INTO "pictures" ("name", "imageable_id", "imageable_type", "created_at", "updated_at") VALUES ('picture1', 2, 'employees', '2011-08-26 01:42:44.193759', '2011-08-26 01:42:44.193759')
447
+ SQL (0.2ms) SELECT imageable_type from `pictures` where imageable_id=2
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+
3
+ class PolymorphicAsTableTest < ActiveSupport::TestCase
4
+ load_schema
5
+
6
+ class Picture < ActiveRecord::Base
7
+ is_polymorphic_as_table
8
+ belongs_to :imageable, :polymorphic => true
9
+ end
10
+
11
+ class Employee < ActiveRecord::Base
12
+ has_polymorphic_as_table
13
+ has_many :pictures, :as => :imageable
14
+ end
15
+
16
+ def test_schema_has_loaded_correctly
17
+ assert_equal [], Picture.all
18
+ assert_equal [], Employee.all
19
+ end
20
+
21
+ def test_type_is_written_as_table_name
22
+ e = Employee.create(:name => "JimBob")
23
+ p = e.pictures.create(:name => "picture1")
24
+
25
+ sql = "SELECT imageable_type from `pictures` where imageable_id=%d"
26
+ type = ActiveRecord::Base.connection.select_value(sql %e.id)
27
+ assert_equal("employees", type)
28
+ end
29
+
30
+ def test_type_is_read_as_class_name
31
+ e = Employee.create(:name => "JimBob")
32
+ p = e.pictures.create(:name => "picture1")
33
+ assert_equal("Employee", p.imageable_type)
34
+ end
35
+ end
data/test/schema.rb ADDED
@@ -0,0 +1,12 @@
1
+ ActiveRecord::Schema.define(:version => 0) do
2
+ create_table :pictures, :force => true do |t|
3
+ t.string :name
4
+ t.integer :imageable_id
5
+ t.string :imageable_type
6
+ t.timestamps
7
+ end
8
+ create_table :employees, :force => true do |t|
9
+ t.string :name
10
+ end
11
+
12
+ end
@@ -0,0 +1,34 @@
1
+ DIR = File.dirname(__FILE__)
2
+ ENV['RAILS_ENV'] = 'test'
3
+ ENV['RAILS_ROOT'] ||= DIR + '/../../../..'
4
+
5
+ require 'test/unit'
6
+ require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb'))
7
+
8
+ def load_schema
9
+ config = YAML::load(IO.read(DIR + '/database.yml'))
10
+ ActiveRecord::Base.logger = Logger.new(DIR + "/polymorphic_as_table_test.log")
11
+
12
+ db_adapter = ENV['DB']
13
+
14
+ db_adapter ||=
15
+ begin
16
+ require 'rubygems'
17
+ require 'sqlite'
18
+ 'sqlite'
19
+ rescue MissingSourceFile
20
+ begin
21
+ require 'sqlite3'
22
+ 'sqlite3'
23
+ rescue MissingSourceFile
24
+ end
25
+ end
26
+
27
+ if db_adapter.nil?
28
+ rase "No DB Adapter selected. Set the DB environment variable or install sqlite or sqlite3"
29
+ end
30
+
31
+ ActiveRecord::Base.establish_connection(config[db_adapter])
32
+ load(DIR + "/schema.rb")
33
+ require DIR + '/../rails/init'
34
+ end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: polymorphic_as_table
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeremiah Dodds
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-26 00:00:00.000000000Z
13
+ dependencies: []
14
+ description:
15
+ email: jeremiah.dodds@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files:
19
+ - README
20
+ files:
21
+ - install.rb
22
+ - uninstall.rb
23
+ - polymorphic_as_table-0.5.0.gem
24
+ - Rakefile
25
+ - README
26
+ - MIT-LICENSE
27
+ - polymorphic_as_table.gemspec
28
+ - lib/polymorphic_as_table.rb
29
+ - lib/polymorphic_as_table/association_proxy.rb
30
+ - lib/polymorphic_as_table/has_one_association.rb
31
+ - lib/polymorphic_as_table/through_association_scope.rb
32
+ - lib/polymorphic_as_table/has_many_association.rb
33
+ - lib/polymorphic_as_table/belongs_to_association.rb
34
+ - lib/polymorphic_as_table/through_reflection.rb
35
+ - rails/init.rb
36
+ - test/polymorphic_as_table_test.log
37
+ - test/schema.rb
38
+ - test/test_helper.rb
39
+ - test/database.yml
40
+ - test/polymorphic_as_table_plugin.sqlit3.db
41
+ - test/polymorphic_as_table_test.rb
42
+ homepage: https://github.com/jdodds/polymorphic_as_table
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.8
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Allow for ActiveRecord polymorphic assocations that write their table name
66
+ as their type
67
+ test_files: []