-
-
Notifications
You must be signed in to change notification settings - Fork 248
/
schema_comment_spec.rb
114 lines (99 loc) · 3.9 KB
/
schema_comment_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Rails::SchemaComment, :config do
context 'when send add_column' do
it 'registers an offense when `add_column` has no `comment` option' do
expect_offense(<<~RUBY)
add_column :table, :column, :integer
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ New database column without `comment`.
RUBY
end
it 'registers an offense when `add_column` has no `comment` option, but other options' do
expect_offense(<<~RUBY)
add_column :table, :column, :integer, default: 0
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ New database column without `comment`.
RUBY
end
it 'registers an offense when `add_column` has a nil `comment` option' do
expect_offense(<<~RUBY)
add_column :table, :column, :integer, comment: nil
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ New database column without `comment`.
RUBY
end
it 'registers an offense when `add_column` has an empty `comment` option' do
expect_offense(<<~RUBY)
add_column :table, :column, :integer, comment: ''
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ New database column without `comment`.
RUBY
end
it 'does not register an offense when `add_column` has `comment` option' do
expect_no_offenses(<<~RUBY)
add_column :table, :column, :integer, comment: 'An integer field'
RUBY
end
it 'does not register an offense when `add_column` has `comment` option among other options' do
expect_no_offenses(<<~RUBY)
add_column :table, :column, :integer, null: false, comment: 'An integer field', default: 0
RUBY
end
end
context 'when send create_table' do
it 'registers an offense when `create_table` has no `comment` option' do
expect_offense(<<~RUBY)
create_table :users do |t|
^^^^^^^^^^^^^^^^^^^ New database table without `comment`.
end
RUBY
end
it 'registers an offense when `create_table` has a nil `comment` option' do
expect_offense(<<~RUBY)
create_table :users, comment: nil do |t|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ New database table without `comment`.
end
RUBY
end
it 'registers an offense when `create_table` has a empty `comment` option' do
expect_offense(<<~RUBY)
create_table :users, comment: '' do |t|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ New database table without `comment`.
end
RUBY
end
it 'registers an offense when `t.column` has no `comment` option' do
expect_offense(<<~RUBY)
create_table :users, comment: 'Table' do |t|
t.column :column, :integer
^^^^^^^^^^^^^^^^^^^^^^^^^^ New database column without `comment`.
end
RUBY
end
it 'registers an offense when `t.integer` has no `comment` option' do
expect_offense(<<~RUBY)
create_table :users, comment: 'Table' do |t|
t.integer :column
^^^^^^^^^^^^^^^^^ New database column without `comment`.
end
RUBY
end
it 'does not register an offense when `t.column` has `comment` option' do
expect_no_offenses(<<~RUBY)
create_table :users, comment: 'Table' do |t|
t.column :column, :integer, comment: 'I am a column'
end
RUBY
end
it 'does not register an offense when `t.column` has `comment` option among other options' do
expect_no_offenses(<<~RUBY)
create_table :users, comment: 'Table' do |t|
t.column :column, :integer, default: nil, comment: 'I am a column', null: true
end
RUBY
end
it 'does not register an offense when `t.integer` has `comment` option among other options' do
expect_no_offenses(<<~RUBY)
create_table :users, comment: 'Table' do |t|
t.integer :column, default: nil, comment: 'I am a column', null: true
end
RUBY
end
end
end