enum_column 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/LICENSE +20 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/enum_column.gemspec +108 -0
- data/lib/enum/active_record_helper.rb +107 -0
- data/lib/enum/enum_adapter.rb +76 -0
- data/lib/enum/mysql_adapter.rb +33 -0
- data/lib/enum/postgresql_adapter.rb +64 -0
- data/lib/enum/quoting.rb +17 -0
- data/lib/enum/schema_definitions.rb +12 -0
- data/lib/enum/schema_statements.rb +32 -0
- data/lib/enum/sqlite3_adapter.rb +52 -0
- data/lib/enum/validations.rb +40 -0
- data/lib/enum_column.rb +9 -0
- data/readme.html +18 -0
- data/test/db/schema.rb +28 -0
- data/test/enum_mysql_test.rb +220 -0
- data/test/fixtures/db_definitions/mysql.drop.sql +32 -0
- data/test/fixtures/db_definitions/mysql.sql +244 -0
- data/test/fixtures/enumeration.rb +20 -0
- data/test/mock_app/.gitignore +3 -0
- data/test/mock_app/README +243 -0
- data/test/mock_app/Rakefile +10 -0
- data/test/mock_app/app/controllers/application_controller.rb +10 -0
- data/test/mock_app/app/controllers/contents_controller.rb +85 -0
- data/test/mock_app/app/models/content.rb +2 -0
- data/test/mock_app/config/boot.rb +110 -0
- data/test/mock_app/config/database.yml +5 -0
- data/test/mock_app/config/environment.rb +41 -0
- data/test/mock_app/config/environments/development.rb +17 -0
- data/test/mock_app/config/environments/production.rb +28 -0
- data/test/mock_app/config/environments/test.rb +28 -0
- data/test/mock_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/mock_app/config/initializers/inflections.rb +10 -0
- data/test/mock_app/config/initializers/mime_types.rb +5 -0
- data/test/mock_app/config/initializers/new_rails_defaults.rb +19 -0
- data/test/mock_app/config/initializers/session_store.rb +15 -0
- data/test/mock_app/config/locales/en.yml +5 -0
- data/test/mock_app/config/routes.rb +45 -0
- data/test/mock_app/config/sitemap.rb +13 -0
- data/test/mock_app/db/migrate/20090826121911_create_contents.rb +12 -0
- data/test/mock_app/db/schema.rb +20 -0
- data/test/mock_app/db/test.sqlite3 +0 -0
- data/test/mock_app/public/index.html +275 -0
- data/test/mock_app/script/console +3 -0
- data/test/test_helper.rb +21 -0
- metadata +130 -0
data/test/db/schema.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
ActiveRecord::Schema.define do
|
3
|
+
create_table :enumerations, :force => true do |t|
|
4
|
+
t.column :severity, :enum, :limit => [:low, :medium, :high, :critical],
|
5
|
+
:default => :medium
|
6
|
+
t.column :color, :enum, :limit => [:red, :blue, :green, :yellow]
|
7
|
+
t.column :string_field, :string, :limit => 8, :null => false
|
8
|
+
t.column :int_field, :integer
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
create_table :basic_enums, :force => true do |t|
|
13
|
+
t.column :value, :enum, :limit => [:good, :working]
|
14
|
+
end
|
15
|
+
|
16
|
+
create_table :basic_default_enums, :force => true do |t|
|
17
|
+
t.column :value, :enum, :limit => [:good, :working],:default => :working
|
18
|
+
end
|
19
|
+
|
20
|
+
create_table :nonnull_enums, :force => true do |t|
|
21
|
+
t.column :value, :enum, :limit => [:good, :working],:null => false
|
22
|
+
end
|
23
|
+
|
24
|
+
create_table :nonnull_default_enums, :force => true do |t|
|
25
|
+
t.column :value, :enum, :limit => [:good, :working],:null => false,:default => :working
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,220 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
require 'fixtures/enumeration'
|
3
|
+
|
4
|
+
class EnumerationsTest < Test::Unit::TestCase
|
5
|
+
class EnumController < ActionController::Base
|
6
|
+
def test1
|
7
|
+
@test = Enumeration.new
|
8
|
+
render :inline => "<%= input('test', 'severity')%>"
|
9
|
+
end
|
10
|
+
|
11
|
+
def test2
|
12
|
+
@test = Enumeration.new
|
13
|
+
render :inline => "<%= enum_radio('test', 'severity')%>"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup
|
18
|
+
Enumeration.connection.execute 'DELETE FROM enumerations'
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_column_values
|
22
|
+
columns = Enumeration.columns_hash
|
23
|
+
color_column = columns['color']
|
24
|
+
assert color_column
|
25
|
+
assert_equal [:red, :blue, :green, :yellow], color_column.values
|
26
|
+
|
27
|
+
severity_column = columns['severity']
|
28
|
+
assert severity_column
|
29
|
+
assert_equal [:low, :medium, :high, :critical], severity_column.values
|
30
|
+
assert_equal :medium, severity_column.default
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_insert_enum
|
34
|
+
row = Enumeration.new
|
35
|
+
row.color = :blue
|
36
|
+
row.string_field = 'test'
|
37
|
+
assert_equal :medium, row.severity
|
38
|
+
assert row.save
|
39
|
+
|
40
|
+
db_row = Enumeration.find(row.id)
|
41
|
+
assert db_row
|
42
|
+
assert :blue, row.color
|
43
|
+
assert :medium, row.severity
|
44
|
+
end
|
45
|
+
|
46
|
+
# Uses the automatic validates_columns to create automatic validation rules
|
47
|
+
# for columns based on the schema information.
|
48
|
+
def test_bad_value
|
49
|
+
row = Enumeration.new
|
50
|
+
row.color = :violet
|
51
|
+
row.string_field = 'test'
|
52
|
+
assert !row.save
|
53
|
+
|
54
|
+
assert row.errors
|
55
|
+
assert_equal 'is not included in the list', row.errors['color']
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_other_types
|
59
|
+
row = Enumeration.new
|
60
|
+
row.string_field = 'a' * 10
|
61
|
+
assert !row.save
|
62
|
+
assert_equal 'is too long (maximum is 8 characters)', row.errors['string_field']
|
63
|
+
|
64
|
+
row = Enumeration.new
|
65
|
+
assert !row.save
|
66
|
+
assert_equal 'can\'t be blank', row.errors['string_field']
|
67
|
+
|
68
|
+
row = Enumeration.new
|
69
|
+
row.string_field = 'test'
|
70
|
+
row.int_field = 'aaaa'
|
71
|
+
assert !row.save
|
72
|
+
assert_equal 'is not a number', row.errors['int_field']
|
73
|
+
|
74
|
+
row = Enumeration.new
|
75
|
+
row.string_field = 'test'
|
76
|
+
row.int_field = '500'
|
77
|
+
assert row.save
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_view_helper
|
81
|
+
request = ActionController::TestRequest.new
|
82
|
+
response = ActionController::TestResponse.new
|
83
|
+
request.action = 'test1'
|
84
|
+
body = EnumController.process(request, response).body
|
85
|
+
assert_equal '<select id="test_severity" name="test[severity]"><option value="low">low</option><option value="medium" selected="selected">medium</option><option value="high">high</option><option value="critical">critical</option></select>', body
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_radio_helper
|
89
|
+
request = ActionController::TestRequest.new
|
90
|
+
response = ActionController::TestResponse.new
|
91
|
+
request.action = 'test2'
|
92
|
+
body = EnumController.process(request, response).body
|
93
|
+
assert_equal '<label>low: <input id="test_severity_low" name="test[severity]" type="radio" value="low" /></label><label>medium: <input checked="checked" id="test_severity_medium" name="test[severity]" type="radio" value="medium" /></label><label>high: <input id="test_severity_high" name="test[severity]" type="radio" value="high" /></label><label>critical: <input id="test_severity_critical" name="test[severity]" type="radio" value="critical" /></label>', body
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
# Basic tests
|
98
|
+
def test_create_basic_default
|
99
|
+
assert (object = BasicEnum.create)
|
100
|
+
assert_nil object.value,
|
101
|
+
"Enum columns without explicit default, default to null if allowed"
|
102
|
+
assert !object.new_record?
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_create_basic_good
|
106
|
+
assert (object = BasicEnum.create(:value => :good))
|
107
|
+
assert_equal :good, object.value
|
108
|
+
assert !object.new_record?
|
109
|
+
assert (object = BasicEnum.create(:value => :working))
|
110
|
+
assert_equal :working, object.value
|
111
|
+
assert !object.new_record?
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_create_basic_null
|
115
|
+
assert (object = BasicEnum.create(:value => nil))
|
116
|
+
assert_nil object.value
|
117
|
+
assert !object.new_record?
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_create_basic_bad
|
121
|
+
assert (object = BasicEnum.create(:value => :bad))
|
122
|
+
assert object.new_record?
|
123
|
+
end
|
124
|
+
|
125
|
+
# Basic w/ Default
|
126
|
+
|
127
|
+
######################################################################
|
128
|
+
|
129
|
+
def test_create_basic_wd_default
|
130
|
+
assert (object = BasicDefaultEnum.create)
|
131
|
+
assert_equal :working, object.value, "Explicit default ignored columns"
|
132
|
+
assert !object.new_record?
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_create_basic_wd_good
|
136
|
+
assert (object = BasicDefaultEnum.create(:value => :good))
|
137
|
+
assert_equal :good, object.value
|
138
|
+
assert !object.new_record?
|
139
|
+
assert (object = BasicDefaultEnum.create(:value => :working))
|
140
|
+
assert_equal :working, object.value
|
141
|
+
assert !object.new_record?
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_create_basic_wd_null
|
145
|
+
assert (object = BasicDefaultEnum.create(:value => nil))
|
146
|
+
assert_nil object.value
|
147
|
+
assert !object.new_record?
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_create_basic_wd_bad
|
151
|
+
assert (object = BasicDefaultEnum.create(:value => :bad))
|
152
|
+
assert object.new_record?
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
# Nonnull
|
158
|
+
|
159
|
+
######################################################################
|
160
|
+
|
161
|
+
def test_create_nonnull_default
|
162
|
+
assert (object = NonnullEnum.create)
|
163
|
+
# assert_equal :good, object.value,
|
164
|
+
# "Enum columns without explicit default, default to first value if null not allowed"
|
165
|
+
assert object.new_record?
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_create_nonnull_good
|
169
|
+
assert (object = NonnullEnum.create(:value => :good))
|
170
|
+
assert_equal :good, object.value
|
171
|
+
assert !object.new_record?
|
172
|
+
assert (object = NonnullEnum.create(:value => :working))
|
173
|
+
assert_equal :working, object.value
|
174
|
+
assert !object.new_record?
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_create_nonnull_null
|
178
|
+
assert (object = NonnullEnum.create(:value => nil))
|
179
|
+
assert object.new_record?
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_create_nonnull_bad
|
183
|
+
assert (object = NonnullEnum.create(:value => :bad))
|
184
|
+
assert object.new_record?
|
185
|
+
end
|
186
|
+
|
187
|
+
# Nonnull w/ Default
|
188
|
+
|
189
|
+
######################################################################
|
190
|
+
|
191
|
+
def test_create_nonnull_wd_default
|
192
|
+
assert (object = NonnullDefaultEnum.create)
|
193
|
+
assert_equal :working, object.value
|
194
|
+
assert !object.new_record?
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_create_nonnull_wd_good
|
198
|
+
assert (object = NonnullDefaultEnum.create(:value => :good))
|
199
|
+
assert_equal :good, object.value
|
200
|
+
assert !object.new_record?
|
201
|
+
assert (object = NonnullDefaultEnum.create(:value => :working))
|
202
|
+
assert_equal :working, object.value
|
203
|
+
assert !object.new_record?
|
204
|
+
end
|
205
|
+
|
206
|
+
def test_create_nonnull_wd_null
|
207
|
+
assert (object = NonnullDefaultEnum.create(:value => nil))
|
208
|
+
assert object.new_record?
|
209
|
+
end
|
210
|
+
|
211
|
+
def test_create_nonnull_wd_bad
|
212
|
+
assert (object = NonnullDefaultEnum.create(:value => :bad))
|
213
|
+
assert object.new_record?
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_quoting
|
217
|
+
value = ActiveRecord::Base.send(:sanitize_sql, ["value = ? ", :"'" ] )
|
218
|
+
assert_equal "value = '\\'' ", value
|
219
|
+
end
|
220
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
DROP TABLE accounts;
|
2
|
+
DROP TABLE funny_jokes;
|
3
|
+
DROP TABLE companies;
|
4
|
+
DROP TABLE topics;
|
5
|
+
DROP TABLE developers;
|
6
|
+
DROP TABLE projects;
|
7
|
+
DROP TABLE developers_projects;
|
8
|
+
DROP TABLE customers;
|
9
|
+
DROP TABLE orders;
|
10
|
+
DROP TABLE movies;
|
11
|
+
DROP TABLE subscribers;
|
12
|
+
DROP TABLE booleantests;
|
13
|
+
DROP TABLE auto_id_tests;
|
14
|
+
DROP TABLE entrants;
|
15
|
+
DROP TABLE colnametests;
|
16
|
+
DROP TABLE mixins;
|
17
|
+
DROP TABLE people;
|
18
|
+
DROP TABLE readers;
|
19
|
+
DROP TABLE binaries;
|
20
|
+
DROP TABLE computers;
|
21
|
+
DROP TABLE tasks;
|
22
|
+
DROP TABLE posts;
|
23
|
+
DROP TABLE comments;
|
24
|
+
DROP TABLE authors;
|
25
|
+
DROP TABLE categories;
|
26
|
+
DROP TABLE categories_posts;
|
27
|
+
DROP TABLE fk_test_has_fk;
|
28
|
+
DROP TABLE fk_test_has_pk;
|
29
|
+
DROP TABLE keyboards;
|
30
|
+
DROP TABLE enumerations;
|
31
|
+
DROP TABLE legacy_things;
|
32
|
+
DROP TABLE numeric_data;
|
@@ -0,0 +1,244 @@
|
|
1
|
+
CREATE TABLE `accounts` (
|
2
|
+
`id` int(11) NOT NULL auto_increment,
|
3
|
+
`firm_id` int(11) default NULL,
|
4
|
+
`credit_limit` int(5) default NULL,
|
5
|
+
PRIMARY KEY (`id`)
|
6
|
+
) TYPE=InnoDB;
|
7
|
+
|
8
|
+
CREATE TABLE `funny_jokes` (
|
9
|
+
`id` int(11) NOT NULL auto_increment,
|
10
|
+
`name` varchar(50) default NULL,
|
11
|
+
PRIMARY KEY (`id`)
|
12
|
+
) TYPE=InnoDB;
|
13
|
+
|
14
|
+
CREATE TABLE `companies` (
|
15
|
+
`id` int(11) NOT NULL auto_increment,
|
16
|
+
`type` varchar(50) default NULL,
|
17
|
+
`ruby_type` varchar(50) default NULL,
|
18
|
+
`firm_id` int(11) default NULL,
|
19
|
+
`name` varchar(50) default NULL,
|
20
|
+
`client_of` int(11) default NULL,
|
21
|
+
`rating` int(11) default NULL default 1,
|
22
|
+
PRIMARY KEY (`id`)
|
23
|
+
) TYPE=InnoDB;
|
24
|
+
|
25
|
+
|
26
|
+
CREATE TABLE `topics` (
|
27
|
+
`id` int(11) NOT NULL auto_increment,
|
28
|
+
`title` varchar(255) default NULL,
|
29
|
+
`author_name` varchar(255) default NULL,
|
30
|
+
`author_email_address` varchar(255) default NULL,
|
31
|
+
`written_on` datetime default NULL,
|
32
|
+
`bonus_time` time default NULL,
|
33
|
+
`last_read` date default NULL,
|
34
|
+
`content` text,
|
35
|
+
`approved` tinyint(1) default 1,
|
36
|
+
`replies_count` int(11) default 0,
|
37
|
+
`parent_id` int(11) default NULL,
|
38
|
+
`type` varchar(50) default NULL,
|
39
|
+
PRIMARY KEY (`id`)
|
40
|
+
) TYPE=InnoDB;
|
41
|
+
|
42
|
+
CREATE TABLE `developers` (
|
43
|
+
`id` int(11) NOT NULL auto_increment,
|
44
|
+
`name` varchar(100) default NULL,
|
45
|
+
`salary` int(11) default 70000,
|
46
|
+
`created_at` datetime default NULL,
|
47
|
+
`updated_at` datetime default NULL,
|
48
|
+
PRIMARY KEY (`id`)
|
49
|
+
) TYPE=InnoDB;
|
50
|
+
|
51
|
+
CREATE TABLE `projects` (
|
52
|
+
`id` int(11) NOT NULL auto_increment,
|
53
|
+
`name` varchar(100) default NULL,
|
54
|
+
`type` VARCHAR(255) default NULL,
|
55
|
+
PRIMARY KEY (`id`)
|
56
|
+
) TYPE=InnoDB;
|
57
|
+
|
58
|
+
CREATE TABLE `developers_projects` (
|
59
|
+
`developer_id` int(11) NOT NULL,
|
60
|
+
`project_id` int(11) NOT NULL,
|
61
|
+
`joined_on` date default NULL,
|
62
|
+
`access_level` smallint default 1
|
63
|
+
) TYPE=InnoDB;
|
64
|
+
|
65
|
+
CREATE TABLE `orders` (
|
66
|
+
`id` int(11) NOT NULL auto_increment,
|
67
|
+
`name` varchar(100) default NULL,
|
68
|
+
`billing_customer_id` int(11) default NULL,
|
69
|
+
`shipping_customer_id` int(11) default NULL,
|
70
|
+
PRIMARY KEY (`id`)
|
71
|
+
) TYPE=InnoDB;
|
72
|
+
|
73
|
+
CREATE TABLE `customers` (
|
74
|
+
`id` int(11) NOT NULL auto_increment,
|
75
|
+
`name` varchar(100) default NULL,
|
76
|
+
`balance` int(6) default 0,
|
77
|
+
`address_street` varchar(100) default NULL,
|
78
|
+
`address_city` varchar(100) default NULL,
|
79
|
+
`address_country` varchar(100) default NULL,
|
80
|
+
`gps_location` varchar(100) default NULL,
|
81
|
+
PRIMARY KEY (`id`)
|
82
|
+
) TYPE=InnoDB;
|
83
|
+
|
84
|
+
CREATE TABLE `movies` (
|
85
|
+
`movieid` int(11) NOT NULL auto_increment,
|
86
|
+
`name` varchar(100) default NULL,
|
87
|
+
PRIMARY KEY (`movieid`)
|
88
|
+
) TYPE=InnoDB;
|
89
|
+
|
90
|
+
CREATE TABLE `subscribers` (
|
91
|
+
`nick` varchar(100) NOT NULL,
|
92
|
+
`name` varchar(100) default NULL,
|
93
|
+
PRIMARY KEY (`nick`)
|
94
|
+
) TYPE=InnoDB;
|
95
|
+
|
96
|
+
CREATE TABLE `booleantests` (
|
97
|
+
`id` int(11) NOT NULL auto_increment,
|
98
|
+
`value` integer default NULL,
|
99
|
+
PRIMARY KEY (`id`)
|
100
|
+
) TYPE=InnoDB;
|
101
|
+
|
102
|
+
CREATE TABLE `auto_id_tests` (
|
103
|
+
`auto_id` int(11) NOT NULL auto_increment,
|
104
|
+
`value` integer default NULL,
|
105
|
+
PRIMARY KEY (`auto_id`)
|
106
|
+
) TYPE=InnoDB;
|
107
|
+
|
108
|
+
CREATE TABLE `entrants` (
|
109
|
+
`id` INTEGER NOT NULL auto_increment PRIMARY KEY,
|
110
|
+
`name` VARCHAR(255) NOT NULL,
|
111
|
+
`course_id` INTEGER NOT NULL
|
112
|
+
);
|
113
|
+
|
114
|
+
CREATE TABLE `colnametests` (
|
115
|
+
`id` int(11) NOT NULL auto_increment,
|
116
|
+
`references` int(11) NOT NULL,
|
117
|
+
PRIMARY KEY (`id`)
|
118
|
+
) TYPE=InnoDB;
|
119
|
+
|
120
|
+
CREATE TABLE `mixins` (
|
121
|
+
`id` int(11) NOT NULL auto_increment,
|
122
|
+
`parent_id` int(11) default NULL,
|
123
|
+
`pos` int(11) default NULL,
|
124
|
+
`created_at` datetime default NULL,
|
125
|
+
`updated_at` datetime default NULL,
|
126
|
+
`lft` int(11) default NULL,
|
127
|
+
`rgt` int(11) default NULL,
|
128
|
+
`root_id` int(11) default NULL,
|
129
|
+
`type` varchar(40) default NULL,
|
130
|
+
PRIMARY KEY (`id`)
|
131
|
+
) TYPE=InnoDB;
|
132
|
+
|
133
|
+
CREATE TABLE `people` (
|
134
|
+
`id` INTEGER NOT NULL auto_increment PRIMARY KEY,
|
135
|
+
`first_name` VARCHAR(40) NOT NULL,
|
136
|
+
`lock_version` INTEGER NOT NULL DEFAULT 0
|
137
|
+
) TYPE=InnoDB;
|
138
|
+
|
139
|
+
CREATE TABLE `readers` (
|
140
|
+
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
|
141
|
+
`post_id` INTEGER NOT NULL,
|
142
|
+
`person_id` INTEGER NOT NULL
|
143
|
+
) TYPE=InnoDB;
|
144
|
+
|
145
|
+
CREATE TABLE `binaries` (
|
146
|
+
`id` int(11) NOT NULL auto_increment,
|
147
|
+
`data` mediumblob,
|
148
|
+
PRIMARY KEY (`id`)
|
149
|
+
) TYPE=InnoDB;
|
150
|
+
|
151
|
+
CREATE TABLE `computers` (
|
152
|
+
`id` INTEGER NOT NULL auto_increment PRIMARY KEY,
|
153
|
+
`developer` INTEGER NOT NULL,
|
154
|
+
`extendedWarranty` INTEGER NOT NULL
|
155
|
+
) TYPE=InnoDB;
|
156
|
+
|
157
|
+
CREATE TABLE `posts` (
|
158
|
+
`id` INTEGER NOT NULL auto_increment PRIMARY KEY,
|
159
|
+
`author_id` INTEGER,
|
160
|
+
`title` VARCHAR(255) NOT NULL,
|
161
|
+
`body` TEXT NOT NULL,
|
162
|
+
`type` VARCHAR(255) NOT NULL
|
163
|
+
) TYPE=InnoDB;
|
164
|
+
|
165
|
+
CREATE TABLE `comments` (
|
166
|
+
`id` INTEGER NOT NULL auto_increment PRIMARY KEY,
|
167
|
+
`post_id` INTEGER NOT NULL,
|
168
|
+
`body` TEXT NOT NULL,
|
169
|
+
`type` VARCHAR(255) NOT NULL
|
170
|
+
) TYPE=InnoDB;
|
171
|
+
|
172
|
+
CREATE TABLE `authors` (
|
173
|
+
`id` INTEGER NOT NULL auto_increment PRIMARY KEY,
|
174
|
+
`name` VARCHAR(255) NOT NULL
|
175
|
+
) TYPE=InnoDB;
|
176
|
+
|
177
|
+
CREATE TABLE `tasks` (
|
178
|
+
`id` int(11) NOT NULL auto_increment,
|
179
|
+
`starting` datetime NOT NULL default '0000-00-00 00:00:00',
|
180
|
+
`ending` datetime NOT NULL default '0000-00-00 00:00:00',
|
181
|
+
PRIMARY KEY (`id`)
|
182
|
+
) TYPE=InnoDB;
|
183
|
+
|
184
|
+
CREATE TABLE `categories` (
|
185
|
+
`id` int(11) NOT NULL auto_increment,
|
186
|
+
`name` VARCHAR(255) NOT NULL,
|
187
|
+
`type` VARCHAR(255) NOT NULL,
|
188
|
+
PRIMARY KEY (`id`)
|
189
|
+
) TYPE=InnoDB;
|
190
|
+
|
191
|
+
CREATE TABLE `categories_posts` (
|
192
|
+
`category_id` int(11) NOT NULL,
|
193
|
+
`post_id` int(11) NOT NULL
|
194
|
+
) TYPE=InnoDB;
|
195
|
+
|
196
|
+
CREATE TABLE `fk_test_has_pk` (
|
197
|
+
`id` INTEGER NOT NULL auto_increment PRIMARY KEY
|
198
|
+
) TYPE=InnoDB;
|
199
|
+
|
200
|
+
CREATE TABLE `fk_test_has_fk` (
|
201
|
+
`id` INTEGER NOT NULL auto_increment PRIMARY KEY,
|
202
|
+
`fk_id` INTEGER NOT NULL,
|
203
|
+
|
204
|
+
FOREIGN KEY (`fk_id`) REFERENCES `fk_test_has_pk`(`id`)
|
205
|
+
) TYPE=InnoDB;
|
206
|
+
|
207
|
+
|
208
|
+
CREATE TABLE `keyboards` (
|
209
|
+
`key_number` int(11) NOT NULL auto_increment primary key,
|
210
|
+
`name` varchar(50) default NULL
|
211
|
+
);
|
212
|
+
|
213
|
+
<<<<<<< .mine
|
214
|
+
CREATE TABLE `enumerations` (
|
215
|
+
`id` INTEGER NOT NULL auto_increment PRIMARY KEY,
|
216
|
+
`severity` enum('low', 'medium', 'high', 'critical') DEFAULT 'medium',
|
217
|
+
`color` enum('red', 'blue', 'green', 'yellow'),
|
218
|
+
`string_field` varchar(8) NOT NULL,
|
219
|
+
`int_field` int(11)
|
220
|
+
) TYPE=InnoDB;
|
221
|
+
|
222
|
+
--Altered lock_version column name.
|
223
|
+
=======
|
224
|
+
-- Altered lock_version column name.
|
225
|
+
>>>>>>> .r3595
|
226
|
+
CREATE TABLE `legacy_things` (
|
227
|
+
`id` int(11) NOT NULL auto_increment,
|
228
|
+
`tps_report_number` int(11) default NULL,
|
229
|
+
`version` int(11) NOT NULL default 0,
|
230
|
+
PRIMARY KEY (`id`)
|
231
|
+
) TYPE=InnoDB;
|
232
|
+
<<<<<<< .mine
|
233
|
+
|
234
|
+
=======
|
235
|
+
|
236
|
+
CREATE TABLE `numeric_data` (
|
237
|
+
`id` INTEGER NOT NULL auto_increment PRIMARY KEY,
|
238
|
+
`bank_balance` decimal(10,2),
|
239
|
+
`big_bank_balance` decimal(15,2),
|
240
|
+
`world_population` decimal(10),
|
241
|
+
`my_house_population` decimal(2),
|
242
|
+
`decimal_number_with_default` decimal(3,2) DEFAULT 2.78
|
243
|
+
) TYPE=InnoDB;
|
244
|
+
>>>>>>> .r4885
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
class Enumeration < ActiveRecord::Base
|
3
|
+
validates_columns :color, :severity, :string_field, :int_field
|
4
|
+
end
|
5
|
+
|
6
|
+
class BasicEnum < ActiveRecord::Base
|
7
|
+
validates_columns :value
|
8
|
+
end
|
9
|
+
|
10
|
+
class BasicDefaultEnum < ActiveRecord::Base
|
11
|
+
validates_columns :value
|
12
|
+
end
|
13
|
+
|
14
|
+
class NonnullEnum < ActiveRecord::Base
|
15
|
+
validates_columns :value
|
16
|
+
end
|
17
|
+
|
18
|
+
class NonnullDefaultEnum < ActiveRecord::Base
|
19
|
+
validates_columns :value
|
20
|
+
end
|