Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 373
- Log:
Initial import of Radiant 0.9.1, which is now packaged as a gem. This is an
import of the tagged 0.9.1 source checked out from GitHub, which isn't quite
the same as the gem distribution - but it doesn't seem to be available in an
archived form and the installed gem already has modifications, so this is
the closest I can get.
- Author:
- rool
- Date:
- Mon Mar 21 13:40:05 +0000 2011
- Size:
- 7711 Bytes
1 | require "cases/helper" |
2 | require 'stringio' |
3 | |
4 | |
5 | class SchemaDumperTest < ActiveRecord::TestCase |
6 | def standard_dump |
7 | stream = StringIO.new |
8 | ActiveRecord::SchemaDumper.ignore_tables = [] |
9 | ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream) |
10 | stream.string |
11 | end |
12 | |
13 | def test_schema_dump |
14 | output = standard_dump |
15 | assert_match %r{create_table "accounts"}, output |
16 | assert_match %r{create_table "authors"}, output |
17 | assert_no_match %r{create_table "schema_migrations"}, output |
18 | end |
19 | |
20 | def test_schema_dump_excludes_sqlite_sequence |
21 | output = standard_dump |
22 | assert_no_match %r{create_table "sqlite_sequence"}, output |
23 | end |
24 | |
25 | def test_schema_dump_includes_camelcase_table_name |
26 | output = standard_dump |
27 | assert_match %r{create_table "CamelCase"}, output |
28 | end |
29 | |
30 | def assert_line_up(lines, pattern, required = false) |
31 | return assert(true) if lines.empty? |
32 | matches = lines.map { |line| line.match(pattern) } |
33 | assert matches.all? if required |
34 | matches.compact! |
35 | return assert(true) if matches.empty? |
36 | assert_equal 1, matches.map{ |match| match.offset(0).first }.uniq.length |
37 | end |
38 | |
39 | def column_definition_lines(output = standard_dump) |
40 | output.scan(/^( *)create_table.*?\n(.*?)^\1end/m).map{ |m| m.last.split(/\n/) } |
41 | end |
42 | |
43 | def test_types_line_up |
44 | column_definition_lines.each do |column_set| |
45 | next if column_set.empty? |
46 | |
47 | lengths = column_set.map do |column| |
48 | if match = column.match(/t\.(?:integer|decimal|float|datetime|timestamp|time|date|text|binary|string|boolean)\s+"/) |
49 | match[0].length |
50 | end |
51 | end |
52 | |
53 | assert_equal 1, lengths.uniq.length |
54 | end |
55 | end |
56 | |
57 | def test_arguments_line_up |
58 | column_definition_lines.each do |column_set| |
59 | assert_line_up(column_set, /:default => /) |
60 | assert_line_up(column_set, /:limit => /) |
61 | assert_line_up(column_set, /:null => /) |
62 | end |
63 | end |
64 | |
65 | def test_no_dump_errors |
66 | output = standard_dump |
67 | assert_no_match %r{\# Could not dump table}, output |
68 | end |
69 | |
70 | def test_schema_dump_includes_not_null_columns |
71 | stream = StringIO.new |
72 | |
73 | ActiveRecord::SchemaDumper.ignore_tables = [/^[^r]/] |
74 | ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream) |
75 | output = stream.string |
76 | assert_match %r{:null => false}, output |
77 | end |
78 | |
79 | def test_schema_dump_includes_limit_constraint_for_integer_columns |
80 | stream = StringIO.new |
81 | |
82 | ActiveRecord::SchemaDumper.ignore_tables = [/^(?!integer_limits)/] |
83 | ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream) |
84 | output = stream.string |
85 | |
86 | if current_adapter?(:PostgreSQLAdapter) |
87 | assert_match %r{c_int_1.*:limit => 2}, output |
88 | assert_match %r{c_int_2.*:limit => 2}, output |
89 | |
90 | # int 3 is 4 bytes in postgresql |
91 | assert_match %r{c_int_3.*}, output |
92 | assert_no_match %r{c_int_3.*:limit}, output |
93 | |
94 | assert_match %r{c_int_4.*}, output |
95 | assert_no_match %r{c_int_4.*:limit}, output |
96 | elsif current_adapter?(:MysqlAdapter) |
97 | assert_match %r{c_int_1.*:limit => 1}, output |
98 | assert_match %r{c_int_2.*:limit => 2}, output |
99 | assert_match %r{c_int_3.*:limit => 3}, output |
100 | |
101 | assert_match %r{c_int_4.*}, output |
102 | assert_no_match %r{c_int_4.*:limit}, output |
103 | elsif current_adapter?(:SQLiteAdapter) |
104 | assert_match %r{c_int_1.*:limit => 1}, output |
105 | assert_match %r{c_int_2.*:limit => 2}, output |
106 | assert_match %r{c_int_3.*:limit => 3}, output |
107 | assert_match %r{c_int_4.*:limit => 4}, output |
108 | end |
109 | assert_match %r{c_int_without_limit.*}, output |
110 | assert_no_match %r{c_int_without_limit.*:limit}, output |
111 | |
112 | if current_adapter?(:SQLiteAdapter) |
113 | assert_match %r{c_int_5.*:limit => 5}, output |
114 | assert_match %r{c_int_6.*:limit => 6}, output |
115 | assert_match %r{c_int_7.*:limit => 7}, output |
116 | assert_match %r{c_int_8.*:limit => 8}, output |
117 | else |
118 | assert_match %r{c_int_5.*:limit => 8}, output |
119 | assert_match %r{c_int_6.*:limit => 8}, output |
120 | assert_match %r{c_int_7.*:limit => 8}, output |
121 | assert_match %r{c_int_8.*:limit => 8}, output |
122 | end |
123 | end |
124 | |
125 | def test_schema_dump_with_string_ignored_table |
126 | stream = StringIO.new |
127 | |
128 | ActiveRecord::SchemaDumper.ignore_tables = ['accounts'] |
129 | ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream) |
130 | output = stream.string |
131 | assert_no_match %r{create_table "accounts"}, output |
132 | assert_match %r{create_table "authors"}, output |
133 | assert_no_match %r{create_table "schema_migrations"}, output |
134 | end |
135 | |
136 | def test_schema_dump_with_regexp_ignored_table |
137 | stream = StringIO.new |
138 | |
139 | ActiveRecord::SchemaDumper.ignore_tables = [/^account/] |
140 | ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream) |
141 | output = stream.string |
142 | assert_no_match %r{create_table "accounts"}, output |
143 | assert_match %r{create_table "authors"}, output |
144 | assert_no_match %r{create_table "schema_migrations"}, output |
145 | end |
146 | |
147 | def test_schema_dump_illegal_ignored_table_value |
148 | stream = StringIO.new |
149 | ActiveRecord::SchemaDumper.ignore_tables = [5] |
150 | assert_raise(StandardError) do |
151 | ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream) |
152 | end |
153 | end |
154 | |
155 | def test_schema_dumps_index_columns_in_right_order |
156 | index_definition = standard_dump.split(/\n/).grep(/add_index.*companies/).first.strip |
157 | assert_equal 'add_index "companies", ["firm_id", "type", "rating", "ruby_type"], :name => "company_index"', index_definition |
158 | end |
159 | |
160 | def test_schema_dump_should_honor_nonstandard_primary_keys |
161 | output = standard_dump |
162 | match = output.match(%r{create_table "movies"(.*)do}) |
163 | assert_not_nil(match, "nonstandardpk table not found") |
164 | assert_match %r(:primary_key => "movieid"), match[1], "non-standard primary key not preserved" |
165 | end |
166 | |
167 | if current_adapter?(:MysqlAdapter) |
168 | def test_schema_dump_should_not_add_default_value_for_mysql_text_field |
169 | output = standard_dump |
170 | assert_match %r{t.text\s+"body",\s+:null => false$}, output |
171 | end |
172 | |
173 | def test_schema_dump_includes_length_for_mysql_blob_and_text_fields |
174 | output = standard_dump |
175 | assert_match %r{t.binary\s+"tiny_blob",\s+:limit => 255$}, output |
176 | assert_match %r{t.binary\s+"normal_blob"$}, output |
177 | assert_match %r{t.binary\s+"medium_blob",\s+:limit => 16777215$}, output |
178 | assert_match %r{t.binary\s+"long_blob",\s+:limit => 2147483647$}, output |
179 | assert_match %r{t.text\s+"tiny_text",\s+:limit => 255$}, output |
180 | assert_match %r{t.text\s+"normal_text"$}, output |
181 | assert_match %r{t.text\s+"medium_text",\s+:limit => 16777215$}, output |
182 | assert_match %r{t.text\s+"long_text",\s+:limit => 2147483647$}, output |
183 | end |
184 | end |
185 | |
186 | def test_schema_dump_includes_decimal_options |
187 | stream = StringIO.new |
188 | ActiveRecord::SchemaDumper.ignore_tables = [/^[^n]/] |
189 | ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream) |
190 | output = stream.string |
191 | assert_match %r{:precision => 3,[[:space:]]+:scale => 2,[[:space:]]+:default => 2.78}, output |
192 | end |
193 | |
194 | if current_adapter?(:PostgreSQLAdapter) |
195 | def test_schema_dump_includes_xml_shorthand_definition |
196 | output = standard_dump |
197 | if %r{create_table "postgresql_xml_data_type"} =~ output |
198 | assert_match %r{t.xml "data"}, output |
199 | end |
200 | end |
201 | end |
202 | |
203 | def test_schema_dump_keeps_id_column_when_id_is_false_and_id_column_added |
204 | output = standard_dump |
205 | match = output.match(%r{create_table "goofy_string_id"(.*)do.*\n(.*)\n}) |
206 | assert_not_nil(match, "goofy_string_id table not found") |
207 | assert_match %r(:id => false), match[1], "no table id not preserved" |
208 | assert_match %r{t.string[[:space:]]+"id",[[:space:]]+:null => false$}, match[2], "non-primary key id column not preserved" |
209 | end |
210 | end |
211 |