@@ -24,21 +24,6 @@ class HoverTest < ActiveSupport::TestCase
24
24
end
25
25
26
26
test "hook returns model column information" do
27
- expected_response = {
28
- schema_file : "#{ dummy_root } /db/schema.rb" ,
29
- columns : [
30
- [ "id" , "integer" ] ,
31
- [ "first_name" , "string" ] ,
32
- [ "last_name" , "string" ] ,
33
- [ "age" , "integer" ] ,
34
- [ "created_at" , "datetime" ] ,
35
- [ "updated_at" , "datetime" ] ,
36
- ] ,
37
- primary_keys : [ "id" ] ,
38
- }
39
-
40
- RunnerClient . any_instance . stubs ( model : expected_response )
41
-
42
27
response = hover_on_source ( <<~RUBY , { line : 3 , character : 0 } )
43
28
class User < ApplicationRecord
44
29
end
@@ -70,40 +55,23 @@ class User < ApplicationRecord
70
55
end
71
56
72
57
test "return column information for namespaced models" do
73
- expected_response = {
74
- schema_file : "#{ dummy_root } /db/schema.rb" ,
75
- columns : [
76
- [ "id" , "integer" ] ,
77
- [ "first_name" , "string" ] ,
78
- [ "last_name" , "string" ] ,
79
- [ "age" , "integer" ] ,
80
- [ "created_at" , "datetime" ] ,
81
- [ "updated_at" , "datetime" ] ,
82
- ] ,
83
- primary_keys : [ "id" ] ,
84
- }
85
-
86
- RunnerClient . any_instance . stubs ( model : expected_response )
87
-
88
58
response = hover_on_source ( <<~RUBY , { line : 4 , character : 6 } )
89
59
module Blog
90
- class User < ApplicationRecord
60
+ class Post < ApplicationRecord
91
61
end
92
62
end
93
63
94
- Blog::User
64
+ Blog::Post
95
65
RUBY
96
66
97
67
assert_equal ( <<~CONTENT . chomp , response . contents . value )
98
68
[Schema](file://#{ dummy_root } /db/schema.rb)
99
69
100
70
**id**: integer (PK)
101
71
102
- **first_name**: string
103
-
104
- **last_name**: string
72
+ **title**: string
105
73
106
- **age **: integer
74
+ **body **: text
107
75
108
76
**created_at**: datetime
109
77
@@ -112,20 +80,6 @@ class User < ApplicationRecord
112
80
end
113
81
114
82
test "returns column information for models with composite primary keys" do
115
- expected_response = {
116
- schema_file : "#{ dummy_root } /db/schema.rb" ,
117
- columns : [
118
- [ "order_id" , "integer" ] ,
119
- [ "product_id" , "integer" ] ,
120
- [ "note" , "string" ] ,
121
- [ "created_at" , "datetime" ] ,
122
- [ "updated_at" , "datetime" ] ,
123
- ] ,
124
- primary_keys : [ "order_id" , "product_id" ] ,
125
- }
126
-
127
- RunnerClient . any_instance . stubs ( model : expected_response )
128
-
129
83
response = hover_on_source ( <<~RUBY , { line : 3 , character : 0 } )
130
84
class CompositePrimaryKey < ApplicationRecord
131
85
end
@@ -146,55 +100,14 @@ class CompositePrimaryKey < ApplicationRecord
146
100
147
101
**product_id**: integer (PK)
148
102
149
- **note**: string
103
+ **note**: text
150
104
151
105
**created_at**: datetime
152
106
153
107
**updated_at**: datetime
154
108
CONTENT
155
109
end
156
110
157
- test "handles `db/structure.sql` instead of `db/schema.rb`" do
158
- expected_response = {
159
- schema_file : "#{ dummy_root } /db/structure.sql" ,
160
- columns : [ ] ,
161
- primary_keys : [ ] ,
162
- }
163
-
164
- RunnerClient . any_instance . stubs ( model : expected_response )
165
-
166
- response = hover_on_source ( <<~RUBY , { line : 3 , character : 0 } )
167
- class User < ApplicationRecord
168
- end
169
-
170
- User
171
- RUBY
172
-
173
- assert_includes (
174
- response . contents . value ,
175
- "[Schema](file://#{ dummy_root } /db/structure.sql)" ,
176
- )
177
- end
178
-
179
- test "handles neither `db/structure.sql` nor `db/schema.rb` being present" do
180
- expected_response = {
181
- schema_file : nil ,
182
- columns : [ ] ,
183
- primary_keys : [ ] ,
184
- }
185
-
186
- RunnerClient . any_instance . stubs ( model : expected_response )
187
-
188
- response = hover_on_source ( <<~RUBY , { line : 3 , character : 0 } )
189
- class User < ApplicationRecord
190
- end
191
-
192
- User
193
- RUBY
194
-
195
- refute_match ( /Schema/ , response . contents . value )
196
- end
197
-
198
111
test "shows documentation for routes DSLs" do
199
112
value = hover_on_source ( "root 'projects#index'" , { line : 0 , character : 0 } ) . contents . value
200
113
0 commit comments